zhongrj
2023-08-23 1d893feaa091ea901dec35a1e2f7bcb1e46cf120
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
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.common.config.MyThreadPoolConfig;
import cn.gistack.sm.feedback.service.IFeedbackService;
import cn.gistack.sm.intelligentCall.vo.CallTaskStatistic;
import cn.gistack.sm.sjztmd.entity.TbAttResBase;
import cn.gistack.sm.sjztmd.mapper.TbAttResBaseMapper;
import cn.gistack.sm.sjztmd.service.ITbAttResBaseService;
import cn.gistack.system.user.feign.IUserClient;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
 
/**
 * @ClassName AttResBaseServiceImpl
 * @Description TODO
 * @author zhongrj
 * @date 2023/8/14
 * @Version 1.0
 */
@Service
@DS("zt")
public class TbAttResBaseServiceImpl extends ServiceImpl<TbAttResBaseMapper, TbAttResBase> implements ITbAttResBaseService {
 
    @Autowired
    private IUserClient userClient;
 
    @Autowired
    private MyThreadPoolConfig myThreadPoolConfig;
 
    /**
     * 查询水库填报详情信息
     * @param guid
     * @return
     */
    @Override
    public TbAttResBase getDetailByGuid(String guid) {
        return baseMapper.getDetailByGuid(guid);
    }
 
    /**
     * 编辑
     * @param tbAttResBase
     * @return
     */
    @Override
    public boolean updateByGuid(TbAttResBase tbAttResBase) {
        // 查询是否存在
        TbAttResBase detail = baseMapper.getDetailByGuid(tbAttResBase.getGuid());
        // 更新审核日志
        setUpdateLog(detail,tbAttResBase);
        // 修改
        int i = addOrUpdateByGuid(tbAttResBase);
        if (i>0){
            return true;
        }
        return false;
    }
 
    /**
     * 审核
     * @param tbAttResBase
     * @return
     */
    @Override
    public boolean auditByGuid(TbAttResBase tbAttResBase) {
        // 查询是否存在
        TbAttResBase detail = baseMapper.getDetailByGuid(tbAttResBase.getGuid());
        // 更新操作日志
        setUpdateLog(detail,tbAttResBase);
        // 更新审核日志
        setUpdateCheckLog(detail,tbAttResBase);
        if (null!=detail){
            tbAttResBase.setGuid(detail.getGuid());
        }
        // 驳回情况下将状态修改回0即已填写未提交状态
        if (tbAttResBase.getCheckState()==3){
            tbAttResBase.setCheckState(0);
        }
        // 更新数据
        int i = baseMapper.updateById(tbAttResBase);
        if (i>0){
            return true;
        }
        return false;
    }
 
    /**
     * 更新
     * @param tbAttResBase
     * @return
     */
    private int addOrUpdateByGuid(TbAttResBase tbAttResBase){
        int i = 0;
        if (null!=tbAttResBase.getGuid()){
            // 更新
            i = baseMapper.updateById(tbAttResBase);
        }else {
            tbAttResBase.setCreateTime(new Date());
            i = baseMapper.insert(tbAttResBase);
        }
        // 返回
        return i;
    }
 
