123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package com.fdkankan.manage.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage.common.ExcelErrorUtil;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.entity.JyPlatform;
- import com.fdkankan.manage.entity.JyPlatformUserWait;
- import com.fdkankan.manage.entity.JyUser;
- import com.fdkankan.manage.entity.SysUser;
- import com.fdkankan.manage.service.*;
- import com.fdkankan.manage.vo.JyUserPlatform;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.mapper.IJyUserPlatformMapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage.vo.request.*;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Objects;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-11-15
- */
- @Service
- @Slf4j
- public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper, JyUserPlatform> implements IJyUserPlatformService {
- @Autowired
- IJyPlatformService platformService;
- @Autowired
- IJyUserService jyUserService;
- @Autowired
- ISysUserService sysUserService;
- @Override
- public void bindPlatform(Integer id, Integer platformId) {
- jyUserService.updatePlatformId(id,platformId);
- }
- @Override
- public void addByParam(JyUserPlatformAddParam param) {
- if(param.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Integer loginPlatformId = this.getLoginPlatformId();
- if(loginPlatformId == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- param.setPlatformId(loginPlatformId);
- JyUser jyUser = jyUserService.getById(param.getId());
- SysUser byId = sysUserService.getById(jyUser.getSysUserId());
- if(byId.getRoleId() != 47L ){
- throw new BusinessException(ResultCode.PLATFORM_USER_ADDERROR);
- }
- this.bindPlatform(param.getId(),loginPlatformId);
- }
- @Override
- public void updateByParam(JyUserPlatformAddParam param) {
- if(param.getId() == null || param.getPlatformId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- JyUser jyUser = jyUserService.getById(param.getId());
- SysUser byId = sysUserService.getById(jyUser.getSysUserId());
- if(byId.getRoleId() != 47L ){
- throw new BusinessException(ResultCode.PLATFORM_USER_ADDERROR);
- }
- this.bindPlatform(param.getId(),param.getPlatformId());
- }
- @Override
- public void del(JyUserPlatformAddParam param) {
- if(param.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaQueryWrapper<JyUserPlatform> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(JyUserPlatform::getId,param.getId());
- this.removeById(wrapper);
- }
- @Override
- public Object pageList(JyUserPlatformParam param) {
- SysUser byId = sysUserService.getById(Long.valueOf(StpUtil.getLoginId().toString()));
- if(byId.getRoleId() != 1L ){
- Integer loginPlatformId = getLoginPlatformId();
- if(loginPlatformId == null){
- return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
- }
- param.setPlatformId(getLoginPlatformId());
- }
- Page<JyUserPlatformVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<Integer> ids = page.getRecords().stream().map(JyUserPlatform::getPlatformId).collect(Collectors.toList());
- HashMap<Integer,JyPlatform> map = new HashMap<>();
- if(!ids.isEmpty()){
- List<JyPlatform> jyPlatforms = platformService.listByIds(ids);
- jyPlatforms.forEach(e -> map.put(e.getId(),e));
- }
- for (JyUserPlatformVo record : page.getRecords()) {
- if(record.getRyId() == null){
- record.setCreateTime(null);
- }
- JyPlatform jyPlatform = map.get(record.getPlatformId());
- if(jyPlatform != null){
- record.setPlatformName(jyPlatform.getPlatformName());
- }
- }
- return PageInfo.PageInfo(page);
- }
- @Override
- public Object queryByKey(JyUserPlatformParam param) {
- if(StringUtils.isBlank(param.getQueryKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- List<JyUserPlatform> jyUserPlatforms = this.getBaseMapper().queryByKey(param.getQueryKey());
- List<Integer> collect = jyUserPlatforms.stream().map(JyUserPlatform::getPlatformId).filter(Objects::nonNull).collect(Collectors.toList());
- HashMap<Integer,JyPlatform> map = new HashMap<>();
- if(!collect.isEmpty()){
- List<JyPlatform> jyPlatforms = platformService.listByIds(collect);
- jyPlatforms.forEach(e -> map.put(e.getId(),e));
- }
- for (JyUserPlatform jyUserPlatform : jyUserPlatforms) {
- if(jyUserPlatform.getPlatformId()!=null){
- JyPlatform jyPlatform =map.get(jyUserPlatform.getPlatformId());
- if(jyPlatform != null){
- jyUserPlatform.setPlatformName(jyPlatform.getPlatformName());
- }
- }
- }
- return jyUserPlatforms;
- }
- @Override
- public Integer getLoginPlatformId(){
- try {
- return Integer.valueOf(StpUtil.getExtra("platformId").toString());
- }catch (Exception e){
- log.info("StpUtil.getExtra -- platformId-error:{}",e);
- }
- return null;
- }
- @Autowired
- IExcelService excelService;
- @Override
- public Integer addPlatformUser(List<HashMap<Integer, String>> excelRowList) {
- List<JyUserPlatformAddParam> params = new ArrayList<>();
- List<Integer> errorIndex = new ArrayList<>();
- List<Integer> updatePlatformUserList = new ArrayList<>();
- Integer index = 0;
- for (HashMap<Integer, String> map : excelRowList) {
- index++;
- if (map.isEmpty()) {
- continue;
- }
- if (index == 0 && !map.get(0).equals("平台用户模板")) {
- throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
- }
- if (index < 4) {
- continue;
- }
- String name = map.get(0);
- if(StringUtils.isBlank(name) ){
- errorIndex.add(index -3 );
- continue;
- }
- JyUser user = jyUserService.getByNickName(name);
- if(user != null && user.getPlatformId() == null){
- updatePlatformUserList.add(user.getId());
- continue;
- }
- if(user != null ){
- errorIndex.add(index -3 );
- continue;
- }
- JyPlatformUserWait jyPlatformUserWait = platformUserWaitService.getByName(name);
- if(jyPlatformUserWait != null ){
- errorIndex.add(index -3 );
- continue;
- }
- List<JyUserPlatformAddParam> collect = params.stream().filter(e -> e.getName().equals(name)).collect(Collectors.toList());
- if(!collect.isEmpty()){
- errorIndex.add(index -3 );
- continue;
- }
- JyUserPlatformAddParam param = new JyUserPlatformAddParam();
- param.setName(name);
- params.add(param);
- }
- if(!errorIndex.isEmpty()){
- excelService.toExcelError(errorIndex);
- }
- if(params.size() <=0 && updatePlatformUserList.isEmpty()){
- throw new BusinessException(ResultCode.TEMPLATE_EMPTY);
- }
- Integer count = this.addPlatformUsers(params);
- Integer count1 = 0;
- for (Integer jyUserId : updatePlatformUserList) {
- if(getLoginPlatformId() != null){
- jyUserService.updatePlatformId(jyUserId,getLoginPlatformId());
- count1 ++;
- }
- }
- return count1 + count;
- }
- @Autowired
- IJyPlatformUserWaitService platformUserWaitService;
- private Integer addPlatformUsers(List<JyUserPlatformAddParam> params) {
- Integer count = 0;
- for (JyUserPlatformAddParam param : params) {
- JyPlatformUserWait jyPlatformUserWait = new JyPlatformUserWait();
- jyPlatformUserWait.setName(param.getName());
- jyPlatformUserWait.setPlatformId(this.getLoginPlatformId());
- platformUserWaitService.save(jyPlatformUserWait);
- count ++;
- }
- return count;
- }
- }
|