提交代码,设备权限分享
This commit is contained in:
@@ -25,6 +25,9 @@ public enum AlgorithmResponseEnum {
|
||||
FILE_SIZE_ERROR ("A00507","文件不能超过10M"),
|
||||
|
||||
DATA_EXIST ("A00508","删除失败,有子数据"),
|
||||
LOSE_EFFICACY ("A00509","二维码失效,该设备已绑定"),
|
||||
DATA_LOSE ("A00510","未找到设备与主用户信息"),
|
||||
REPEAT_SHARE ("A00511","设备已分享完成,请勿再次分享"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.Date;
|
||||
@@ -22,7 +23,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@TableName(value = "cs_device_user")
|
||||
public class CsDeviceUserPO {
|
||||
public class CsDeviceUserPO extends BaseEntity {
|
||||
/**
|
||||
* 主用户id
|
||||
*/
|
||||
@@ -44,21 +45,7 @@ public class CsDeviceUserPO {
|
||||
@ApiModelProperty(value="装置Id")
|
||||
private String deviceId;
|
||||
|
||||
@TableField(value = "create_by")
|
||||
@ApiModelProperty(value="")
|
||||
private String createBy;
|
||||
|
||||
@TableField(value = "create_time")
|
||||
@ApiModelProperty(value="")
|
||||
private Date createTime;
|
||||
|
||||
@TableField(value = "update_by")
|
||||
@ApiModelProperty(value="")
|
||||
private String updateBy;
|
||||
|
||||
@TableField(value = "update_time")
|
||||
@ApiModelProperty(value="")
|
||||
private Date updateTime;
|
||||
|
||||
public static final String COL_PRIMARY_USER_ID = "primary_user_id";
|
||||
|
||||
|
||||
@@ -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