“djh”
2025-09-23 f7a6a108af93eb225299e771f9958eae36f776bf
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
package com.gkhy.exam.system.service.impl;
 
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.MonthlyInspection;
import com.gkhy.exam.system.domain.MonthlyInspectionMess;
import com.gkhy.exam.system.mapper.MonthlyInspectionMapper;
import com.gkhy.exam.system.mapper.MonthlyInspectionMessMapper;
import com.gkhy.exam.system.service.MonthlyInspectionService;
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 MonthlyInspectionServiceImpl extends ServiceImpl<MonthlyInspectionMapper, MonthlyInspection> implements MonthlyInspectionService {
 
    @Autowired
    private MonthlyInspectionMapper monthlyInspectionMapper;
 
    @Autowired
    private MonthlyInspectionMessMapper monthlyInspectionMessMapper;
 
 
    @Override
    public CommonPage selectMonthlyInspectionList(MonthlyInspection monthlyInspection) {
        if (!SecurityUtils.adminUser()){
            if (monthlyInspection.getCompanyId()==null){
                throw new ApiException("非管理员操作,查询条件不可为空");
            }
        }
        PageUtils.startPage();
        List<MonthlyInspection> monthlyInspections = monthlyInspectionMapper.selectInspectionList(monthlyInspection);
        for (MonthlyInspection inspection : monthlyInspections) {
            List<MonthlyInspectionMess> monthlyInspectionMesses = monthlyInspectionMessMapper.selectByMonthlyId(inspection.getId());
            inspection.setInspectionMesses(monthlyInspectionMesses);
        }
        return CommonPage.restPage(monthlyInspections);
    }
 
    @Override
    @Transactional
    public CommonResult insertMonthlyInspection(MonthlyInspection monthlyInspection) {
        monthlyInspection.setCreateBy(SecurityUtils.getUsername());
        monthlyInspection.setCreateTime(LocalDateTime.now());
        int insert = monthlyInspectionMapper.insert(monthlyInspection);
        if (insert>0){
            List<MonthlyInspectionMess> inspectionMesses = monthlyInspection.getInspectionMesses();
            for (MonthlyInspectionMess inspectionMess : inspectionMesses) {
                inspectionMess.setMonthlyId(monthlyInspection.getId());
            }
            monthlyInspectionMessMapper.insertMonthlys(inspectionMesses);
        }
        return CommonResult.success();
    }
 
    @Override
    @Transactional
    public CommonResult updateMonthlyInspection(MonthlyInspection monthlyInspection) {
        monthlyInspection.setUpdateBy(SecurityUtils.getUsername());
        monthlyInspection.setUpdateTime(LocalDateTime.now());
        int i = monthlyInspectionMapper.updateById(monthlyInspection);
        if (i>0){
            List<MonthlyInspectionMess> inspectionMesses = monthlyInspection.getInspectionMesses();
            monthlyInspectionMessMapper.deleteByMonthlyId(monthlyInspection.getId());
            monthlyInspectionMessMapper.insertMonthlys(inspectionMesses);
        }
        return CommonResult.success();
    }
 
    @Override
    public CommonResult deletedMonthlyInspection(Integer monthlyId) {
        MonthlyInspection monthlyInspection = new MonthlyInspection();
        monthlyInspection.setId(monthlyId);
        monthlyInspection.setUpdateBy(SecurityUtils.getUsername());
        monthlyInspection.setUpdateTime(LocalDateTime.now());
        monthlyInspection.setDelFlag(2);
        int i = monthlyInspectionMapper.updateById(monthlyInspection);
        if (i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}