| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
- /// <summary>
- /// 生产线维护(LineMaster 语义,表 ado_s0_mfg_line_master)。
- /// </summary>
- [ApiController]
- [Route("api/s0/manufacturing/production-lines")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0MfgProductionLinesController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0LineMaster> _rep;
- public AdoS0MfgProductionLinesController(SqlSugarRepository<AdoS0LineMaster> rep)
- {
- _rep = rep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0LineMasterQueryDto q)
- {
- var page = q.EffectivePage;
- var pageSize = q.PageSize;
- (page, pageSize) = PagingGuard.Normalize(page, 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.Keyword),
- x => x.Line.Contains(q.Keyword!) || (x.Describe != null && x.Describe.Contains(q.Keyword!)))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Line), x => x.Line.Contains(q.Line!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Workshop),
- x => x.Workshop != null && x.Workshop.Contains(q.Workshop!))
- .WhereIF(q.IsEnabled.HasValue, x => x.IsActive == q.IsEnabled!.Value);
- var total = await query.CountAsync();
- var entities = await query
- .OrderByDescending(x => x.Id)
- .Skip((page - 1) * pageSize)
- .Take(pageSize)
- .ToListAsync();
- // GeneralizedCodeMaster 中文说明:当前库无码表实体,占位供列表展示;后续可 JOIN 补全。
- var list = entities.Select(x => new
- {
- x.Id,
- x.CompanyRefId,
- x.FactoryRefId,
- x.Domain,
- x.Line,
- describe = x.Describe,
- x.LineType,
- x.LineCategory,
- x.Location,
- x.Workshop,
- vLocation = x.VLocation,
- x.Location2,
- x.Location3,
- pickingLocation = x.PickingLocation,
- midLocation = x.MidLocation,
- isActive = x.IsActive,
- x.CreateUser,
- x.CreateTime,
- x.UpdateUser,
- x.UpdateTime,
- lineCategoryComments = (string?)null,
- workshopComments = (string?)null
- }).ToList();
- 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] AdoS0LineMasterUpsertDto dto)
- {
- var now = DateTime.Now;
- var entity = new AdoS0LineMaster
- {
- CompanyRefId = dto.CompanyRefId,
- FactoryRefId = dto.FactoryRefId,
- Domain = dto.Domain.Trim(),
- Line = dto.Line.Trim(),
- Describe = string.IsNullOrWhiteSpace(dto.Describe) ? null : dto.Describe.Trim(),
- LineType = string.IsNullOrWhiteSpace(dto.LineType) ? null : dto.LineType.Trim(),
- LineCategory = string.IsNullOrWhiteSpace(dto.LineCategory) ? null : dto.LineCategory.Trim(),
- Location = string.IsNullOrWhiteSpace(dto.Location) ? null : dto.Location.Trim(),
- Workshop = string.IsNullOrWhiteSpace(dto.Workshop) ? null : dto.Workshop.Trim(),
- VLocation = string.IsNullOrWhiteSpace(dto.VLocation) ? null : dto.VLocation.Trim(),
- Location2 = string.IsNullOrWhiteSpace(dto.Location2) ? null : dto.Location2.Trim(),
- Location3 = string.IsNullOrWhiteSpace(dto.Location3) ? null : dto.Location3.Trim(),
- PickingLocation = string.IsNullOrWhiteSpace(dto.PickingLocation) ? null : dto.PickingLocation.Trim(),
- MidLocation = string.IsNullOrWhiteSpace(dto.MidLocation) ? null : dto.MidLocation.Trim(),
- IsActive = dto.IsActive,
- CreateUser = dto.CreateUser,
- CreateTime = now,
- UpdateUser = null,
- UpdateTime = null
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0LineMasterUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.CompanyRefId = dto.CompanyRefId;
- entity.FactoryRefId = dto.FactoryRefId;
- entity.Domain = dto.Domain.Trim();
- entity.Line = dto.Line.Trim();
- entity.Describe = string.IsNullOrWhiteSpace(dto.Describe) ? null : dto.Describe.Trim();
- entity.LineType = string.IsNullOrWhiteSpace(dto.LineType) ? null : dto.LineType.Trim();
- entity.LineCategory = string.IsNullOrWhiteSpace(dto.LineCategory) ? null : dto.LineCategory.Trim();
- entity.Location = string.IsNullOrWhiteSpace(dto.Location) ? null : dto.Location.Trim();
- entity.Workshop = string.IsNullOrWhiteSpace(dto.Workshop) ? null : dto.Workshop.Trim();
- entity.VLocation = string.IsNullOrWhiteSpace(dto.VLocation) ? null : dto.VLocation.Trim();
- entity.Location2 = string.IsNullOrWhiteSpace(dto.Location2) ? null : dto.Location2.Trim();
- entity.Location3 = string.IsNullOrWhiteSpace(dto.Location3) ? null : dto.Location3.Trim();
- entity.PickingLocation = string.IsNullOrWhiteSpace(dto.PickingLocation) ? null : dto.PickingLocation.Trim();
- entity.MidLocation = string.IsNullOrWhiteSpace(dto.MidLocation) ? null : dto.MidLocation.Trim();
- entity.IsActive = dto.IsActive;
- entity.UpdateUser = dto.UpdateUser;
- entity.UpdateTime = DateTime.Now;
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpPatch("{id:long}/toggle-enabled")]
- public async Task<IActionResult> ToggleEnabledAsync(long id, [FromBody] AdoS0ToggleEnabledDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.IsActive = dto.IsEnabled;
- entity.UpdateTime = DateTime.Now;
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(new { entity.Id, isActive = entity.IsActive, entity.UpdateTime });
- }
- [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 = "删除成功" });
- }
- }
|