| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Manufacturing;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
- [ApiController]
- [Route("api/s0/manufacturing/sop-documents")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0MfgSopDocumentsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QualitySegmentImage> _rep;
- public AdoS0MfgSopDocumentsController(SqlSugarRepository<AdoS0QualitySegmentImage> rep)
- {
- _rep = rep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MfgSopDocumentQueryDto q)
- {
- var page = q.Page;
- var pageSize = q.PageSize;
- (page, pageSize) = PagingGuard.Normalize(page, pageSize);
- var domain = q.Domain.Trim();
- var baseQuery = _rep.AsQueryable()
- .Where(x => x.Domain == domain)
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
- x => (x.Line != null && x.Line.Contains(q.Keyword!))
- || (x.ItemNum != null && x.ItemNum.Contains(q.Keyword!))
- || (x.Op != null && x.Op.Contains(q.Keyword!))
- || (x.Path != null && x.Path.Contains(q.Keyword!))
- || (x.Descr != null && x.Descr.Contains(q.Keyword!))
- || (x.Rev != null && x.Rev.Contains(q.Keyword!)));
- var total = await baseQuery.CountAsync();
- // 左联仅用于展示字段(Line/Op/imgType),主表字段仍可 CRUD
- var list = await baseQuery
- .LeftJoin<AdoS0ImageType>((qsi, it) => qsi.ImageTypeID == it.ImageTypeID && qsi.Domain == it.Domain)
- .LeftJoin<AdoS0LineMaster>((qsi, it, lm) => qsi.Line == lm.Line && qsi.Domain == lm.Domain)
- .LeftJoin<AdoS0MfgRoutingOpDetail>((qsi, it, lm, rd) => qsi.ItemNum == rd.MaterialCode && qsi.Op == rd.OperationCode)
- .OrderByDescending((qsi, it, lm, rd) => qsi.Id)
- .Select((qsi, it, lm, rd) => new
- {
- id = qsi.Id,
- line = qsi.Line,
- lineDisplay = qsi.Line == null ? "" : (lm.Line + " " + (lm.Describe ?? "")),
- itemNum = qsi.ItemNum,
- op = qsi.Op,
- opDisplay = qsi.Op == null ? "" : (rd.OperationCode + " " + (rd.OperationDescription ?? "")),
- imageTypeID = qsi.ImageTypeID,
- imgType = it.Descr,
- path = qsi.Path,
- descr = qsi.Descr,
- rev = qsi.Rev,
- sortID = qsi.SortID,
- domain = qsi.Domain
- })
- .Skip((page - 1) * pageSize)
- .Take(pageSize)
- .ToListAsync();
- return Ok(new { total, page, pageSize, list });
- }
- [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] AdoS0MfgSopDocumentUpsertDto dto)
- {
- var entity = new AdoS0QualitySegmentImage
- {
- Domain = dto.Domain.Trim(),
- Line = dto.Line,
- ItemNum = dto.ItemNum,
- Op = dto.Op,
- ImageTypeID = dto.ImageTypeID,
- Path = dto.Path,
- Descr = dto.Descr,
- Rev = dto.Rev,
- SortID = dto.SortID
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MfgSopDocumentUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.Domain = dto.Domain.Trim();
- entity.Line = dto.Line;
- entity.ItemNum = dto.ItemNum;
- entity.Op = dto.Op;
- entity.ImageTypeID = dto.ImageTypeID;
- entity.Path = dto.Path;
- entity.Descr = dto.Descr;
- entity.Rev = dto.Rev;
- entity.SortID = dto.SortID;
- 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 = "删除成功" });
- }
- }
|