jiangping
2024-01-30 a9ca0823ab8f33ca85abebcf6ec4a8da235adb49
server/service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
@@ -31,9 +32,12 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.net.URI;
import java.net.URLEncoder;
import java.util.*;
/**
@@ -72,9 +76,10 @@
        if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
                .eq(Company::getCode,company.getCode())
               .or().eq(Company::getPhone,company.getPhone())
               .or().eq(Company::getEmail,company.getEmail())
               .or().eq(Company::getUsername,company.getUsername())
                .or().eq(Company::getName,company.getName()))>0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该企业【名称】【统一信用代码或者【手机号】已存在,请确认后重新提交!");
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该企业【名称】【统一信用代码】【邮箱】或者【手机号】已存在,请确认后重新提交!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        company.setCreator(user.getId());
@@ -110,6 +115,46 @@
        companySolutionJoinMapper.delete(new UpdateWrapper<CompanySolution>().lambda().eq(CompanySolution::getCompanyId,company.getId()));
        //处理关联方案
        dealSolutionsData(company);
    }
    @Transactional
    public void exportFiles(Integer id, HttpServletResponse response){
        try {
            Company model = companyMapper.selectById(id);
            if(model == null){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            List<File> fileList = new ArrayList<>();
            List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                    .eq(Multifile::getObjId,id)
                    .isNotNull(Multifile::getFileurl)
                    .in(Multifile::getObjType, Arrays.asList(new Integer[]{
                            Constants.MultiFile.COM_BUSINESS_LICENSE.getKey(),
                            Constants.MultiFile.COM_IDCARD_IMG.getKey(),
                    }))
            );
            if(multifileList== null || multifileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.COMPANY_FILE).getCode();
            for(Multifile l : multifileList){
                File f = Constants.getFileByNetFile(path + l.getFileurl(),StringUtils.defaultString(l.getName(),"未命名"));
                if(f !=null && f.isFile()){
                    fileList.add(f);
                }
            }
            if(fileList == null || fileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String fileName =  model.getName() +"_企业证件_"+System.currentTimeMillis()+".zip" ;
            String encodeFileName = URLEncoder.encode(fileName);
            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
            response.setContentType("application/octet-stream");
            response.setHeader("eva-opera-type", "download");
            response.setHeader("eva-download-filename", encodeFileName);
            Constants. packFilesToZip(fileList,response.getOutputStream());
        } catch (IOException e) {
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
    private void dealSystemUserData(Company company) {
@@ -258,13 +303,11 @@
        List<Multifile> multifileList = new ArrayList<>();
        List<Integer> objList = new ArrayList<>();
        if(company.getBusinessImg()!=null && StringUtils.isNotBlank(company.getBusinessImg().getFileurl())){
        if(company.getBusinessImg()!=null && company.getBusinessImg().getId() ==null && StringUtils.isNotBlank(company.getBusinessImg().getFileurl())){
            multifileList.add(initMultiFileByCompay(company,company.getBusinessImg(),Constants.MultiFile.COM_BUSINESS_LICENSE.getKey()));
            objList.add(Constants.MultiFile.COM_BUSINESS_LICENSE.getKey());
        }else  {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请上传营业执照!");
        }
        if(company.getSignImg()!=null && StringUtils.isNotBlank(company.getSignImg().getFileurl())){
        if(company.getSignImg()!=null&& company.getSignImg().getId() ==null && StringUtils.isNotBlank(company.getSignImg().getFileurl())){
            multifileList.add(initMultiFileByCompay(company,company.getSignImg(),Constants.MultiFile.COM_SING_IMG.getKey()));
            objList.add(Constants.MultiFile.COM_SING_IMG.getKey());
            company.setSignIdStatus(Constants.ZERO);//标记电子签章未上传
@@ -275,10 +318,16 @@
            company.setSignId("");
        }
        if(company.getIdcardImgList()!=null && company.getIdcardImgList()!=null){
            boolean isNew = false;
            for(Multifile f : company.getIdcardImgList()){
                if(f.getId() !=null){
                    continue;
                }
                isNew = true;
                multifileList.add(initMultiFileByCompay(company,f,Constants.MultiFile.COM_IDCARD_IMG.getKey()));
            }
            objList.add(Constants.MultiFile.COM_IDCARD_IMG.getKey());
            if(isNew)
              objList.add(Constants.MultiFile.COM_IDCARD_IMG.getKey());
        }
        if(objList.size()>0){
            multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda()
@@ -340,7 +389,9 @@
                || StringUtils.isBlank(company.getCaptche())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST );
        }
        SmsEmailServiceImpl.isCaptcheValide(smsEmailMapper,company.getPhone(),company.getCaptche());
        if(!debugModel){
            SmsEmailServiceImpl.isCaptcheValide(smsEmailMapper,company.getPhone(),company.getCaptche());
        }
        Company model = companyMapper.selectById(company.getId());
        if(model == null  || StringUtils.equals(model.getPhone(),company.getPhone()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"手机号未发生改变~" );
@@ -378,9 +429,8 @@
    }
    private void isValidUpdateParam(Company company) {
        if( StringUtils.isBlank(company.getName())
                ||StringUtils.isBlank(company.getUsername())
//                ||StringUtils.isBlank(company.getUsername())
                ||StringUtils.isBlank(company.getCode())
                ||StringUtils.isBlank(company.getCaptche())
                ||StringUtils.isBlank(company.getLegalName())
                ||StringUtils.isBlank(company.getEmail()) ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
@@ -404,10 +454,11 @@
        if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
                .ne(Company::getId,company.getId())
                .and(w->w.eq(Company::getCode,company.getCode())
                    .or().eq(Company::getEmail,company.getEmail())
                    .or().eq(Company::getUsername,company.getUsername())
                    .or().eq(Company::getName,company.getName()))
                )>0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该企业【名称】【统一信用代码或者【企业账号】已存在,请确认后重新提交!");
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该企业【名称】【统一信用代码】【邮箱】或者【企业账号】已存在,请确认后重新提交!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Constants.equalsInteger(model.getSignIdStatus(),Constants.ONE)){
@@ -416,7 +467,6 @@
        dealFileDataForUpdate(company);
        Company update = new Company();
        update.setIsdeleted(company.getId());
        update.setName(company.getName());
        update.setCode(company.getCode());
        update.setEditDate(new Date());
@@ -427,6 +477,8 @@
        update.setTaxCode(company.getTaxCode());
        update.setTaxBank(company.getTaxBank());
        update.setEmail(company.getEmail());
        update.setId(model.getId());
        update.setLegalName(company.getLegalName());
        update.setInvoiceAddr(company.getInvoiceAddr());
        update.setSignIdStatus(company.getSignIdStatus());
        update.setInvoiceEmail(company.getInvoiceEmail());
@@ -437,7 +489,7 @@
            //如果邮箱发生改变
            update.setSignStatus(Constants.ZERO);
        }
        companyMapper.updateById(company);
        companyMapper.updateById(update);
        company.setCreator(update.getEditor());
        company.setCreateDate(update.getEditDate());
        if(StringUtils.isNotBlank(company.getUsername())){
@@ -460,7 +512,7 @@
    @Override
    public Company findById(Integer id) {
        Company model = findById(id);
        Company model = companyMapper.selectById(id);
        if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
@@ -515,6 +567,7 @@
     *   public boolean organizationCreate (String fullname,String creditCode,String legalName,String email,File  businessimg,String notifyUrl){
     */
    @Override
    @Async
    public   void startSignAuth(Integer id){
        Company company = companyMapper.selectById(id);
        Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda()
@@ -654,10 +707,9 @@
            }else {
                wrapper.lambda().in(Company::getId, user.getCompanyIdList());
            }
//            queryWrapper.exists("select b.id from company_permission b where b.user_id="+user.getId()+" and b.isdeleted=0 and b.company_id=company.id");
        } else if (company.getQueryFlag() == 1) {
        } else if (company.getQueryFlag() == 1 && company.getUserId()!=null) {
            //查詢是否有查看權限
            wrapper.select("*,(select count(1) from company_permission b where b.user_id="+user.getId()+" and b.isdeleted=0 and b.company_id=company.id) as hasPerimission");
            wrapper.select("*,(select count(1) from company_permission b where b.user_id="+company.getUserId()+" and b.isdeleted=0 and b.company_id=company.id) as hasPerimission");
        }
        return companyMapper.selectList(wrapper);
    }