zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/controller/DeviceInfoController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,181 @@
package org.jeecg.modules.dnc.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.dnc.entity.DeviceInfo;
import org.jeecg.modules.dnc.response.*;
import org.jeecg.modules.dnc.service.IDeviceInfoService;
import org.jeecg.modules.dnc.service.IDevicePermissionService;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
@Slf4j
@Api(tags = "设备表")
@RestController
@RequestMapping("/nc/device")
public class DeviceInfoController extends JeecgController<DeviceInfo, IDeviceInfoService> {
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDevicePermissionService devicePermissionService;
    @AutoLog(value = "设备表-新增设备")
    @ApiOperation(value = "设备表-新增设备", notes = "设备表-新增设备")
    @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);
    }
    @AutoLog(value = "设备表-编辑设备信息")
    @ApiOperation(value = "设备表-编辑设备信息", notes = "设备表-编辑设备信息")
    @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);
    }
    @AutoLog(value = "设备表-删除设备")
    @ApiOperation(value = "设备表-删除设备", notes = "设备表-删除设备")
    @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);
    }
    @AutoLog(value = "设备表-根据用户权限获取树")
    @ApiOperation(value = "设备表-根据用户权限获取树", notes = "设备表-根据用户权限获取树")
    @GetMapping("/load/tree")
    public QueryListResponseResult<CommonGenericTree> loadTree() {
        List<CommonGenericTree> list = deviceInfoService.loadTree();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
    @AutoLog(value = "设备表-获取节点已分配的用户")
    @ApiOperation(value = "设备表-获取节点已分配的用户", notes = "设备表-获取节点已分配的用户")
    @GetMapping("/get/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<SysUser> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<SysUser> list = deviceInfoService.getUserPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
    @AutoLog(value = "设备表-获取节点未分配的用户")
    @ApiOperation(value = "设备表-获取节点未分配的用户", notes = "设备表-获取节点未分配的用户")
    @GetMapping("/get/non/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<SysUser> getUserNonPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<SysUser> list = deviceInfoService.getUserNonPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
    /**
     * æ£€æŸ¥ç”¨æˆ·æ˜¯å¦æœ‰è¯¥è®¾å¤‡çš„æƒé™
     * @param nodeType 1 è®¾å¤‡åˆ†ç»„ 2 è®¾å¤‡
     * @param paramId
     * @return
     */
    @AutoLog(value = "设备表-检查用户是否有该设备的权限 1 è®¾å¤‡åˆ†ç»„ 2 è®¾å¤‡")
    @ApiOperation(value = "设备表-检查用户是否有该设备的权限 1 è®¾å¤‡åˆ†ç»„ 2 è®¾å¤‡", notes = "设备表-检查用户是否有该设备的权限 1 è®¾å¤‡åˆ†ç»„ 2 è®¾å¤‡")
    @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);
    }
    @AutoLog(value = "设备表-增加设备树节点的用户权限")
    @ApiOperation(value = "设备表-增加设备树节点的用户权限", notes = "设备表-增加设备树节点的用户权限")
    @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);
    }
    @AutoLog(value = "设备表-删除设备树节点的用户权限")
    @ApiOperation(value = "设备表-删除设备树节点的用户权限", notes = "设备表-删除设备树节点的用户权限")
    @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);
    }
    @AutoLog(value = "设备表-全部设备列表")
    @ApiOperation(value = "设备表-全部设备列表", notes = "设备表-全部设备列表")
    @GetMapping("/list/all")
    public QueryListResponseResult<DeviceInfo> findListAll() {
        List<DeviceInfo> list = deviceInfoService.list();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
    @AutoLog(value = "设备表-指派到设备 è®¾å¤‡æ ‘")
    @ApiOperation(value = "设备表-指派到设备 è®¾å¤‡æ ‘", notes = "设备表-指派到设备 è®¾å¤‡æ ‘")
    @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);
    }
    @AutoLog(value = "设备表-获取唯一 è®¾å¤‡ç¼–号")
    @ApiOperation(value = "设备表-获取唯一 è®¾å¤‡ç¼–号", notes = "设备表-获取唯一 è®¾å¤‡ç¼–号")
    @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);
    }
    /**
     * åŠ è½½äº§çº¿è®¾å¤‡æ ‘
     */
    @AutoLog(value = "设备表-加载产线设备树")
    @ApiOperation(value = "设备表-加载产线设备树", notes = "设备表-加载产线设备树")
    @GetMapping(value = "/queryTreeListByProduction")
    public Result<List<MdcEquipmentTree>> queryTreeListByProduction() {
        Result<List<MdcEquipmentTree>> result = new Result<>();
        try {
            List<MdcEquipmentTree> mdcEquipmentTreeList = devicePermissionService.DncLoadTreeListByProduction();
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
            return Result.error("加载产线设备树失败!" + e.getMessage());
        }
        return result;
    }
}