- 新增 PayRoll(工资)、Wms(仓储)、Prod(车速/缫丝/考勤/丝片检测/丝片台账/纤检日报/质量日报) 模块 - 新增对应 Domain 实体、Application DTO/Service、Api Controller 与前端页面 - 移除旧 Attendance 考勤模块(Controller/Service/Entity/DTO 及 5 个前端页面),由 Prod/Kaoqin 取代 - 调整路由、仪表盘、Lsjl 流丝记录实体与服务 - 更新业务种子数据与 DbSeeder - 补充工作进度文档 14-27
110 lines
4.2 KiB
C#
110 lines
4.2 KiB
C#
using F9WebAiTest.Application.Common;
|
|
using F9WebAiTest.Application.Dtos.Prod;
|
|
using F9WebAiTest.Domain.Common;
|
|
using F9WebAiTest.Domain.Entities.Base;
|
|
using F9WebAiTest.Domain.Entities.Prod;
|
|
using SysDept = F9WebAiTest.Domain.Entities.SYS.Departments;
|
|
|
|
namespace F9WebAiTest.Application.Services.Prod;
|
|
|
|
/// <summary>公量纤度:以落丝记录为主表,取纤度检验的平均纤度,由质检录入公量纤度(按日期 + 车间整日批量保存)</summary>
|
|
public interface IGlxdService
|
|
{
|
|
Task<List<GlxdListItemDto>> GetListAsync(DateTime? date, long? deptId);
|
|
Task SaveAsync(GlxdSaveDto dto);
|
|
}
|
|
|
|
public class GlxdService : IGlxdService
|
|
{
|
|
private readonly IRepository<LsjlRecord> _lsjlRepo;
|
|
private readonly IRepository<Glxd> _glxdRepo;
|
|
private readonly IRepository<XdjyLsjl> _xdjyLsjlRepo;
|
|
private readonly IRepository<SysDept.Department> _deptRepo;
|
|
private readonly IRepository<CraftZhuangKou> _zkRepo;
|
|
|
|
public GlxdService(
|
|
IRepository<LsjlRecord> lsjlRepo,
|
|
IRepository<Glxd> glxdRepo,
|
|
IRepository<XdjyLsjl> xdjyLsjlRepo,
|
|
IRepository<SysDept.Department> deptRepo,
|
|
IRepository<CraftZhuangKou> zkRepo)
|
|
{
|
|
_lsjlRepo = lsjlRepo;
|
|
_glxdRepo = glxdRepo;
|
|
_xdjyLsjlRepo = xdjyLsjlRepo;
|
|
_deptRepo = deptRepo;
|
|
_zkRepo = zkRepo;
|
|
}
|
|
|
|
public async Task<List<GlxdListItemDto>> GetListAsync(DateTime? date, long? deptId)
|
|
{
|
|
var lsjls = await _lsjlRepo.GetAllAsync();
|
|
var q = lsjls.AsQueryable();
|
|
if (date.HasValue) q = q.Where(x => x.WorkDate.Date == date.Value.Date);
|
|
if (deptId.HasValue) q = q.Where(x => x.DeptId == deptId.Value);
|
|
|
|
var items = q.OrderBy(x => x.DeptId).ThenBy(x => x.Jizu).ThenBy(x => x.Huishu).ToList();
|
|
if (items.Count == 0) return new List<GlxdListItemDto>();
|
|
|
|
var depts = await _deptRepo.GetAllAsync();
|
|
var deptDict = depts.ToDictionary(d => d.Id, d => d.Name);
|
|
var zks = await _zkRepo.GetAllAsync();
|
|
var zkDict = zks.ToDictionary(z => z.Id, z => z.ZhuangKouName);
|
|
var glxds = (await _glxdRepo.GetAllAsync()).ToDictionary(x => x.LsjlId);
|
|
var xdjySums = (await _xdjyLsjlRepo.GetAllAsync()).ToDictionary(x => x.LsjlId);
|
|
|
|
return items.Select(x =>
|
|
{
|
|
glxds.TryGetValue(x.Id, out var g);
|
|
xdjySums.TryGetValue(x.Id, out var xs);
|
|
return new GlxdListItemDto
|
|
{
|
|
LsjlId = x.Id,
|
|
WorkDate = x.WorkDate,
|
|
DeptId = x.DeptId,
|
|
DeptName = deptDict.GetValueOrDefault(x.DeptId, ""),
|
|
Jizu = x.Jizu,
|
|
Huishu = x.Huishu,
|
|
Guige = x.Guige,
|
|
ZhuangKouName = zkDict.GetValueOrDefault(x.GyzkId, ""),
|
|
Yanse = x.Yanse,
|
|
Isbanche = x.Isbanche,
|
|
IsbancheName = x.Isbanche ? "半车" : "整车",
|
|
Chetaishu = x.Chetaishu,
|
|
Avgxiandu = xs?.Avgxiandu ?? 0,
|
|
Gongliangxiandu = g?.Gongliangxiandu ?? 0
|
|
};
|
|
}).ToList();
|
|
}
|
|
|
|
public async Task SaveAsync(GlxdSaveDto dto)
|
|
{
|
|
if (dto.Items == null || dto.Items.Count == 0) throw new ServiceException("没有需要保存的公量纤度");
|
|
|
|
// 校验落丝记录存在,并按落丝记录 Id 去重
|
|
var dict = new Dictionary<long, decimal>();
|
|
foreach (var it in dto.Items)
|
|
{
|
|
if (it.LsjlId == 0) throw new ServiceException("存在无效的落丝记录");
|
|
var lsjl = await _lsjlRepo.GetByIdAsync(it.LsjlId);
|
|
if (lsjl == null) throw new ServiceException($"落丝记录 {it.LsjlId} 不存在", 404);
|
|
dict[it.LsjlId] = it.Gongliangxiandu;
|
|
}
|
|
|
|
foreach (var (lsjlId, value) in dict)
|
|
{
|
|
var e = await _glxdRepo.FirstOrDefaultAsync(x => x.LsjlId == lsjlId);
|
|
if (e == null)
|
|
{
|
|
e = new Glxd { LsjlId = lsjlId, Gongliangxiandu = value };
|
|
await _glxdRepo.AddAsync(e);
|
|
}
|
|
else
|
|
{
|
|
e.Gongliangxiandu = value;
|
|
await _glxdRepo.UpdateAsync(e);
|
|
}
|
|
}
|
|
}
|
|
}
|