车间能级提升-智能设备管理系统
zhuguifei
2025-06-06 00cf6c13531447af59a8d2121bbfb1a3a1f68c0d
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
package org.dromara.eims.controller;
 
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.List;
 
import jakarta.servlet.ServletOutputStream;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.eims.domain.vo.EimsMaintPlanVo;
import org.dromara.eims.domain.bo.EimsMaintPlanBo;
import org.dromara.eims.service.IEimsMaintPlanService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * 保养计划
 *
 * @author zhuguifei
 * @date 2025-03-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/eims/maintPlan")
public class EimsMaintPlanController extends BaseController {
 
    private final IEimsMaintPlanService eimsMaintPlanService;
 
    /**
     * 查询保养计划列表
     */
    @SaCheckPermission("eims:maintPlan:list")
    @GetMapping("/list")
    public TableDataInfo<EimsMaintPlanVo> list(EimsMaintPlanBo bo, PageQuery pageQuery) {
//        return eimsMaintPlanService.queryPageList(bo, pageQuery);
        return eimsMaintPlanService.queryPageListCustom(bo, pageQuery);
    }
 
    /**
     * 导出保养计划列表
     */
    @SaCheckPermission("eims:maintPlan:export")
    @Log(title = "保养计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EimsMaintPlanBo bo, HttpServletResponse response) {
        List<EimsMaintPlanVo> list = eimsMaintPlanService.queryList(bo);
        ExcelUtil.exportExcel(list, "保养计划", EimsMaintPlanVo.class, response);
    }
 
    /**
     * 获取保养计划详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("eims:maintPlan:query")
    @GetMapping("/{id}")
    public R<EimsMaintPlanVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long id) {
        return R.ok(eimsMaintPlanService.queryById(id));
    }
 
    /**
     * 新增保养计划
     */
    @SaCheckPermission("eims:maintPlan:add")
    @Log(title = "保养计划", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EimsMaintPlanBo bo) {
        return toAjax(eimsMaintPlanService.insertByBo(bo));
    }
 
    /**
     * 修改保养计划
     */
    @SaCheckPermission("eims:maintPlan:edit")
    @Log(title = "保养计划", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EimsMaintPlanBo bo) {
        return toAjax(eimsMaintPlanService.updateByBo(bo));
    }
 
    /**
     * 删除保养计划
     *
     * @param ids 主键串
     */
    @SaCheckPermission("eims:maintPlan:remove")
    @Log(title = "保养计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(eimsMaintPlanService.deleteWithValidByIds(List.of(ids), true));
    }
 
    /**
     * 导入数据
     *
     * @param file          导入文件
     * @param updateSupport 是否更新已存在数据
     */
    @Log(title = "保养计划", businessType = BusinessType.IMPORT)
    @SaCheckPermission("eims:maintPlan:import")
    @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> importData(@RequestPart("files") List<MultipartFile> files, boolean updateSupport) throws Exception {
        StringBuilder successMsg = new StringBuilder();
        for (MultipartFile file : files) {
            String res = eimsMaintPlanService.importData(file, updateSupport);
 
            successMsg.append(res).append("; \r\n");
 
        }
        return R.ok(successMsg.toString());
    }
 
    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 设置响应类型
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
 
        // 设置文件名
        String fileName = URLEncoder.encode("保养计划导入模板", "UTF-8");
        response.setHeader("Content-Disposition",
            "attachment;filename=" + fileName + ".xls");
 
        // 读取模板文件
        ClassPathResource templateResource = new ClassPathResource("template/by.xls");
        try (InputStream inputStream = templateResource.getInputStream();
             ServletOutputStream outputStream = response.getOutputStream()) {
 
            // 流拷贝
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            throw new RuntimeException("模板文件读取失败", e);
        }
    }
}