教育训练处考试制证系统后端
“djh”
2025-02-20 ca90224ae08ff40b78daad37175639cae71c0855
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
package com.gkhy.exam.pay.service.impl;
 
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.pay.dto.rep.NonCoalCateRep;
import com.gkhy.exam.pay.dto.rep.NonCoalPayOrder;
import com.gkhy.exam.pay.dto.rep.NonCoalStuRep;
import com.gkhy.exam.pay.dto.req.NonCoalPayStuImport;
import com.gkhy.exam.pay.dto.req.NonCoalPayStudentReqDto;
import com.gkhy.exam.pay.entity.NonCoalPay;
import com.gkhy.exam.pay.entity.NonCoalPayStudent;
import com.gkhy.exam.pay.entity.PayReqData;
import com.gkhy.exam.pay.mapper.NonCoalPayMapper;
import com.gkhy.exam.pay.mapper.NonCoalPayStudentMapper;
import com.gkhy.exam.pay.service.NonCoalPayStudentService;
import com.gkhy.exam.pay.utils.CaiZhengConstans;
import com.gkhy.exam.pay.utils.PayUtils;
import com.gkhy.exam.pay.utils.ResultVo;
import com.gkhy.exam.pay.utils.SexUtils;
import com.ruoyi.common.constant.ResultConstants;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.RandomUtil;
import com.ruoyi.common.utils.RedisLock;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
 
/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author hh
 * @date 2025-01-16
 */
@Service
@Slf4j
public class NonCoalPayStudentServiceImpl extends ServiceImpl<NonCoalPayStudentMapper, NonCoalPayStudent> implements NonCoalPayStudentService {
    @Resource
    private NonCoalPayStudentMapper nonCoalPayStudentMapper;
    @Resource
    private NonCoalPayMapper nonCoalPayMapper;
    @Resource
    private PayUtils payUtils;
    @Autowired
    private RedisLock redisLock;
 
 
    @Override
    public String sendOrder(Long dataId, String payType) {
 
        String lockKey = CaiZhengConstans.NON_COAL_PAY_STUDENT_LOCK + dataId + CaiZhengConstans.UN_COAL_ORDER_KEY_1 + payType;
 
 
        Boolean b = redisLock.tryLock(lockKey, 30, 40, TimeUnit.SECONDS);
        if (b) {
            String orderNo = RandomUtil.generateOrderNumber(dataId, CaiZhengConstans.UN_COAL_ORDER_PERFIX);
            List<NonCoalPayOrder> nonCoalPayOrders = nonCoalPayMapper.selectNonCoalPayOrderByParam(dataId, Long.valueOf(payType), 1L);
            if (StringUtils.isEmpty(nonCoalPayOrders)) {
                throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息");
            }
            NonCoalPayOrder nonCoalPayOrder = nonCoalPayOrders.get(0);
 
            List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList();
 
            if (StringUtils.isEmpty(nonCoalStuList)) {
                throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到需要缴费的学员");
            }
            NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0);
 
            if (nonCoalStuRep.getPayStatus() == 1) {
                throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已缴费请勿重复缴费");
            }
            //财政缴款码已生成了
            if (nonCoalStuRep.getGovPayStatus() == 2) {
                return nonCoalStuRep.getOrderId();
            }
            //财政缴款码未生成
//            if (nonCoalStuRep.getPayStatus() == 0) {
//                if ("1".equals(payType)) {
//                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
//                            .set(NonCoalPayStudent::getOrderNo, orderNo)
//                            .set(NonCoalPayStudent::getGovPayStatus, 1)
//                            .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
//                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
//                } else {
//                    //团体缴费
//                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
//                            .set(NonCoalPayStudent::getOrderNo, orderNo)
//                            .set(NonCoalPayStudent::getGovPayStatus, 1)
//                            .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
//                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
//                }
//            } else {
//                orderNo = nonCoalStuRep.getOrderNo();
//            }
            List<NonCoalCateRep> nonCoalPayCategoryList = nonCoalPayOrder.getNonCoalPayCategoryList();
 
            if (StringUtils.isEmpty(nonCoalPayCategoryList)) {
                throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "缴费信息缺失");
            }
            // 业务处理
            //查询主信息   查询是否是团队
            PayReqData payReqData = dealData(nonCoalPayOrder, orderNo, payType);
 
