using NCC.Common.Core.Manager; using NCC.Common.Enum; using NCC.Common.Extension; using NCC.Common.Filter; using NCC.Dependency; using NCC.DynamicApiController; using NCC.FriendlyException; using NCC.Extend.Interfaces.LqYcsdGzhsfdtjsz; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NCC.Extend.Entitys.lq_ycsd_gzhsfdtjsz; using NCC.Extend.Entitys.Dto.LqYcsdGzhsfdtjsz; using Yitter.IdGenerator; using NCC.Common.Helper; using NCC.JsonSerialization; using NCC.Common.Model.NPOI; using NCC.Common.Configuration; using NCC.DataEncryption; using NCC.ClayObject; namespace NCC.Extend.LqYcsdGzhsfdtjsz { /// /// 工资核算浮动条件设置服务 /// [ApiDescriptionSettings(Tag = "Extend",Name = "LqYcsdGzhsfdtjsz", Order = 200)] [Route("api/Extend/[controller]")] public class LqYcsdGzhsfdtjszService : ILqYcsdGzhsfdtjszService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _lqYcsdGzhsfdtjszRepository; private readonly SqlSugarScope _db; private readonly IUserManager _userManager; /// /// 初始化一个类型的新实例 /// public LqYcsdGzhsfdtjszService( ISqlSugarRepository lqYcsdGzhsfdtjszRepository, IUserManager userManager) { _lqYcsdGzhsfdtjszRepository = lqYcsdGzhsfdtjszRepository; _db = _lqYcsdGzhsfdtjszRepository.Context; _userManager = userManager; } /// /// 获取工资核算浮动条件设置 /// /// 参数 /// [HttpGet("{id}")] public async Task GetInfo(string id) { var entity = await _db.Queryable().FirstAsync(p => p.Id == id); var output = entity.Adapt(); return output; } /// /// 获取工资核算浮动条件设置列表 /// /// 请求参数 /// [HttpGet("")] public async Task GetList([FromQuery] LqYcsdGzhsfdtjszListQueryInput input) { var sidx = input.sidx == null ? "id" : input.sidx; List queryKssj = input.kssj != null ? input.kssj.Split(',').ToObeject>() : null; DateTime? startKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.First()) : null; DateTime? endKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.Last()) : null; List queryJssj = input.jssj != null ? input.jssj.Split(',').ToObeject>() : null; DateTime? startJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.First()) : null; DateTime? endJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.Last()) : null; var data = await _db.Queryable() .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id)) .WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md)) .WhereIF(!string.IsNullOrEmpty(input.rts1), p => p.Rts1.Contains(input.rts1)) .WhereIF(!string.IsNullOrEmpty(input.rts2), p => p.Rts2.Contains(input.rts2)) .WhereIF(!string.IsNullOrEmpty(input.sxzbSmxYj), p => p.SxzbSmxYj.Contains(input.sxzbSmxYj)) .WhereIF(!string.IsNullOrEmpty(input.sxzbRtGd), p => p.SxzbRtGd.Contains(input.sxzbRtGd)) .WhereIF(!string.IsNullOrEmpty(input.sxzbXhGd), p => p.SxzbXhGd.Contains(input.sxzbXhGd)) .WhereIF(!string.IsNullOrEmpty(input.jlzbxYjJd1), p => p.JlzbxYjJd1.Contains(input.jlzbxYjJd1)) .WhereIF(!string.IsNullOrEmpty(input.jlzbxYjJd2), p => p.JlzbxYjJd2.Contains(input.jlzbxYjJd2)) .WhereIF(!string.IsNullOrEmpty(input.zjlzbxYjJd1), p => p.ZjlzbxYjJd1.Contains(input.zjlzbxYjJd1)) .WhereIF(!string.IsNullOrEmpty(input.zjlzbxYjJd2), p => p.ZjlzbxYjJd2.Contains(input.zjlzbxYjJd2)) .WhereIF(queryKssj != null, p => p.Kssj >= new DateTime(startKssj.ToDate().Year, startKssj.ToDate().Month, startKssj.ToDate().Day, 0, 0, 0)) .WhereIF(queryKssj != null, p => p.Kssj <= new DateTime(endKssj.ToDate().Year, endKssj.ToDate().Month, endKssj.ToDate().Day, 23, 59, 59)) .WhereIF(queryJssj != null, p => p.Jssj >= new DateTime(startJssj.ToDate().Year, startJssj.ToDate().Month, startJssj.ToDate().Day, 0, 0, 0)) .WhereIF(queryJssj != null, p => p.Jssj <= new DateTime(endJssj.ToDate().Year, endJssj.ToDate().Month, endJssj.ToDate().Day, 23, 59, 59)) .Select(it=> new LqYcsdGzhsfdtjszListOutput { id = it.Id, md=it.Md, rts1=it.Rts1, rts2=it.Rts2, sxzbSmxYj=it.SxzbSmxYj, sxzbRtGd=it.SxzbRtGd, sxzbXhGd=it.SxzbXhGd, jlzbxYjJd1=it.JlzbxYjJd1, jlzbxYjJd2=it.JlzbxYjJd2, zjlzbxYjJd1=it.ZjlzbxYjJd1, zjlzbxYjJd2=it.ZjlzbxYjJd2, kssj=it.Kssj, jssj=it.Jssj, }).MergeTable().OrderBy(sidx+" "+input.sort).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(data); } /// /// 新建工资核算浮动条件设置 /// /// 参数 /// [HttpPost("")] public async Task Create([FromBody] LqYcsdGzhsfdtjszCrInput input) { var userInfo = await _userManager.GetUserInfo(); var entity = input.Adapt(); entity.Id = YitIdHelper.NextId().ToString(); var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); } /// /// 获取工资核算浮动条件设置无分页列表 /// /// 请求参数 /// [NonAction] public async Task GetNoPagingList([FromQuery] LqYcsdGzhsfdtjszListQueryInput input) { var sidx = input.sidx == null ? "id" : input.sidx; List queryKssj = input.kssj != null ? input.kssj.Split(',').ToObeject>() : null; DateTime? startKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.First()) : null; DateTime? endKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.Last()) : null; List queryJssj = input.jssj != null ? input.jssj.Split(',').ToObeject>() : null; DateTime? startJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.First()) : null; DateTime? endJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.Last()) : null; var data = await _db.Queryable() .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id)) .WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md)) .WhereIF(!string.IsNullOrEmpty(input.rts1), p => p.Rts1.Contains(input.rts1)) .WhereIF(!string.IsNullOrEmpty(input.rts2), p => p.Rts2.Contains(input.rts2)) .WhereIF(!string.IsNullOrEmpty(input.sxzbSmxYj), p => p.SxzbSmxYj.Contains(input.sxzbSmxYj)) .WhereIF(!string.IsNullOrEmpty(input.sxzbRtGd), p => p.SxzbRtGd.Contains(input.sxzbRtGd)) .WhereIF(!string.IsNullOrEmpty(input.sxzbXhGd), p => p.SxzbXhGd.Contains(input.sxzbXhGd)) .WhereIF(!string.IsNullOrEmpty(input.jlzbxYjJd1), p => p.JlzbxYjJd1.Contains(input.jlzbxYjJd1)) .WhereIF(!string.IsNullOrEmpty(input.jlzbxYjJd2), p => p.JlzbxYjJd2.Contains(input.jlzbxYjJd2)) .WhereIF(!string.IsNullOrEmpty(input.zjlzbxYjJd1), p => p.ZjlzbxYjJd1.Contains(input.zjlzbxYjJd1)) .WhereIF(!string.IsNullOrEmpty(input.zjlzbxYjJd2), p => p.ZjlzbxYjJd2.Contains(input.zjlzbxYjJd2)) .WhereIF(queryKssj != null, p => p.Kssj >= new DateTime(startKssj.ToDate().Year, startKssj.ToDate().Month, startKssj.ToDate().Day, 0, 0, 0)) .WhereIF(queryKssj != null, p => p.Kssj <= new DateTime(endKssj.ToDate().Year, endKssj.ToDate().Month, endKssj.ToDate().Day, 23, 59, 59)) .WhereIF(queryJssj != null, p => p.Jssj >= new DateTime(startJssj.ToDate().Year, startJssj.ToDate().Month, startJssj.ToDate().Day, 0, 0, 0)) .WhereIF(queryJssj != null, p => p.Jssj <= new DateTime(endJssj.ToDate().Year, endJssj.ToDate().Month, endJssj.ToDate().Day, 23, 59, 59)) .Select(it=> new LqYcsdGzhsfdtjszListOutput { id = it.Id, md=it.Md, rts1=it.Rts1, rts2=it.Rts2, sxzbSmxYj=it.SxzbSmxYj, sxzbRtGd=it.SxzbRtGd, sxzbXhGd=it.SxzbXhGd, jlzbxYjJd1=it.JlzbxYjJd1, jlzbxYjJd2=it.JlzbxYjJd2, zjlzbxYjJd1=it.ZjlzbxYjJd1, zjlzbxYjJd2=it.ZjlzbxYjJd2, kssj=it.Kssj, jssj=it.Jssj, }).MergeTable().OrderBy(sidx+" "+input.sort).ToListAsync(); return data; } /// /// 导出工资核算浮动条件设置 /// /// 请求参数 /// [HttpGet("Actions/Export")] public async Task Export([FromQuery] LqYcsdGzhsfdtjszListQueryInput input) { var userInfo = await _userManager.GetUserInfo(); var exportData = new List(); if (input.dataType == 0) { var data = Clay.Object(await this.GetList(input)); exportData = data.Solidify>().list; } else { exportData = await this.GetNoPagingList(input); } List paramList = "[{\"value\":\"主键\",\"field\":\"id\"},{\"value\":\"门店\",\"field\":\"md\"},{\"value\":\"人头数-一阶段\",\"field\":\"rts1\"},{\"value\":\"人头数-二阶段\",\"field\":\"rts2\"},{\"value\":\"三项指标-生命线-业绩\",\"field\":\"sxzbSmxYj\"},{\"value\":\"三项指标-人头-固定\",\"field\":\"sxzbRtGd\"},{\"value\":\"三项指标-消耗-固定\",\"field\":\"sxzbXhGd\"},{\"value\":\"经理指标线-业绩-一阶段\",\"field\":\"jlzbxYjJd1\"},{\"value\":\"经理指标线-业绩-二阶段\",\"field\":\"jlzbxYjJd2\"},{\"value\":\"总经理指标线-业绩-一阶段\",\"field\":\"zjlzbxYjJd1\"},{\"value\":\"总经理指标线-业绩-二阶段\",\"field\":\"zjlzbxYjJd2\"},{\"value\":\"开始时间\",\"field\":\"kssj\"},{\"value\":\"结束时间\",\"field\":\"jssj\"},]".ToList(); ExcelConfig excelconfig = new ExcelConfig(); excelconfig.FileName = "工资核算浮动条件设置.xls"; excelconfig.HeadFont = "微软雅黑"; excelconfig.HeadPoint = 10; excelconfig.IsAllSizeColumn = true; excelconfig.ColumnModel = new List(); List selectKeyList = input.selectKey.Split(',').ToList(); foreach (var item in selectKeyList) { var isExist = paramList.Find(p => p.field == item); if (isExist != null) { excelconfig.ColumnModel.Add(new ExcelColumnModel() { Column = isExist.field, ExcelColumn = isExist.value }); } } var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName; ExcelExportHelper.Export(exportData, excelconfig, addPath); var fileName = _userManager.UserId + "|" + addPath + "|xls"; var output = new { name = excelconfig.FileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC") }; return output; } /// /// 批量删除工资核算浮动条件设置 /// /// 主键数组 /// [HttpPost("batchRemove")] public async Task BatchRemove([FromBody] List ids) { var entitys = await _db.Queryable().In(it => it.Id, ids).ToListAsync(); if (entitys.Count > 0) { try { //开启事务 _db.BeginTran(); //批量删除工资核算浮动条件设置 await _db.Deleteable().In(d => d.Id,ids).ExecuteCommandAsync(); //关闭事务 _db.CommitTran(); } catch (Exception) { //回滚事务 _db.RollbackTran(); throw NCCException.Oh(ErrorCode.COM1002); } } } /// /// 更新工资核算浮动条件设置 /// /// 主键 /// 参数 /// [HttpPut("{id}")] public async Task Update(string id, [FromBody] LqYcsdGzhsfdtjszUpInput input) { var entity = input.Adapt(); var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001); } /// /// 删除工资核算浮动条件设置 /// /// [HttpDelete("{id}")] public async Task Delete(string id) { var entity = await _db.Queryable().FirstAsync(p => p.Id == id); _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005); var isOk = await _db.Deleteable().Where(d => d.Id == id).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002); } } }