yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
package com.qianwen.smartman.modules.cps.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.annotation.PutResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.excel.MalfunctionTypeExcel;
import com.qianwen.smartman.modules.cps.excel.MalfunctionTypeImport;
import com.qianwen.smartman.modules.cps.service.IMalfunctionTypeService;
import com.qianwen.smartman.modules.cps.vo.MalfunctionTypeRecordVO;
import com.qianwen.smartman.modules.cps.vo.MalfunctionTypeVO;
import com.qianwen.smartman.modules.cps.wrapper.MalfunctionTypeExcelWrapper;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.resource.enums.TemplateEnum;
import com.qianwen.smartman.modules.resource.service.ISystemResourceService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
@ApiResource({"smis/malfunction"})
@Api(value = "故障类型", tags = {"故障类型"})
@RestController
public class MalfunctionTypeController extends BladeController {
    private final IMalfunctionTypeService malfunctionTypeService;
    private final OssBuilder ossBuilder;
    private final ISystemResourceService systemResourceService;
 
    public MalfunctionTypeController(final IMalfunctionTypeService malfunctionTypeService, final OssBuilder ossBuilder, final ISystemResourceService systemResourceService) {
        this.malfunctionTypeService = malfunctionTypeService;
        this.ossBuilder = ossBuilder;
        this.systemResourceService = systemResourceService;
    }
 
    @ApiOperationSupport(order = 1)
    @PostResource({"/save"})
    @ApiOperation("新增或更改故障类型")
    @PreAuth
    public R<MalfunctionTypeVO> save(@RequestBody MalfunctionTypeVO malfunctionTypeVO) {
        return R.data(this.malfunctionTypeService.insert(malfunctionTypeVO));
    }
 
    @ApiOperationSupport(order = 2)
    @GetResource({"/page"})
    @ApiOperation("分页/查询故障类型列表")
    @PreAuth
    public R<IPage<MalfunctionTypeVO>> page(@ApiParam("分页条件") Query query, @RequestParam("malfunctionTypeCodeOrName") @ApiParam("故障类型编号或姓名") String keyword, @RequestParam(value = "status", required = false) @ApiParam("1 启用 0 停用") Integer status) {
        return R.data(this.malfunctionTypeService.listPage(query, keyword, status));
    }
 
    @ApiOperationSupport(order = 3)
    @ApiOperation("批量删除故障类型")
    @PreAuth
    @DeleteResource({"/delete"})
    public R<Boolean> delete(@RequestParam("malfunctionTypeIds") String ids, @RequestParam("type") @ApiParam("删除传0 停用传1") Integer type) {
        return R.data(this.malfunctionTypeService.deleteMalfunctionTypeByIdList(Func.toLongList(ids), type));
    }
 
    @ApiOperationSupport(order = 4)
    @GetResource({"/detail"})
    @ApiOperation(value = "故障类型详情", notes = "传入id")
    public R<MalfunctionTypeVO> detail(@RequestParam("malfunctionTypeId") String malfunctionTypeId) {
        return R.data(this.malfunctionTypeService.detail(Long.valueOf(Func.toLong(malfunctionTypeId))));
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @PostResource({"/export-malfunctionType"})
    @ApiOperation("导出故障类型")
    @PreAuth
    public R<BladeFile> exportMalfunctionType(@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(value = "status", required = false) @ApiParam("1 启用 0 停用") Integer status) {
        IPage<MalfunctionTypeVO> pages = this.malfunctionTypeService.listPage(new Query().setCurrent(1).setSize(-1), keyword, status);
        List<MalfunctionTypeExcel> list = MalfunctionTypeExcelWrapper.build().pageVO(pages).getRecords();
        String fileName = String.format("%s-%s.xlsx", "故障类型数据", DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "故障类型表", list, MalfunctionTypeExcel.class);
        BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        return R.data(bladeFile);
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/import-malfunctionType"})
    @ApiOperation("导入故障类型")
    @PreAuth
    public R<BladeFile> importMalfunctionType(MultipartFile file) {
        List<MalfunctionTypeImport> data = ExcelUtil.read(file, 0, 2, MalfunctionTypeImport.class);
        return R.data(this.malfunctionTypeService.importMalfunctionType(data));
    }
 
    @ApiOperationSupport(order = 7)
    @PutResource({"/update-malfunctionType"})
    @ApiOperation("编辑故障类型")
    @PreAuth
    public R<Boolean> updateMalfunctionType(@RequestBody MalfunctionTypeVO malfunctionTypeVO) {
        return R.data(this.malfunctionTypeService.updateMalfunctionType(malfunctionTypeVO));
    }
 
    @ApiOperationSupport(order = 8)
    @GetResource({"/export-template"})
    @ApiOperation("导出模板")
    @PreAuth
    public R<BladeFile> exportTemplate() {
        return R.data(this.systemResourceService.getBusinessTemplateInfo(TemplateEnum.MALFUNCTION_TYPE));
    }
 
    @ApiOperationSupport(order = 9)
    @GetResource({"/malfunction-code-list"})
    @ApiOperation(value = "获取故障编码list", notes = "给维修记录故障码提供")
    public R<List<MalfunctionTypeRecordVO>> getCodeAndRecord() {
        return R.data(this.malfunctionTypeService.getCodeAndRecord());
    }
}