zhaowc
2025-04-01 1650f3fe1467d21074b597042861c46f3a8c4447
Wms/Wms/Controllers/SysController.cs
@@ -20,6 +20,8 @@
using System.Security.Cryptography;
using Model.ModelDto;
using Model.ModelDto.LogDto;
using Newtonsoft.Json.Linq;
using Model.ModelVm.LogVm;
namespace Wms.Controllers
{
@@ -41,6 +43,9 @@
        private readonly IOperationSysServer _operation; //操作日志
        private readonly IExceptionServer _table; //异常处理
        private readonly IHeaderSettingsServer _headerSet;//表头设置
        private readonly IMaterialCategoryServer _category;//物料类别
        /// <summary>
        /// 构造函数
        /// </summary>
@@ -54,7 +59,8 @@
        /// <param name="dic">数据字典</param>
        /// <param name="operation">操作日志</param>
        /// <param name="table">异常处理</param>
        public SysController(IWareHouseServer wareHouseSvc, IStorageAreaServer areaSvc, IStorageRoadwayServer roadwaySvc, IStorageLocatServer locatSvc, IPalletsServer palletSvc, IPalletTrackServer palletTrackSvc, IMenuServer menuSvc, IDictionaryServer dic, IOperationSysServer operation, IExceptionServer table, IHeaderSettingsServer headerSet)
        /// <param name="category">物料类别</param>
        public SysController(IWareHouseServer wareHouseSvc, IStorageAreaServer areaSvc, IStorageRoadwayServer roadwaySvc, IStorageLocatServer locatSvc, IPalletsServer palletSvc, IPalletTrackServer palletTrackSvc, IMenuServer menuSvc, IDictionaryServer dic, IOperationSysServer operation, IExceptionServer table, IHeaderSettingsServer headerSet, IMaterialCategoryServer category)
        {
            _wareHouseSvc = wareHouseSvc; //仓库
            _areaSvc = areaSvc; //区域
@@ -69,6 +75,7 @@
            _table = table; //异常处理
            _headerSet = headerSet;//表头设置
            _category = category;//物料类别
        }
        #region 菜单管理
@@ -225,7 +232,7 @@
            }
            catch (Exception ex)
            {
                return Ok(new { data = "", code = 3,  msg = "新增菜单信息异常:"+ ex.Message });
                return Ok(new { data = "", code = 3, msg = "新增菜单信息异常:" + ex.Message });
            }
        }
@@ -729,6 +736,50 @@
                return Ok(new { code = 1, msg = e.Message });
            }
        }
        /// <summary>
        /// 添加区域信息
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns>
        [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 });
            }
        }
        /// <summary>
        /// 修改区域信息
        /// </summary>
@@ -1006,7 +1057,7 @@
            }
        }
        /// <summary>
        /// 添加储位信息
        /// 添加立体库储位信息
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns> 
@@ -1051,6 +1102,54 @@
                return Ok(new { code = 400, ErrorMsg = "数据格式错误" });
            }
        }
        /// <summary>
        /// 添加平库储位信息
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<IActionResult> 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 = "数据格式错误" });
            }
        }
        /// <summary>
        /// 修改储位信息
        /// </summary>
