“djh”
4 hours ago 2d9bf42ce507096c3b73a782da3ad16f29d2ccdc
multi-system/src/main/java/com/gkhy/exam/system/service/impl/SupplierSureServiceImpl.java
@@ -1,5 +1,6 @@
package com.gkhy.exam.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
@@ -7,10 +8,17 @@
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.SupplierSure;
import com.gkhy.exam.system.domain.SupplierSureCertifity;
import com.gkhy.exam.system.domain.SupplierSurePerformance;
import com.gkhy.exam.system.domain.SupplierSureQuality;
import com.gkhy.exam.system.mapper.SupplierSureCertifityMapper;
import com.gkhy.exam.system.mapper.SupplierSureMapper;
import com.gkhy.exam.system.mapper.SupplierSurePerformanceMapper;
import com.gkhy.exam.system.mapper.SupplierSureQualityMapper;
import com.gkhy.exam.system.service.SupplierSureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@@ -20,6 +28,12 @@
    @Autowired
    private SupplierSureMapper supplierSureMapper;
    @Autowired
    private SupplierSurePerformanceMapper performanceMapper;
    @Autowired
    private SupplierSureQualityMapper qualityMapper;
    @Autowired
    private SupplierSureCertifityMapper certifityMapper;
    @Override
    public CommonPage selectSupplierList(SupplierSure sure) {
@@ -38,6 +52,8 @@
        sure.setCreateTime(LocalDateTime.now());
        sure.setCreateBy(SecurityUtils.getUsername());
        supplierSureMapper.insert(sure);
        performanceMapper.savePerformance(sure.getId());
        qualityMapper.saveQuality(sure.getId());
        return CommonResult.success();
    }
