123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package com.fdkankan.manage.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.entity.JyPlatform;
- import com.fdkankan.manage.entity.JyUser;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.mapper.IJyPlatformMapper;
- import com.fdkankan.manage.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage.vo.request.JyPlatformParam;
- import com.fdkankan.manage.vo.request.JyPlatformVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-11-14
- */
- @Service
- public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlatform> implements IJyPlatformService {
- @Autowired
- IJyUserPlatformService jyUserPlatformService;
- @Autowired
- ISysUserService sysUserService;
- @Autowired
- IJyUserService jyUserService;
- @Override
- public Object pageList(JyPlatformParam param) {
- LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getPlatformName())){
- wrapper.like(JyPlatform::getPlatformName,param.getPlatformName());
- }
- if(StringUtils.isNotBlank(param.getName())){
- wrapper.like(JyPlatform::getName,param.getName());
- }
- if(StringUtils.isNotBlank(param.getPhone())){
- wrapper.like(JyPlatform::getPhone,param.getPhone());
- }
- wrapper.orderByDesc(JyPlatform::getId);
- Page<JyPlatform> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- return PageInfo.PageInfo(page);
- }
- @Override
- public JyPlatform addOrUpdate(JyPlatformVo param) {
- if(StringUtils.isBlank(param.getPlatformName()) || StringUtils.isBlank(param.getName())
- || StringUtils.isBlank(param.getIdCard())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyPlatform jyPlatform = null;
- JyUser jyUser = null;
- if(param.getId() == null){ //创建平台自动生成平台访问地址
- String uuid = UUID.randomUUID().toString().substring(0, 18).replace("-", "");
- param.setPlatformAddress(uuid);
- jyPlatform = this.getByIdCard(param.getIdCard());
- if(jyPlatform != null){
- throw new BusinessException(ResultCode.ID_CARD_EXIT);
- }
- jyPlatform = new JyPlatform();
- jyUser = jyUserService.getByIdCard(param.getIdCard());
- if(jyUser != null && (jyUser.getPlatformId() != null || jyUser.getIsJm() == 0)){
- throw new BusinessException(ResultCode.ID_CARD_EXIT);
- }
- }else {
- jyPlatform = this.getById(param.getId());
- if(jyPlatform == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- param.setPlatformAddress(jyPlatform.getPlatformAddress());
- JyPlatform jyPlatform2 = this.getByIdCard(param.getIdCard());
- if(jyPlatform2 != null && !jyPlatform2.getId().equals(jyPlatform.getId())){
- throw new BusinessException(ResultCode.ID_CARD_EXIT);
- }
- }
- BeanUtils.copyProperties(param,jyPlatform);
- this.saveOrUpdate(jyPlatform);
- if (jyUser !=null){
- jyUserService.updatePlatformId(jyUser.getId(),jyPlatform.getId());
- }
- return jyPlatform;
- }
- @Override
- public JyPlatform getByIdCard(String idCard) {
- LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(JyPlatform::getIdCard,idCard);
- return this.getOne(wrapper);
- }
- @Override
- public void del(JyPlatform param) {
- if(param.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- this.removeById(param.getId());
- }
- @Override
- public Object getByAddress(String address) {
- LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(JyPlatform::getPlatformAddress,address);
- JyPlatform one = this.getOne(wrapper);
- return one;
- }
- @Override
- public void enable(JyPlatformVo param) {
- if(param.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyPlatform jyPlatform = this.getById(param.getId());
- if(jyPlatform == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- //update userRole
- JyUser jyUser = jyUserService.getById(param.getJyUserId());
- if(jyUser != null){
- sysUserService.updateRoleId(jyUser.getSysUserId(),48);
- }
- this.updateStatus(jyPlatform.getId(),0);
- }
- private void updateStatus(Integer id, Integer status) {
- LambdaUpdateWrapper<JyPlatform> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(JyPlatform::getId,id);
- wrapper.set(JyPlatform::getStatus,status);
- this.update(wrapper);
- }
- @Override
- public void disable(JyPlatformVo param) {
- if(param.getId() == null|| param.getToPlatformId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getId() == 1){
- throw new BusinessException(ResultCode.ADMIN_NOT_DISABLE);
- }
- JyPlatform jyPlatform = this.getById(param.getId());
- if(jyPlatform == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- //update userRole
- JyUser jyUser = jyUserService.getById(param.getJyUserId());
- if(jyUser != null){
- sysUserService.updateRoleId(jyUser.getSysUserId(),47);
- }
- jyUserService.updatePlatformId(param.getId(),param.getToPlatformId());
- this.updateStatus(jyPlatform.getId(),1);
- }
- @Override
- public List<String> getIds() {
- LambdaQueryWrapper<JyPlatform > wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(JyPlatform::getStatus,0);
- List<JyPlatform> list = this.list();
- if(list.isEmpty()){
- return new ArrayList<>();
- }
- return list.stream().map(JyPlatform::getIdCard).collect(Collectors.toList());
- }
- }
|