lyh
9 小时以前 78aeb8a8c97a884a640d46755e4be706bde48b7d
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
package com.lxzn.nc.controller;
 
 
import com.lxzn.api.nc.DeviceInfoControllerApi;
import com.lxzn.framework.domain.nc.DeviceInfo;
import com.lxzn.framework.domain.nc.response.DeviceCode;
import com.lxzn.framework.domain.ucenter.Department;
import com.lxzn.framework.domain.ucenter.User;
import com.lxzn.framework.domain.ucenter.ext.UserDepartExt;
import com.lxzn.framework.model.response.CommonCode;
import com.lxzn.framework.model.response.CommonGenericTree;
import com.lxzn.framework.model.response.QueryListResponseResult;
import com.lxzn.framework.model.response.ResponseResult;
import com.lxzn.nc.service.IDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Collections;
import java.util.List;
 
@RestController
@RequestMapping("/nc/device")
public class DeviceInfoController implements DeviceInfoControllerApi {
    @Autowired
    private IDeviceInfoService deviceInfoService;
 
    @Override
    @PostMapping("/add")
    public ResponseResult addDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        boolean b = deviceInfoService.addDeviceInfo(deviceInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PutMapping("/edit/{id}")
    public ResponseResult editDeviceInfo(@PathVariable("id") String id, @RequestBody DeviceInfo deviceInfo) {
        boolean b = deviceInfoService.editDeviceInfo(id, deviceInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @DeleteMapping("/delete")
    public ResponseResult deleteDeviceInfo(@RequestParam("id") String id) {
        boolean b = deviceInfoService.deleteDeviceInfo(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @GetMapping("/load/tree")
    public QueryListResponseResult<CommonGenericTree> loadTree() {
        List<CommonGenericTree> list = deviceInfoService.loadTree();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/get/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<UserDepartExt> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<UserDepartExt> list = deviceInfoService.getUserPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/get/non/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<User> getUserNonPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<User> list = deviceInfoService.getUserNonPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
 
 
    @Override
    @GetMapping("/check/{nodeType}/{paramId}")
    public ResponseResult checkDevicePerm(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
        boolean b = deviceInfoService.checkDevicePerm(nodeType, paramId);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.UNAUTHORISE);
    }
 
    @Override
    @PostMapping("/assign/add/user/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignAddUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = deviceInfoService.assignAddUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PostMapping("/assign/remove/user/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignRemoveUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = deviceInfoService.assignRemoveUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @GetMapping("/list/all")
    public QueryListResponseResult<DeviceInfo> findListAll() {
        List<DeviceInfo> list = deviceInfoService.list();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/load/depart/tree/{nodeType}/{paramId}")
    public QueryListResponseResult<CommonGenericTree> loadDepartTree(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
        List<CommonGenericTree> list = deviceInfoService.loadDepartTree(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/valid/device")
    public ResponseResult validateDeviceNo(String deviceNo) {
        DeviceInfo byDeviceNo = deviceInfoService.getByDeviceNo(deviceNo);
        if(byDeviceNo == null) {
            return new ResponseResult(DeviceCode.DEVICE_NOT_EXIST);
        }
        return new ResponseResult(CommonCode.SUCCESS);
    }
}