| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Warehouse;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Warehouse;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Warehouse;
- /// <summary>
- /// S0 物料职责维护(EmpWorkDutyMaster 语义)
- /// </summary>
- [ApiController]
- [Route("api/s0/warehouse/emp-work-duties")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0EmpWorkDutiesController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0EmpWorkDutyMaster> _rep;
- private readonly SqlSugarRepository<AdoS0EmployeeMaster> _empRep;
- private readonly SqlSugarRepository<AdoS0LocationMaster> _locRep;
- public AdoS0EmpWorkDutiesController(
- SqlSugarRepository<AdoS0EmpWorkDutyMaster> rep,
- SqlSugarRepository<AdoS0EmployeeMaster> empRep,
- SqlSugarRepository<AdoS0LocationMaster> locRep)
- {
- _rep = rep;
- _empRep = empRep;
- _locRep = locRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0EmpWorkDutyQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(q.CompanyRefId.HasValue, x => x.CompanyRefId == q.CompanyRefId!.Value)
- .WhereIF(q.FactoryRefId.HasValue, x => x.FactoryRefId == q.FactoryRefId!.Value)
- .WhereIF(!string.IsNullOrWhiteSpace(q.DomainCode), x => x.DomainCode == q.DomainCode)
- .WhereIF(!string.IsNullOrWhiteSpace(q.Employee), x => x.Employee.Contains(q.Employee!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Location), x => x.Location == q.Location)
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
- x => x.Employee.Contains(q.Keyword!) || (x.ItemNum1 != null && x.ItemNum1.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query
- .OrderBy(x => x.Employee)
- .Skip((q.Page - 1) * q.PageSize)
- .Take(q.PageSize)
- .ToListAsync();
- await ApplyDisplayFieldsAsync(list);
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetAsync(long id)
- {
- var item = await _rep.GetByIdAsync(id);
- if (item == null) return NotFound();
- await ApplyDisplayFieldsAsync(new List<AdoS0EmpWorkDutyMaster> { item });
- return Ok(item);
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0EmpWorkDutyUpsertDto dto)
- {
- var entity = new AdoS0EmpWorkDutyMaster
- {
- CompanyRefId = dto.CompanyRefId,
- FactoryRefId = dto.FactoryRefId,
- DomainCode = dto.DomainCode ?? string.Empty,
- Employee = dto.Employee,
- ItemNum1 = dto.ItemNum1,
- ItemNum2 = dto.ItemNum2,
- Location = dto.Location,
- ProdLine = dto.ProdLine,
- Duty = dto.Duty,
- EmpType = dto.EmpType,
- Ufld2 = dto.Ufld2,
- CreateUser = dto.CreateUser,
- CreateTime = DateTime.Now
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0EmpWorkDutyUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.CompanyRefId = dto.CompanyRefId;
- entity.FactoryRefId = dto.FactoryRefId;
- entity.DomainCode = dto.DomainCode ?? string.Empty;
- entity.Employee = dto.Employee;
- entity.ItemNum1 = dto.ItemNum1;
- entity.ItemNum2 = dto.ItemNum2;
- entity.Location = dto.Location;
- entity.ProdLine = dto.ProdLine;
- entity.Duty = dto.Duty;
- entity.EmpType = dto.EmpType;
- entity.Ufld2 = dto.Ufld2;
- entity.UpdateUser = dto.UpdateUser;
- entity.UpdateTime = DateTime.Now;
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var item = await _rep.GetByIdAsync(id);
- if (item == null) return NotFound();
- await _rep.DeleteAsync(item);
- return Ok(new { message = "删除成功" });
- }
- private static readonly Dictionary<string, string> DutyMap = new(StringComparer.OrdinalIgnoreCase)
- {
- ["iss-po"] = "采购收货",
- ["iss-so"] = "销售发货",
- ["iss-wo"] = "发料",
- ["packing"] = "退料",
- ["rct-unp"] = "计划外入库",
- ["rct-wo"] = "入库",
- ["Up-Shelf"] = "上架"
- };
- private async Task ApplyDisplayFieldsAsync(List<AdoS0EmpWorkDutyMaster> duties)
- {
- if (duties.Count == 0) return;
- var domainCodes = duties.Select(d => d.DomainCode).Distinct().ToList();
- var employees = await _empRep.AsQueryable()
- .Where(e => domainCodes.Contains(e.DomainCode))
- .ToListAsync();
- var locations = await _locRep.AsQueryable()
- .Where(l => domainCodes.Contains(l.DomainCode))
- .ToListAsync();
- foreach (var duty in duties)
- {
- var emp = employees.Find(e =>
- string.Equals(e.DomainCode, duty.DomainCode, StringComparison.OrdinalIgnoreCase)
- && string.Equals(e.Employee, duty.Employee, StringComparison.OrdinalIgnoreCase));
- duty.EmployeeName = emp?.Name;
- if (!string.IsNullOrWhiteSpace(duty.Location))
- {
- var loc = locations.Find(l =>
- string.Equals(l.DomainCode, duty.DomainCode, StringComparison.OrdinalIgnoreCase)
- && string.Equals(l.Location, duty.Location, StringComparison.OrdinalIgnoreCase));
- duty.LocationName = $"{duty.Location} {loc?.Descr ?? ""}".Trim();
- }
- // Duty 翻译(原始多值逗号/空格拼接场景兼容)
- if (!string.IsNullOrWhiteSpace(duty.Duty))
- {
- var parts = duty.Duty.Split(new[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- duty.DutyDisplay = string.Join("、", parts.Select(p => DutyMap.TryGetValue(p.Trim(), out var cn) ? cn : p.Trim()));
- }
- }
- }
- }
|