GlobalVar.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. public static ILJServer server
  27. {
  28. get
  29. {
  30. return excutorManager;
  31. }
  32. }
  33. internal static void Init()
  34. {
  35. Trace.Listeners.Clear();
  36. Trace.Listeners.Add(new LocalTraceListener(new SyncLogger(new Logger(App_Data))));
  37. try
  38. {
  39. _timer = new Timer((state) =>
  40. {
  41. lock (_syncRoot)
  42. {
  43. if (_initing)
  44. {
  45. return;
  46. }
  47. _initing = true;
  48. }
  49. try
  50. {
  51. if (_timer == null)
  52. {
  53. return;
  54. }
  55. // 获取数据库连接
  56. string xmlfile = GlobalVar.XmlFile;
  57. XmlConfig xmlconfig = new XmlConfig();
  58. string connectionString = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "ConnectionString", string.Empty);
  59. if (string.IsNullOrEmpty(connectionString))
  60. {
  61. Trace.Write("未设置数据库连接");
  62. }
  63. else
  64. {
  65. try
  66. {
  67. connectionString = DESEncrypt.Decrypt(connectionString, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  68. GlobalVar.ConnectionString = connectionString;
  69. // DONE: 更新数据库
  70. var version = new ParkDbVersion();
  71. version.CreateTables(GlobalVar.ConnectionString);
  72. BllHelper.InitUser(GlobalVar.ConnectionString);
  73. _timer.Dispose();
  74. _timer = null;
  75. }
  76. catch (Exception ex)
  77. {
  78. Trace.Write(ex.ToString());
  79. GlobalVar.ConnectionString = string.Empty;
  80. }
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. Trace.Write(ex.ToString());
  86. }
  87. finally
  88. {
  89. _initing = false;
  90. }
  91. }, null, 0, 10000);
  92. // HTTP服务
  93. excutorManager = new ExcutorManager();
  94. // excutorManager.AddMap("HelloWord", typeof(HelloWordRequest), new HelloWordExcutor());
  95. excutorManager.AddMap("Login", typeof(LoginRequest), new LoginExcutor());//登陆
  96. excutorManager.AddMap("GetSysUserFileString", typeof(GetSysUserFileStringRequest), new GetSysUserFileStringExcutor());
  97. excutorManager.AddMap("SetSysUserFileString", typeof(SetSysUserFileStringRequest), new SetSysUserFileStringExcutor());
  98. excutorManager.AddMap("CommonDynamicSelect", typeof(CommonDynamicSelectRequest), new CommonDynamicSelectExcutor());
  99. excutorManager.AddMap("GetFileByMd5", typeof(GetFileByMd5Request), new GetFileByMd5Excutor());//根据md5获取文件
  100. excutorManager.AddMap("PostFile", typeof(PostFileRequest), new PostFileExcutor());//上传文件
  101. excutorManager.AddMap("GetUserList", typeof(GetUserListRequest), new GetUserListExcutor());//获取用户列表
  102. excutorManager.AddMap("SaveUserList", typeof(SaveUserListRequest), new SaveUserListExcutor());//保存用户列表
  103. excutorManager.AddMap("DelUserList", typeof(DelUserListRequest), new DelUserListExcutor());//删除用户列表
  104. excutorManager.AddMap("GetSysFuncPwr", typeof(GetSysFuncPwrRequest), new GetSysFuncPwrExcutor());//获取权限列表
  105. excutorManager.AddMap("GetDept", typeof(GetDeptRequest), new GetDeptExcutor());//获取部门列表
  106. excutorManager.AddMap("GetPriceList", typeof(GetPriceListRequest), new GetPriceListExcutor());//获取价格表列表
  107. excutorManager.AddMap("SaveDept", typeof(SaveDeptRequest), new SaveDeptExcutor());//保存部门
  108. excutorManager.AddMap("DeleteDept", typeof(DeleteDeptRequest), new DeleteDeptExcutor());//删除部门
  109. excutorManager.AddMap("SaveProfitrate", typeof(SaveProfitrateRequest), new SaveProfitrateExcutor());// 保存工厂利润率
  110. excutorManager.AddMap("SaveWorkmanship", typeof(SaveWorkmanshipRequest), new SaveWorkmanshipExcutor());// 保存工艺加点设置
  111. excutorManager.AddMap("DeleteWorkmanship", typeof(DeleteWorkmanshipRequest), new DeleteWorkmanshipExcutor());// 删除工艺加点设置
  112. excutorManager.AddMap("SaveBedNetType", typeof(SaveBedNetTypeRequest), new SaveBedNetTypeExcutor());// 保存床网类别定义
  113. excutorManager.AddMap("DeleteBedNetType", typeof(DeleteBedNetTypeRequest), new DeleteBedNetTypeExcutor());// 删除床网类别定义
  114. excutorManager.AddMap("SaveMattressType", typeof(SaveMattressTypeRequest), new SaveMattressTypeExcutor());// 保存床垫类别定义
  115. excutorManager.AddMap("DeleteMattressType", typeof(DeleteMattressTypeRequest), new DeleteMattressTypeExcutor());// 删除床垫类别定义
  116. excutorManager.AddMap("SaveMattressFormula", typeof(SaveMattressFormulaRequest), new SaveMattressFormulaExcutor());// 保存床垫公式定义
  117. excutorManager.AddMap("DeleteMattressFormula", typeof(DeleteMattressFormulaRequest), new DeleteMattressFormulaExcutor());// 删除床垫公式定义
  118. excutorManager.AddMap("SaveShrinkage", typeof(SaveShrinkageRequest), new SaveShrinkageExcutor());// 保存裥棉收缩率
  119. excutorManager.AddMap("DeleteShrinkage", typeof(DeleteShrinkageRequest), new DeleteShrinkageExcutor());// 删除裥棉收缩率
  120. excutorManager.AddMap("SaveSpring", typeof(SaveSpringRequest), new SaveSpringExcutor());// 保存弹簧资料
  121. excutorManager.AddMap("DeleteSpring", typeof(DeleteSpringRequest), new DeleteSpringExcutor());// 删除弹簧资料
  122. excutorManager.AddMap("AuditSpring", typeof(AuditSpringRequest), new AuditSpringExcutor());// 审核弹簧资料
  123. excutorManager.AddMap("GetBedNetVarList", typeof(GetBedNetVarListRequest), new GetBedNetVarListExcutor());// 获取物料类型
  124. excutorManager.AddMap("SaveBedNetVar", typeof(SaveBedNetVarRequest), new SaveBedNetVarExcutor());// 保存床网/床垫变量定义
  125. excutorManager.AddMap("DeleteBedNetVar", typeof(DeleteBedNetVarRequest), new DeleteBedNetVarExcutor());// 删除床网/床垫变量定义
  126. excutorManager.AddMap("GetMtrlTypeList", typeof(GetMtrlTypeListRequest), new GetMtrlTypeListExcutor());// 获取物料类型
  127. excutorManager.AddMap("SaveMtrlType", typeof(SaveMtrlTypeRequest), new SaveMtrlTypeExcutor());// 获取物料类型
  128. excutorManager.AddMap("DeleteMtrlType", typeof(DeleteMtrlTypeRequest), new DeleteMtrlTypeExcutor());// 获取物料类型
  129. excutorManager.AddMap("SaveMtrlDef", typeof(SaveMtrlDefRequest), new SaveMtrlDefExcutor());// 获取物料资料
  130. excutorManager.AddMap("DeleteMtrlDef", typeof(DeleteMtrlDefRequest), new DeleteMtrlDefExcutor());// 删除物料资料
  131. excutorManager.AddMap("BanMtrlDef", typeof(BanMtrlDefRequest), new BanMtrlDefExcutor());// 禁用物料资料
  132. excutorManager.AddMap("GetFormulaCompute", typeof(GetFormulaComputeRequest), new GetFormulaComputeExcutor());// 公式计算
  133. excutorManager.AddMap("SaveMultiPrice", typeof(SaveMultiPriceRequest), new SaveMultiPriceExcutor());// 保存多维度定价
  134. excutorManager.AddMap("DeleteMultiPrice", typeof(DeleteMultiPriceRequest), new DeleteMultiPriceExcutor());// 删除多维度定价
  135. excutorManager.AddMap("BanMultiPrice", typeof(BanMultiPriceRequest), new BanMultiPriceExcutor());// 禁用多维度定价
  136. excutorManager.AddMap("SaveBedNetArea", typeof(SaveBedNetAreaRequest), new SaveBedNetAreaExcutor());// 保存床网分区定义
  137. excutorManager.AddMap("DeleteBedNetArea", typeof(DeleteBedNetAreaRequest), new DeleteBedNetAreaExcutor());// 删除床网分区定义
  138. excutorManager.AddMap("SaveConfigureType", typeof(SaveConfigureTypeRequest), new SaveConfigureTypeExcutor());// 保存部件选配类型
  139. excutorManager.AddMap("DeleteConfigureType", typeof(DeleteConfigureTypeRequest), new DeleteConfigureTypeExcutor());// 删除部件选配类型
  140. excutorManager.AddMap("SaveConfigureCode", typeof(SaveConfigureCodeRequest), new SaveConfigureCodeExcutor());// 保存部件选配项
  141. excutorManager.AddMap("DeleteConfigureCode", typeof(DeleteConfigureCodeRequest), new DeleteConfigureCodeExcutor());// 删除部件选配项
  142. excutorManager.AddMap("SaveConfigureCodeMx", typeof(SaveConfigureCodeMxRequest), new SaveConfigureCodeMxExcutor());// 保存部件选配项值
  143. excutorManager.AddMap("DeleteConfigureCodeMx", typeof(DeleteConfigureCodeMxRequest), new DeleteConfigureCodeMxExcutor());// 删除部件选配项值
  144. excutorManager.AddMap("GetMattressImportDW2", typeof(GetMattressImportDW2Request), new GetMattressImportDW2Excutor());// 下拉选择床垫类别
  145. excutorManager.AddMap("SaveMattress", typeof(SaveMattressRequest), new SaveMattressExcutor());// 保存床垫报价
  146. excutorManager.AddMap("SaveMattressAuditing", typeof(SaveMattressAuditingRequest), new SaveMattressAuditingExcutor());// 床垫报价:业务下单/取消
  147. excutorManager.AddMap("DelMattress", typeof(DelMattressRequest), new DelMattressExcutor());// 床垫报价:删除
  148. excutorManager.AddMap("SaveMattressBcp", typeof(SaveMattressBcpRequest), new SaveMattressBcpExcutor());// 保存半成品报价
  149. excutorManager.AddMap("DeleteMattressBcp", typeof(DeleteMattressBcpRequest), new DeleteMattressBcpExcutor());// 删除半成品报价
  150. excutorManager.AddMap("AuditMattressBcp", typeof(AuditMattressBcpRequest), new AuditMattressBcpExcutor());// 审核半成品报价
  151. excutorManager.AddMap("SaveBedNet", typeof(SaveBedNetRequest), new SaveBedNetExcutor());// 保存床网报价
  152. excutorManager.AddMap("DeleteBedNet", typeof(DeleteBedNetRequest), new DeleteBedNetExcutor());// 删除床网报价
  153. excutorManager.AddMap("AuditBedNet", typeof(AuditBedNetRequest), new AuditBedNetExcutor());// 审核床网报价
  154. excutorManager.AddMap("GetComputeMattress", typeof(GetComputeMattressRequest), new GetComputeMattressExcutor());// 计算床垫报价
  155. excutorManager.AddMap("GetComputeBednet", typeof(GetComputeBednetRequest), new GetComputeBednetExcutor());// 计算床网报价
  156. excutorManager.AddMap("CopyMattressAudited", typeof(CopyMattressAuditedRequest), new CopyMattressAuditedExcutor());// 复制审核床垫报价
  157. excutorManager.AddMap("ReCalculateNoAudit", typeof(ReCalculateNoAuditRequest), new ReCalculateNoAuditExcutor());// 重算床垫报价
  158. excutorManager.AddMap("ReCalculateBedNetNoAudit", typeof(ReCalculateBedNetNoAuditRequest), new ReCalculateBedNetNoAuditExcutor());// 重算床网报价
  159. }
  160. catch (Exception ex)
  161. {
  162. Trace.Write(ex.ToString());
  163. }
  164. }
  165. public static string ConnectionString { get; set; }
  166. public static string BinPath
  167. {
  168. get
  169. {
  170. return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
  171. }
  172. }
  173. public static bool webapp { get; set; }
  174. public static string App_Data
  175. {
  176. get
  177. {
  178. string app_data = BinPath;
  179. if (webapp)
  180. {
  181. app_data = Directory.GetParent(app_data).FullName + "\\App_Data";
  182. }
  183. if (!Directory.Exists(app_data))
  184. {
  185. Directory.CreateDirectory(app_data);
  186. }
  187. return app_data;
  188. }
  189. }
  190. public static string XmlFile
  191. {
  192. get
  193. {
  194. return App_Data + "\\config.xml";
  195. }
  196. }
  197. public static string App_Files
  198. {
  199. get
  200. {
  201. string app_files = App_Data + "\\App_Files";
  202. if (!Directory.Exists(app_files))
  203. {
  204. Directory.CreateDirectory(app_files);
  205. }
  206. return app_files;
  207. }
  208. }
  209. public class ParkFileModel:IFileDBModel
  210. {
  211. public byte[] GetBytes(string md5)
  212. {
  213. if (!string.IsNullOrEmpty(md5))
  214. {
  215. using (var con = new SqlConnection(ConnectionString))
  216. using (var cmd = con.CreateCommand())
  217. {
  218. con.Open();
  219. cmd.CommandText = @"SELECT filedata
  220. FROM st_file
  221. WHERE filemd5 = @filemd5 ";
  222. cmd.Parameters.Clear();
  223. cmd.Parameters.AddWithValue("@filemd5", md5);
  224. using (var reader = cmd.ExecuteReader())
  225. {
  226. if (reader.Read())
  227. {
  228. return reader["fileData"] == DBNull.Value ? null : (byte[]) reader["fileData"];
  229. }
  230. }
  231. }
  232. }
  233. return null;
  234. }
  235. }
  236. }
  237. }