songhuangfeng123
2022-08-02 aace11a7e1201a8d1fc0b50b659368918d23e794
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
package com.gkhy.safePlatform.equipment.controller;
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.equipment.entity.*;
import com.gkhy.safePlatform.equipment.model.dto.req.EquipmentInfoImportExcel;
import com.gkhy.safePlatform.equipment.model.dto.req.EquipmentInfoSaveOrUpdate;
import com.gkhy.safePlatform.equipment.model.dto.resp.EquipmentInfoExcel;
import com.gkhy.safePlatform.equipment.utils.DateUtils;
import com.gkhy.safePlatform.equipment.utils.poihelper.ExcelLogs;
import com.gkhy.safePlatform.equipment.utils.poihelper.ExcelUtil;
import com.google.common.collect.Lists;
 
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.Timestamp;
 
 
import com.gkhy.safePlatform.equipment.model.dto.resp.EquipmentInfoDto;
import com.gkhy.safePlatform.equipment.service.EquipmentInfoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.PageUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.equipment.model.dto.req.EquipmentInfoQueryCriteria;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
 
/**
 * 设备设施详细信息(EquipmentInfo)表控制层
 *
 * @author xurui
 * @since 2022-07-19 14:02:50
 */
@RestController
@RequestMapping("equipmentInfo")
public class EquipmentInfoController {
    /**
     * 服务对象
     */
    @Resource
    private EquipmentInfoService equipmentInfoService;
 
    @Autowired
    public HttpServletRequest request;
 
    @Autowired
    public HttpServletResponse response;
 
    /**
     * 分页查询所有数据
     *
     * @param pageQuery 查询实体
     * @return 所有数据
     */
    @PostMapping(value = "/page/list")
    public ResultVO selectAll(@RequestBody PageQuery<EquipmentInfoQueryCriteria> pageQuery){
        if(pageQuery.getSearchParams().getInfoType() == null){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少infoType");
        }
 
        PageUtils.checkCheck(pageQuery);
        return this.equipmentInfoService.queryAll(pageQuery);
    }
 
 
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping(value = "/selectOne/{id}")
    public ResultVO selectOne(@PathVariable Serializable id) {
        return new ResultVO<>(ResultCodes.OK,this.equipmentInfoService.selectOne(id));
    }
 
    /**
     * 新增或者修改数据
     *
     * @param infoDto 实体对象
     * @return 修改结果
     */
    @PostMapping(value = "/addOrUpdate")
    public ResultVO update(@RequestBody EquipmentInfoSaveOrUpdate infoDto) {
        if(infoDto.getInfoType() == null || infoDto.getEquipmentTypeId() == null){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少infoType或者equipmentTypeId");
        }
        if(infoDto.getInfoType() == 3){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"infoType值异常");
        }
 
