CgzjZjbzflRepository.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using QM.KJGH.CGGL.IRepository;
  2. using QM.KJGH.CGGL.Model.Cggl;
  3. using QM.KJGH.Model.KJGH;
  4. using QM.OrmSqlSugar;
  5. using System;
  6. using System.Threading.Tasks;
  7. using WS;
  8. namespace QM.KJGH.CGGL.Repository
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public class CgzjZjbzflRepository : SqlSugarRepository<CgzjZjbzfl>, ICgzjZjbzflRepository
  14. {
  15. /// <summary>
  16. /// 添加审查分组
  17. /// </summary>
  18. /// <returns></returns>
  19. public async Task<bool> Add(CgzjZjbzfl input)
  20. {
  21. if (string.IsNullOrWhiteSpace(input.BSM))
  22. {
  23. var chk = await GetAsync(t => t.FLMC == input.FLMC && t.ZJFA_BSM == input.ZJFA_BSM && t.FBSM == input.FBSM);
  24. if(chk != null)
  25. throw new UseMassageException(input.FLMC + " 已经在,请重新输入");
  26. input.BSM = DateTime.Now.ToTimeStamp();
  27. await InsertAsync(input);
  28. }
  29. else
  30. {
  31. var chk = await GetAsync(t => t.FLMC == input.FLMC && t.ZJFA_BSM == input.ZJFA_BSM && t.FBSM == input.FBSM && t.BSM != input.BSM);
  32. if (chk != null)
  33. throw new UseMassageException(input.FLMC + " 已经在,请重新输入");
  34. await UpdateAsync(input);
  35. }
  36. return true;
  37. }
  38. /// <summary>
  39. /// 修改审查项分类
  40. /// </summary>
  41. /// <returns></returns>
  42. public async Task<bool> Update(CgglScflDto input)
  43. {
  44. var model = await GetAsync(t => t.BSM == input.BSM);
  45. if (model == null)
  46. throw new UseArgumentException("参数错误");
  47. model.FLMC = input.FLMC;
  48. return await UpdateAsync(model);
  49. }
  50. /// <summary>
  51. /// 删除方案
  52. /// </summary>
  53. /// <returns></returns>
  54. public async Task<bool> Delete(CgglScflDto input)
  55. {
  56. var db = DbClient();
  57. try
  58. {
  59. db.BeginTran();
  60. //删除之前的方案
  61. await db.Deleteable<CgzjZjbzfl>(t => t.BSM == input.BSM || t.FBSM == input.BSM).ExecuteCommandAsync();
  62. await db.Deleteable<CgzjZjbz>(t => t.FLBSM == input.BSM).ExecuteCommandAsync();
  63. db.CommitTran();
  64. return true;
  65. }
  66. catch (Exception ex)
  67. {
  68. db.RollbackTran();
  69. WS.Log.RunLog.Error(ex);
  70. throw new UseArgumentException("服务器错误");
  71. }
  72. }
  73. }
  74. }