yangkang
2023-09-13 51ebb09a85d622cae75dc169b4c86723977d3756
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
package org.jeecg.modules.eam.controller;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.entity.SysUpload;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.model.DepartVo;
import org.jeecg.modules.eam.service.*;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
 
import org.jeecg.common.system.base.controller.JeecgController;
 
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
 
 /**
 * @Description: mom_eam_equipment
 * @Author: jeecg-boot
 * @Date:   2023-03-23
 * @Version: V1.0
 */
@Api(tags="mom_eam_equipment")
@RestController
@RequestMapping("/eam/equipment")
@Slf4j
public class EamEquipmentController extends JeecgController<Equipment, IEamEquipmentService> {
    @Autowired
    private IEamEquipmentService equipmentService;
 
    @Autowired
    private IPrecisionParametersTemplateDetailService precisionParametersTemplateDetailService;
 
    @Autowired
    private IProcessParametersTemplateDetailService processParametersTemplateDetailService;
 
     @Autowired
    private IEquipmentProcessParametersService equipmentProcessParametersService;
 
     @Autowired
    private IEquipmentPrecisionParametersService equipmentPrecisionParametersService;
 
     @Autowired
     private IPrecisionParametersTemplateService precisionParametersTemplateService;
 
     @Autowired
     private IProcessParametersTemplateService processParametersTemplateService;
 
 
 
     @Autowired
     private ISysBaseAPI sysBaseApi;
 
     @Autowired
     @Lazy
     private IEquipmentSealDetailService equipmentSealDetailService;
 
     @Autowired
     @Lazy
     private IInspectionOrderDetailService inspectionOrderDetailService;
 
     @Autowired
     @Lazy
     private ISpecialtyInspectionOrderDetailService specialtyInspectionOrderDetailService;
 
     @Autowired
     private ICalibrationOrderDetailService calibrationOrderDetailService;
 
     @Autowired
     private ICalibrationOrderReportService calibrationOrderReportService;
 
