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
package com.qianwen.smartman.modules.cps.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.BladeUser;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.DeviceTypeConvert;
import com.qianwen.smartman.modules.cps.entity.DeviceType;
import com.qianwen.smartman.modules.cps.excel.DeviceTypeExcel;
import com.qianwen.smartman.modules.cps.service.IDeviceTypeService;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeAddVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeExcelVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeIdListVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeUpdateVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeVO;
import com.qianwen.smartman.modules.resource.enums.TemplateEnum;
import com.qianwen.smartman.modules.resource.service.ISystemResourceService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
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;
 
@Api(value = "机器类型", tags = {"机器类型"})
@RestController
@ApiResource({"smis/device-types"})
@NonDS
@Validated
public class DeviceTypeController {
    private final IDeviceTypeService deviceTypeService;
    private final ISystemResourceService systemResourceService;
 
    public DeviceTypeController(final IDeviceTypeService deviceTypeService, final ISystemResourceService systemResourceService) {
        this.deviceTypeService = deviceTypeService;
        this.systemResourceService = systemResourceService;
    }
 
    @PreAuth
    @PostResource
    @ApiOperation(value = "新增机器类型", notes = "新增机器类型", tags = {"机器类型"})
    public R<DeviceType> createDeviceType(@Validated @RequestBody DeviceTypeAddVO deviceTypeAddVO) {
        return R.data(this.deviceTypeService.createDeviceType(deviceTypeAddVO));
    }
 
    @PreAuth
    @PutResource
    @ApiOperation(value = "更新机器类型", notes = "更新机器类型", tags = {"机器类型"})
    public R<DeviceTypeVO> updateDeviceType(@Validated @RequestBody DeviceTypeUpdateVO deviceTypeUpdateVO) {
        return R.data(DeviceTypeConvert.INSTANCE.convert(this.deviceTypeService.updateDeviceType(deviceTypeUpdateVO)));
    }
 
    @GetResource({"/page"})
    @ApiOperation(value = "分页查询机器类型", notes = "分页查询机器类型", tags = {"机器类型"})
    public R<IPage<DeviceTypeVO>> pageDeviceType(@RequestParam(value = "keyWord", required = false) @ApiParam("关键词") String keyWord, @RequestParam(value = "status", required = false) @ApiParam("状态 1启用 0 停用") Integer status, Query query) {
        return R.data(this.deviceTypeService.pageDeviceType(keyWord, status, query));
    }
 
    @GetResource({"/detail/{id}"})
    @ApiOperation(value = "机器类型详情", notes = "机器类型详情", tags = {"机器类型"})
    public R<DeviceTypeVO> getDeviceTypeById(@PathVariable("id") String id) {
        return R.data(this.deviceTypeService.getDeviceTypeById(Long.valueOf(id)));
    }
 
    @PreAuth
    @DeleteResource
    @ApiOperation(value = "删除机器类型", notes = "删除机器类型", tags = {"机器类型"})
    public R<Boolean> deleteDeviceTypeByIds(@Validated @RequestBody DeviceTypeIdListVO deviceTypeIdListVO, @RequestParam("type") @ApiParam("删除传0 停用传1") Integer type) {
        return R.data(this.deviceTypeService.deleteDeviceTypeByIds(Func.toLongList(deviceTypeIdListVO.getIdList()), type));
    }
 
    @PreAuth
    @GetResource({"/export/template"})
    @ApiOperation("导出机器类型模板")
    public R<BladeFile> exportMaintainItemTemplate(HttpServletResponse response, BladeUser bladeUser) {
        return R.data(this.systemResourceService.getBusinessTemplateInfo(TemplateEnum.DEVICE_TYPE));
    }
 
    @PreAuth
    @PostResource({"/excel/export"})
    @ApiOperation(value = "导出机器类型", notes = "导出机器类型", tags = {"机器类型"})
    public R<BladeFile> export(@RequestBody DeviceTypeExcelVO deviceTypeExcelVO) {
        return R.data(this.deviceTypeService.export(deviceTypeExcelVO));
    }
 
    @PreAuth
    @PostResource({"/excel/import"})
    @ApiOperation(value = "导入机器类型", notes = "导入机器类型", tags = {"机器类型"})
    public R<BladeFile> importDeviceType(MultipartFile file) {
        List<DeviceTypeExcel> data = ExcelUtil.read(file, 0, 2, DeviceTypeExcel.class);
        return R.data(this.deviceTypeService.importDeviceType(data));
    }
}