GlobalVar.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. using LJLib;
  19. using LJLib.TextLog;
  20. using JLHHJSvr.Tools;
  21. using JLHHJSvr.Helper;
  22. namespace JLHHJSvr
  23. {
  24. public static class GlobalVar
  25. {
  26. private static ExcutorManager excutorManager = null;
  27. private static Timer _timer = null;
  28. private static DailySchedulerManager _dailySchedulerManager = null;
  29. private static IntervalSchedulerManager _intervalSchedulerManager = null;
  30. private static ScheduleTaskHelper _scheduleTaskHelper = null;
  31. private static object _syncRoot = new object();
  32. private static bool _initing = false;
  33. /// <summary>
  34. /// L1业务后台-HTTP端口(HTTP协议)
  35. /// </summary>
  36. public static string ERP_API_URL { get; set; }
  37. /// <summary>
  38. /// L1业务后台-登录账套名
  39. /// </summary>
  40. public static string ERP_ACCOUNT_NAME { get; set; }
  41. /// <summary>
  42. /// L1业务后台-登录账号
  43. /// </summary>
  44. public static string ERP_ACCOUNT_USERNAME { get; set; }
  45. /// <summary>
  46. /// L1业务后台-登录密码
  47. /// </summary>
  48. public static string ERP_ACCOUNT_PASSWORD { get; set; }
  49. /// <summary>
  50. /// L1业务后台-Token
  51. /// </summary>
  52. public static string ERP_TOKEN { get; set; }
  53. public static ILJServer server
  54. {
  55. get
  56. {
  57. return excutorManager;
  58. }
  59. }
  60. internal static void Init()
  61. {
  62. Trace.Listeners.Clear();
  63. Trace.Listeners.Add(new LocalTraceListener(new SyncLogger(new Logger(App_Data))));
  64. try
  65. {
  66. _timer = new Timer((state) =>
  67. {
  68. lock (_syncRoot)
  69. {
  70. if (_initing)
  71. {
  72. return;
  73. }
  74. _initing = true;
  75. }
  76. try
  77. {
  78. if (_timer == null)
  79. {
  80. return;
  81. }
  82. // 获取数据库连接
  83. string xmlfile = GlobalVar.XmlFile;
  84. XmlConfig xmlconfig = new XmlConfig();
  85. string connectionString = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "ConnectionString", string.Empty);
  86. string L1Password = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Password", "");
  87. GlobalVar.ERP_ACCOUNT_NAME = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Server", "");
  88. GlobalVar.ERP_API_URL = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1API", "");
  89. GlobalVar.ERP_ACCOUNT_USERNAME = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "L1Usercode", "");
  90. GlobalVar.ERP_ACCOUNT_PASSWORD = DESEncrypt.Decrypt(L1Password, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  91. if (string.IsNullOrEmpty(connectionString))
  92. {
  93. Trace.Write("未设置数据库连接");
  94. }
  95. else
  96. {
  97. try
  98. {
  99. connectionString = DESEncrypt.Decrypt(connectionString, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  100. GlobalVar.ConnectionString = connectionString;
  101. // DONE: 更新数据库
  102. var version = new ParkDbVersion();
  103. version.CreateTables(GlobalVar.ConnectionString);
  104. BllHelper.InitUser(GlobalVar.ConnectionString);
  105. _timer.Dispose();
  106. _timer = null;
  107. }
  108. catch (Exception ex)
  109. {
  110. Trace.Write(ex.ToString());
  111. GlobalVar.ConnectionString = string.Empty;
  112. }
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. Trace.Write(ex.ToString());
  118. }
  119. finally
  120. {
  121. _initing = false;
  122. }
  123. }, null, 0, 10000);
  124. // HTTP服务
  125. excutorManager = new ExcutorManager();
  126. // excutorManager.AddMap("HelloWord", typeof(HelloWordRequest), new HelloWordExcutor());
  127. excutorManager.AddMap("Login", typeof(LoginRequest), new LoginExcutor());//登陆
  128. excutorManager.AddMap("ChangePassword", typeof(ChangePasswordRequest), new ChangePasswordExcutor());
  129. excutorManager.AddMap("GetSysUserFileString", typeof(GetSysUserFileStringRequest), new GetSysUserFileStringExcutor());
  130. excutorManager.AddMap("SetSysUserFileString", typeof(SetSysUserFileStringRequest), new SetSysUserFileStringExcutor());
  131. excutorManager.AddMap("CommonDynamicSelect", typeof(CommonDynamicSelectRequest), new CommonDynamicSelectExcutor());
  132. excutorManager.AddMap("PingToken", typeof(PingTokenRequest), new PingTokenExcutor());//没啥用
  133. excutorManager.AddMap("GetFileByMd5", typeof(GetFileByMd5Request), new GetFileByMd5Excutor());//根据md5获取文件
  134. excutorManager.AddMap("PostFile", typeof(PostFileRequest), new PostFileExcutor());//上传文件
  135. excutorManager.AddMap("GetUserList", typeof(GetUserListRequest), new GetUserListExcutor());//获取用户列表
  136. excutorManager.AddMap("SaveUserList", typeof(SaveUserListRequest), new SaveUserListExcutor());//保存用户列表
  137. excutorManager.AddMap("DelUserList", typeof(DelUserListRequest), new DelUserListExcutor());//删除用户列表
  138. excutorManager.AddMap("UnLockUser", typeof(UnLockUserRequest), new UnLockUserExcutor());//删除用户列表
  139. excutorManager.AddMap("GetSysFuncPwr", typeof(GetSysFuncPwrRequest), new GetSysFuncPwrExcutor());//获取权限列表
  140. excutorManager.AddMap("GetDept", typeof(GetDeptRequest), new GetDeptExcutor());//获取部门列表
  141. excutorManager.AddMap("GetPriceList", typeof(GetPriceListRequest), new GetPriceListExcutor());//获取价格表列表
  142. excutorManager.AddMap("AuditPriceList", typeof(AuditPriceListRequest), new AuditPriceListExcutor());//审核价格表列表
  143. excutorManager.AddMap("SaveDept", typeof(SaveDeptRequest), new SaveDeptExcutor());//保存部门
  144. excutorManager.AddMap("DeleteDept", typeof(DeleteDeptRequest), new DeleteDeptExcutor());//删除部门
  145. excutorManager.AddMap("AuditDept", typeof(AuditDeptRequest), new AuditDeptExcutor());//审核部门
  146. excutorManager.AddMap("SaveProfitrate", typeof(SaveProfitrateRequest), new SaveProfitrateExcutor());// 保存工厂利润率
  147. excutorManager.AddMap("SaveWorkmanship", typeof(SaveWorkmanshipRequest), new SaveWorkmanshipExcutor());// 保存工艺加点设置
  148. excutorManager.AddMap("DeleteWorkmanship", typeof(DeleteWorkmanshipRequest), new DeleteWorkmanshipExcutor());// 删除工艺加点设置
  149. excutorManager.AddMap("AuditWorkmanship", typeof(AuditWorkmanshipRequest), new AuditWorkmanshipExcutor());// 删除工艺加点设置
  150. excutorManager.AddMap("SaveBedNetType", typeof(SaveBedNetTypeRequest), new SaveBedNetTypeExcutor());// 保存床网类别定义
  151. excutorManager.AddMap("DeleteBedNetType", typeof(DeleteBedNetTypeRequest), new DeleteBedNetTypeExcutor());// 删除床网类别定义
  152. excutorManager.AddMap("SaveMattressType", typeof(SaveMattressTypeRequest), new SaveMattressTypeExcutor());// 保存床垫类别定义
  153. excutorManager.AddMap("DeleteMattressType", typeof(DeleteMattressTypeRequest), new DeleteMattressTypeExcutor());// 删除床垫类别定义
  154. excutorManager.AddMap("SaveMattressFormula", typeof(SaveMattressFormulaRequest), new SaveMattressFormulaExcutor());// 保存床垫公式定义
  155. excutorManager.AddMap("DeleteMattressFormula", typeof(DeleteMattressFormulaRequest), new DeleteMattressFormulaExcutor());// 删除床垫公式定义
  156. excutorManager.AddMap("SaveShrinkage", typeof(SaveShrinkageRequest), new SaveShrinkageExcutor());// 保存裥棉收缩率
  157. excutorManager.AddMap("DeleteShrinkage", typeof(DeleteShrinkageRequest), new DeleteShrinkageExcutor());// 删除裥棉收缩率
  158. excutorManager.AddMap("SaveSpring", typeof(SaveSpringRequest), new SaveSpringExcutor());// 保存弹簧资料
  159. excutorManager.AddMap("DeleteSpring", typeof(DeleteSpringRequest), new DeleteSpringExcutor());// 删除弹簧资料
  160. excutorManager.AddMap("AuditSpring", typeof(AuditSpringRequest), new AuditSpringExcutor());// 审核弹簧资料
  161. excutorManager.AddMap("GetBedNetVarList", typeof(GetBedNetVarListRequest), new GetBedNetVarListExcutor());// 获取物料类型
  162. excutorManager.AddMap("SaveBedNetVar", typeof(SaveBedNetVarRequest), new SaveBedNetVarExcutor());// 保存床网/床垫变量定义
  163. excutorManager.AddMap("DeleteBedNetVar", typeof(DeleteBedNetVarRequest), new DeleteBedNetVarExcutor());// 删除床网/床垫变量定义
  164. excutorManager.AddMap("GetMtrlTypeList", typeof(GetMtrlTypeListRequest), new GetMtrlTypeListExcutor());// 获取物料类型
  165. excutorManager.AddMap("SaveMtrlType", typeof(SaveMtrlTypeRequest), new SaveMtrlTypeExcutor());// 获取物料类型
  166. excutorManager.AddMap("DeleteMtrlType", typeof(DeleteMtrlTypeRequest), new DeleteMtrlTypeExcutor());// 获取物料类型
  167. excutorManager.AddMap("GetMtrlDefList", typeof(GetMtrlDefListRequest), new GetMtrlDefListExcutor());// 获取物料资料
  168. excutorManager.AddMap("SaveMtrlDef", typeof(SaveMtrlDefRequest), new SaveMtrlDefExcutor());// 保存物料资料
  169. excutorManager.AddMap("DeleteMtrlDef", typeof(DeleteMtrlDefRequest), new DeleteMtrlDefExcutor());// 删除物料资料
  170. excutorManager.AddMap("BanMtrlDef", typeof(BanMtrlDefRequest), new BanMtrlDefExcutor());// 禁用物料资料
  171. excutorManager.AddMap("CopyMtrlDef", typeof(CopyMtrlDefRequest), new CopyMtrlDefExcutor());// 复制物料资料
  172. excutorManager.AddMap("ModifyMtrlDefList", typeof(ModifyMtrlDefListRequest), new ModifyMtrlDefListExcutor());// 复制物料资料
  173. excutorManager.AddMap("GetFormulaCompute", typeof(GetFormulaComputeRequest), new GetFormulaComputeExcutor());// 公式计算
  174. excutorManager.AddMap("SaveMultiPrice", typeof(SaveMultiPriceRequest), new SaveMultiPriceExcutor());// 保存多维度定价
  175. excutorManager.AddMap("DeleteMultiPrice", typeof(DeleteMultiPriceRequest), new DeleteMultiPriceExcutor());// 删除多维度定价
  176. excutorManager.AddMap("BanMultiPrice", typeof(BanMultiPriceRequest), new BanMultiPriceExcutor());// 禁用多维度定价
  177. excutorManager.AddMap("SaveBedNetArea", typeof(SaveBedNetAreaRequest), new SaveBedNetAreaExcutor());// 保存床网分区定义
  178. excutorManager.AddMap("DeleteBedNetArea", typeof(DeleteBedNetAreaRequest), new DeleteBedNetAreaExcutor());// 删除床网分区定义
  179. excutorManager.AddMap("SaveConfigureType", typeof(SaveConfigureTypeRequest), new SaveConfigureTypeExcutor());// 保存部件选配类型
  180. excutorManager.AddMap("DeleteConfigureType", typeof(DeleteConfigureTypeRequest), new DeleteConfigureTypeExcutor());// 删除部件选配类型
  181. excutorManager.AddMap("SaveConfigureCode", typeof(SaveConfigureCodeRequest), new SaveConfigureCodeExcutor());// 保存部件选配项
  182. excutorManager.AddMap("DeleteConfigureCode", typeof(DeleteConfigureCodeRequest), new DeleteConfigureCodeExcutor());// 删除部件选配项
  183. excutorManager.AddMap("SaveConfigureCodeMx", typeof(SaveConfigureCodeMxRequest), new SaveConfigureCodeMxExcutor());// 保存部件选配项值
  184. excutorManager.AddMap("DeleteConfigureCodeMx", typeof(DeleteConfigureCodeMxRequest), new DeleteConfigureCodeMxExcutor());// 删除部件选配项值
  185. excutorManager.AddMap("SaveConfigureBomList", typeof(SaveConfigureBomListRequest), new SaveConfigureBomListExcutor());// 删除部件选配项值
  186. excutorManager.AddMap("DeleteConfigureBomList", typeof(DeleteConfigureBomListRequest), new DeleteConfigureBomListExcutor());// 删除部件选配项值
  187. excutorManager.AddMap("GetMattressImportDW2", typeof(GetMattressImportDW2Request), new GetMattressImportDW2Excutor());// 下拉选择床垫类别
  188. excutorManager.AddMap("SaveMattress", typeof(SaveMattressRequest), new SaveMattressExcutor());// 保存床垫报价
  189. excutorManager.AddMap("SaveMattressAuditing", typeof(SaveMattressAuditingRequest), new SaveMattressAuditingExcutor());// 床垫报价:业务下单/取消
  190. excutorManager.AddMap("DelMattress", typeof(DelMattressRequest), new DelMattressExcutor());// 床垫报价:删除
  191. excutorManager.AddMap("SaveMattressBcp", typeof(SaveMattressBcpRequest), new SaveMattressBcpExcutor());// 保存半成品报价
  192. excutorManager.AddMap("DeleteMattressBcp", typeof(DeleteMattressBcpRequest), new DeleteMattressBcpExcutor());// 删除半成品报价
  193. excutorManager.AddMap("AuditMattressBcp", typeof(AuditMattressBcpRequest), new AuditMattressBcpExcutor());// 审核半成品报价
  194. excutorManager.AddMap("GetMattressPackagMx", typeof(GetMattressPackagMxRequest), new GetMattressPackagMxExcutor());// 包装方式切换
  195. excutorManager.AddMap("GetMattressSubspecs", typeof(GetMattressSubspecsRequest), new GetMattressSubspecsExcutor());// 获取主副规格
  196. excutorManager.AddMap("SaveBedNet", typeof(SaveBedNetRequest), new SaveBedNetExcutor());// 保存床网报价
  197. excutorManager.AddMap("DeleteBedNet", typeof(DeleteBedNetRequest), new DeleteBedNetExcutor());// 删除床网报价
  198. excutorManager.AddMap("AuditBedNet", typeof(AuditBedNetRequest), new AuditBedNetExcutor());// 审核床网报价
  199. excutorManager.AddMap("GetComputeMattress", typeof(GetComputeMattressRequest), new GetComputeMattressExcutor());// 计算床垫报价
  200. excutorManager.AddMap("GetComputeMattressById", typeof(GetComputeMattressByIdRequest), new GetComputeMattressByIdExcutor());// 计算床垫报价
  201. excutorManager.AddMap("GetComputeBednet", typeof(GetComputeBednetRequest), new GetComputeBednetExcutor());// 计算床网报价
  202. excutorManager.AddMap("GetComputeSpring", typeof(GetComputeSpringRequest), new GetComputeSpringExcutor());// 计算弹簧数量
  203. excutorManager.AddMap("CopyMattressAudited", typeof(CopyMattressAuditedRequest), new CopyMattressAuditedExcutor());// 复制审核床垫报价
  204. excutorManager.AddMap("ReCalculateNoAudit", typeof(ReCalculateNoAuditRequest), new ReCalculateNoAuditExcutor());// 重算床垫报价
  205. excutorManager.AddMap("ReCalculateBedNetNoAudit", typeof(ReCalculateBedNetNoAuditRequest), new ReCalculateBedNetNoAuditExcutor());// 重算床网报价
  206. excutorManager.AddMap("ReCalculateERPCost", typeof(ReCalculateERPCostRequest), new ReCalculateERPCostExcutor());// 重算床网报价
  207. excutorManager.AddMap("CreateScheduleTask", typeof(CreateScheduleTaskRequest), new CreateScheduleTaskExcutor());// 创建定时任务
  208. excutorManager.AddMap("CoverMattressInterface", typeof(CoverMattressInterfaceRequest), new CoverMattressInterfaceExcutor());// 覆盖配置到副规格产品
  209. excutorManager.AddMap("MattressYWAudit", typeof(MattressYWAuditRequest), new MattressYWAuditExcutor());// 床垫接口业务审核撤审
  210. excutorManager.AddMap("MattressJSAudit", typeof(MattressJSAuditRequest), new MattressJSAuditExcutor());// 床垫接口产品补充审核撤审
  211. excutorManager.AddMap("MattressJS2Audit", typeof(MattressJS2AuditRequest), new MattressJS2AuditExcutor());// 床垫接口清单补充审核撤审
  212. excutorManager.AddMap("SaveMattressInterface", typeof(SaveMattressInterfaceRequest), new SaveMattressInterfaceExcutor());// 床垫接口清单补充审核撤审
  213. excutorManager.AddMap("BatchModifyMattressInterfaceConfig", typeof(BatchModifyMattressInterfaceConfigRequest), new BatchModifyMattressInterfaceConfigExcutor());// 床垫清单批量批改配置
  214. excutorManager.AddMap("RefreshMattressInterface", typeof(RefreshMattressInterfaceRequest), new RefreshMattressInterfaceExcutor());// 刷新床垫配置清单
  215. excutorManager.AddMap("RefreshMattressInterfaceQd", typeof(RefreshMattressInterfaceQdRequest), new RefreshMattressInterfaceQdExcutor());// 刷新床垫清单
  216. excutorManager.AddMap("CreatMtrldef", typeof(CreatMtrldefRequest), new CreatMtrldefExcutor());// 生成L1物料
  217. excutorManager.AddMap("UpdateMtrlPrice", typeof(UpdateMtrlPriceRequest), new UpdateMtrlPriceExcutor());// 更新L1计划价
  218. excutorManager.AddMap("DelMtrlPf", typeof(CreatMtrldefRequest), new DelMtrlPfExcutor());// 删除L1清单
  219. excutorManager.AddMap("CreatPrdPf", typeof(CreatPrdPfRequest), new CreatPrdPfExcutor());// 生成L1清单
  220. excutorManager.AddMap("GetERPMtrldefList", typeof(GetERPMtrldefListRequest), new GetERPMtrldefListExcutor());// 获取ERP物料资料
  221. excutorManager.AddMap("GetERPConfigureList", typeof(GetERPConfigureListRequest), new GetERPConfigureListExcutor());// 获取ERP配置资料
  222. excutorManager.AddMap("GetERPWrkGrpList", typeof(GetERPWrkGrpListRequest), new GetERPWrkGrpListExcutor());// 获取工组列表
  223. excutorManager.AddMap("GetERPMtrlTypeList", typeof(GetERPMtrlTypeListRequest), new GetERPMtrlTypeListExcutor());// 获取ERP物料类型
  224. excutorManager.AddMap("GetMattressInterfaceList", typeof(GetMattressInterfaceListRequest), new GetMattressInterfaceListExcutor());// 获取产品清单明细
  225. //excutorManager.AddMap("GetSemiFinishedMxList", typeof(GetSemiFinishedMxListRequest), new GetSemiFinishedMxListExcutor());// 获取产品清单明细
  226. //excutorManager.AddMap("ImportSpring", typeof(ImportSpringRequest), new ImportSpringExcutor());
  227. excutorManager.AddMap("SaveMattressExtra", typeof(SaveMattressExtraRequest), new SaveMattressExtraExcutor());// 保存床网分区定义
  228. excutorManager.AddMap("DeleteMattressExtra", typeof(DeleteMattressExtraRequest), new DeleteMattressExtraExcutor());// 删除床网分区定义
  229. excutorManager.AddMap("SaveMattressExtraType", typeof(SaveMattressExtraTypeRequest), new SaveMattressExtraTypeExcutor());// 保存床网分区类型
  230. excutorManager.AddMap("DeleteMattressExtraType", typeof(DeleteMattressExtraTypeRequest), new DeleteMattressExtraTypeExcutor());// 删除床网分区类型
  231. excutorManager.AddMap("GetFormulaVarList",typeof(GetFormulaVarListRequest),new GetFormulaVarListExcutor());
  232. excutorManager.AddMap("FormulaCheck", typeof(FormulaCheckRequest),new FormulaCheckExcutor());
  233. excutorManager.AddMap("JLH_FetchPrice", typeof(JLH_FetchPriceRequest), new JLH_FetchPriceExcutor());
  234. excutorManager.AddMap("GetResetWiptype", typeof(GetResetWiptypeRequest), new GetResetWiptypeExcutor());
  235. excutorManager.AddMap("ImportMtrlPriceByExcel", typeof(ImportMtrlPriceByExcelRequest), new ImportMtrlPriceByExcelExcutor()); //更新物料价格表单价
  236. excutorManager.AddMap("UpdateL1Basicinfo", typeof(UpdateL1BasicinfoRequest), new UpdateL1BasicinfoExcutor()); // 更新L1基础资料(物料、物料分类、工组)
  237. excutorManager.AddMap("GetBedNetInterfaceList", typeof(GetBedNetInterfaceListRequest), new GetBedNetInterfaceListExcutor()); // 床网清单获取
  238. excutorManager.AddMap("SaveBedNetInterface", typeof(SaveBedNetInterfaceRequest), new SaveBedNetInterfaceExcutor());// 床网接口清单补充审核撤审
  239. excutorManager.AddMap("RefreshBedNetInterface", typeof(RefreshBedNetInterfaceRequest), new RefreshBedNetInterfaceExcutor());// 刷新床网配置清单
  240. excutorManager.AddMap("RefreshBedNetInterfaceQd", typeof(RefreshBedNetInterfaceQdRequest), new RefreshBedNetInterfaceQdExcutor());// 刷新床网清单
  241. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. excutorManager.AddMap("CopyConfigureCodeMxList", typeof(CopyConfigureCodeMxListRequest), new CopyConfigureCodeMxListExcutor()); // 复制部件选配项值
  243. excutorManager.AddMap("SaveSoftBedQuote", typeof(SaveSoftBedQuoteRequest), new SaveSoftBedQuoteExcutor()); // 保存/修改软床报价
  244. excutorManager.AddMap("DeleteSoftBedQuote", typeof(DeleteSoftBedQuoteRequest), new DeleteSoftBedQuoteExcutor()); // 删除软床报价
  245. excutorManager.AddMap("AuditSoftBedQuote", typeof(AuditSoftBedQuoteRequest), new AuditSoftBedQuoteExcutor()); // 审核软床报价
  246. excutorManager.AddMap("GetSoftBedMxList", typeof(GetSoftBedMxListRequest), new GetSoftBedMxListExcutor()); // 获取软床报价明细
  247. excutorManager.AddMap("GetSoftBedConfigureList", typeof(GetSoftBedConfigureListRequest), new GetSoftBedConfigureListExcutor()); // 获取软床报价部件选配
  248. excutorManager.AddMap("DeleteSoftBedFormula", typeof(DeleteSoftBedFormulaRequest), new DeleteSoftBedFormulaExcutor()); // 删除软床公式定义
  249. excutorManager.AddMap("SaveSoftBedFormula", typeof(SaveSoftBedFormulaRequest), new SaveSoftBedFormulaExcutor()); // 保存软床公式定义
  250. excutorManager.AddMap("SaveErpMtrlPriceList", typeof(SaveErpMtrlPriceListRequest), new SaveErpMtrlPriceListExcutor()); // 保存物料价格
  251. excutorManager.AddMap("GetErpMtrlPriceList", typeof(GetErpMtrlPriceListRequest), new GetErpMtrlPriceListExcutor()); // 获取ERP物料资料定义
  252. excutorManager.AddMap("GetChangeSoftBedMxList", typeof(GetChangeSoftBedMxListRequest), new GetChangeSoftBedMxListExcutor()); // 获取软床报价换料后明细
  253. excutorManager.AddMap("SaveMattressSubSpecs", typeof(SaveMattressSubSpecsRequest), new SaveMattressSubSpecsExcutor()); // 获取软床报价换料后明细
  254. excutorManager.AddMap("SaveSysPost", typeof(SaveSysPostRequest), new SaveSysPostExcutor()); // 发布公告
  255. excutorManager.AddMap("DeleteSysPostMessage", typeof(DeleteSysPostMessageRequest), new DeleteSysPostMessageExcutor()); // 删除公告
  256. excutorManager.AddMap("LockTable", typeof(LockTableRequest), new LockTableExcutor()); // 单据加锁
  257. excutorManager.AddMap("UnLockTable", typeof(UnLockTableRequest), new UnLockTableExcutor()); // 单据解锁
  258. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  259. //excutorManager.AddMap("AdminTestFunction", typeof(AdminTestFunctionRequest), new AdminTestFunctionExcutor());
  260. }
  261. catch (Exception ex)
  262. {
  263. Trace.Write(ex.ToString());
  264. }
  265. }
  266. /// <summary>
  267. /// 定时任务
  268. /// </summary>
  269. public static void StartTimer()
  270. {
  271. _dailySchedulerManager = new DailySchedulerManager();
  272. _intervalSchedulerManager = new IntervalSchedulerManager();
  273. //定时执行任务
  274. _dailySchedulerManager.AddTask("ClearExpireLock", new TimeSpan(2, 0, 0),() => ClearExpireLock());
  275. _dailySchedulerManager.AddTask("ClearOldLogs", new TimeSpan(2, 0, 0),() => CleanupOldLogs());
  276. // 定时轮询执行任务
  277. _scheduleTaskHelper = new ScheduleTaskHelper();
  278. _intervalSchedulerManager.AddTask("ScheduleTask", TimeSpan.FromMinutes(1), () => _scheduleTaskHelper.ExecuteDueTasks());
  279. }
  280. /// <summary>
  281. /// 清理7天前的请求日志文件
  282. /// </summary>
  283. public static void CleanupOldLogs()
  284. {
  285. try
  286. {
  287. var files = Directory.GetFiles(Path.Combine(App_Data, "log"), "REQUEST_*.log");
  288. DateTime threshold = DateTime.Now.AddDays(-7);
  289. foreach (var file in files)
  290. {
  291. string fileName = Path.GetFileNameWithoutExtension(file);
  292. // 格式: REQUEST_yyyyMMdd
  293. if (fileName.Length == "REQUEST_yyyyMMdd".Length &&
  294. DateTime.TryParseExact(fileName.Replace("REQUEST_", ""),
  295. "yyyyMMdd",
  296. null,
  297. System.Globalization.DateTimeStyles.None,
  298. out DateTime logDate))
  299. {
  300. if (logDate < threshold.Date)
  301. {
  302. File.Delete(file);
  303. }
  304. }
  305. }
  306. }
  307. catch(Exception ex)
  308. {
  309. Trace.Write(ex);
  310. }
  311. }
  312. /// <summary>
  313. /// 清理过期锁
  314. /// </summary>
  315. public static void ClearExpireLock()
  316. {
  317. using (SqlConnection con = new SqlConnection(GlobalVar.ConnectionString))
  318. using (SqlCommand cmd = con.CreateCommand())
  319. {
  320. con.Open();
  321. using (cmd.Transaction = con.BeginTransaction())
  322. {
  323. try
  324. {
  325. LockHelper.ClearExpireLock(cmd);
  326. cmd.Transaction.Commit();
  327. }
  328. catch (Exception e)
  329. {
  330. cmd.Transaction?.Rollback();
  331. }
  332. }
  333. }
  334. }
  335. public static string ConnectionString { get; set; }
  336. public static string BinPath
  337. {
  338. get
  339. {
  340. return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
  341. }
  342. }
  343. public static bool webapp { get; set; }
  344. public static string App_Data
  345. {
  346. get
  347. {
  348. string app_data = BinPath;
  349. if (webapp)
  350. {
  351. app_data = Directory.GetParent(app_data).FullName + "\\App_Data";
  352. }
  353. if (!Directory.Exists(app_data))
  354. {
  355. Directory.CreateDirectory(app_data);
  356. }
  357. return app_data;
  358. }
  359. }
  360. /// <summary>
  361. /// 是否Web启动模式
  362. /// </summary>
  363. public static bool WebMode { get; set; }
  364. public static string XmlFile
  365. {
  366. get
  367. {
  368. return App_Data + "\\config.xml";
  369. }
  370. }
  371. public static string DataPath
  372. {
  373. get
  374. {
  375. var binpath = FilePathHelper.GetExecutingPath();
  376. string dataPath = binpath;
  377. if (WebMode)
  378. {
  379. dataPath = Directory.GetParent(binpath).FullName + "\\App_Data";
  380. }
  381. if (!Directory.Exists(dataPath))
  382. {
  383. Directory.CreateDirectory(dataPath);
  384. }
  385. return dataPath;
  386. }
  387. }
  388. public static string App_Files
  389. {
  390. get
  391. {
  392. string app_files = App_Data + "\\App_Files";
  393. if (!Directory.Exists(app_files))
  394. {
  395. Directory.CreateDirectory(app_files);
  396. }
  397. return app_files;
  398. }
  399. }
  400. public class ParkFileModel:IFileDBModel
  401. {
  402. public byte[] GetBytes(string md5)
  403. {
  404. if (!string.IsNullOrEmpty(md5))
  405. {
  406. using (var con = new SqlConnection(ConnectionString))
  407. using (var cmd = con.CreateCommand())
  408. {
  409. con.Open();
  410. cmd.CommandText = @"SELECT filedata
  411. FROM st_file
  412. WHERE filemd5 = @filemd5 ";
  413. cmd.Parameters.Clear();
  414. cmd.Parameters.AddWithValue("@filemd5", md5);
  415. using (var reader = cmd.ExecuteReader())
  416. {
  417. if (reader.Read())
  418. {
  419. return reader["fileData"] == DBNull.Value ? null : (byte[]) reader["fileData"];
  420. }
  421. }
  422. }
  423. }
  424. return null;
  425. }
  426. }
  427. }
  428. }