设备分享问题修改

This commit is contained in:
zzc 2025-06-16 23:06:54 +08:00
parent f65fc0df5c
commit a11f8ef493

View File

@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.secure.BCrypt; import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
@ -250,17 +251,27 @@ public class EqHomeController extends BaseController {
SysUserVo sysUserVo = userService.selectUserByUserName(bo.getSharedUserName()); SysUserVo sysUserVo = userService.selectUserByUserName(bo.getSharedUserName());
if (sysUserVo==null) throw new RuntimeException("被分享者用户名不存在"); if (sysUserVo==null) throw new RuntimeException("被分享者用户名不存在");
if (bo.getShareUserId() == null){
bo.setShareUserId(LoginHelper.getUserId());
String currentUserName = LoginHelper.getUsername(); String currentUserName = LoginHelper.getUsername();
if (currentUserName.equals(bo.getSharedUserName())) throw new RuntimeException("不能分享给自己"); if (currentUserName.equals(bo.getSharedUserName())) throw new RuntimeException("不能分享给自己");
bo.setShareUserId(LoginHelper.getUserId());
/*if (bo.getShareUserId() == null){
bo.setShareUserId(LoginHelper.getUserId());
bo.setShareUserName(currentUserName); bo.setShareUserName(currentUserName);
} }*/
bo.setSharedUserId(sysUserVo.getUserId()); bo.setSharedUserId(sysUserVo.getUserId());
List<EqShareVo> eqShareVos = shareService.queryList(bo);
bo.setShareUserName(currentUserName);
bo.setSharedUserName(sysUserVo.getUserName()); bo.setSharedUserName(sysUserVo.getUserName());
// List<EqShareVo> eqShareVos = shareService.queryList(bo); if (CollUtil.isEmpty(eqShareVos)){
// if (!eqShareVos.isEmpty()) throw new RuntimeException("该成员已被分享");
return toAjax(shareService.insertByBo(bo)); return toAjax(shareService.insertByBo(bo));
}else{
EqShareVo eqShareVo = eqShareVos.get(0);
String sharedEquipmentIds = eqShareVo.getSharedEquipmentIds();
if (sharedEquipmentIds.contains(bo.getSharedEquipmentIds())) throw new RuntimeException("该设备已经分享到该成员");
sharedEquipmentIds = sharedEquipmentIds + "," + bo.getSharedEquipmentIds();
eqShareVo.setSharedEquipmentIds(sharedEquipmentIds);
return toAjax(shareService.updateByBo(bo));
}
} }
/** /**