BasicInfoHelper.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. public void DeleteSoftBedFormula(u_softbed_formula formula)
  67. {
  68. if (formula == null || formula.formulaid <= 0)
  69. {
  70. throw new LJCommonException("未提交软床公式定义信息");
  71. }
  72. DbSqlHelper.Delete(cmd, formula);
  73. }
  74. /// <summary>
  75. /// 核价软床公式定义-保存
  76. /// </summary>
  77. /// <param name="formula"></param>
  78. public void SaveSoftBedFormula(u_softbed_formula formula)
  79. {
  80. if (formula == null)
  81. {
  82. throw new LJCommonException("未提交软床公式定义信息");
  83. }
  84. if (string.IsNullOrEmpty(formula.formulaname))
  85. {
  86. throw new LJCommonException($"公式名称不能为空,请检查!");
  87. }
  88. var fields = "formulaname,price_formula,use_formula";
  89. if (formula.formulaid <= 0)
  90. {
  91. // 新建
  92. fields += ",formulaid,create_date,create_emp";
  93. formula.formulaid = BllHelper.GetID(cmd, "u_softbed_formula");
  94. formula.create_date = context.opdate;
  95. formula.create_emp = context.tokendata.username;
  96. DbSqlHelper.Insert(cmd, "u_softbed_formula", null, formula, fields);
  97. }
  98. else
  99. {
  100. //修改
  101. fields += ",update_date,update_emp";
  102. formula.update_date = context.opdate;
  103. formula.update_emp = context.tokendata.username;
  104. DbSqlHelper.Update(cmd, "u_softbed_formula", null, formula, "formulaid", fields);
  105. }
  106. }
  107. /// <summary>
  108. /// 保存ERP物料资料定义
  109. /// </summary>
  110. /// <param name="mtrl"></param>
  111. /// <exception cref="LJCommonException"></exception>
  112. public void SaveErpMtrlPrice(u_erpmtrl_price mtrl)
  113. {
  114. var fields = "";
  115. if(mtrl.mtrlid <= 0)
  116. {
  117. throw new LJCommonException("物料ID有误,请检查!");
  118. }
  119. mtrl.update_date = context.opdate;
  120. mtrl.update_emp = context.tokendata.username;
  121. if(DbSqlHelper.Update(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid", "price,update_date,update_emp") == 0)
  122. {
  123. mtrl.create_date = context.opdate;
  124. mtrl.create_emp = context.tokendata.username;
  125. DbSqlHelper.Insert(cmd, "u_erpmtrl_price", null, mtrl, "mtrlid,price,create_date,create_emp");
  126. }
  127. }
  128. /// <summary>
  129. /// 获取ERP物料资料定义
  130. /// </summary>
  131. /// <param name="whereList"></param>
  132. /// <param name="param"></param>
  133. /// <param name="pageindex"></param>
  134. /// <param name="pagesize"></param>
  135. /// <param name="totalcnt"></param>
  136. /// <returns></returns>
  137. public List<L1Mtrldef> GetErpMtrlPriceList(List<string> whereList, Dictionary<string, object> param,int pageindex,int pagesize,out int totalcnt)
  138. {
  139. var mtrldefList = new List<L1Mtrldef>();
  140. 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,
  141. u_mtrldef.unit,u_mtrldef.mtrlmode,u_mtrldef.mtrlsectype,u_mtrldef.zxmtrlmode,u_mtrldef.status_config,u_mtrldef.woodcode_config,
  142. u_mtrldef.pcode_config,u_mtrldef.statustype,u_mtrldef.woodcodetype,u_mtrldef.pcodetype,ISNULL(u_erpmtrl_price.price,0) AS price,
  143. u_erpmtrl_price.create_date,u_erpmtrl_price.create_emp,u_erpmtrl_price.update_date,u_erpmtrl_price.update_emp";
  144. var outputFileds = @"rowNum,scid,mtrlid,mtrlcode,mtrlname,mtrlorigin,mtrltype,mtrlengname,unit,mtrlmode,mtrlsectype,zxmtrlmode,status_config,woodcode_config,
  145. pcode_config,statustype,woodcodetype,pcodetype,price,create_date,create_emp,update_date,update_emp";
  146. var selectStr = $@"SELECT {selectFields}
  147. FROM u_mtrldef
  148. LEFT JOIN u_erpmtrl_price ON u_mtrldef.mtrlid = u_erpmtrl_price.mtrlid";
  149. var whereStr = string.Empty;
  150. if (whereList != null && whereList.Count > 0)
  151. {
  152. whereStr = ListEx.GetWhereStr(whereList);
  153. }
  154. var orderStr = "mtrlcode";
  155. totalcnt = 0;
  156. DbSqlHelper.SelectJoin(cmd, selectStr, whereStr, param, orderStr, outputFileds, pageindex,
  157. pagesize, mtrldefList, ref totalcnt);
  158. return mtrldefList;
  159. }
  160. public void SaveSysPostMessage(u_sys_post message)
  161. {
  162. if (message == null)
  163. {
  164. throw new LJCommonException("未提交公告栏信息!");
  165. }
  166. if (string.IsNullOrEmpty(message.dscrp))
  167. {
  168. throw new LJCommonException($"公告内容不能为空,请检查!");
  169. }
  170. if(message.type == 1 && message.empid == 0)
  171. {
  172. throw new LJCommonException("不允许向超级管理员发布提醒!");
  173. }
  174. AutoInit.AutoInitS(message);
  175. //
  176. message.sdate = message.sdate.Value.Date;
  177. message.edate = message.edate.Value.Date.AddDays(1).AddSeconds(-1);
  178. // 新建
  179. message.postid = BllHelper.GetID(cmd, "u_sys_post");
  180. message.opdate = context.opdate;
  181. message.opemp = context.tokendata.username;
  182. //if(message.empidList != null && message.empidList.Count > 0) message.empids = string.Join(",",message.empidList);
  183. DbSqlHelper.Insert(cmd, "u_sys_post", null, message, "postid,scid,deptid,empid,sdate,edate,dscrp,opemp,opdate,level,type");
  184. }
  185. /// <summary>
  186. /// 保存核价物料资料
  187. /// </summary>
  188. /// <param name="mtrldef"></param>
  189. public void SaveMtrlDef(u_mtrl_price mtrldef)
  190. {
  191. if (mtrldef.mtrlid <= 0)
  192. {
  193. mtrldef.mtrlid = BllHelper.GetID(cmd, "u_mtrl_price");
  194. mtrldef.createtime = context.opdate;
  195. mtrldef.createby = context.tokendata.username;
  196. 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";
  197. DbSqlHelper.Insert(cmd, "u_mtrl_price", null, mtrldef, fields);
  198. var fields2 = @"mtrlid,pricelistid,price,pricetype,price_formula,qty_formula";
  199. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  200. {
  201. foreach (var mx in mtrldef.mxlist)
  202. {
  203. AutoInit.AutoInitS(cmd, mx);
  204. mx.mtrlid = mtrldef.mtrlid;
  205. DbSqlHelper.Insert(cmd, "u_mtrl_price_pricelist", null, mx, fields2);
  206. }
  207. }
  208. }
  209. else
  210. {
  211. //修改
  212. 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";
  213. DbSqlHelper.Update(cmd, "u_mtrl_price", null, mtrldef, "mtrlid", fields);
  214. var fields2 = @"price,pricetype,price_formula,qty_formula";
  215. if (mtrldef.mxlist != null && mtrldef.mxlist.Any())
  216. {
  217. foreach (var mx in mtrldef.mxlist)
  218. {
  219. AutoInit.AutoInitS(cmd, mx);
  220. DbSqlHelper.Update(cmd, "u_mtrl_price_pricelist", null, mx, "mtrlid,pricelistid", fields2);
  221. }
  222. }
  223. }
  224. Cache.RemoveData<MtrlMapping, u_mtrl_price>(mtrldef.mtrlid);
  225. }
  226. /// <summary>
  227. /// 保存部门资料
  228. /// </summary>
  229. /// <param name="dept"></param>
  230. public void SaveDept(u_dept dept)
  231. {
  232. if (dept.deptid <= 0)
  233. {
  234. cmd.CommandText = @"SELECT COUNT(deptname) AS cnt FROM u_dept WHERE deptname = @deptname";
  235. cmd.Parameters.Clear();
  236. cmd.Parameters.AddWithValue("@deptname", dept.deptname);
  237. var cnt = Convert.ToInt32(cmd.ExecuteScalar());
  238. if (cnt > 0)
  239. {
  240. throw new LJCommonException("存在重复部门名称,请检查!");
  241. }
  242. //新建
  243. dept.createtime = context.opdate;
  244. dept.deptid = BllHelper.GetID(cmd, "u_dept");
  245. 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";
  246. DbSqlHelper.Insert(cmd, "u_dept", null, dept, fields);
  247. }
  248. else
  249. {
  250. //修改
  251. dept.moddate = context.opdate;
  252. dept.modemp = context.tokendata.username;
  253. 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";
  254. DbSqlHelper.Update(cmd, "u_dept", null, dept, "deptid", fields);
  255. }
  256. Cache.RemoveData<DeptMapping, u_dept>(dept.deptid);
  257. }
  258. public void DeleteSysPostMessage(int postid)
  259. {
  260. if (postid == 0)
  261. {
  262. throw new LJCommonException("删除公告id有误,请检查!");
  263. }
  264. var message = new u_sys_post() { postid = postid };
  265. DbSqlHelper.Delete(cmd, message);
  266. }
  267. }
  268. }