123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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<CoverMattressInterfaceRequest, CoverMattressInterfaceResponse>
- {
- 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<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
- var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
- var mainDict = new Dictionary<int, List<u_mattress_interface>> ();
- foreach(var mattress in request.list)
- {
- DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype,parentid");
- if (!mainDict.ContainsKey(mattress.parentid.Value))
- {
- var interfacelist = new List<u_mattress_interface>();
- 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<u_mattress_interface>();
- 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<string, object>() { { "@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;
- }
- }
- }
- }
- }
- }
|