BE_MallUserLevel_Edit.groovy 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import com.sdtool.business.dao.MallDao
  2. import com.sdtool.common.api.BusinessExecutor
  3. import com.sdtool.common.api.NoSqlKeysService
  4. import com.sdtool.common.api.mall.MallAdminService
  5. import com.sdtool.common.datas.ERPModule
  6. import com.sdtool.common.datas.RedisKeys
  7. import com.sdtool.common.entity.base.InvokeCallParams
  8. import com.sdtool.common.entity.base.InvokeCallResult
  9. import com.sdtool.common.entity.mall.MallUserLevel
  10. import com.dySweetFishPlugin.redis.RedisService
  11. import com.dySweetFishPlugin.sql.TableIdService
  12. import com.dySweetFishPlugin.sql.dao.OperatorWait
  13. import com.dySweetFishPlugin.sql.dao.TunaService
  14. import com.sweetfish.convert.json.JsonConvert
  15. import com.sweetfish.service.RetResult
  16. import org.apache.commons.lang3.StringUtils
  17. import javax.annotation.Resource
  18. /**
  19. * @Author: xl Created on 2024-05-11
  20. * @Content:
  21. */
  22. class BE_MallUserLevel_Edit implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
  23. @Resource
  24. TunaService tunaService
  25. @Resource
  26. JsonConvert jsonConvert
  27. @Resource
  28. TableIdService tableIdService
  29. @Resource
  30. RedisService redisService
  31. @Resource
  32. NoSqlKeysService keysService
  33. @Resource
  34. MallAdminService mallAdminService
  35. private MallDao mallDao
  36. @Override
  37. String scriptName() {
  38. return "用户级别-修改"
  39. }
  40. @Override
  41. ERPModule module() {
  42. return ERPModule.MALL_ADMIN
  43. }
  44. @Override
  45. OperatorWait getAWait(InvokeCallParams s) {
  46. return OperatorWait.ASNYC
  47. }
  48. @Override
  49. boolean needLogin(InvokeCallParams source) {
  50. return true
  51. }
  52. @Override
  53. void start(long supplierCode) {
  54. mallDao = tunaService.generate(MallDao.class)
  55. }
  56. @Override
  57. RetResult<InvokeCallParams> checkExecute(InvokeCallParams source) {
  58. MallUserLevel srcLevel = jsonConvert.convertFrom(MallUserLevel.class, source.params)
  59. if (StringUtils.isBlank(srcLevel.levelName)) {
  60. return RetResult.<InvokeCallParams>errorT().retinfo("级别名称不能为空")
  61. }
  62. MallUserLevel redisLevel = mallAdminService.getRedisMallUserLevel(srcLevel.id,source.supplierCode)
  63. if (redisLevel == null) {
  64. return RetResult.<InvokeCallParams>errorT().retinfo("未找到此级别")
  65. }
  66. return RetResult.<InvokeCallParams>successT().result(source)
  67. }
  68. RetResult<InvokeCallResult> execute(InvokeCallParams source) {
  69. MallUserLevel userLevel = jsonConvert.convertFrom(MallUserLevel.class, source.params)
  70. if (userLevel.levelValue == null || userLevel.levelValue <= 0) {
  71. userLevel.levelValue = BigDecimal.ONE
  72. }
  73. // 如果级别不多,就没必要判断重名了
  74. MallUserLevel redisLevel = mallAdminService.getRedisMallUserLevel(userLevel.id,source.supplierCode)
  75. redisLevel.levelName = userLevel.levelName
  76. redisLevel.levelValue = userLevel.levelValue
  77. redisLevel.checkFileFlag = userLevel.checkFileFlag
  78. redisLevel.viewPriceDetailFlag = userLevel.viewPriceDetailFlag
  79. redisLevel.expireDays = userLevel.expireDays
  80. redisLevel.idDowngradeLevel = userLevel.idDowngradeLevel
  81. MallUserLevel.update(redisLevel,source.currentUser.id)
  82. int iData = mallDao.updateMallUserLevel(redisLevel,source.dataSourceId,source.supplierCode)
  83. if (iData > 0) {
  84. redisService.hset(keysService.getRedisKey(RedisKeys.KEY_ERP_MALL_USER_LEVEL,source.supplierCode), String.valueOf(redisLevel.id),jsonConvert.convertTo(redisLevel))
  85. return RetResult.<InvokeCallResult>successT()
  86. }
  87. return RetResult.<InvokeCallResult>errorT().retinfo(" 修改用户级别失败")
  88. }
  89. }