提交代码,设备权限分享
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.njcn.csdevice.controller.equipment;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
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.csdevice.pojo.param.CsEquipmentTransferAddParm;
|
||||
import com.njcn.csdevice.service.CsDeviceUserPOService;
|
||||
import com.njcn.csdevice.service.CsEquipmentTransferPOService;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* (cs_equipment_transfer)表控制层
|
||||
*
|
||||
* @author xxxxx
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/deviceUser")
|
||||
@Api(tags = " 设备用户操作")
|
||||
@AllArgsConstructor
|
||||
public class DeviceUserController extends BaseController {
|
||||
|
||||
private final CsDeviceUserPOService csDeviceUserPOService;
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增设备扫码设备用户绑定")
|
||||
@ApiImplicitParam(name = "id", value = "设备id", required = true)
|
||||
public HttpResult<Boolean> add(@RequestParam("id") String id){
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
|
||||
Boolean flag = csDeviceUserPOService.add (id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||
}
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/share")
|
||||
@ApiOperation("设备扫码分享")
|
||||
@ApiImplicitParam(name = "id", value = "设备id", required = true)
|
||||
public HttpResult<Boolean> share(@RequestParam("id") String id){
|
||||
String methodDescribe = getMethodDescribe("share");
|
||||
|
||||
Boolean flag = csDeviceUserPOService.share (id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class CsTouristDataPOController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增游客数据")
|
||||
@ApiImplicitParam(name = "csTouristDataParm", value = "新增工程参数", required = true)
|
||||
@ApiImplicitParam(name = "csTouristDataParms", value = "新增工程参数", required = true)
|
||||
public HttpResult<Boolean> add(@Validated @RequestBody List<CsTouristDataParm> csTouristDataParms){
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
|
||||
|
||||
@@ -13,4 +13,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface CsDeviceUserPOService extends IService<CsDeviceUserPO>{
|
||||
|
||||
|
||||
}
|
||||
Boolean add(String id);
|
||||
|
||||
Boolean share(String id);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
|
||||
import com.njcn.csdevice.mapper.CsDeviceUserPOMapper;
|
||||
import com.njcn.csdevice.service.CsDeviceUserPOService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
@@ -14,6 +26,44 @@ import com.njcn.csdevice.service.CsDeviceUserPOService;
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CsDeviceUserPOServiceImpl extends ServiceImpl<CsDeviceUserPOMapper, CsDeviceUserPO> implements CsDeviceUserPOService{
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean add(String id) {
|
||||
CsDeviceUserPO one = this.lambdaQuery().eq(CsDeviceUserPO::getDeviceId, id).one();
|
||||
if(!Objects.isNull(one)){
|
||||
throw new BusinessException(AlgorithmResponseEnum.LOSE_EFFICACY);
|
||||
}
|
||||
String userIndex = RequestUtil.getUserIndex();
|
||||
CsDeviceUserPO csDevice = new CsDeviceUserPO();
|
||||
//设备PrimaryUserId与SubUserId相同就是主用户
|
||||
csDevice.setDeviceId(id);
|
||||
csDevice.setPrimaryUserId(userIndex);
|
||||
csDevice.setSubUserId(userIndex);
|
||||
boolean save = this.save(csDevice);
|
||||
return save;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean share(String id) {
|
||||
List<CsDeviceUserPO> list = this.lambdaQuery().eq(CsDeviceUserPO::getDeviceId, id).list();
|
||||
if(CollectionUtils.isEmpty(list)){
|
||||
throw new BusinessException(AlgorithmResponseEnum.DATA_LOSE);
|
||||
|
||||
}
|
||||
String userIndex = RequestUtil.getUserIndex();
|
||||
CsDeviceUserPO one = this.lambdaQuery().eq(CsDeviceUserPO::getDeviceId, id).eq(CsDeviceUserPO::getSubUserId,userIndex).one();
|
||||
if(!Objects.isNull(one)){
|
||||
throw new BusinessException(AlgorithmResponseEnum.REPEAT_SHARE);
|
||||
}
|
||||
CsDeviceUserPO csDeviceUserPO = list.get(0);
|
||||
csDeviceUserPO.setSubUserId(userIndex);
|
||||
boolean save = this.save(csDeviceUserPO);
|
||||
|
||||
return save;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user