using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using NCC.ClayObject; using NCC.Common.Configuration; using NCC.Common.Core.Manager; using NCC.Common.Enum; using NCC.Common.Extension; using NCC.Common.Filter; using NCC.Common.Helper; using NCC.Common.Model.NPOI; using NCC.DataEncryption; using NCC.Dependency; using NCC.DynamicApiController; using NCC.Extend.Entitys.Dto.LqGz; using NCC.Extend.Entitys.lq_gz; using NCC.Extend.Entitys.lq_jlmxb; using NCC.Extend.Entitys.lq_kd_jksyj; using NCC.Extend.Entitys.lq_kd_kdjlb; using NCC.Extend.Entitys.lq_kd_kjbsyj; using NCC.Extend.Entitys.lq_kd_pxmx; using NCC.Extend.Entitys.lq_mdxx; using NCC.Extend.Entitys.lq_xmzl; using NCC.Extend.Entitys.lq_ycsd_jsj; using NCC.Extend.Interfaces.LqGz; using NCC.FriendlyException; using NCC.JsonSerialization; using SqlSugar; using Yitter.IdGenerator; namespace NCC.Extend.LqGz { /// /// 工资全字段服务 /// [ApiDescriptionSettings(Tag = "绿纤工资全字段服务", Name = "LqGz", Order = 200)] [Route("api/Extend/[controller]")] public class LqGzService : ILqGzService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _lqGzRepository; private readonly SqlSugarScope _db; private readonly IUserManager _userManager; private readonly ILogger _logger; /// /// 初始化一个类型的新实例 /// public LqGzService(ISqlSugarRepository lqGzRepository, IUserManager userManager, ILogger logger) { _lqGzRepository = lqGzRepository; _db = _lqGzRepository.Context; _userManager = userManager; _logger = logger; } #region 获取工资全字段 /// /// 获取工资全字段 /// /// 参数 /// [HttpGet("{id}")] public async Task GetInfo(string id) { var entity = await _db.Queryable().FirstAsync(p => p.Id == id); var output = entity.Adapt(); return output; } #endregion #region 获取工资全字段列表 /// /// 获取工资全字段列表 /// /// 请求参数 /// [HttpGet("")] public async Task GetList([FromQuery] LqGzListQueryInput 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.md), p => p.Md.Contains(input.md)) .WhereIF(!string.IsNullOrEmpty(input.hsgw), p => p.Hsgw.Contains(input.hsgw)) .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm)) .WhereIF(!string.IsNullOrEmpty(input.jsjzd), p => p.Jsjzd.Contains(input.jsjzd)) .WhereIF(!string.IsNullOrEmpty(input.zyj), p => p.Zyj.Equals(input.zyj)) .WhereIF(!string.IsNullOrEmpty(input.jcyj), p => p.Jcyj.Equals(input.jcyj)) .WhereIF(!string.IsNullOrEmpty(input.hzyj), p => p.Hzyj.Equals(input.hzyj)) .WhereIF(!string.IsNullOrEmpty(input.jlyj), p => p.Jlyj.Equals(input.jlyj)) .WhereIF(!string.IsNullOrEmpty(input.mdzyj), p => p.Mdzyj.Equals(input.mdzyj)) .WhereIF(!string.IsNullOrEmpty(input.dwyj), p => p.Dwyj.Equals(input.dwyj)) .WhereIF(!string.IsNullOrEmpty(input.zb), p => p.Zb.Equals(input.zb)) .WhereIF(!string.IsNullOrEmpty(input.xkyj), p => p.Xkyj.Equals(input.xkyj)) .WhereIF(!string.IsNullOrEmpty(input.xkcjl), p => p.Xkcjl.Equals(input.xkcjl)) .WhereIF(!string.IsNullOrEmpty(input.xktd), p => p.Xktd.Equals(input.xktd)) .WhereIF(!string.IsNullOrEmpty(input.sdyj), p => p.Sdyj.Equals(input.sdyj)) .WhereIF(!string.IsNullOrEmpty(input.sdtd), p => p.Sdtd.Equals(input.sdtd)) .WhereIF(!string.IsNullOrEmpty(input.syyj), p => p.Syyj.Equals(input.syyj)) .WhereIF(!string.IsNullOrEmpty(input.cellyj), p => p.Cellyj.Equals(input.cellyj)) .WhereIF(!string.IsNullOrEmpty(input.dxmybyj), p => p.Dxmybyj.Equals(input.dxmybyj)) .WhereIF(!string.IsNullOrEmpty(input.dxmebyj), p => p.Dxmebyj.Equals(input.dxmebyj)) .WhereIF(!string.IsNullOrEmpty(input.dyyj), p => p.Dyyj.Equals(input.dyyj)) .WhereIF(!string.IsNullOrEmpty(input.wysd), p => p.Wysd.Equals(input.wysd)) .WhereIF(!string.IsNullOrEmpty(input.mdzc), p => p.Mdzc.Equals(input.mdzc)) .WhereIF(!string.IsNullOrEmpty(input.cpwl), p => p.Cpwl.Equals(input.cpwl)) .WhereIF(!string.IsNullOrEmpty(input.wdcb), p => p.Wdcb.Equals(input.wdcb)) .WhereIF(!string.IsNullOrEmpty(input.qthzcb), p => p.Qthzcb.Equals(input.qthzcb)) .WhereIF(!string.IsNullOrEmpty(input.xmj), p => p.Xmj.Equals(input.xmj)) .WhereIF(!string.IsNullOrEmpty(input.ml), p => p.Ml.Equals(input.ml)) .WhereIF(!string.IsNullOrEmpty(input.zjltce), p => p.Zjltce.Equals(input.zjltce)) .WhereIF(!string.IsNullOrEmpty(input.jltce), p => p.Jltce.Equals(input.jltce)) .WhereIF(!string.IsNullOrEmpty(input.xh), p => p.Xh.Equals(input.xh)) .WhereIF(!string.IsNullOrEmpty(input.xms), p => p.Xms.Equals(input.xms)) .WhereIF(!string.IsNullOrEmpty(input.ddrt), p => p.Ddrt.Equals(input.ddrt)) .WhereIF(!string.IsNullOrEmpty(input.zdts), p => p.Zdts.Equals(input.zdts)) .WhereIF(!string.IsNullOrEmpty(input.qjts), p => p.Qjts.Equals(input.qjts)) .WhereIF(!string.IsNullOrEmpty(input.td), p => p.Td.Equals(input.td)) .WhereIF(!string.IsNullOrEmpty(input.jcyjtc), p => p.Jcyjtc.Equals(input.jcyjtc)) .WhereIF(!string.IsNullOrEmpty(input.hzyjtc), p => p.Hzyjtc.Equals(input.hzyjtc)) .WhereIF(!string.IsNullOrEmpty(input.gwtc), p => p.Gwtc.Equals(input.gwtc)) .WhereIF(!string.IsNullOrEmpty(input.mdtqtc), p => p.Mdtqtc.Equals(input.mdtqtc)) .WhereIF(!string.IsNullOrEmpty(input.dztc1), p => p.Dztc1.Equals(input.dztc1)) .WhereIF(!string.IsNullOrEmpty(input.dzzrtc), p => p.Dzzrtc.Equals(input.dzzrtc)) .WhereIF(!string.IsNullOrEmpty(input.zrtc), p => p.Zrtc.Equals(input.zrtc)) .WhereIF(!string.IsNullOrEmpty(input.dztc2), p => p.Dztc2.Equals(input.dztc2)) .WhereIF(!string.IsNullOrEmpty(input.zjltc), p => p.Zjltc.Equals(input.zjltc)) .WhereIF(!string.IsNullOrEmpty(input.jltc), p => p.Jltc.Equals(input.jltc)) .WhereIF(!string.IsNullOrEmpty(input.yjtc), p => p.Yjtc.Equals(input.yjtc)) .WhereIF(!string.IsNullOrEmpty(input.xhtc), p => p.Xhtc.Equals(input.xhtc)) .WhereIF(!string.IsNullOrEmpty(input.kjbzctc), p => p.Kjbzctc.Equals(input.kjbzctc)) .WhereIF(!string.IsNullOrEmpty(input.sytc), p => p.Sytc.Equals(input.sytc)) .WhereIF(!string.IsNullOrEmpty(input.celltc), p => p.Celltc.Equals(input.celltc)) .WhereIF(!string.IsNullOrEmpty(input.dxmbtc), p => p.Dxmbtc.Equals(input.dxmbtc)) .WhereIF(!string.IsNullOrEmpty(input.tchj), p => p.Tchj.Equals(input.tchj)) .WhereIF(!string.IsNullOrEmpty(input.jksdx), p => p.Jksdx.Equals(input.jksdx)) .WhereIF(!string.IsNullOrEmpty(input.dzhudx), p => p.Dzhudx.Equals(input.dzhudx)) .WhereIF(!string.IsNullOrEmpty(input.dzhangdx), p => p.Dzhangdx.Equals(input.dzhangdx)) .WhereIF(!string.IsNullOrEmpty(input.zrdx), p => p.Zrdx.Equals(input.zrdx)) .WhereIF(!string.IsNullOrEmpty(input.dzzrdx), p => p.Dzzrdx.Equals(input.dzzrdx)) .WhereIF(!string.IsNullOrEmpty(input.zjldx), p => p.Zjldx.Equals(input.zjldx)) .WhereIF(!string.IsNullOrEmpty(input.jldx), p => p.Jldx.Equals(input.jldx)) .WhereIF(!string.IsNullOrEmpty(input.kjblsdx), p => p.Kjblsdx.Equals(input.kjblsdx)) .WhereIF(!string.IsNullOrEmpty(input.dxmbdx), p => p.Dxmbdx.Equals(input.dxmbdx)) .WhereIF(!string.IsNullOrEmpty(input.dxhj), p => p.Dxhj.Equals(input.dxhj)) .WhereIF(!string.IsNullOrEmpty(input.sg), p => p.Sg.Equals(input.sg)) .WhereIF(!string.IsNullOrEmpty(input.rtjl), p => p.Rtjl.Equals(input.rtjl)) .WhereIF(!string.IsNullOrEmpty(input.sjgl), p => p.Sjgl.Equals(input.sjgl)) .WhereIF(!string.IsNullOrEmpty(input.cb), p => p.Cb.Equals(input.cb)) .WhereIF(!string.IsNullOrEmpty(input.sx), p => p.Sx.Equals(input.sx)) .WhereIF(!string.IsNullOrEmpty(input.qq), p => p.Qq.Equals(input.qq)) .WhereIF(!string.IsNullOrEmpty(input.hsyfgz), p => p.Hsyfgz.Equals(input.hsyfgz)) .WhereIF(!string.IsNullOrEmpty(input.bd), p => p.Bd.Equals(input.bd)) .WhereIF(!string.IsNullOrEmpty(input.bdqj), p => p.Bdqj.Equals(input.bdqj)) .WhereIF(!string.IsNullOrEmpty(input.bddx), p => p.Bddx.Equals(input.bddx)) .WhereIF(!string.IsNullOrEmpty(input.bdbc), p => p.Bdbc.Equals(input.bdbc)) .WhereIF(!string.IsNullOrEmpty(input.zzyfgz), p => p.Zzyfgz.Equals(input.zzyfgz)) .WhereIF(!string.IsNullOrEmpty(input.dypxbt), p => p.Dypxbt.Equals(input.dypxbt)) .WhereIF(!string.IsNullOrEmpty(input.dyjtbt), p => p.Dyjtbt.Equals(input.dyjtbt)) .WhereIF(!string.IsNullOrEmpty(input.sypxbt), p => p.Sypxbt.Equals(input.sypxbt)) .WhereIF(!string.IsNullOrEmpty(input.syjtbt), p => p.Syjtbt.Equals(input.syjtbt)) .WhereIF(!string.IsNullOrEmpty(input.bthj), p => p.Bthj.Equals(input.bthj)) .WhereIF(!string.IsNullOrEmpty(input.qk), p => p.Qk.Equals(input.qk)) .WhereIF(!string.IsNullOrEmpty(input.cd), p => p.Cd.Equals(input.cd)) .WhereIF(!string.IsNullOrEmpty(input.qj), p => p.Qj.Equals(input.qj)) .WhereIF(!string.IsNullOrEmpty(input.ksb), p => p.Ksb.Equals(input.ksb)) .WhereIF(!string.IsNullOrEmpty(input.kcjl), p => p.Kcjl.Equals(input.kcjl)) .WhereIF(!string.IsNullOrEmpty(input.kzs), p => p.Kzs.Equals(input.kzs)) .WhereIF(!string.IsNullOrEmpty(input.kxxq), p => p.Kxxq.Equals(input.kxxq)) .WhereIF(!string.IsNullOrEmpty(input.kgzf), p => p.Kgzf.Equals(input.kgzf)) .WhereIF(!string.IsNullOrEmpty(input.kkhj), p => p.Kkhj.Equals(input.kkhj)) .WhereIF(!string.IsNullOrEmpty(input.fjj), p => p.Fjj.Equals(input.fjj)) .WhereIF(!string.IsNullOrEmpty(input.tsjyj), p => p.Tsjyj.Equals(input.tsjyj)) .WhereIF(!string.IsNullOrEmpty(input.tzsyj), p => p.Tzsyj.Equals(input.tzsyj)) .WhereIF(!string.IsNullOrEmpty(input.sfgz), p => p.Sfgz.Equals(input.sfgz)) .WhereIF(!string.IsNullOrEmpty(input.dysfff), p => p.Dysfff.Contains(input.dysfff)) .WhereIF(!string.IsNullOrEmpty(input.zfje), p => p.Zfje.Equals(input.zfje)) .WhereIF(!string.IsNullOrEmpty(input.dzjfe), p => p.Dzjfe.Equals(input.dzjfe)) .WhereIF(!string.IsNullOrEmpty(input.bfsy), p => p.Bfsy.Equals(input.bfsy)) .WhereIF(!string.IsNullOrEmpty(input.dyzfze), p => p.Dyzfze.Equals(input.dyzfze)) .Select(it => new LqGzListOutput { id = it.Id, md = it.Md, hsgw = it.Hsgw, xm = it.Xm, jsjzd = it.Jsjzd, zyj = it.Zyj, jcyj = it.Jcyj, hzyj = it.Hzyj, jlyj = it.Jlyj, mdzyj = it.Mdzyj, dwyj = it.Dwyj, zb = it.Zb, xkyj = it.Xkyj, xkcjl = it.Xkcjl, xktd = it.Xktd, sdyj = it.Sdyj, sdtd = it.Sdtd, syyj = it.Syyj, cellyj = it.Cellyj, dxmybyj = it.Dxmybyj, dxmebyj = it.Dxmebyj, dyyj = it.Dyyj, wysd = it.Wysd, mdzc = it.Mdzc, cpwl = it.Cpwl, wdcb = it.Wdcb, qthzcb = it.Qthzcb, xmj = it.Xmj, ml = it.Ml, zjltce = it.Zjltce, jltce = it.Jltce, xh = it.Xh, xms = it.Xms, ddrt = it.Ddrt, zdts = it.Zdts, qjts = it.Qjts, td = it.Td, jcyjtc = it.Jcyjtc, hzyjtc = it.Hzyjtc, gwtc = it.Gwtc, mdtqtc = it.Mdtqtc, dztc1 = it.Dztc1, dzzrtc = it.Dzzrtc, zrtc = it.Zrtc, dztc2 = it.Dztc2, zjltc = it.Zjltc, jltc = it.Jltc, yjtc = it.Yjtc, xhtc = it.Xhtc, kjbzctc = it.Kjbzctc, sytc = it.Sytc, celltc = it.Celltc, dxmbtc = it.Dxmbtc, tchj = it.Tchj, jksdx = it.Jksdx, dzhudx = it.Dzhudx, dzhangdx = it.Dzhangdx, zrdx = it.Zrdx, dzzrdx = it.Dzzrdx, zjldx = it.Zjldx, jldx = it.Jldx, kjblsdx = it.Kjblsdx, dxmbdx = it.Dxmbdx, dxhj = it.Dxhj, sg = it.Sg, rtjl = it.Rtjl, sjgl = it.Sjgl, cb = it.Cb, sx = it.Sx, qq = it.Qq, hsyfgz = it.Hsyfgz, bd = it.Bd, bdqj = it.Bdqj, bddx = it.Bddx, bdbc = it.Bdbc, zzyfgz = it.Zzyfgz, dypxbt = it.Dypxbt, dyjtbt = it.Dyjtbt, sypxbt = it.Sypxbt, syjtbt = it.Syjtbt, bthj = it.Bthj, qk = it.Qk, cd = it.Cd, qj = it.Qj, ksb = it.Ksb, kcjl = it.Kcjl, kzs = it.Kzs, kxxq = it.Kxxq, kgzf = it.Kgzf, kkhj = it.Kkhj, fjj = it.Fjj, tsjyj = it.Tsjyj, tzsyj = it.Tzsyj, sfgz = it.Sfgz, dysfff = it.Dysfff, zfje = it.Zfje, dzjfe = it.Dzjfe, bfsy = it.Bfsy, dyzfze = it.Dyzfze, }) .MergeTable() .OrderBy(sidx + " " + input.sort) .ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(data); } #endregion #region 新建工资全字段 /// /// 新建工资全字段 /// /// 参数 /// [HttpPost("")] public async Task Create([FromBody] LqGzCrInput 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); } #endregion #region 获取工资全字段无分页列表 /// /// 获取工资全字段无分页列表 /// /// 请求参数 /// [NonAction] public async Task GetNoPagingList([FromQuery] LqGzListQueryInput 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.md), p => p.Md.Contains(input.md)) .WhereIF(!string.IsNullOrEmpty(input.hsgw), p => p.Hsgw.Contains(input.hsgw)) .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm)) .WhereIF(!string.IsNullOrEmpty(input.jsjzd), p => p.Jsjzd.Contains(input.jsjzd)) .WhereIF(!string.IsNullOrEmpty(input.zyj), p => p.Zyj.Equals(input.zyj)) .WhereIF(!string.IsNullOrEmpty(input.jcyj), p => p.Jcyj.Equals(input.jcyj)) .WhereIF(!string.IsNullOrEmpty(input.hzyj), p => p.Hzyj.Equals(input.hzyj)) .WhereIF(!string.IsNullOrEmpty(input.jlyj), p => p.Jlyj.Equals(input.jlyj)) .WhereIF(!string.IsNullOrEmpty(input.mdzyj), p => p.Mdzyj.Equals(input.mdzyj)) .WhereIF(!string.IsNullOrEmpty(input.dwyj), p => p.Dwyj.Equals(input.dwyj)) .WhereIF(!string.IsNullOrEmpty(input.zb), p => p.Zb.Equals(input.zb)) .WhereIF(!string.IsNullOrEmpty(input.xkyj), p => p.Xkyj.Equals(input.xkyj)) .WhereIF(!string.IsNullOrEmpty(input.xkcjl), p => p.Xkcjl.Equals(input.xkcjl)) .WhereIF(!string.IsNullOrEmpty(input.xktd), p => p.Xktd.Equals(input.xktd)) .WhereIF(!string.IsNullOrEmpty(input.sdyj), p => p.Sdyj.Equals(input.sdyj)) .WhereIF(!string.IsNullOrEmpty(input.sdtd), p => p.Sdtd.Equals(input.sdtd)) .WhereIF(!string.IsNullOrEmpty(input.syyj), p => p.Syyj.Equals(input.syyj)) .WhereIF(!string.IsNullOrEmpty(input.cellyj), p => p.Cellyj.Equals(input.cellyj)) .WhereIF(!string.IsNullOrEmpty(input.dxmybyj), p => p.Dxmybyj.Equals(input.dxmybyj)) .WhereIF(!string.IsNullOrEmpty(input.dxmebyj), p => p.Dxmebyj.Equals(input.dxmebyj)) .WhereIF(!string.IsNullOrEmpty(input.dyyj), p => p.Dyyj.Equals(input.dyyj)) .WhereIF(!string.IsNullOrEmpty(input.wysd), p => p.Wysd.Equals(input.wysd)) .WhereIF(!string.IsNullOrEmpty(input.mdzc), p => p.Mdzc.Equals(input.mdzc)) .WhereIF(!string.IsNullOrEmpty(input.cpwl), p => p.Cpwl.Equals(input.cpwl)) .WhereIF(!string.IsNullOrEmpty(input.wdcb), p => p.Wdcb.Equals(input.wdcb)) .WhereIF(!string.IsNullOrEmpty(input.qthzcb), p => p.Qthzcb.Equals(input.qthzcb)) .WhereIF(!string.IsNullOrEmpty(input.xmj), p => p.Xmj.Equals(input.xmj)) .WhereIF(!string.IsNullOrEmpty(input.ml), p => p.Ml.Equals(input.ml)) .WhereIF(!string.IsNullOrEmpty(input.zjltce), p => p.Zjltce.Equals(input.zjltce)) .WhereIF(!string.IsNullOrEmpty(input.jltce), p => p.Jltce.Equals(input.jltce)) .WhereIF(!string.IsNullOrEmpty(input.xh), p => p.Xh.Equals(input.xh)) .WhereIF(!string.IsNullOrEmpty(input.xms), p => p.Xms.Equals(input.xms)) .WhereIF(!string.IsNullOrEmpty(input.ddrt), p => p.Ddrt.Equals(input.ddrt)) .WhereIF(!string.IsNullOrEmpty(input.zdts), p => p.Zdts.Equals(input.zdts)) .WhereIF(!string.IsNullOrEmpty(input.qjts), p => p.Qjts.Equals(input.qjts)) .WhereIF(!string.IsNullOrEmpty(input.td), p => p.Td.Equals(input.td)) .WhereIF(!string.IsNullOrEmpty(input.jcyjtc), p => p.Jcyjtc.Equals(input.jcyjtc)) .WhereIF(!string.IsNullOrEmpty(input.hzyjtc), p => p.Hzyjtc.Equals(input.hzyjtc)) .WhereIF(!string.IsNullOrEmpty(input.gwtc), p => p.Gwtc.Equals(input.gwtc)) .WhereIF(!string.IsNullOrEmpty(input.mdtqtc), p => p.Mdtqtc.Equals(input.mdtqtc)) .WhereIF(!string.IsNullOrEmpty(input.dztc1), p => p.Dztc1.Equals(input.dztc1)) .WhereIF(!string.IsNullOrEmpty(input.dzzrtc), p => p.Dzzrtc.Equals(input.dzzrtc)) .WhereIF(!string.IsNullOrEmpty(input.zrtc), p => p.Zrtc.Equals(input.zrtc)) .WhereIF(!string.IsNullOrEmpty(input.dztc2), p => p.Dztc2.Equals(input.dztc2)) .WhereIF(!string.IsNullOrEmpty(input.zjltc), p => p.Zjltc.Equals(input.zjltc)) .WhereIF(!string.IsNullOrEmpty(input.jltc), p => p.Jltc.Equals(input.jltc)) .WhereIF(!string.IsNullOrEmpty(input.yjtc), p => p.Yjtc.Equals(input.yjtc)) .WhereIF(!string.IsNullOrEmpty(input.xhtc), p => p.Xhtc.Equals(input.xhtc)) .WhereIF(!string.IsNullOrEmpty(input.kjbzctc), p => p.Kjbzctc.Equals(input.kjbzctc)) .WhereIF(!string.IsNullOrEmpty(input.sytc), p => p.Sytc.Equals(input.sytc)) .WhereIF(!string.IsNullOrEmpty(input.celltc), p => p.Celltc.Equals(input.celltc)) .WhereIF(!string.IsNullOrEmpty(input.dxmbtc), p => p.Dxmbtc.Equals(input.dxmbtc)) .WhereIF(!string.IsNullOrEmpty(input.tchj), p => p.Tchj.Equals(input.tchj)) .WhereIF(!string.IsNullOrEmpty(input.jksdx), p => p.Jksdx.Equals(input.jksdx)) .WhereIF(!string.IsNullOrEmpty(input.dzhudx), p => p.Dzhudx.Equals(input.dzhudx)) .WhereIF(!string.IsNullOrEmpty(input.dzhangdx), p => p.Dzhangdx.Equals(input.dzhangdx)) .WhereIF(!string.IsNullOrEmpty(input.zrdx), p => p.Zrdx.Equals(input.zrdx)) .WhereIF(!string.IsNullOrEmpty(input.dzzrdx), p => p.Dzzrdx.Equals(input.dzzrdx)) .WhereIF(!string.IsNullOrEmpty(input.zjldx), p => p.Zjldx.Equals(input.zjldx)) .WhereIF(!string.IsNullOrEmpty(input.jldx), p => p.Jldx.Equals(input.jldx)) .WhereIF(!string.IsNullOrEmpty(input.kjblsdx), p => p.Kjblsdx.Equals(input.kjblsdx)) .WhereIF(!string.IsNullOrEmpty(input.dxmbdx), p => p.Dxmbdx.Equals(input.dxmbdx)) .WhereIF(!string.IsNullOrEmpty(input.dxhj), p => p.Dxhj.Equals(input.dxhj)) .WhereIF(!string.IsNullOrEmpty(input.sg), p => p.Sg.Equals(input.sg)) .WhereIF(!string.IsNullOrEmpty(input.rtjl), p => p.Rtjl.Equals(input.rtjl)) .WhereIF(!string.IsNullOrEmpty(input.sjgl), p => p.Sjgl.Equals(input.sjgl)) .WhereIF(!string.IsNullOrEmpty(input.cb), p => p.Cb.Equals(input.cb)) .WhereIF(!string.IsNullOrEmpty(input.sx), p => p.Sx.Equals(input.sx)) .WhereIF(!string.IsNullOrEmpty(input.qq), p => p.Qq.Equals(input.qq)) .WhereIF(!string.IsNullOrEmpty(input.hsyfgz), p => p.Hsyfgz.Equals(input.hsyfgz)) .WhereIF(!string.IsNullOrEmpty(input.bd), p => p.Bd.Equals(input.bd)) .WhereIF(!string.IsNullOrEmpty(input.bdqj), p => p.Bdqj.Equals(input.bdqj)) .WhereIF(!string.IsNullOrEmpty(input.bddx), p => p.Bddx.Equals(input.bddx)) .WhereIF(!string.IsNullOrEmpty(input.bdbc), p => p.Bdbc.Equals(input.bdbc)) .WhereIF(!string.IsNullOrEmpty(input.zzyfgz), p => p.Zzyfgz.Equals(input.zzyfgz)) .WhereIF(!string.IsNullOrEmpty(input.dypxbt), p => p.Dypxbt.Equals(input.dypxbt)) .WhereIF(!string.IsNullOrEmpty(input.dyjtbt), p => p.Dyjtbt.Equals(input.dyjtbt)) .WhereIF(!string.IsNullOrEmpty(input.sypxbt), p => p.Sypxbt.Equals(input.sypxbt)) .WhereIF(!string.IsNullOrEmpty(input.syjtbt), p => p.Syjtbt.Equals(input.syjtbt)) .WhereIF(!string.IsNullOrEmpty(input.bthj), p => p.Bthj.Equals(input.bthj)) .WhereIF(!string.IsNullOrEmpty(input.qk), p => p.Qk.Equals(input.qk)) .WhereIF(!string.IsNullOrEmpty(input.cd), p => p.Cd.Equals(input.cd)) .WhereIF(!string.IsNullOrEmpty(input.qj), p => p.Qj.Equals(input.qj)) .WhereIF(!string.IsNullOrEmpty(input.ksb), p => p.Ksb.Equals(input.ksb)) .WhereIF(!string.IsNullOrEmpty(input.kcjl), p => p.Kcjl.Equals(input.kcjl)) .WhereIF(!string.IsNullOrEmpty(input.kzs), p => p.Kzs.Equals(input.kzs)) .WhereIF(!string.IsNullOrEmpty(input.kxxq), p => p.Kxxq.Equals(input.kxxq)) .WhereIF(!string.IsNullOrEmpty(input.kgzf), p => p.Kgzf.Equals(input.kgzf)) .WhereIF(!string.IsNullOrEmpty(input.kkhj), p => p.Kkhj.Equals(input.kkhj)) .WhereIF(!string.IsNullOrEmpty(input.fjj), p => p.Fjj.Equals(input.fjj)) .WhereIF(!string.IsNullOrEmpty(input.tsjyj), p => p.Tsjyj.Equals(input.tsjyj)) .WhereIF(!string.IsNullOrEmpty(input.tzsyj), p => p.Tzsyj.Equals(input.tzsyj)) .WhereIF(!string.IsNullOrEmpty(input.sfgz), p => p.Sfgz.Equals(input.sfgz)) .WhereIF(!string.IsNullOrEmpty(input.dysfff), p => p.Dysfff.Contains(input.dysfff)) .WhereIF(!string.IsNullOrEmpty(input.zfje), p => p.Zfje.Equals(input.zfje)) .WhereIF(!string.IsNullOrEmpty(input.dzjfe), p => p.Dzjfe.Equals(input.dzjfe)) .WhereIF(!string.IsNullOrEmpty(input.bfsy), p => p.Bfsy.Equals(input.bfsy)) .WhereIF(!string.IsNullOrEmpty(input.dyzfze), p => p.Dyzfze.Equals(input.dyzfze)) .Select(it => new LqGzListOutput { id = it.Id, md = it.Md, hsgw = it.Hsgw, xm = it.Xm, jsjzd = it.Jsjzd, zyj = it.Zyj, jcyj = it.Jcyj, hzyj = it.Hzyj, jlyj = it.Jlyj, mdzyj = it.Mdzyj, dwyj = it.Dwyj, zb = it.Zb, xkyj = it.Xkyj, xkcjl = it.Xkcjl, xktd = it.Xktd, sdyj = it.Sdyj, sdtd = it.Sdtd, syyj = it.Syyj, cellyj = it.Cellyj, dxmybyj = it.Dxmybyj, dxmebyj = it.Dxmebyj, dyyj = it.Dyyj, wysd = it.Wysd, mdzc = it.Mdzc, cpwl = it.Cpwl, wdcb = it.Wdcb, qthzcb = it.Qthzcb, xmj = it.Xmj, ml = it.Ml, zjltce = it.Zjltce, jltce = it.Jltce, xh = it.Xh, xms = it.Xms, ddrt = it.Ddrt, zdts = it.Zdts, qjts = it.Qjts, td = it.Td, jcyjtc = it.Jcyjtc, hzyjtc = it.Hzyjtc, gwtc = it.Gwtc, mdtqtc = it.Mdtqtc, dztc1 = it.Dztc1, dzzrtc = it.Dzzrtc, zrtc = it.Zrtc, dztc2 = it.Dztc2, zjltc = it.Zjltc, jltc = it.Jltc, yjtc = it.Yjtc, xhtc = it.Xhtc, kjbzctc = it.Kjbzctc, sytc = it.Sytc, celltc = it.Celltc, dxmbtc = it.Dxmbtc, tchj = it.Tchj, jksdx = it.Jksdx, dzhudx = it.Dzhudx, dzhangdx = it.Dzhangdx, zrdx = it.Zrdx, dzzrdx = it.Dzzrdx, zjldx = it.Zjldx, jldx = it.Jldx, kjblsdx = it.Kjblsdx, dxmbdx = it.Dxmbdx, dxhj = it.Dxhj, sg = it.Sg, rtjl = it.Rtjl, sjgl = it.Sjgl, cb = it.Cb, sx = it.Sx, qq = it.Qq, hsyfgz = it.Hsyfgz, bd = it.Bd, bdqj = it.Bdqj, bddx = it.Bddx, bdbc = it.Bdbc, zzyfgz = it.Zzyfgz, dypxbt = it.Dypxbt, dyjtbt = it.Dyjtbt, sypxbt = it.Sypxbt, syjtbt = it.Syjtbt, bthj = it.Bthj, qk = it.Qk, cd = it.Cd, qj = it.Qj, ksb = it.Ksb, kcjl = it.Kcjl, kzs = it.Kzs, kxxq = it.Kxxq, kgzf = it.Kgzf, kkhj = it.Kkhj, fjj = it.Fjj, tsjyj = it.Tsjyj, tzsyj = it.Tzsyj, sfgz = it.Sfgz, dysfff = it.Dysfff, zfje = it.Zfje, dzjfe = it.Dzjfe, bfsy = it.Bfsy, dyzfze = it.Dyzfze, }) .MergeTable() .OrderBy(sidx + " " + input.sort) .ToListAsync(); return data; } #endregion #region 导出工资全字段 /// /// 导出工资全字段 /// /// 请求参数 /// [HttpGet("Actions/Export")] public async Task Export([FromQuery] LqGzListQueryInput 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\":\"hsgw\"},{\"value\":\"姓名\",\"field\":\"xm\"},{\"value\":\"金山角战队\",\"field\":\"jsjzd\"},{\"value\":\"基础业绩\",\"field\":\"jcyj\"},{\"value\":\"合作业绩\",\"field\":\"hzyj\"},{\"value\":\"奖励业绩\",\"field\":\"jlyj\"},{\"value\":\"门店总业绩\",\"field\":\"mdzyj\"},{\"value\":\"队伍业绩\",\"field\":\"dwyj\"},{\"value\":\"占比\",\"field\":\"zb\"},{\"value\":\"新客业绩\",\"field\":\"xkyj\"},{\"value\":\"新客成交率\",\"field\":\"xkcjl\"},{\"value\":\"新客提点\",\"field\":\"xktd\"},{\"value\":\"升单业绩\",\"field\":\"sdyj\"},{\"value\":\"升单提点\",\"field\":\"sdtd\"},{\"value\":\"溯源业绩\",\"field\":\"syyj\"},{\"value\":\"cell业绩\",\"field\":\"cellyj\"},{\"value\":\"项目一部业绩\",\"field\":\"dxmybyj\"},{\"value\":\"项目二部业绩\",\"field\":\"dxmebyj\"},{\"value\":\"当月业绩\",\"field\":\"dyyj\"},{\"value\":\"物业水电\",\"field\":\"wysd\"},{\"value\":\"门店支出\",\"field\":\"mdzc\"},{\"value\":\"产品物料\",\"field\":\"cpwl\"},{\"value\":\"微雕成本\",\"field\":\"wdcb\"},{\"value\":\"其它合作成本\",\"field\":\"qthzcb\"},{\"value\":\"洗毛巾\",\"field\":\"xmj\"},{\"value\":\"毛利\",\"field\":\"ml\"},{\"value\":\"总经理提成额\",\"field\":\"zjltce\"},{\"value\":\"经理提成额\",\"field\":\"jltce\"},{\"value\":\"消耗\",\"field\":\"xh\"},{\"value\":\"项目数\",\"field\":\"xms\"},{\"value\":\"到店人头\",\"field\":\"ddrt\"},{\"value\":\"在店天数\",\"field\":\"zdts\"},{\"value\":\"请假天数\",\"field\":\"qjts\"},{\"value\":\"提点\",\"field\":\"td\"},{\"value\":\"基础业绩提成\",\"field\":\"jcyjtc\"},{\"value\":\"合作业绩提成\",\"field\":\"hzyjtc\"},{\"value\":\"顾问提成\",\"field\":\"gwtc\"},{\"value\":\"门店T区提成\",\"field\":\"mdtqtc\"},{\"value\":\"店助提成\",\"field\":\"dztc1\"},{\"value\":\"店助主任提成\",\"field\":\"dzzrtc\"},{\"value\":\"主任提成\",\"field\":\"zrtc\"},{\"value\":\"店长提成\",\"field\":\"dztc2\"},{\"value\":\"总经理提成\",\"field\":\"zjltc\"},{\"value\":\"经理提成\",\"field\":\"jltc\"},{\"value\":\"业绩提成\",\"field\":\"yjtc\"},{\"value\":\"消耗提成\",\"field\":\"xhtc\"},{\"value\":\"科技部组长提成\",\"field\":\"kjbzctc\"},{\"value\":\"溯源提成\",\"field\":\"sytc\"},{\"value\":\"cell提成\",\"field\":\"celltc\"},{\"value\":\"大项目部提成\",\"field\":\"dxmbtc\"},{\"value\":\"提成合计\",\"field\":\"tchj\"},{\"value\":\"健康师底薪\",\"field\":\"jksdx\"},{\"value\":\"店助底薪\",\"field\":\"dzhudx\"},{\"value\":\"店长底薪\",\"field\":\"dzhangdx\"},{\"value\":\"主任底薪\",\"field\":\"zrdx\"},{\"value\":\"店助主任底薪\",\"field\":\"dzzrdx\"},{\"value\":\"总经理底薪\",\"field\":\"zjldx\"},{\"value\":\"经理底薪\",\"field\":\"jldx\"},{\"value\":\"科技部底薪\",\"field\":\"kjblsdx\"},{\"value\":\"大项目部底薪\",\"field\":\"dxmbdx\"},{\"value\":\"底薪合计\",\"field\":\"dxhj\"},{\"value\":\"手工\",\"field\":\"sg\"},{\"value\":\"人头奖励\",\"field\":\"rtjl\"},{\"value\":\"手机管理\",\"field\":\"sjgl\"},{\"value\":\"车补\",\"field\":\"cb\"},{\"value\":\"少休\",\"field\":\"sx\"},{\"value\":\"全勤\",\"field\":\"qq\"},{\"value\":\"核算应发工资\",\"field\":\"hsyfgz\"},{\"value\":\"保底\",\"field\":\"bd\"},{\"value\":\"保底请假\",\"field\":\"bdqj\"},{\"value\":\"保底底薪\",\"field\":\"bddx\"},{\"value\":\"保底补差\",\"field\":\"bdbc\"},{\"value\":\"最终应发工资\",\"field\":\"zzyfgz\"},{\"value\":\"当月培训补贴\",\"field\":\"dypxbt\"},{\"value\":\"当月交通补贴\",\"field\":\"dyjtbt\"},{\"value\":\"上月培训补贴\",\"field\":\"sypxbt\"},{\"value\":\"上月交通补贴\",\"field\":\"syjtbt\"},{\"value\":\"补贴合计\",\"field\":\"bthj\"},{\"value\":\"缺卡\",\"field\":\"qk\"},{\"value\":\"迟到\",\"field\":\"cd\"},{\"value\":\"请假\",\"field\":\"qj\"},{\"value\":\"扣社保\",\"field\":\"ksb\"},{\"value\":\"扣除奖励\",\"field\":\"kcjl\"},{\"value\":\"扣住宿\",\"field\":\"kzs\"},{\"value\":\"扣学习期\",\"field\":\"kxxq\"},{\"value\":\"扣工作服\",\"field\":\"kgzf\"},{\"value\":\"扣款合计\",\"field\":\"kkhj\"},{\"value\":\"发奖金\",\"field\":\"fjj\"},{\"value\":\"退手机押金\",\"field\":\"tsjyj\"},{\"value\":\"退住宿押金\",\"field\":\"tzsyj\"},{\"value\":\"实发工资\",\"field\":\"sfgz\"},{\"value\":\"当月是否发放\",\"field\":\"dysfff\"},{\"value\":\"支付金额\",\"field\":\"zfje\"},{\"value\":\"待支付金额\",\"field\":\"dzjfe\"},{\"value\":\"补发上月\",\"field\":\"bfsy\"},{\"value\":\"当月支付总额\",\"field\":\"dyzfze\"},{\"value\":\"总业绩\",\"field\":\"zyj\"},]".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; } #endregion #region 批量删除工资全字段 /// /// 批量删除工资全字段 /// /// 主键数组 /// [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); } } } #endregion #region 更新工资全字段 /// /// 更新工资全字段 /// /// 主键 /// 参数 /// [HttpPut("{id}")] public async Task Update(string id, [FromBody] LqGzUpInput input) { var entity = input.Adapt(); var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001); } #endregion #region 删除工资全字段 /// /// 删除工资全字段 /// /// [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); } #endregion #region 业绩计算相关方法 /// /// 计算个人业绩数据 /// /// /// 根据薪酬规则计算个人的基础业绩、合作业绩、奖励业绩、门店总业绩、队伍业绩等 /// /// 计算逻辑: /// 1. 基础业绩:从开单品项明细表中统计,基于项目资料中的基础服务提成 /// 2. 合作业绩:从开单品项明细表中统计,基于项目资料中的合作项目设置 /// 3. 奖励业绩:从奖励明细表中统计 /// 4. 门店总业绩:该员工所在门店的所有业绩总和 /// 5. 队伍业绩:该员工所在金三角战队的所有业绩总和 /// /// 示例请求: /// ```json /// { /// "employeeId": "员工ID", /// "storeId": "门店ID", /// "calculationMonth": "2025-01" /// } /// ``` /// /// 参数说明: /// - employeeId: 员工ID(必填) /// - storeId: 门店ID(必填) /// - calculationMonth: 计算月份,格式:YYYYMM(必填) /// /// 业绩计算输入参数 /// 业绩计算结果 /// 成功返回业绩计算结果 /// 参数错误或数据不存在 /// 服务器内部错误 [HttpPost("CalculatePerformance")] public async Task CalculatePerformance([FromBody] PerformanceCalculationInput input) { try { _logger.LogInformation($"开始计算员工业绩 - 员工ID: {input.EmployeeId}, 门店ID: {input.StoreId}, 月份: {input.CalculationMonth}"); var result = new PerformanceCalculationOutput { EmployeeId = input.EmployeeId, StoreId = input.StoreId, CalculationMonth = input.CalculationMonth, }; // 1. 计算基础业绩 result.BasicPerformance = await CalculateBasicPerformance(input.EmployeeId, input.StoreId, input.CalculationMonth); // 2. 计算合作业绩 result.CooperationPerformance = await CalculateCooperationPerformance(input.EmployeeId, input.StoreId, input.CalculationMonth); // 3. 计算奖励业绩 result.RewardPerformance = await CalculateRewardPerformance(input.EmployeeId, input.StoreId, input.CalculationMonth); // 4. 计算总业绩 result.TotalPerformance = result.BasicPerformance + result.CooperationPerformance + result.RewardPerformance; // 5. 计算门店总业绩 result.StoreTotalPerformance = await CalculateStoreTotalPerformance(input.StoreId, input.CalculationMonth); // 6. 计算队伍业绩 result.TeamPerformance = await CalculateTeamPerformance(input.EmployeeId, input.StoreId, input.CalculationMonth); // 7. 计算占比 result.PerformanceRatio = result.StoreTotalPerformance > 0 ? Math.Round(result.TotalPerformance / result.StoreTotalPerformance * 100, 2) : 0; _logger.LogInformation($"业绩计算完成 - 员工ID: {input.EmployeeId}, 总业绩: {result.TotalPerformance}, 门店总业绩: {result.StoreTotalPerformance}"); return result; } catch (Exception ex) { _logger.LogError(ex, $"计算员工业绩失败 - 员工ID: {input.EmployeeId}, 门店ID: {input.StoreId}"); throw NCCException.Oh(ErrorCode.COM1005, "业绩计算失败"); } } /// /// 计算基础业绩 /// private async Task CalculateBasicPerformance(string employeeId, string storeId, string calculationMonth) { var startDate = DateTime.Parse($"{calculationMonth}-01"); var endDate = startDate.AddMonths(1).AddDays(-1); // 从开单品项明细表中统计基础业绩 var basicPerformance = await _db.Queryable() .LeftJoin((px, xm) => px.Px == xm.Xmbh) .LeftJoin((px, xm, kd) => px.Glkdbh == kd.Id) .Where((px, xm, kd) => kd.Djmd == storeId && kd.Kdrq >= startDate && kd.Kdrq <= endDate && (px.Px == employeeId || px.Px.Contains(employeeId))) // 根据实际情况调整匹配条件 .SumAsync((px, xm, kd) => px.Pxjg * xm.Jcfwtc / 100); return basicPerformance; } /// /// 计算合作业绩 /// private async Task CalculateCooperationPerformance(string employeeId, string storeId, string calculationMonth) { var startDate = DateTime.Parse($"{calculationMonth}-01"); var endDate = startDate.AddMonths(1).AddDays(-1); // 从开单品项明细表中统计合作业绩 var cooperationPerformance = await _db.Queryable() .LeftJoin((px, xm) => px.Px == xm.Xmbh) .LeftJoin((px, xm, kd) => px.Glkdbh == kd.Id) .Where( (px, xm, kd) => kd.Djmd == storeId && kd.Kdrq >= startDate && kd.Kdrq <= endDate && kd.Hgjg != null && kd.Hgjg != "" && // 有合作机构 (px.Px == employeeId || px.Px.Contains(employeeId)) ) .SumAsync((px, xm, kd) => px.Pxjg * 0.65m); // 合作业绩按65%计算 return cooperationPerformance; } /// /// 计算奖励业绩 /// private async Task CalculateRewardPerformance(string employeeId, string storeId, string calculationMonth) { // 从奖励明细表中统计奖励业绩 var rewardPerformance = await _db.Queryable() .Where(jl => jl.Mdbh == storeId && jl.Jks == employeeId && jl.Hj != null && jl.Hj != "") .SumAsync(jl => Convert.ToDecimal(jl.Hj)); return rewardPerformance; } /// /// 计算门店总业绩 /// private async Task CalculateStoreTotalPerformance(string storeId, string calculationMonth) { var startDate = DateTime.Parse($"{calculationMonth}-01"); var endDate = startDate.AddMonths(1).AddDays(-1); // 从开单记录表中统计门店总业绩 var storeTotalPerformance = await _db.Queryable().Where(kd => kd.Djmd == storeId && kd.Kdrq >= startDate && kd.Kdrq <= endDate).SumAsync(kd => kd.Zdyj); return storeTotalPerformance; } /// /// 计算队伍业绩 /// private async Task CalculateTeamPerformance(string employeeId, string storeId, string calculationMonth) { // 先获取员工所在的金三角战队 var goldenTriangle = await _db.Queryable().Where(jsj => jsj.Md == storeId && jsj.Yf == calculationMonth && jsj.Jsj.Contains(employeeId)).FirstAsync(); if (goldenTriangle == null) { return 0; // 没有加入金三角战队 } var startDate = DateTime.Parse($"{calculationMonth}-01"); var endDate = startDate.AddMonths(1).AddDays(-1); // 统计该战队所有成员的业绩 var teamPerformance = await _db.Queryable() .Where(kd => kd.Djmd == storeId && kd.Kdrq >= startDate && kd.Kdrq <= endDate && goldenTriangle.Jsj.Contains(kd.Jsj)) .SumAsync(kd => kd.Zdyj); return teamPerformance; } /// /// 批量更新工资表中的业绩数据 /// /// /// 批量更新指定月份所有员工的业绩数据 /// /// 示例请求: /// ```json /// { /// "calculationMonth": "2025-01", /// "storeIds": ["门店ID1", "门店ID2"] /// } /// ``` /// /// 参数说明: /// - calculationMonth: 计算月份,格式:YYYYMM(必填) /// - storeIds: 门店ID列表(可选,为空则更新所有门店) /// /// 批量更新参数 /// 更新结果 /// 成功更新业绩数据 /// 参数错误 /// 服务器内部错误 [HttpPost("BatchUpdatePerformance")] public async Task BatchUpdatePerformance([FromBody] BatchUpdatePerformanceInput input) { try { _logger.LogInformation($"开始批量更新业绩数据 - 月份: {input.CalculationMonth}"); var updatedCount = 0; var errorCount = 0; // 获取需要更新的工资记录 var salaryRecords = await _db.Queryable().WhereIF(input.StoreIds != null && input.StoreIds.Any(), gz => input.StoreIds.Contains(gz.Md)).ToListAsync(); foreach (var record in salaryRecords) { try { // 计算该员工的业绩数据 var performanceInput = new PerformanceCalculationInput { EmployeeId = record.Xm, // 使用姓名作为员工标识 StoreId = record.Md, CalculationMonth = input.CalculationMonth, }; var performance = await CalculatePerformance(performanceInput); // 更新工资记录 record.Jcyj = performance.BasicPerformance; record.Hzyj = performance.CooperationPerformance; record.Jlyj = performance.RewardPerformance; record.Zyj = performance.TotalPerformance; record.Mdzyj = performance.StoreTotalPerformance; record.Dwyj = performance.TeamPerformance; record.Zb = performance.PerformanceRatio; await _db.Updateable(record) .UpdateColumns(gz => new { gz.Jcyj, gz.Hzyj, gz.Jlyj, gz.Zyj, gz.Mdzyj, gz.Dwyj, gz.Zb, }) .ExecuteCommandAsync(); updatedCount++; } catch (Exception ex) { _logger.LogError(ex, $"更新员工业绩失败 - 员工: {record.Xm}, 门店: {record.Md}"); errorCount++; } } _logger.LogInformation($"批量更新业绩数据完成 - 成功: {updatedCount}, 失败: {errorCount}"); return new { Success = true, UpdatedCount = updatedCount, ErrorCount = errorCount, Message = $"成功更新 {updatedCount} 条记录,失败 {errorCount} 条记录", }; } catch (Exception ex) { _logger.LogError(ex, $"批量更新业绩数据失败 - 月份: {input.CalculationMonth}"); throw NCCException.Oh(ErrorCode.COM1005, "批量更新业绩数据失败"); } } #endregion } }