using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Newtonsoft.Json; using Utility; using Utility.Tools; using WMS.IBLL.ILogServer; using WMS.IBLL.ISysServer; using WMS.Entity.SysEntity; using SqlSugar; using Model.ModelDto.SysDto; using Model.ModelVm; using Model.ModelVm.SysVm; using System.Reflection.Metadata.Ecma335; using System.Security.Cryptography; using Model.ModelDto; using Model.ModelDto.LogDto; using Newtonsoft.Json.Linq; using Wms.Tools; using Microsoft.Extensions.Options; namespace Wms.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize] public class SysController : ControllerBase { private readonly IWareHouseServer _wareHouseSvc; //仓库 private readonly IStorageAreaServer _areaSvc; //区域 private readonly IStorageRoadwayServer _roadwaySvc; //巷道 private readonly IStorageLocatServer _locatSvc; //储位 private readonly IPalletsServer _palletSvc; //条码 private readonly IPalletTrackServer _palletTrackSvc; //托盘 private readonly IDictionaryServer _dic; //数据字典 private readonly IMenuServer _menuSvc; //菜单 private readonly IOperationSysServer _operation; //操作日志 private readonly IExceptionServer _table; //异常处理 private readonly IHeaderSettingsServer _headerSet;//表头设置 private readonly IMaterialCategoryServer _category;//物料类别 private readonly IArchivingServer _archiving;//数据归档 private readonly ApiUrlConfig _config; //接口交互路径 /// /// 构造函数 /// /// 仓库 /// 区域 /// 巷道 /// 储位 /// 条码 /// 托盘 /// 菜单 /// 数据字典 /// 操作日志 /// 异常处理 /// 物料类别 public SysController(IOptions setting, IWareHouseServer wareHouseSvc, IStorageAreaServer areaSvc, IStorageRoadwayServer roadwaySvc, IStorageLocatServer locatSvc, IPalletsServer palletSvc, IPalletTrackServer palletTrackSvc, IMenuServer menuSvc, IDictionaryServer dic, IOperationSysServer operation, IExceptionServer table, IHeaderSettingsServer headerSet, IMaterialCategoryServer category, IArchivingServer archiving) { _config = setting.Value; _wareHouseSvc = wareHouseSvc; //仓库 _areaSvc = areaSvc; //区域 _roadwaySvc = roadwaySvc; //巷道 _locatSvc = locatSvc; //储位 _palletSvc = palletSvc; //条码 _palletTrackSvc = palletTrackSvc; //托盘 _menuSvc = menuSvc; //菜单 _dic = dic; //数据字典 _operation = operation; //操作日志 _table = table; //异常处理 _headerSet = headerSet;//表头设置 _category = category;//物料类别 _archiving = archiving;//数据归档 } #region 菜单管理 /// /// 获取菜单信息列表 /// /// 菜单名称 /// 父级菜单号 /// 菜单号 /// 层级 /// [HttpPost] public IActionResult GetMenuList(string MenuName, string pMenuNo, string MenuNo, string level) { //查询菜单信息列表 List menulist = _menuSvc.GetMenuList(MenuName, pMenuNo, MenuNo, level); return Ok(new { data = menulist, code = 0, msg = "成功" }); } /// /// 根据层级获取菜单列表(分配权限用到) /// /// /// [HttpGet] public IActionResult GetMenuListForRight(string level) { //获取当前操作用户id 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("未获取到用户信息"); } //查询菜单信息列表 List menulist = _menuSvc.GetMenuListForRight(level, UserId); return Ok(new { data = menulist, code = 0, msg = "成功" }); } /// /// 获取模块菜单 /// /// [HttpPost] public IActionResult GetParentMenuList() { //查询菜单信息列表 List menulist = _menuSvc.GetParentMenuList(); return Ok(new { data = menulist, code = 0, msg = "成功" }); } /// /// 根据父级菜单号获取菜单信息 /// /// 菜单号 /// [HttpGet] public IActionResult GetMenuByParentNo(string MenuNo) { List menulist = _menuSvc.GetMenuByParentNo(MenuNo); return Ok(new { data = menulist, code = 0, msg = "成功" }); } /// /// 根据id获取菜单信息列表 /// /// 菜单id /// [HttpGet] public IActionResult GetMenuListById(int id) { SysFunctionMenu menu = _menuSvc.GetMenuListById(id); return Ok(new { data = menu, code = 0, msg = "成功" }); } /// /// 新增菜单信息 /// /// 菜单DTO模型 /// /// 捕获异常 [HttpPost] public async Task AddMenu(FunctionMenuDto menudto) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //创建人 menudto.CreateUser = uid; int i = await _menuSvc.InsertMenu(menudto); //判断是否新增成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "新增失败" }); } else if (i == 3) { return Ok(new { data = i, code = 3, msg = "菜单号必须唯一" }); } else { await _operation.InsertOperation("系统设置", "菜单管理", menudto.MenuNo, "添加", "添加菜单信息 菜单编号:" + menudto.MenuNo, uid); return Ok(new { data = i, code = 0, msg = "新增成功" }); } } catch (Exception ex) { return Ok(new { data = "", code = 3, msg = "新增菜单信息异常:" + ex.Message }); } } /// /// 删除菜单信息 /// 单删 /// /// 菜单Id /// /// 捕获异常 [HttpGet] public async Task DelMenu(int Id) { //捕获异常 try { SysFunctionMenu menu = _menuSvc.GetMenuListById(Id); //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //创建人 menu.CreateUser = uid; int i = await _menuSvc.DeleteMenu(menu); //判断是否删除成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "删除失败" }); } else { await _operation.InsertOperation("系统设置", "菜单管理", menu.MenuNo, "删除", "删除菜单信息 菜单号:" + menu.MenuNo, uid); return Ok(new { data = i, code = 0, msg = "删除成功" }); } } catch (Exception ex) { //抛出异常 throw new Exception("删除菜单信息异常", ex); } } /// /// 编辑菜单信息 /// /// 菜单视图模型 /// /// 捕获异常 [HttpPost] public async Task UpdateMenu(FunctionMenuVm menuvm) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //更改人 menuvm.UpdateUser = uid; int i = await _menuSvc.UpdateMenu(menuvm); //判断是否编辑成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "编辑失败" }); } else { await _operation.InsertOperation("系统设置", "菜单管理", menuvm.MenuNo, "修改", "修改菜单信息 菜单编号:" + menuvm.MenuNo, uid); return Ok(new { data = i, code = 0, msg = "编辑成功" }); } } catch (Exception ex) { return Ok(new { data = "", code = 3, msg = "编辑菜单信息异常:" + ex.Message }); } } #endregion #region 数据字典 #region csc /// /// 获取字典信息 /// /// /// [HttpGet] public IActionResult GetDictionaryByParentNo(string parentNo) { try { var bolls = _dic.GetDictionaryByParentNo(parentNo); return Ok(new { code = 0, msg = "字典信息", data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion #region yyk /// /// 获取字典信息列表 /// /// 字典名称 /// 父级字典号 /// 层级 /// 允许编辑 /// 允许新增 /// [HttpGet] public IActionResult GetDicList(string DictName, string DictNo, string Level, string IsEdit, string IsAdd = "") { List diclist = _dic.GetDicList(DictName, DictNo, Level, IsEdit, IsAdd); return Ok(new { data = diclist, code = 0, msg = "成功" }); } /// /// 获取父级字典号(根据层级根目录) /// /// [HttpGet] public IActionResult GetDicParentListByLevel() { List diclist = _dic.GetDicParentListByLevel(); return Ok(new { data = diclist, code = 0, msg = "成功" }); } /// /// 根据id查询字典信息 /// /// 字典id /// [HttpGet] public IActionResult GetDicById(int id) { SysDictionary dic = _dic.GetDicById(id); return Ok(new { data = dic, code = 0, msg = "成功" }); } /// /// 新增字典信息 /// /// 数据字典dto /// /// 捕获异常 [HttpPost] public async Task AddDic(DictionaryDto dicdto) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //创建人 dicdto.CreateUser = uid; //新增 int i = await _dic.AddDic(dicdto); //判断是否新增成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "失败" }); } else if (i == 3) { await _operation.InsertOperation("系统设置", "数据字典", dicdto.DictNo, "添加", "添加字典信息 字典号:" + dicdto.DictNo, uid); return Ok(new { data = i, code = 3, msg = "字典号必须唯一" }); } else { await _operation.InsertOperation("系统设置", "数据字典", dicdto.DictNo, "添加", "添加字典信息 字典号:" + dicdto.DictNo, uid); return Ok(new { data = i, code = 0, msg = "成功" }); } } catch (Exception ex) { //抛出异常 throw new Exception("新增字典异常", ex); } } /// /// 删除字典信息 /// /// 字典id /// /// 捕获异常 [HttpGet] public async Task DelDic(int id) { //捕获异常 try { SysDictionary dic = _dic.GetDicById(id); //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //更改人 dic.UpdateUser = uid; //删除 int i = await _dic.DelDic(dic); //判断是否删除成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "失败" }); } else { await _operation.InsertOperation("系统设置", "数据字典", dic.DictNo, "删除", "删除字典信息 字典号:" + dic.DictNo, uid); return Ok(new { data = i, code = 0, msg = "成功" }); } } catch (Exception ex) { //抛出异常 throw new Exception("删除字典异常", ex); } } /// /// 编辑字典信息 /// /// 字典dto /// /// 捕获异常 [HttpPost] public async Task ExitDic(DictionaryDto dicdto) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //更改人 dicdto.UpdateUser = uid; //编辑 int i = await _dic.ExitDic(dicdto); //判断是否编辑成功 if (i == 0) { return Ok(new { data = i, code = 1, msg = "失败" }); } else { await _operation.InsertOperation("系统设置", "数据字典", dicdto.DictNo, "修改", "修改字典信息 字典号:" + dicdto.DictNo, uid); return Ok(new { data = i, code = 0, msg = "成功" }); } } catch (Exception ex) { //抛出异常 throw new Exception("编辑字典异常", ex); } } #endregion #endregion #region 仓库管理 /// /// 获取仓库信息 /// /// /// [HttpPost] public IActionResult GetWarehouseList(GetWareHouseVm model) { try { var bolls = _wareHouseSvc.GetWarehouseList(model.WareHouseNo, model.WareHouseName, model.Type, 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 }); } } /// /// 获取单条仓库信息 /// /// ID /// [HttpPost] public async Task GetWarehouse(IdVm model) { try { var bolls = await _wareHouseSvc.GetWarehouse(model.Id); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 修改仓库信息 /// /// /// [HttpPost] public async Task EditWarehouse(EditWareHouseVm 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 = "为获取到当前操作人信息" }); } var bolls = await _wareHouseSvc.EditWareHouse(model.Id, model.WareHouseNo, model.WareHouseName, model.Type, model.Temp, model.Row, model.Col, model.Layer, int.Parse(userId)); if (bolls) { await _operation.InsertOperation("仓库设置", "仓库管理", model.WareHouseNo, "修改", "修改仓库信息 仓库号:" + model.WareHouseNo, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 获取仓库信息(前端下拉框可用) /// /// [HttpGet] public async Task GetWarehouseDic() { try { var bolls = await _wareHouseSvc.GetWareHouseDic(); return Ok(new { code = 0, msg = "仓库信息", data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion #region 区域管理 /// /// 获取区域信息 /// /// /// [HttpPost] public IActionResult GetStorageAreaList(GetAreaVm model) { try { var bolls = _areaSvc.GetStorageAreaList(model.AreaName, model.WareHouseNo, model.Status, model.Type, 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 }); } } /// /// 获取单条区域信息 /// /// /// [HttpPost] public IActionResult GetStorageArea(IdVm model) { try { var bolls = _areaSvc.GetStorageArea(model.Id); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 获取区域信息(根据仓库号) /// /// 仓库号 /// [HttpGet] public IActionResult GetStorageAreaByHouseNo(string wareHouseNo) { try { var bolls = _areaSvc.GetStorageAreaByHouseNo(wareHouseNo); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 添加区域信息 /// /// 模型 /// [HttpPost] public IActionResult InsertStorageArea(SysStorageArea 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); string bolls = _areaSvc.InsertStorageArea(model); var arr = bolls.Split(":"); if (arr[0] != "-1") { SysStorageArea area = _areaSvc.GetStorageMaxArea(); _operation.InsertOperation("仓库设置", "区域管理", area.AreaNo, "添加", "添加区域信息 区域号:" + area.AreaNo, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = bolls, data = "" }); } else { return Ok(new { code = 1, msg = bolls, data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 修改区域信息 /// /// 模型 /// [HttpPost] public IActionResult EditStorageArea(EditAreaVm 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 = "为获取到当前操作人信息" }); } var bolls = _areaSvc.EditStorageArea(model.Id, model.AreaName, model.Priority, model.Type, model.Temperature, model.DeviceCode, int.Parse(userId)); if (bolls) { SysStorageArea area = _areaSvc.GetStorageArea(model.Id); _operation.InsertOperation("仓库设置", "区域管理", area.AreaNo, "修改", "修改区域信息 区域号:" + area.AreaNo, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 修改区域状态 /// /// 模型 /// [HttpPost] public IActionResult EditStorageAreaStatus(EditAreaStatusVm 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 = "为获取到当前操作人信息" }); } var bolls = _areaSvc.EditStorageAreaStatus(model.Id, model.Status, int.Parse(userId)); if (bolls) { SysStorageArea area = _areaSvc.GetStorageArea(model.Id); string msg = "区域状态 区域号:" + area.AreaNo; _operation.InsertOperation("仓库设置", "区域管理", area.AreaNo, "修改", model.Status == "0" ? "启用" + msg : "停用" + msg, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑状态成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑状态失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = "请联系管理员/" + e.Message }); } } #endregion #region 巷道管理 /// /// 获取巷道信息 /// /// /// [HttpPost] public IActionResult GetStorageRoadwayList(GetRoadwayVm model) { try { var bolls = _roadwaySvc.GetStorageRoadwayList(model.WareHouseNo, model.RoadwayName, model.Status, model.Type, 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 }); } } /// /// 获取单条巷道信息 /// /// /// [HttpPost] public IActionResult GetStorageRoadway(IdVm model) { try { var bolls = _roadwaySvc.GetStorageRoadway(model.Id); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 获取巷道信息(根据仓库号) /// /// 仓库号 /// [HttpGet] public IActionResult GetStorageRoadwayByHouseNo(string wareHouseNo) { try { var bolls = _roadwaySvc.GetStorageRoadwayByHouseNo(wareHouseNo); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 修改巷道信息 /// /// 模型 /// [HttpPost] public IActionResult EditStorageRoadway(EditRoadwayVm model) { if (ModelState.IsValid) { 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 = "为获取到当前操作人信息" }); } var bolls = _roadwaySvc.EditStorageRoadway(model.Id, model.RoadwayName, model.Priority, model.Type, model.Temp,model.Availa, int.Parse(userId)); if (bolls) { SysStorageRoadway storage = _roadwaySvc.GetStorageRoadway(model.Id); _operation.InsertOperation("仓库设置", "巷道管理", storage.RoadwayNo, "修改", "修改巷道信息 巷道号:" + storage.RoadwayNo, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } else //数据格式错误 { return Ok(new { code = 1, msg = "数据格式错误" }); } } /// /// 修改巷道状态 /// /// 模型 /// [HttpPost] public IActionResult EditStorageRoadwayStatus(EditRoadwayStatusVm model) { if (ModelState.IsValid) { 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 = "为获取到当前操作人信息" }); } var bolls = _roadwaySvc.EditStorageRoadwayStatus(model.Id, model.Status, int.Parse(userId)); if (bolls) { SysStorageRoadway storage = _roadwaySvc.GetStorageRoadway(model.Id); string msg = "巷道状态 巷道号:" + storage.RoadwayNo; _operation.InsertOperation("仓库设置", "巷道管理", storage.RoadwayNo, "修改", model.Status == "0" ? "启用" + msg : "停用" + msg, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑状态成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑状态失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } else //数据格式错误 { return Ok(new { code = 1, msg = "数据格式错误" }); } } #endregion #region 储位管理 /// /// 获取储位信息 /// /// /// [HttpPost] public IActionResult GetStorageLocatList(GetLocateVm model) { try { var bolls = _locatSvc.GetStorageLocatList(model.HouseNo, model.RoadwayNo, model.AreaNo, model.Status, model.Flag, model.Locat, model.Row, model.Col, model.Layer, 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 }); } } /// /// 获取单条储位信息 /// /// /// [HttpPost] public IActionResult GetStorageLocat(IdVm model) { try { var bolls = _locatSvc.GetStorageLocat(model.Id); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, ErrorMsg = e.Message }); } } /// /// 添加立体库储位信息 /// /// 模型 /// [AllowAnonymous] [HttpPost] public async Task AddStorageLocat(AddLocateVm model) { if (ModelState.IsValid) { try { ////获取当前登录的用户ID //var claimsIdentity = this.User.Identity as ClaimsIdentity; //if (claimsIdentity == null) //{ // return Ok(new { code = 400, ErrorMsg = "为获取到当前操作人信息" }); //} //var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; //if (string.IsNullOrWhiteSpace(userId)) //{ // return Ok(new { code = 400, ErrorMsg = "为获取到当前操作人信息" }); //} var bolls = await _locatSvc.AddStorageLocat(model.HouseNo, model.RoadwayNo, model.AreaNo, model.Row, model.Col, model.Layer, model.Depth.ToString(), 1); if (bolls > 0) { await _operation.InsertOperation("仓库设置", "储位管理", model.RoadwayNo, "添加", "添加储位信息 储位号:" + model.RoadwayNo, 1); return Ok(new { code = 200, ErrorMsg = "添加成功", data = bolls }); } else { return Ok(new { code = 400, ErrorMsg = "添加失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message }); } } else //数据格式错误 { return Ok(new { code = 400, ErrorMsg = "数据格式错误" }); } } /// /// 添加平库储位信息 /// /// 模型 /// [AllowAnonymous] [HttpPost] public async Task AddPkStorageLocat(AddLocateVm model) { if (ModelState.IsValid) { try { //获取当前登录的用户ID //var claimsIdentity = this.User.Identity as ClaimsIdentity; //if (claimsIdentity == null) //{ // return Ok(new { code = 400, ErrorMsg = "为获取到当前操作人信息" }); //} //var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; //if (string.IsNullOrWhiteSpace(userId)) //{ // return Ok(new { code = 400, ErrorMsg = "为获取到当前操作人信息" }); //} var bolls = await _locatSvc.AddPkStorageLocat(model, 1); if (bolls > 0) { await _operation.InsertOperation("仓库设置", "储位管理", model.RoadwayNo, "添加", "添加储位信息 储位号:" + model.RoadwayNo, 1); return Ok(new { code = 200, ErrorMsg = "添加成功", data = bolls }); } else { return Ok(new { code = 400, ErrorMsg = "添加失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message }); } } else //数据格式错误 { return Ok(new { code = 400, ErrorMsg = "数据格式错误" }); } } /// /// 修改储位信息 /// /// 模型 /// [HttpPost] public IActionResult EditStorageLocat(EditLocateVm model) { if (ModelState.IsValid) { 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 = "为获取到当前操作人信息" }); } var bolls = _locatSvc.EditStorageLocat(model, _config.WcsHost + _config.EditLocateUrl,int.Parse(userId)); if (bolls) { SysStorageLocat storage = _locatSvc.GetStorageLocat(model.Id); _operation.InsertOperation("仓库设置", "储位管理", storage.LocatNo, "修改", "修改储位信息 储位号:" + storage.LocatNo, Convert.ToInt32(userId)); return Ok(new { code = 0, msg = "编辑成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } else //数据格式错误 { return Ok(new { code = 1, msg = "数据格式错误" }); } } /// /// 修改储位状态标识信息集合 /// /// 模型 /// [AllowAnonymous] [HttpPost] public IActionResult EditStorageLocatList(EditLocateListVm model) { if (ModelState.IsValid) { 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 = "为获取到当前操作人信息" }); } var bolls = _locatSvc.EditStorageLocatList(model, _config.WcsHost + _config.EditLocateUrl, 1);//int.Parse(userId) if (bolls) { SysStorageLocat storage = _locatSvc.GetStorageLocat(model.Id[0]); string msg = "储位状态 储位号:" + storage.RoadwayNo; if (model.Id.Count > 1) { foreach (var item in model.Id) { storage = _locatSvc.GetStorageLocat(item); _operation.InsertOperation("仓库设置", "储位管理", storage.LocatNo, "批量编辑", "批量修改储位信息 储位号:" + storage.LocatNo, Convert.ToInt32(userId)); } } else { _operation.InsertOperation("仓库设置", "储位管理", storage.LocatNo, "修改", "修改储位信息 储位号:" + storage.LocatNo, Convert.ToInt32(userId)); } return Ok(new { code = 0, msg = "编辑成功", data = "" }); } else { return Ok(new { code = 1, msg = "编辑失败", data = "" }); } } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } else //数据格式错误 { return Ok(new { code = 1, msg = "数据格式错误" }); } } #endregion #region 托盘条码管理 /// /// 查询托盘条码信息 /// /// /// [HttpPost] public IActionResult GetPalletsList(GetPalletVm model) { try { var bolls = _palletSvc.GetPalletsList(model.PalletNo, model.Status, 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 GetPalletTrackList(string palletNo) { try { var bolls = _palletTrackSvc.GetPalletTrackByPallNoList(palletNo); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, ErrorMsg = e.Message }); } } /// /// 添加托盘信息 /// /// 模型 /// [HttpPost] public IActionResult AddPallets(AddPalletVm 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 = "为获取到当前操作人信息" }); } _palletSvc.AddPallets(model.PalletNo, model.LocatNo, model.DeviceCode, int.Parse(userId)); return Ok(new { code = 0, msg = "添加成功", data = "" }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 获取托盘条码信息 /// /// /// [HttpPost] public IActionResult GetPalletsNo(GetImgBarVm model) { try { var bolls = _palletSvc.GetPalletsNo(model.PalletNo); return Ok(new { code = 0, data = bolls }); } catch (Exception e) { return Ok(new { code = 1, ErrorMsg = e.Message }); } } /// /// 获取条形码 /// /// /// [HttpPost] public IActionResult GetImgBar(GetImgBarVm model) { try { List list = new List(); var stockCode = _palletSvc.GetPalletsNo(""); if (stockCode != model.PalletNo) { throw new Exception("当前显示的条码不是最新条码,请重新添加"); } string str = model.PalletNo.Substring(3, 5); string remove = model.PalletNo.Substring(0, 3); int sibelius = Convert.ToInt16(str); for (int i = 0; i < model.GroupCount; i++) { if (i != 0) { sibelius += 1; } string code = remove + Convert.ToString(sibelius).PadLeft(5, '0'); for (int j = 0; j < model.SameCount; j++) { var re = BarcodeHelper.GetCodeBarBase64(code, 80, 50); list.Add(re); } } return Ok(new { code = 0, data = list }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 补打条形码 /// /// /// [HttpPost] public IActionResult GetImgBarReprint(GetImgBarVm model) { try { List list = new List(); for (int i = 0; i < model.GroupCount; i++) { for (int j = 0; j < model.SameCount; j++) { var re = BarcodeHelper.GetCodeBarBase64(model.PalletNo, 80, 50); list.Add(re); } } return Ok(new { code = 0, data = list }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion #region 异常处理 /// /// 获取异常处理信息列表 /// /// 异常号 /// 托盘号 /// 异常储位 /// 关联单号 /// 关联任务号 /// 异常类型 /// 状态 /// [HttpGet] public IActionResult GetTableList(string exceptionNo, string palletNo, string excLocatNo, string orderNo, string taskNo, string type, string status) { List tabledto = _table.GetTableList(exceptionNo, palletNo, excLocatNo, orderNo, taskNo, type, status); return Ok(new { data = tabledto, code = 0, msg = "成功" }); } /// /// 根据id获取异常信息 /// /// 异常id /// [HttpGet] public IActionResult GetTableById(int id) { SysException table = _table.GetTableById(id); return Ok(new { data = table, code = 0, msg = "成功" }); } /// /// 处理异常状态-空取异常 /// /// 异常处理dto /// /// 捕获异常 [HttpPost] public IActionResult EditStatus(ExceptionDto tabledto) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //更改人 tabledto.UpdateUser = uid; string strMesage = _table.EditStatus(tabledto); if (strMesage == "") { return Ok(new { code = 0, msg = "处理成功" }); } else { return Ok(new { code = 1, msg = strMesage }); } } catch (Exception ex) { //抛出异常 throw new Exception("处理状态异常", ex); } } /// /// 处理异常状态-满入异常 /// /// 异常处理dto /// /// 捕获异常 [HttpPost] public IActionResult EditStatus2(ExceptionDto tabledto) { //捕获异常 try { //获取当前操作用户id var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; int uid = Convert.ToInt32(userId); //更改人 tabledto.UpdateUser = uid; string strMesage = _table.EditStatus2(tabledto); if (strMesage == "") { return Ok(new { code = 0, msg = "处理成功" }); } else { return Ok(new { code = 1, msg = strMesage }); } } catch (Exception ex) { //抛出异常 throw new Exception("处理状态异常", ex); } } #endregion #region 储位图例 #region 立库 /// /// 根据仓库 排 /// /// 仓库 /// 巷道号 /// 排 /// 深度 /// [HttpGet] public IActionResult GetStorageLocatLists(string wareHouseNo, string roadway, string row, string depth) { //获取储位信息 List storagelist = _locatSvc.GetStorageLocatLists(wareHouseNo, roadway, row, depth); //获取最大层级 int maxLayer = _locatSvc.GetMaxLayer(wareHouseNo, roadway, row); //获取最大列数 int maxColumn = _locatSvc.GetColumn(wareHouseNo, roadway, row); return Ok(new { data = storagelist, code = 0, maxlayer = maxLayer, maxcolumn = maxColumn, msg = "" }); } /// /// 根据仓库获取储位深度 /// /// /// [HttpGet] public IActionResult GetDepth(string wareHouseNo) { List depth = _locatSvc.GetDepth(wareHouseNo); return Ok(new { data = depth, code = 0, msg = "成功" }); } /// /// 根据排获取储位深度 /// /// /// [HttpGet] public IActionResult GetRowDepth(string row) { List depth = _locatSvc.GetRowDepth(row); return Ok(new { data = depth, code = 0, msg = "成功" }); } /// /// 获取该仓库排数 /// /// 仓库号 /// [HttpGet] public IActionResult GetStorageLocatRow(string wareHouseNo) { List maxrow = _locatSvc.GetStorageLocatRow(wareHouseNo); return Ok(new { data = maxrow, code = 0, msg = "成功" }); } /// /// 获取库位占比(圆 /// /// 仓库号 /// [HttpGet] public IActionResult GetStorageProportion(string wareHouseNo) { List getLocateVms = _locatSvc.GetStorageProportion(wareHouseNo); return Ok(new { data = getLocateVms, code = 0, msg = "获取库位占比数成功" }); } /// /// 获取库位占比(柱 /// /// 仓库号 /// 巷道号 /// [HttpGet] public IActionResult GetStorageProportion1(string wareHouseNo, string roadwayNo) { List getLocateVms = _locatSvc.GetStorageProportion1(wareHouseNo, roadwayNo); return Ok(new { data = getLocateVms, code = 0, msg = "获取库位占比数成功" }); } /// /// 获取仓库巷道 /// /// 仓库号 /// [HttpGet] public IActionResult GetRoadwayList(string wareHouseNo) { List roadway = _locatSvc.GetRoadwayList(wareHouseNo); return Ok(new { data = roadway, code = 0, msg = "获取仓库巷道成功" }); } /// /// 根据巷道获取排 /// /// 巷道号 /// [HttpGet] public IActionResult ByRoadwayGetRow(string roadwayNo) { List row = _locatSvc.ByRoadwayGetRow(roadwayNo); return Ok(new { data = row, code = 0, msg = "获取巷道排成功" }); } #endregion #region 平库 /// /// 根据仓库 排 /// /// 排 /// [HttpGet] public IActionResult GetFlatLibraryLegend(string row) { //获取储位信息 List storagelist = _locatSvc.GetFlatLibraryLegend(row); //Dictionary dic = new Dictionary() //{ // "B01" //}; return Ok(new { data = storagelist, code = 0, msg = "" }); } #endregion /// /// 根据储位地址获取储位上的托盘和物品信息 /// /// /// [HttpGet] public IActionResult GetLocateInfo(string locatNo) { try { //获取储位信息 LocateInfoVm model = _locatSvc.GetLocateInfo(locatNo); return Ok(new { data = model, code = 0, msg = "" }); } catch (Exception e) { return Ok(new { data = "", code = 1, msg = e.Message }); } } #endregion #region 物料类别 /// /// 获取物料类别信息 /// /// 类别名称 /// 区域编码 /// /// [HttpGet] public IActionResult GetMaterialCategories(string categoryName, string areaNo) { try { var list = _category.GetMaterialCategories(categoryName, areaNo); return Ok(new { data = list, code = 1, msg = "获取物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } /// /// 获取物料类别下拉菜单信息 /// /// /// [HttpGet] public IActionResult GetMaterialCategories1() { try { var list = _category.GetMaterialCategories(); return Ok(new { data = list, code = 1, msg = "获取物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } /// /// 根据Id获取物料类别信息 /// /// Id /// /// [HttpGet] public IActionResult GetMaterialCategoriesById(int Id) { try { var list = _category.GetMaterialCategoriesById(Id); return Ok(new { data = list, code = 1, msg = "根据Id获取物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } /// /// 获取区域信息 /// /// [HttpGet] public IActionResult GetStorageAreaList() { try { var bolls = _category.GetStorageAreaList(); List list = new List(); foreach (var item in bolls) { XmSelectDto list1 = new XmSelectDto() { name = item.AreaName, //区域名称 value = item.AreaNo, //区域号 selected = false, //是否选中 }; list.Add(list1); } return Ok(new { code = 0, msg = "区域信息", data = bolls, list }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } /// /// 新增类别信息 /// /// 物料类别实体 /// /// [HttpPost] public IActionResult InsertMaterialCategories(SysMaterialCategory category) { 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 = "为获取到当前操作人信息" }); } category.CreateUser = int.Parse(userId); var list = _category.InsertMaterialCategories(category); _operation.InsertOperation("基础信息", "物料类别", category.CategoryNo, "添加", "添加类别信息 类别号:" + category.CategoryNo, Convert.ToInt32(userId)); return Ok(new { data = list, code = 1, msg = "新增物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } /// /// 编辑类别信息 /// /// 物料类别实体 /// /// [HttpPost] public IActionResult ExitMaterialCategories(SysMaterialCategory category) { 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 = "为获取到当前操作人信息" }); } category.UpdateUser = int.Parse(userId); var list = _category.ExitMaterialCategories(category); _operation.InsertOperation("基础信息", "物料类别", category.CategoryNo, "编辑", "编辑类别信息 类别号:" + category.CategoryNo, Convert.ToInt32(userId)); return Ok(new { data = list, code = 1, msg = "编辑物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } /// /// 删除类别信息 /// /// 物料类别实体 /// /// [HttpPost] public IActionResult DeleteMaterialCategories(MaterialCategoryDto category) { 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 = "为获取到当前操作人信息" }); } category.UpdateUser = userId; var list = _category.DeleteMaterialCategories(category); _operation.InsertOperation("基础信息", "物料类别", category.CategoryNo, "删除", "删除类别信息 类别号:" + category.CategoryNo, Convert.ToInt32(userId)); return Ok(new { data = list, code = 1, msg = "删除物料类别信息成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 0, msg = ex.Message }); } } #endregion #region 低储位预警 /// /// 获取低储位巷道信息及剩余储位数量 /// /// [HttpGet] public IActionResult GetAvailabilityRoadry() { try { var list = _locatSvc.GetAvailabilityRoadry(); return Ok(new { data = list, code = 0, msg = "获取成功" }); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } #endregion #region 数据表格表头自定义(通用方法) /// /// 获取用户自定义表头 /// /// /// [HttpPost] public IActionResult GetTableColsByUserId(HeaderSetVm model) { //获取当前登录的用户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.UserId = int.Parse(userId); string cols = _headerSet.GetTableColsByUserId(model); return Ok(new { data = cols, code = 0, msg = "获取自定义表头成功" }); } /// /// 获取系统表头 /// /// /// [HttpPost] public IActionResult GetTableColsSys(HeaderSetVm model) { //获取当前登录的用户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.UserId = int.Parse(userId); var obj = _headerSet.GetTableColsSys(model); return Ok(new { data = obj, code = 0, msg = "获取表头成功" }); } /// /// 保存自定义表头 /// /// /// [HttpPost] public IActionResult SaveClosUser(HeaderSetVm model) { //获取当前登录的用户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.UserId = int.Parse(userId); string saveResult = _headerSet.SaveClosUser(model); if (!string.IsNullOrEmpty(saveResult)) { return Ok(new { data = saveResult, code = 0, msg = "自定义列成功" }); } else { return Ok(new { data = "", code = 1, msg = "自定义列失败" }); } } #endregion #region 数据归档 [HttpGet] public IActionResult GetArchivingLogList(int Page=1, int Limit=10) { try { var list = _archiving.GetArchivingLogList(Page,Limit, out int count); return Ok(new { data = list, code = 0, count = count, msg = "获取成功" }); } catch (Exception ex) { return Ok(new { data = "", code = 1, msg = ex.Message }); } } [HttpPost] public IActionResult DataArchive(DataArchiveVm 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 = "为获取到当前操作人信息" }); } _archiving.DataArchive(model.TimeStr, int.Parse(userId)); return Ok(new { data = "", code = 0, msg = "操作成功" }); } catch (Exception e) { return Ok(new { data = "", code = 1, msg = $"操作失败:{e.Message}" }); } } #endregion } }