            try {
                ResultVo resultVo = payUtils.faqiV2(payReqData);
                log.info("调用接口返回结果:" + resultVo);
                if (resultVo.getRespcode().equals(CaiZhengConstans.CAI_ZHENG_SUCCESS)) {
                    String orderId = resultVo.getRespdata().getOrderId();
                    String billNo = resultVo.getRespdata().getBillNo();
                    if (StringUtils.isNotEmpty(orderId)) {
                        // 更新订单
                        if ("1".equals(payType)) {
                            baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                                    .set(NonCoalPayStudent::getOrderId, orderId)
                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getPayCode, billNo)
                                    .set(NonCoalPayStudent::getGovPayStatus, 2)
                                    .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                                    .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                        } else {
                            //团体缴费
                            baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                                    .set(NonCoalPayStudent::getOrderId, orderId)
                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getPayCode, billNo)
                                    .set(NonCoalPayStudent::getGovPayStatus, 2)
                                    .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                                    .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                        }
                    }
                    return orderId;
                } else {
                    log.error("生成订单失败:" + resultVo.getRespmsg() + ",请稍后重试,错误编码:" + resultVo.getRespcode() + "参数如下:" + payReqData);
                    throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "发起支付失败,请稍后重试");
                }
 
            } catch (Exception e) {
                log.error("发起支付调用接口失败:" + e);
                throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, e.getMessage());
            } finally {
                redisLock.unlock(lockKey);
            }
        }
 
 
        return null;
    }
 
    @Override
    public NonCoalStuRep queryOrder(Long dataId, String payType) {
        List<NonCoalPayOrder> nonCoalPayOrders = nonCoalPayMapper.selectNonCoalPayOrderByParam(dataId, Long.valueOf(payType), 2L);
        if (StringUtils.isEmpty(nonCoalPayOrders)) {
            throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息");
        }
        NonCoalPayOrder nonCoalPayOrder = nonCoalPayOrders.get(0);
 
        List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList();
 
        if (StringUtils.isEmpty(nonCoalStuList)) {
            throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到需要缴费的学员");
        }
        NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0);
 
