using HH.Redis.ReisModel; using HH.WMS.BLL; using HH.WMS.BLL.Algorithm; using HH.WMS.BLL.Basic; using HH.WMS.BLL.ERP; using HH.WMS.BLL.External; using HH.WMS.BLL.InStock; using HH.WMS.BLL.Interface; using HH.WMS.BLL.Pda; using HH.WMS.BLL.SysMgr; using HH.WMS.Common; using HH.WMS.Common.Algorithm; using HH.WMS.Common.External; using HH.WMS.Common.Response; using HH.WMS.DAL; using HH.WMS.DAL.Algorithm; using HH.WMS.DAL.Basic; using HH.WMS.Entitys; using HH.WMS.Entitys.Autobom; using HH.WMS.Entitys.Basic; using HH.WMS.Entitys.Common; using HH.WMS.Entitys.Dto; using HH.WMS.Entitys.Entitys; using HH.WMS.Entitys.Enums; using HH.WMS.Entitys.ERP; using HH.WMS.Entitys.External; using HH.WMS.Entitys.Tzlj; using HH.WMS.TaskService.Jobs; using HH.WMS.WebApi.App_Start; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Web.Http; using System.Linq; using HH.WMS.WebApi.Areas.Common.Controllers; namespace HH.WMS.WebApi.Controllers { /// /// /// public class WmsApiController : BaseController { #region 入作业区 + InWorkArea /// /// 入作业区 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public string InWorkArea(List inWorkAreaEntitys) { var result = WmsApiBLLRoute.InWorkArea(inWorkAreaEntitys); return result; } [HttpPost] public string ReturnWorkArea(List inWorkAreaEntitys) { foreach (var i in inWorkAreaEntitys) { i.taskType = "退库"; } return WmsApiBLLRoute.InWorkArea(inWorkAreaEntitys); } #endregion #region 出作业区 + OutWorkArea /// /// 出作业区 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public string OutWorkArea(List outWorkAreaEntitys) { return WmsApiBLLRoute.OutWorkArea(outWorkAreaEntitys); } #endregion #region 完工回报 + ExecuteState /// /// AGV执行情况 完成时调用 /// /// 传入的Json数组 /// /// [HanHe(lt)] CREATED 2018/4/8 [HttpPost] public string ExecuteState(ExecuteStateDto data) { var result = WmsApiBLLRoute.ExecuteState(data); return result; } #endregion #region 生成流转任务 /// /// 生成流转任务 /// /// /// /// [HanHe(XDL)] CREATED 2018/6/30 [HttpPost] public string CreateTransTask(JObject jsonData) { try { //var logPara = LogType.LogPara("巨星-CreateTransTask"); //Log.Detail(logPara, JsonConvert.SerializeObject(jsonData)); TN_WM_B_TRAN_TASKEntity entity = JsonConvert.DeserializeObject(jsonData.ToString()); //string startPosition = jsonData.Value("startPosition"); //string endPosition = jsonData.Value("endPosition"); //string taskPriority = jsonData.Value("taskPriority"); Log.Info("调用CreateTransTask", "请求参数:startPosition" + JsonConvert.SerializeObject(jsonData)); OperateResult result = BLLCreator.Create().CreateTransTask(entity.startPosition, entity.endPosition, entity.taskPriority, "转运", ProjectCodes.JuXingHaiNing); return JsonConvert.SerializeObject(result); } catch (Exception ex) { Log.Error("CreateTransTask异常:====>", ex.Message + ex.StackTrace); return JsonConvert.SerializeObject(OperateResult.Error(ex.Message.ToString())); } } #endregion #region 取库区物料信息 /// /// 取库区物料信息 /// /// [HttpGet] public OperateResult GetStockAreaItems() { try { var areaList = BLLCreator.CreateDapper().GetList(); var stocks = GetStock(); var areas = GetStockArea(); var res = areaList.Select(s => { string stockName = (stocks.Find(f => f.CN_S_STOCK_CODE == s.CN_S_STOCK_CODE) ?? new Entitys.Algorithm.TN_AB_STOCKEntity()).CN_S_STOCK_NAME; string areaName = (areas.Find(f => f.CN_S_AREA_CODE == s.CN_S_STOCK_AREA) ?? new AutoBomStockAreaEntity()).CN_S_AREA_NAME; return new { material_name = s.CN_S_ITEM_NAME, model = s.CN_S_MODEL, no = s.CN_S_ITEM_CODE, send_instruct_no = s.CN_S_LOT_NO, //weight = s.CN_F_QUANTITY, warehouse = stockName, area = areaName, able_no = s.CN_F_QUANTITY - s.CN_F_ALLOC_QTY }; }); return OperateResult.Succeed(null, res); } catch (Exception ex) { return OperateResult.Error(ex.Message); } } #endregion #region 更新托盘中物料的长度或重量 ///// ///// 更新托盘中物料的长度或重量 ///// ///// //[HttpPost] //public string UpdateTrayItemInfo(dynamic param) //{ // Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口请求参数:" + JsonConvert.SerializeObject(param)); // CommInfResult res = new CommInfResult() { success = false }; // try // { // //任务号 // string taskNo = Util.ToReplaceSymbolStr(param.taskNo); // //托盘号 // string trayCode = Util.ToReplaceSymbolStr(param.trayCode); // //更新对象 1:物料长度 2:重量 // string updateObj = Util.ToString(param.updateObj); // //物料长度 // string itemQty = Util.ToString(param.itemQty); // //物料重量 // string weight = Util.ToString(param.weight); // if (string.IsNullOrEmpty(taskNo) && string.IsNullOrEmpty(trayCode)) // { // res.errMsg = "任务号和托盘不可同时为空!"; // } // if (updateObj != "1" && updateObj != "2") // { // res.errMsg += " 更新对象参数不正确!"; // } // else // { // if (updateObj.Equals("1")) // { // if (!Util.IsNumber(itemQty)) // res.errMsg += " 物料长度值不正确!"; // } // else // { // if (!Util.IsNumber(weight)) // res.errMsg += " 托盘重量值不正确!"; // } // } // //参数校验失败,直接return // if (string.IsNullOrEmpty(res.errMsg)) // { // //托盘为空,根据任务号先把托盘取出来 // if (string.IsNullOrEmpty(trayCode)) // { // var currentTaskDt = BLLCreator.Create>().GetSingleEntity(new { CN_S_TASK_NO = taskNo });//BLLCreator.Create().GetTaskEntity(taskNo); // if (currentTaskDt == null) // { // res.errMsg = "未找到任务号:" + taskNo; // Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + JsonConvert.SerializeObject(res)); // return JsonConvert.SerializeObject(res); // } // else // { // trayCode = Util.ToString(currentTaskDt.CN_S_TRAY_CODE); // } // } // //校验是否该托盘有物料关联数据 // var trayItemRelList = BLLCreator.Create>().GetList(new { CN_S_TRAY_CODE = trayCode }); //BLLCreator.Create().GetItemRelModel(" WHERE CN_S_TRAY_CODE='" + trayCode + "' "); // if (!trayItemRelList.Any()) // { // res.errMsg = "未找到托盘:" + trayCode + "的物料关联数据"; // Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + JsonConvert.SerializeObject(res)); // return JsonConvert.SerializeObject(res); // } // SqlExecuteResult sqlResult = new SqlExecuteResult(); // if (updateObj.Equals("1")) // { // //更新物料长度 // sqlResult = BLLCreator.Create().UpdateItemQtyByTrayCode(trayCode, itemQty); // } // else // { // //更新托盘重量 // sqlResult = BLLCreator.Create().UpdateTrayWeight(trayCode, weight); // } // if (sqlResult.Success) // { // //成功 // res.success = true; // } // else // { // res.errMsg = sqlResult.Exception.Message + sqlResult.Exception.StackTrace; // } // } // } // catch (Exception ex) // { // res.errMsg = "UpdateTrayItemInfo方法异常" + ex.Message + ex.StackTrace; // } // string result = JsonConvert.SerializeObject(res); // Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + result); // return result; //} #endregion #region 同步货位状态,货位状态不一致设为异常 /// /// 同步货位状态,货位状态不一致设为异常 /// /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public string SynchroLocation(List synchroLocationEntitys) { Log.Info("同步货位状态", "SynchroLocation接口请求参数:" + JsonConvert.SerializeObject(synchroLocationEntitys)); ExternalResponse response = BLLCreator.Create().SynchroLocation(synchroLocationEntitys); Log.Info("同步货位状态", "SynchroLocation接口返回参数:" + JsonConvert.SerializeObject(response)); return JsonConvert.SerializeObject(response); } #endregion #region 改道 /// /// 改道 /// /// /// [HttpPost] public string UpdateWay(dynamic param) { var logPara = new TOOLS.LOG.LogPara("改道"); logPara.Push("接口请求参数:" + JsonConvert.SerializeObject(param)); var result = new UpdateWayResult() { success = false, errCode = "200", location = "" }; try { //任务号 string taskNo = param.taskNo; //改道类型(起点/终点) string updateType = param.updateType; //改道类型对应的原因 string reasonCode = param.reasonCode; if (string.IsNullOrEmpty(taskNo)) { result.errMsg = "任务号不可为空"; result.errCode = "102"; } if (string.IsNullOrEmpty(updateType) || !(updateType.Equals("起点") || updateType.Equals("终点"))) { result.errMsg += " 改道类型不正确"; result.errCode = "102"; } var currentTask = BLLCreator.Create>().GetSingleEntity(new { CN_S_TASK_NO = taskNo });//BLLCreator.Create().GetTransportTask(taskNo); if (currentTask == null) { result.errMsg += "未找到任务号:" + taskNo; result.errCode = "102"; } string changeLocation = param.changeLocation; if (string.IsNullOrEmpty(changeLocation)) { result.errCode = "102"; result.errMsg = "改道货位不能为空!"; } else { //Log.Info("改道", "UpdateWay接口changeLocation不为空,不需重新计算货位,改道货位为:" + changeLocation); string type = updateType.Equals("起点") ? "start" : "end"; AutoBomLocationEntity locationModel = DALCreator.Create().GetModel(changeLocation); var locationArea = DALCreator.Create().GetAreaModelByLocation(changeLocation); var sqlResult = BLLCreator.Create().UpdateWay(currentTask, locationModel, locationArea, type); if (!sqlResult.Success) result.errMsg = sqlResult.Msg; else { result.success = true; result.errCode = "100"; result.location = changeLocation; } } if (result.success) { logPara.PushAndAdd("改道成功!"); } else { logPara.PushAndAdd("改道失败,原因:" + result.errMsg); } } catch (Exception ex) { result.errCode = "200"; result.errMsg = "UpdateWay方法异常" + ex.Message + ex.StackTrace; logPara.PushAndAdd(ex); } return JsonConvert.SerializeObject(result); } #endregion #region 宇寿 叫料 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public OperateResult CallMaterial(JObject jsonData) { try { Log.Info("===>宇寿MES叫料传进来的参数:", jsonData.ToString()); TN_WM_B_CALL_MATERIALEntity entity = JsonConvert.DeserializeObject(jsonData.ToString()); if (!string.IsNullOrEmpty(entity.itemCode)) { //检查物料编码是否正确 var item = BLLCreator.Create().GetItem(entity.itemCode); if (item == null) { return OperateResult.Error("当前物料编码在AutoBom中未找到!"); } } #region StringBuilder strAreaCodes = new StringBuilder(); string stockCode = string.Empty; List areaModel = BLLCreator.Create().GetAreaByManyClass("中间库,混装区"); Log.Info("===>宇寿MES叫料areaModel:", JsonConvert.SerializeObject(areaModel)); string workFloor = string.Empty; if (entity.workBit.IndexOf("F1") >= 0) { workFloor = "F1"; } else if (entity.workBit.IndexOf("F2") >= 0) { workFloor = "F2"; } else if (entity.workBit.IndexOf("F3") >= 0) { workFloor = "F3"; } List lstArea = new List(); foreach (AutoBomStockAreaEntity areaEntity in areaModel) { if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") >= 0) { areaPriorClass areaClass = new areaPriorClass(); areaClass.areaCode = areaEntity.CN_S_AREA_CODE; areaClass.Prior = 1; lstArea.Add(areaClass); stockCode = areaEntity.CN_S_STOCK_CODE; } } foreach (AutoBomStockAreaEntity abEntity in areaModel) { if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") >= 0) { areaPriorClass areaClass = new areaPriorClass(); areaClass.areaCode = abEntity.CN_S_AREA_CODE; areaClass.Prior = 2; lstArea.Add(areaClass); stockCode = abEntity.CN_S_STOCK_CODE; } } if (lstArea.Count == 0) { return OperateResult.Error("该叫料任务工作站点找不到对应的叫料库区!"); } #endregion //调用出库算法,获取待出去托盘 OutAssignEnitty oAe = new OutAssignEnitty() { projectCode = "ys001", lstAreaPrior = lstArea, stockCode = stockCode, itemCode = entity.itemCode, traySpec = "", itemQty = entity.qty, lockLocation = true//是否需要锁定货位 }; OutAssignResultEntity oaEresult = BLLCreator.Create().OutAssign(oAe); if (!oaEresult.Success) { Log.Error("调用出库算法,获取待出库托盘:", oaEresult.Msg); return OperateResult.Error(oaEresult.Msg);//货位获取失败! } //转运货位-移动起点外层的货位 var logPara = LogType.LogPara("叫料"); var moveResult = BLLCreator.Create().MoveLocation(oaEresult.locationCode, logPara); Log.Detail(logPara, "转运货位结果:" + moveResult.Success + ",信息:" + moveResult.Msg); if (!moveResult.Success) { BLLCreator.Create().RollBackLocation(moveResult, oaEresult.locationCode, logPara); return OperateResult.Error(moveResult.Msg); } TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity(); trayOnEntity.CN_S_DEVICE_NO = entity.workBit; //目的货位码 trayOnEntity.CN_S_LOCATION_CODE = oaEresult.locationCode; //建议货位码 trayOnEntity.CN_S_END_AREA_CODE = oaEresult.areaCode;//目标库区 trayOnEntity.CN_S_TRAY_CODE = oaEresult.trayCode; //起始托盘码 trayOnEntity.CN_S_TASK_TYPE = "叫料"; //任务类型 RedisUserEntity userEntity = new RedisUserEntity(); userEntity.CN_S_LOGIN = "mes"; userEntity.CN_S_NAME = "mes"; OperateResult opResult = BLLCreator.Create().SimZTDownShelfCallMaterialYS(trayOnEntity, userEntity); if (!opResult.Success) { BLLCreator.Create().RollBackLocation(moveResult, oaEresult.locationCode, logPara); } else { //增加库区量表 TN_WM_LOCATION_EXTEntity startlocation = BLLCreator.Create().GetExtModel(" where CN_S_LOCATION_CODE='" + oaEresult.locationCode + "'"); BLLCreator.Create().AddAllocQty(oaEresult.trayCode, startlocation.CN_S_STOCK_CODE, startlocation.CN_S_AREA_CODE, logPara); } Log.Detail(logPara, "调用叫料结果:" + JsonConvert.SerializeObject(opResult)); entity.CN_GUID = Guid.NewGuid().ToString(); entity.CN_S_STATE = "未执行"; entity.CN_T_CREATE = DateTime.Now; if (opResult.Success) { opResult = BLLCreator.Create().CallMaterial(entity); } Log.Info("===>宇寿MES叫料返回结果:", JsonConvert.SerializeObject(opResult)); return opResult; } catch (Exception ex) { Log.Info("CallMaterial异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 宇寿 送料 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public OperateResult SendMaterial(JObject jsonData) { try { Log.Info("===>宇寿MES送料传进来的参数:", jsonData.ToString()); TN_WM_B_SEND_MATERIALEntity entity = JsonConvert.DeserializeObject(jsonData.ToString()); string deviceNo = entity.workBit;//起点 string locationCode = "CK001-B-02-01"; string endAreaCode = ""; string trayCode = entity.trayNo; string stockCode = string.Empty; List areaModel = BLLCreator.Create().GetAreaByManyClass("中间库,混装区"); string workFloor = string.Empty; if (entity.workBit.IndexOf("F1") >= 0) { workFloor = "F1"; } else if (entity.workBit.IndexOf("F2") >= 0) { workFloor = "F2"; } else if (entity.workBit.IndexOf("F3") >= 0) { workFloor = "F3"; } List lstArea = new List(); foreach (AutoBomStockAreaEntity areaEntity in areaModel) { if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") >= 0) { endAreaCode = areaEntity.CN_S_AREA_CODE; stockCode = areaEntity.CN_S_STOCK_CODE; } } foreach (AutoBomStockAreaEntity abEntity in areaModel) { if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") >= 0) { endAreaCode = abEntity.CN_S_AREA_CODE; stockCode = abEntity.CN_S_STOCK_CODE; } } if (string.IsNullOrEmpty(endAreaCode)) { return OperateResult.Error("该送料任务工作站点找不到对应的入库库区!"); } if (string.IsNullOrEmpty(locationCode)) { //调用算法计算终点货位 //调用入库算法,获取空货位 List lstTmpArea = new List(); lstTmpArea.Add(new areaPriorClass { areaCode = endAreaCode, Prior = 1 }); InAssignEntity iAe = new InAssignEntity() { lstAreaPrior = lstTmpArea, logicAreaCode = "", objectCode = trayCode, projectCode = "ys001", lockLocation = false//是否需要锁定货位 }; iAe.lstDevice = null; InAssignResultEntity irEresult = BLLCreator.Create().InAssign(iAe); if (!irEresult.Success) { return OperateResult.Error(irEresult.Msg);//货位获取失败! } else { locationCode = irEresult.locationCode.ToString(); } } TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity(); trayOnEntity.CN_S_DEVICE_NO = entity.workBit; //目的货位码 trayOnEntity.CN_S_LOCATION_CODE = locationCode; //建议货位码 trayOnEntity.CN_S_END_AREA_CODE = endAreaCode;//目标库区 trayOnEntity.CN_S_TRAY_CODE = trayCode; //起始托盘码 trayOnEntity.CN_S_TASK_TYPE = "上架"; //任务类型 RedisUserEntity userEntity = new RedisUserEntity(); userEntity.CN_S_LOGIN = "mes"; userEntity.CN_S_NAME = "mes"; OperateResult result = BLLCreator.Create().SimZTShelfAutoYS(trayOnEntity, userEntity); entity.CN_GUID = Guid.NewGuid().ToString(); entity.CN_S_STATE = "未执行"; entity.CN_T_CREATE = DateTime.Now; if (result.Success) { result = BLLCreator.Create().SendMaterial(entity); } return result; Log.Info("===>宇寿MES送料返回结果:", JsonConvert.SerializeObject(result)); return result; } catch (Exception ex) { Log.Info("SendMaterial异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 宇寿 获取库存信息 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpGet] public OperateResult GetStockQtyInfo(string itemName, string itemCode, string stockCode, string areaCode) { try { List lstResult = BLLCreator.Create().GetStockQtyInfo(itemName, itemCode, stockCode, areaCode); return OperateResult.Succeed("", lstResult); } catch (Exception ex) { Log.Info("GetStockQtyInfo异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 宇寿 获取库存明细信息 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpGet] public OperateResult GetStockQtyDetailList(string itemName, string itemCode, string stockCode, string areaCode) { try { List lstResult = BLLCreator.Create().GetStockQtyDetailList(itemName, itemCode, stockCode, areaCode); return OperateResult.Succeed("", lstResult); } catch (Exception ex) { Log.Info("GetStockQtyDetailList异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 宇寿 叫料送料延时反馈 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public OperateResult WMSFeedbackResult(JObject jsonData) { try { Log.Info("===>宇寿MES叫料送料延时反馈传进来的参数:", jsonData.ToString()); string result = WebApiManager.HttpMes_Post("YesoMedMes/WMSFeedbackResult", JsonConvert.SerializeObject(jsonData)); MesResponse s = JsonConvert.DeserializeObject(result); Log.Info("===>宇寿MES叫料送料延时反馈返回结果:", result); if (s.Success) { return OperateResult.Succeed(); } else { return OperateResult.Error(s.Msg.ToString()); } } catch (Exception ex) { Log.Info("SendMaterial异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 宇寿 整托叫料 /// /// 叫料 /// /// /// [HanHe(zh)] CREATED 2018/5/3 [HttpPost] public OperateResult CallMaterialTray(JObject jsonData) { try { Log.Info("===>宇寿MES叫料CallMaterialTray传进来的参数:", jsonData.ToString()); TN_WM_B_CALL_MATERIALEntity entity = JsonConvert.DeserializeObject(jsonData.ToString()); if (!string.IsNullOrEmpty(entity.itemCode)) { //检查物料编码是否正确 var item = BLLCreator.Create().GetItem(entity.itemCode); if (item == null) { return OperateResult.Error("当前物料编码在AutoBom中未找到!"); } } #region StringBuilder strAreaCodes = new StringBuilder(); string stockCode = string.Empty; List areaModel = BLLCreator.Create().GetAreaByManyClass("中间库,混装区"); string workFloor = string.Empty; if (entity.workBit.IndexOf("F1") > 0) { workFloor = "F1"; } else if (entity.workBit.IndexOf("F2") > 0) { workFloor = "F2"; } else if (entity.workBit.IndexOf("F3") > 0) { workFloor = "F3"; } List lstArea = new List(); foreach (AutoBomStockAreaEntity areaEntity in areaModel) { if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) > 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") > 0) { areaPriorClass areaClass = new areaPriorClass(); areaClass.areaCode = areaEntity.CN_S_AREA_CODE; areaClass.Prior = 1; lstArea.Add(areaClass); stockCode = areaEntity.CN_S_STOCK_CODE; } } foreach (AutoBomStockAreaEntity abEntity in areaModel) { if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) > 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") > 0) { areaPriorClass areaClass = new areaPriorClass(); areaClass.areaCode = abEntity.CN_S_AREA_CODE; areaClass.Prior = 2; lstArea.Add(areaClass); stockCode = abEntity.CN_S_STOCK_CODE; } } if (lstArea.Count == 0) { return OperateResult.Error("该叫料任务工作站点找不到对应的叫料库区!"); } #endregion //调用出库算法,获取待出去托盘 OutAssignEnitty oAe = new OutAssignEnitty() { projectCode = "ys001", lstAreaPrior = lstArea, stockCode = stockCode, itemCode = entity.itemCode, traySpec = "", itemQty = entity.qty, lockLocation = true//是否需要锁定货位 }; OutAssignResultEntity oaEresult = BLLCreator.Create().OutAssign(oAe); if (!oaEresult.Success) { Log.Error("调用出库算法,获取待出库托盘:", oaEresult.Msg); return OperateResult.Error(oaEresult.Msg);//货位获取失败! } //转运货位-移动起点外层的货位 var logPara = LogType.LogPara("叫料"); var moveResult = BLLCreator.Create().MoveLocation(oaEresult.locationCode, logPara); Log.Detail(logPara, "转运货位结果:" + moveResult.Success + ",信息:" + moveResult.Msg); if (!moveResult.Success) { BLLCreator.Create().RollBackLocation(moveResult, oaEresult.locationCode, logPara); return OperateResult.Error(moveResult.Msg); } TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity(); trayOnEntity.CN_S_DEVICE_NO = entity.workBit; //目的货位码 trayOnEntity.CN_S_LOCATION_CODE = oaEresult.locationCode; //建议货位码 trayOnEntity.CN_S_END_AREA_CODE = oaEresult.areaCode;//目标库区 trayOnEntity.CN_S_TRAY_CODE = oaEresult.trayCode; //起始托盘码 trayOnEntity.CN_S_TASK_TYPE = "叫料"; //任务类型 RedisUserEntity userEntity = new RedisUserEntity(); userEntity.CN_S_LOGIN = "mes"; userEntity.CN_S_NAME = "mes"; var result = BLLCreator.Create().SimZTDownShelfCallMaterialYS(trayOnEntity, userEntity); if (!result.Success) { BLLCreator.Create().RollBackLocation(moveResult, oaEresult.locationCode, logPara); } else { //增加库区量表 TN_WM_LOCATION_EXTEntity startlocation = BLLCreator.Create().GetExtModel(" where CN_S_LOCATION_CODE='" + oaEresult.locationCode + "'"); BLLCreator.Create().AddAllocQty(oaEresult.trayCode, startlocation.CN_S_STOCK_CODE, startlocation.CN_S_AREA_CODE, logPara); } Log.Detail(logPara, "调用叫料结果:" + JsonConvert.SerializeObject(result)); return result; } catch (Exception ex) { Log.Info("CallMaterialTray异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message.ToString()); } } #endregion #region 南通桑德 称重 /// /// 大榜单 进厂 车牌号、车辆总重 /// /// [HttpPost] public IHttpActionResult InCarPound(CarPoundPara data) { var logPara = LogType.LogPara("AMS上传大榜单-进厂"); var response = BLLCreator.Create().InCarPound(data.carNo, data.areaCode, data.weight, data.itemType, data.supplierCode, logPara); Log.Detail(logPara, response.Describe()); return Json(response); } /// /// 大榜单 出厂 /// /// /// [HttpPost] public IHttpActionResult OutCarPound(CarPoundPara data) { var logPara = LogType.LogPara("AMS上传大榜单-出厂"); var response = BLLCreator.Create().OutCarPound(data.carNo, data.weight, logPara); Log.Detail(logPara, response.Describe()); return Json(response); } [HttpGet] public IHttpActionResult GetErrorInfo() { return Json(CommResponse.Error("123")); } #endregion #region 南通桑德 根据货位找产线开工的物料 /// /// 产线开工的物料 /// /// /// [HttpPost] public string GetItemByLocationForNt(dynamic obj) { var locationCode = obj.Value("locationCode"); var produceLineMapStr = JsonHelper.GetValue("produceLineMapping"); List produceLineMaps = JsonConvert.DeserializeObject>(produceLineMapStr); foreach (var produceLineMap in produceLineMaps) { if (produceLineMap.locationCode.Equals(locationCode)) { var produceLine = produceLineMap.produceLine; if (!string.IsNullOrEmpty(produceLine)) { List materialStockOuts = BLLCreator.Create().GetMaterialStockOut(produceLine); if (materialStockOuts.Count > 0) { var materialStockOut = materialStockOuts[0]; var data = new { itemName = materialStockOut.CN_S_ITEM_NAME, itemCode = materialStockOut.CN_S_ITEM_CODE, produceLine = materialStockOut.CN_S_LINE }; return JsonConvert.SerializeObject(DataResponse.Data(true, ErrorEnum.Normal, "", data)); } } } } //var endBits = new Dictionary { { "HCX01", "1" }, { "HCX02", "2" }, { "HCX03", "3" }, { "HCX04", "4" } }; //if (endBits.ContainsKey(locationCode)) //{ //} return JsonConvert.SerializeObject(DataResponse.Data(false, ErrorEnum.SystemError, "", null)); } #endregion #region 解绑货位 [HttpGet] public IHttpActionResult UnbindLocation(string locationCode) { return Json(WmsApiBLLRoute.UnbindLocation(locationCode)); } #endregion #region 获取货位状态 - 板焊 /// /// 获取货位状态 /// /// /// [HttpPost] public string GetLocationUseState(dynamic obj) { var logPara = LogType.LogPara("获取货位状态-板焊"); var result = ""; try { var locationCode = obj.Value("locationCode"); if (string.IsNullOrEmpty(locationCode)) { return JsonConvert.SerializeObject(new { success = false, errMsg = "货位编码不能为空!", errCode = "-1", state = "" }); } var locationExt = BLLCreator.Create>().GetSingleEntity(new { CN_S_LOCATION_CODE = locationCode }); if (locationExt == null) { return JsonConvert.SerializeObject(new { success = false, errMsg = "未找到当前货位!", errCode = "-1", state = "" }); } result = JsonConvert.SerializeObject(new { success = true, errMsg = "成功!", errCode = "0", state = locationExt.CN_S_LOCATION_STATE == "正常" ? locationExt.CN_S_USE_STATE : locationExt.CN_S_LOCATION_STATE }); Log.Detail(logPara, result); return result; } catch (Exception ex) { return JsonConvert.SerializeObject(new { success = false, errMsg = ex.Message, errCode = "-1", state = "" }); } } #endregion #region 同步服务测试 [HttpGet] public IHttpActionResult TestSyncJob() { NtErpPoundJob job = new NtErpPoundJob(); job.Run(new LogPara("同步服务测试")); return Json("成功"); } [HttpGet] public IHttpActionResult TestEnum() { var temp = EnumExtensions.GetEnumByName("EEEE"); return Json(EnumExtensions.GetDescription(temp)); } #endregion #region 泰州隆基测试 [HttpPost] public OperateResult SendAmsTask(JObject jsonData) { try { TN_WM_TRANSPORT_TASKEntity entity = JsonConvert.DeserializeObject(jsonData.ToString()); AutoBomLocationEntity locationEntity = DALCreator.Create().GetModel(entity.CN_S_START_BIT); entity.CN_S_STOCK_CODE = locationEntity.CN_S_STOCK_CODE; entity.CN_N_PRIORITY = 1; // entity.CN_S_END_BIT = GetEndBit(entity.CN_S_START_BIT); string postData = "{\"appCode\":\"" + Constants.appCode + "\",\"ruleName\":\"" + Constants.Rule_TransTaskNo + "\",\"orgId\":\"\",\"orgFlag\":\"0\"}"; string taskNo = WebApiManager.HttpAutoBom_Post("api/BillRule/GenBillNo", postData); if (string.IsNullOrEmpty(taskNo)) { return OperateResult.Error("任务号生成失败,请检查autobom中是否配置了转运任务号生成规则!"); } entity.CN_S_TASK_NO = taskNo; OperateResult re = new OtherSysApi().SendAmsCreateTaskLJ(entity); if (!re.Success) { throw new Exception("SendAmsCreateTask异常:" + re.Msg); } else { return OperateResult.Succeed(); } } catch (Exception ex) { Log.Error("SendAmsTask异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message); } } public string GetEndBit(string startBit) { string str = string.Empty; if (startBit.IndexOf("A") > 0) { str = "A-RGSL01"; } else if (startBit.IndexOf("B") > 0) { str = "B-RGSL01"; } else if (startBit.IndexOf("C") > 0) { str = "C-RGSL01"; } else if (startBit.IndexOf("D") > 0) { str = "D-RGSL01"; } return str; } [HttpGet] public OperateResult GetMesInfo(string trayCode) { try { var result = WebApiManager.HttpMes_Auth_Get("/api/values/?lotsn=" + trayCode, ""); var mesStackTrayDto = JsonConvert.DeserializeObject(result); if (mesStackTrayDto.RetVal.Equals("true")) { //var mesStackTrayEntity = new MesStackTrayEntity().Map(mesStackTrayDto); // var result2 = BLLCreator.Create>().Add(mesStackTrayEntity, null); return OperateResult.Succeed(null, mesStackTrayDto); } else { return OperateResult.Error(mesStackTrayDto.ErrMsg); } } catch (Exception ex) { Log.Error("GetMesInfo异常:====>", ex.Message + ex.StackTrace); return OperateResult.Error(ex.Message); } } #endregion } }