物联用户权限功能添加
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.njcn.cssystem.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class WlUserParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty(value = "工程id集合")
|
||||
private List<String> engineeringList;
|
||||
|
||||
@ApiModelProperty(value = "便携式设备id")
|
||||
private List<String> portableDevList;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.cssystem.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class WlUserVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "工程集合")
|
||||
private List<EngineeringVo> engineeringList;
|
||||
|
||||
@ApiModelProperty(value = "便携式设备集合")
|
||||
private List<portableDevVo> portableDevList;
|
||||
|
||||
|
||||
@Data
|
||||
public static class EngineeringVo implements Serializable{
|
||||
|
||||
@ApiModelProperty(value = "工程id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "工程名称")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class portableDevVo implements Serializable{
|
||||
|
||||
@ApiModelProperty(value = "设备id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "设备名称")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.njcn.cssystem.controller;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.cssystem.pojo.param.WlUserParam;
|
||||
import com.njcn.cssystem.pojo.vo.WlUserVo;
|
||||
import com.njcn.cssystem.service.IWlUserService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-11-12
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wlUser")
|
||||
@Api(tags = "用户设备分配")
|
||||
@AllArgsConstructor
|
||||
public class WlUserController extends BaseController {
|
||||
|
||||
private final IWlUserService wlUserService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
|
||||
@PostMapping("/selectDevByUserId")
|
||||
@ApiOperation("根据用户id查询工程和便携式设备")
|
||||
@ApiImplicitParam(name = "userId", value = "用户id", required = true)
|
||||
public HttpResult<WlUserVo> selectDevByUserId(@RequestParam @Validated String userId ) {
|
||||
String methodDescribe = getMethodDescribe("selectDevByUserId");
|
||||
LogUtil.njcnDebug(log, "{},用户数据为:{}", methodDescribe, userId);
|
||||
WlUserVo vo = wlUserService.selectDevByUserId(userId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/addUserDev")
|
||||
@ApiOperation("用户绑定工程和便携式设备")
|
||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||
public HttpResult<WlUserVo> addUserDev(@RequestBody @Validated WlUserParam param) {
|
||||
String methodDescribe = getMethodDescribe("addUserDev");
|
||||
LogUtil.njcnDebug(log, "{},参数:{}", methodDescribe, param);
|
||||
wlUserService.addUserDev(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
|
||||
@PostMapping("/deleteUserDev")
|
||||
@ApiOperation("用户取消绑定工程和便携式设备")
|
||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||
public HttpResult<WlUserVo> deleteUserDev(@RequestBody @Validated WlUserParam param) {
|
||||
String methodDescribe = getMethodDescribe("deleteUserDev");
|
||||
LogUtil.njcnDebug(log, "{},参数:{}", methodDescribe, param);
|
||||
wlUserService.deleteUserDev(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.cssystem.service;
|
||||
|
||||
import com.njcn.cssystem.pojo.param.WlUserParam;
|
||||
import com.njcn.cssystem.pojo.vo.WlUserVo;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IWlUserService {
|
||||
|
||||
WlUserVo selectDevByUserId(String userId);
|
||||
|
||||
void addUserDev(WlUserParam param);
|
||||
|
||||
void deleteUserDev(WlUserParam param);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.param.UserDevParam;
|
||||
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
|
||||
import com.njcn.cssystem.pojo.param.WlUserParam;
|
||||
import com.njcn.cssystem.pojo.vo.WlUserVo;
|
||||
import com.njcn.cssystem.service.IWlUserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class WlUserServiceImpl implements IWlUserService {
|
||||
|
||||
private final CsDeviceUserFeignClient csDeviceUserFeignClient;
|
||||
private final CsLedgerFeignClient csLedgerFeignClient;
|
||||
|
||||
@Override
|
||||
public WlUserVo selectDevByUserId(String userId) {
|
||||
WlUserVo wlUserVo = new WlUserVo();
|
||||
List<WlUserVo.EngineeringVo> list1 = new ArrayList<>();
|
||||
List<WlUserVo.portableDevVo> list2 = new ArrayList<>();
|
||||
//根据用户信息获取设备信息
|
||||
List<String> devList = csDeviceUserFeignClient.findDevByUserId(userId).getData();
|
||||
//根据设备查询工程信息
|
||||
if (CollectionUtil.isNotEmpty(devList)) {
|
||||
List<DevDetailDTO> ledger = csLedgerFeignClient.getInfoByIds(devList).getData();
|
||||
ledger.forEach(item->{
|
||||
if (Objects.equals(item.getEngineeringid(),"/")) {
|
||||
WlUserVo.portableDevVo portableDevVo = new WlUserVo.portableDevVo();
|
||||
portableDevVo.setId(item.getEquipmentId());
|
||||
portableDevVo.setName(item.getEquipmentName());
|
||||
list2.add(portableDevVo);
|
||||
} else {
|
||||
WlUserVo.EngineeringVo engineeringVo = new WlUserVo.EngineeringVo();
|
||||
engineeringVo.setId(item.getEngineeringid());
|
||||
engineeringVo.setName(item.getEngineeringName());
|
||||
list1.add(engineeringVo);
|
||||
}
|
||||
});
|
||||
}
|
||||
wlUserVo.setEngineeringList(list1);
|
||||
wlUserVo.setPortableDevList(list2);
|
||||
return wlUserVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserDev(WlUserParam param) {
|
||||
List<String> devList = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(param.getEngineeringList())) {
|
||||
//根据工程id获取设备id
|
||||
List<DevDetailDTO> dto = csLedgerFeignClient.getDevInfoByEngineerIds(param.getEngineeringList()).getData();
|
||||
if (CollectionUtil.isNotEmpty(dto)) {
|
||||
devList.addAll(dto.stream().map(DevDetailDTO::getEquipmentId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(param.getPortableDevList())) {
|
||||
devList.addAll(param.getPortableDevList());
|
||||
}
|
||||
//存储用户和设备的关系
|
||||
if (CollectionUtil.isNotEmpty(devList)) {
|
||||
List<CsDeviceUserPO> list = new ArrayList<>();
|
||||
devList.forEach(item->{
|
||||
CsDeviceUserPO po = new CsDeviceUserPO();
|
||||
po.setPrimaryUserId(param.getUserId());
|
||||
po.setSubUserId(param.getUserId());
|
||||
po.setDeviceId(item);
|
||||
po.setStatus("1");
|
||||
list.add(po);
|
||||
});
|
||||
csDeviceUserFeignClient.add(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserDev(WlUserParam param) {
|
||||
List<String> devList = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(param.getEngineeringList())) {
|
||||
//根据工程id获取设备id
|
||||
List<DevDetailDTO> dto = csLedgerFeignClient.getDevInfoByEngineerIds(param.getEngineeringList()).getData();
|
||||
if (CollectionUtil.isNotEmpty(dto)) {
|
||||
devList.addAll(dto.stream().map(DevDetailDTO::getEquipmentId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(param.getPortableDevList())) {
|
||||
devList.addAll(param.getPortableDevList());
|
||||
}
|
||||
//解绑用户和设备的关系
|
||||
if (CollectionUtil.isNotEmpty(devList)) {
|
||||
UserDevParam par = new UserDevParam();
|
||||
par.setUserId(param.getUserId());
|
||||
par.setList(devList);
|
||||
csDeviceUserFeignClient.channelDevByUserId(par);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user