        equipmentInfoService.addOrUpdate(infoDto);
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @GetMapping(value = "/delete")
    public ResultVO delete(String ids) {
    List<String> idList = Arrays.stream(ids.split(","))
                .collect(Collectors.toList());
        this.equipmentInfoService.removeByIds(idList);
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * 统计
     *
     * @return 删除结果
     */
    @GetMapping(value = "/statistics")
    public ResultVO statistics() {
 
        return new ResultVO<>(ResultCodes.OK,this.equipmentInfoService.statistics());
    }
 
 
 
 
    /**
     * 下载模板
     *
     */
    @GetMapping(value = "/exportTemplate")
    public void exportTemplate() throws IOException {
        Map<String,String> map = new LinkedHashMap<>();
        map.put("1", "类型/类别外键");
        map.put("2", "具体类型(页面左侧的导航栏使用) 0:仪器仪表信息 1:生产设备设施 2:安全设备设施 ");
        map.put("3", "名称");
        map.put("4", "位号");
        map.put("5", "用途");
        map.put("6", "型号");
        map.put("7", "单位部门外键");
        map.put("8", "设置部位");
        map.put("9", "生产日期(yyyy-MM-dd HH:mm:ss)");
        map.put("10", "使用期限(天)");
        map.put("11", "生命周期 1:已使用 2:库存中 3:报废");
        map.put("12", "投用日期(yyyy-MM-dd HH:mm:ss)");
        map.put("13", "维修状态 1:维修中 2:已修好");
        map.put("14", "停用状态 1:停用 2.在用 3.维修 4.报废");
        map.put("15", "上次检查日期(yyyy-MM-dd HH:mm:ss)");
        map.put("16", "上次检测日期(yyyy-MM-dd HH:mm:ss)");
        map.put("17", "上次保养日期(yyyy-MM-dd HH:mm:ss)");
        map.put("18", "下次检查日期(yyyy-MM-dd HH:mm:ss)");
        map.put("19", "下次检测日期(yyyy-MM-dd HH:mm:ss)");
        map.put("20", "下次保养日期(yyyy-MM-dd HH:mm:ss)");
        map.put("21", "负责人ID外键");
        map.put("22", "负责人部门外键");
        map.put("23", "供应商");
        map.put("24", "使用说明");
        map.put("25", "是否检查 1:是 2:否");
        map.put("26", "检查周期");
        map.put("27", "检查提前提醒");
        map.put("28", "是否检测 1:是 2:否");
        map.put("29", "检测周期");
        map.put("30", "检测提前提醒");
        map.put("31", "是否保养 1:是 2:否");
        map.put("32", "检查内容");
        map.put("33", "负责部门/外键");
        map.put("34", "检查指标");
        map.put("35", "预警值");
        map.put("36", "联锁值");
        map.put("37", "停用理由");
        map.put("38", "停用后措施");
        map.put("39", "实际停用日期(yyyy-MM-dd HH:mm:ss)");
        map.put("40", "停用提交人/外键");
        map.put("41", "停用提交日期(yyyy-MM-dd HH:mm:ss)");
        map.put("42", "恢复理由");
        map.put("43", "恢复填报日期(yyyy-MM-dd HH:mm:ss)");
        map.put("44", "实际恢复日期(yyyy-MM-dd HH:mm:ss)");
        map.put("45", "报废理由");
        map.put("46", "报废填报日期(yyyy-MM-dd HH:mm:ss)");
        map.put("47", "实际报废日期(yyyy-MM-dd HH:mm:ss)");
        String fileName = URLEncoder.encode("设备设施管理数据导入模板.xls", "UTF-8");
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
 
        ExcelUtil.exportExcel(map,new ArrayList<>() , response.getOutputStream());
        response.getOutputStream().close();
    }
 
 
    /**
     * 导入数据
     *
     */
    @RequestMapping(value = "/importData")
    public ResultVO importData(MultipartFile file) throws IOException {
        String contentType = file.getContentType();
        if(!"application/vnd.ms-excel".equals(contentType)
                && !"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) {
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL, "上传的excel格式错误");
        }
 
        Collection<EquipmentInfoImportExcel> importExcel = ExcelUtil.importExcel(EquipmentInfoImportExcel.class, file.getInputStream(), "yyyy-MM-dd HH:mm:ss", new ExcelLogs() , 0);
 
        if (CollectionUtils.isEmpty(importExcel)) {
            return new ResultVO<>(ResultCodes.OK);
        }
 
        List<EquipmentInfo> respList = BeanCopyUtils.copyBeanList((List<EquipmentInfoImportExcel>)importExcel, EquipmentInfo.class);
 
        equipmentInfoService.saveBatch(respList);
        return new ResultVO<>(ResultCodes.OK);
    }
 
 
 
 
    /**
     * 导出一览数据
     *
     */
    @GetMapping(value = "/exportData")
    public void exportData(EquipmentInfoQueryCriteria queryCriteria) throws IOException {
        Map<String,String> map = new LinkedHashMap<>();
        map.put("0", "ID");
        map.put("1", "类型/类别外键");
        map.put("2", "具体类型(页面左侧的导航栏使用) 0:仪器仪表信息 1:生产设备设施 2:安全设备设施 ");
        map.put("3", "名称");
        map.put("4", "位号");
        map.put("5", "用途");
        map.put("6", "型号");
        map.put("7", "单位部门外键");
        map.put("8", "设置部位");
        map.put("9", "生产日期(yyyy-MM-dd HH:mm:ss)");
        map.put("10", "使用期限(天)");
        map.put("11", "生命周期 1:已使用 2:库存中 3:报废");
        map.put("12", "投用日期(yyyy-MM-dd HH:mm:ss)");
        map.put("13", "维修状态 1:维修中 2:已修好");
        map.put("14", "停用状态 1:停用 2.在用 3.维修 4.报废");
        map.put("15", "上次检查日期(yyyy-MM-dd HH:mm:ss)");
        map.put("16", "上次检测日期(yyyy-MM-dd HH:mm:ss)");
        map.put("17", "上次保养日期(yyyy-MM-dd HH:mm:ss)");
        map.put("18", "下次检查日期(yyyy-MM-dd HH:mm:ss)");
        map.put("19", "下次检测日期(yyyy-MM-dd HH:mm:ss)");
        map.put("20", "下次保养日期(yyyy-MM-dd HH:mm:ss)");
        map.put("21", "负责人ID外键");
        map.put("22", "负责人部门外键");
        map.put("23", "供应商");
        map.put("24", "使用说明");
        map.put("25", "是否检查 1:是 2:否");
        map.put("26", "检查周期");
        map.put("27", "检查提前提醒");
        map.put("28", "是否检测 1:是 2:否");
        map.put("29", "检测周期");
        map.put("30", "检测提前提醒");
        map.put("31", "是否保养 1:是 2:否");
        map.put("32", "检查内容");
        map.put("33", "负责部门/外键");
        map.put("34", "检查指标");
        map.put("35", "预警值");
        map.put("36", "联锁值");
        map.put("37", "停用理由");
        map.put("38", "停用后措施");
        map.put("39", "实际停用日期(yyyy-MM-dd HH:mm:ss)");
        map.put("40", "停用提交人/外键");
        map.put("41", "停用提交日期(yyyy-MM-dd HH:mm:ss)");
        map.put("42", "恢复理由");
        map.put("43", "恢复填报日期(yyyy-MM-dd HH:mm:ss)");
        map.put("44", "实际恢复日期(yyyy-MM-dd HH:mm:ss)");
        map.put("45", "报废理由");
        map.put("46", "报废填报日期(yyyy-MM-dd HH:mm:ss)");
        map.put("47", "实际报废日期(yyyy-MM-dd HH:mm:ss)");
 
        String key = DateUtils.date2String(new Date(), DateUtils.PATTERN_ALLTIME_NOSIGN) ;
        String fileName = URLEncoder.encode("设备设施管理"+key+".xls", "UTF-8");
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
 
 
        List<EquipmentInfoExcel> respList = BeanCopyUtils.copyBeanList(equipmentInfoService.queryAll(queryCriteria), EquipmentInfoExcel.class);
 
        ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD);
        response.getOutputStream().close();
    }
 
 
 
 
    public static void main(String[] args) {
        EquipmentInfoDto infoDto = new EquipmentInfoDto();
        List<EquipmentRepairDetail> repairDetails = Lists.newArrayList();
        EquipmentRepairDetail repairDetail = new EquipmentRepairDetail();
        repairDetail.setInfoTpe(0);
        repairDetail.setRepairPersonId(0L);
        repairDetail.setRepairStartDate(new Timestamp(new java.util.Date().getTime()));
        repairDetail.setRepairEndDate(new Timestamp(new java.util.Date().getTime()));
        repairDetail.setRepairPersonDepartmentId(0L);
        repairDetail.setRepairMemo("");
        repairDetail.setRepairStatus(0);
        repairDetail.setExceptionInfo("");
        repairDetails.add(repairDetail);
        infoDto.setRepaireDetailList(repairDetails);
 
        //
        infoDto.setCheckDetailList(new ArrayList());
 
        //
        List<EquipmentTestDetail> testDetails = Lists.newArrayList();
        EquipmentTestDetail equipmentTestDetail = new EquipmentTestDetail();
        equipmentTestDetail.setTestPersonId(0L);
        equipmentTestDetail.setTestDate(new Timestamp(new java.util.Date().getTime()));
        equipmentTestDetail.setTestPersonDepartmentId(0L);
        equipmentTestDetail.setTestMemo("");
        equipmentTestDetail.setTestResult(0);
        equipmentTestDetail.setTestStatus("");
        testDetails.add(equipmentTestDetail);
        infoDto.setTestDetailList(testDetails);
 
        List<EquipmentTakecareDetail> takecareDetails = Lists.newArrayList();
        EquipmentTakecareDetail takecareDetail = new EquipmentTakecareDetail();
        takecareDetail.setEquipmentId(0L);
        takecareDetail.setTakecareMemo("");
        takecareDetail.setLeadingPersonId(0L);
        takecareDetail.setTakecareDate(new Timestamp(new java.util.Date().getTime()));
        takecareDetail.setLeadingPersonDepartmentId(0L);
        takecareDetails.add(takecareDetail);
        infoDto.setTakecareDetailList(takecareDetails);
 
        List<EquipmentTakecareStardardDetail> takecareStardardDetails = Lists.newArrayList();
        EquipmentTakecareStardardDetail takecareStardardDetail = new EquipmentTakecareStardardDetail();
        takecareStardardDetail.setFilePath("123");
        takecareStardardDetails.add(takecareStardardDetail);
        infoDto.setTakecareStardardeDetailList(takecareStardardDetails);
 
 
        List<EquipmentCheckStandardDetail> theckStandardeDetails = Lists.newArrayList();
        EquipmentCheckStandardDetail theckStandardeDetail = new EquipmentCheckStandardDetail();
        theckStandardeDetail.setIndexNum("1");
        theckStandardeDetail.setCheckContent("2");
        theckStandardeDetail.setCheckTarget("3");
        theckStandardeDetail.setUnit("4");
        theckStandardeDetail.setCheckPart("5");
        theckStandardeDetail.setRate("6");
        theckStandardeDetails.add(theckStandardeDetail);
        infoDto.setCheckStandardeDetailList(theckStandardeDetails);
 
 
 
 
        infoDto.setEquipmentTypeId(0L);
        infoDto.setInfoType(0);
        infoDto.setqName("");
        infoDto.setPositionNum("");
        infoDto.setqUsage("");
        infoDto.setModel("");
        infoDto.setDepartmentId(0L);
        infoDto.setSetPart("");
        infoDto.setProduceTime(new Timestamp(new java.util.Date().getTime()));
        infoDto.setUseEndDay("");
        infoDto.setLifeCycle(0);
        infoDto.setUseDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setRepairStatus(0);
        infoDto.setStopStatus(0);
        infoDto.setPreviousCheckDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setPreviousTestDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setPreviousTakecareDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setNextCheckDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setNextTestDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setNextTakecareDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setLeadingPersonId(0L);
        infoDto.setLeadingPersonDepartmentId(0L);
        infoDto.setSupplyName("");
        infoDto.setUseMemo("");
        infoDto.setIsNeedCheck(0);
        infoDto.setCheckCycle("");
        infoDto.setCheckWarn("");
        infoDto.setIsNeedTest(0);
        infoDto.setTestCycle("");
        infoDto.setTestWarn("");
        infoDto.setIsNeedTakecare(0);
        infoDto.setCheckContent("");
        infoDto.setLeadingDepartmentId(0L);
        infoDto.setCheckPoint("");
        infoDto.setAlertNum("");
        infoDto.setLockNum("");
        infoDto.setStopReason("");
        infoDto.setAfterStopStep("");
        infoDto.setActualStopDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setStopSubmitPersonId(0L);
        infoDto.setStopSubmitDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setRecoveryReason("");
        infoDto.setRecoverySubmitDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setActualRecoveryDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setDestoryReason("");
        infoDto.setDestorySubmitDate(new Timestamp(new java.util.Date().getTime()));
        infoDto.setActualDestoryDate(new Timestamp(new java.util.Date().getTime()));
        System.out.println(JSONObject.toJSONString(infoDto));
 
 
    }
}