优化代码生成
This commit is contained in:
@@ -16,7 +16,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
|
||||
public static string TIME_FORMAT_FULL_2 = "MM-dd HH:mm:ss";
|
||||
|
||||
protected IActionResult SUCCESS(object data, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult SUCCESS(object data, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(GetApiResult(data != null ? ResultCode.SUCCESS : ResultCode.FAIL, data), timeFormatStr);
|
||||
return Content(jsonStr, "application/json");
|
||||
@@ -34,13 +34,13 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="apiResult"></param>
|
||||
/// <param name="timeFormatStr"></param>
|
||||
/// <returns></returns>
|
||||
protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(apiResult, timeFormatStr);
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected IActionResult OutputJson(long rows, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult OutputJson(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr);
|
||||
|
||||
|
||||
138
ZR.Admin.WebApi/Controllers/business/GendemoController.cs
Normal file
138
ZR.Admin.WebApi/Controllers/business/GendemoController.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Controllers;
|
||||
using ZR.Service.Business;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model.Models;
|
||||
|
||||
namespace ZRAdmin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码自动生成
|
||||
/// </summary>
|
||||
|
||||
//[Verify]
|
||||
[Route("bus/gendemo")]
|
||||
public class GendemoController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 接口
|
||||
/// </summary>
|
||||
private readonly IGendemoService _GendemoService;
|
||||
|
||||
public GendemoController(IGendemoService GendemoService)
|
||||
{
|
||||
_GendemoService = GendemoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "gendemo:list")]
|
||||
public IActionResult Query([FromQuery] GendemoQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<Gendemo>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _GendemoService.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{Id}")]
|
||||
[ActionPermissionFilter(Permission = "gendemo:query")]
|
||||
public IActionResult Get(int Id)
|
||||
{
|
||||
var response = _GendemoService.GetId(Id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "gendemo:add")]
|
||||
[Log(Title = "添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] GendemoDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<Gendemo>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_GendemoService.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "gendemo:update")]
|
||||
[Log(Title = "修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] GendemoDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var updateModel = parm.Adapt<Gendemo>().ToCreate();
|
||||
//updateModel.CreateID = User.Identity.Name;
|
||||
|
||||
var response = _GendemoService.Update(w => w.Id == updateModel.Id, it => new Gendemo()
|
||||
{
|
||||
//TODO 字段映射
|
||||
Name = parm.Name,
|
||||
Icon = parm.Icon,
|
||||
ShowStatus = parm.ShowStatus,
|
||||
AddTime = parm.AddTime,
|
||||
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{Id}")]
|
||||
[ActionPermissionFilter(Permission = "gendemo:delete")]
|
||||
[Log(Title = "删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int Id = 0)
|
||||
{
|
||||
if (Id <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
// 删除
|
||||
var response = _GendemoService.Delete(Id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
<el-button type="primary" v-hasPermi="['{Permission}:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" v-hasPermi="['{Permission}:update']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
|
||||
<el-button type="success" :disabled="single" v-hasPermi="['{Permission}:update']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" v-hasPermi="['{Permission}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||
@@ -53,7 +53,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination class="mt10" background :total="total" :current-page.sync="queryParams.pageNum" :page-size="queryParams.pageSize" :page-sizes="[20, 30, 50, 100]" @size-change="handleSizeChange" @current-change="getList" />
|
||||
<el-pagination class="mt10" background :total="total" :current-page.sync="queryParams.pageNum" :page-size="queryParams.pageSize" :page-sizes="[20, 30, 50, 100]" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="getList" />
|
||||
|
||||
<!-- 添加或修改菜单对话框 -->
|
||||
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
||||
@@ -232,14 +232,4 @@ export default {
|
||||
.table-td-thumb {
|
||||
width: 80px;
|
||||
}
|
||||
.icon {
|
||||
width: 100px;
|
||||
}
|
||||
.uploader-icon {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
border: 1px dashed #ccc;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user