using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using JLHHJSvr.BLL; using JLHHJSvr.Com; using JLHHJSvr.Com.Model; using JLHHJSvr.Helper; using JLHHJSvr.LJException; using LJLib.DAL.SQL; using LJLib.Net.SPI.Server; namespace JLHHJSvr.Excutor { internal sealed class RefreshMattressInterfaceQdExcutor : ExcutorBase { protected override void ExcuteInternal(RefreshMattressInterfaceQdRequest request, object state, RefreshMattressInterfaceQdResponse rslt) { var tokendata = BllHelper.GetToken(request.token); if (tokendata == null) { rslt.ErrMsg = "会话已经中断,请重新登录"; return; } if (request.mattressid == null || request.mattressid <= 0) { rslt.ErrMsg = "床垫id有误,请检查!"; return; } using (var con = new SqlConnection(GlobalVar.ConnectionString)) using (var cmd = con.CreateCommand()) { con.Open(); var mattress = new u_mattress() { mattressid = request.mattressid.Value }; DbSqlHelper.SelectOne(cmd, mattress, "js2_flag"); if (request.isCheck == 1 && mattress.js2_flag == 1) { throw new LJCommonException("床垫已技术2审核,不能重新生成!"); } var copy_list = new List(); var selectStr = @"SELECT u_mattress_interface_qd.mattressid ,u_mattress_interface_qd.printid ,u_mattress_interface_qd.itemname ,u_mattress_interface_qd.bj_pzname ,u_mattress_interface_qd.bj_pzname_mx ,u_mattress_interface_qd.bj_pzname_mx_mx ,u_mattress_interface_qd.mtrlid ,u_mattress_interface_qd.erp_mtrlid ,u_mattress_interface_qd.useqty ,u_mattress_interface_qd.dscrp ,u_mtrl_price.name AS mtrlname ,u_mattress_interface_qd.actual_useqty ,u_mattress_interface_qd.qd_actual_size ,u_mattress_interface_qd.qd_pfgroupqty ,u_mattress_interface_qd.wrkgrpid ,u_mattress_interface_qd.ss_rate ,u_mattress_interface_qd.ls_rate ,u_mattress_interface_qd.sh_rate ,ISNULL(u_mattress_interface_qd.formulaid, 0) AS formulaid FROM u_mattress_interface_qd LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid"; var outputFields = "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,mtrlid,erp_mtrlid,useqty,dscrp,mtrlname,actual_useqty,qd_actual_size,qd_pfgroupqty,wrkgrpid,ss_rate,ls_rate,sh_rate,formulaid"; DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary() { { "@mattressid", request.mattressid } }, "printid", outputFields, 0, 0, copy_list); var interfaceHelper = HelperBase.GetHelper(cmd, new HelperBase.Context() { tokendata = tokendata }); var qdList = interfaceHelper.RefreshMattressInterfaceQdList(request.mattressid.Value); if (request.isPz != null && request.isPz == 1) { var copyDict = new Dictionary, u_mattress_interface_qd>(); foreach (var mx2 in copy_list) { var key = Tuple.Create(mx2.itemname, mx2.bj_pzname, mx2.bj_pzname_mx); if (!copyDict.ContainsKey(key)) { copyDict[key] = mx2; } } // 遍历qdList foreach (var mx in qdList) { var key = Tuple.Create(mx.itemname, mx.bj_pzname, mx.bj_pzname_mx); // 创建复合键 if (copyDict.TryGetValue(key, out var mx2)) // 高效查找对应的mx2 { // 更新mx属性 mx.erp_mtrlid = mx2.erp_mtrlid; mx.erp_mtrlcode = mx2.erp_mtrlcode; mx.erp_mtrlname = mx2.erp_mtrlname; mx.erp_mtrlmode = mx2.erp_mtrlmode; mx.erp_unit = mx2.erp_unit; mx.useqty = mx2.useqty; mx.actual_useqty = mx2.actual_useqty; mx.wrkgrpid = mx2.wrkgrpid; mx.qd_actual_size = mx2.qd_actual_size; mx.qd_pfgroupqty = mx2.qd_pfgroupqty; mx.dscrp = mx2.dscrp; } } } interfaceHelper.MattressInterfaceFindERPPrdPf(qdList); rslt.mxList = qdList; } } } }