JyPlatformServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.DistrictUtil;
  6. import com.fdkankan.manage.common.PageInfo;
  7. import com.fdkankan.manage.common.ResultCode;
  8. import com.fdkankan.manage.entity.DistrictCode;
  9. import com.fdkankan.manage.entity.JyPlatform;
  10. import com.fdkankan.manage.entity.JyUser;
  11. import com.fdkankan.manage.entity.SysUser;
  12. import com.fdkankan.manage.exception.BusinessException;
  13. import com.fdkankan.manage.mapper.IJyPlatformMapper;
  14. import com.fdkankan.manage.service.*;
  15. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  16. import com.fdkankan.manage.vo.request.JyPlatformParam;
  17. import com.fdkankan.manage.vo.request.JyPlatformVo;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.UUID;
  25. import java.util.stream.Collectors;
  26. /**
  27. * <p>
  28. * 服务实现类
  29. * </p>
  30. *
  31. * @author
  32. * @since 2024-11-14
  33. */
  34. @Service
  35. public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlatform> implements IJyPlatformService {
  36. @Autowired
  37. IJyUserPlatformService jyUserPlatformService;
  38. @Autowired
  39. ISysUserService sysUserService;
  40. @Autowired
  41. IJyUserService jyUserService;
  42. @Autowired
  43. IDistrictCodeService districtCodeService;
  44. @Override
  45. public Object pageList(JyPlatformParam param) {
  46. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  47. if(StringUtils.isNotBlank(param.getPlatformName())){
  48. wrapper.like(JyPlatform::getPlatformName,param.getPlatformName());
  49. }
  50. if(StringUtils.isNotBlank(param.getName())){
  51. wrapper.like(JyPlatform::getName,param.getName());
  52. }
  53. if(StringUtils.isNotBlank(param.getPhone())){
  54. wrapper.like(JyPlatform::getPhone,param.getPhone());
  55. }
  56. if(param.getStatus() !=null){
  57. wrapper.eq(JyPlatform::getStatus,param.getStatus());
  58. }
  59. wrapper.orderByDesc(JyPlatform::getId);
  60. Page<JyPlatform> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  61. return PageInfo.PageInfo(page);
  62. }
  63. @Override
  64. public synchronized JyPlatform addOrUpdate(JyPlatformVo param) {
  65. if(StringUtils.isBlank(param.getPlatformName()) || StringUtils.isBlank(param.getName())
  66. || StringUtils.isBlank(param.getIdCard())){
  67. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  68. }
  69. JyPlatform jyPlatform = null;
  70. JyUser jyUser = null;
  71. if(param.getId() == null){ //创建平台自动生成平台访问地址
  72. String uuid = UUID.randomUUID().toString().substring(0, 18).replace("-", "");
  73. param.setPlatformAddress(uuid);
  74. jyPlatform = this.getByIdCard(param.getIdCard());
  75. if(jyPlatform != null){
  76. throw new BusinessException(ResultCode.ID_CARD_EXIT);
  77. }
  78. jyUser = jyUserService.getByIdCard(param.getIdCard());
  79. if(jyUser != null && jyUser.getPlatformId() != null ){
  80. throw new BusinessException(ResultCode.ID_CARD_EXIT2);
  81. }
  82. if(jyUser != null && jyUser.getStatus() !=1){
  83. throw new BusinessException(ResultCode.USER_BAN);
  84. }
  85. jyPlatform = new JyPlatform();
  86. BeanUtils.copyProperties(param,jyPlatform);
  87. this.save(jyPlatform);
  88. }else {
  89. jyPlatform = this.getById(param.getId());
  90. if(jyPlatform == null){
  91. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  92. }
  93. JyPlatform jyPlatform2 = this.getByIdCard(param.getIdCard());
  94. if(jyPlatform2 != null && !jyPlatform2.getId().equals(jyPlatform.getId())){
  95. throw new BusinessException(ResultCode.ID_CARD_EXIT);
  96. }
  97. jyUser = jyUserService.getByIdCard(param.getIdCard());
  98. if(jyUser != null && jyUser.getPlatformId() != null && !jyUser.getPlatformId().equals(param.getId())){
  99. throw new BusinessException(ResultCode.ID_CARD_EXIT2);
  100. }
  101. if(jyUser != null && jyUser.getStatus() !=1){
  102. throw new BusinessException(ResultCode.USER_BAN);
  103. }
  104. if(!param.getIdCard().equals(jyPlatform.getIdCard())){
  105. JyUser jyUser1 = jyUserService.getByIdCard(jyPlatform.getIdCard());
  106. if(jyUser1 != null && jyUser1.getStatus() !=1){
  107. throw new BusinessException(ResultCode.USER_BAN);
  108. }
  109. if(jyUser1 != null){
  110. sysUserService.updateRoleId(jyUser1.getSysUserId(),47L);
  111. }
  112. }
  113. param.setPlatformAddress(jyPlatform.getPlatformAddress());
  114. BeanUtils.copyProperties(param,jyPlatform);
  115. this.updateById(jyPlatform);
  116. }
  117. if (jyUser !=null){
  118. jyUserService.updatePlatformId(jyUser.getId(),jyPlatform.getId());
  119. sysUserService.updateRoleId(jyUser.getSysUserId(),48L);
  120. }
  121. return jyPlatform;
  122. }
  123. @Override
  124. public JyPlatform getByIdCard(String idCard) {
  125. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  126. wrapper.eq(JyPlatform::getIdCard,idCard);
  127. return this.getOne(wrapper);
  128. }
  129. @Override
  130. public void del(JyPlatform param) {
  131. if(param.getId() == null){
  132. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  133. }
  134. this.removeById(param.getId());
  135. }
  136. @Override
  137. public Object getByAddress(String address) {
  138. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  139. wrapper.eq(JyPlatform::getPlatformAddress,address);
  140. JyPlatform one = this.getOne(wrapper);
  141. return one;
  142. }
  143. @Override
  144. public void enable(JyPlatformVo param) {
  145. if(param.getId() == null){
  146. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  147. }
  148. JyPlatform jyPlatform = this.getById(param.getId());
  149. if(jyPlatform == null){
  150. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  151. }
  152. //update userRole
  153. JyUser jyUser = jyUserService.getByIdCard(jyPlatform.getIdCard());
  154. if(jyUser != null){
  155. sysUserService.updateRoleId(jyUser.getSysUserId(),48L);
  156. }
  157. this.updateStatus(jyPlatform.getId(),0);
  158. }
  159. private void updateStatus(Integer id, Integer status) {
  160. LambdaUpdateWrapper<JyPlatform> wrapper = new LambdaUpdateWrapper<>();
  161. wrapper.eq(JyPlatform::getId,id);
  162. wrapper.set(JyPlatform::getStatus,status);
  163. this.update(wrapper);
  164. }
  165. @Override
  166. public void disable(JyPlatformVo param) {
  167. if(param.getId() == null|| param.getToPlatformId() == null){
  168. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  169. }
  170. if(param.getId() == 1){
  171. throw new BusinessException(ResultCode.ADMIN_NOT_DISABLE);
  172. }
  173. JyPlatform jyPlatform = this.getById(param.getId());
  174. if(jyPlatform == null){
  175. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  176. }
  177. JyUser jyUser = jyUserService.getByIdCard(jyPlatform.getIdCard());
  178. //update userRole
  179. if(jyUser != null){
  180. sysUserService.updateRoleId(jyUser.getSysUserId(),47L);
  181. jyUserService.updatePlatformIdByPlatformId(param.getId(),param.getToPlatformId());
  182. }
  183. this.updateStatus(jyPlatform.getId(),1);
  184. }
  185. @Override
  186. public List<String> getIds() {
  187. LambdaQueryWrapper<JyPlatform > wrapper = new LambdaQueryWrapper<>();
  188. wrapper.eq(JyPlatform::getStatus,0);
  189. List<JyPlatform> list = this.list();
  190. if(list.isEmpty()){
  191. return new ArrayList<>();
  192. }
  193. return list.stream().map(JyPlatform::getIdCard).collect(Collectors.toList());
  194. }
  195. @Override
  196. public List<JyPlatform> getNotBanList() {
  197. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  198. wrapper.eq(JyPlatform::getStatus,0);
  199. return this.list(wrapper);
  200. }
  201. @Override
  202. public JyPlatform getByDistrictCode(String districtCode,String phone ,String idCard) {
  203. DistrictCode district = getPlatFormDistrictCode(districtCode);
  204. if(district != null){
  205. JyPlatform jyPlatform = getPlatformByCode(district.getCode());
  206. if(jyPlatform != null){
  207. return jyPlatform;
  208. }
  209. String platflormName = DistrictUtil.getPureCityName(district.getName()) +"公安";
  210. jyPlatform = this.getPlatformName(platflormName);
  211. if(jyPlatform!=null){
  212. LambdaUpdateWrapper<JyPlatform> wrapper = new LambdaUpdateWrapper<>();
  213. wrapper.eq(JyPlatform::getId,jyPlatform.getId());
  214. wrapper.set(JyPlatform::getDistrictCode,district.getCode());
  215. wrapper.set(JyPlatform::getDistrictName,district.getName());
  216. this.update(wrapper);
  217. return jyPlatform;
  218. }
  219. String uuid = UUID.randomUUID().toString().substring(0, 18).replace("-", "");
  220. jyPlatform = new JyPlatform();
  221. jyPlatform.setPlatformName(platflormName);
  222. jyPlatform.setPlatformAddress(uuid);
  223. jyPlatform.setName(platflormName);
  224. jyPlatform.setIdCard(idCard);
  225. jyPlatform.setDistrictCode(district.getCode());
  226. jyPlatform.setDistrictName(district.getName());
  227. jyPlatform.setIsNew(true);
  228. this.save(jyPlatform);
  229. return jyPlatform;
  230. }
  231. return null;
  232. }
  233. private JyPlatform getPlatformName(String platflormName) {
  234. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  235. wrapper.eq(JyPlatform::getPlatformName,platflormName);
  236. List<JyPlatform> list = this.list(wrapper);
  237. if(list == null || list.isEmpty()){
  238. return null;
  239. }
  240. return list.get(0);
  241. }
  242. private JyPlatform getPlatformByCode(String code){
  243. LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
  244. wrapper.eq(JyPlatform::getDistrictCode,code);
  245. List<JyPlatform> list = this.list(wrapper);
  246. if(list == null || list.isEmpty()){
  247. return null;
  248. }
  249. return list.get(0);
  250. }
  251. private DistrictCode getPlatFormDistrictCode(String districtCode){
  252. DistrictCode byCode = districtCodeService.getByCode(districtCode);
  253. if(byCode == null || StringUtils.isBlank(byCode.getParentCode())){
  254. return null;
  255. }
  256. if(DistrictUtil.isCityLevel(districtCode)){
  257. return byCode;
  258. }
  259. return getPlatFormDistrictCode(byCode.getParentCode());
  260. }
  261. }