“djh”
6 hours ago 2d9bf42ce507096c3b73a782da3ad16f29d2ccdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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<SupplierSureMapper, SupplierSure> 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<SupplierSure> 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<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("复制成功");
    }
 
}