using F9WebAiTest.Application.Common; using F9WebAiTest.Application.Dtos.PayRoll; using F9WebAiTest.Domain.Common; using F9WebAiTest.Domain.Entities.Base; using F9WebAiTest.Domain.Entities.PayRoll; using SysDept = F9WebAiTest.Domain.Entities.SYS.Departments; using SysWt = F9WebAiTest.Domain.Entities.SYS.WorkTypes; namespace F9WebAiTest.Application.Services.PayRoll; // 薪资计算依赖的 5 套配置(对应 F9 PAYROLL 下的 CONFGYZK / CONFGZ / CONFDCG / DCXDJK / XinZiJiaGePeiZhi) // ==================== 薪资配置-工艺庄口 ==================== public interface IConfGyzkService { Task> GetListAsync(int? year, int? month); Task GetForEditAsync(long id); Task SaveAsync(ConfGyzkSaveDto dto); Task DeleteAsync(long id); } public class ConfGyzkService : IConfGyzkService { private readonly IRepository _repo; private readonly IRepository _zkRepo; public ConfGyzkService(IRepository repo, IRepository zkRepo) { _repo = repo; _zkRepo = zkRepo; } public async Task> GetListAsync(int? year, int? month) { var all = await _repo.GetAllAsync(); var q = all.AsQueryable(); if (year.HasValue) q = q.Where(x => x.Year == year.Value); if (month.HasValue) q = q.Where(x => x.Month == month.Value); var items = q.OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).ThenBy(x => x.GyzkId).ToList(); var zks = await _zkRepo.GetAllAsync(); var zkDict = zks.ToDictionary(z => z.Id, z => z.ZhuangKouName); return items.Select(x => new ConfGyzkListItemDto { Id = x.Id, Year = x.Year, Month = x.Month, GyzkId = x.GyzkId, GyzkName = zkDict.GetValueOrDefault(x.GyzkId, ""), Guige = x.Guige, QsTaichan = x.QsTaichan, QsDengji = x.QsDengji, QsDengjifen = x.QsDengjifen, SaoZhe = x.SaoZhe, MeiTongJianLiang = x.MeiTongJianLiang, LuoSiTongShu = x.LuoSiTongShu, MeiCheSiLiang = x.MeiCheSiLiang, DcgJijianXishu = x.DcgJijianXishu, CtgJijianXishu = x.CtgJijianXishu, GyzkLtwxKs = x.GyzkLtwxKs, GyzkLtwxl = x.GyzkLtwxl, XjChanliangPrice = x.XjChanliangPrice }).ToList(); } public async Task GetForEditAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("工艺庄口薪资配置不存在或已删除", 404); return new ConfGyzkSaveDto { Id = e.Id, Year = e.Year, Month = e.Month, GyzkId = e.GyzkId, Guige = e.Guige, QsTaichan = e.QsTaichan, QsDengji = e.QsDengji, QsDengjifen = e.QsDengjifen, SaoZhe = e.SaoZhe, MeiTongJianLiang = e.MeiTongJianLiang, LuoSiTongShu = e.LuoSiTongShu, MeiCheSiLiang = e.MeiCheSiLiang, DcgJijianXishu = e.DcgJijianXishu, CtgJijianXishu = e.CtgJijianXishu, GyzkLtwxKs = e.GyzkLtwxKs, GyzkLtwxl = e.GyzkLtwxl, XjChanliangPrice = e.XjChanliangPrice }; } public async Task SaveAsync(ConfGyzkSaveDto dto) { if (dto.GyzkId == 0) throw new ServiceException("请选择工艺庄口"); if (dto.Year <= 0 || dto.Month <= 0) throw new ServiceException("年度/月份无效"); ConfGyzk e; if (dto.Id > 0) { e = await _repo.GetByIdAsync(dto.Id); if (e == null) throw new ServiceException("工艺庄口薪资配置不存在或已删除", 404); var dup = await _repo.FirstOrDefaultAsync(x => x.Id != dto.Id && x.Year == dto.Year && x.Month == dto.Month && x.GyzkId == dto.GyzkId); if (dup != null) throw new ServiceException("该年度月份已存在此庄口的配置!"); } else { var dup = await _repo.AnyAsync(x => x.Year == dto.Year && x.Month == dto.Month && x.GyzkId == dto.GyzkId); if (dup) throw new ServiceException("该年度月份已存在此庄口的配置!"); e = new ConfGyzk(); await _repo.AddAsync(e); } e.Year = dto.Year; e.Month = dto.Month; e.GyzkId = dto.GyzkId; e.Guige = dto.Guige ?? ""; e.QsTaichan = dto.QsTaichan; e.QsDengji = dto.QsDengji ?? ""; e.QsDengjifen = dto.QsDengjifen; e.SaoZhe = dto.SaoZhe; e.MeiTongJianLiang = dto.MeiTongJianLiang; e.LuoSiTongShu = dto.LuoSiTongShu; e.MeiCheSiLiang = dto.MeiCheSiLiang; e.DcgJijianXishu = dto.DcgJijianXishu; e.CtgJijianXishu = dto.CtgJijianXishu; e.GyzkLtwxKs = dto.GyzkLtwxKs; e.GyzkLtwxl = dto.GyzkLtwxl; e.XjChanliangPrice = dto.XjChanliangPrice; await _repo.UpdateAsync(e); return e.Id; } public async Task DeleteAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("工艺庄口薪资配置不存在或已删除", 404); await _repo.HardDeleteAsync(e); } } // ==================== 薪资配置-工种 ==================== public interface IConfGzService { Task> GetListAsync(); Task GetForEditAsync(long id); Task SaveAsync(ConfGzSaveDto dto); Task DeleteAsync(long id); } public class ConfGzService : IConfGzService { private readonly IRepository _repo; private readonly IRepository _wtRepo; public ConfGzService(IRepository repo, IRepository wtRepo) { _repo = repo; _wtRepo = wtRepo; } public async Task> GetListAsync() { var items = await _repo.GetAllAsync(); var wts = await _wtRepo.GetAllAsync(); var wtDict = wts.ToDictionary(w => w.Id, w => w.WorkName); return items.Select(x => ToDto(x, wtDict)).ToList(); } public async Task GetForEditAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("工种薪资配置不存在或已删除", 404); return FromEntity(e); } public async Task SaveAsync(ConfGzSaveDto dto) { if (dto.WorkTypeId == 0) throw new ServiceException("请选择工种"); ConfGz e; if (dto.Id > 0) { e = await _repo.GetByIdAsync(dto.Id); if (e == null) throw new ServiceException("工种薪资配置不存在或已删除", 404); var dup = await _repo.FirstOrDefaultAsync(x => x.Id != dto.Id && x.WorkTypeId == dto.WorkTypeId); if (dup != null) throw new ServiceException("该工种已存在薪资配置!"); } else { var dup = await _repo.AnyAsync(x => x.WorkTypeId == dto.WorkTypeId); if (dup) throw new ServiceException("该工种已存在薪资配置!"); e = new ConfGz(); await _repo.AddAsync(e); } Apply(e, dto); await _repo.UpdateAsync(e); return e.Id; } public async Task DeleteAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("工种薪资配置不存在或已删除", 404); await _repo.HardDeleteAsync(e); } private static ConfGzListItemDto ToDto(ConfGz x, Dictionary wtDict) => new() { Id = x.Id, WorkTypeId = x.WorkTypeId, WorkTypeName = wtDict.GetValueOrDefault(x.WorkTypeId, ""), HoursPerday = x.HoursPerday, QqDaysStandard = x.QqDaysStandard, QqHoursMaxQj = x.QqHoursMaxQj, QqHoursDkMinjiaban = x.QqHoursDkMinjiaban, QqHoursDkQingjia = x.QqHoursDkQingjia, XgJineQuanqin = x.XgJineQuanqin, XgJineGangwei = x.XgJineGangwei, JineNiangong = x.JineNiangong, JineQuanqin = x.JineQuanqin, JineGangwei = x.JineGangwei, JineYuekhJixiao = x.JineYuekhJixiao, JineGwkh = x.JineGwkh, JineYueticheng = x.JineYueticheng, JineJtkhYear = x.JineJtkhYear, JineJisuanjishu = x.JineJisuanjishu, JineYeban = x.JineYeban, JineJiaotongButie = x.JineJiaotongButie, LiudongJineGuding = x.LiudongJineGuding, JiaqiJineKuangongKk = x.JiaqiJineKuangongKk, JiaqiJineFadingGz = x.JiaqiJineFadingGz, JiaqiJineFadingBz = x.JiaqiJineFadingBz, JiaqiJineHunjiaBz = x.JiaqiJineHunjiaBz, JiaqiJineSangjiaBz = x.JiaqiJineSangjiaBz, JiaqiJineBingjiaBz = x.JiaqiJineBingjiaBz, JiaqiJineLunxiuBz = x.JiaqiJineLunxiuBz, JiabanJineBz = x.JiabanJineBz, Jiaqi_Jine_TiaoxiuBz = x.Jiaqi_Jine_TiaoxiuBz, Jiaqi_Jine_NianjiaBz = x.Jiaqi_Jine_NianjiaBz, GwsrkhJineQianhege = x.GwsrkhJineQianhege, GwsrkhJineQiwang = x.GwsrkhJineQiwang, GwsrkhJineHege = x.GwsrkhJineHege, GwsrkhJineShengren = x.GwsrkhJineShengren, GwsrkhJineChaoshengren = x.GwsrkhJineChaoshengren, Jiaban_GwsrkhJineQianhege = x.Jiaban_GwsrkhJineQianhege, Jiaban_GwsrkhJineQiwang = x.Jiaban_GwsrkhJineQiwang, Jiaban_GwsrkhJineHege = x.Jiaban_GwsrkhJineHege, Jiaban_GwsrkhJineShengren = x.Jiaban_GwsrkhJineShengren, Jiaban_GwsrkhJineChaoshengren = x.Jiaban_GwsrkhJineChaoshengren }; private static ConfGzSaveDto FromEntity(ConfGz x) => new() { Id = x.Id, WorkTypeId = x.WorkTypeId, HoursPerday = x.HoursPerday, QqDaysStandard = x.QqDaysStandard, QqHoursMaxQj = x.QqHoursMaxQj, QqHoursDkMinjiaban = x.QqHoursDkMinjiaban, QqHoursDkQingjia = x.QqHoursDkQingjia, XgJineQuanqin = x.XgJineQuanqin, XgJineGangwei = x.XgJineGangwei, JineNiangong = x.JineNiangong, JineQuanqin = x.JineQuanqin, JineGangwei = x.JineGangwei, JineYuekhJixiao = x.JineYuekhJixiao, JineGwkh = x.JineGwkh, JineYueticheng = x.JineYueticheng, JineJtkhYear = x.JineJtkhYear, JineJisuanjishu = x.JineJisuanjishu, JineYeban = x.JineYeban, JineJiaotongButie = x.JineJiaotongButie, LiudongJineGuding = x.LiudongJineGuding, JiaqiJineKuangongKk = x.JiaqiJineKuangongKk, JiaqiJineFadingGz = x.JiaqiJineFadingGz, JiaqiJineFadingBz = x.JiaqiJineFadingBz, JiaqiJineHunjiaBz = x.JiaqiJineHunjiaBz, JiaqiJineSangjiaBz = x.JiaqiJineSangjiaBz, JiaqiJineBingjiaBz = x.JiaqiJineBingjiaBz, JiaqiJineLunxiuBz = x.JiaqiJineLunxiuBz, JiabanJineBz = x.JiabanJineBz, Jiaqi_Jine_TiaoxiuBz = x.Jiaqi_Jine_TiaoxiuBz, Jiaqi_Jine_NianjiaBz = x.Jiaqi_Jine_NianjiaBz, GwsrkhJineQianhege = x.GwsrkhJineQianhege, GwsrkhJineQiwang = x.GwsrkhJineQiwang, GwsrkhJineHege = x.GwsrkhJineHege, GwsrkhJineShengren = x.GwsrkhJineShengren, GwsrkhJineChaoshengren = x.GwsrkhJineChaoshengren, Jiaban_GwsrkhJineQianhege = x.Jiaban_GwsrkhJineQianhege, Jiaban_GwsrkhJineQiwang = x.Jiaban_GwsrkhJineQiwang, Jiaban_GwsrkhJineHege = x.Jiaban_GwsrkhJineHege, Jiaban_GwsrkhJineShengren = x.Jiaban_GwsrkhJineShengren, Jiaban_GwsrkhJineChaoshengren = x.Jiaban_GwsrkhJineChaoshengren }; private static void Apply(ConfGz e, ConfGzSaveDto d) { e.WorkTypeId = d.WorkTypeId; e.HoursPerday = d.HoursPerday; e.QqDaysStandard = d.QqDaysStandard; e.QqHoursMaxQj = d.QqHoursMaxQj; e.QqHoursDkMinjiaban = d.QqHoursDkMinjiaban; e.QqHoursDkQingjia = d.QqHoursDkQingjia; e.XgJineQuanqin = d.XgJineQuanqin; e.XgJineGangwei = d.XgJineGangwei; e.JineNiangong = d.JineNiangong; e.JineQuanqin = d.JineQuanqin; e.JineGangwei = d.JineGangwei; e.JineYuekhJixiao = d.JineYuekhJixiao; e.JineGwkh = d.JineGwkh; e.JineYueticheng = d.JineYueticheng; e.JineJtkhYear = d.JineJtkhYear; e.JineJisuanjishu = d.JineJisuanjishu; e.JineYeban = d.JineYeban; e.JineJiaotongButie = d.JineJiaotongButie; e.LiudongJineGuding = d.LiudongJineGuding; e.JiaqiJineKuangongKk = d.JiaqiJineKuangongKk; e.JiaqiJineFadingGz = d.JiaqiJineFadingGz; e.JiaqiJineFadingBz = d.JiaqiJineFadingBz; e.JiaqiJineHunjiaBz = d.JiaqiJineHunjiaBz; e.JiaqiJineSangjiaBz = d.JiaqiJineSangjiaBz; e.JiaqiJineBingjiaBz = d.JiaqiJineBingjiaBz; e.JiaqiJineLunxiuBz = d.JiaqiJineLunxiuBz; e.JiabanJineBz = d.JiabanJineBz; e.Jiaqi_Jine_TiaoxiuBz = d.Jiaqi_Jine_TiaoxiuBz; e.Jiaqi_Jine_NianjiaBz = d.Jiaqi_Jine_NianjiaBz; e.GwsrkhJineQianhege = d.GwsrkhJineQianhege; e.GwsrkhJineQiwang = d.GwsrkhJineQiwang; e.GwsrkhJineHege = d.GwsrkhJineHege; e.GwsrkhJineShengren = d.GwsrkhJineShengren; e.GwsrkhJineChaoshengren = d.GwsrkhJineChaoshengren; e.Jiaban_GwsrkhJineQianhege = d.Jiaban_GwsrkhJineQianhege; e.Jiaban_GwsrkhJineQiwang = d.Jiaban_GwsrkhJineQiwang; e.Jiaban_GwsrkhJineHege = d.Jiaban_GwsrkhJineHege; e.Jiaban_GwsrkhJineShengren = d.Jiaban_GwsrkhJineShengren; e.Jiaban_GwsrkhJineChaoshengren = d.Jiaban_GwsrkhJineChaoshengren; } } // ==================== 薪资配置-挡车/车头岗位 ==================== public interface IConfDcgService { Task> GetListAsync(); Task GetForEditAsync(long id); Task SaveAsync(ConfDcgSaveDto dto); Task DeleteAsync(long id); } public class ConfDcgService : IConfDcgService { private readonly IRepository _repo; private readonly IRepository _depRepo; public ConfDcgService(IRepository repo, IRepository depRepo) { _repo = repo; _depRepo = depRepo; } public async Task> GetListAsync() { var items = await _repo.GetAllAsync(); var deps = await _depRepo.GetAllAsync(); var depDict = deps.ToDictionary(d => d.Id, d => d.Name); return items.Select(x => new ConfDcgListItemDto { Id = x.Id, DepId = x.DepId, DepName = depDict.GetValueOrDefault(x.DepId, ""), JineJisuanjishu50 = x.JineJisuanjishu50, JineJisuanjishu60 = x.JineJisuanjishu60, JineJisuanjishu70 = x.JineJisuanjishu70, JineJisuanjishu100 = x.JineJisuanjishu100, JineCtg = x.JineCtg }).ToList(); } public async Task GetForEditAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("挡车岗位薪资配置不存在或已删除", 404); return new ConfDcgSaveDto { Id = e.Id, DepId = e.DepId, JineJisuanjishu50 = e.JineJisuanjishu50, JineJisuanjishu60 = e.JineJisuanjishu60, JineJisuanjishu70 = e.JineJisuanjishu70, JineJisuanjishu100 = e.JineJisuanjishu100, JineCtg = e.JineCtg }; } public async Task SaveAsync(ConfDcgSaveDto dto) { if (dto.DepId == 0) throw new ServiceException("请选择部门"); ConfDcg e; if (dto.Id > 0) { e = await _repo.GetByIdAsync(dto.Id); if (e == null) throw new ServiceException("挡车岗位薪资配置不存在或已删除", 404); var dup = await _repo.FirstOrDefaultAsync(x => x.Id != dto.Id && x.DepId == dto.DepId); if (dup != null) throw new ServiceException("该部门已存在挡车岗位薪资配置!"); } else { var dup = await _repo.AnyAsync(x => x.DepId == dto.DepId); if (dup) throw new ServiceException("该部门已存在挡车岗位薪资配置!"); e = new ConfDcg(); await _repo.AddAsync(e); } e.DepId = dto.DepId; e.JineJisuanjishu50 = dto.JineJisuanjishu50; e.JineJisuanjishu60 = dto.JineJisuanjishu60; e.JineJisuanjishu70 = dto.JineJisuanjishu70; e.JineJisuanjishu100 = dto.JineJisuanjishu100; e.JineCtg = dto.JineCtg; await _repo.UpdateAsync(e); return e.Id; } public async Task DeleteAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("挡车岗位薪资配置不存在或已删除", 404); await _repo.HardDeleteAsync(e); } } // ==================== 挡车纤度奖扣 ==================== public interface IDcxdjkService { Task> GetListAsync(string guige); Task GetForEditAsync(long id); Task SaveAsync(DcxdjkSaveDto dto); Task DeleteAsync(long id); } public class DcxdjkService : IDcxdjkService { private readonly IRepository _repo; public DcxdjkService(IRepository repo) => _repo = repo; public async Task> GetListAsync(string guige) { var items = await _repo.GetAllAsync(); var q = items.AsQueryable(); if (!string.IsNullOrWhiteSpace(guige)) q = q.Where(x => x.GuiGe == guige); return q.OrderBy(x => x.GuiGe).ThenBy(x => x.XianDu).ToList() .Select(x => new DcxdjkListItemDto { Id = x.Id, GuiGe = x.GuiGe, XianDu = x.XianDu, JiangLi = x.JiangLi, KouKuan = x.KouKuan }).ToList(); } public async Task GetForEditAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("挡车纤度奖扣不存在或已删除", 404); return new DcxdjkSaveDto { Id = e.Id, GuiGe = e.GuiGe, XianDu = e.XianDu, JiangLi = e.JiangLi, KouKuan = e.KouKuan }; } public async Task SaveAsync(DcxdjkSaveDto dto) { if (string.IsNullOrWhiteSpace(dto.GuiGe)) throw new ServiceException("请填写规格"); DangCheXianDuJiangKou e; if (dto.Id > 0) { e = await _repo.GetByIdAsync(dto.Id); if (e == null) throw new ServiceException("挡车纤度奖扣不存在或已删除", 404); var dup = await _repo.FirstOrDefaultAsync(x => x.Id != dto.Id && x.GuiGe == dto.GuiGe && x.XianDu == dto.XianDu); if (dup != null) throw new ServiceException("该规格已存在相同纤度的奖扣配置!"); } else { var dup = await _repo.AnyAsync(x => x.GuiGe == dto.GuiGe && x.XianDu == dto.XianDu); if (dup) throw new ServiceException("该规格已存在相同纤度的奖扣配置!"); e = new DangCheXianDuJiangKou(); await _repo.AddAsync(e); } e.GuiGe = dto.GuiGe.Trim(); e.XianDu = dto.XianDu; e.JiangLi = dto.JiangLi; e.KouKuan = dto.KouKuan; await _repo.UpdateAsync(e); return e.Id; } public async Task DeleteAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("挡车纤度奖扣不存在或已删除", 404); await _repo.HardDeleteAsync(e); } } // ==================== 薪资价格配置 ==================== public interface IXzjgService { Task> GetListAsync(string group); Task GetForEditAsync(long id); Task SaveAsync(XzjgSaveDto dto); Task DeleteAsync(long id); Task GetPriceAsync(string group, string key); } public class XzjgService : IXzjgService { private readonly IRepository _repo; public XzjgService(IRepository repo) => _repo = repo; public async Task> GetListAsync(string group) { var items = await _repo.GetAllAsync(); var q = items.AsQueryable(); if (!string.IsNullOrWhiteSpace(group)) q = q.Where(x => x.Group == group); return q.OrderBy(x => x.Group).ThenBy(x => x.Key).ToList() .Select(x => new XzjgListItemDto { Id = x.Id, Group = x.Group, Key = x.Key, Unit = x.Unit, Price = x.Price, Memo = x.Memo }).ToList(); } public async Task GetForEditAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("薪资价格配置不存在或已删除", 404); return new XzjgSaveDto { Id = e.Id, Group = e.Group, Key = e.Key, Unit = e.Unit, Price = e.Price, Memo = e.Memo }; } public async Task SaveAsync(XzjgSaveDto dto) { if (string.IsNullOrWhiteSpace(dto.Group)) throw new ServiceException("请填写分组"); if (string.IsNullOrWhiteSpace(dto.Key)) throw new ServiceException("请填写项目"); var grp = dto.Group.Trim(); var key = dto.Key.Trim(); XinZiJiaGePeiZhi e; if (dto.Id > 0) { e = await _repo.GetByIdAsync(dto.Id); if (e == null) throw new ServiceException("薪资价格配置不存在或已删除", 404); var dup = await _repo.FirstOrDefaultAsync(x => x.Id != dto.Id && x.Group == grp && x.Key == key); if (dup != null) throw new ServiceException("该分组已存在相同的项目!"); } else { var dup = await _repo.AnyAsync(x => x.Group == grp && x.Key == key); if (dup) throw new ServiceException("该分组已存在相同的项目!"); e = new XinZiJiaGePeiZhi(); await _repo.AddAsync(e); } e.Group = grp; e.Key = key; e.Unit = dto.Unit ?? ""; e.Price = dto.Price; e.Memo = dto.Memo ?? ""; await _repo.UpdateAsync(e); return e.Id; } public async Task DeleteAsync(long id) { var e = await _repo.GetByIdAsync(id); if (e == null) throw new ServiceException("薪资价格配置不存在或已删除", 404); await _repo.HardDeleteAsync(e); } /// 取价:无配置返回 0 public async Task GetPriceAsync(string group, string key) { var e = await _repo.FirstOrDefaultAsync(x => x.Group == group && x.Key == key); return e?.Price ?? 0m; } }