JyPlatformServiceImpl.java 6.8 KB

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