160 lines
5.3 KiB
C#
Raw Normal View History

2021-09-27 08:06:09 +08:00
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SqlSugar;
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Service.Business;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Common;
2021-10-10 10:22:30 +08:00
using Infrastructure.Extensions;
2021-11-27 20:00:13 +08:00
using System.Linq;
2021-09-27 08:06:09 +08:00
namespace ZR.Admin.WebApi.Controllers
{
/// <summary>
/// 代码生成演示Controller
///
/// @author zr
2021-11-27 20:00:13 +08:00
/// @date 2021-11-27
2021-09-27 08:06:09 +08:00
/// </summary>
[Verify]
[Route("business/Gendemo")]
2021-11-27 20:00:13 +08:00
public class GendemoController: BaseController
2021-09-27 08:06:09 +08:00
{
/// <summary>
/// 代码生成演示接口
/// </summary>
private readonly IGendemoService _GendemoService;
public GendemoController(IGendemoService GendemoService)
{
_GendemoService = GendemoService;
}
/// <summary>
/// 查询代码生成演示列表
/// </summary>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:gendemo:list")]
public IActionResult QueryGendemo([FromQuery] GendemoQueryDto parm)
{
//开始拼装查询条件
var predicate = Expressionable.Create<Gendemo>();
2021-11-24 14:30:21 +08:00
//TODO 自己实现搜索条件查询语法参考Sqlsugar默认查询所有
2021-09-27 08:06:09 +08:00
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
2021-11-27 20:00:13 +08:00
predicate = predicate.AndIF(parm.Id > 0, m => m.Id == parm.Id);
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Name), m => m.Name.Contains(parm.Name));
predicate = predicate.AndIF(parm.ShowStatus > 0, m => m.ShowStatus != parm.ShowStatus);
predicate = predicate.AndIF(parm.BeginTime != null, it => it.AddTime >= parm.BeginTime);
predicate = predicate.AndIF(parm.EndTime != null, it => it.AddTime <= parm.EndTime);
2021-11-24 14:30:21 +08:00
2021-09-27 08:06:09 +08:00
var response = _GendemoService.GetPages(predicate.ToExpression(), parm);
return SUCCESS(response);
}
/// <summary>
/// 查询代码生成演示详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:gendemo:query")]
public IActionResult GetGendemo(int Id)
{
2021-11-27 20:00:13 +08:00
var response = _GendemoService.GetFirst(x => x.Id == Id);
2021-09-27 08:06:09 +08:00
return SUCCESS(response);
}
/// <summary>
/// 添加代码生成演示
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:gendemo:add")]
2021-11-24 14:30:21 +08:00
[Log(Title = "代码生成演示", BusinessType = BusinessType.INSERT)]
2021-09-27 08:06:09 +08:00
public IActionResult AddGendemo([FromBody] GendemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
2021-10-10 10:22:30 +08:00
var model = parm.Adapt<Gendemo>().ToCreate(HttpContext);
2021-09-27 08:06:09 +08:00
2021-11-27 09:43:04 +08:00
return SUCCESS(_GendemoService.Insert(model, it => new
2021-09-27 08:06:09 +08:00
{
2021-11-27 20:00:13 +08:00
it.Name,
it.Icon,
it.ShowStatus,
it.AddTime,
it.Sex,
it.Sort,
it.BeginTime,
it.EndTime,
it.Remark,
2021-09-27 08:06:09 +08:00
}));
}
/// <summary>
/// 更新代码生成演示
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:gendemo:update")]
2021-11-24 14:30:21 +08:00
[Log(Title = "代码生成演示", BusinessType = BusinessType.UPDATE)]
2021-09-27 08:06:09 +08:00
public IActionResult UpdateGendemo([FromBody] GendemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求实体不能为空");
}
//从 Dto 映射到 实体
2021-10-10 10:22:30 +08:00
var model = parm.Adapt<Gendemo>().ToUpdate(HttpContext);
2021-09-27 08:06:09 +08:00
var response = _GendemoService.Update(w => w.Id == model.Id, it => new Gendemo()
{
//Update 字段映射
2021-11-27 20:00:13 +08:00
Name = model.Name,
Icon = model.Icon,
ShowStatus = model.ShowStatus,
AddTime = model.AddTime,
Sex = model.Sex,
Sort = model.Sort,
BeginTime = model.BeginTime,
EndTime = model.EndTime,
Remark = model.Remark,
2021-09-27 08:06:09 +08:00
});
return SUCCESS(response);
}
/// <summary>
/// 删除代码生成演示
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:gendemo:delete")]
2021-11-24 14:30:21 +08:00
[Log(Title = "代码生成演示", BusinessType = BusinessType.DELETE)]
2021-09-27 08:06:09 +08:00
public IActionResult DeleteGendemo(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
2021-09-27 16:07:55 +08:00
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
2021-09-27 08:06:09 +08:00
var response = _GendemoService.Delete(idsArr);
return SUCCESS(response);
}
}
}