李林
2024-03-06 d83e2977769b3d56f4ca6fdbf798e22d3940e003
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
package com.yuanchu.mom.controller;
 
 
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.pojo.Device;
import com.yuanchu.mom.service.DeviceService;
import com.yuanchu.mom.utils.JackSonUtil;
import com.yuanchu.mom.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 设备(DeviceController)表控制层
 */
@Api(tags = "设备")
@RestController
@RequestMapping("/deviceScope")
public class DeviceController {
 
 
    @Resource
    private DeviceService deviceService;
 
    @Value("${file.path}")
    private String filePath;
 
    @ApiOperation(value = "查询设备详情列表")
    @PostMapping("/selectDeviceParameter")
    public Result selectDeviceParameter(@RequestBody Map<String, Object> data) throws Exception {
        Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
        Device itemParameter = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), Device.class);
        return Result.success(deviceService.selectDeviceParameter(page, itemParameter));
    }
 
    @ApiOperation(value = "添加设备详情参数")
    @PostMapping("/addDeviceParameter")
    public Result addDeviceParameter(@RequestBody Device itemParameter) {
        return Result.success(deviceService.addDeviceParameter(itemParameter));
    }
 
    @ApiOperation(value = "删除设备详情参数")
    @PostMapping("/delDeviceParameter")
    public Result<?> delDeviceParameter(Integer id) {
        return Result.success(deviceService.delDeviceParameter(id));
    }
 
    @ApiOperation(value = "修改设备详情参数")
    @PostMapping("/upDeviceParameter")
    public Result<?> upDeviceParameter(@RequestBody Device itemParameter) {
        return Result.success(deviceService.upDeviceParameter(itemParameter));
    }
 
    @ApiOperation(value = "获取设备总览")
    @GetMapping("/selectEquipmentOverview")
    @ValueAuth
    public Result selectEquipmentOverview() {
        return Result.success(deviceService.selectEquipmentOverview());
    }
 
    @ApiOperation(value = "获取被授权人")
    @GetMapping("/authorizedPerson")
    @ValueAuth
    public Result authorizedPerson() {
        return Result.success(deviceService.authorizedPerson());
    }
 
    @ApiOperation(value = "搜索")
    @GetMapping("/search")
    @ValueAuth
    public Result search(Integer status, String deviceName, String specificationModel, String largeCategory) {
        return Result.success(deviceService.search(status, deviceName, specificationModel, largeCategory));
    }
 
    //图片上传
    @ApiOperation(value = "设备图片上传")
    @PostMapping("/uploadFile")
    public Result uploadFile(MultipartFile file) {
        String urlString;
        String pathName;
        String filename = file.getOriginalFilename();
        try {
            String path = filePath;
            File realpath = new File(path);
            if (!realpath.exists()) {
                realpath.mkdirs();
            }
            pathName = UUID.randomUUID() + "_" + file.getOriginalFilename();
            urlString = realpath + "/" + pathName;
            file.transferTo(new File(urlString));
            HashMap<String, String> map = new HashMap<>();
            map.put("name", filename);
            map.put("url", pathName);
            return Result.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("图片上传错误");
            return null;
        }
    }
 
    @ApiOperation(value = "获取设备负责人")
    @GetMapping("/selectDevicePrincipal")
    @ValueAuth
    public Result selectDevicePrincipal() {
        return Result.success(deviceService.selectDevicePrincipal());
    }
}