| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Manufacturing;
- using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
- [ApiController]
- [Route("api/s0/manufacturing/material-process-elements")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0MfgMaterialProcessElementsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0ItemOpCondition> _rep;
- public AdoS0MfgMaterialProcessElementsController(SqlSugarRepository<AdoS0ItemOpCondition> rep)
- {
- _rep = rep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0ItemOpConditionQueryDto q)
- {
- var page = q.Page;
- var pageSize = q.PageSize;
- (page, pageSize) = PagingGuard.Normalize(page, pageSize);
- var domain = q.Domain.Trim();
- var query = _rep.AsQueryable()
- .Where(x => x.Domain == domain && x.CodeType == "Prod")
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
- x =>
- x.ItemNum.Contains(q.Keyword!)
- || (x.ItemCode != null && x.ItemCode.Contains(q.Keyword!))
- || (x.Descr != null && x.Descr.Contains(q.Keyword!))
- || (x.Op != null && x.Op.Contains(q.Keyword!))
- || (x.Typed != null && x.Typed.Contains(q.Keyword!)))
- .WhereIF(!string.IsNullOrWhiteSpace(q.ItemNum), x => x.ItemNum.Contains(q.ItemNum!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Op), x => x.Op != null && x.Op.Contains(q.Op!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Line), x => x.Line != null && x.Line.Contains(q.Line!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Typed), x => x.Typed != null && x.Typed.Contains(q.Typed!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.ItemCode), x => x.ItemCode != null && x.ItemCode.Contains(q.ItemCode!));
- var total = await query.CountAsync();
- var list = await query.OrderByDescending(x => x.UpdateTime ?? x.CreateTime).Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
- // 展示字段:ItemDescr / OpDescr / TypedDescr(当前阶段仅能稳定补 ItemDescr 与 OpDescr;TypedDescr 先留空)
- var itemNums = list.Select(x => x.ItemNum).Distinct().ToList();
- var items = await _rep.Context.Queryable<AdoS0ItemMaster>()
- .Where(m => m.DomainCode == domain && itemNums.Contains(m.ItemNum))
- .Select(m => new { m.ItemNum, m.Descr })
- .ToListAsync();
- var itemDescrMap = items.ToDictionary(x => x.ItemNum, x => x.Descr);
- var opKeys = list
- .Where(x => !string.IsNullOrWhiteSpace(x.Op))
- .Select(x => new { x.ItemNum, Op = x.Op! })
- .Distinct()
- .ToList();
- var opDescrMap = new Dictionary<string, string>();
- if (opKeys.Count > 0)
- {
- var r = await _rep.Context.Queryable<AdoS0MfgRoutingOpDetail>()
- .Where(x => x.MaterialCode != null && itemNums.Contains(x.MaterialCode))
- .ToListAsync();
- foreach (var k in opKeys)
- {
- var match = r.FirstOrDefault(x => x.MaterialCode == k.ItemNum && x.OperationCode == k.Op);
- if (match != null) opDescrMap[$"{k.ItemNum}::{k.Op}"] = match.OperationDescription;
- }
- }
- var shaped = list.Select(x => new
- {
- id = x.Id,
- itemNum = x.ItemNum,
- itemDescr = itemDescrMap.TryGetValue(x.ItemNum, out var idesc) ? idesc : "",
- op = x.Op,
- opDescr = x.Op != null && opDescrMap.TryGetValue($"{x.ItemNum}::{x.Op}", out var odesc) ? odesc : "",
- line = x.Line,
- typed = x.Typed,
- typedDescr = "",
- itemCode = x.ItemCode,
- descr = x.Descr,
- isMain = x.IsMain,
- codeType = x.CodeType,
- domain = x.Domain,
- createUser = x.CreateUser,
- createTime = x.CreateTime,
- updateUser = x.UpdateUser,
- updateTime = x.UpdateTime,
- }).ToList();
- return Ok(new { total, page, pageSize, list = shaped });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetAsync(long id)
- {
- var item = await _rep.GetByIdAsync(id);
- return item == null ? NotFound() : Ok(item);
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0ItemOpConditionUpsertDto dto)
- {
- var now = DateTime.Now;
- var entity = new AdoS0ItemOpCondition
- {
- Domain = dto.Domain.Trim(),
- CodeType = "Prod",
- ItemNum = dto.ItemNum.Trim(),
- Op = dto.Op,
- Line = dto.Line,
- Typed = dto.Typed,
- ItemCode = dto.ItemCode,
- Descr = dto.Descr,
- IsMain = dto.IsMain,
- CreateUser = dto.CreateUser ?? dto.UpdateUser,
- CreateTime = dto.CreateTime ?? dto.UpdateTime ?? now,
- UpdateUser = dto.UpdateUser,
- UpdateTime = dto.UpdateTime
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0ItemOpConditionUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.Domain = dto.Domain.Trim();
- entity.CodeType = "Prod";
- entity.ItemNum = dto.ItemNum.Trim();
- entity.Op = dto.Op;
- entity.Line = dto.Line;
- entity.Typed = dto.Typed;
- entity.ItemCode = dto.ItemCode;
- entity.Descr = dto.Descr;
- entity.IsMain = dto.IsMain;
- entity.UpdateUser = dto.UpdateUser;
- entity.UpdateTime = dto.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 = "删除成功" });
- }
- }
|