| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
- /// <summary>
- /// S0 物料主数据
- /// </summary>
- [ApiController]
- [Route("api/s0/sales/materials")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0MaterialsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0Material> _rep;
- public AdoS0MaterialsController(SqlSugarRepository<AdoS0Material> rep)
- {
- _rep = rep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MaterialQueryDto 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.Keyword), x => x.Code.Contains(q.Keyword!) || x.Name.Contains(q.Keyword!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Code), x => x.Code.Contains(q.Code!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Name), x => x.Name.Contains(q.Name!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.Spec), x => x.Spec!.Contains(q.Spec!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.DrawingNo), x => x.DrawingNo!.Contains(q.DrawingNo!))
- .WhereIF(!string.IsNullOrWhiteSpace(q.PlCategory), x => x.PlCategory == q.PlCategory)
- .WhereIF(!string.IsNullOrWhiteSpace(q.MaterialType), x => x.MaterialType == q.MaterialType)
- .WhereIF(!string.IsNullOrWhiteSpace(q.Language), x => x.Language == q.Language)
- .WhereIF(q.IsEnabled.HasValue, x => x.IsEnabled == q.IsEnabled.Value);
- var total = await query.CountAsync();
- var list = await query
- .OrderByDescending(x => x.CreatedAt)
- .Skip((q.Page - 1) * q.PageSize)
- .Take(q.PageSize)
- .ToListAsync();
- 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);
- return item == null ? NotFound() : Ok(item);
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0MaterialUpsertDto dto)
- {
- var entity = new AdoS0Material
- {
- CompanyRefId = dto.CompanyRefId,
- FactoryRefId = dto.FactoryRefId,
- Code = dto.Code,
- Name = dto.Name,
- NameEn = dto.NameEn,
- MaterialType = dto.MaterialType,
- Unit = dto.Unit,
- Spec = dto.Spec,
- PlCategory = dto.PlCategory,
- DrawingNo = dto.DrawingNo,
- Language = dto.Language,
- BizVersion = dto.BizVersion,
- ProductCode = dto.ProductCode,
- MaterialAttribute = dto.MaterialAttribute,
- DefaultLocationId = dto.DefaultLocationId,
- DefaultRackId = dto.DefaultRackId,
- StockTypeCode = dto.StockTypeCode,
- SafetyStock = dto.SafetyStock,
- ShelfLifeDays = dto.ShelfLifeDays,
- ExpireWarningDays = dto.ExpireWarningDays,
- PurchaseLeadDays = dto.PurchaseLeadDays,
- MinOrderQty = dto.MinOrderQty,
- MaxOrderQty = dto.MaxOrderQty,
- OrderMultiple = dto.OrderMultiple,
- PreparationLeadDays = dto.PreparationLeadDays,
- IsOnDemand = dto.IsOnDemand,
- SpecialReqType = dto.SpecialReqType,
- IsInspectionRequired = dto.IsInspectionRequired,
- InspectionDays = dto.InspectionDays,
- IsKeyMaterial = dto.IsKeyMaterial,
- IsMainMaterial = dto.IsMainMaterial,
- IsPreprocess = dto.IsPreprocess,
- IsAutoBatch = dto.IsAutoBatch,
- IsLabelRequired = dto.IsLabelRequired,
- IsBatchFifoReminder = dto.IsBatchFifoReminder,
- IsBatchFifoStrict = dto.IsBatchFifoStrict,
- InventoryTurnoverRate = dto.InventoryTurnoverRate,
- Remark = dto.Remark,
- IsEnabled = dto.IsEnabled,
- CreatedAt = DateTime.Now
- };
- entity.ForbidStatus = AdoS0SalesRules.ForbidStatusFromIsEnabled(dto.IsEnabled);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MaterialUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.CompanyRefId = dto.CompanyRefId;
- entity.FactoryRefId = dto.FactoryRefId;
- entity.Code = dto.Code;
- entity.Name = dto.Name;
- entity.NameEn = dto.NameEn;
- entity.MaterialType = dto.MaterialType;
- entity.Unit = dto.Unit;
- entity.Spec = dto.Spec;
- entity.PlCategory = dto.PlCategory;
- entity.DrawingNo = dto.DrawingNo;
- entity.Language = dto.Language;
- entity.BizVersion = dto.BizVersion;
- entity.ProductCode = dto.ProductCode;
- entity.MaterialAttribute = dto.MaterialAttribute;
- entity.DefaultLocationId = dto.DefaultLocationId;
- entity.DefaultRackId = dto.DefaultRackId;
- entity.StockTypeCode = dto.StockTypeCode;
- entity.SafetyStock = dto.SafetyStock;
- entity.ShelfLifeDays = dto.ShelfLifeDays;
- entity.ExpireWarningDays = dto.ExpireWarningDays;
- entity.PurchaseLeadDays = dto.PurchaseLeadDays;
- entity.MinOrderQty = dto.MinOrderQty;
- entity.MaxOrderQty = dto.MaxOrderQty;
- entity.OrderMultiple = dto.OrderMultiple;
- entity.PreparationLeadDays = dto.PreparationLeadDays;
- entity.IsOnDemand = dto.IsOnDemand;
- entity.SpecialReqType = dto.SpecialReqType;
- entity.IsInspectionRequired = dto.IsInspectionRequired;
- entity.InspectionDays = dto.InspectionDays;
- entity.IsKeyMaterial = dto.IsKeyMaterial;
- entity.IsMainMaterial = dto.IsMainMaterial;
- entity.IsPreprocess = dto.IsPreprocess;
- entity.IsAutoBatch = dto.IsAutoBatch;
- entity.IsLabelRequired = dto.IsLabelRequired;
- entity.IsBatchFifoReminder = dto.IsBatchFifoReminder;
- entity.IsBatchFifoStrict = dto.IsBatchFifoStrict;
- entity.InventoryTurnoverRate = dto.InventoryTurnoverRate;
- entity.Remark = dto.Remark;
- entity.IsEnabled = dto.IsEnabled;
- entity.ForbidStatus = AdoS0SalesRules.ForbidStatusFromIsEnabled(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.ForbidStatus = AdoS0SalesRules.ForbidStatusFromIsEnabled(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 = "删除成功" });
- }
- }
|