| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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>
- /// 前处理要素参数行(独立列表页,与聚合保存并存)。
- /// </summary>
- [ApiController]
- [Route("api/s0/manufacturing/preprocess-element-params")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0MfgPreprocessElementParamsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0MfgPreprocessElementParam> _rep;
- private readonly SqlSugarRepository<AdoS0MfgElementParam> _elementParamRep;
- public AdoS0MfgPreprocessElementParamsController(
- SqlSugarRepository<AdoS0MfgPreprocessElementParam> rep,
- SqlSugarRepository<AdoS0MfgElementParam> elementParamRep)
- {
- _rep = rep;
- _elementParamRep = elementParamRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MfgPreprocessElementParamQueryDto 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(q.PreprocessElementId.HasValue, x => x.PreprocessElementId == q.PreprocessElementId!.Value)
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
- x => (x.Remark != null && x.Remark.Contains(q.Keyword!)))
- .WhereIF(q.IsEnabled.HasValue, x => x.IsEnabled == q.IsEnabled!.Value);
- var total = await query.CountAsync();
- var list = await query.OrderByDescending(x => x.CreatedAt).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] AdoS0MfgPreprocessElementParamUpsertDto dto)
- {
- var ok = await _elementParamRep.IsAnyAsync(e =>
- e.Id == dto.ElementParamId && e.CompanyRefId == dto.CompanyRefId && e.FactoryRefId == dto.FactoryRefId);
- if (!ok) return BadRequest(new { message = "生产要素参数引用无效" });
- var entity = new AdoS0MfgPreprocessElementParam
- {
- CompanyRefId = dto.CompanyRefId,
- FactoryRefId = dto.FactoryRefId,
- PreprocessElementId = dto.PreprocessElementId,
- ElementParamId = dto.ElementParamId,
- ParamValue = dto.ParamValue,
- SortNo = dto.SortNo,
- Remark = dto.Remark,
- IsEnabled = dto.IsEnabled,
- CreatedAt = DateTime.Now
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MfgPreprocessElementParamUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- var ok = await _elementParamRep.IsAnyAsync(e =>
- e.Id == dto.ElementParamId && e.CompanyRefId == dto.CompanyRefId && e.FactoryRefId == dto.FactoryRefId);
- if (!ok) return BadRequest(new { message = "生产要素参数引用无效" });
- entity.CompanyRefId = dto.CompanyRefId;
- entity.FactoryRefId = dto.FactoryRefId;
- entity.PreprocessElementId = dto.PreprocessElementId;
- entity.ElementParamId = dto.ElementParamId;
- entity.ParamValue = dto.ParamValue;
- entity.SortNo = dto.SortNo;
- entity.Remark = dto.Remark;
- entity.IsEnabled = dto.IsEnabled;
- entity.UpdatedAt = 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.IsEnabled = dto.IsEnabled;
- entity.UpdatedAt = 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 = "删除成功" });
- }
- }
|