     @Autowired
     private IEquipmentCategoryService equipmentCategoryService;
    /**
     * 分页列表查询
     *
     * @param equipment
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "mom_eam_equipment-分页列表查询")
    @ApiOperation(value="mom_eam_equipment-分页列表查询", notes="mom_eam_equipment-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<Equipment>> queryPageList(Equipment equipment,
                                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                  HttpServletRequest req) {
        //QueryWrapper<Equipment> queryWrapper = QueryGenerator.initQueryWrapper(equipment, req.getParameterMap());
        QueryWrapper<Equipment> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(equipment.getNum())){
            queryWrapper.like("num",equipment.getNum());
        }
        if(StringUtils.isNotBlank(equipment.getName())){
            queryWrapper.like("name",equipment.getName());
        }
        if(StringUtils.isNotBlank(equipment.getEquipmentStatus())){
            queryWrapper.eq("equipment_status",equipment.getEquipmentStatus());
        }
        if(StringUtils.isNotBlank(equipment.getTechnologyStatus())){
            queryWrapper.eq("technology_status",equipment.getTechnologyStatus());
        }
        if(StringUtils.isNotBlank(equipment.getEquipmentCategoryId())){
            queryWrapper.eq("equipment_category_id",equipment.getEquipmentCategoryId());
        }
 
        queryWrapper.eq("status","1");
        queryWrapper.eq("del_flag",0);
        queryWrapper.orderByDesc("create_time");
 
        Page<Equipment> page = new Page<Equipment>(pageNo, pageSize);
        IPage<Equipment> pageList = equipmentService.page(page, queryWrapper);
        List<Equipment> equipmentList = pageList.getRecords();
        for (Equipment eq : equipmentList) {
            String precisionParametersTemplateId = eq.getPrecisionParametersTemplateId();
            if(StringUtils.isNotBlank(precisionParametersTemplateId)){
                PrecisionParametersTemplate precisionParametersTemplate = precisionParametersTemplateService.getById(precisionParametersTemplateId);
                if(precisionParametersTemplate != null){
                    eq.setPrecisionParametersTemplateName(precisionParametersTemplate.getName());
                }else{
                    eq.setPrecisionParametersTemplateName("");
                }
            }else{
                eq.setPrecisionParametersTemplateName("");
            }
 
            String processParametersTemplateId = eq.getProcessParametersTemplateId();
            if(StringUtils.isNotBlank(processParametersTemplateId)){
                ProcessParametersTemplate processParametersTemplate = processParametersTemplateService.getById(processParametersTemplateId);
                if(processParametersTemplate != null){
                    eq.setProcessParametersTemplateName(processParametersTemplate.getName());
                }else{
                    eq.setProcessParametersTemplateName("");
                }
            }else{
                eq.setProcessParametersTemplateName("");
            }
            //查询封存原因和封存日期
            List<EquipmentSealDetail> equipmentSealDetailList = equipmentSealDetailService.lambdaQuery().eq(EquipmentSealDetail::getEquipmentId,eq.getId())
                    .eq(EquipmentSealDetail::getDelFlag, CommonConstant.DEL_FLAG_0).orderByDesc(EquipmentSealDetail::getCreateTime).list();
            if(CollectionUtils.isNotEmpty(equipmentSealDetailList)){
                eq.setSealReason(equipmentSealDetailList.get(0).getSealReason());
                eq.setSealDate(equipmentSealDetailList.get(0).getSealDate());
            }
        }
        return Result.OK(pageList);
    }
 
 
     /**
      * 设备保修  获取设备列表组件
      * qsw 2023-7-14
      */
     @GetMapping(value = "/getEquipmentList")
     public Result<IPage<Equipment>> getEquipmentList(Equipment equipment,
                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                   HttpServletRequest req) {
         QueryWrapper<Equipment> queryWrapper = QueryGenerator.initQueryWrapper(equipment, req.getParameterMap());
         queryWrapper.eq("status","1");
         queryWrapper.eq("del_flag",0);
         Page<Equipment> page = new Page<Equipment>(pageNo, pageSize);
         IPage<Equipment> pageList = equipmentService.page(page, queryWrapper);
         return Result.OK(pageList);
     }
 
     @GetMapping(value = "/pageEquipment")
     public Result<IPage<Equipment>> pageEquipment(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Equipment> pageList = equipmentService.pageEquipment(pageNo, pageSize, params);
         return Result.OK(pageList);
     }
 
    /**
     *   添加
     *
     * @param equipment
     * @return
     */
    @AutoLog(value = "mom_eam_equipment-添加")
    @ApiOperation(value="mom_eam_equipment-添加", notes="mom_eam_equipment-添加")
    @PostMapping(value = "/add")
    @Transactional(rollbackFor = { Exception.class })
    public Result<String> add(@RequestBody Equipment equipment) {
        equipmentService.save(equipment);
        //获取工艺参数模板明细
        String processParametersTemplateId = equipment.getProcessParametersTemplateId();
        List<ProcessParametersTemplateDetail> processParameters = processParametersTemplateDetailService.lambdaQuery()
                .eq(ProcessParametersTemplateDetail::getProcessParametersTemplateId, processParametersTemplateId)
                .eq(ProcessParametersTemplateDetail::getDelFlag, 0).list();
        for (ProcessParametersTemplateDetail processParameter : processParameters) {
            EquipmentProcessParameters equipmentProcessParameters = new EquipmentProcessParameters();
            equipmentProcessParameters.setEquipmentId(equipment.getId());
            equipmentProcessParameters.setProcessParametersId(processParameter.getProcessParametersId());
            equipmentProcessParametersService.save(equipmentProcessParameters);
        }
        //获取设备精度参数模板明细
        String precisionParametersTemplateId = equipment.getPrecisionParametersTemplateId();
        List<PrecisionParametersTemplateDetail> precisionParameters = precisionParametersTemplateDetailService.lambdaQuery()
                .eq(PrecisionParametersTemplateDetail::getPrecisionParametersTemplateId, precisionParametersTemplateId)
                .eq(PrecisionParametersTemplateDetail::getDelFlag, 0).list();
        for (PrecisionParametersTemplateDetail precisionParameter : precisionParameters) {
            EquipmentPrecisionParameters equipmentPrecisionParameters = new EquipmentPrecisionParameters();
            equipmentPrecisionParameters.setEquipmentId(equipment.getId());
            equipmentPrecisionParameters.setPrecisionParametersId(precisionParameter.getPrecisionParametersId());
            equipmentPrecisionParametersService.save(equipmentPrecisionParameters);
        }
 
        List<SysUpload> sysUploads = equipment.getSysUploadList();
        if (sysUploads!= null){
//            uploadRelaService.saveOrUpdateUploadRale(equipment.getId(), "equipment_photo",sysUploads.get(0).getId());
            sysBaseApi.saveOrUpdateUploadRale(equipment.getId(), "equipment_photo",sysUploads.get(0).getId());
        }
        return Result.OK("添加成功!");
    }
 
