using System; using System.Collections; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using JLHHJSvr.BLL; using JLHHJSvr.Com; using JLHHJSvr.Com.Model; using JLHHJSvr.Helper; using JLHHJSvr.LJException; using JLHHJSvr.Tools; using LJLib.DAL.SQL; using LJLib.Net.SPI.Server; using NPOI.POIFS.Properties; using NPOI.SS.Formula.Functions; namespace JLHHJSvr.Excutor { internal sealed class CoverMattressInterfaceExcutor : ExcutorBase { protected override void ExcuteInternal(CoverMattressInterfaceRequest request, object state, CoverMattressInterfaceResponse rslt) { var tokendata = BllHelper.GetToken(request.token); if (tokendata == null) { rslt.ErrMsg = "会话已经中断,请重新登录"; return; } if (request.list == null) { rslt.ErrMsg = "提交缺少列表参数,请检查!"; return; } if (!request.list.Any()) { rslt.ErrMsg = "至少提交一条需要覆盖的记录"; return; } using (var con = new SqlConnection(GlobalVar.ConnectionString)) using (var cmd = con.CreateCommand()) { con.Open(); var helper = HelperBase.GetHelper(cmd, new HelperBase.Context() { tokendata = tokendata }); var interfaceHelper = HelperBase.GetHelper(cmd, new HelperBase.Context() { tokendata = tokendata }); var mainDict = new Dictionary> (); foreach(var mattress in request.list) { DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype,parentid"); if (!mainDict.ContainsKey(mattress.parentid.Value)) { var interfacelist = new List(); mainDict.Add(mattress.parentid.Value, interfacelist); // 获取主规格床垫的配置 interfacelist = interfaceHelper.GetMattressInterfaceList(mattress.parentid.Value,0); } } using (cmd.Transaction = con.BeginTransaction()) { try { foreach (var mattress in request.list) { var copy_list = new List(); if (mainDict.TryGetValue(mattress.parentid.Value, out var parentlist)) { // 获取副规格床垫的配置 copy_list = interfaceHelper.GetMattressInterfaceList(mattress.mattressid, 0); var copyDict = parentlist.Where(mx2 => mx2.erp_pzid > 0) .ToDictionary(mx2 => mx2.erp_pzid, mx2 => mx2); bool isUpdate = DbSqlHelper.SelectCount(cmd, "u_mattress_interface", "mattressid = @mattressid", new Dictionary() { { "@mattressid", mattress.mattressid } }) > 0; foreach (var mx in copy_list) { if (mx.bj_inputtype == null) mx.bj_inputtype = 0; if (mx.erp_pzid > 0 && copyDict.TryGetValue(mx.erp_pzid, out var mx2) && (mx.bj_inputtype == 1 || mx.bj_inputtype == 0)) { mx.bj_namemx = mx2.bj_namemx; mx.bj_inputtype = mx2.bj_inputtype; } if(isUpdate) { DbSqlHelper.Update(cmd, mx, "bj_inputtype,bj_namemx"); } else { DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,bj_inputtype,ss_rate,ls_rate"); } } } } cmd.Transaction.Commit(); } catch (Exception e) { cmd.Transaction.Rollback(); rslt.ErrMsg = e.Message; } } } } } }