//        if (nonCoalStuRep.getPayStatus() == 1) {
//            throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已缴费请勿重复缴费");
//        }
 
        if (nonCoalStuRep.getGovPayStatus() == 2 && nonCoalStuRep.getPayStatus() == 0) {
            try {
                JSONObject result = payUtils.query(nonCoalStuRep.getOrderNo());
                log.info("查询财政订单返回结果:" + result);
                String respcode = result.getString("respcode");
                if (CaiZhengConstans.CAI_ZHENG_SUCCESS.equals(respcode)) {
                    JSONObject respdata = result.getJSONObject("respdata");
                    if (respdata != null && "1".equals(respdata.getString("status"))) {
                        nonCoalPayStudentMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                                .set(NonCoalPayStudent::getPayStatus, 1)
                                .set(NonCoalPayStudent::getPayTime, respdata.getDate("payTime"))
                                .eq(NonCoalPayStudent::getOrderNo, nonCoalStuRep.getOrderNo()).eq(NonCoalPayStudent::getDelFlag, 0)
                                .eq(NonCoalPayStudent::getPayStatus, 0));
                        // 回调确认支付
                        payUtils.affirmPost(nonCoalStuRep.getOrderNo());
                    } else {
                        log.error("查询财政订单失败:" + result.getString("respmsg") + ",错误编码:" + result.getString("respcode"));
                    }
 
                }
            } catch (Exception e) {
                log.error("查询财政订单失败:" + e.getMessage());
 
            }
        }
 
        return nonCoalStuRep;
    }
 
    private PayReqData dealData(NonCoalPayOrder nonCoalPayOrder, String orderNo, String payType) {
        List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList();
        List<NonCoalCateRep> nonCoalPayCategoryList = nonCoalPayOrder.getNonCoalPayCategoryList();
        PayReqData payReqData = new PayReqData();
        payReqData.setOrderNo(orderNo);
        payReqData.setPayerType(Integer.valueOf(payType));
        payReqData.setMoney(nonCoalPayOrder.getAmount().multiply(BigDecimal.valueOf(nonCoalStuList.size())));
        payReqData.setAmount(nonCoalStuList.size());
 
        payReqData.setDesc(nonCoalPayOrder.getBatchName());
 
        NonCoalCateRep nonCoalCateRep1 = nonCoalPayCategoryList.get(0);
        payReqData.setHandlingPerson(nonCoalCateRep1.getDrawer());
        payReqData.setChecker(nonCoalCateRep1.getReviewer());
        payReqData.setEnterCode(nonCoalCateRep1.getCompanyCode());
        payReqData.setInvoiceSocialCode(nonCoalCateRep1.getInvoicingCompanyCode());
 
        List<PayReqData.Feedata> feedatas1 = new ArrayList<>();
        for (NonCoalCateRep nonCoalCateRep : nonCoalPayCategoryList) {
            PayReqData.Feedata feedatas = new PayReqData.Feedata();
            feedatas.setAmount(nonCoalStuList.size());
            feedatas.setBusCode(nonCoalCateRep.getBusinessCode());
            feedatas.setPrice(nonCoalCateRep.getCategoryAmount());
            feedatas1.add(feedatas);
        }
        payReqData.setFeeDatas(feedatas1);
        if ("1".equals(payType)) {
            //个人缴费
            NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0);
            payReqData.setPayerName(nonCoalStuRep.getStudentName());
            payReqData.setCertNo(nonCoalStuRep.getIdCard());
        } else {
            //团体缴费
            payReqData.setPayerName(nonCoalPayOrder.getPayCompanyName());
            payReqData.setCertNo(nonCoalPayOrder.getPayCompanyCard());
            //todo 待确认
            payReqData.setInvoiceSocialCode(nonCoalPayOrder.getPayCompanyCard());
            payReqData.setEnterCode(nonCoalPayOrder.getPayCompanyCard());
        }
        return payReqData;
 
    }
 
    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public NonCoalPayStudent selectNonCoalPayStudentById(Long id) {
        return nonCoalPayStudentMapper.selectNonCoalPayStudentById(id);
    }
 
 
    /**
     * 查询【请填写功能名称】列表
     *
     * @param nonCoalPayStudent 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<NonCoalPayStudent> selectNonCoalPayStudentList(NonCoalPayStudent nonCoalPayStudent) {
        return nonCoalPayStudentMapper.selectNonCoalPayStudentList(nonCoalPayStudent);
    }
 
    /**
     * 新增【请填写功能名称】
     *
     * @param nonCoalPayStudent 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertNonCoalPayStudent(NonCoalPayStudent nonCoalPayStudent) {
        checkSameData(nonCoalPayStudent);
        NonCoalPay nonCoalPay = checkNonCoalPay(nonCoalPayStudent.getNonCoalPayId());
        nonCoalPayStudent.setPayType(nonCoalPay.getPayPersonType().longValue());
//        nonCoalPayStudent.setOrderNo(RandomUtil.generateOrderNumber());
 
        nonCoalPayStudent.setCreateBy(SecurityUtils.getUsername());
        return nonCoalPayStudentMapper.insertNonCoalPayStudent(nonCoalPayStudent);
    }
 
    /**
     * 修改【请填写功能名称】
     *
     * @param nonCoalPayStudent 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateNonCoalPayStudent(NonCoalPayStudent nonCoalPayStudent) {
        checkData(nonCoalPayStudent.getId());
        checkSameData(nonCoalPayStudent);
        nonCoalPayStudent.setPayType(null);
        nonCoalPayStudent.setOrderNo(null);
        nonCoalPayStudent.setUpdateBy(SecurityUtils.getUsername());
        return nonCoalPayStudentMapper.updateNonCoalPayStudent(nonCoalPayStudent);
    }
 
    @Override
    public int updateNonCoalStu(NonCoalPayStudentReqDto nonCoalPayStudent) {
 
        if (nonCoalPayStudent.getId() != null) {
            NonCoalPayStudent nonCoalPayStudent1 = selectNonCoalPayStudentById(nonCoalPayStudent.getId());
            if (nonCoalPayStudent1 != null) {
                nonCoalPayStudent1.setPayCode(nonCoalPayStudent.getPayCode());
                nonCoalPayStudent1.setPayStatus(1L);
                nonCoalPayStudent1.setUpdateBy(SecurityUtils.getUsername());
            } else {
                log.error("修改缴费学员失败,该缴费学员不存在:" + nonCoalPayStudent.getId());
            }
        } else {
            if (nonCoalPayStudent.getNonCoalPayId() != null) {
                baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                        .set(NonCoalPayStudent::getUpdateBy, SecurityUtils.getUsername())
                        .set(NonCoalPayStudent::getPayCode, nonCoalPayStudent.getPayCode())
                        .set(NonCoalPayStudent::getPayStatus, 1L)
                        .eq(NonCoalPayStudent::getNonCoalPayId, nonCoalPayStudent.getNonCoalPayId())
                        .eq(NonCoalPayStudent::getPayStatus, 0L).eq(NonCoalPayStudent::getDelFlag, 0));
            }
        }
        return 0;
    }
 
    private void checkSameData(NonCoalPayStudent nonCoalPay) {
        LambdaQueryWrapper<NonCoalPayStudent> lambdaQueryWrapper = Wrappers.<NonCoalPayStudent>lambdaQuery()
                .eq(NonCoalPayStudent::getNonCoalPayId, nonCoalPay.getNonCoalPayId())
                .eq(NonCoalPayStudent::getIdCard, nonCoalPay.getIdCard())
                .eq(NonCoalPayStudent::getDelFlag, 0);
        if (nonCoalPay.getId() != null) {
            lambdaQueryWrapper.ne(NonCoalPayStudent::getId, nonCoalPay.getId());
        }
        Long l = baseMapper.selectCount(lambdaQueryWrapper);
        if (l > 0) {
            throw new ServiceException("该缴费学员已存在");
        }
    }
 
    @Override
    public void checkHavePayData(Long nonPayId) {
        LambdaQueryWrapper<NonCoalPayStudent> lambdaQueryWrapper = Wrappers.<NonCoalPayStudent>lambdaQuery()
                .eq(NonCoalPayStudent::getNonCoalPayId, nonPayId)
                .eq(NonCoalPayStudent::getDelFlag, 0).eq(NonCoalPayStudent::getPayStatus, 1L);
 
        Long l = baseMapper.selectCount(lambdaQueryWrapper);
        if (l > 0) {
            throw new ServiceException("已开始缴费不可修改");
        }
    }
 
 
    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteNonCoalPayStudentByIds(Long[] ids) {
        return nonCoalPayStudentMapper.deleteNonCoalPayStudentByIds(ids);
    }
 
    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteNonCoalPayStudentById(Long id) {
        checkData(id);
        return nonCoalPayStudentMapper.deleteNonCoalPayStudentById(id, SecurityUtils.getUsername());
    }
 
    @Override
    public String importData(List<NonCoalPayStuImport> nonCoalPayStudents, String operName, Long nonCoalPayId) {
        if (StringUtils.isNull(nonCoalPayStudents) || nonCoalPayStudents.isEmpty()) {
            throw new ServiceException("导入数据不能为空!");
        }
        NonCoalPay nonCoalPay = checkNonCoalPay(nonCoalPayId);
        Integer payPersonType = nonCoalPay.getPayPersonType();
        Set<String> collect = nonCoalPayStudents.stream()
                .map(NonCoalPayStuImport::getIdCard)
                .collect(Collectors.toSet());
        if (collect.size() != nonCoalPayStudents.size()) {
            throw new ServiceException("导入数据不能有重复身份证号!");
        }
        Map<String, String> idCardToNameMap = new HashMap<>();
        NonCoalPayStudent student = new NonCoalPayStudent();
        student.setNonCoalPayId(nonCoalPayId);
 
        List<NonCoalPayStudent> nonCoalPayStudents1 = nonCoalPayStudentMapper.selectNonCoalPayStudentList(student);
        if (nonCoalPayStudents1 != null && !nonCoalPayStudents1.isEmpty()) {
            idCardToNameMap = nonCoalPayStudents1.stream()
                    .collect(Collectors.toMap(
                            NonCoalPayStudent::getIdCard,
                            NonCoalPayStudent::getIdCard
                    ));
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (NonCoalPayStuImport stu : nonCoalPayStudents) {
            try {
                if (StringUtils.isEmpty(stu.getIdCard()) || StringUtils.isEmpty(stu.getName()) || StringUtils.isEmpty(stu.getPhone())) {
                    failureMsg.append("<br/>" + failureNum + "、导入数据为空: " + stu.getIdCard() + " 数据错误");
                } else if (idCardToNameMap.get(stu.getIdCard().trim()) != null) {
                    failureMsg.append("<br/>" + failureNum + "、身份证号: " + stu.getIdCard() + " 数据已存在");
                } else {
                    NonCoalPayStudent stu1 = new NonCoalPayStudent();
                    stu1.setPayStatus(0L);
                    stu1.setPayType(payPersonType.longValue());
                    stu1.setNonCoalPayId(nonCoalPayId);
                    stu1.setCreateBy(operName);
                    stu1.setName(stu.getName());
                    stu1.setIdCard(stu.getIdCard());
                    stu1.setPhone(stu.getPhone());
                    if (StringUtils.isNotEmpty(stu.getTrain())) {
                        stu1.setTrain(stu.getTrain());
                    }
                    stu1.setSex(SexUtils.sexType(stu.getIdCard()));
                    nonCoalPayStudentMapper.insertNonCoalPayStudent(stu1);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、身份证号 " + stu.getIdCard() + " 导入成功");
                    idCardToNameMap.put(stu.getIdCard(), stu.getIdCard());
                }
 
            } catch (Exception e) {
                failureNum++;
                String msg = "<br/>" + failureNum + "、身份证号 " + stu.getIdCard() + " 导入失败:";
                failureMsg.append(msg + e.getMessage());
                log.error(msg, e);
            }
        }
        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
            throw new ServiceException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
        }
        return successMsg.toString();
    }
 
    private NonCoalPayStudent checkData(Long id) {
        NonCoalPayStudent byId = nonCoalPayStudentMapper.selectNonCoalPayStudentById(id);
        if (byId == null) {
            throw new RuntimeException("该数据不存在");
        }
        if (byId.getDelFlag() == 2) {
            throw new RuntimeException("该数据已删除");
        }
        if (byId.getPayStatus() == 1) {
            throw new RuntimeException("该数据已缴费,不可操作");
        }
        return byId;
    }
 
 
    private NonCoalPay checkNonCoalPay(Long nonCoalPayId) {
        NonCoalPay nonCoalPay = nonCoalPayMapper.selectNonCoalPayById(nonCoalPayId);
        if (nonCoalPay == null) {
            throw new ServiceException("该主数据不存在");
        }
        return nonCoalPay;
    }
}