    /**
     *  编辑
     *
     * @param equipment
     * @return
     */
    @AutoLog(value = "mom_eam_equipment-编辑")
    @ApiOperation(value="mom_eam_equipment-编辑", notes="mom_eam_equipment-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    @Transactional(rollbackFor = { Exception.class })
    public Result<String> edit(@RequestBody Equipment equipment) {
 
        List<EquipmentProcessParameters> proParameters = equipmentProcessParametersService.lambdaQuery()
                .eq(EquipmentProcessParameters::getEquipmentId, equipment.getId())
                .eq(EquipmentProcessParameters::getDelFlag, 0).list();
        for (EquipmentProcessParameters proParameter : proParameters) {
            equipmentProcessParametersService.removeById(proParameter);
        }
 
        List<EquipmentPrecisionParameters> preParameters = equipmentPrecisionParametersService.lambdaQuery()
                .eq(EquipmentPrecisionParameters::getEquipmentId, equipment.getId())
                .eq(EquipmentPrecisionParameters::getDelFlag, 0).list();
        for (EquipmentPrecisionParameters preParameter : preParameters) {
            equipmentPrecisionParametersService.removeById(preParameter);
        }
 
        //获取工艺参数模板明细
        String processParametersTemplateId = equipment.getProcessParametersTemplateId();
        List<ProcessParametersTemplateDetail> processParameters = processParametersTemplateDetailService.lambdaQuery()
                .eq(ProcessParametersTemplateDetail::getProcessParametersTemplateId, processParametersTemplateId)
                .eq(ProcessParametersTemplateDetail::getDelFlag, 0).list();
        for (ProcessParametersTemplateDetail processParameter : processParameters) {
            EquipmentProcessParameters equipmentProcessParameters = new EquipmentProcessParameters();
            equipmentProcessParameters.setEquipmentId(equipment.getId());
            equipmentProcessParameters.setProcessParametersId(processParameter.getProcessParametersId());
            equipmentProcessParametersService.save(equipmentProcessParameters);
        }
        //获取设备精度参数模板明细
        String precisionParametersTemplateId = equipment.getPrecisionParametersTemplateId();
        List<PrecisionParametersTemplateDetail> precisionParameters = precisionParametersTemplateDetailService.lambdaQuery()
                .eq(PrecisionParametersTemplateDetail::getPrecisionParametersTemplateId, precisionParametersTemplateId)
                .eq(PrecisionParametersTemplateDetail::getDelFlag, 0).list();
        for (PrecisionParametersTemplateDetail precisionParameter : precisionParameters) {
            EquipmentPrecisionParameters equipmentPrecisionParameters = new EquipmentPrecisionParameters();
            equipmentPrecisionParameters.setEquipmentId(equipment.getId());
            equipmentPrecisionParameters.setPrecisionParametersId(precisionParameter.getPrecisionParametersId());
            equipmentPrecisionParametersService.save(equipmentPrecisionParameters);
        }
 
        equipmentService.updateById(equipment);
 
        List<SysUpload> sysUploads = equipment.getSysUploadList();
        if (sysUploads!= null){
//            uploadRelaService.saveOrUpdateUploadRale(equipment.getId(), "equipment_photo",sysUploads.get(0).getId());
            sysBaseApi.saveOrUpdateUploadRale(equipment.getId(), "equipment_photo",sysUploads.get(0).getId());
        }
        return Result.OK("编辑成功!");
    }
 
    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "mom_eam_equipment-通过id删除")
    @ApiOperation(value="mom_eam_equipment-通过id删除", notes="mom_eam_equipment-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        Equipment equipment = equipmentService.getById(id);
        equipment.setDelFlag(1);
        equipmentService.updateById(equipment);
        return Result.OK("删除成功!");
    }
 
    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "mom_eam_equipment-批量删除")
    @ApiOperation(value="mom_eam_equipment-批量删除", notes="mom_eam_equipment-批量删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        List<String> stringList = Arrays.asList(ids.split(","));
        for (String id : stringList) {
            Equipment equipment = equipmentService.getById(id);
            equipment.setDelFlag(1);
            equipmentService.updateById(equipment);
        }
//        this.equipmentService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }
 
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "mom_eam_equipment-通过id查询")
    @ApiOperation(value="mom_eam_equipment-通过id查询", notes="mom_eam_equipment-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<Equipment> queryById(@RequestParam(name="id",required=true) String id) {
        Equipment equipment = equipmentService.getById(id);
        if(equipment==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(equipment);
    }
 
    /**
    * 导出excel
    *
    * @param request
    * @param equipment
    */
    //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, Equipment equipment) {
        return super.exportXls(request, equipment, Equipment.class, "设备台账导出");
    }
 
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    //@RequiresPermissions("mom_eam_equipment:importExcel")
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, Equipment.class);
//    }
 
 
     /**
      * 设备建账  获取组织部门
      * qsw 2023-4-28
      */
     @GetMapping("getSysDeparts")
     public Result<?> getSysDeparts() {
         List<DepartVo> sysDeparts = equipmentService.getSysDeparts();
         return Result.ok(sysDeparts);
     }
 
 
     /**
      *设备履历 获取设备使用记录
      * qsw 2023-7-28
      */
     @GetMapping(value = "/getResumeUseRecordList")
     public Result<?> getResumeUseRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeUseRecordList = equipmentService.getResumeUseRecordList(pageNo, pageSize, params);
         return Result.ok(resumeUseRecordList);
     }
 
     /**
      *设备履历 获取设备点检记录
      * qsw 2023-7-28
      */
     @GetMapping(value = "/getResumeInspectionRecordList")
     public Result<?> getResumeInspectionRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeInspectionRecordList = equipmentService.getResumeInspectionRecordList(pageNo, pageSize, params);
         LoginUser user= (LoginUser) SecurityUtils.getSubject().getPrincipal();
         for (Map<String, Object> record : resumeInspectionRecordList.getRecords()) {
             String id = (String)record.get("id");
             String inspectionType = (String)record.get("inspectionType");
             if("日常点检".equals(inspectionType)){
                 List<InspectionOrderDetail> failCount = inspectionOrderDetailService.lambdaQuery()
                         .eq(InspectionOrderDetail::getInspectionOrderId, id)
                         .eq(InspectionOrderDetail::getJudgmentResult, "fail")
                         .eq(InspectionOrderDetail::getDelFlag, 0).list();
 
                 List<InspectionOrderDetail> passCount = inspectionOrderDetailService.lambdaQuery()
                         .eq(InspectionOrderDetail::getInspectionOrderId, id)
                         .eq(InspectionOrderDetail::getJudgmentResult,"pass")
                         .eq(InspectionOrderDetail::getDelFlag, 0).list();
                 record.put("result","正常:"+passCount.size()+","+"异常:"+failCount.size());
             }else{
                 List<SpecialtyInspectionOrderDetail> failCount = specialtyInspectionOrderDetailService.lambdaQuery()
                         .eq(SpecialtyInspectionOrderDetail::getSpecialtyInspectionOrderId, id)
                         .eq(SpecialtyInspectionOrderDetail::getJudgmentResult,"fail")
                         .eq(SpecialtyInspectionOrderDetail::getDelFlag, 0).list();
 
                 List<SpecialtyInspectionOrderDetail> passCount = specialtyInspectionOrderDetailService.lambdaQuery()
                         .eq(SpecialtyInspectionOrderDetail::getSpecialtyInspectionOrderId, id)
                         .eq(SpecialtyInspectionOrderDetail::getJudgmentResult,"pass")
                         .eq(SpecialtyInspectionOrderDetail::getDelFlag, 0).list();
                 record.put("result","正常:"+passCount.size()+","+"异常:"+failCount.size());
             }
         }
         return Result.ok(resumeInspectionRecordList);
     }
 
     /**
      *设备履历 获取设备保养记录
      * qsw 2023-7-31
      */
     @GetMapping(value = "/getResumeMaintenanceRecordList")
     public Result<?> getResumeMaintenanceRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeMaintenanceRecordList = equipmentService.getResumeMaintenanceRecordList(pageNo, pageSize, params);
         return Result.ok(resumeMaintenanceRecordList);
     }
 
     /**
      *设备履历 获取设备维修记录
      * qsw 2023-7-31
      */
     @GetMapping(value = "/getResumeRepairRecordList")
     public Result<?> getResumeRepairRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeRepairRecordList = equipmentService.getResumeRepairRecordList(pageNo, pageSize, params);
         return Result.ok(resumeRepairRecordList);
     }
 
     /**
      *设备履历 获取设备检定记录
      * qsw 2023-7-31
      */
     @GetMapping(value = "/getResumeCalibrationRecordList")
     public Result<?> getResumeCalibrationRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeCalibrationRecordList = equipmentService.getResumeCalibrationRecordList(pageNo, pageSize, params);
         for (Map<String, Object> record : resumeCalibrationRecordList.getRecords()) {
             String id = (String)record.get("id");
             String status = (String)record.get("status");
             String managementMode = (String)record.get("managementMode");
             if("4".equals(status)){
                 if("data".equals(managementMode)){
                     List<CalibrationOrderDetail> calibrationOrderDetails = calibrationOrderDetailService.lambdaQuery()
                             .eq(CalibrationOrderDetail::getCalibrationOrderId, id)
                             .eq(CalibrationOrderDetail::getJudgmentResult, "fail")
                             .eq(CalibrationOrderDetail::getDelFlag,"0").list();
                     if(calibrationOrderDetails.size()>0){
                         record.put("calibrationResult","异常");
                     }else{
                         record.put("calibrationResult","正常常");
                     }
                 }else{
                     List<CalibrationOrderReport> calibrationOrderReports = calibrationOrderReportService.lambdaQuery()
                             .eq(CalibrationOrderReport::getCalibrationOrderId, id)
                             .eq(CalibrationOrderReport::getJudgmentResult, "fail")
                             .eq(CalibrationOrderReport::getDelFlag, "0").list();
                     if(calibrationOrderReports.size()>0){
                         record.put("calibrationResult","异常");
                     }else{
                         record.put("calibrationResult","正常常");
                     }
                 }
             }
         }
         return Result.ok(resumeCalibrationRecordList);
     }
 
     /**
      *设备履历 获取设备处置记录
      * qsw 2023-7-31
      */
     @GetMapping(value = "/getResumeChangeRecordList")
     public Result<?> getResumeChangeRecordList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam Map<String, Object> params) {
         IPage<Map<String, Object>> resumeChangeRecordList = equipmentService.getResumeChangeRecordList(pageNo, pageSize, params);
         return Result.ok(resumeChangeRecordList);
     }
 
     /**
      * 根据状态查询设备列表
      */
     @GetMapping(value = "/getEquipmentListByStatus")
     public Result<IPage<Equipment>> getEquipmentList(Equipment equipment,String status,
                                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                      HttpServletRequest req) {
         QueryWrapper<Equipment> queryWrapper = QueryGenerator.initQueryWrapper(equipment, req.getParameterMap());
         List<String> statusList = Arrays.asList(status.split(","));
         Page<Equipment> page = new Page<Equipment>(pageNo, pageSize);
         queryWrapper.in("equipment_status",statusList);
         IPage<Equipment> pageList = equipmentService.page(page, queryWrapper);
         return Result.OK(pageList);
     }/**
      * 导入
      * @return
      */
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     @Transactional(rollbackFor = Exception.class)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
         LoginUser user= (LoginUser) SecurityUtils.getSubject().getPrincipal();
         Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
         String exceptionInfo = "";
         int exceptionNum = 0;
         for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
             MultipartFile file = entity.getValue();
             ImportParams params = new ImportParams();
             params.setNeedSave(true);
             try {
                 List<EquipmentImportVo> list = ExcelImportUtil.importExcel(file.getInputStream(), EquipmentImportVo.class, params);
                 for(int i = 0;i<list.size();i++){
                     EquipmentImportVo equipmentImportVo = list.get(i);
                     EquipmentCategory equipmentCategory = equipmentCategoryService.getOne(new QueryWrapper<EquipmentCategory>().eq("name",equipmentImportVo.getEquipmentCategoryName()),false);
                     if(StringUtils.isBlank(equipmentImportVo.getNum())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:统一编码缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getName())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备名称缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getUseId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:使用部门缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getEquipmentUda1())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:工区缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getManageId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:维护部门缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getTeamId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:维修班组缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getEquipmentImportanceId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:ABC标识缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getEquipmentCategoryName())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备分类缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getEquipmentStatus())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备状态缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getTechnologyStatus())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备技术缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getFactoryModelId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:车间缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getWorkCenterId())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:产线缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(ObjectUtils.isNotNull(equipmentImportVo.getWarrantyStart())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:质保开始日期缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getPropertyStatus())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:资产状态缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     //非必填项
//                     else if(StringUtils.isBlank(equipmentImportVo.getEquipmentUda5())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:功能位置缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getLocation())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:安装位置缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getLeaveFactoryDate())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:出厂日期缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getProjectApprovalNo())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:立项卡号缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getFundSource())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:资金来源缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getAcceptanceCheckDate())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:验收日期缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getLeaveFactoryDate())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:出厂日期缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getFactoryNo())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:出厂编号缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
//                     else if( StringUtils.isBlank(equipmentImportVo.getConstructorId())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:资产制造商缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getModel())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备型号缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
                     else if(StringUtils.isBlank(equipmentImportVo.getSpecification())){
                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备规格缺失,请填写必填项后再导入;";
                         exceptionNum++;
                     }
//                     else if(StringUtils.isBlank(equipmentImportVo.getGpo())){
//                         exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:设备功率缺失,请填写必填项后再导入;";
//                         exceptionNum++;
//                     }
                     else if(ObjectUtils.isNull(equipmentCategory))
                           {
                              exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:该设备所属类别不存在,请先维护设备类别;";
                              exceptionNum++;
                           }
                     else{
                         if(equipmentImportVo.getPropertyStatus().equals("warranty")){
                             if(
                                     ObjectUtils.isNull(equipmentImportVo.getWarrantyStart())
                                     ||ObjectUtils.isNull(equipmentImportVo.getWarrantyEnd())
                             ){
                                 exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:该设备处于质保期,质保信息缺失,请先维护质保开始时间或结束时间;";
                                 exceptionNum++;
                             }
 
                         }else{
                             Equipment oriEquipment = equipmentService.getOne(new QueryWrapper<Equipment>().eq("num",equipmentImportVo.getNum()),false);
                             if(ObjectUtils.isNull(oriEquipment)){
                                 Equipment equipment = new Equipment();
                                 equipment.setNum(equipmentImportVo.getNum())
                                         .setName(equipmentImportVo.getName())
                                         .setUseId(equipmentImportVo.getUseId())
                                         .setEquipmentUda1(equipmentImportVo.getEquipmentUda1())
                                         .setManageId(equipmentImportVo.getManageId())
                                         .setTeamId(equipmentImportVo.getTeamId())
                                         .setTechnologyStatus(equipmentImportVo.getTechnologyStatus())
                                         .setEquipmentImportanceId(equipmentImportVo.getEquipmentImportanceId())
                                         .setEquipmentCategoryId(equipmentCategory.getId())
                                         .setSpecificEquipment(equipmentImportVo.getKeyEquipmentIdentification())
                                         .setSecurityConfiguration(equipmentImportVo.getSecurityConfiguration())
                                         .setCoolingSystem(equipmentImportVo.getCoolingSystem())
                                         .setFireExtinguisher(equipmentImportVo.getFireExtinguisher())
                                         .setFireExtinguisherValidityPeriod(equipmentImportVo.getFireExtinguisherValidityPeriod())
                                         .setOperatingSystem(equipmentImportVo.getOperatingSystem())
                                         .setSystem(equipmentImportVo.getSystem())
                                         .setPort(equipmentImportVo.getPort())
                                         .setCoordinateNum(equipmentImportVo.getCoordinateNum())
                                         .setEquipmentStatus(equipmentImportVo.getEquipmentStatus())
                                         .setEquipmentUda3(equipmentImportVo.getEquipmentUda3())
                                         .setEquipmentUda4(equipmentImportVo.getEquipmentUda4())
                                         .setEquipmentUda5(equipmentImportVo.getEquipmentUda5())
                                         .setLocation(equipmentImportVo.getLocation())
                                         .setLastVerificationDate(equipmentImportVo.getLeaveFactoryDate())
                                         .setProjectApprovalNo(equipmentImportVo.getProjectApprovalNo())
                                         .setFundSource(equipmentImportVo.getFundSource())
                                         .setAcceptanceCheckDate(equipmentImportVo.getAcceptanceCheckDate())
                                         .setFactoryNumber(equipmentImportVo.getFactoryNumber())
                                         .setConstructorId(equipmentImportVo.getConstructorId())
                                         .setSourceCountry(equipmentImportVo.getSourceCountry())
                                         .setModel(equipmentImportVo.getModel())
                                         .setSpecification(equipmentImportVo.getSpecification())
                                         .setFactoryModelId(equipmentImportVo.getFactoryModelId())
                                         .setWorkCenterId(equipmentImportVo.getWorkCenterId())
                                         .setPropertyStatus(equipmentImportVo.getPropertyStatus())
                                         .setWarrantyStart(equipmentImportVo.getWarrantyStart())
                                         .setWarrantyEnd(equipmentImportVo.getWarrantyEnd())
                                         .setGpo(equipmentImportVo.getGpo());
                                 equipmentService.save(equipment);
                             }else {
                                 exceptionInfo = exceptionInfo+"第"+(i+2)+"行导入失败,原因:统一编码已存在,数据重复导入;";
                                 exceptionNum++;
                             }
                         }
 
                     }
                 }
                 if(exceptionNum!=0){
                     String headInfo = "小导提醒您!设备台账:导入成功"+(list.size()-exceptionNum)+"条,失败"+exceptionNum+"条";
                     MessageDTO messageDTO = new MessageDTO();
                     messageDTO.setTitle(headInfo);
                     messageDTO.setFromUser("数据导入小助手-小导");
                     messageDTO.setCategory("导入操作附加信息");
                     messageDTO.setContent(exceptionInfo);
                     messageDTO.setToUser(user.getUsername());
                     sysBaseApi.sendSysAnnouncement(messageDTO);
                     return Result.OK(headInfo+",可在-系统消息-查看导入详情");
                 }
                 return Result.OK("导入成功,已导入全部数据。");
             } catch (Exception e) {
                 log.error(e.getMessage(), e);
                 return Result.error("文件导入失败:" + e.getMessage());
             }
         }
         return Result.error("文件导入失败!");
     }
 
 
}