mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
分享单个或全部设备功能实现,用户设备列表接口调整,新增别人分享给自己的设备
This commit is contained in:
@@ -69,7 +69,7 @@ public class DeviceController extends BaseController
|
||||
{
|
||||
list = deviceService.selectDeviceShortList(device);
|
||||
}else {
|
||||
// 精确查询
|
||||
// 精确查询
|
||||
list = deviceService.selectDeviceShortListAccurate(device);
|
||||
}
|
||||
return getDataTable(list);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.ruoyi.iot.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.iot.domain.Firmware;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -22,7 +20,6 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
import com.ruoyi.iot.service.IDeviceUserService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
@@ -53,7 +50,7 @@ public class DeviceUserController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备用户详细信息
|
||||
* 获取设备用户详细信息 根据deviceId 查询的话可能会查出多个
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/{deviceId}")
|
||||
@@ -63,6 +60,17 @@ public class DeviceUserController extends BaseController
|
||||
return AjaxResult.success(deviceUserService.selectDeviceUserByDeviceId(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备用户详细信息 双主键 device_id 和 user_id
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/{deviceId}/{userId}")
|
||||
@ApiOperation("获取设备用户详情,根据用户id 和 设备id")
|
||||
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId, @PathVariable("userId") Long userId)
|
||||
{
|
||||
return AjaxResult.success(deviceUserService.selectDeviceUserByDeviceIdAndUserId(deviceId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备用户
|
||||
*/
|
||||
@@ -75,6 +83,18 @@ public class DeviceUserController extends BaseController
|
||||
return toAjax(deviceUserService.insertDeviceUser(deviceUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增多个设备用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/addDeviceUsers")
|
||||
@ApiOperation("添加设备用户")
|
||||
public AjaxResult addDeviceUsers(@RequestBody List<DeviceUser> deviceUsers)
|
||||
{
|
||||
return toAjax(deviceUserService.insertDeviceUserList(deviceUsers));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备用户
|
||||
*/
|
||||
@@ -91,13 +111,13 @@ public class DeviceUserController extends BaseController
|
||||
/**
|
||||
* 删除设备用户
|
||||
*/
|
||||
@ApiOperation("批量删除设备用户")
|
||||
@ApiOperation("删除设备用户")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:remove')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{deviceIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] deviceIds)
|
||||
@DeleteMapping
|
||||
public AjaxResult remove(@RequestBody DeviceUser deviceUser)
|
||||
{
|
||||
int count=deviceUserService.deleteDeviceUserByDeviceIds(deviceIds);
|
||||
int count=deviceUserService.deleteDeviceUser(deviceUser);
|
||||
if(count==0){
|
||||
return AjaxResult.error("设备所有者不能删除");
|
||||
}else{
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.iot.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,7 @@ public interface DeviceUserMapper
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 设备用户
|
||||
*/
|
||||
public DeviceUser selectDeviceUserByDeviceId(Long deviceId);
|
||||
public List<DeviceUser> selectDeviceUserByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 查询设备用户列表
|
||||
@@ -60,4 +61,21 @@ public interface DeviceUserMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceUserByDeviceIds(Long[] deviceIds);
|
||||
|
||||
/**
|
||||
* 批量添加设备用户
|
||||
* @param deviceUsers 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceUserList(List<DeviceUser> deviceUsers);
|
||||
|
||||
/**
|
||||
* 根据deviceId 和 userId 查询
|
||||
* @param deviceId 设备id
|
||||
* @param userId 用户id
|
||||
* @return 结果
|
||||
*/
|
||||
public DeviceUser selectDeviceUserByDeviceIdAndUserId(@Param("deviceId") Long deviceId, @Param("userId") Long userId);
|
||||
|
||||
public int deleteDeviceUser(DeviceUser deviceUser);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface IDeviceUserService
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 设备用户
|
||||
*/
|
||||
public DeviceUser selectDeviceUserByDeviceId(Long deviceId);
|
||||
public List<DeviceUser> selectDeviceUserByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 查询设备用户列表
|
||||
@@ -58,4 +58,21 @@ public interface IDeviceUserService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceUserByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 批量添加设备用户
|
||||
* @param deviceUsers 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceUserList(List<DeviceUser> deviceUsers);
|
||||
|
||||
/**
|
||||
* 查询设备用户
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 设备用户
|
||||
*/
|
||||
public DeviceUser selectDeviceUserByDeviceIdAndUserId(Long deviceId, Long userId);
|
||||
|
||||
public int deleteDeviceUser(DeviceUser deviceUser);
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
// 精准查询所有条件的设备
|
||||
// 精准查询所有条件的设备
|
||||
@Override
|
||||
public List<DeviceShortOutput> selectDeviceShortListAccurate(Device device) {
|
||||
return deviceMapper.selectDeviceShortListAccurate(device);
|
||||
@@ -544,7 +544,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
public List<DeviceAllShortOutput> selectAllDeviceShortListAccurate(String userName) {
|
||||
return deviceMapper.selectAllDeviceShortListAccurate(userName);
|
||||
}
|
||||
// 精准查询
|
||||
// 精准查询 新增别人分享给自己的设备
|
||||
@Override
|
||||
public List<Device> selectDeviceListAccurate(Device device) {
|
||||
return deviceMapper.selectDeviceListAccurate(device);
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.ruoyi.iot.domain.DeviceUser;
|
||||
import com.ruoyi.iot.mapper.DeviceUserMapper;
|
||||
import com.ruoyi.iot.service.IDeviceUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
@@ -31,7 +33,7 @@ public class DeviceUserServiceImpl implements IDeviceUserService
|
||||
* @return 设备用户
|
||||
*/
|
||||
@Override
|
||||
public DeviceUser selectDeviceUserByDeviceId(Long deviceId)
|
||||
public List<DeviceUser> selectDeviceUserByDeviceId(Long deviceId)
|
||||
{
|
||||
return deviceUserMapper.selectDeviceUserByDeviceId(deviceId);
|
||||
}
|
||||
@@ -57,6 +59,8 @@ public class DeviceUserServiceImpl implements IDeviceUserService
|
||||
@Override
|
||||
public int insertDeviceUser(DeviceUser deviceUser)
|
||||
{
|
||||
List<DeviceUser> deviceUsers = selectDeviceUserList(deviceUser);
|
||||
if (!deviceUsers.isEmpty()) throw new RuntimeException("该用户已添加, 禁止重复添加");
|
||||
deviceUser.setCreateTime(DateUtils.getNowDate());
|
||||
deviceUser.setIsOwner(0);
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
@@ -101,4 +105,30 @@ public class DeviceUserServiceImpl implements IDeviceUserService
|
||||
{
|
||||
return deviceUserMapper.deleteDeviceUserByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertDeviceUserList(List<DeviceUser> deviceUsers) {
|
||||
try {
|
||||
deviceUsers.forEach(deviceUser -> {
|
||||
deviceUser.setCreateTime(DateUtils.getNowDate());
|
||||
deviceUser.setIsOwner(0);
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
deviceUser.setTenantId(sysUser.getUserId());
|
||||
deviceUser.setTenantName(sysUser.getUserName());
|
||||
});
|
||||
return deviceUserMapper.insertDeviceUserList(deviceUsers);
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw new RuntimeException("存在设备已经与用户绑定");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceUser selectDeviceUserByDeviceIdAndUserId(Long deviceId, Long userId) {
|
||||
return deviceUserMapper.selectDeviceUserByDeviceIdAndUserId(deviceId, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteDeviceUser(DeviceUser deviceUser) {
|
||||
return deviceUserMapper.deleteDeviceUser(deviceUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceListAccurate" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceResult">
|
||||
<include refid="selectDeviceVo"/>
|
||||
<where>
|
||||
<if test="deviceName != null and deviceName != ''"> and device_name = #{deviceName}</if>
|
||||
<if test="deviceName != null and deviceName != ''"> and device_name = #{deviceName} </if>
|
||||
<if test="productId != null "> and product_id = #{productId}</if>
|
||||
<if test="productName != null and productName != ''"> and product_name = #{productName}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
@@ -166,7 +167,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
|
||||
<if test="productId != null "> and product_id = #{productId}</if>
|
||||
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="userId != null ">
|
||||
and user_id = #{userId}
|
||||
or device_id in (select device_id from iot_device_user where iot_device_user.user_name = #{userName})
|
||||
</if>
|
||||
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
|
||||
<if test="tenantId != null "> and tenant_id = #{tenantId}</if>
|
||||
<if test="tenantName != null and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
|
||||
@@ -183,7 +187,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="productId != null "> and product_id = #{productId}</if>
|
||||
<if test="productName != null and productName != ''"> and product_name = #{productName}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="userName != null and userName != ''"> and user_name = #{userName}</if>
|
||||
<if test="userName != null and userName != ''">
|
||||
and user_name = #{userName}
|
||||
or device_id in (select device_id from iot_device_user where iot_device_user.user_name = #{userName})
|
||||
</if>
|
||||
<if test="tenantId != null "> and tenant_id = #{tenantId}</if>
|
||||
<if test="tenantName != null and tenantName != ''"> and tenant_name=#{tenantName}</if>
|
||||
<if test="serialNumber != null and serialNumber != ''"> and serial_number = #{serialNumber}</if>
|
||||
|
||||
@@ -36,10 +36,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectDeviceUserVo"/>
|
||||
where device_id = #{deviceId}
|
||||
</select>
|
||||
|
||||
<insert id="insertDeviceUser" parameterType="com.ruoyi.iot.domain.DeviceUser" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
|
||||
<select id="selectDeviceUserByDeviceIdAndUserId" resultMap="DeviceUserResult">
|
||||
<include refid="selectDeviceUserVo"/>
|
||||
where device_id = #{deviceId} and user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<insert id="insertDeviceUser" parameterType="com.ruoyi.iot.domain.DeviceUser" keyProperty="deviceId">
|
||||
insert into iot_device_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="deviceId != null">device_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="deviceName != null and deviceName != ''">device_name,</if>
|
||||
<if test="userName != null and userName != ''">user_name,</if>
|
||||
@@ -55,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="deviceId != null">#{deviceId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||||
<if test="userName != null and userName != ''">#{userName},</if>
|
||||
@@ -71,6 +78,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertDeviceUserList" parameterType="java.util.ArrayList">
|
||||
insert into iot_device_user
|
||||
(device_id, user_id, device_name, user_name, is_owner,tenant_id,tenant_name,phonenumber, create_time) values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.deviceId},#{item.userId},#{item.deviceName}, #{item.userName}, #{item.isOwner}, #{item.tenantId},#{item.tenantName},#{item.phonenumber}, #{item.createTime})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateDeviceUser" parameterType="com.ruoyi.iot.domain.DeviceUser">
|
||||
update iot_device_user
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
@@ -88,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
where device_id = #{deviceId} and user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteDeviceUserByDeviceId" parameterType="Long">
|
||||
@@ -101,4 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{deviceId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteDeviceUser">
|
||||
delete from iot_device_user where device_id = #{deviceId} and is_owner !=1 and user_id = #{userId}
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user