using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model.ModelVm;
using Model.ModelVm.SysVm;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using Model.ModelVm.LogVm;
using WMS.IBLL.IBllAsnServer;
using WMS.IBLL.ILogServer;
using Model.ModelVm.BllAsnVm;
namespace Wms_09.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class BllAsnController : ControllerBase
{
#region 依赖注入
private readonly IArrivalNoticeServer _arrivalNoticeSvc; // 入库单据Svc
private readonly IPalletBindServer _PalletBindSvc; // 托盘绑定Svc
private readonly IBllBoxInfoServer _BoxInfoSvc;
private readonly ITaskServer _taskSvc; //入库任务Svc
private readonly IOperationASNServer _logSvc; //入库库操作日志Svc
private readonly IPalletUnbindServer _palletUnbind; //托盘解绑绑定
private readonly IAuditLogServer _auditLog; //审核记录
#endregion
#region 构造函数
public BllAsnController(IArrivalNoticeServer arrivalNoticeSvc, IPalletBindServer palletBindSvc,IBllBoxInfoServer bllBoxInfoSvc, ITaskServer taskSvc,IOperationASNServer logSvc, IPalletUnbindServer palletUnbind,IAuditLogServer auditLog)
{
_arrivalNoticeSvc = arrivalNoticeSvc;
_PalletBindSvc = palletBindSvc;
_BoxInfoSvc = bllBoxInfoSvc;
_taskSvc = taskSvc;
_logSvc = logSvc;
_palletUnbind = palletUnbind;
_auditLog = auditLog;
}
#endregion
#region 入库单据
///
/// 获取入库单信息
///
/// 查询条件
/// 入库单信息
[HttpPost]
public IActionResult GetArrivalNoticeList(ArrivalNoticeVm model)
{
try
{
var models = _arrivalNoticeSvc.GetArrivalNoticeList(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 GetArrivalNoticeDetailList(ArrivalNoticeDetailVm model)
{
try
{
var models = _arrivalNoticeSvc.GetArrivalNoticeDetailList(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 GetMaterialsList(GetMaterialsVm model)
{
try
{
var models = _arrivalNoticeSvc.GetMaterialsList(model);
return Ok(new { code = 0, msg = "物料信息", data = models });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
[HttpPost]
public IActionResult AddArrivalNotice(ArrivalNoticeVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _arrivalNoticeSvc.AddArrivalNotice(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "添加成功" });
}
if (strMesage.Contains("-1"))
{
return Ok(new { code = 0, msg = strMesage });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
[HttpPost]
public IActionResult EditArrivalNotice(ArrivalNoticeVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _arrivalNoticeSvc.EditArrivalNotice(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "编辑成功" });
}
if (strMesage.Contains("-1"))
{
return Ok(new { code = 0, msg = "部分成功" });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
[HttpPost]
public IActionResult DelArrivalNotice(ArrivalNoticeVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _arrivalNoticeSvc.DelArrivalNotice(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
[HttpPost]
public IActionResult DelArrivalNoticeDetail(ArrivalNoticeDetailVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _arrivalNoticeSvc.DelArrivalNoticeDetail(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 入库单撤销申请
///
///
///
///
[HttpGet]
public IActionResult CancelOrder(int id,string reason)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_arrivalNoticeSvc.CancelOrder(id,reason,int.Parse(userId));
return Ok(new { code = 0, msg = "入库单撤销申请成功" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 维护入库单备注信息
///
///
///
///
[HttpGet]
public IActionResult EditNoticeDemo(int id, string demo)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_arrivalNoticeSvc.EditNoticeDemo(id, demo, int.Parse(userId));
return Ok(new { code = 0, msg = "编辑备注成功" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 托盘绑定
[HttpPost]
public IActionResult GetPalletBindList(PalletBindVm model)
{
try
{
var models = _PalletBindSvc.GetPalletBindList(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 GetBoxInfoList(BoxInfoVm model)
{
try
{
var models = _PalletBindSvc.GetBoxInfoList(model, out int count);
return Ok(new { code = 0, count, msg = "箱支明细信息", data = models });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
[HttpGet]
public IActionResult GetBoxInfoByBoxNo(string boxNo, string boxNo3)
{
try
{
var models = _PalletBindSvc.GetBoxInfoByBoxNo(boxNo, boxNo3);
return Ok(new { code = 0, count= models.Count, msg = "箱支明细信息", data = models });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除托盘绑定信息
///
///
///
[HttpPost]
public IActionResult DelPalletBind(IdVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_PalletBindSvc.DelPalletBind(model.Id, int.Parse(userId));
return Ok(new { code = 0, count = 0, msg = "删除成功", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除绑定的箱码信息
///
/// 箱号
///
[HttpGet]
public IActionResult DelBindBoxInfo(string boxNo)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_PalletBindSvc.DelBindBoxInfo(boxNo,int.Parse(userId));
return Ok(new { code = 0, count = 0, msg = "删除成功", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 托盘绑定撤销申请
///
///
/// 申请原因
///
[HttpGet]
public IActionResult CancelPalletBind(int id, string reason)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_PalletBindSvc.CancelPalletBind(id, reason,int.Parse(userId));
return Ok(new { code = 0, count = 0, msg = "托盘绑定撤销申请成功", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 根据箱码获取未组盘的箱码信息
///
///
///
///
///
[HttpGet]
public IActionResult GetBoxInfoListByBoxCode(string boxNo, string isContinue, string boxNo2)
{
try
{
var list = _BoxInfoSvc.GetBoxInfoList(boxNo, isContinue, boxNo2);
var num = 0;
if (list!=null)
{
num = list.Count;
}
return Ok(new { code = 0, count = num, msg = "箱码信息", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 指定储位
///
/// 指定储位数据源(正常的空储位)
///
///
///
[HttpPost]
public IActionResult GetLocateList(GetOkLocateVm model)
{
try
{
var models = _PalletBindSvc.GetLocateList("W01",model.RoadwayNo,model.Row,model.Column,model.Layer,model.LocateNo,model.Page,model.Limit, 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 SaveAppointSlot(SaveLocateVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
throw new Exception("未获取到用户信息");
}
_PalletBindSvc.SaveAppointSlot(model.BindId,model.LocateId,int.Parse(userId));
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 GetBllBoxInfoList(BoxInfoVm model)
{
try
{
var models = _BoxInfoSvc.GetBoxInfoList(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 AddBllBoxInfo(BoxInfoVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _BoxInfoSvc.AddBoxInfo(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "添加成功" });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = "添加失败:" + e.Message });
}
}
[HttpPost]
public IActionResult DelBllBoxInfo(BoxInfoVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
string strMesage = _BoxInfoSvc.DelBoxInfo(model);
if (strMesage == "")
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = strMesage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 物料信息录入 导入
///
///
///
[HttpPost]
public IActionResult ImportBllBoxInfo(BoxInfoVms models)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
models.CreateUser = int.Parse(UserId);
string strMessage = _BoxInfoSvc.ImportBoxInfo(models);
if (strMessage.Contains("-1"))
{
return Ok(new { code = 1, msg = strMessage });
}
else
{
return Ok(new { code = 0, msg = strMessage });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 入库日志
///
/// 获取入库任务信息
///
///
///
[HttpPost]
public IActionResult GetArrivalTaskList(GetTaskVm model)
{
try
{
var type = new List() { "0" };
var bolls = _taskSvc.GetTaskList(type, model.Type, model.Status, model.TaskNo, model.IsSuccess, model.PalletNo, model.Msg, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "入库任务信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 取消入库任务
///
///
///
[HttpGet]
public IActionResult CancelAsnTask(string taskNo)
{
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 = "未获取到当前操作人信息" });
}
_PalletBindSvc.CancelAsnTask(taskNo, int.Parse(userId));
return Ok(new { code = 0, msg = "取消任务已完成", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 完成入库任务
///
///
///
[HttpGet]
public IActionResult FinishAsnTask(string taskNo)
{
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 = "未获取到当前操作人信息" });
}
_PalletBindSvc.ArrivalSuccess(taskNo, int.Parse(userId));
return Ok(new { code = 0, msg = "成功完成任务", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 操作日志
///
/// 获取入库操作日志信息
///
///
///
[HttpPost]
public IActionResult GetLogOperationAsnList(GetOperationVm model)
{
try
{
var bolls = _logSvc.GetLogOperationAsnList(model.MenuName, model.Type, model.Msg, model.StartTime, model.EndTime, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "入库操作日志信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 托盘解绑绑定
[HttpPost]
public IActionResult GetPalletUnbindList(PalletUnbindVm model)
{
try
{
int count = 0;
var list = _palletUnbind.GetPalletUnbindList(model, out count);
return Ok(new { code = 0, count = count, msg = "托盘解绑绑定列表", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, count = 0, msg = e.Message });
}
}
[HttpPost]
public IActionResult GetPalletUnbindList2(PalletUnbindVm model)
{
try
{
int count = 0;
var list = _palletUnbind.GetPalletUnbindList2(model, out count);
return Ok(new { code = 0, count = count, msg = "托盘解绑绑定箱码列表", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, count = 0, msg = e.Message });
}
}
#endregion
#region 审核记录
[HttpPost]
public IActionResult GetAuditLogList(AuditLogVm model)
{
try
{
var list = _auditLog.GetAuditLogList(model, out int count);
return Ok(new { code = 0, count, msg = "审核记录列表", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, count = 0, msg = e.Message });
}
}
///
/// 编辑审核
///
///
///
[HttpPost]
public IActionResult EditAudit(EditAuditVm 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 = "未获取到当前操作人信息" });
}
_auditLog.EditAudit(model.Id,model.Status,model.Opinion, int.Parse(userId));
return Ok(new { code = 0, count=0, msg = "审核记录列表", data = "" });
}
catch (Exception e)
{
return Ok(new { code = 1, count = 0, msg = e.Message });
}
}
#endregion
}
}