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; import com.gkhy.exam.common.exception.ApiException; 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; @Service public class SupplierSureServiceImpl extends ServiceImpl implements SupplierSureService { @Autowired private SupplierSureMapper supplierSureMapper; @Autowired private SupplierSurePerformanceMapper performanceMapper; @Autowired private SupplierSureQualityMapper qualityMapper; @Autowired private SupplierSureCertifityMapper certifityMapper; @Override public CommonPage selectSupplierList(SupplierSure sure) { if (!SecurityUtils.adminUser()){ if (sure.getCompanyId()==null){ throw new ApiException("非管理员操作,企业id不可为空"); } } PageUtils.startPage(); List supplierSures = supplierSureMapper.selectSupplierList(sure); return CommonPage.restPage(supplierSures); } @Override public CommonResult insertSupplier(SupplierSure sure) { sure.setCreateTime(LocalDateTime.now()); sure.setCreateBy(SecurityUtils.getUsername()); supplierSureMapper.insert(sure); performanceMapper.savePerformance(sure.getId()); qualityMapper.saveQuality(sure.getId()); return CommonResult.success(); } @Override public CommonResult updateSupplier(SupplierSure sure) { sure.setUpdateBy(SecurityUtils.getUsername()); sure.setUpdateTime(LocalDateTime.now()); supplierSureMapper.updateById(sure); return CommonResult.success(); } @Override public CommonResult deletedSupplier(Integer supplierId) { SupplierSure supplierSure = new SupplierSure(); supplierSure.setId(supplierId); supplierSure.setUpdateTime(LocalDateTime.now()); supplierSure.setUpdateBy(SecurityUtils.getUsername()); supplierSure.setDelFlag(2); 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 targetQueryWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); targetQueryWrapper.eq(SupplierSure::getCompanyId, companyId) .eq(SupplierSure::getYear, targetYear) .eq(SupplierSure::getDelFlag, 1); List 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 sourceQueryWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); sourceQueryWrapper.eq(SupplierSure::getCompanyId, companyId) .eq(SupplierSure::getYear, sourceYear) .eq(SupplierSure::getDelFlag, 1); List 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 certifityQueryWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); certifityQueryWrapper.eq(SupplierSureCertifity::getSupplierSureId, oldSupplierId) .eq(SupplierSureCertifity::getDelFlag, 1); List 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 qualityQueryWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); qualityQueryWrapper.eq(SupplierSureQuality::getSupplierSureId, oldSupplierId); List 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 performanceQueryWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); performanceQueryWrapper.eq(SupplierSurePerformance::getSupplierSureId, oldSupplierId); List 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("复制成功"); } }