接口优化

This commit is contained in:
zhangzhicheng 2024-08-12 17:51:22 +08:00
parent 39dc86655c
commit 5ab83b6051
4 changed files with 31 additions and 27 deletions

View File

@ -19,6 +19,7 @@ import org.dromara.web.domain.vo.*;
import org.dromara.web.service.*;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -67,12 +68,25 @@ public class EqDeviceController extends BaseController {
public R<Boolean> bindDevice(EqAppHomeBo bo){
String equipmentCode = bo.getEquipmentCode();
if (equipmentCode == null) throw new ServiceException("设备编码不能为空");
if (bo.getUserId() == null) throw new ServiceException("用户ID不能为空");
if (bo.getAreaId() == null) throw new ServiceException("分布ID不能为空");
if (bo.getUserId() == null) throw new ServiceException("用户ID不能为空");//分享用户要使用家庭主体的用户id
return R.ok(eqEquipmentService.bindDevice(bo));
}
/**
*
* 删除设备
* 传参设备id
*/
@DeleteMapping("/delete")
public R<Boolean> delete(EqAppHomeBo bo){
if (bo.getEquipmentId() == null) throw new ServiceException("设备ID不能为空");
Long userId = LoginHelper.getUserId();
if (!userId.equals(bo.getUserId())){
return R.fail("删除失败,设备不属于当前用户");
}
return R.ok(eqEquipmentService.deleteWithValidByIds(Collections.singletonList(bo.getEquipmentId()),Boolean.FALSE));
}
/**
* 控制设备 灯光 控制
* 传参设备编码

View File

@ -95,16 +95,22 @@ public class EqHomeController extends BaseController {
*/
@PostMapping("/share")
public R<Void> share(@Validated(AddGroup.class) @RequestBody EqShareBo bo) {
if (bo.getSharedUserName() == null){
return R.fail("被分享者用户名不能为空");
}
SysUserVo sysUserVo = userService.selectUserByUserName(bo.getSharedUserName());
if (bo.getShareUserId() == null){
bo.setShareUserId(LoginHelper.getUserId());
bo.setShareUserName(LoginHelper.getUsername());
}
bo.setSharedUserId(sysUserVo.getUserId());
bo.setSharedUserName(sysUserVo.getUserName());
return toAjax(eqShareService.insertByBo(bo));
}
/**
* 删除被分享的成员
* @param sharedId
* @param sharedId 被分享者用户id
* @return
*/
@DeleteMapping("/{sharedId}")
@ -122,15 +128,16 @@ public class EqHomeController extends BaseController {
return R.ok(eqAreaService.queryList(bo));
}
/** todo
/**
* 首页查看设备列表
*/
@GetMapping("/list")
public TableDataInfo<EqEquipmentVo> list(EqAppHomeBo bo, PageQuery pageQuery){
//当前用户为家庭主体 切换用户后需要传输用户id
if (bo.getUserId() == null) bo.setUserId(LoginHelper.getUserId());
//TODO 下面返回的状态 会在设备状态变化时更新设备状态
EqEquipmentBo eqEquipmentBo = new EqEquipmentBo();
eqEquipmentBo.setCreateBy(bo.getUserId());
eqEquipmentBo.setUserId(bo.getUserId());
return eqEquipmentService.queryPageList(eqEquipmentBo, pageQuery); //在设备表中增加了分布id
}
@ -138,29 +145,11 @@ public class EqHomeController extends BaseController {
* 设备详情 (暂时无用)
* 传参 设备id
*/
@GetMapping("/info")
/*@GetMapping("/info")
public R<EqEquipmentVo> info(EqAppHomeBo bo){
if (bo.getEquipmentId() == null) throw new ServiceException("设备ID不能为空");
return R.ok(eqEquipmentService.queryById(bo.getEquipmentId()));
}
/**
*
* 删除设备
* 传参设备id
*/
@GetMapping("/delete")
public R<Boolean> delete(EqAppHomeBo bo){
if (bo.getEquipmentId() == null) throw new ServiceException("设备ID不能为空");
Long userId = LoginHelper.getUserId();
if (!userId.equals(bo.getUserId())){
return R.fail("删除失败,设备不属于当前用户");
}
return R.ok(eqEquipmentService.deleteWithValidByIds(Collections.singletonList(bo.getEquipmentId()),Boolean.FALSE));
}
}*/
/**
* 密码验证

View File

@ -12,7 +12,7 @@ import org.dromara.common.mybatis.core.domain.BaseEntity;
@Data
public class EqAppHomeBo extends BaseEntity{
/**
* 选取用户ID家庭主体ID
* 选取用户ID家庭主体ID 当前登录用户非家庭主体用户时该字段必传
*/
private Long userId;
/**

View File

@ -89,6 +89,7 @@ public class EqEquipmentServiceImpl implements IEqEquipmentService {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<EqEquipment> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getAreaId() != null, EqEquipment::getAreaId, bo.getAreaId());
lqw.eq(bo.getUserId() != null, EqEquipment::getUserId, bo.getUserId());
lqw.eq(bo.getType() != null, EqEquipment::getType, bo.getType());
lqw.like(StringUtils.isNotBlank(bo.getUserName()), EqEquipment::getUserName, bo.getUserName());
lqw.like(StringUtils.isNotBlank(bo.getNickName()), EqEquipment::getNickName, bo.getNickName());