jiangping
2024-12-27 5506edbe54883b31db3cc8e4a1d9d0795a18a3c9
server/service/src/main/java/com/doumee/service/business/impl/CompanyUserApplyServiceImpl.java
@@ -1,20 +1,35 @@
package com.doumee.service.business.impl;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CompanyUserApplyMapper;
import com.doumee.dao.business.model.CompanyUserApply;
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.CompanyUserApplyJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CompanyUserApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.*;
/**
 * 集团申请记录表Service实现
@@ -26,16 +41,119 @@
    @Autowired
    private CompanyUserApplyMapper companyUserApplyMapper;
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private MultifileMapper multifileMapper;
    @Autowired
    private CompanyUserApplyJoinMapper companyUserApplyJoinMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private CompanyPermissionMapper companyPermissionMapper;
    @Autowired
    private NoticesMapper noticesMapper;
    @Override
    public Integer create(CompanyUserApply companyUserApply) {
        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(companyUserApply)
            || Objects.isNull(companyUserApply.getUserId())
            || CollectionUtils.isEmpty(companyUserApply.getMultifileList())
            || StringUtils.isBlank(companyUserApply.getCompanyIds())
            || StringUtils.isBlank(companyUserApply.getCompanyNames())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(!Constants.equalsInteger(loginUserInfo.getType(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"登录用户不允许当前操作");
        }
        //查询当前用户是否存在申请中
        if(companyUserApplyMapper.selectCount(new QueryWrapper<CompanyUserApply>().lambda()
                .eq(CompanyUserApply::getUserId,companyUserApply.getUserId())
                .eq(CompanyUserApply::getIsdeleted, Constants.ZERO)
                .eq(CompanyUserApply::getStatus,Constants.ZERO))>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户存在待审批数据,无法进行申请");
        };
        SystemUser applyUser = systemUserMapper.selectById(companyUserApply.getUserId());
        if(Objects.isNull(applyUser)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到申请用户信息");
        }
        Company applyCompany = companyMapper.selectById(applyUser.getCompanyId());
        if(Objects.isNull(applyCompany)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到申请用户企业信息");
        }
        List<String> companyIds = Arrays.asList(companyUserApply.getCompanyIds().split(","));
        for (String companyId:companyIds) {
            if(Constants.equalsInteger(loginUserInfo.getCompanyId(),Integer.valueOf(companyId))){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无法申请归属公司权限");
            }
            if(companyPermissionMapper.selectCount(new QueryWrapper<CompanyPermission>().lambda()
                    .eq(CompanyPermission::getCompanyId,companyId)
                    .eq(CompanyPermission::getIsdeleted,Constants.ZERO)
                    .eq(CompanyPermission::getUserId,companyUserApply.getUserId()))>Constants.ZERO
            ){
                Company company = companyMapper.selectById(companyId);
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"企业【"+company.getName()+"】已申请,请勿重复申请!");
            };
        }
        List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
                .eq(Company::getIsdeleted, Constants.ZERO)
                .eq(Company::getType,Constants.ZERO)
                .in(Company::getId, companyIds)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(companyList) || !Constants.equalsInteger(companyList.size(),companyIds.size())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"企业信息异常,请检查选择企业信息");
        }
        companyUserApply.setStatus(Constants.ZERO);
        companyUserApply.setIsdeleted(Constants.ZERO);
        companyUserApply.setCreateDate(new Date());
        companyUserApply.setCreator(loginUserInfo.getId());
        companyUserApplyMapper.insert(companyUserApply);
        List<Multifile> multifileList = companyUserApply.getMultifileList();
        for (Multifile multifile:multifileList) {
            multifile.setIsdeleted(Constants.ZERO);
            multifile.setCreator(loginUserInfo.getId());
            multifile.setCreateDate(new Date());
            multifile.setObjId(companyUserApply.getId());
            multifile.setObjType(Constants.MultiFile.COMPANY_USER_APPLY.getKey());
            multifileMapper.insert(multifile);
        }
        //存储待办信息
        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.COMPANY_USER_APPLY;
        //平台待办
        Notices notices = new Notices(noticeObjectType,
                Constants.ZERO
                ,companyUserApply.getId(),
                applyCompany.getName() + " - " + applyUser.getRealname() +"提交集团账号申请" ,
                null
                ,Constants.NoticeType.ZERO);
        noticesMapper.insert(notices);
        return companyUserApply.getId();
    }
    @Override
    public void deleteById(Integer id) {
        companyUserApplyMapper.deleteById(id);
        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        CompanyUserApply companyUserApply = companyUserApplyMapper.selectById(id);
        if(Objects.isNull(companyUserApply)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(companyUserApply.getStatus(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前业务状态已流转,不允许该操作");
        }
        companyUserApplyMapper.update(null,new UpdateWrapper<CompanyUserApply>().lambda()
                .set(CompanyUserApply::getIsdeleted,Constants.ONE)
                .set(CompanyUserApply::getEditDate,new Date())
                .set(CompanyUserApply::getEditor,loginUserInfo.getId())
                .eq(CompanyUserApply::getId,id)
        );
    }
    @Override
@@ -69,7 +187,35 @@
    @Override
    public CompanyUserApply findById(Integer id) {
        return companyUserApplyMapper.selectById(id);
        CompanyUserApply companyUserApply = companyUserApplyJoinMapper.selectJoinOne(CompanyUserApply.class,new MPJLambdaWrapper<CompanyUserApply>()
                 .selectAll(CompanyUserApply.class)
                 .select(" t3.name as companyName ")
                 .select(" t1.REALNAME as realName ")
                 .select(" t2.USERNAME as userName ")
                 .leftJoin(" system_user t1 on t1.id = t.creator  ")
                 .leftJoin(" system_user t2 on t2.id = t.user_id  ")
                 .leftJoin(" company t3 on t3.id = t2.company_id  ")
                .eq(CompanyUserApply::getId,id));
        if(Objects.isNull(companyUserApply)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,id)
                .eq(Multifile::getObjType,Constants.MultiFile.COMPANY_USER_APPLY.getKey())
                .eq(Multifile::getIsdeleted,Constants.ZERO)
                .orderByDesc(Multifile::getId)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){
            String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.COMPANY_USER_APPLY).getCode();
            for (Multifile multifile:multifileList) {
                if(StringUtils.isNotBlank(multifile.getFileurl())){
                    multifile.setFileurlFull(url + multifile.getFileurl());
                }
            }
            companyUserApply.setMultifileList(multifileList);
        }
        return companyUserApply;
    }
    @Override
@@ -87,64 +233,33 @@
    @Override
    public PageData<CompanyUserApply> findPage(PageWrap<CompanyUserApply> pageWrap) {
        IPage<CompanyUserApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<CompanyUserApply> queryWrapper = new QueryWrapper<>();
        MPJLambdaWrapper<CompanyUserApply> queryWrapper = new MPJLambdaWrapper<CompanyUserApply>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getId, pageWrap.getModel().getId());
        queryWrapper.selectAll(CompanyUserApply.class);
        queryWrapper.select(" t3.name as companyName ");
        queryWrapper.select(" t1.REALNAME as realName ");
        queryWrapper.select(" t2.USERNAME as userName ");
        queryWrapper.leftJoin(" system_user t1 on t1.id = t.creator  ");
        queryWrapper.leftJoin(" system_user t2 on t2.id = t.user_id  ");
        queryWrapper.leftJoin(" company t3 on t3.id = t2.company_id  ");
        queryWrapper.eq(CompanyUserApply::getIsdeleted,Constants.ZERO);
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.apply(" t3.id = "+pageWrap.getModel().getCompanyId()+" ");
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(CompanyUserApply::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(CompanyUserApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(CompanyUserApply::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(CompanyUserApply::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getCompanyIds() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getCompanyIds, pageWrap.getModel().getCompanyIds());
        }
        if (pageWrap.getModel().getUserId() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getUserId, pageWrap.getModel().getUserId());
        }
        if (pageWrap.getModel().getContent() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getContent, pageWrap.getModel().getContent());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getStatus, pageWrap.getModel().getStatus());
            queryWrapper.eq(CompanyUserApply::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getCompanyNames() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getCompanyNames, pageWrap.getModel().getCompanyNames());
        if (pageWrap.getModel().getUserId() != null) {
            queryWrapper.eq(CompanyUserApply::getUserId, pageWrap.getModel().getUserId());
        }
        if (pageWrap.getModel().getCheckorId() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getCheckorId, pageWrap.getModel().getCheckorId());
        }
        if (pageWrap.getModel().getCheckDate() != null) {
            queryWrapper.lambda().ge(CompanyUserApply::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
            queryWrapper.lambda().le(CompanyUserApply::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
        }
        if (pageWrap.getModel().getCheckInfo() != null) {
            queryWrapper.lambda().eq(CompanyUserApply::getCheckInfo, pageWrap.getModel().getCheckInfo());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(companyUserApplyMapper.selectPage(page, queryWrapper));
        queryWrapper.orderByDesc(CompanyUserApply::getCreateDate);
        IPage<CompanyUserApply> iPage = companyUserApplyJoinMapper.selectJoinPage(page,CompanyUserApply.class,queryWrapper);
        return PageData.from(iPage);
    }
    @Override
@@ -152,4 +267,57 @@
        QueryWrapper<CompanyUserApply> wrapper = new QueryWrapper<>(companyUserApply);
        return companyUserApplyMapper.selectCount(wrapper);
    }
    @Override
    public void audit(CompanyUserApply companyUserApply){
        LoginUserInfo loginUserInfo =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(companyUserApply)
                ||Objects.isNull(companyUserApply.getId())
                || Objects.isNull(companyUserApply.getStatus())
                || !(Constants.equalsInteger(companyUserApply.getStatus(),Constants.ONE) || Constants.equalsInteger(companyUserApply.getStatus(),Constants.TWO))
                || (StringUtils.isBlank(companyUserApply.getCheckInfo()) && Constants.equalsInteger(companyUserApply.getStatus(),Constants.TWO))
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        CompanyUserApply userApply = companyUserApplyJoinMapper.selectById(companyUserApply.getId());
        if(Objects.isNull(userApply)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(userApply.getStatus(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"业务状态已流转");
        }
        CompanyUserApply update = new CompanyUserApply();
        update.setId(companyUserApply.getId());
        update.setEditDate(new Date());
        update.setEditor(loginUserInfo.getId());
        update.setStatus(companyUserApply.getStatus());
        update.setCheckInfo(companyUserApply.getCheckInfo());
        update.setCheckDate(new Date());
        update.setCheckorId(loginUserInfo.getId());
        companyUserApplyJoinMapper.updateById(update);
        if(Constants.equalsInteger(companyUserApply.getStatus(),Constants.ONE) && StringUtils.isNotBlank(userApply.getCompanyIds())){
            List<String> ids = Arrays.asList(userApply.getCompanyIds().split(","));
            List<CompanyPermission> companyPermissionList = new ArrayList<>();
            for (String id:ids) {
                CompanyPermission companyPermission = new CompanyPermission();
                companyPermission.setCreator(loginUserInfo.getId());
                companyPermission.setCreateDate(new Date());
                companyPermission.setIsdeleted(Constants.ZERO);
                companyPermission.setUserId(userApply.getUserId());
                companyPermission.setCompanyId(Integer.valueOf(id));
                companyPermission.setType(Constants.ONE);
                companyPermissionList.add(companyPermission);
            }
            companyPermissionMapper.insertBatchSomeColumn(companyPermissionList);
        }
        //存储待办信息
        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.COMPANY_USER_APPLY;
        //删除其他待办
        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey())
                .ne(Notices::getType,Constants.NoticeType.SIX.getStatus())
                .eq(Notices::getObjId,update.getId()));
    }
}