BasicInfoHelper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using static JLHHJSvr.Helper.CacheHelper;
  11. namespace JLHHJSvr.Helper
  12. {
  13. internal class BasicInfoHelper: HelperBase
  14. {
  15. /// <summary>
  16. /// 核价选配类型-保存
  17. /// </summary>
  18. /// <param name="configure"></param>
  19. public void SaveConfigureType(u_configure_type configure)
  20. {
  21. if (configure.contfigtypeid <= 0)
  22. {
  23. configure.contfigtypeid = BllHelper.GetID(cmd, "u_configure_type");
  24. var fields = @"contfigtypeid,contfigtype,contfigtypename,usechflag,flag";
  25. DbSqlHelper.Insert(cmd, "u_configure_type", null, configure, fields);
  26. }
  27. else
  28. {
  29. configure.moddate = context.opdate;
  30. configure.modemp = context.tokendata.username;
  31. //修改
  32. var fields = @"contfigtype,contfigtypename,usechflag,modemp,moddate";
  33. DbSqlHelper.Update(cmd, "u_configure_type", null, configure, "contfigtypeid", fields);
  34. }
  35. }
  36. /// <summary>
  37. /// 核价选配项值-保存
  38. /// </summary>
  39. /// <param name="configure"></param>
  40. public void SaveConfigureCodeMx(u_configure_codemx codeMx)
  41. {
  42. if (codeMx.printid <= 0)
  43. {
  44. int _printid = 0;
  45. cmd.CommandText = @"SELECT ISNULL(MAX(printid),0) AS printid FROM u_configure_codemx WHERE pzid = @pzid";
  46. cmd.Parameters.Clear();
  47. cmd.Parameters.AddWithValue("@pzid", codeMx.pzid);
  48. using (var reader = cmd.ExecuteReader())
  49. {
  50. if (reader.Read())
  51. {
  52. _printid = Convert.ToInt32(reader["printid"]);
  53. }
  54. }
  55. codeMx.printid = _printid + 1;
  56. var fields = @"pzid,printid,pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  57. DbSqlHelper.Insert(cmd, "u_configure_codemx", null, codeMx, fields);
  58. }
  59. else
  60. {
  61. //修改
  62. var fields = @"pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  63. DbSqlHelper.Update(cmd, "u_configure_codemx", null, codeMx, "pzid,printid", fields);
  64. }
  65. }
  66. /// <summary>
  67. /// 核价软床公式定义-保存
  68. /// </summary>
  69. /// <param name="formula"></param>
  70. public void SaveSoftBedFormula(u_softbed_formula formula)
  71. {
  72. if (formula == null)
  73. {
  74. throw new LJCommonException("未提交软床公式定义信息");
  75. }
  76. if (string.IsNullOrEmpty(formula.formulaname))
  77. {
  78. throw new LJCommonException($"公式名称不能为空,请检查!");
  79. }
  80. var fields = "formulaname,price_formula,use_formula";
  81. if (formula.formulaid <= 0)
  82. {
  83. // 新建
  84. fields += ",formulaid,create_date,create_emp";
  85. formula.formulaid = BllHelper.GetID(cmd, "u_softbed_formula");
  86. formula.create_date = context.opdate;
  87. formula.create_emp = context.tokendata.username;
  88. DbSqlHelper.Insert(cmd, "u_softbed_formula", null, formula, fields);
  89. }
  90. else
  91. {
  92. //修改
  93. fields += ",update_date,update_emp";
  94. formula.update_date = context.opdate;
  95. formula.update_emp = context.tokendata.username;
  96. DbSqlHelper.Update(cmd, "u_softbed_formula", null, formula, "formulaid", fields);
  97. }
  98. }
  99. /// <summary>
  100. /// 保存ERP物料资料定义
  101. /// </summary>
  102. /// <param name="mtrl"></param>
  103. /// <exception cref="LJCommonException"></exception>
  104. public void SaveErpMtrlPrice(u_erpmtrl_price mtrl)
  105. {
  106. var fields = "";
  107. if(mtrl.mtrlid <= 0)
  108. {
  109. throw new LJCommonException("物料ID有误,请检查!");
  110. }
  111. mtrl.update_date = context.opdate;
  112. mtrl.update_emp = context.tokendata.username;
  113. if(DbSqlHelper.Update(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid", "price,update_date,update_emp") == 0)
  114. {
  115. mtrl.create_date = context.opdate;
  116. mtrl.create_emp = context.tokendata.username;
  117. DbSqlHelper.Insert(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid,price,create_date,create_emp");
  118. }
  119. }
  120. /// <summary>
  121. /// 获取ERP物料资料定义
  122. /// </summary>
  123. /// <param name="whereList"></param>
  124. /// <param name="param"></param>
  125. /// <param name="pageindex"></param>
  126. /// <param name="pagesize"></param>
  127. /// <param name="totalcnt"></param>
  128. /// <returns></returns>
  129. public List<L1Mtrldef> GetErpMtrlPriceList(List<string> whereList, Dictionary<string, object> param,int pageindex,int pagesize,out int totalcnt)
  130. {
  131. var mtrldefList = new List<L1Mtrldef>();
  132. 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,
  133. u_mtrldef.unit,u_mtrldef.mtrlmode,u_mtrldef.mtrlsectype,u_mtrldef.zxmtrlmode,u_mtrldef.status_config,u_mtrldef.woodcode_config,
  134. u_mtrldef.pcode_config,u_mtrldef.statustype,u_mtrldef.woodcodetype,u_mtrldef.pcodetype,ISNULL(u_erpmtrl_price.price,0) AS price,
  135. u_erpmtrl_price.create_date,u_erpmtrl_price.create_emp,u_erpmtrl_price.update_date,u_erpmtrl_price.update_emp";
  136. var outputFileds = @"rowNum,scid,mtrlid,mtrlcode,mtrlname,mtrlorigin,mtrltype,mtrlengname,unit,mtrlmode,mtrlsectype,zxmtrlmode,status_config,woodcode_config,
  137. pcode_config,statustype,woodcodetype,pcodetype,price,create_date,create_emp,update_date,update_emp";
  138. var selectStr = $@"SELECT {selectFields}
  139. FROM u_mtrldef
  140. LEFT JOIN u_erpmtrl_price ON u_mtrldef.mtrlid = u_erpmtrl_price.mtrlid";
  141. var whereStr = string.Empty;
  142. if (whereList != null && whereList.Count > 0)
  143. {
  144. whereStr = ListEx.GetWhereStr(whereList);
  145. }
  146. var orderStr = "mtrlcode";
  147. totalcnt = 0;
  148. DbSqlHelper.SelectJoin(cmd, selectStr, whereStr, param, orderStr, outputFileds, pageindex,
  149. pagesize, mtrldefList, ref totalcnt);
  150. return mtrldefList;
  151. }
  152. public void SaveSysPostMessage(u_sys_post message)
  153. {
  154. if (message == null)
  155. {
  156. throw new LJCommonException("未提交公告栏信息!");
  157. }
  158. if (string.IsNullOrEmpty(message.dscrp))
  159. {
  160. throw new LJCommonException($"公告内容不能为空,请检查!");
  161. }
  162. if(message.type == 1 && message.empid == 0)
  163. {
  164. throw new LJCommonException("不允许向超级管理员发布提醒!");
  165. }
  166. AutoInit.AutoInitS(message);
  167. //
  168. message.sdate = message.sdate.Value.Date;
  169. message.edate = message.edate.Value.Date.AddDays(1).AddSeconds(-1);
  170. // 新建
  171. message.postid = BllHelper.GetID(cmd, "u_sys_post");
  172. message.opdate = context.opdate;
  173. message.opemp = context.tokendata.username;
  174. //if(message.empidList != null && message.empidList.Count > 0) message.empids = string.Join(",",message.empidList);
  175. DbSqlHelper.Insert(cmd, "u_sys_post", null, message, "postid,scid,deptid,empid,sdate,edate,dscrp,opemp,opdate,level,type");
  176. }
  177. /// <summary>
  178. /// 保存核价物料资料
  179. /// </summary>
  180. /// <param name="mtrldef"></param>
  181. public void SaveMtrlDef(u_mtrl_price mtrldef)
  182. {
  183. if (mtrldef.mtrlid <= 0)
  184. {
  185. mtrldef.mtrlid = BllHelper.GetID(cmd, "u_mtrl_price");
  186. mtrldef.createtime = context.opdate;
  187. mtrldef.createby = context.tokendata.username;
  188. 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";
  189. DbSqlHelper.Insert(cmd, "u_mtrl_price", null, mtrldef, fields);
  190. var fields2 = @"mtrlid,pricelistid,price,pricetype,price_formula,qty_formula";
  191. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  192. {
  193. foreach (var mx in mtrldef.mxlist)
  194. {
  195. AutoInit.AutoInitS(cmd, mx);
  196. mx.mtrlid = mtrldef.mtrlid;
  197. DbSqlHelper.Insert(cmd, "u_mtrl_price_pricelist", null, mx, fields2);
  198. }
  199. }
  200. }
  201. else
  202. {
  203. //修改
  204. 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";
  205. DbSqlHelper.Update(cmd, "u_mtrl_price", null, mtrldef, "mtrlid", fields);
  206. var fields2 = @"price,pricetype,price_formula,qty_formula";
  207. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  208. {
  209. foreach (var mx in mtrldef.mxlist)
  210. {
  211. AutoInit.AutoInitS(cmd, mx);
  212. DbSqlHelper.Update(cmd, "u_mtrl_price_pricelist", null, mx, "mtrlid,pricelistid", fields2);
  213. }
  214. }
  215. }
  216. Cache.RemoveData<MtrlMapping, u_mtrl_price>(mtrldef.mtrlid);
  217. }
  218. /// <summary>
  219. /// 保存部门资料
  220. /// </summary>
  221. /// <param name="dept"></param>
  222. public void SaveDept(u_dept dept)
  223. {
  224. if (dept.deptid <= 0)
  225. {
  226. cmd.CommandText = @"SELECT COUNT(deptname) AS cnt FROM u_dept WHERE deptname = @deptname";
  227. cmd.Parameters.Clear();
  228. cmd.Parameters.AddWithValue("@deptname", dept.deptname);
  229. var cnt = Convert.ToInt32(cmd.ExecuteScalar());
  230. if (cnt > 0)
  231. {
  232. throw new LJCommonException("存在重复部门名称,请检查!");
  233. }
  234. //新建
  235. dept.createtime = context.opdate;
  236. dept.deptid = BllHelper.GetID(cmd, "u_dept");
  237. 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";
  238. DbSqlHelper.Insert(cmd, "u_dept", null, dept, fields);
  239. }
  240. else
  241. {
  242. //修改
  243. dept.moddate = context.opdate;
  244. dept.modemp = context.tokendata.username;
  245. 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";
  246. DbSqlHelper.Update(cmd, "u_dept", null, dept, "deptid", fields);
  247. }
  248. Cache.RemoveData<DeptMapping, u_dept>(dept.deptid);
  249. }
  250. public void DeleteSysPostMessage(int postid)
  251. {
  252. if (postid == 0)
  253. {
  254. throw new LJCommonException("删除公告id有误,请检查!");
  255. }
  256. var message = new u_sys_post() { postid = postid };
  257. DbSqlHelper.Delete(cmd, message);
  258. }
  259. }
  260. }