| | |
| | | using System.Net.NetworkInformation; |
| | | using Tiger.Model.MES.Yada; |
| | | using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser; |
| | | using Tiger.Model.Minsun; |
| | | |
| | | namespace Tiger.Business.MES |
| | | { |
| | |
| | | pars[1].Direction = System.Data.ParameterDirection.Output; |
| | | pars[2].Direction = System.Data.ParameterDirection.Output; |
| | | Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("SP_MES_WO2CUST", pars); |
| | | //response.LocaleMsg = new(pars[2].Value.ToString()); |
| | | if (pars[1].Value.ToInt32() == 0) |
| | | { |
| | | Logger.Default.Info($"工单[{input.Wo.ORDER_NO}]下发完成后保存工艺路线数据到产品[{input.Wo.ITEM_CODE}]的客户[{input.Wo.CUST_CODE ?? ""}]的工艺路线中,{pars[2].Value.ToString()}"); |
| | |
| | | var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.WorkOrder).FirstAsync(); |
| | | if (_wo != null) |
| | | { |
| | | _wo.CHANGE_TIME = _wo.STATUS == BIZ_MES_WO.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO.STATUSs.Working.GetValue() ? DateTime.Now : _wo.CHANGE_TIME; |
| | | _wo.CHANGE_USER = _wo.STATUS == BIZ_MES_WO.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO.STATUSs.Working.GetValue() ? input.UserId : _wo.CHANGE_USER; |
| | | _wo.STATUS = input.Status < 0 ? _wo.STATUS : input.Status; |
| | | _wo.ROUTE_STATUS = input.RouteStatus; |
| | | } |
| | |
| | | var _woBatch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.BATCH_NO == input.WoBatch).FirstAsync(); |
| | | if (_woBatch != null) |
| | | { |
| | | _woBatch.CHANGE_TIME = _woBatch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()? DateTime.Now: _woBatch.CHANGE_TIME; |
| | | _woBatch.CHANGE_USER = _woBatch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue() ? input.UserId: _woBatch.CHANGE_USER; |
| | | _woBatch.STATUS = input.Status < 0 ? _woBatch.STATUS : input.Status; |
| | | if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue()) |
| | | { |
| | |
| | | _woBatch.RELEASE_TIME = DateTime.Now; |
| | | _woBatch.RELEASE_USER = input.UserId; |
| | | _woBatch.ACT_LINE = input.ActLine; |
| | | _woBatch.CHANGE_USER = input.UserId; |
| | | _woBatch.CHANGE_TIME = DateTime.Now; |
| | | _wo.STATUS = BIZ_MES_WO.STATUSs.Release.GetValue(); |
| | | } |
| | | else |
| | | { |
| | | if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Init.GetValue() && !Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.WorkOrder && x.BATCH_NO != input.WoBatch && x.STATUS > BIZ_MES_WO_BATCH.STATUSs.Init.GetValue()).Any()) |
| | | { |
| | | _wo.STATUS = BIZ_MES_WO.STATUSs.Init.GetValue(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | //如果是下发 |
| | | if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue()) |
| | | { |
| | | db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.RELEASE_USER, x.RELEASE_TIME, x.ACT_LINE, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); |
| | | db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.RELEASE_USER, x.RELEASE_TIME, x.ACT_LINE, x.UPDATE_USER, x.UPDATE_TIME, x.CHANGE_USER,x.CHANGE_TIME }).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); |
| | | db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME, x.CHANGE_USER, x.CHANGE_TIME }).ExecuteCommand(); |
| | | } |
| | | if (!_wo.IsNullOrEmpty()) |
| | | { |
| | | db.Updateable(_wo, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); |
| | | } |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | |
| | | } |
| | | } |
| | | //入库标签 |
| | | var wipActInStore = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN == woSn.SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3) && q.ACT_VALUE_4 == "InStroe").First(); |
| | | var wipActInStore = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN == woSn.SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3) && q.ACT_VALUE_4 == "InStore").First(); |
| | | if (!wipActInStore.IsNullOrEmpty()) |
| | | { |
| | | var label = JsonConvert.DeserializeObject<BAS_LABEL_TEMP>(wipActInStore.ACT_VALUE_3); |
| | |
| | | string ACT_VALUE_3 = JsonConvert.SerializeObject(label); |
| | | foreach (var pkg in pkgList) |
| | | { |
| | | var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "InStroe").First(); |
| | | var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "InStore").First(); |
| | | if (!actSn.IsNullOrEmpty()) |
| | | { |
| | | actSn.ACT_VALUE_3 = ACT_VALUE_3; |
| | |
| | | try |
| | | { |
| | | //先查出工单条码中是否存在 |
| | | var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code)).FirstAsync(); |
| | | var outerSn = input.Code.Split('|')[0]; |
| | | var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code) || q.OUTER_SN == outerSn).FirstAsync(); |
| | | if (woSn == null) |
| | | { |
| | | result.IsSuccessed = false; |
| | |
| | | //如果查不到就去行为日志查 |
| | | if (labelPrint.IsNullOrEmpty() && input.ReqType == 1) |
| | | { |
| | | printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => (q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code)) && q.ACT_VALUE_4 == "Customer").First()?.ACT_VALUE_3 ?? ""; |
| | | printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN.Equals(woSn.OUTER_SN) && q.ACT_VALUE_4 == "Customer" && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3)).First()?.ACT_VALUE_3 ?? ""; |
| | | } |
| | | else if (labelPrint.IsNullOrEmpty() && input.ReqType == 2) |
| | | { |
| | | printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN.Equals(woSn.SN) && q.ACT_VALUE_4 == "InStore").First()?.ACT_VALUE_3 ?? ""; |
| | | } |
| | | else |
| | | { |
| | | printParam = labelPrint.PRINT_PARAM; |
| | | printParam = labelPrint?.PRINT_PARAM ?? ""; |
| | | } |
| | | result.Data = printParam; |
| | | result.LocaleMsg = new($"重打条码[{input.Code}]的标签成功"); |
| | |
| | | /// </summary> |
| | | /// <param name="wo"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> GetShipList(string wo, string orgCode) |
| | | public async Task<ApiAction<ShippingOutput>> GetShipList(ShippingInput input) |
| | | { |
| | | var result = new ApiAction(); |
| | | var result = new ApiAction<ShippingOutput>(); |
| | | try |
| | | { |
| | | DbClient db = Biz.DataSource["YadaU9C"].Client; |
| | | var org = await Biz.Db.Queryable<SYS_ORGANIZATION>().Where(q=>q.ORG_CODE == orgCode).FirstAsync(); |
| | | if (db.Queryable<mes_ShipList>().Any(q => q.MoDoc.Equals(wo) && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now) && q.Status == 2 && q.Org == org.ID.ToInt64())) |
| | | var org = await Biz.Db.Queryable<SYS_ORGANIZATION>().Where(q => q.ORG_CODE == input.orgCode).FirstAsync(); |
| | | string wo = input.wo; |
| | | if (!input.SN.IsNullOrEmpty() && input.wo.IsNullOrEmpty()) { |
| | | var woSn = Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN).First(); |
| | | if (!woSn.IsNullOrEmpty()) { |
| | | wo = woSn.WORK_ORDER; |
| | | } |
| | | } |
| | | var ship = db.Queryable<mes_ShipList>().Where(q => q.MoDoc.Equals(wo) && q.Org == org.ID.ToInt64() && q.Status == 2 ).First(); |
| | | if (!ship.IsNullOrEmpty()) |
| | | { |
| | | result.Data = "Customer"; |
| | | result.Data = ship.BusinessDate.Date == DateTime.Now.Date ? new() |
| | | { |
| | | ShipDoc = ship.ShipDoc, |
| | | ShippingQty = ship.ShipQty.ToDouble(), |
| | | Tag = "Customer" |
| | | } : new() |
| | | { |
| | | ShipDoc = ship.ShipDoc, |
| | | ShippingQty = ship.ShipQty.ToDouble(), |
| | | Tag = "InStoreLabel" |
| | | }; |
| | | result.LocaleMsg = new($"出货信息存在!"); |
| | | } |
| | | else |
| | | { |
| | | result.Data = "InStoreLabel"; |
| | | result.Data = new() |
| | | { |
| | | ShipDoc = "", |
| | | ShippingQty = 0, |
| | | Tag = "InStoreLabel" |
| | | }; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | var wipList = await Biz.Db.Queryable<MES_WIP_DATA>().Where(q => q.SN.Equals(input.SN) || q.FLOW_SN.Equals(input.SN)).ToListAsync(); |
| | | var cartonSn = input.SN.Split('|')[0]; |
| | | var wipList = await Biz.Db.Queryable<MES_WIP_DATA>().Where(q => q.SN.Equals(input.SN) || q.FLOW_SN.Equals(input.SN) || q.CARTON_SN == cartonSn).ToListAsync(); |
| | | if (wipList.Count == 0) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"解绑的条码不存在当前操作表中!"); |
| | | return result; |
| | | } |
| | | var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == wipList[0].WORK_ORDER).FirstAsync(); |
| | | result = WorkBatch.UnbindWipSnFromWO(wo, wipList, input.user); |
| | | if (result.IsSuccessed) |
| | | { |
| | | var newList = await Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.WORK_ORDER == wo.ORDER_NO && q.BATCH_NO == wipList[0].BATCH_NO && SqlFunc.IsNullOrEmpty(q.PARENT_SN) && q.QTY > 0).ToListAsync(); |
| | | result.Data = newList; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成入库获取条码工单信息及包装信息 |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<InStoreInfo>> GetErpProdInBth(string code) |
| | | { |
| | | var result = new ApiAction<InStoreInfo>(); |
| | | try |
| | | { |
| | | //得到工单条码记录 |
| | | var cartonSn = code.Split('|')[0]; |
| | | var woSns = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.OUTER_SN == cartonSn).ToListAsync(); |
| | | if (woSns.Count == 0) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"条码不存在!"); |
| | | return result; |
| | | } |
| | | var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == woSns[0].WORK_ORDER ).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q._ItemInfos).FirstAsync(); |
| | | if (wo == null) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"条码对应的工单不存在"); |
| | | return result; |
| | | } |
| | | //判断工单是否已经全部入库 |
| | | |
| | | |
| | | InStoreInfo inStoreInfo = new() { |
| | | ErpProdInBth= new() { |
| | | WORK_ORDER = wo.ORDER_NO, |
| | | BATCH_NO = woSns[0].BATCH_NO, |
| | | SALES_ORDER = wo.SALES_ORDER, |
| | | ITEM_CODE = wo.ITEM_CODE, |
| | | ITEM_NAME = wo.ItemInfo?.ITEM_DESC, |
| | | SapCode = wo.ItemInfo?.ExtInfo?.SapCode, |
| | | SCAN_QTY = woSns.Count, |
| | | IS_HANDLED = "N" //Y-已生成,N-未生成,F-失败 |
| | | }, |
| | | InStoreScanInfo = new() { |
| | | SN = cartonSn, |
| | | SALES_ORDER = wo.SALES_ORDER, |
| | | WORK_ORDER = wo.ORDER_NO, |
| | | BATCH_NO = woSns[0].BATCH_NO, |
| | | SCAN_QTY = woSns.Count |
| | | } |
| | | }; |
| | | result.Data = inStoreInfo; |
| | | result.LocaleMsg = new($"获取条码[{code}]工单信息及包装信息成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchExceptionWithLog(ex, $"获取条码[{code}]工单信息及包装信息异常"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | #region 提交前通用方法 |
| | | /// <summary> |
| | | /// 提交前检查是否岗位、工单和不良代码 |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<CheckCodeOutput>> CheckCode(string code) |
| | | { |
| | | var action = new ApiAction<CheckCodeOutput>($"检查条码{code}成功", new CheckCodeOutput()); |
| | | try |
| | | { |
| | | action.Data.Position = DbCache.Cache.Position[code]; |
| | | action.Data.WorkOrder = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == code).FirstAsync(); |
| | | action.Data.Defect = DbCache.Cache.Defect[code]; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, $"检查条码{code}异常"); |
| | | } |
| | | return action; |
| | | } |
| | | #endregion |
| | | } |
| | | } |