BasicInfoHelper.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com.Model;
  4. using JLHHJSvr.LJException;
  5. using JLHHJSvr.Tools;
  6. using LJLib.DAL.SQL;
  7. using NPOI.SS.Formula.Functions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using static JLHHJSvr.Helper.CacheHelper;
  13. namespace JLHHJSvr.Helper
  14. {
  15. internal class BasicInfoHelper: HelperBase
  16. {
  17. /// <summary>
  18. /// 核价选配类型-保存
  19. /// </summary>
  20. /// <param name="configure"></param>
  21. public void SaveConfigureType(u_configure_type configure)
  22. {
  23. if (configure.contfigtypeid <= 0)
  24. {
  25. configure.contfigtypeid = BllHelper.GetID(cmd, "u_configure_type");
  26. var fields = @"contfigtypeid,contfigtype,contfigtypename,usechflag,flag";
  27. DbSqlHelper.Insert(cmd, "u_configure_type", null, configure, fields);
  28. }
  29. else
  30. {
  31. configure.moddate = context.opdate;
  32. configure.modemp = context.tokendata.username;
  33. //修改
  34. var fields = @"contfigtype,contfigtypename,usechflag,modemp,moddate";
  35. DbSqlHelper.Update(cmd, "u_configure_type", null, configure, "contfigtypeid", fields);
  36. }
  37. }
  38. /// <summary>
  39. /// 核价选配项-保存
  40. /// </summary>
  41. /// <param name="configure"></param>
  42. public void SaveConfigureCode(u_configure_code configure)
  43. {
  44. if (configure.pzid <= 0)
  45. {
  46. // 新增
  47. configure.pzid = BllHelper.GetID(cmd, "u_configure_code");
  48. var fields = @"typeid,pzid,pzcode,inputtype,name,configtype,ifcross,ifcheck,ifuse,rulestr,ifnum,decnum,maxnum,minnum,pricestr,priceratestr,ifpack,zj_special";
  49. DbSqlHelper.Insert(cmd, "u_configure_code", null, configure, fields);
  50. }
  51. else
  52. {
  53. //修改
  54. var fields = @"pzcode,inputtype,name,configtype,ifcross,ifcheck,ifuse,rulestr,ifnum,decnum,maxnum,minnum,pricestr,priceratestr,ifpack,zj_special";
  55. DbSqlHelper.Update(cmd, "u_configure_code", null, configure, "typeid,pzid", fields);
  56. }
  57. }
  58. /// <summary>
  59. /// 核价选配项值-保存
  60. /// </summary>
  61. /// <param name="configure"></param>
  62. public void SaveConfigureCodeMx(u_configure_codemx codeMx)
  63. {
  64. if (codeMx.printid <= 0)
  65. {
  66. int _printid = 0;
  67. cmd.CommandText = @"SELECT ISNULL(MAX(printid),0) AS printid FROM u_configure_codemx WHERE pzid = @pzid";
  68. cmd.Parameters.Clear();
  69. cmd.Parameters.AddWithValue("@pzid", codeMx.pzid);
  70. using (var reader = cmd.ExecuteReader())
  71. {
  72. if (reader.Read())
  73. {
  74. _printid = Convert.ToInt32(reader["printid"]);
  75. }
  76. }
  77. codeMx.printid = _printid + 1;
  78. var fields = @"pzid,printid,pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  79. DbSqlHelper.Insert(cmd, "u_configure_codemx", null, codeMx, fields);
  80. }
  81. else
  82. {
  83. //修改
  84. var fields = @"pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  85. DbSqlHelper.Update(cmd, "u_configure_codemx", null, codeMx, "pzid,printid", fields);
  86. }
  87. }
  88. /// <summary>
  89. /// 核价选配项值物料清单-保存
  90. /// </summary>
  91. /// <param name="configure"></param>
  92. public void SaveConfigureCodeMxBomList(List<u_configure_codemxbom> bomList)
  93. {
  94. var sb = new StringBuilder();
  95. var saveList = new List<u_configure_codemxbom>();
  96. foreach (var bom in bomList)
  97. {
  98. AutoInit.AutoInitS(cmd, bom);
  99. if (bom.pzid <= 0)
  100. {
  101. sb.AppendLine($"物料:{bom.mtrlname}配置项ID错误!\r\n");
  102. }
  103. if (bom.printid <= 0)
  104. {
  105. sb.AppendLine($"物料:{bom.mtrlname}配置值ID错误!\r\n");
  106. }
  107. if (sb.Length > 0)
  108. {
  109. continue;
  110. }
  111. saveList.Add(bom);
  112. }
  113. if (sb.Length > 0) throw new LJCommonException(sb.ToString());
  114. var fields = @"mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,sonloss,sonloss_formula,sondecloss,sondecloss_formula,default_length,default_width,default_qty";
  115. foreach (var item in saveList)
  116. {
  117. if (item.pid <= 0)
  118. {
  119. // 新增
  120. fields += ",pzid,printid,pid";
  121. int _pid = 0;
  122. cmd.CommandText = @"SELECT ISNULL(MAX(pid),0) AS pid FROM u_configure_codemxbom WHERE pzid = @pzid AND printid = @printid";
  123. cmd.Parameters.Clear();
  124. cmd.Parameters.AddWithValue("@pzid", item.pzid);
  125. cmd.Parameters.AddWithValue("@printid", item.printid);
  126. using (var reader = cmd.ExecuteReader())
  127. {
  128. if (reader.Read())
  129. {
  130. _pid = Convert.ToInt32(reader["pid"]);
  131. }
  132. }
  133. item.pid = _pid + 1;
  134. DbSqlHelper.Insert(cmd, "u_configure_codemxbom", null, item, fields);
  135. }
  136. else
  137. {
  138. // 修改
  139. DbSqlHelper.Update(cmd, "u_configure_codemxbom", null, item, "pzid,printid,pid", fields);
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 核价软工公式定义-删除
  145. /// </summary>
  146. /// <param name="formula"></param>
  147. /// <exception cref="LJCommonException"></exception>
  148. public void DeleteSoftBedFormula(u_softbed_formula formula)
  149. {
  150. if (formula == null || formula.formulaid <= 0)
  151. {
  152. throw new LJCommonException("未提交软床公式定义信息");
  153. }
  154. DbSqlHelper.Delete(cmd, formula);
  155. }
  156. /// <summary>
  157. /// 核价软床公式定义-保存
  158. /// </summary>
  159. /// <param name="formula"></param>
  160. public void SaveSoftBedFormula(u_softbed_formula formula)
  161. {
  162. if (formula == null)
  163. {
  164. throw new LJCommonException("未提交软床公式定义信息");
  165. }
  166. if (string.IsNullOrEmpty(formula.formulaname))
  167. {
  168. throw new LJCommonException($"公式名称不能为空,请检查!");
  169. }
  170. var fields = "formulaname,price_formula,use_formula";
  171. if (formula.formulaid <= 0)
  172. {
  173. // 新建
  174. fields += ",formulaid,create_date,create_emp";
  175. formula.formulaid = BllHelper.GetID(cmd, "u_softbed_formula");
  176. formula.create_date = context.opdate;
  177. formula.create_emp = context.tokendata.username;
  178. DbSqlHelper.Insert(cmd, "u_softbed_formula", null, formula, fields);
  179. }
  180. else
  181. {
  182. //修改
  183. fields += ",update_date,update_emp";
  184. formula.update_date = context.opdate;
  185. formula.update_emp = context.tokendata.username;
  186. DbSqlHelper.Update(cmd, "u_softbed_formula", null, formula, "formulaid", fields);
  187. }
  188. }
  189. /// <summary>
  190. /// 保存ERP物料资料定义
  191. /// </summary>
  192. /// <param name="mtrl"></param>
  193. /// <exception cref="LJCommonException"></exception>
  194. public void SaveErpMtrlPrice(u_erpmtrl_price mtrl)
  195. {
  196. var fields = "";
  197. if(mtrl.mtrlid <= 0)
  198. {
  199. throw new LJCommonException("物料ID有误,请检查!");
  200. }
  201. mtrl.update_date = context.opdate;
  202. mtrl.update_emp = context.tokendata.username;
  203. if(DbSqlHelper.Update(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid", "price,update_date,update_emp") == 0)
  204. {
  205. mtrl.create_date = context.opdate;
  206. mtrl.create_emp = context.tokendata.username;
  207. DbSqlHelper.Insert(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid,price,create_date,create_emp");
  208. }
  209. }
  210. /// <summary>
  211. /// 获取ERP物料资料定义
  212. /// </summary>
  213. /// <param name="whereList"></param>
  214. /// <param name="param"></param>
  215. /// <param name="pageindex"></param>
  216. /// <param name="pagesize"></param>
  217. /// <param name="totalcnt"></param>
  218. /// <returns></returns>
  219. public List<L1Mtrldef> GetErpMtrlPriceList(List<string> whereList, Dictionary<string, object> param,int pageindex,int pagesize,out int totalcnt)
  220. {
  221. var mtrldefList = new List<L1Mtrldef>();
  222. var selectFields = @"row_number() over (order by u_mtrldef.mtrlcode) as rowNum,u_mtrldef.scid,u_mtrldef.mtrlid,u_mtrldef.mtrlcode,u_mtrldef.mtrlname,u_mtrldef.mtrlorigin,u_mtrldef.mtrltype,u_mtrldef.mtrlengname,
  223. u_mtrldef.unit,u_mtrldef.mtrlmode,u_mtrldef.mtrlsectype,u_mtrldef.zxmtrlmode,u_mtrldef.status_config,u_mtrldef.woodcode_config,
  224. u_mtrldef.pcode_config,u_mtrldef.statustype,u_mtrldef.woodcodetype,u_mtrldef.pcodetype,ISNULL(u_erpmtrl_price.price,0) AS price,
  225. u_erpmtrl_price.create_date,u_erpmtrl_price.create_emp,u_erpmtrl_price.update_date,u_erpmtrl_price.update_emp";
  226. var outputFileds = @"rowNum,scid,mtrlid,mtrlcode,mtrlname,mtrlorigin,mtrltype,mtrlengname,unit,mtrlmode,mtrlsectype,zxmtrlmode,status_config,woodcode_config,
  227. pcode_config,statustype,woodcodetype,pcodetype,price,create_date,create_emp,update_date,update_emp";
  228. var selectStr = $@"SELECT {selectFields}
  229. FROM u_mtrldef
  230. LEFT JOIN u_erpmtrl_price ON u_mtrldef.mtrlid = u_erpmtrl_price.mtrlid";
  231. var whereStr = string.Empty;
  232. if (whereList != null && whereList.Count > 0)
  233. {
  234. whereStr = ListEx.GetWhereStr(whereList);
  235. }
  236. var orderStr = "mtrlcode";
  237. totalcnt = 0;
  238. DbSqlHelper.SelectJoin(cmd, selectStr, whereStr, param, orderStr, outputFileds, pageindex,
  239. pagesize, mtrldefList, ref totalcnt);
  240. return mtrldefList;
  241. }
  242. public void SaveSysPostMessage(u_sys_post message)
  243. {
  244. if (message == null)
  245. {
  246. throw new LJCommonException("未提交公告栏信息!");
  247. }
  248. if (string.IsNullOrEmpty(message.dscrp))
  249. {
  250. throw new LJCommonException($"公告内容不能为空,请检查!");
  251. }
  252. if(message.type == 1 && message.empid == 0)
  253. {
  254. throw new LJCommonException("不允许向超级管理员发布提醒!");
  255. }
  256. AutoInit.AutoInitS(message);
  257. //
  258. message.sdate = message.sdate.Value.Date;
  259. message.edate = message.edate.Value.Date.AddDays(1).AddSeconds(-1);
  260. // 新建
  261. message.postid = BllHelper.GetID(cmd, "u_sys_post");
  262. message.opdate = context.opdate;
  263. message.opemp = context.tokendata.username;
  264. //if(message.empidList != null && message.empidList.Count > 0) message.empids = string.Join(",",message.empidList);
  265. DbSqlHelper.Insert(cmd, "u_sys_post", null, message, "postid,scid,deptid,empid,sdate,edate,dscrp,opemp,opdate,level,type");
  266. }
  267. /// <summary>
  268. /// 保存核价物料资料
  269. /// </summary>
  270. /// <param name="mtrldef"></param>
  271. public void SaveMtrlDef(u_mtrl_price mtrldef)
  272. {
  273. if (mtrldef.mtrlid <= 0)
  274. {
  275. mtrldef.mtrlid = BllHelper.GetID(cmd, "u_mtrl_price");
  276. mtrldef.createtime = context.opdate;
  277. mtrldef.createby = context.tokendata.username;
  278. var fields = @"mtrlid,mtrltype,name,priceunit,shrinkage,gram_weight,cloth_width,if_inputqty,if_areaprice,createtime,createby,thickness,dscrp,erp_mtrlid,fjcnt,isuse,handtype,lastdate,erp_mtrlengname,if_subspecs,extra_cost,is_singleqty";
  279. DbSqlHelper.Insert(cmd, "u_mtrl_price", null, mtrldef, fields);
  280. var fields2 = @"mtrlid,pricelistid,price,pricetype,price_formula,qty_formula";
  281. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  282. {
  283. foreach (var mx in mtrldef.mxlist)
  284. {
  285. AutoInit.AutoInitS(cmd, mx);
  286. mx.mtrlid = mtrldef.mtrlid;
  287. DbSqlHelper.Insert(cmd, "u_mtrl_price_pricelist", null, mx, fields2);
  288. }
  289. }
  290. }
  291. else
  292. {
  293. //修改
  294. var fields = @"mtrltype,name,priceunit,shrinkage,gram_weight,cloth_width,if_inputqty,if_areaprice,thickness,dscrp,erp_mtrlid,fjcnt,isuse,handtype,lastdate,erp_mtrlengname,if_subspecs,extra_cost,is_singleqty";
  295. DbSqlHelper.Update(cmd, "u_mtrl_price", null, mtrldef, "mtrlid", fields);
  296. var fields2 = @"price,pricetype,price_formula,qty_formula";
  297. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  298. {
  299. foreach (var mx in mtrldef.mxlist)
  300. {
  301. AutoInit.AutoInitS(cmd, mx);
  302. DbSqlHelper.Update(cmd, "u_mtrl_price_pricelist", null, mx, "mtrlid,pricelistid", fields2);
  303. }
  304. }
  305. }
  306. Cache.RemoveData<MtrlMapping, u_mtrl_price>(mtrldef.mtrlid);
  307. }
  308. /// <summary>
  309. /// 保存部门资料
  310. /// </summary>
  311. /// <param name="dept"></param>
  312. public void SaveDept(u_dept dept)
  313. {
  314. if (dept.deptid <= 0)
  315. {
  316. cmd.CommandText = @"SELECT COUNT(deptname) AS cnt FROM u_dept WHERE deptname = @deptname";
  317. cmd.Parameters.Clear();
  318. cmd.Parameters.AddWithValue("@deptname", dept.deptname);
  319. var cnt = Convert.ToInt32(cmd.ExecuteScalar());
  320. if (cnt > 0)
  321. {
  322. throw new LJCommonException("存在重复部门名称,请检查!");
  323. }
  324. //新建
  325. dept.createtime = context.opdate;
  326. dept.deptid = BllHelper.GetID(cmd, "u_dept");
  327. var fields = "deptid,deptname,profitrate,pricelistid,springtypeid,createtime,moneyrate,discount,flag,if_rate_auto,manage_amt,mtrltype,managerate,com_profitrate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate,taxes_rate";
  328. DbSqlHelper.Insert(cmd, "u_dept", null, dept, fields);
  329. }
  330. else
  331. {
  332. //修改
  333. dept.moddate = context.opdate;
  334. dept.modemp = context.tokendata.username;
  335. var fields = "deptname,profitrate,pricelistid,springtypeid,moneyrate,discount,flag,if_rate_auto,manage_amt,mtrltype,moddate,modemp,managerate,com_profitrate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate,taxes_rate";
  336. DbSqlHelper.Update(cmd, "u_dept", null, dept, "deptid", fields);
  337. }
  338. Cache.RemoveData<DeptMapping, u_dept>(dept.deptid);
  339. }
  340. public void DeleteSysPostMessage(int postid)
  341. {
  342. if (postid == 0)
  343. {
  344. throw new LJCommonException("删除公告id有误,请检查!");
  345. }
  346. var message = new u_sys_post() { postid = postid };
  347. DbSqlHelper.Delete(cmd, message);
  348. }
  349. }
  350. }