yangys
2025-09-09 3d558e1bb5091b76a6525f6fab015574e1755200
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
package org.springblade.mdm.basesetting.machine.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
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.apache.commons.io.IOUtils;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.basesetting.machine.service.MachineImportService;
import org.springblade.mdm.basesetting.machine.vo.MachineExcel;
import org.springblade.mdm.basesetting.machine.vo.MachineQueryVO;
import org.springblade.mdm.basesetting.machine.vo.MachineSaveVO;
import org.springblade.mdm.basesetting.machine.vo.MachineVO;
import org.springblade.mdm.basesetting.producedivision.vo.ImportResult;
import org.springblade.mdm.commons.service.ParamService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@RestController
@RequestMapping("/machine")
@Tag(name = "机床", description = "机床")
public class MachineController {
 
    @Autowired
    private MachineService service;
    @Autowired
    private MachineImportService machineImportService;
    @Autowired
    private ParamService paramService;
    @Autowired
    private OssTemplate ossTemplate;
    /**
     * 新增
     */
    @PostMapping("/save")
    @Operation(summary = "新增", description = "机床信息")
    public R<Boolean> save(@RequestBody MachineSaveVO vo) {
        try {
            service.saveMachine(vo);
        }catch (Exception e) {
            log.error("新增机床失败", e);;
            return R.fail(e.getMessage());
        }
        return R.<Boolean>status(true);
    }
 
    /**
     * 修改
     */
    @Operation(summary = "修改", description = "机床信息")
    @PostMapping("/update")
    public R<Boolean> update(@RequestBody MachineSaveVO vo) {
        try{
            return R.data(service.updateMachine(vo));
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
    }
 
    @Operation(summary = "详情", description = "查询机床详情")
    @GetMapping("/detail")
    public R<MachineVO> deatail(long id) {
        return R.data(service.detail(id));
    }
 
    @PostMapping("import")
    @ApiOperationSupport(order = 1)
    @Operation(summary = "机床导入", description = "机床导入,全部成功返回空串,部分成功返回具体信息")
    public R<ImportResult> importMachines(@RequestParam MultipartFile file) {
        try {
            return R.data(machineImportService.importMachines(file));
        }catch (Exception e){
            log.error("导入错误",e);
            return R.fail(e.getMessage());
        }
    }
    /**
     * 删除
     */
    @Operation(summary = "删除", description = "删除")
    @PostMapping("/remove")
    public R<Void> remove(@RequestParam String ids) {
        try {
            service.removeBatchByIds(Func.toLongList(ids));
        } catch (Exception e) {
            log.error("删除异常",e);
            return R.fail(e.getMessage());
        }
        return R.status(true);
    }
 
    /**
     * 分页
     */
    @Operation(summary = "分页查询", description = "名称或编码")
    @GetMapping("/page")
    public R<IPage<MachineVO>> page(MachineQueryVO query) {
        IPage<MachineVO> pages = service.pageQuery(query);
        return R.data(pages);
    }
 
    @GetMapping("export")
    @ApiOperationSupport(order = 13)
    @Operation(summary = "导出机床", description = "名称或编码")
    public void export(MachineQueryVO query, HttpServletResponse response) {
        query.setCurrent(1);
        query.setSize(Integer.MAX_VALUE);
        IPage<MachineVO> pages = service.pageQuery(query);
 
        List<MachineExcel> list = new ArrayList<>();
        pages.getRecords().forEach(m ->{
            MachineExcel excelVO = new MachineExcel();
            BeanUtils.copyProperties(m, excelVO);
            list.add(excelVO);
        });
 
        ExcelUtil.export(response, "机床数据" + DateUtil.time(), "机床数据表", list, MachineExcel.class);
    }
 
    @Operation(summary = "下载机床导入模板", description = "下载机床导入模板")
    @GetMapping("/download-template")
    public void downloadTemplate(HttpServletResponse response) {
        String PARAMKEY = "MACHINE_TEMPLATE";
 
        try {
            String filename = "machinetemplate.xlsx";
            response.setHeader("Content-Disposition", "attachment; filename="+filename);
            response.setContentType("application/octet-stream");
            String ossName  = paramService.getParamValue(PARAMKEY,"");
            try(InputStream ins = ossTemplate.statFileStream(ossName);){
                IOUtils.copy(ins,response.getOutputStream());
            }
 
        } catch (Exception e) {
            log.error("导出分机床模板异常", e);
        }
    }
    /*
    @Operation(summary = "产生机床回传结构树", description = "产生机床回传结构树")
    @PostMapping("/gen-fileback-dirs")
    public R<Void> genFileBackDirs(@RequestParam Long id) {
        try {
            service.genMachineFileBackDirs(id);
        } catch (Exception e) {
            log.error("产生目录异常",e);
            return R.fail(e.getMessage());
        }
        return R.status(true);
    }
     */
}