You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
17 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. namespace EasyBL.WEBAPP.WSM
  7. {
  8. public class ArgumentMaintain_UpdService : ServiceBase
  9. {
  10. #region 參數值(單筆查詢)
  11. /// <summary>
  12. /// 參數值(單筆查詢)
  13. /// </summary>
  14. /// <param name="i_crm"></param>
  15. /// <returns></returns>
  16. public ResponseMessage QueryOne(RequestMessage i_crm)
  17. {
  18. ResponseMessage rm = null;
  19. string sMsg = null;
  20. var db = SugarBase.GetIntance();
  21. try
  22. {
  23. do
  24. {
  25. var sArgumentClassID = _fetchString(i_crm, @"ArgumentClassID");
  26. var sArgumentID = _fetchString(i_crm, @"ArgumentID");
  27. var oEntity = db.Queryable<OTB_SYS_Arguments, OTB_SYS_Members, OTB_SYS_Members>
  28. ((t1, t2, t3) =>
  29. new object[] {
  30. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  31. JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
  32. }
  33. )
  34. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.ArgumentClassID == sArgumentClassID && t1.ArgumentID == sArgumentID)
  35. .Select((t1, t2, t3) => new OTB_SYS_Arguments
  36. {
  37. ArgumentID = SqlFunc.GetSelfAndAutoFill(t1.ArgumentID),
  38. CreateUserName = t2.MemberName,
  39. ModifyUserName = t3.MemberName
  40. })
  41. .Single();
  42. //var json = db.Queryable<OTB_SYS_Profiles>().ToJson();
  43. //var json2 = db.Queryable<OTB_SYS_Members>().ToList();
  44. //var data = db.Queryable<OTB_SYS_Members>().Select<KeyValuePair<string, string>>("MemberID,MemberName").ToList();
  45. //foreach (var item in json2)
  46. //{
  47. // Console.WriteLine(item.MemberName);
  48. // Console.WriteLine(item.Department.DepartmentName);
  49. // Console.WriteLine(item.Rules.Count);
  50. //}
  51. //var list = db.Queryable<OTB_SYS_Members>().Select<ExpandoObject>("*").ToList();
  52. //foreach (var item in list)
  53. //{
  54. // var dic = item.ToDictionary(x => x.Key, x => x.Value);
  55. // //dic的Key为列的名称, value为列的值
  56. //}
  57. rm = new SuccessResponseMessage(null, i_crm);
  58. rm.DATA.Add(BLWording.REL, oEntity);
  59. } while (false);
  60. }
  61. catch (Exception ex)
  62. {
  63. sMsg = Util.GetLastExceptionMsg(ex);
  64. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), "", "QueryOne(參數值(單筆查詢))", "", "", "");
  65. }
  66. finally
  67. {
  68. if (null != sMsg)
  69. {
  70. rm = new ErrorResponseMessage(sMsg, i_crm);
  71. }
  72. }
  73. return rm;
  74. }
  75. #endregion 參數值(單筆查詢)
  76. #region 參數值(多筆)
  77. /// <summary>
  78. /// 參數值(多筆)
  79. /// </summary>
  80. /// <param name="i_crm"></param>
  81. /// <returns></returns>
  82. public ResponseMessage QueryList(RequestMessage i_crm)
  83. {
  84. ResponseMessage rm = null;
  85. string sMsg = null;
  86. var db = SugarBase.GetIntance();
  87. try
  88. {
  89. do
  90. {
  91. var saArgumentClass = db.Queryable<OTB_SYS_Arguments>()
  92. .Where(X => X.OrgID == i_crm.ORIGID && X.Effective == "Y" && X.DelStatus == "N").ToList();
  93. rm = new SuccessResponseMessage(null, i_crm);
  94. rm.DATA.Add(BLWording.REL, saArgumentClass);
  95. } while (false);
  96. }
  97. catch (Exception ex)
  98. {
  99. sMsg = Util.GetLastExceptionMsg(ex);
  100. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.SYS.Leave_QryService", "", "QueryList(參數值(多筆))", "", "", "");
  101. }
  102. finally
  103. {
  104. if (null != sMsg)
  105. {
  106. rm = new ErrorResponseMessage(sMsg, i_crm);
  107. }
  108. }
  109. return rm;
  110. }
  111. #endregion 參數值(多筆)
  112. #region 參數值(新增)
  113. /// <summary>
  114. /// 參數值(新增)
  115. /// </summary>
  116. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  117. /// <returns></returns>
  118. public ResponseMessage Insert(RequestMessage i_crm)
  119. {
  120. ResponseMessage rm = null;
  121. string sMsg = null;
  122. try
  123. {
  124. rm = SugarBase.ExecTran(db =>
  125. {
  126. do
  127. {
  128. var oEntity = _fetchEntity<OTB_SYS_Arguments>(i_crm);
  129. _setEntityBase(oEntity, i_crm);
  130. oEntity.LevelOfArgument = 0;
  131. if (!string.IsNullOrEmpty(oEntity.ParentArgument))
  132. {
  133. var oParent = db.Queryable<OTB_SYS_Arguments>()
  134. .Single(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oEntity.ArgumentClassID && x.ArgumentID == oEntity.ParentArgument);
  135. oEntity.LevelOfArgument = oParent.LevelOfArgument + 1;
  136. }
  137. oEntity.DelStatus = "N";
  138. var iOldCout = db.Queryable<OTB_SYS_Arguments>().Count(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oEntity.ArgumentClassID);
  139. if (oEntity.OrderByValue <= iOldCout)
  140. {
  141. var iRelUp = db.Updateable<OTB_SYS_Arguments>()
  142. .UpdateColumns(x => new OTB_SYS_Arguments { OrderByValue = x.OrderByValue + 1 })
  143. .Where(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oEntity.ArgumentClassID && x.OrderByValue >= oEntity.OrderByValue)
  144. .ExecuteCommand();
  145. }
  146. var oEntity_Del = db.Queryable<OTB_SYS_Arguments>()
  147. .Single(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oEntity.ArgumentClassID && x.ArgumentID == oEntity.ArgumentID && x.DelStatus == "Y");
  148. var iRel = 0;
  149. if (oEntity_Del != null)
  150. {
  151. oEntity_Del.OrderByValue = oEntity.OrderByValue;
  152. oEntity_Del.LevelOfArgument = oEntity.LevelOfArgument;
  153. oEntity_Del.DelStatus = "N";
  154. oEntity_Del.Memo = oEntity.Memo;
  155. oEntity_Del.ArgumentValue = oEntity.ArgumentValue;
  156. oEntity_Del.ArgumentValue_CN = oEntity.ArgumentValue_CN;
  157. oEntity_Del.ArgumentValue_EN = oEntity.ArgumentValue_EN;
  158. oEntity_Del.ParentArgument = oEntity.ParentArgument;
  159. oEntity_Del.Effective = oEntity.Effective;
  160. iRel = db.Updateable(oEntity_Del)
  161. .IgnoreColumns(x => new
  162. {
  163. x.CreateUser,
  164. x.CreateDate
  165. }).ExecuteCommand();
  166. }
  167. else
  168. {
  169. iRel = db.Insertable(oEntity).ExecuteCommand();
  170. }
  171. rm = new SuccessResponseMessage(null, i_crm);
  172. rm.DATA.Add(BLWording.REL, iRel);
  173. } while (false);
  174. return rm;
  175. });
  176. }
  177. catch (Exception ex)
  178. {
  179. sMsg = Util.GetLastExceptionMsg(ex);
  180. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), @"參數值", @"Add(參數值(新增))", @"", @"", @"");
  181. }
  182. finally
  183. {
  184. if (null != sMsg)
  185. {
  186. rm = new ErrorResponseMessage(sMsg, i_crm);
  187. }
  188. }
  189. return rm;
  190. }
  191. #endregion 參數值(新增)
  192. #region 參數值(修改)
  193. /// <summary>
  194. /// 參數值(修改)
  195. /// </summary>
  196. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  197. /// <returns></returns>
  198. public ResponseMessage Update(RequestMessage i_crm)
  199. {
  200. ResponseMessage rm = null;
  201. string sMsg = null;
  202. try
  203. {
  204. rm = SugarBase.ExecTran(db =>
  205. {
  206. do
  207. {
  208. var oNewEntity = _fetchEntity<OTB_SYS_Arguments>(i_crm);
  209. _setEntityBase(oNewEntity, i_crm);
  210. oNewEntity.DelStatus = "N";
  211. oNewEntity.LevelOfArgument = 0;
  212. if (!string.IsNullOrEmpty(oNewEntity.ParentArgument))
  213. {
  214. var oParent = db.Queryable<OTB_SYS_Arguments>()
  215. .Single(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oNewEntity.ArgumentClassID && x.ArgumentID == oNewEntity.ParentArgument);
  216. oNewEntity.LevelOfArgument = oParent.LevelOfArgument + 1;
  217. }
  218. var oOldEntity = db.Queryable<OTB_SYS_Arguments>().Single(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == oNewEntity.ArgumentClassID && x.ArgumentID == oNewEntity.ArgumentID);
  219. if (oNewEntity.OrderByValue > oOldEntity.OrderByValue)
  220. {
  221. var iRelUp = db.Updateable<OTB_SYS_Arguments>()
  222. .UpdateColumns(x => new OTB_SYS_Arguments { OrderByValue = x.OrderByValue - 1 })
  223. .Where(x => x.OrgID == oNewEntity.OrgID && x.ArgumentClassID == oNewEntity.ArgumentClassID && x.OrderByValue <= oNewEntity.OrderByValue && x.OrderByValue > oOldEntity.OrderByValue).ExecuteCommand();
  224. }
  225. else
  226. {
  227. var iRelDown = db.Updateable<OTB_SYS_Arguments>()
  228. .UpdateColumns(x => new OTB_SYS_Arguments { OrderByValue = x.OrderByValue + 1 })
  229. .Where(x => x.OrgID == oNewEntity.OrgID && x.ArgumentClassID == oNewEntity.ArgumentClassID && x.OrderByValue >= oNewEntity.OrderByValue && x.OrderByValue < oOldEntity.OrderByValue).ExecuteCommand();
  230. }
  231. var iRel = db.Updateable(oNewEntity)
  232. .IgnoreColumns(x => new
  233. {
  234. x.CreateUser,
  235. x.CreateDate
  236. }).ExecuteCommand();
  237. rm = new SuccessResponseMessage(null, i_crm);
  238. rm.DATA.Add(BLWording.REL, iRel);
  239. } while (false);
  240. return rm;
  241. });
  242. }
  243. catch (Exception ex)
  244. {
  245. sMsg = Util.GetLastExceptionMsg(ex);
  246. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), @"參數值", @"Update(參數值(修改))", @"", @"", @"");
  247. }
  248. finally
  249. {
  250. if (null != sMsg)
  251. {
  252. rm = new ErrorResponseMessage(sMsg, i_crm);
  253. }
  254. }
  255. return rm;
  256. }
  257. #endregion 參數值(修改)
  258. #region 參數值(刪除)
  259. /// <summary>
  260. /// 參數值(刪除)
  261. /// </summary>
  262. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  263. /// <returns></returns>
  264. public ResponseMessage Delete(RequestMessage i_crm)
  265. {
  266. ResponseMessage rm = null;
  267. string sMsg = null;
  268. try
  269. {
  270. rm = SugarBase.ExecTran(db =>
  271. {
  272. do
  273. {
  274. var sArgumentClassID = _fetchString(i_crm, @"ArgumentClassID");
  275. var sArgumentID = _fetchString(i_crm, @"ArgumentID");
  276. var oEntity = db.Queryable<OTB_SYS_Arguments>().Single(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == sArgumentClassID && x.ArgumentID == sArgumentID);
  277. var iRel = db.Updateable<OTB_SYS_Arguments>()
  278. .UpdateColumns(x => new OTB_SYS_Arguments { DelStatus = "Y" })
  279. .Where(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == sArgumentClassID && x.ArgumentID == sArgumentID).ExecuteCommand();
  280. var iRelUp = db.Updateable<OTB_SYS_Arguments>()
  281. .UpdateColumns(x => new OTB_SYS_Arguments { OrderByValue = x.OrderByValue - 1 })
  282. .Where(x => x.OrgID == oEntity.OrgID && x.ArgumentClassID == sArgumentClassID && x.OrderByValue > oEntity.OrderByValue)
  283. .ExecuteCommand();
  284. rm = new SuccessResponseMessage(null, i_crm);
  285. rm.DATA.Add(BLWording.REL, iRel);
  286. } while (false);
  287. return rm;
  288. });
  289. }
  290. catch (Exception ex)
  291. {
  292. sMsg = Util.GetLastExceptionMsg(ex);
  293. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), @"參數值", @"Delete(參數值(刪除))", @"", @"", @"");
  294. }
  295. finally
  296. {
  297. if (null != sMsg)
  298. {
  299. rm = new ErrorResponseMessage(sMsg, i_crm);
  300. }
  301. }
  302. return rm;
  303. }
  304. #endregion 參數值(刪除)
  305. #region 參數值(查詢筆數)
  306. /// <summary>
  307. /// 參數值(查詢筆數)
  308. /// </summary>
  309. /// <param name="i_crm"></param>
  310. /// <returns></returns>
  311. public ResponseMessage QueryCout(RequestMessage i_crm)
  312. {
  313. ResponseMessage rm = null;
  314. string sMsg = null;
  315. var db = SugarBase.GetIntance();
  316. try
  317. {
  318. do
  319. {
  320. var sArgumentClassID = _fetchString(i_crm, @"ArgumentClassID");
  321. var sArgumentID = _fetchString(i_crm, @"ArgumentID");
  322. var iCout = db.Queryable<OTB_SYS_Arguments>()
  323. .Where(x => x.OrgID == i_crm.ORIGID && x.DelStatus == "N")
  324. .WhereIF(!string.IsNullOrEmpty(sArgumentClassID), x => x.ArgumentClassID == sArgumentClassID)
  325. .WhereIF(!string.IsNullOrEmpty(sArgumentID), x => x.ArgumentID == sArgumentID)
  326. .Count();
  327. rm = new SuccessResponseMessage(null, i_crm);
  328. rm.DATA.Add(BLWording.REL, iCout);
  329. } while (false);
  330. }
  331. catch (Exception ex)
  332. {
  333. sMsg = Util.GetLastExceptionMsg(ex);
  334. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), "", "QueryCout(參數值(查詢筆數))", "", "", "");
  335. }
  336. finally
  337. {
  338. if (null != sMsg)
  339. {
  340. rm = new ErrorResponseMessage(sMsg, i_crm);
  341. }
  342. }
  343. return rm;
  344. }
  345. #endregion 參數值(查詢筆數)
  346. }
  347. }