kazelee
2025-06-17 33b84a02e80c24e2106c67a388d9a3c1fa5f5603
core/Monitor.cs
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using HH.WCS.Mobox3.DSZSH.api;
using HH.WCS.Mobox3.DSZSH.device;
using HH.WCS.Mobox3.DSZSH.models;
using HH.WCS.Mobox3.DSZSH.util;
@@ -11,6 +12,8 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.X509;
namespace HH.WCS.Mobox3.DSZSH.core {
    public class Monitor {
@@ -65,41 +68,6 @@
                    var startLocCode = prod.OffLoc[0]; // 用于测试
                    //var startLocCode = "CX01"; // 用于测试
                    //var cgDetail = new TN_CG_Detail { // 空托上线时就绑定好了
                    //    S_ITEM_CODE = itemCode,
                    //    S_BATCH_NO = batchNo,
                    //    S_CNTR_CODE = cntrCode,
                    //};
                    //var needInsertContainer = false;
                    //var needUpdateContainer = false;
                    // TEMP 自动触发的托盘下线暂时不考虑判断,默认没有时写入
                    // 查容器信息表是否已经有这个容器
                    //var cntr = db.Queryable<TN_Container>()
                    //    .Where(c => c.S_CODE == cntrCode).First();
                    // 如果找不到该容器,需要添加,并且将容器来源设置为任务名称
                    //if (cntr == null) {
                    //    needInsertContainer = true;
                    //    LogHelper.Info($"轮询:{taskName}:容器:{cntrCode},在容器表中没有登记,登记并设置容器来源为:{taskName}");
                    //    cntr = new TN_Container {
                    //        S_CODE = cntrCode,
                    //        S_TYPE = cntrType,
                    //        S_SPEC = itemCode,
                    //    };
                    //}
                    //else {
                    //    如果找到该容器,但容器物料类型与下线物料不符,记录并直接覆盖(待定)
                    //    if (!string.IsNullOrEmpty(cntr.S_SPEC) && cntr.S_SPEC != itemCode) {
                    //        needUpdateContainer = true;
                    //        LogHelper.Info($"轮询:{taskName}:容器表中容器{cntrCode}对应的物料信息:{cntr.S_SPEC}," +
                    //            $"与所需要的物料信息{itemCode}不符,直接覆盖结果");
                    //        cntr.S_SPEC = itemCode;
                    //    }
                    //}
                    var startLoc = db.Queryable<TN_Location>()
                    .Where(l => l.S_CODE == startLocCode)
                    .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE))
@@ -142,9 +110,6 @@
                    LocationHelper.LockStartLoc(ref startLoc); // 起点出库锁
                    LocationHelper.LockEndLoc(ref endLoc); // 终点入库锁
                    //cntr.S_SOURCE = task.S_CODE;
                    //cntr.T_MODIFY = DateTime.Now;
                    using (var tran = db.Ado.UseTran()) {
                        if (locCntrRelOld != null) {
                            if (db.Deleteable<TN_Loc_Container>(locCntrRelOld).ExecuteCommand() <= 0 &&
@@ -155,30 +120,6 @@
                                continue;
                            }
                        }
                        //if (needInsertContainer) {
                        //    if (db.Insertable<TN_Container>(cntr).ExecuteCommand() <= 0) {
                        //        info = $"插入容器表失败:" + JsonConvert.SerializeObject(cntr);
                        //        tran.RollbackTran();
                        //        LogHelper.Info(info);
                        //        continue;
                        //    }
                        //}
                        //else if (needUpdateContainer) {
                        //    if (db.Updateable<TN_Container>(cntr)
                        //        .UpdateColumns(c => new { c.S_SPEC, c.S_SOURCE, c.T_MODIFY }).ExecuteCommand() <= 0) {
                        //        info = $"更新容器表失败:" + JsonConvert.SerializeObject(cntr);
                        //        tran.RollbackTran();
                        //        LogHelper.Info(info);
                        //        continue;
                        //    }
                        //}
                        //if (db.Insertable<TN_CG_Detail>(cgDetail).ExecuteCommand() <= 0) {
                        //    tran.RollbackTran();
                        //    info = $"插入容器货品信息表失败:物料编码{cgDetail.S_ITEM_CODE},容器编码{cgDetail.S_CNTR_CODE}";
                        //    LogHelper.Info(info);
                        //    continue;
                        //}
                        if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) {
                            tran.RollbackTran();
@@ -250,6 +191,8 @@
                    LogHelper.Info(info);
                    return;
                }
                Console.WriteLine(JsonConvert.SerializeObject(orderList)); // TEST
                var detailList = new List<TN_Outbound_Detail>();
                foreach (var order in orderList) {
@@ -372,8 +315,17 @@
                        tran.CommitTran();
                        info = $"生成任务'{taskName}'成功,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}";
                        LogHelper.Info(info);
                        continue;
                        //continue;
                    }
                    // 如果当前出库单明细是ERP下发的,任务创建完成反馈货位信息
                    if (detail.S_BS_TYPE == "ERP") {
                        //var createTaskReturnErpTask = Task.Run(() => {
                        //    CreateTaskReturnErp(task);
                        //});
                        CreateTaskReturnErp(task);
                    }
                }
