优化代码生成
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user