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; [ApiController] [Route("api/s0/manufacturing/person-skill-assignments")] [AllowAnonymous] [NonUnify] public class AdoS0MfgPersonSkillAssignmentsController : ControllerBase { private readonly SqlSugarRepository _rep; public AdoS0MfgPersonSkillAssignmentsController(SqlSugarRepository rep) { _rep = rep; } [HttpGet] public async Task GetPagedAsync([FromQuery] AdoS0EmpSkillsQueryDto q) { var page = q.EffectivePage; var pageSize = q.PageSize; (page, pageSize) = PagingGuard.Normalize(page, pageSize); var query = _rep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(q.Domain), x => x.Domain == q.Domain) .WhereIF(!string.IsNullOrWhiteSpace(q.Employee), x => x.Employee.Contains(q.Employee!)) .WhereIF(!string.IsNullOrWhiteSpace(q.Site), x => x.Site != null && x.Site.Contains(q.Site!)) .WhereIF(!string.IsNullOrWhiteSpace(q.SkillNo), x => x.SkillNo.Contains(q.SkillNo!)) .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x => x.Employee.Contains(q.Keyword!) || (x.EmployeeName != null && x.EmployeeName.Contains(q.Keyword!)) || x.SkillNo.Contains(q.Keyword!) || (x.SkillDescription != null && x.SkillDescription.Contains(q.Keyword!))); var total = await query.CountAsync(); var list = await query .OrderByDescending(x => x.UpdateTime ?? x.CreateTime) .Skip((page - 1) * pageSize) .Take(pageSize) .ToListAsync(); return Ok(new { total, page, pageSize, list }); } [HttpGet("{id:long}")] public async Task GetAsync(long id) { var item = await _rep.GetByIdAsync(id); return item == null ? NotFound() : Ok(item); } [HttpPost] public async Task CreateAsync([FromBody] AdoS0EmpSkillsUpsertDto dto) { var now = DateTime.Now; var entity = new AdoS0EmpSkills { Employee = dto.Employee.Trim(), EmployeeId = dto.EmployeeId, EmployeeName = dto.EmployeeName, Site = dto.Site, SkillNo = dto.SkillNo.Trim(), SkillDescription = dto.SkillDescription, SkillLevel = dto.SkillLevel, EfficiencyCoefficient = dto.EfficiencyCoefficient, DateSkill = dto.DateSkill, Domain = dto.Domain.Trim(), CreateUser = dto.CreateUser, CreateTime = dto.CreateTime ?? now, UpdateUser = dto.UpdateUser, UpdateTime = dto.UpdateTime }; await _rep.AsInsertable(entity).ExecuteReturnEntityAsync(); return Ok(entity); } [HttpPut("{id:long}")] public async Task UpdateAsync(long id, [FromBody] AdoS0EmpSkillsUpsertDto dto) { var entity = await _rep.GetByIdAsync(id); if (entity == null) return NotFound(); entity.Employee = dto.Employee.Trim(); entity.EmployeeId = dto.EmployeeId; entity.EmployeeName = dto.EmployeeName; entity.Site = dto.Site; entity.SkillNo = dto.SkillNo.Trim(); entity.SkillDescription = dto.SkillDescription; entity.SkillLevel = dto.SkillLevel; entity.EfficiencyCoefficient = dto.EfficiencyCoefficient; entity.DateSkill = dto.DateSkill; entity.Domain = dto.Domain.Trim(); entity.UpdateUser = dto.UpdateUser; entity.UpdateTime = dto.UpdateTime ?? DateTime.Now; await _rep.AsUpdateable(entity).ExecuteCommandAsync(); return Ok(entity); } [HttpDelete("{id:long}")] public async Task DeleteAsync(long id) { var item = await _rep.GetByIdAsync(id); if (item == null) return NotFound(); await _rep.DeleteAsync(item); return Ok(new { message = "删除成功" }); } }