using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Myshipping.Core.Entity;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Myshipping.Core.Service;
///
/// 代码生成详细配置服务
///
[ApiDescriptionSettings(Name = "CodeGenConfig", Order = 100)]
public class CodeGenConfigService : ICodeGenConfigService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _sysCodeGenConfigRep; // 代码生成详细配置仓储
public CodeGenConfigService(SqlSugarRepository sysCodeGenConfigRep)
{
_sysCodeGenConfigRep = sysCodeGenConfigRep;
}
///
/// 代码生成详细配置列表
///
///
///
[HttpGet("/sysCodeGenerateConfig/list")]
public async Task> List([FromQuery] CodeGenConfig input)
{
return await _sysCodeGenConfigRep.Where(u => u.CodeGenId == input.CodeGenId && u.WhetherCommon != YesOrNot.Y.ToString())
.Select().ToListAsync();
}
///
/// 增加
///
///
///
[NonAction]
public async Task Add(CodeGenConfig input)
{
var codeGenConfig = input.Adapt();
await _sysCodeGenConfigRep.InsertAsync(codeGenConfig);
}
///
/// 删除
///
///
///
[NonAction]
public async Task Delete(long codeGenId)
{
await _sysCodeGenConfigRep.DeleteAsync(u => u.CodeGenId == codeGenId);
}
///
/// 更新
///
///
///
[HttpPost("/sysCodeGenerateConfig/edit")]
public async Task Update(List inputList)
{
if (inputList == null || inputList.Count < 1) return;
List list = inputList.Adapt>();
await _sysCodeGenConfigRep.UpdateAsync(list);
}
///
/// 详情
///
///
///
[HttpGet("/sysCodeGenerateConfig/detail")]
public async Task Detail(CodeGenConfig input)
{
return await _sysCodeGenConfigRep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 批量增加
///
///
///
[NonAction]
public void AddList(List tableColumnOuputList, SysCodeGen codeGenerate)
{
if (tableColumnOuputList == null) return;
var codeGenConfigs = new List();
foreach (var tableColumn in tableColumnOuputList)
{
var codeGenConfig = new SysCodeGenConfig();
var YesOrNo = YesOrNot.Y.ToString();
if (Convert.ToBoolean(tableColumn.ColumnKey))
{
YesOrNo = YesOrNot.N.ToString();
}
if (CodeGenUtil.IsCommonColumn(tableColumn.ColumnName))
{
codeGenConfig.WhetherCommon = YesOrNot.Y.ToString();
YesOrNo = YesOrNot.N.ToString();
}
else
{
codeGenConfig.WhetherCommon = YesOrNot.N.ToString();
}
codeGenConfig.CodeGenId = codeGenerate.Id;
codeGenConfig.ColumnName = tableColumn.ColumnName;
codeGenConfig.ColumnComment = tableColumn.ColumnComment;
codeGenConfig.NetType = CodeGenUtil.ConvertDataType(tableColumn.DataType);
codeGenConfig.WhetherRetract = YesOrNot.N.ToString();
codeGenConfig.WhetherRequired = YesOrNot.N.ToString();
codeGenConfig.QueryWhether = YesOrNo;
codeGenConfig.WhetherAddUpdate = YesOrNo;
codeGenConfig.WhetherTable = YesOrNo;
codeGenConfig.ColumnKey = tableColumn.ColumnKey;
codeGenConfig.DataType = tableColumn.DataType;
codeGenConfig.EffectType = CodeGenUtil.DataTypeToEff(codeGenConfig.NetType);
codeGenConfig.QueryType = "=="; // QueryTypeEnum.eq.ToString();
codeGenConfigs.Add(codeGenConfig);
}
_sysCodeGenConfigRep.InsertAsync(codeGenConfigs);
}
}