using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using System; using WMS.Entity.BllQualityEntity; using WMS.IBLL.IBllQualityServer; using Model.ModelVm.BllQualityVm; using Model.ModelVm; using Wms.Tools; using Microsoft.Extensions.Options; namespace Wms.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize] public class BllQualityController : ControllerBase { private readonly IQualityInspectServer _qualityServer; //质检信息 private readonly IInspectionRequest _inspectionRequestServer; // 质检请验 private readonly ApiUrlConfig _config; //接口交互路径 /// /// 构造函数 /// /// 质检信息 public BllQualityController(IQualityInspectServer qualityServer,IInspectionRequest inspectionRequestServer, IOptions setting) { _qualityServer = qualityServer; _inspectionRequestServer = inspectionRequestServer; _config = setting.Value; } #region 质检信息 /// /// 获取质检信息 /// /// 质检信息实体模型 /// [HttpPost] public IActionResult GetBllQualityList(BllQualityInspect model) { try { var bolls = _qualityServer.GetBllQualityList(model); return Ok(new { code = 0, msg = "质检信息", data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 添加物料质检信息 /// /// 质检信息实体模型 /// [HttpPost] public IActionResult InsertQuality(BllQualityInspect model) { try { //获取当前登录的用户ID var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } model.CreateUser = int.Parse(userId); _qualityServer.InsertQuality(model); return Ok(new { code = 0, count = 0, msg = "物料质检信息操作成功", data = "" }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion #region 质检请验 /// /// 获取请验单信息 /// /// 查询条件 /// [HttpPost] public IActionResult GetInspectionRequest(BllQualityInspectionRequestVm model) { try { var models = _inspectionRequestServer.GetInspectionRequest(model, out int count); return Ok(new { code = 0, count, msg = "获取请验单信息成功", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 获取请验单对应的取样信息 /// /// 查询条件 /// [HttpPost] public IActionResult GetSamplingDetails(BllSamplingDetailsVm model) { try { var models = _inspectionRequestServer.GetSamplingDetails(model, out int count); return Ok(new { code = 0, count, msg = "获取取样信息功能", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 删除取样记录 /// /// 主键ID /// [HttpPost] public IActionResult DelSamplingDetails(IdVm model) { try { var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var models = _inspectionRequestServer.DelSamplingDetails(model, int.Parse(userId)); return Ok(new { code = 0, count=0, msg = "删除取样记录成功", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 发送请验单据 /// /// 主键ID /// [HttpPost] public IActionResult SendInspectionRequest(IdVm model) { try { var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userName = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value; string url = _config.WcsHost + _config.IssueComApiUrl; var models = _inspectionRequestServer.SendInspectionRequest(model, int.Parse(userId),url,userName); return Ok(new { code = 0, count=0, msg = "向Limes请验成功!", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 删除请验单信息 /// /// 主键ID /// [HttpPost] public IActionResult DelInspectionRequest(IdVm model) { try { var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var models = _inspectionRequestServer.DelInspectionRequest(model, int.Parse(userId)); return Ok(new { code = 0, count=0, msg = "删除请验单信息成功", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 执行取样出库动作 /// /// 主键ID /// [HttpPost] public IActionResult OutWhInspectionRequest(IdVm model) { try { var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } string url = _config.WcsHost + _config.IssueComApiUrl; var models = _inspectionRequestServer.OutWhInspectionRequest(model, int.Parse(userId), url); return Ok(new { code = 0, count=0, msg = "取样出库操作成功!", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 完成请验单据 /// /// 主键ID /// [HttpPost] public IActionResult ClossInspectionRequest(IdVm model) { try { var claimsIdentity = this.User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return Ok(new { code = 1, msg = "未获取到当前操作人信息" }); } string url = _config.WcsHost + _config.IssueComApiUrl; var models = _inspectionRequestServer.ClossInspectionRequest(model, int.Parse(userId),url); return Ok(new { code = 0, msg = "完成请验单", data = models }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion /// /// 获取库存批次号集合 /// /// [HttpGet] public IActionResult GetLotNoList() { try { var bolls = _qualityServer.GetLotNoList(); return Ok(new { code = 0, msg = "批次号集合", data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } } }