- 新增 PayRoll(工资)、Wms(仓储)、Prod(车速/缫丝/考勤/丝片检测/丝片台账/纤检日报/质量日报) 模块 - 新增对应 Domain 实体、Application DTO/Service、Api Controller 与前端页面 - 移除旧 Attendance 考勤模块(Controller/Service/Entity/DTO 及 5 个前端页面),由 Prod/Kaoqin 取代 - 调整路由、仪表盘、Lsjl 流丝记录实体与服务 - 更新业务种子数据与 DbSeeder - 补充工作进度文档 14-27
133 lines
5.5 KiB
C#
133 lines
5.5 KiB
C#
using F9WebAiTest.Application.Common;
|
|
using F9WebAiTest.Application.Dtos;
|
|
using F9WebAiTest.Application.Dtos.Prod;
|
|
using F9WebAiTest.Domain.Common;
|
|
using F9WebAiTest.Domain.Entities;
|
|
using F9WebAiTest.Domain.Entities.Base;
|
|
using F9WebAiTest.Domain.Entities.Prod;
|
|
using SysDept = F9WebAiTest.Domain.Entities.SYS.Departments;
|
|
|
|
namespace F9WebAiTest.Application.Services.Prod;
|
|
|
|
public interface ILsjlService
|
|
{
|
|
Task<PageResult<LsjlDto>> GetPagedAsync(int pageIndex, int pageSize, DateTime? date, long? deptId, string keyword);
|
|
Task<LsjlDto> CreateAsync(LsjlCreateDto dto);
|
|
Task<LsjlDto> UpdateAsync(long id, LsjlCreateDto dto);
|
|
Task DeleteAsync(long id);
|
|
}
|
|
|
|
public class LsjlService : ILsjlService
|
|
{
|
|
private readonly IRepository<LsjlRecord> _repo;
|
|
private readonly IRepository<SysDept.Department> _deptRepo;
|
|
private readonly IRepository<CraftZhuangKou> _zkRepo;
|
|
|
|
public LsjlService(IRepository<LsjlRecord> repo, IRepository<SysDept.Department> deptRepo, IRepository<CraftZhuangKou> zkRepo)
|
|
{
|
|
_repo = repo;
|
|
_deptRepo = deptRepo;
|
|
_zkRepo = zkRepo;
|
|
}
|
|
|
|
public async Task<PageResult<LsjlDto>> GetPagedAsync(int pageIndex, int pageSize, DateTime? date, long? deptId, string keyword)
|
|
{
|
|
var all = await _repo.GetAllAsync();
|
|
var q = all.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 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);
|
|
|
|
if (!string.IsNullOrWhiteSpace(keyword))
|
|
{
|
|
var kwDeptIds = depts.Where(d => d.Name.Contains(keyword)).Select(d => d.Id).ToHashSet();
|
|
var kwZkIds = zks.Where(z => z.ZhuangKouName.Contains(keyword)).Select(z => z.Id).ToHashSet();
|
|
q = q.Where(x => kwDeptIds.Contains(x.DeptId) || kwZkIds.Contains(x.GyzkId) || x.Guige.Contains(keyword));
|
|
}
|
|
|
|
var total = q.LongCount();
|
|
var items = q.OrderByDescending(x => x.WorkDate).ThenByDescending(x => x.Id)
|
|
.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
|
|
|
return new PageResult<LsjlDto>
|
|
{
|
|
Items = items.Select(x => ToDto(x, deptDict, zkDict)).ToList(),
|
|
Total = total, PageIndex = pageIndex, PageSize = pageSize
|
|
};
|
|
}
|
|
|
|
public async Task<LsjlDto> CreateAsync(LsjlCreateDto dto)
|
|
{
|
|
if (dto.DeptId == 0) throw new ServiceException("请选择车间");
|
|
if (dto.GyzkId == 0) throw new ServiceException("请选择庄口");
|
|
var e = Map(new LsjlRecord(), dto);
|
|
await _repo.AddAsync(e);
|
|
await _repo.SaveChangesAsync();
|
|
return await ToDto(e);
|
|
}
|
|
|
|
public async Task<LsjlDto> UpdateAsync(long id, LsjlCreateDto dto)
|
|
{
|
|
var e = await _repo.GetByIdAsync(id);
|
|
if (e == null) throw new ServiceException("记录不存在", 404);
|
|
Map(e, dto);
|
|
await _repo.UpdateAsync(e);
|
|
await _repo.SaveChangesAsync();
|
|
return await ToDto(e);
|
|
}
|
|
|
|
public async Task DeleteAsync(long id)
|
|
{
|
|
var e = await _repo.GetByIdAsync(id);
|
|
if (e == null) throw new ServiceException("记录不存在", 404);
|
|
await _repo.DeleteAsync(e);
|
|
await _repo.SaveChangesAsync();
|
|
}
|
|
|
|
private static LsjlRecord Map(LsjlRecord e, LsjlCreateDto d)
|
|
{
|
|
e.WorkDate = d.WorkDate; e.DeptId = d.DeptId; e.GyzkId = d.GyzkId; e.Jizu = d.Jizu;
|
|
e.LuosiTime = d.LuosiTime; e.Yanse = d.Yanse; e.Huishu = d.Huishu;
|
|
e.ChetaiStart = d.ChetaiStart; e.ChetaiEnd = d.ChetaiEnd; e.Chetaishu = d.Chetaishu;
|
|
e.Isbanche = d.Isbanche; e.Hours = d.Hours; e.Guige = d.Guige; e.Chesu = d.Chesu;
|
|
e.Tongshu = d.Tongshu; e.Meitongjianliang = d.Meitongjianliang;
|
|
return e;
|
|
}
|
|
|
|
private async Task<LsjlDto> ToDto(LsjlRecord e)
|
|
{
|
|
var dept = await _deptRepo.GetByIdAsync(e.DeptId);
|
|
var zk = await _zkRepo.GetByIdAsync(e.GyzkId);
|
|
return new LsjlDto
|
|
{
|
|
Id = e.Id, WorkDate = e.WorkDate, DeptId = e.DeptId, DeptName = dept?.Name ?? "",
|
|
GyzkId = e.GyzkId, ZhuangKouName = zk?.ZhuangKouName ?? "", Jizu = e.Jizu,
|
|
LuosiTime = e.LuosiTime, Yanse = e.Yanse, Huishu = e.Huishu,
|
|
ChetaiStart = e.ChetaiStart, ChetaiEnd = e.ChetaiEnd, Chetaishu = e.Chetaishu,
|
|
Isbanche = e.Isbanche, IsbancheName = e.Isbanche ? "半车" : "整车",
|
|
Hours = e.Hours, Tongshu = e.Tongshu, Meitongjianliang = e.Meitongjianliang,
|
|
Guige = e.Guige, Chesu = e.Chesu
|
|
};
|
|
}
|
|
|
|
private static LsjlDto ToDto(LsjlRecord e, Dictionary<long, string> deptDict, Dictionary<long, string> zkDict)
|
|
{
|
|
return new LsjlDto
|
|
{
|
|
Id = e.Id, WorkDate = e.WorkDate, DeptId = e.DeptId, DeptName = deptDict.GetValueOrDefault(e.DeptId, ""),
|
|
GyzkId = e.GyzkId, ZhuangKouName = zkDict.GetValueOrDefault(e.GyzkId, ""), Jizu = e.Jizu,
|
|
LuosiTime = e.LuosiTime, Yanse = e.Yanse, Huishu = e.Huishu,
|
|
ChetaiStart = e.ChetaiStart, ChetaiEnd = e.ChetaiEnd, Chetaishu = e.Chetaishu,
|
|
Isbanche = e.Isbanche, IsbancheName = e.Isbanche ? "半车" : "整车",
|
|
Hours = e.Hours, Tongshu = e.Tongshu, Meitongjianliang = e.Meitongjianliang,
|
|
Guige = e.Guige, Chesu = e.Chesu
|
|
};
|
|
}
|
|
}
|