yangys
2024-03-07 2f4053acadaea4eb13d74e516af5c4ed914879c1
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
package com.qianwen.mdc.controller.devicetype;
 
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianwen.mdc.common.OpResult;
import com.qianwen.mdc.dto.IdsDTO;
import com.qianwen.mdc.dto.devicetype.DeviceTypeDTO;
import com.qianwen.mdc.service.devicetype.DeviceTypeService;
import com.qianwen.mdc.vallidate.AddGroup;
import com.qianwen.mdc.vallidate.UpdateGroup;
 
/**
 * 设备类型管理控制器
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/devicetype")
public class DeviceTypeController {
    
    @Autowired
    private DeviceTypeService deviceTypeService;
 
    public static final Logger logger = LoggerFactory.getLogger(DeviceTypeController.class);
 
    @PostMapping(value = "/create")
    public OpResult<Void> create(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated(value = {AddGroup.class}) @RequestBody DeviceTypeDTO dto, HttpServletRequest request) {
        
        try {
            //accountTokenService.checkToken(token);
            deviceTypeService.save(dto);
        }catch(Exception ex) {
            logger.error("新增设备类型错误",ex);
            return OpResult.fail(ex.getMessage());
        }
        return OpResult.success();
    }
 
    @PostMapping(value = "/update")
    public OpResult<Void> update(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated(value = {UpdateGroup.class}) @RequestBody DeviceTypeDTO dto, HttpServletRequest request) {
        
        try {
            //accountTokenService.checkToken(token);
            deviceTypeService.modify(dto);
        }catch(Exception ex) {
            logger.error("修改设备类型错误",ex);
            return OpResult.fail(ex.getMessage());
        }
        return OpResult.success();
    }
    
    
    @PostMapping("/pageQuery")
    public OpResult<Page<DeviceTypeDTO>> pageQuery(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @RequestBody DeviceTypeDTO dto) {
        
        try {
            return OpResult.success(deviceTypeService.pageQuery(dto));
        }catch(Exception e) {
            logger.error("设备类型分页查询异常",e);
            return OpResult.fail(e.getMessage());
        }
        
    }
 
    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public OpResult<DeviceTypeDTO> get(@PathVariable("id") Integer id) {
        try {
            DeviceTypeDTO d = deviceTypeService.get(id);
            return OpResult.success(d);
        }catch(Exception e) {
            logger.error("设备类型详情查询异常",e);
            return OpResult.fail(e.getMessage());
        }
        
    }
    
    @GetMapping(value = "/list")
    public OpResult<List<DeviceTypeDTO>> list() {
        try {
            return OpResult.success(deviceTypeService.allList());
        }catch(Exception e) {
            logger.error("设备类型下拉i了表查询异常",e);
            return OpResult.fail(e.getMessage());
        }
        
    }
    
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public OpResult<Void> delete(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @RequestBody IdsDTO dto, HttpServletRequest request) {
        //accountTokenService.checkToken(token);@RequestParam List<Integer> ids
        
        try {
            deviceTypeService.delete(dto.getIds());
            return OpResult.success();
        }catch(Exception e) {
            logger.error("删除失败",e);
            return OpResult.fail(e.getMessage());
        }
    }
}