@@ -1128,17 +1227,22 @@
                        string msg = "储位状态 储位号:" + storage.RoadwayNo;
                        if (model.Id.Count > 1)
                        {
                            foreach (var item in model.Id)
                            var sstorage = _locatSvc.GetStorageLocat(model.Id);
                            foreach (var item in sstorage)
                            {
                                storage = _locatSvc.GetStorageLocat(item);
                                _operation.InsertOperation("仓库设置", "储位管理", storage.LocatNo, "批量编辑", "批量修改储位信息 储位号:" + storage.LocatNo, Convert.ToInt32(userId));
                                _operation.InsertOperation("仓库设置", "储位管理", item.LocatNo, "批量编辑", "批量修改储位信息 储位号:" + item.LocatNo, Convert.ToInt32(userId));
                            }
                            //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
@@ -1157,6 +1261,47 @@
                return Ok(new { code = 1, msg = "数据格式错误" });
            }
        }
        /// <summary>
        /// 修改储位状态标识信息集合
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult EditStorageLocatListNew (EditLocateListNewVm 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 = _locatSvc.EditStorageLocatListNew(model, int.Parse(userId));
                if (bolls)
                {
                    _operation.InsertOperation("仓库设置", "储位管理", "", "修改", $"修改巷道:{model.RoadWayNo}、排:{model.Row}、列:{model.Column}、层:{model.Layer}、深度:{model.Dept}的区域:{model.AreaNo}、状态:{model.Status}、标识:{model.Flag}的储位信息 ", 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 托盘条码管理
@@ -1271,17 +1416,21 @@
                {
                    throw new Exception("当前显示的条码不是最新条码,请重新添加");
                }
                string str = model.PalletNo.Substring(3, 5);
                string remove = model.PalletNo.Substring(0, 3);
                string str = model.PalletNo.Substring(2, 6);
                string remove = model.PalletNo.Substring(0, 2);
                int sibelius = Convert.ToInt16(str);
                for (int i = 0; i < model.GroupCount; i++)
                {
                    if (sibelius>999999)
                    {
                        throw new Exception("托盘组中已有托盘码位数已达上线");
                    }
                    if (i != 0)
                    {
                        sibelius += 1;
                    }
                    string code = remove + Convert.ToString(sibelius).PadLeft(5, '0');
                    string code = remove + Convert.ToString(sibelius).PadLeft(6, '0');
                    for (int j = 0; j < model.SameCount; j++)
                    {
                        var re = BarcodeHelper.GetCodeBarBase64(code, 80, 50);
@@ -1384,11 +1533,11 @@
                int uid = Convert.ToInt32(userId);
                //更改人
                tabledto.UpdateUser = uid;
                string strMesage  = _table.EditStatus(tabledto);
                string strMesage = _table.EditStatus(tabledto);
                if (strMesage == "")
                {
                    return Ok(new { code = 0, msg = "处理成功" });
                }
                }
                else
                {
                    return Ok(new { code = 1, msg = strMesage });
@@ -1438,18 +1587,20 @@
        #region 储位图例
        #region 立库
        /// <summary>
        /// 根据仓库 排
        /// </summary>
        /// <param name="wareHouseNo">仓库</param>
        /// <param name="roadway">巷道号</param>
        /// <param name="row">排</param>
        /// <param name="depth">深度</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStorageLocatLists(string wareHouseNo, string roadway,string row)
        public IActionResult GetStorageLocatLists(string wareHouseNo, string roadway, string row, string depth)
        {
            //获取储位信息
            List<SysStorageLocat> storagelist = _locatSvc.GetStorageLocatLists(wareHouseNo, roadway, row);
            List<SysStorageLocat> storagelist = _locatSvc.GetStorageLocatLists(wareHouseNo, roadway, row, depth);
            //获取最大层级
            int maxLayer = _locatSvc.GetMaxLayer(wareHouseNo, roadway, row);
@@ -1527,7 +1678,7 @@
        [HttpGet]
        public IActionResult GetStorageProportion1(string wareHouseNo, string roadwayNo)
        {
            List<GetLocateVm> getLocateVms = _locatSvc.GetStorageProportion1(wareHouseNo,roadwayNo);
            List<GetLocateVm> getLocateVms = _locatSvc.GetStorageProportion1(wareHouseNo, roadwayNo);
            return Ok(new
            {
                data = getLocateVms,
@@ -1552,6 +1703,41 @@
                msg = "获取仓库巷道成功"
            });
        }
        #endregion
        #region 平库
        /// <summary>
        /// 根据仓库 排
        /// </summary>
        /// <param name="wareHouseNo">仓库</param>
        /// <param name="row">排</param>
        /// <param name="depth">深度</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetFlatLibraryLegend(string wareHouseNo, string row)
        {
            //获取储位信息
            List<SysStorageLocat> storagelist = _locatSvc.GetFlatLibraryLegend(wareHouseNo, row);
            //Dictionary<string, int> dic = new Dictionary<string, int>()
            //{
            //    "B01"
            //};
            return Ok(new
            {
                data = storagelist,
                //dic,
                code = 0,
                msg = ""
            });
        }
        #endregion
        /// <summary>
        /// 根据储位地址获取储位上的托盘和物品信息
@@ -1586,7 +1772,301 @@
        #endregion
        #region 物料类别
        /// <summary>
        /// 获取物料类别信息
        /// </summary>
        /// <param name="categoryName">类别名称</param>
        /// <param name="areaNo">区域编码</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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
                });
            }
        }
        /// <summary>
        /// 获取物料类别下拉菜单信息
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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
                });
            }
        }
        /// <summary>
        /// 根据Id获取物料类别信息
        /// </summary>
        /// <param name="Id">Id</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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
                });
            }
        }
        /// <summary>
        /// 获取区域信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStorageAreaList()
        {
            try
            {
                var bolls = _category.GetStorageAreaList();
                List<XmSelectDto> list = new List<XmSelectDto>();
                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 });
            }
        }
        /// <summary>
        /// 新增类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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
                });
            }
        }
        /// <summary>
        /// 编辑类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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
                });
            }
        }
        /// <summary>
        /// 删除类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [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 操作日志
        /// <summary>
        /// 获取操作日志信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public IActionResult GetLogOperationList(GetOperationVm model)
        {
            try
            {
                var bolls = _operation.GetOperationList(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 数据表格表头自定义(通用方法)
        /// <summary>
@@ -1677,26 +2157,5 @@
        }
        #endregion
        /// <summary>
        /// 测试git
        /// </summary>
        /// <param name="MenuName"></param>
        /// <param name="pMenuNo"></param>
        /// <param name="MenuNo"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult TestGit(string MenuName, string pMenuNo, string MenuNo, string level)
        {
            //查询菜单信息列表
            List<FunctionMenuVm> menulist = _menuSvc.GetMenuList(MenuName, pMenuNo, MenuNo, level);
            return Ok(new
            {
                data = menulist,
                code = 0,
                msg = "成功"
            });
        }
    }
}