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.LqYcsdDysbmxb; 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_dysbmxb; using NCC.Extend.Entitys.Dto.LqYcsdDysbmxb; 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.LqYcsdDysbmxb { /// /// 当月社保明细表服务 /// [ApiDescriptionSettings(Tag = "Extend", Name = "LqYcsdDysbmxb", Order = 200)] [Route("api/Extend/[controller]")] public class LqYcsdDysbmxbService : ILqYcsdDysbmxbService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _lqYcsdDysbmxbRepository; private readonly SqlSugarScope _db; private readonly IUserManager _userManager; /// /// 初始化一个类型的新实例 /// public LqYcsdDysbmxbService( ISqlSugarRepository lqYcsdDysbmxbRepository, IUserManager userManager) { _lqYcsdDysbmxbRepository = lqYcsdDysbmxbRepository; _db = _lqYcsdDysbmxbRepository.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] LqYcsdDysbmxbListQueryInput input) { var sidx = input.sidx == null ? "id" : input.sidx; var data = await _db.Queryable() .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id)) .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm)) .WhereIF(!string.IsNullOrEmpty(input.md1), p => p.Md1.Contains(input.md1)) .WhereIF(!string.IsNullOrEmpty(input.md2), p => p.Md2.Contains(input.md2)) .WhereIF(!string.IsNullOrEmpty(input.gmmd), p => p.Gmmd.Contains(input.gmmd)) .WhereIF(!string.IsNullOrEmpty(input.hxcb), p => p.Hxcb.Contains(input.hxcb)) .WhereIF(!string.IsNullOrEmpty(input.cbyf), p => p.Cbyf.Contains(input.cbyf)) .WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf)) .WhereIF(!string.IsNullOrEmpty(input.sb), p => p.Sb.Equals(input.sb)) .WhereIF(!string.IsNullOrEmpty(input.yb), p => p.Yb.Equals(input.yb)) .WhereIF(!string.IsNullOrEmpty(input.zj), p => p.Zj.Equals(input.zj)) .WhereIF(!string.IsNullOrEmpty(input.gzk), p => p.Gzk.Equals(input.gzk)) .WhereIF(!string.IsNullOrEmpty(input.cb), p => p.Cb.Equals(input.cb)) .Select(it => new LqYcsdDysbmxbListOutput { id = it.Id, xm = it.Xm, md1 = it.Md1, md2 = it.Md2, gmmd = it.Gmmd, hxcb = it.Hxcb, cbyf = it.Cbyf, yf = it.Yf, sb = it.Sb, yb = it.Yb, zj = it.Zj, gzk = it.Gzk, cb = it.Cb, }).MergeTable().OrderBy(sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(data); } /// /// 新建当月社保明细表 /// /// 参数 /// [HttpPost("")] public async Task Create([FromBody] LqYcsdDysbmxbCrInput 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] LqYcsdDysbmxbListQueryInput input) { var sidx = input.sidx == null ? "id" : input.sidx; var data = await _db.Queryable() .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id)) .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm)) .WhereIF(!string.IsNullOrEmpty(input.md1), p => p.Md1.Contains(input.md1)) .WhereIF(!string.IsNullOrEmpty(input.md2), p => p.Md2.Contains(input.md2)) .WhereIF(!string.IsNullOrEmpty(input.gmmd), p => p.Gmmd.Contains(input.gmmd)) .WhereIF(!string.IsNullOrEmpty(input.hxcb), p => p.Hxcb.Contains(input.hxcb)) .WhereIF(!string.IsNullOrEmpty(input.cbyf), p => p.Cbyf.Contains(input.cbyf)) .WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf)) .WhereIF(!string.IsNullOrEmpty(input.sb), p => p.Sb.Equals(input.sb)) .WhereIF(!string.IsNullOrEmpty(input.yb), p => p.Yb.Equals(input.yb)) .WhereIF(!string.IsNullOrEmpty(input.zj), p => p.Zj.Equals(input.zj)) .WhereIF(!string.IsNullOrEmpty(input.gzk), p => p.Gzk.Equals(input.gzk)) .WhereIF(!string.IsNullOrEmpty(input.cb), p => p.Cb.Equals(input.cb)) .Select(it => new LqYcsdDysbmxbListOutput { id = it.Id, xm = it.Xm, md1 = it.Md1, md2 = it.Md2, gmmd = it.Gmmd, hxcb = it.Hxcb, cbyf = it.Cbyf, yf = it.Yf, sb = it.Sb, yb = it.Yb, zj = it.Zj, gzk = it.Gzk, cb = it.Cb, }).MergeTable().OrderBy(sidx + " " + input.sort).ToListAsync(); return data; } /// /// 导出当月社保明细表 /// /// 请求参数 /// [HttpGet("Actions/Export")] public async Task Export([FromQuery] LqYcsdDysbmxbListQueryInput 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\":\"xm\"},{\"value\":\"门店1\",\"field\":\"md1\"},{\"value\":\"门店2\",\"field\":\"md2\"},{\"value\":\"购买门店\",\"field\":\"gmmd\"},{\"value\":\"后续参保\",\"field\":\"hxcb\"},{\"value\":\"参保月份\",\"field\":\"cbyf\"},{\"value\":\"月份\",\"field\":\"yf\"},{\"value\":\"社保\",\"field\":\"sb\"},{\"value\":\"医保\",\"field\":\"yb\"},{\"value\":\"总计\",\"field\":\"zj\"},{\"value\":\"工资扣\",\"field\":\"gzk\"},{\"value\":\"成本\",\"field\":\"cb\"},]".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] LqYcsdDysbmxbUpInput 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); } } }