using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model.ModelDto.SysDto;
using Model.ModelVm;
using Model.ModelVm.SysVm;
using Utility.Tools;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
using WMS.IBLL.ISysServer;
namespace WmsApi.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; //异常处理
///
/// 构造函数
///
/// 仓库
/// 区域
/// 巷道
/// 储位
/// 条码
/// 托盘
/// 菜单
/// 数据字典
/// 操作日志
/// 异常处理
public SysController(IWareHouseServer wareHouseSvc, IStorageAreaServer areaSvc, IStorageRoadwayServer roadwaySvc, IStorageLocatServer locatSvc, IPalletsServer palletSvc, IPalletTrackServer palletTrackSvc, IMenuServer menuSvc, IDictionaryServer dic, IOperationSysServer operation, IExceptionServer table)
{
_wareHouseSvc = wareHouseSvc; //仓库
_areaSvc = areaSvc; //区域
_roadwaySvc = roadwaySvc; //巷道
_locatSvc = locatSvc; //储位
_palletSvc = palletSvc; //条码
_palletTrackSvc = palletTrackSvc; //托盘
_menuSvc = menuSvc; //菜单
_dic = dic; //数据字典
_operation = operation; //操作日志
_table = table; //异常处理
}
#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)
{
//抛出异常
throw new Exception("新增菜单信息异常", ex);
}
}
///
/// 删除菜单信息
/// 单删
///
/// 菜单Id
///
/// 捕获异常
[HttpPost]
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)
{
//抛出异常
throw new Exception("编辑菜单信息异常", ex);
}
}
#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
{
return Ok(new
{
data = i,
code = 0,
msg = "成功"
});
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增字典异常", ex);
}
}
///
/// 删除字典信息
///
/// 字典id
///
/// 捕获异常
[HttpPost]
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 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, 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" ? "启用" : "停用", 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, 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" ? "启用" : "停用", 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, Convert.ToInt32(userId));
if (bolls > 0)
{
await _operation.InsertOperation("仓库设置", "储位管理", model.RoadwayNo, "添加", "添加储位信息 储位号:" + model.RoadwayNo, Convert.ToInt32(userId));
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, int.Parse(userId));
if (bolls)
{
SysStorageLocat storage = _locatSvc.GetStorageLocat(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 = "数据格式错误" });
}
}
///
/// 修改储位状态标识信息集合
///
/// 模型
///
[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, 1);//int.Parse(userId)
if (bolls)
{
SysStorageLocat storage = _locatSvc.GetStorageLocat(model.Id[0]);
string msg = "储位状态 储位号:" + storage.RoadwayNo;
_operation.InsertOperation("仓库设置", "储位管理", storage.RoadwayNo, model.Status == "0" ? "启用" : "停用", 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 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 async Task 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 = "为获取到当前操作人信息" });
}
var bolls = await _palletSvc.AddPallets(model.GroupCount, int.Parse(userId));
if (bolls)
{
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 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(1, 2);
int sibelius = Convert.ToInt16(str);
for (int i = 0; i < model.GroupCount; i++)
{
if (i != 0)
{
sibelius += 1;
}
string code = "T" + 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 async Task 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;
int i = await _table.EditStatus(tabledto);
if (i == 0)
{
return Ok(new
{
data = i,
code = 1,
msg = "处理失败"
});
}
else
{
return Ok(new
{
data = i,
code = 0,
msg = "处理成功"
});
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("处理状态异常", ex);
}
}
#endregion
#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 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 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
}
}