郑永安
2023-08-23 0a9ed7b7488de66a50799f79369d7806910ae00a
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
package com.gk.hotwork.Service.ServiceImpl;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.CompanyInfo;
import com.gk.hotwork.Domain.SafetyFacilityInspection;
import com.gk.hotwork.Domain.SafetyFacilityProcessflow;
import com.gk.hotwork.Domain.SafetyInspectionItemDeduction;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Mapper.CompanyInfoMapper;
import com.gk.hotwork.Mapper.SafetyFacilityInspectionMapper;
import com.gk.hotwork.Mapper.SafetyFacilityProcessflowMapper;
import com.gk.hotwork.Mapper.UserInfoMapper;
import com.gk.hotwork.Service.SafetyFacilityInspectionService;
 
@Service("SafetyFacilityInspectionService")
@Transactional
public class SafetyFacilityInspectionImpl extends ServiceImpl<SafetyFacilityInspectionMapper, SafetyFacilityInspection>
        implements SafetyFacilityInspectionService {
 
    @Autowired
    private SafetyFacilityInspectionMapper safetyFacilityInspectionMapper;
 
    @Autowired
    private SafetyFacilityProcessflowMapper safetyFacilityProcessflowMapper;
 
    @Autowired
    private UserInfoMapper userInfoMapper;
 
    @Autowired
    private CompanyInfoMapper companyInfoMapper;
 
    @Override
    public IPage<SafetyFacilityInspection> selectPage(Page<SafetyFacilityInspection> page, Map<String, Object> filter,
            UserInfo user) {
        Date date = new Date();
 
        if (user.getType() == 3 ) {
            filter.put("createBy", user.getUsername());
        }
        if (user.getType() == 4) {
            filter.put("expert", user.getId());
        }
        if (user.getType() == 2) {
            QueryWrapper<CompanyInfo> queryWrapper = new QueryWrapper<CompanyInfo>();
            queryWrapper.eq("city", user.getCity());
            queryWrapper.eq("province", user.getProvince());
            List<CompanyInfo> list = companyInfoMapper.selectList(queryWrapper);
            List<String> companyList = new ArrayList<String>();
            for (CompanyInfo companyInfo : list) {
                companyList.add(companyInfo.getCompany());
            }
            filter.put("company", companyList);
        }
        if("安科院".equals(user.getCompany())){
            filter.remove("createBy");
            filter.remove("company");
        }
 
        IPage<SafetyFacilityInspection> res = safetyFacilityInspectionMapper.selectPages(page, filter);
        List<SafetyFacilityInspection> list = new ArrayList<SafetyFacilityInspection>();
        for (SafetyFacilityInspection safetyFacilityInspection : res.getRecords()) {
            if (safetyFacilityInspection.getProgress() == 10 && safetyFacilityInspection.getReviewTime() != null && safetyFacilityInspection.getReviewTime().before(date)) {
                safetyFacilityInspection.setProgress(11);
                this.updateById(safetyFacilityInspection);
                SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
                flow.setCheckTime(new Date());
                flow.setValidFlag(Byte.valueOf("1"));
                flow.setCreateBy("SYSTEM");
                flow.setUpdateTime(date);
                flow.setCreateTime(date);
                flow.setProgressName("评审中");
                flow.setResult("预置时间到");
                flow.setLinkInspectionId(safetyFacilityInspection.getId());
                flow.setProcessBy(user.getRealname());
                safetyFacilityProcessflowMapper.insert(flow);
                safetyFacilityProcessflowMapper.modPending(safetyFacilityInspection.getId());
            }
 
            if (safetyFacilityInspection.getProgress() == 20 && safetyFacilityInspection.getExamineTime() != null && safetyFacilityInspection.getExamineTime().before(date)) {
                safetyFacilityInspection.setProgress(21);
                this.updateById(safetyFacilityInspection);
                SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
                flow.setCheckTime(new Date());
                flow.setValidFlag(Byte.valueOf("1"));
                flow.setCreateBy("SYSTEM");
                flow.setUpdateTime(date);
                flow.setCreateTime(date);
                flow.setProgressName("审查中");
                flow.setResult("预置时间到");
                flow.setLinkInspectionId(safetyFacilityInspection.getId());
                flow.setProcessBy(user.getRealname());
                safetyFacilityProcessflowMapper.insert(flow);
                safetyFacilityProcessflowMapper.modPending(safetyFacilityInspection.getId());
            }
 
            if (safetyFacilityInspection.getExpert() != null) {
                String[] expertIds = safetyFacilityInspection.getExpert().split(",");
                String expertName = "";
                List<UserInfo> temp = userInfoMapper.selectBatchIds(Arrays.asList(expertIds));
                for (UserInfo userInfo : temp) {
                    expertName += "," + userInfo.getRealname();
                }
                safetyFacilityInspection.setExpertName(expertName.substring(1));
            }
            list.add(safetyFacilityInspection);
        }
        res.setRecords(list);
        return res;
 
    }
 
    @Override
    public void addOne(SafetyFacilityInspection param, UserInfo user) {
        Date date = new Date();
        String username = user.getUsername();
        param.setValidFlag(Byte.valueOf("1"));
        param.setCreateBy(username);
        param.setUpdateTime(date);
        param.setCreateTime(date);
        param.setSubmitDate(param.getSubmitDate() == null ? date : param.getSubmitDate());
        param.setProgress(Integer.valueOf(0));
        param.setCompany(param.getCompany() == null ? user.getCompany() : param.getCompany());
        this.save(param);
    }
 
    @Override
    public void modOne(SafetyFacilityInspection param, UserInfo user) {
        param.setUpdateTime(new Date());
        this.updateById(param);
    }
 
    @Override
    public void delOne(Long id, UserInfo user) {
        SafetyFacilityInspection object = safetyFacilityInspectionMapper.selectByPrimaryKey(id);
        object.setValidFlag(Byte.valueOf("0"));
        object.setUpdateTime(new Date());
        this.updateById(object);
 
    }
 
    @Override
    public SafetyFacilityInspection selectByPrimaryKey(Long id, UserInfo user) {
        return safetyFacilityInspectionMapper.selectByPrimaryKey(id);
    }
}