JyPlatformServiceImpl.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package com.fdkankan.manage.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.manage.common.PageInfo;
  6. import com.fdkankan.manage.common.ResultCode;
  7. import com.fdkankan.manage.entity.JyPlatform;
  8. import com.fdkankan.manage.entity.JyUser;
  9. import com.fdkankan.manage.entity.SysUser;
  10. import com.fdkankan.manage.exception.BusinessException;
  11. import com.fdkankan.manage.mapper.IJyPlatformMapper;
  12. import com.fdkankan.manage.service.*;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.fdkankan.manage.vo.request.JyPlatformParam;
  15. import com.fdkankan.manage.vo.request.JyPlatformVo;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.BeanUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.UUID;
  23. import java.util.stream.Collectors;
  24. /**
  25. * <p>
  26. * 服务实现类
  27. * </p>
  28. *
  29. * @author
  30. * @since 2024-11-14
  31. */
  32. @Service
  33. public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlatform> implements IJyPlatformService {
  34. @Autowired
  35. IJyUserPlatformService jyUserPlatformService;
  36. @Autowired
  37. ISysUserService sysUserService;
  38. @Autowired
  39. IJyUserService jyUserService;
  40. @Override
  41. public Object pageList(JyPlatformParam param) {
  42. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  43. if(StringUtils.isNotBlank(param.getPlatformName())){
  44. wrapper.like(JyPlatform::getPlatformName,param.getPlatformName());
  45. }
  46. if(StringUtils.isNotBlank(param.getName())){
  47. wrapper.like(JyPlatform::getName,param.getName());
  48. }
  49. if(StringUtils.isNotBlank(param.getPhone())){
  50. wrapper.like(JyPlatform::getPhone,param.getPhone());
  51. }
  52. wrapper.orderByDesc(JyPlatform::getId);
  53. Page<JyPlatform> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  54. return PageInfo.PageInfo(page);
  55. }
  56. @Override
  57. public JyPlatform addOrUpdate(JyPlatformVo param) {
  58. if(StringUtils.isBlank(param.getPlatformName()) || StringUtils.isBlank(param.getName())
  59. || StringUtils.isBlank(param.getIdCard())){
  60. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  61. }
  62. JyPlatform jyPlatform = null;
  63. JyUser jyUser = null;
  64. if(param.getId() == null){ //创建平台自动生成平台访问地址
  65. String uuid = UUID.randomUUID().toString().substring(0, 18).replace("-", "");
  66. param.setPlatformAddress(uuid);
  67. jyPlatform = this.getByIdCard(param.getIdCard());
  68. if(jyPlatform != null){
  69. throw new BusinessException(ResultCode.ID_CARD_EXIT);
  70. }
  71. jyUser = jyUserService.getByIdCard(param.getIdCard());
  72. if(jyUser != null && jyUser.getPlatformId() != null ){
  73. throw new BusinessException(ResultCode.ID_CARD_EXIT2);
  74. }
  75. if(jyUser != null && jyUser.getStatus() !=1){
  76. throw new BusinessException(ResultCode.USER_BAN);
  77. }
  78. jyPlatform = new JyPlatform();
  79. BeanUtils.copyProperties(param,jyPlatform);
  80. this.save(jyPlatform);
  81. }else {
  82. jyPlatform = this.getById(param.getId());
  83. if(jyPlatform == null){
  84. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  85. }
  86. JyPlatform jyPlatform2 = this.getByIdCard(param.getIdCard());
  87. if(jyPlatform2 != null && !jyPlatform2.getId().equals(jyPlatform.getId())){
  88. throw new BusinessException(ResultCode.ID_CARD_EXIT);
  89. }
  90. jyUser = jyUserService.getByIdCard(param.getIdCard());
  91. if(jyUser != null && jyUser.getPlatformId() != null && !jyUser.getPlatformId().equals(param.getId())){
  92. throw new BusinessException(ResultCode.ID_CARD_EXIT2);
  93. }
  94. if(!param.getIdCard().equals(jyPlatform.getIdCard())){
  95. JyUser jyUser1 = jyUserService.getByIdCard(jyPlatform.getIdCard());
  96. if(jyUser1 != null){
  97. sysUserService.updateRoleId(jyUser1.getSysUserId(),47L);
  98. }
  99. }
  100. param.setPlatformAddress(jyPlatform.getPlatformAddress());
  101. BeanUtils.copyProperties(param,jyPlatform);
  102. this.updateById(jyPlatform);
  103. }
  104. if (jyUser !=null){
  105. jyUserService.updatePlatformId(jyUser.getId(),jyPlatform.getId());
  106. sysUserService.updateRoleId(jyUser.getSysUserId(),48L);
  107. }
  108. return jyPlatform;
  109. }
  110. @Override
  111. public JyPlatform getByIdCard(String idCard) {
  112. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  113. wrapper.eq(JyPlatform::getIdCard,idCard);
  114. return this.getOne(wrapper);
  115. }
  116. @Override
  117. public void del(JyPlatform param) {
  118. if(param.getId() == null){
  119. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  120. }
  121. this.removeById(param.getId());
  122. }
  123. @Override
  124. public Object getByAddress(String address) {
  125. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  126. wrapper.eq(JyPlatform::getPlatformAddress,address);
  127. JyPlatform one = this.getOne(wrapper);
  128. return one;
  129. }
  130. @Override
  131. public void enable(JyPlatformVo param) {
  132. if(param.getId() == null){
  133. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  134. }
  135. JyPlatform jyPlatform = this.getById(param.getId());
  136. if(jyPlatform == null){
  137. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  138. }
  139. //update userRole
  140. JyUser jyUser = jyUserService.getByIdCard(jyPlatform.getIdCard());
  141. if(jyUser != null){
  142. sysUserService.updateRoleId(jyUser.getSysUserId(),48L);
  143. }
  144. this.updateStatus(jyPlatform.getId(),0);
  145. }
  146. private void updateStatus(Integer id, Integer status) {
  147. LambdaUpdateWrapper<JyPlatform> wrapper = new LambdaUpdateWrapper<>();
  148. wrapper.eq(JyPlatform::getId,id);
  149. wrapper.set(JyPlatform::getStatus,status);
  150. this.update(wrapper);
  151. }
  152. @Override
  153. public void disable(JyPlatformVo param) {
  154. if(param.getId() == null|| param.getToPlatformId() == null){
  155. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  156. }
  157. if(param.getId() == 1){
  158. throw new BusinessException(ResultCode.ADMIN_NOT_DISABLE);
  159. }
  160. JyPlatform jyPlatform = this.getById(param.getId());
  161. if(jyPlatform == null){
  162. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  163. }
  164. JyUser jyUser = jyUserService.getByIdCard(jyPlatform.getIdCard());
  165. //update userRole
  166. if(jyUser != null){
  167. sysUserService.updateRoleId(jyUser.getSysUserId(),47L);
  168. }
  169. jyUserService.updatePlatformId(param.getId(),param.getToPlatformId());
  170. this.updateStatus(jyPlatform.getId(),1);
  171. }
  172. @Override
  173. public List<String> getIds() {
  174. LambdaQueryWrapper<JyPlatform > wrapper = new LambdaQueryWrapper<>();
  175. wrapper.eq(JyPlatform::getStatus,0);
  176. List<JyPlatform> list = this.list();
  177. if(list.isEmpty()){
  178. return new ArrayList<>();
  179. }
  180. return list.stream().map(JyPlatform::getIdCard).collect(Collectors.toList());
  181. }
  182. @Override
  183. public List<JyPlatform> getNotBanList() {
  184. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  185. wrapper.eq(JyPlatform::getStatus,0);
  186. return this.list(wrapper);
  187. }
  188. }