@@ -59,4 +75,163 @@
        supplierSureMapper.updateById(supplierSure);
        return CommonResult.success();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult copySupplierSure(Integer companyId, String sourceYear, String targetYear) {
        if (companyId == null) {
            companyId = Math.toIntExact(SecurityUtils.getCompanyId());
        }
        if (sourceYear == null || sourceYear.isEmpty()) {
            return CommonResult.failed("源年份不能为空");
        }
        if (targetYear == null || targetYear.isEmpty()) {
            return CommonResult.failed("目标年份不能为空");
        }
        String currentUsername = SecurityUtils.getUsername();
        LocalDateTime now = LocalDateTime.now();
        LambdaQueryWrapper<SupplierSure> targetQueryWrapper =
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
        targetQueryWrapper.eq(SupplierSure::getCompanyId, companyId)
                .eq(SupplierSure::getYear, targetYear)
                .eq(SupplierSure::getDelFlag, 1);
        List<SupplierSure> targetSuppliers = supplierSureMapper.selectList(targetQueryWrapper);
        if (targetSuppliers != null && !targetSuppliers.isEmpty()) {
            for (SupplierSure targetSupplier : targetSuppliers) {
                Integer targetSupplierId = targetSupplier.getId();
                SupplierSure deleteSupplier = new SupplierSure();
                deleteSupplier.setId(targetSupplierId);
                deleteSupplier.setDelFlag(2);
                deleteSupplier.setUpdateTime(now);
                deleteSupplier.setUpdateBy(currentUsername);
                supplierSureMapper.updateById(deleteSupplier);
            }
        }
        LambdaQueryWrapper<SupplierSure> sourceQueryWrapper =
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
        sourceQueryWrapper.eq(SupplierSure::getCompanyId, companyId)
                .eq(SupplierSure::getYear, sourceYear)
                .eq(SupplierSure::getDelFlag, 1);
        List<SupplierSure> sourceSuppliers = supplierSureMapper.selectList(sourceQueryWrapper);
        if (sourceSuppliers == null || sourceSuppliers.isEmpty()) {
            return CommonResult.failed("源年份没有可复制的数据");
        }
        for (SupplierSure sourceSupplier : sourceSuppliers) {
            Integer oldSupplierId = sourceSupplier.getId();
            SupplierSure newSupplier = new SupplierSure();
            newSupplier.setCompanyId(sourceSupplier.getCompanyId());
            newSupplier.setYear(targetYear);
            newSupplier.setSupplierName(sourceSupplier.getSupplierName());
            newSupplier.setSupplierAddr(sourceSupplier.getSupplierAddr());
            newSupplier.setMerito(sourceSupplier.getMerito());
            newSupplier.setUser(sourceSupplier.getUser());
            newSupplier.setPhone(sourceSupplier.getPhone());
            newSupplier.setRemark(sourceSupplier.getRemark());
            newSupplier.setDelFlag(1);
            newSupplier.setCreateBy(currentUsername);
            newSupplier.setCreateTime(now);
            newSupplier.setUpdateBy(currentUsername);
            newSupplier.setUpdateTime(now);
            supplierSureMapper.insert(newSupplier);
            Integer newSupplierId = newSupplier.getId();
            LambdaQueryWrapper<SupplierSureCertifity> certifityQueryWrapper =
                    new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
            certifityQueryWrapper.eq(SupplierSureCertifity::getSupplierSureId, oldSupplierId)
                    .eq(SupplierSureCertifity::getDelFlag, 1);
            List<SupplierSureCertifity> certifities = certifityMapper.selectList(certifityQueryWrapper);
            if (certifities != null && !certifities.isEmpty()) {
                for (SupplierSureCertifity certifity : certifities) {
                    SupplierSureCertifity newCertifity = new SupplierSureCertifity();
                    newCertifity.setSupplierSureId(newSupplierId);
                    newCertifity.setCertifityName(certifity.getCertifityName());
                    newCertifity.setFilePath(certifity.getFilePath());
                    newCertifity.setDelFlag(1);
                    certifityMapper.insert(newCertifity);
                }
            }
            LambdaQueryWrapper<SupplierSureQuality> qualityQueryWrapper =
                    new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
            qualityQueryWrapper.eq(SupplierSureQuality::getSupplierSureId, oldSupplierId);
            List<SupplierSureQuality> qualities = qualityMapper.selectList(qualityQueryWrapper);
            if (qualities != null && !qualities.isEmpty()) {
                for (SupplierSureQuality quality : qualities) {
                    SupplierSureQuality newQuality = new SupplierSureQuality();
                    newQuality.setSupplierSureId(newSupplierId);
                    newQuality.setName(quality.getName());
                    newQuality.setAddress(quality.getAddress());
                    newQuality.setPerson(quality.getPerson());
                    newQuality.setEmil(quality.getEmil());
                    newQuality.setPhone(quality.getPhone());
                    newQuality.setTrait(quality.getTrait());
                    newQuality.setFacility(quality.getFacility());
                    newQuality.setCraft(quality.getCraft());
                    newQuality.setDevelop(quality.getDevelop());
                    newQuality.setTeamWork(quality.getTeamWork());
                    newQuality.setQualification(quality.getQualification());
                    newQuality.setOtherQualifi(quality.getOtherQualifi());
                    newQuality.setOtherDate(quality.getOtherDate());
                    newQuality.setProduct(quality.getProduct());
                    newQuality.setOtherProduct(quality.getOtherProduct());
                    newQuality.setCompanyMess(quality.getCompanyMess());
                    newQuality.setChargeName(quality.getChargeName());
                    newQuality.setChargeTime(now);
                    qualityMapper.insert(newQuality);
                }
            }
            LambdaQueryWrapper<SupplierSurePerformance> performanceQueryWrapper =
                    new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
            performanceQueryWrapper.eq(SupplierSurePerformance::getSupplierSureId, oldSupplierId);
            List<SupplierSurePerformance> performances = performanceMapper.selectList(performanceQueryWrapper);
            if (performances != null && !performances.isEmpty()) {
                for (SupplierSurePerformance performance : performances) {
                    SupplierSurePerformance newPerformance = new SupplierSurePerformance();
                    newPerformance.setSupplierSureId(newSupplierId);
                    newPerformance.setName(performance.getName());
                    newPerformance.setAddress(performance.getAddress());
                    newPerformance.setPeople(performance.getPeople());
                    newPerformance.setPhone(performance.getPhone());
                    newPerformance.setEmil(performance.getEmil());
                    newPerformance.setProduct(performance.getProduct());
                    newPerformance.setType(performance.getType());
                    newPerformance.setGist(performance.getGist());
                    newPerformance.setVerify(performance.getVerify());
                    newPerformance.setP1(performance.getP1());
                    newPerformance.setP2(performance.getP2());
                    newPerformance.setP3(performance.getP3());
                    newPerformance.setP4(performance.getP4());
                    newPerformance.setP5(performance.getP5());
                    newPerformance.setP6(performance.getP6());
                    newPerformance.setOpinion(performance.getOpinion());
                    newPerformance.setReviewUsers(performance.getReviewUsers());
                    newPerformance.setReviewTime(now);
                    newPerformance.setReviewMess(performance.getReviewMess());
                    newPerformance.setCheckId(performance.getCheckId());
                    newPerformance.setCheckTime(now);
                    performanceMapper.insert(newPerformance);
                }
            }
        }
        return CommonResult.success("复制成功");
    }
}