GlobalVar.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. using LJLib.LocalLog;
  2. using LJLib.Net.SPI.Server;
  3. using LJLib.Tools.DEncrypt;
  4. using LJLib.Tools.File;
  5. using System;
  6. using System.Data.SqlClient;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Threading;
  11. using JLHHJSvr.BLL;
  12. using JLHHJSvr.Com;
  13. using JLHHJSvr.Com.APP;
  14. using JLHHJSvr.DBA;
  15. using JLHHJSvr.Excutor;
  16. using JLHHJSvr.Excutor.APP;
  17. using JLHHJSvr.LJLib.HttpServer;
  18. namespace JLHHJSvr
  19. {
  20. public static class GlobalVar
  21. {
  22. private static ExcutorManager excutorManager = null;
  23. private static Timer _timer = null;
  24. private static object _syncRoot = new object();
  25. private static bool _initing = false;
  26. /// <summary>
  27. /// L1业务后台-HTTP端口(HTTP协议)
  28. /// </summary>
  29. public static string ERP_API_URL { get; set; }
  30. /// <summary>
  31. /// L1业务后台-登录账套名
  32. /// </summary>
  33. public static string ERP_ACCOUNT_NAME { get; set; }
  34. /// <summary>
  35. /// L1业务后台-登录账号
  36. /// </summary>
  37. public static string ERP_ACCOUNT_USERNAME { get; set; }
  38. /// <summary>
  39. /// L1业务后台-登录密码
  40. /// </summary>
  41. public static string ERP_ACCOUNT_PASSWORD { get; set; }
  42. /// <summary>
  43. /// L1业务后台-Token
  44. /// </summary>
  45. public static string ERP_TOKEN { get; set; }
  46. public static ILJServer server
  47. {
  48. get
  49. {
  50. return excutorManager;
  51. }
  52. }
  53. internal static void Init()
  54. {
  55. Trace.Listeners.Clear();
  56. Trace.Listeners.Add(new LocalTraceListener(new SyncLogger(new Logger(App_Data))));
  57. try
  58. {
  59. _timer = new Timer((state) =>
  60. {
  61. lock (_syncRoot)
  62. {
  63. if (_initing)
  64. {
  65. return;
  66. }
  67. _initing = true;
  68. }
  69. try
  70. {
  71. if (_timer == null)
  72. {
  73. return;
  74. }
  75. // 获取数据库连接
  76. string xmlfile = GlobalVar.XmlFile;
  77. XmlConfig xmlconfig = new XmlConfig();
  78. string connectionString = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "ConnectionString", string.Empty);
  79. string L1Password = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Password", "");
  80. GlobalVar.ERP_ACCOUNT_NAME = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Server", "");
  81. GlobalVar.ERP_API_URL = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1API", "");
  82. GlobalVar.ERP_ACCOUNT_USERNAME = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Usercode", "");
  83. GlobalVar.ERP_ACCOUNT_PASSWORD = DESEncrypt.Decrypt(L1Password, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  84. if (string.IsNullOrEmpty(connectionString))
  85. {
  86. Trace.Write("未设置数据库连接");
  87. }
  88. else
  89. {
  90. try
  91. {
  92. connectionString = DESEncrypt.Decrypt(connectionString, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  93. GlobalVar.ConnectionString = connectionString;
  94. // DONE: 更新数据库
  95. var version = new ParkDbVersion();
  96. version.CreateTables(GlobalVar.ConnectionString);
  97. BllHelper.InitUser(GlobalVar.ConnectionString);
  98. _timer.Dispose();
  99. _timer = null;
  100. }
  101. catch (Exception ex)
  102. {
  103. Trace.Write(ex.ToString());
  104. GlobalVar.ConnectionString = string.Empty;
  105. }
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. Trace.Write(ex.ToString());
  111. }
  112. finally
  113. {
  114. _initing = false;
  115. }
  116. }, null, 0, 10000);
  117. // HTTP服务
  118. excutorManager = new ExcutorManager();
  119. // excutorManager.AddMap("HelloWord", typeof(HelloWordRequest), new HelloWordExcutor());
  120. excutorManager.AddMap("Login", typeof(LoginRequest), new LoginExcutor());//登陆
  121. excutorManager.AddMap("GetSysUserFileString", typeof(GetSysUserFileStringRequest), new GetSysUserFileStringExcutor());
  122. excutorManager.AddMap("SetSysUserFileString", typeof(SetSysUserFileStringRequest), new SetSysUserFileStringExcutor());
  123. excutorManager.AddMap("CommonDynamicSelect", typeof(CommonDynamicSelectRequest), new CommonDynamicSelectExcutor());
  124. excutorManager.AddMap("GetFileByMd5", typeof(GetFileByMd5Request), new GetFileByMd5Excutor());//根据md5获取文件
  125. excutorManager.AddMap("PostFile", typeof(PostFileRequest), new PostFileExcutor());//上传文件
  126. excutorManager.AddMap("GetUserList", typeof(GetUserListRequest), new GetUserListExcutor());//获取用户列表
  127. excutorManager.AddMap("SaveUserList", typeof(SaveUserListRequest), new SaveUserListExcutor());//保存用户列表
  128. excutorManager.AddMap("DelUserList", typeof(DelUserListRequest), new DelUserListExcutor());//删除用户列表
  129. excutorManager.AddMap("GetSysFuncPwr", typeof(GetSysFuncPwrRequest), new GetSysFuncPwrExcutor());//获取权限列表
  130. excutorManager.AddMap("GetDept", typeof(GetDeptRequest), new GetDeptExcutor());//获取部门列表
  131. excutorManager.AddMap("GetPriceList", typeof(GetPriceListRequest), new GetPriceListExcutor());//获取价格表列表
  132. excutorManager.AddMap("AuditPriceList", typeof(AuditPriceListRequest), new AuditPriceListExcutor());//审核价格表列表
  133. excutorManager.AddMap("SaveDept", typeof(SaveDeptRequest), new SaveDeptExcutor());//保存部门
  134. excutorManager.AddMap("DeleteDept", typeof(DeleteDeptRequest), new DeleteDeptExcutor());//删除部门
  135. excutorManager.AddMap("AuditDept", typeof(AuditDeptRequest), new AuditDeptExcutor());//审核部门
  136. excutorManager.AddMap("SaveProfitrate", typeof(SaveProfitrateRequest), new SaveProfitrateExcutor());// 保存工厂利润率
  137. excutorManager.AddMap("SaveWorkmanship", typeof(SaveWorkmanshipRequest), new SaveWorkmanshipExcutor());// 保存工艺加点设置
  138. excutorManager.AddMap("DeleteWorkmanship", typeof(DeleteWorkmanshipRequest), new DeleteWorkmanshipExcutor());// 删除工艺加点设置
  139. excutorManager.AddMap("AuditWorkmanship", typeof(AuditWorkmanshipRequest), new AuditWorkmanshipExcutor());// 删除工艺加点设置
  140. excutorManager.AddMap("SaveBedNetType", typeof(SaveBedNetTypeRequest), new SaveBedNetTypeExcutor());// 保存床网类别定义
  141. excutorManager.AddMap("DeleteBedNetType", typeof(DeleteBedNetTypeRequest), new DeleteBedNetTypeExcutor());// 删除床网类别定义
  142. excutorManager.AddMap("SaveMattressType", typeof(SaveMattressTypeRequest), new SaveMattressTypeExcutor());// 保存床垫类别定义
  143. excutorManager.AddMap("DeleteMattressType", typeof(DeleteMattressTypeRequest), new DeleteMattressTypeExcutor());// 删除床垫类别定义
  144. excutorManager.AddMap("SaveMattressFormula", typeof(SaveMattressFormulaRequest), new SaveMattressFormulaExcutor());// 保存床垫公式定义
  145. excutorManager.AddMap("DeleteMattressFormula", typeof(DeleteMattressFormulaRequest), new DeleteMattressFormulaExcutor());// 删除床垫公式定义
  146. excutorManager.AddMap("SaveShrinkage", typeof(SaveShrinkageRequest), new SaveShrinkageExcutor());// 保存裥棉收缩率
  147. excutorManager.AddMap("DeleteShrinkage", typeof(DeleteShrinkageRequest), new DeleteShrinkageExcutor());// 删除裥棉收缩率
  148. excutorManager.AddMap("SaveSpring", typeof(SaveSpringRequest), new SaveSpringExcutor());// 保存弹簧资料
  149. excutorManager.AddMap("DeleteSpring", typeof(DeleteSpringRequest), new DeleteSpringExcutor());// 删除弹簧资料
  150. excutorManager.AddMap("AuditSpring", typeof(AuditSpringRequest), new AuditSpringExcutor());// 审核弹簧资料
  151. excutorManager.AddMap("GetBedNetVarList", typeof(GetBedNetVarListRequest), new GetBedNetVarListExcutor());// 获取物料类型
  152. excutorManager.AddMap("SaveBedNetVar", typeof(SaveBedNetVarRequest), new SaveBedNetVarExcutor());// 保存床网/床垫变量定义
  153. excutorManager.AddMap("DeleteBedNetVar", typeof(DeleteBedNetVarRequest), new DeleteBedNetVarExcutor());// 删除床网/床垫变量定义
  154. excutorManager.AddMap("GetMtrlTypeList", typeof(GetMtrlTypeListRequest), new GetMtrlTypeListExcutor());// 获取物料类型
  155. excutorManager.AddMap("SaveMtrlType", typeof(SaveMtrlTypeRequest), new SaveMtrlTypeExcutor());// 获取物料类型
  156. excutorManager.AddMap("DeleteMtrlType", typeof(DeleteMtrlTypeRequest), new DeleteMtrlTypeExcutor());// 获取物料类型
  157. excutorManager.AddMap("GetMtrlDefList", typeof(GetMtrlDefListRequest), new GetMtrlDefListExcutor());// 获取物料资料
  158. excutorManager.AddMap("SaveMtrlDef", typeof(SaveMtrlDefRequest), new SaveMtrlDefExcutor());// 保存物料资料
  159. excutorManager.AddMap("DeleteMtrlDef", typeof(DeleteMtrlDefRequest), new DeleteMtrlDefExcutor());// 删除物料资料
  160. excutorManager.AddMap("BanMtrlDef", typeof(BanMtrlDefRequest), new BanMtrlDefExcutor());// 禁用物料资料
  161. excutorManager.AddMap("CopyMtrlDef", typeof(CopyMtrlDefRequest), new CopyMtrlDefExcutor());// 复制物料资料
  162. excutorManager.AddMap("ModifyMtrlDefList", typeof(ModifyMtrlDefListRequest), new ModifyMtrlDefListExcutor());// 复制物料资料
  163. excutorManager.AddMap("GetFormulaCompute", typeof(GetFormulaComputeRequest), new GetFormulaComputeExcutor());// 公式计算
  164. excutorManager.AddMap("SaveMultiPrice", typeof(SaveMultiPriceRequest), new SaveMultiPriceExcutor());// 保存多维度定价
  165. excutorManager.AddMap("DeleteMultiPrice", typeof(DeleteMultiPriceRequest), new DeleteMultiPriceExcutor());// 删除多维度定价
  166. excutorManager.AddMap("BanMultiPrice", typeof(BanMultiPriceRequest), new BanMultiPriceExcutor());// 禁用多维度定价
  167. excutorManager.AddMap("SaveBedNetArea", typeof(SaveBedNetAreaRequest), new SaveBedNetAreaExcutor());// 保存床网分区定义
  168. excutorManager.AddMap("DeleteBedNetArea", typeof(DeleteBedNetAreaRequest), new DeleteBedNetAreaExcutor());// 删除床网分区定义
  169. excutorManager.AddMap("SaveConfigureType", typeof(SaveConfigureTypeRequest), new SaveConfigureTypeExcutor());// 保存部件选配类型
  170. excutorManager.AddMap("DeleteConfigureType", typeof(DeleteConfigureTypeRequest), new DeleteConfigureTypeExcutor());// 删除部件选配类型
  171. excutorManager.AddMap("SaveConfigureCode", typeof(SaveConfigureCodeRequest), new SaveConfigureCodeExcutor());// 保存部件选配项
  172. excutorManager.AddMap("DeleteConfigureCode", typeof(DeleteConfigureCodeRequest), new DeleteConfigureCodeExcutor());// 删除部件选配项
  173. excutorManager.AddMap("SaveConfigureCodeMx", typeof(SaveConfigureCodeMxRequest), new SaveConfigureCodeMxExcutor());// 保存部件选配项值
  174. excutorManager.AddMap("DeleteConfigureCodeMx", typeof(DeleteConfigureCodeMxRequest), new DeleteConfigureCodeMxExcutor());// 删除部件选配项值
  175. excutorManager.AddMap("GetMattressImportDW2", typeof(GetMattressImportDW2Request), new GetMattressImportDW2Excutor());// 下拉选择床垫类别
  176. excutorManager.AddMap("SaveMattress", typeof(SaveMattressRequest), new SaveMattressExcutor());// 保存床垫报价
  177. excutorManager.AddMap("SaveMattressAuditing", typeof(SaveMattressAuditingRequest), new SaveMattressAuditingExcutor());// 床垫报价:业务下单/取消
  178. excutorManager.AddMap("DelMattress", typeof(DelMattressRequest), new DelMattressExcutor());// 床垫报价:删除
  179. excutorManager.AddMap("SaveMattressBcp", typeof(SaveMattressBcpRequest), new SaveMattressBcpExcutor());// 保存半成品报价
  180. excutorManager.AddMap("DeleteMattressBcp", typeof(DeleteMattressBcpRequest), new DeleteMattressBcpExcutor());// 删除半成品报价
  181. excutorManager.AddMap("AuditMattressBcp", typeof(AuditMattressBcpRequest), new AuditMattressBcpExcutor());// 审核半成品报价
  182. excutorManager.AddMap("GetMattressPackagMx", typeof(GetMattressPackagMxRequest), new GetMattressPackagMxExcutor());// 包装方式切换
  183. excutorManager.AddMap("SaveBedNet", typeof(SaveBedNetRequest), new SaveBedNetExcutor());// 保存床网报价
  184. excutorManager.AddMap("DeleteBedNet", typeof(DeleteBedNetRequest), new DeleteBedNetExcutor());// 删除床网报价
  185. excutorManager.AddMap("AuditBedNet", typeof(AuditBedNetRequest), new AuditBedNetExcutor());// 审核床网报价
  186. excutorManager.AddMap("GetComputeMattress", typeof(GetComputeMattressRequest), new GetComputeMattressExcutor());// 计算床垫报价
  187. excutorManager.AddMap("GetComputeBednet", typeof(GetComputeBednetRequest), new GetComputeBednetExcutor());// 计算床网报价
  188. excutorManager.AddMap("GetComputeSpring", typeof(GetComputeSpringRequest), new GetComputeSpringExcutor());// 计算弹簧数量
  189. excutorManager.AddMap("CopyMattressAudited", typeof(CopyMattressAuditedRequest), new CopyMattressAuditedExcutor());// 复制审核床垫报价
  190. excutorManager.AddMap("ReCalculateNoAudit", typeof(ReCalculateNoAuditRequest), new ReCalculateNoAuditExcutor());// 重算床垫报价
  191. excutorManager.AddMap("ReCalculateBedNetNoAudit", typeof(ReCalculateBedNetNoAuditRequest), new ReCalculateBedNetNoAuditExcutor());// 重算床网报价
  192. excutorManager.AddMap("MattressYWAudit", typeof(MattressYWAuditRequest), new MattressYWAuditExcutor());// 床垫接口业务审核撤审
  193. excutorManager.AddMap("MattressJSAudit", typeof(MattressJSAuditRequest), new MattressJSAuditExcutor());// 床垫接口产品补充审核撤审
  194. excutorManager.AddMap("MattressJS2Audit", typeof(MattressJS2AuditRequest), new MattressJS2AuditExcutor());// 床垫接口清单补充审核撤审
  195. excutorManager.AddMap("SaveMattressInterface", typeof(SaveMattressInterfaceRequest), new SaveMattressInterfaceExcutor());// 床垫接口清单补充审核撤审
  196. excutorManager.AddMap("RefreshMattressInterface", typeof(RefreshMattressInterfaceRequest), new RefreshMattressInterfaceExcutor());// 刷新床垫配置清单
  197. excutorManager.AddMap("RefreshMattressInterfaceQd", typeof(RefreshMattressInterfaceQdRequest), new RefreshMattressInterfaceQdExcutor());// 刷新床垫清单
  198. excutorManager.AddMap("CreatMtrlPf", typeof(CreatMtrlPfRequest), new CreatMtrlPfExcutor());// 生成L1清单
  199. excutorManager.AddMap("UpdateMtrlPrice", typeof(UpdateMtrlPriceRequest), new UpdateMtrlPriceExcutor());// 更新L1计划价
  200. excutorManager.AddMap("DelMtrlPf", typeof(CreatMtrlPfRequest), new DelMtrlPfExcutor());// 删除L1清单
  201. excutorManager.AddMap("GetERPMtrldefList", typeof(GetERPMtrldefListRequest), new GetERPMtrldefListExcutor());// 获取ERP物料资料
  202. excutorManager.AddMap("GetERPConfigureList", typeof(GetERPConfigureListRequest), new GetERPConfigureListExcutor());// 获取ERP配置资料
  203. excutorManager.AddMap("GetERPWrkGrpList", typeof(GetERPWrkGrpListRequest), new GetERPWrkGrpListExcutor());// 获取工组列表
  204. excutorManager.AddMap("GetERPMtrlTypeList", typeof(GetERPMtrlTypeListRequest), new GetERPMtrlTypeListExcutor());// 获取ERP物料类型
  205. excutorManager.AddMap("GetMattressInterfaceList", typeof(GetMattressInterfaceListRequest), new GetMattressInterfaceListExcutor());// 获取产品清单明细
  206. //excutorManager.AddMap("GetSemiFinishedMxList", typeof(GetSemiFinishedMxListRequest), new GetSemiFinishedMxListExcutor());// 获取产品清单明细
  207. //excutorManager.AddMap("ImportSpring", typeof(ImportSpringRequest), new ImportSpringExcutor());
  208. excutorManager.AddMap("SaveMattressExtra", typeof(SaveMattressExtraRequest), new SaveMattressExtraExcutor());// 保存床网分区定义
  209. excutorManager.AddMap("DeleteMattressExtra", typeof(DeleteMattressExtraRequest), new DeleteMattressExtraExcutor());// 删除床网分区定义
  210. excutorManager.AddMap("SaveMattressExtraType", typeof(SaveMattressExtraTypeRequest), new SaveMattressExtraTypeExcutor());// 保存床网分区类型
  211. excutorManager.AddMap("DeleteMattressExtraType", typeof(DeleteMattressExtraTypeRequest), new DeleteMattressExtraTypeExcutor());// 删除床网分区类型
  212. }
  213. catch (Exception ex)
  214. {
  215. Trace.Write(ex.ToString());
  216. }
  217. }
  218. public static string ConnectionString { get; set; }
  219. public static string BinPath
  220. {
  221. get
  222. {
  223. return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
  224. }
  225. }
  226. public static bool webapp { get; set; }
  227. public static string App_Data
  228. {
  229. get
  230. {
  231. string app_data = BinPath;
  232. if (webapp)
  233. {
  234. app_data = Directory.GetParent(app_data).FullName + "\\App_Data";
  235. }
  236. if (!Directory.Exists(app_data))
  237. {
  238. Directory.CreateDirectory(app_data);
  239. }
  240. return app_data;
  241. }
  242. }
  243. public static string XmlFile
  244. {
  245. get
  246. {
  247. return App_Data + "\\config.xml";
  248. }
  249. }
  250. public static string App_Files
  251. {
  252. get
  253. {
  254. string app_files = App_Data + "\\App_Files";
  255. if (!Directory.Exists(app_files))
  256. {
  257. Directory.CreateDirectory(app_files);
  258. }
  259. return app_files;
  260. }
  261. }
  262. public class ParkFileModel:IFileDBModel
  263. {
  264. public byte[] GetBytes(string md5)
  265. {
  266. if (!string.IsNullOrEmpty(md5))
  267. {
  268. using (var con = new SqlConnection(ConnectionString))
  269. using (var cmd = con.CreateCommand())
  270. {
  271. con.Open();
  272. cmd.CommandText = @"SELECT filedata
  273. FROM st_file
  274. WHERE filemd5 = @filemd5 ";
  275. cmd.Parameters.Clear();
  276. cmd.Parameters.AddWithValue("@filemd5", md5);
  277. using (var reader = cmd.ExecuteReader())
  278. {
  279. if (reader.Read())
  280. {
  281. return reader["fileData"] == DBNull.Value ? null : (byte[]) reader["fileData"];
  282. }
  283. }
  284. }
  285. }
  286. return null;
  287. }
  288. }
  289. }
  290. }