@@ -667,5 +619,104 @@
                LogHelper.InfoEx(ex);
            }
        }
        public static void CreateTaskReturnErp(TN_Task task) {
            var db = new SqlHelper<object>().GetInstance();
            var info = "";
            var httpH = new HttpHelper();
            try {
                var plan = db.Queryable<TN_Outbound_Plan>()
                    .Where(p => p.JHDH == task.S_BS_NO)
                    .First();
                if (plan == null) {
                    info = $"计划单号{task.S_BS_NO}不存在!";
                    LogHelper.Info(info);
                }
                var cgDetail = db.Queryable<TN_CG_Detail>()
                    .Where(d => d.S_CNTR_CODE == task.S_CNTR_CODE)
                    .First();
                if (cgDetail == null) {
                    info = $"物料编码不存在!";
                    LogHelper.Info(info);
                }
                var model = new OtherModel.CreateTaskReturnErpInfo {
                    jhdh = plan.JHDH , // 计划单号(唯一标识)
                    ckzt = plan.CKZT , // 出库状态(需要返回)
                    jhlb = plan.JHLB , // 计划类别
                    ckdh = plan.CKDH , // 参考单号
                    cph = plan.CPH , // 车牌号
                    ysfs = plan.YSFS , // 运输方式
                    cpzt = plan.CPZT , // 产品状态
                    mddw = plan.MDDW , // 买断单位
                    cpdm = plan.CPDM , // 产品代码
                    cplb = plan.CPLB , // 产品类别
                    cplbmx = plan.CPLBMX , // 产品类别明细
                    pp = plan.PP , // 品牌
                    dj = plan.DJ , // 等级(需要返回)
                    gh = plan.GH , // 罐号
                    ph = plan.PH , // 批号(需要返回)
                    bzlx = plan.BZLX , // 包装类型
                    pzdh = plan.PZDH , // 派装单号
                    pzd_dw = plan.PZD_DW , // 派装单单位
                    pzd_dybh = plan.PZD_DYBH , // 派装单调运编号
                    pzjs = plan.PZJS , // 派装件数
                    pzsl = plan.PZSL , // 派装数量
                    pz_rq = plan.PZ_RQ , // 派装日期(yyyy-mm-dd)
                    pz_czrq = plan.PZ_CZRQ , // 派装操作日期
                    pz_zfbj = plan.PZ_ZFBJ , // 派装作废标记
                    pz_zfrq = plan.PZ_ZFRQ , // 派装作废日期
                    pz_bz = plan.PZ_BZ , // 派装备注
                    ckdbh = plan.CKDBH , // 出库单编号
                    //sfjs = plan.SFJS , // 实发件数(需要返回)
                    //sfsl = plan.SFSL , // 实发数量(需要返回)
                    //sfcs = plan.SFCS , // 实发车数(需要返回)
                    //zcsj = plan.ZCSJ , // 装车时间(需要返回)
                    //jldw = plan.JLDW , // 计量单位(需要返回)
                    //fhrq = plan.FHRQ , // 发货日期(需要返回)
                    //ckdm = plan.CKDM , // 仓库代码(需要返回)
                    //fhr = plan.FHR , // 发货人(需要返回)
                    //czydm = plan.CZYDM , // 操作员(需要返回)
                    shr_username = plan.SHR_USERNAME , // 审核人
                    shrq = plan.SHRQ , // 审核日期
                    zfbj = plan.ZFBJ , // 作废标记
                    zfrq = plan.ZFRQ , // 作废日期
                    jsdw = plan.JSDW , // 结算单位
                    shdw = plan.SHDW , // 收货单位
                    ysdw = plan.YSDW , // 运输单位
                    lxr = plan.LXR , // 联系人
                    //ry_zxg = plan.RY_ZXG , // 装卸工(需要返回)
                    //ry_ccsj = plan.RY_CCSJ , // 叉车司机(需要返回)
                    erphx_jhdh = plan.ERPHX_JHDH , // erp交货单号
                    erphx_wlbm = plan.ERPHX_WLBM , // erp物料编码
                    erphx_wlmc = plan.ERPHX_WLMC , // erp物料名称
                    erphx_cjrq = plan.ERPHX_CJRQ , // erp创建日期
                    hw = plan.HW , // 货位(需要返回)
                    hwzt  = plan.HWZT // 货位状态(需要返回)
                };
                model.hw = task.S_START_LOC;
                model.hwzt = "待出库";
                model.ph = cgDetail.S_BATCH_NO;
                var jsonInfo = JsonConvert.SerializeObject(model);
                var result = httpH.WebPost(Settings.ErpApiUrl + "CreateTaskReturn", jsonInfo);
                LogHelper.InfoApi($"创建任务完成反馈ERP接口,结果={result},调用参数:", model);
                plan.HW = model.hw;
                plan.HWZT = model.hwzt;
                plan.PH = model.ph;
                var success = db.Updateable<TN_Outbound_Plan>(plan).UpdateColumns(p => new { p.HW, p.HWZT, p.PH }).ExecuteCommand() > 0;
                info = "更新出库计划单记录表" + (success ? "成功" : "失败");
                LogHelper.Info(info);
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
            }
        }
    }
}