    /**
     * @param oldAbAttResBase
     * @param newTbAttResBase
     * 更新审核记录
     */
    private void setUpdateCheckLog(TbAttResBase oldAbAttResBase,TbAttResBase newTbAttResBase) {
        String fillName = "";
        if (newTbAttResBase.getCheckState()==2){
            fillName = "审核";
        }
        if (newTbAttResBase.getCheckState()==3){
            fillName = "退回" + (null==newTbAttResBase.getCheckLog()?"":":" + newTbAttResBase.getCheckLog());
        }
 
        // 拼接
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
        String userName = AuthUtil.getUser().getUserName();
        String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
        StringBuilder builder = new StringBuilder();
        builder.append(time)
            .append(",")
            .append(fillName)
            .append(",")
            .append(userName)
            .append(",")
            .append(phone)
            .append(";");
        // 判断是否存在
        if (null==oldAbAttResBase){
            // 填报
            newTbAttResBase.setCheckLog(builder.toString());
        }else {
            StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getCheckLog()?"":oldAbAttResBase.getCheckLog());
            stringBuilder.append(builder);
            // 填报
            newTbAttResBase.setCheckLog(stringBuilder.toString());
        }
    }
 
    /**
     * @param oldAbAttResBase
     * @param newTbAttResBase
     * 更新操作记录
     */
    private void setUpdateLog(TbAttResBase oldAbAttResBase,TbAttResBase newTbAttResBase) {
        String fillName = "";
        if (newTbAttResBase.getCheckState()==0){
            fillName = "编辑";
        }
        if (newTbAttResBase.getCheckState()==1){
            fillName = "提交";
        }
        if (newTbAttResBase.getCheckState()==2){
            fillName = "审核";
        }
        if (newTbAttResBase.getCheckState()==3){
            fillName = "退回" + (null==newTbAttResBase.getCheckLog()?"":":" + newTbAttResBase.getCheckLog());
        }
        // 管理员编辑
        if (newTbAttResBase.getCheckState()==4){
            fillName = "编辑";
            newTbAttResBase.setCheckState(oldAbAttResBase.getCheckState());
        }
 
        // 拼接
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
        String userName = AuthUtil.getUser().getUserName();
        String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
        StringBuilder builder = new StringBuilder();
        builder.append(time)
            .append(",")
            .append(fillName)
            .append(",")
            .append(userName)
            .append(",")
            .append(phone)
            .append(";");
        // 判断是否存在
        if (null==oldAbAttResBase){
            // 填报
            newTbAttResBase.setLog(builder.toString());
        }else {
            StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getLog()?"":oldAbAttResBase.getLog());
            stringBuilder.append(builder);
            // 填报
            newTbAttResBase.setLog(stringBuilder.toString());
        }
    }
 
    /**
     * 查询所有水库填报的状态信息
     * @param resGuid
     * @return
     */
    @Override
    public List<Map<String, Object>> getAllWaterFillInfoByResGuid(String resGuid) {
        List<Map<String, Object>> list = new ArrayList<>();
        ThreadPoolExecutor executor = myThreadPoolConfig.threadPoolExecutor();
        // 查询水库基础填报数据
        CompletableFuture<List<Map<String,Object>>> tbAttResBaseInfo = getTbAttResBaseInfo("tb_att_res_base",resGuid, executor);
        // 查询水库其他填报数据
        CompletableFuture<List<Map<String,Object>>> tbAttResBuildInfo = getTbInfo("tb_att_res_build_info",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResEngBene = getTbInfo("tb_att_res_eng_bene",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResInfomationProject = getTbInfo("tb_att_res_infomation_project",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResMgrSysB = getTbInfo("tb_att_res_mgr_sys_b",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResPowerStation = getTbInfo("tb_att_res_power_station",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResProjectUtilize = getTbInfo("tb_att_res_project_utilize",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResRsbNorspi = getTbInfo("tb_att_res_rsb_norspi",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResRsbSpillway = getTbInfo("tb_att_res_rsb_spillway",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResRsbVerspi = getTbInfo("tb_att_res_rsb_verspi",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResSafetyMonitor = getTbInfo("tb_att_res_safety_monitor",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResStagChar = getTbInfo("tb_att_res_stag_char",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResWaterBlock = getTbInfo("tb_att_res_water_block",resGuid,executor);
        CompletableFuture<List<Map<String,Object>>> tbAttResWaterDelivery = getTbInfo("tb_att_res_water_delivery",resGuid,executor);
        //等待所有任务执行完成
        try {
            CompletableFuture.allOf(
                tbAttResBaseInfo,
                tbAttResBuildInfo,
                tbAttResEngBene,
                tbAttResInfomationProject,
                tbAttResMgrSysB,
                tbAttResPowerStation,
                tbAttResProjectUtilize,
                tbAttResRsbNorspi,
                tbAttResRsbSpillway,
                tbAttResRsbVerspi,
                tbAttResSafetyMonitor,
                tbAttResStagChar,
                tbAttResWaterBlock,
                tbAttResWaterDelivery).get();
            // 数据处理
            list.addAll(tbAttResBaseInfo.get());
            list.addAll(tbAttResBuildInfo.get());
            list.addAll(tbAttResEngBene.get());
            list.addAll(tbAttResInfomationProject.get());
            list.addAll(tbAttResMgrSysB.get());
            list.addAll(tbAttResPowerStation.get());
            list.addAll(tbAttResProjectUtilize.get());
            list.addAll(tbAttResRsbNorspi.get());
            list.addAll(tbAttResRsbSpillway.get());
            list.addAll(tbAttResRsbVerspi.get());
            list.addAll(tbAttResSafetyMonitor.get());
            list.addAll(tbAttResStagChar.get());
            list.addAll(tbAttResWaterBlock.get());
            list.addAll(tbAttResWaterDelivery.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        // 返回
        return list;
    }
 
    /**
     * 查询水库基础填报数据
     * @param tableName
     * @param resGuid
     * @param executor
     * @return
     */
    private CompletableFuture<List<Map<String,Object>>> getTbAttResBaseInfo(String tableName,String resGuid,ThreadPoolExecutor executor){
        return CompletableFuture.supplyAsync(()->{
            // 查询所有水库填报的状态信息
            return baseMapper.getTbAttResBaseInfo(resGuid,tableName);
        },executor);
    }
 
    /**
     * 查询水库其他填报数据
     * @param tableName
     * @param resGuid
     * @param executor
     * @return
     */
    private CompletableFuture<List<Map<String,Object>>> getTbInfo(String tableName,String resGuid,ThreadPoolExecutor executor){
        return CompletableFuture.supplyAsync(()->{
            // 查询所有水库填报的状态信息
            List<Map<String, Object>> tbInfo = baseMapper.getTbInfo(resGuid,"\'"+tableName+"'" ,"\""+tableName+"\"");
            if (tbInfo.size()==0){
                Map<String, Object> map = new HashMap<>(2);
                map.put("NAME",tableName);
                map.put("VALUE",-1);
                tbInfo.add(map);
            }
            return tbInfo;
        },executor);
    }
}