AuthServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.caimei.service.impl;
  2. import com.caimei.mapper.AuthMapper;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.po.CmBrandAuthPo;
  5. import com.caimei.model.vo.AuthVo;
  6. import com.caimei.service.AuthProductService;
  7. import com.caimei.service.AuthService;
  8. import com.github.pagehelper.PageHelper;
  9. import com.github.pagehelper.PageInfo;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.util.Date;
  16. import java.util.List;
  17. import java.util.ListIterator;
  18. /**
  19. * Description
  20. *
  21. * @author : Aslee
  22. * @date : 2021/5/11
  23. */
  24. @Slf4j
  25. @Service
  26. public class AuthServiceImpl implements AuthService {
  27. @Resource
  28. private AuthMapper authMapper;
  29. private AuthProductService authProductService;
  30. @Autowired
  31. public void setAuthProductService(AuthProductService authProductService) {
  32. this.authProductService = authProductService;
  33. }
  34. @Override
  35. public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty, Integer status, Integer auditStatus, Integer lowerAuditStatus, Integer pageNum, Integer pageSize) {
  36. if (null == authUserId) {
  37. return ResponseJson.error("参数异常,请输入供应商用户id", null);
  38. }
  39. listType = null == listType ? 1 : listType;
  40. PageHelper.startPage(pageNum, pageSize);
  41. List<AuthVo> authList = authMapper.getAuthList(listType, authUserId, authParty, status, auditStatus);
  42. ListIterator<AuthVo> iterator = authList.listIterator();
  43. while (iterator.hasNext()) {
  44. AuthVo auth = iterator.next();
  45. Integer waitAuditNum = auth.getWaitAuditNum();
  46. if (waitAuditNum > 0) {
  47. auth.setLowerAuditStatus(0);
  48. if (null != lowerAuditStatus && 1 == lowerAuditStatus) {
  49. iterator.remove();
  50. }
  51. } else {
  52. auth.setLowerAuditStatus(1);
  53. if (null != lowerAuditStatus && 0 == lowerAuditStatus) {
  54. iterator.remove();
  55. }
  56. }
  57. }
  58. PageInfo<AuthVo> pageData = new PageInfo<>(authList);
  59. return ResponseJson.success(pageData);
  60. }
  61. @Override
  62. public ResponseJson updateAuthStatus(Integer authId, Integer status) {
  63. if (authId == null) {
  64. return ResponseJson.error("请输入授权id");
  65. }
  66. if (status == null) {
  67. return ResponseJson.error("请输入要更新的状态值");
  68. }
  69. authMapper.updateAuthStatusByAuthId(authId, status);
  70. if (status == 0) {
  71. return ResponseJson.success("下线品牌授权成功");
  72. } else {
  73. return ResponseJson.success("上线品牌授权成功");
  74. }
  75. }
  76. @Override
  77. public ResponseJson deleteAuth(Integer authId) {
  78. if (null == authId) {
  79. return ResponseJson.error("参数异常,请输入授权id");
  80. }
  81. // 删除品牌授权
  82. authMapper.deleteAuthByAuthId(authId);
  83. // 删除商品及商品参数
  84. List<Integer> productIdList = authProductService.getProductIdsByAuthId(authId);
  85. productIdList.forEach(productId->{
  86. if (null != productId) {
  87. authProductService.deleteProduct(productId);
  88. }
  89. });
  90. return ResponseJson.success("删除品牌授权成功");
  91. }
  92. @Override
  93. public ResponseJson saveAuth(Integer authId, Integer authUserId, String authParty, Integer createBy) {
  94. if (null == authUserId) {
  95. return ResponseJson.error("参数异常,请输入供应商用户id");
  96. }
  97. if (StringUtils.isBlank(authParty)) {
  98. return ResponseJson.error("参数异常,请输入授权机构名称");
  99. }
  100. if (null == createBy) {
  101. return ResponseJson.error("参数异常,请输入创建人id");
  102. }
  103. /*
  104. 组装授权数据
  105. */
  106. CmBrandAuthPo auth = new CmBrandAuthPo();
  107. auth.setAuthUserId(authUserId);
  108. auth.setAuthParty(authParty);
  109. // 保存品牌授权信息,上线状态默认为“待上线”,审核状态为“待审核”
  110. auth.setStatus(2);
  111. auth.setAuditStatus(2);
  112. if (null == authId) {
  113. auth.setCreateBy(createBy);
  114. auth.setCreateTime(new Date());
  115. } else {
  116. auth.setId(authId);
  117. }
  118. /*
  119. 保存授权
  120. */
  121. if (null == authId) {
  122. authMapper.insertAuth(auth);
  123. } else {
  124. authMapper.updateAuthByAuthId(auth);
  125. }
  126. return ResponseJson.success("保存品牌授权成功");
  127. }
  128. @Override
  129. public ResponseJson auditAuth(Integer authId, Integer auditStatus, String invalidReason, Integer auditBy) {
  130. if (authId == null) {
  131. return ResponseJson.error("请输入授权id");
  132. }
  133. if (auditStatus == null) {
  134. return ResponseJson.error("请输入审核结果");
  135. }
  136. if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) {
  137. return ResponseJson.error("请输入审核不通过的理由");
  138. }
  139. if (auditBy == null) {
  140. return ResponseJson.error("请输入审核人用户id");
  141. }
  142. Date auditTime = new Date();
  143. // 授权状态更新
  144. Integer status = null;
  145. if (auditStatus == 0) {
  146. // 审核不通过,下线授权
  147. status = 0;
  148. } else {
  149. // 审核通过,上线授权
  150. status = 1;
  151. }
  152. authMapper.updateAuthAuditStatus(authId, status, auditStatus, invalidReason, auditBy, auditTime);
  153. return ResponseJson.success("审核品牌授权成功");
  154. }
  155. }