BE_ERPLoginCheck.groovy 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import com.sdtool.common.api.BusinessExecutor
  2. import com.sdtool.common.api.LoginUserService
  3. import com.sdtool.common.api.mall.MallAdminService
  4. import com.sdtool.common.datas.ERPModule
  5. import com.sdtool.common.entity.base.BaseEntity
  6. import com.sdtool.common.entity.base.ProcessEntityItem
  7. import com.sdtool.common.entity.mall.MallUser
  8. import com.sdtool.common.entity.site.ERPTokenUser
  9. import com.sdtool.common.entity.site.LoginResult
  10. import com.sdtool.common.entity.system.LoginUser
  11. import com.sdtool.common.entity.system.SocialUser
  12. import com.sweetfish.service.RetResult
  13. import org.apache.logging.log4j.LogManager
  14. import org.apache.logging.log4j.Logger
  15. import javax.annotation.Resource
  16. /**
  17. * ERP系统登录用户检查
  18. * 主要用于servlet中的身份验证,检查用户是否禁用了,过期了之类的
  19. */
  20. @SuppressWarnings("unused")
  21. class BE_ERPLoginCheck implements BusinessExecutor<ProcessEntityItem<BaseEntity>, BaseEntity> {
  22. protected final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  23. @Resource
  24. LoginUserService userService
  25. @Resource
  26. MallAdminService mallAdminService
  27. //登录策略,当前数据库那一个地方需要重启服务,可改成不需要的,参考TunaDaoService动态sql执行
  28. def loginStrategies = [
  29. "0" : [
  30. "name" : "后台管理系统用户检查",
  31. "check": { ERPTokenUser currentUser ->
  32. if (currentUser.account.equalsIgnoreCase("SuperResourcer")) {
  33. return true
  34. } else {
  35. LoginUser info = userService.getRedisLoginUser(currentUser.id, currentUser.supplierCode)
  36. if ((info == null) || (info.getStatus() == 1)) {
  37. return false
  38. }
  39. return true
  40. }
  41. }
  42. ],
  43. "10": [
  44. "name" : "PC端商城管理用户检查",
  45. "check": { ERPTokenUser currentUser ->
  46. if (currentUser.account.equalsIgnoreCase("SuperResourcer")) {
  47. return true
  48. } else {
  49. LoginUser info = userService.getRedisLoginUser(currentUser.id, currentUser.supplierCode)
  50. if ((info == null) || (info.getStatus() == 1)) {
  51. return false
  52. }
  53. return true
  54. }
  55. }
  56. ],
  57. "11": [
  58. "name" : "PC端商城购物网站登录",
  59. "check": { ERPTokenUser currentUser ->
  60. MallUser info = mallAdminService.getRedisMallUser(currentUser.id, currentUser.supplierCode)
  61. if ((info == null) || (info.voidFlag == 1)) {
  62. return false
  63. }
  64. return true
  65. }
  66. ],
  67. "20": [
  68. "name" : "PC端产品中心登录",
  69. "check": { ERPTokenUser currentUser ->
  70. if (currentUser.account.equalsIgnoreCase("SuperResourcer")) {
  71. return true
  72. } else {
  73. LoginUser info = userService.getRedisLoginUser(currentUser.id, currentUser.supplierCode)
  74. if ((info == null) || (info.getStatus() == 1)) {
  75. return false
  76. }
  77. return true
  78. }
  79. }
  80. ],
  81. "50": [
  82. "name" : "商城小程序",
  83. "check": { ERPTokenUser currentUser ->
  84. SocialUser info = mallMiniService.getRedisMallSocialUser(currentUser.userOpenId, currentUser.supplierCode)
  85. if ((info == null) || (info.getVoidFlag() == 1)) {
  86. return false
  87. }
  88. return true
  89. }
  90. ],
  91. "60": [
  92. "name" : "ERP手机APP登录(用于生产反馈)",
  93. "check": { ERPTokenUser currentUser ->
  94. LoginUser info = userService.getRedisLoginUser(currentUser.id, currentUser.supplierCode)
  95. if ((info == null) || (info.getStatus() == 1)) {
  96. return false
  97. }
  98. return true
  99. }
  100. ]
  101. ]
  102. @Override
  103. String scriptName() {
  104. return "ERP系统登录用户检查"
  105. }
  106. @Override
  107. ERPModule module() {
  108. return ERPModule.LOGIN
  109. }
  110. @Override
  111. RetResult<BaseEntity> execute(ProcessEntityItem<BaseEntity> source) {
  112. ERPTokenUser currentUser = source.currentUser
  113. if (currentUser.supplierCode <= 0L) {
  114. return RetResult.<LoginResult> errorT().retinfo("用户信息不正确")
  115. }
  116. if (!loginStrategies.containsKey(String.valueOf(currentUser.userFrom))) {
  117. return RetResult.<LoginResult> errorT().retinfo("无效的登录来源")
  118. }
  119. def loginStrategy = loginStrategies.get(String.valueOf(currentUser.userFrom))
  120. def checkResult = loginStrategy.check.call(currentUser)
  121. if (checkResult) {
  122. return RetResult.<BaseEntity> successT()
  123. } else {
  124. return RetResult.<LoginResult> errorT().retinfo("未登录")
  125. }
  126. }
  127. }