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 loadTree() { List list = deviceInfoService.loadTree(); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult(CommonCode.SUCCESS, list); } @Override @GetMapping("/get/perm/user/{nodeType}/{paramId}") public QueryListResponseResult getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) { List 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 getUserNonPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) { List 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 findListAll() { List list = deviceInfoService.list(); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult(CommonCode.SUCCESS, list); } @Override @GetMapping("/load/depart/tree/{nodeType}/{paramId}") public QueryListResponseResult loadDepartTree(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) { List 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); } }