分享设备暂时提交
parent
e07f0c1ebd
commit
965e6d542c
|
|
@ -10,6 +10,7 @@ import com.agri.common.utils.poi.ExcelUtil;
|
|||
import com.agri.system.domain.SysAgriInfo;
|
||||
import com.agri.system.domain.SysUserAgri;
|
||||
import com.agri.system.domain.vo.AgriInfoView;
|
||||
import com.agri.system.domain.vo.AgriShareInfoVO;
|
||||
import com.agri.system.service.ISysAgriInfoService;
|
||||
import com.agri.system.service.ISysUserAgriService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -168,4 +169,14 @@ public class SysAgriInfoController extends BaseController
|
|||
|
||||
return update? success():error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备分享信息(可分享列表 + 分享给我的设备列表)
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('assets:agri:list')")
|
||||
@GetMapping("/selectShareInfo")
|
||||
public AjaxResult selectShareInfo() {
|
||||
AgriShareInfoVO result = sysAgriInfoService.selectShareInfoByUser();
|
||||
return success(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,4 +73,11 @@ public interface SysAgriInfoMapper extends BaseMapper<SysAgriInfo> {
|
|||
public List<AgriInfoView> findAgriInfoByUser(SysAgriInfo sysAgriInfo);
|
||||
|
||||
List<AgriAutoInfoVo> findAgriOfAutoInfo();
|
||||
|
||||
/**
|
||||
* 查询设备分享列表(我的分享 + 分享给我的),带shared_count
|
||||
* @param sysAgriInfo 查询条件
|
||||
* @return 设备分享列表
|
||||
*/
|
||||
List<com.agri.system.domain.vo.AgriShareInfoVO.DeviceShareInfo> selectShareList(SysAgriInfo sysAgriInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.agri.system.service;
|
|||
import com.agri.system.domain.SysAgriInfo;
|
||||
import com.agri.system.domain.vo.AgriAutoInfoVo;
|
||||
import com.agri.system.domain.vo.AgriInfoView;
|
||||
import com.agri.system.domain.vo.AgriShareInfoVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -74,4 +75,10 @@ public interface ISysAgriInfoService extends IService<SysAgriInfo> {
|
|||
|
||||
|
||||
List<String> queryImeiByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询设备分享信息(可分享列表 + 分享给我的设备列表)
|
||||
* @return 设备分享信息
|
||||
*/
|
||||
AgriShareInfoVO selectShareInfoByUser();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.agri.system.domain.SysAgriInfo;
|
|||
import com.agri.system.domain.SysUserAgri;
|
||||
import com.agri.system.domain.vo.AgriAutoInfoVo;
|
||||
import com.agri.system.domain.vo.AgriInfoView;
|
||||
import com.agri.system.domain.vo.AgriShareInfoVO;
|
||||
import com.agri.system.mapper.SysAgriInfoMapper;
|
||||
import com.agri.system.service.ISysAgriInfoService;
|
||||
import com.agri.system.service.ISysUserAgriService;
|
||||
|
|
@ -295,4 +296,36 @@ public class SysAgriInfoServiceImpl extends ServiceImpl<SysAgriInfoMapper, SysAg
|
|||
}
|
||||
return agriInfos.stream().map(SysAgriInfo::getImei).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备分享信息(可分享列表 + 分享给我的设备列表)
|
||||
*/
|
||||
@Override
|
||||
public AgriShareInfoVO selectShareInfoByUser() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
AgriShareInfoVO result = new AgriShareInfoVO();
|
||||
|
||||
// 一次查询获取所有设备(我是成员 或 我是邀请人)
|
||||
SysAgriInfo query = new SysAgriInfo();
|
||||
query.setUserId(userId);
|
||||
query.setStatus(1);
|
||||
List<AgriShareInfoVO.DeviceShareInfo> allDevices = baseMapper.selectShareList(query);
|
||||
|
||||
// 根据 inviteBy 字段拆分
|
||||
// 我的分享:invite_by = userId(我是邀请人/owner)
|
||||
List<AgriShareInfoVO.DeviceShareInfo> mySharedDevices = allDevices.stream()
|
||||
.filter(device -> userId.equals(device.getInviteBy()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 分享给我的:invite_by != userId 且 invite_by != null(别人邀请我)
|
||||
List<AgriShareInfoVO.DeviceShareInfo> toMeDevices = allDevices.stream()
|
||||
.filter(device -> device.getInviteBy() != null
|
||||
&& !userId.equals(device.getInviteBy()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
result.setMySharedDevices(mySharedDevices);
|
||||
result.setToMeDevices(toMeDevices);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,4 +237,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and agri.work_mode = 1
|
||||
</select>
|
||||
|
||||
<!-- 查询设备分享列表(我的分享 + 分享给我的),带shared_count -->
|
||||
<select id="selectShareList" parameterType="SysAgriInfo" resultType="com.agri.system.domain.vo.AgriShareInfoVO$DeviceShareInfo">
|
||||
SELECT
|
||||
agri.id,
|
||||
agri.imei,
|
||||
agri.agri_name,
|
||||
agri.work_mode,
|
||||
agri.alarm_status as device_status,
|
||||
agri.install_time,
|
||||
agri.location,
|
||||
user_agri.status,
|
||||
user_agri.invite_by,
|
||||
user_agri.user_id,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM sys_user_agri sua2
|
||||
WHERE sua2.agri_id = agri.imei
|
||||
AND sua2.invite_by = #{userId}
|
||||
AND sua2.user_id != #{userId}
|
||||
AND sua2.status = #{status}
|
||||
) as shared_count
|
||||
FROM sys_agri_info agri
|
||||
LEFT JOIN sys_user_agri user_agri ON user_agri.agri_id = agri.imei
|
||||
<where>
|
||||
agri.is_deleted = 0
|
||||
AND user_agri.status = #{status}
|
||||
AND (user_agri.user_id = #{userId} OR user_agri.invite_by = #{inviteBy})
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue