yangys
2025-09-20 fcee672452c02cc29e0e17ebc27a8c51698c6d0d
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
 
package org.springblade.mdm.statreport.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.basesetting.producedivision.entity.MdmDept;
import org.springblade.mdm.basesetting.producedivision.service.MdmDeptService;
import org.springblade.mdm.machinefile.entity.MachineFile;
import org.springblade.mdm.machinefile.service.MachineFileChangeHisService;
import org.springblade.mdm.machinefile.service.MachineFileService;
import org.springblade.mdm.machinefile.vo.*;
import org.springblade.mdm.program.vo.CompareDataVO;
import org.springblade.mdm.statreport.vo.MachineFileExceptionExcelVO;
import org.springblade.mdm.statreport.vo.MachineFileExceptionQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 工控网异常文件记录
 *
 * @author yangys
 */
@NonDS
@RestController
@RequestMapping("/statreport/exceptionfile")
@Tag(name = "工控网程序节点", description = "工控网程序节点")
@Slf4j
public class MachineFileExceptionController {
    @Autowired
    private MachineFileService machineFileService;
    @Autowired
    private MdmDeptService mdmDeptService;
    @Autowired
    private MachineService machineService;
 
    @GetMapping("/page")
    @Operation(summary = "文件异常记录列表", description = "文件异常记录列表")
    public R<IPage<MachineFile>> page(MachineFileExceptionQueryVO query) {
        /*
        if("workshop".equals(query.getNodeType()) || "seg".equals(query.getNodeType())) {
            //节点为车间、工段
            MdmDept dept = mdmDeptService.getById(query.getNodeId());
 
            String idStr = dept.getAncestors()+","+dept.getId();
            List<MdmDept> depts = mdmDeptService.lambdaQuery().likeRight(MdmDept::getParentId, query.getNodeId()).list();
            List<Long> deptIds = new ArrayList<>(depts.stream().map(MdmDept::getId).toList());
            deptIds.add(dept.getId());
            //+本车间
            //Func.toStrList(",",idStr)
            query.setDeptIds(deptIds);
        }else if("machine".equals(query.getNodeType())){
            Machine machine = machineService.getById(query.getNodeId());
            query.setMachineCode(machine.getCode());
        }else if("dir".equals(query.getNodeType())){
            query.setMachineCode(query.getMachineCode());
        }*/
        return R.data(machineFileService.exceptionFilePageQuery(query));
    }
 
    @Operation(summary = "回传程序处理导出Excel", description = "回传程序处理导出Excel")
    @GetMapping("/export-excel")
    public void exportExcel(MachineFileExceptionQueryVO query, HttpServletResponse response) {
        query.setCurrent(1);
        query.setSize(Integer.MAX_VALUE);
 
        IPage<MachineFile> page = machineFileService.exceptionFilePageQuery(query);
        //List<MachineFileExceptionExcelVO> list = BeanUtil.copy(page.getRecords(), MachineFileExceptionExcelVO.class);
        List<MachineFileExceptionExcelVO> list = new ArrayList<>();
            page.getRecords().forEach(machineFile ->{
            MachineFileExceptionExcelVO excelVO = new MachineFileExceptionExcelVO();
            BeanUtil.copyProperties(machineFile, excelVO);
            //excelVO.setExceptionMsg(machineFile.getExceptionMsg());
 
            list.add(excelVO);
        });
 
        ExcelUtil.export(response, "文件异常记录" + DateUtil.time(), "文件异常记录", list, MachineFileExceptionExcelVO.class);
    }
 
 
}