k94314517
2025-07-04 50fb58286ed3b718c39a97e0987ee7561a295651
server/service/src/main/java/com/doumee/service/business/impl/CompanySolutionServiceImpl.java
@@ -1,25 +1,38 @@
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.CompanyMapper;
import com.doumee.dao.business.CompanySolutionMapper;
import com.doumee.dao.business.MultifileMapper;
import com.doumee.dao.business.SolutionsMapper;
import com.doumee.dao.business.join.CompanySolutionJoinMapper;
import com.doumee.dao.business.model.Company;
import com.doumee.dao.business.model.CompanySolution;
import com.doumee.dao.business.model.Solutions;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CompanySolutionService;
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.doumee.service.business.third.SignService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.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 oshi.driver.linux.Sysfs;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
 * 企业可用保险方案关联表Service实现
@@ -33,6 +46,16 @@
    private CompanySolutionJoinMapper companySolutionJoinMapper;
    @Autowired
    private CompanySolutionMapper companySolutionMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private MultifileMapper multifileMapper;
    @Autowired
    private SolutionsMapper solutionsMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private SignService signService;
    @Override
    public Integer create(CompanySolution companySolution) {
@@ -90,14 +113,30 @@
        csWrapper.selectAll(CompanySolution.class);
        csWrapper.selectAs(Solutions::getType,CompanySolution::getSolutionType);
        csWrapper.selectAs(Solutions::getName,CompanySolution::getSolutionName);
        csWrapper.selectAs(Company::getName,CompanySolution::getShopName);
        csWrapper.selectAs(Company::getName,CompanySolution::getCompanyName);
        csWrapper.selectAs(SystemUser::getRealname,CompanySolution::getSignUserName);
        csWrapper.select(" t4.name as shopName ");
        csWrapper.leftJoin(Solutions.class,Solutions::getId,CompanySolution::getSolutionBaseId);
        csWrapper.leftJoin(Company.class, Company::getId,CompanySolution::getShopId);
        csWrapper.eq(CompanySolution::getCompanyId,companySolution.getCompanyId());
        csWrapper.leftJoin(Company.class, Company::getId,CompanySolution::getCompanyId);
        csWrapper.leftJoin(SystemUser.class, SystemUser::getId,CompanySolution::getSignUserId);
        csWrapper.leftJoin(" company t4 on t4.id = t.shop_id ");
        csWrapper.eq(Objects.nonNull(companySolution.getCompanyId()),CompanySolution::getCompanyId,companySolution.getCompanyId());
        csWrapper.eq(Objects.nonNull(companySolution.getSolutionId()),CompanySolution::getSolutionBaseId,companySolution.getSolutionId());
        csWrapper.eq(CompanySolution::getIsdeleted, Constants.ZERO);
        csWrapper.eq(Solutions::getIsdeleted, Constants.ZERO);
        csWrapper.orderByAsc(CompanySolution::getCreateDate);
        csWrapper.orderByAsc(CompanySolution::getSortnum);
        return companySolutionJoinMapper.selectJoinList(CompanySolution.class,csWrapper);
        List<CompanySolution> companySolutionList = companySolutionJoinMapper.selectJoinList(CompanySolution.class,csWrapper);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(companySolutionList)){
            String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
            for (CompanySolution c:companySolutionList) {
                if(StringUtils.isNotBlank(c.getFileSignUrl())){
                    c.setFileSignUrl(url + c.getFileSignUrl());
                }
            }
        }
        return companySolutionList;
    }
    @Override
    public List<CompanySolution> findList(CompanySolution companySolution) {
@@ -166,4 +205,67 @@
        QueryWrapper<CompanySolution> wrapper = new QueryWrapper<>(companySolution);
        return companySolutionMapper.selectCount(wrapper);
    }
    @Override
    public  String getCompanySolutionSignLink(Integer id) {
        if(id == null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        MPJLambdaWrapper<CompanySolution> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(CompanySolution.class);
        queryWrapper.selectAs(Company::getName,CompanySolution::getShopName);
        queryWrapper.leftJoin(Company.class,Company::getId,CompanySolution::getCompanyId);
        queryWrapper.eq(CompanySolution::getId,id);
        queryWrapper.last(" limit 1");
        CompanySolution companySolution = companySolutionJoinMapper.selectJoinOne(CompanySolution.class,queryWrapper);
        if(companySolution == null ||!Constants.equalsInteger(companySolution.getIsdeleted(),Constants.ZERO) ){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        Company company = companyMapper.selectById(companySolution.getCompanyId());
        if(Objects.isNull(company)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到企业信息!");
        }
        Solutions solutions = solutionsMapper.selectById(companySolution.getSolutionId());
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到关联方案信息!");
        }
        //如果是驳回,只能可驳回已签章状态下的退回申请状态进行操作
        if(!Constants.equalsInteger(companySolution.getStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业的方案确认书状态已流转,当前不支持该操作~");
        }
        Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,companySolution.getSolutionId())
                .eq(Multifile::getObjType,Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey())
                .eq(Multifile::getIsdeleted,Constants.ZERO).last("limit 1"));
        if(f == null || StringUtils.isBlank(f.getFileurl())){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取待签章文件失败,请联系确认签署文件是否正确!");
        }
        String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode()+f.getFileurl();
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        String applyNo = signService.applySign(solutions.getName(),url,company.getName(),company.getCode(),company.getEmail(),null,company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        CompanySolution update= new CompanySolution();
        update.setId(companySolution.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setApplyNo(applyNo);
        update.setSignStatus(Constants.ZERO);
//        update.setSignUserId(user.getId());
//        update.setSignDate(new Date());
        companySolutionJoinMapper.updateById(update);
        return  link;
    }
}