多租户接口调整

This commit is contained in:
kerwincui
2022-06-04 00:51:14 +08:00
parent 4999c2abcb
commit 46aa17f320
12 changed files with 56 additions and 113 deletions

View File

@@ -6,9 +6,9 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
url: jdbc:mysql://localhost/wumei-smart?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://kerwincui.mysql.rds.aliyuncs.com/wumei-smart?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: kerwincui
password: admin password: 1a2b3c4D
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭
@@ -22,7 +22,7 @@ spring:
# 默认不启用TDenginetrue=启用false=不启用 # 默认不启用TDenginetrue=启用false=不启用
enabled: false enabled: false
driverClassName: com.taosdata.jdbc.TSDBDriver driverClassName: com.taosdata.jdbc.TSDBDriver
url: jdbc:TAOS://127.0.0.1:6030/wumei_smart_log?timezone=Asia/Beijing&charset=utf-8 url: jdbc:TAOS://wumei.live:6030/wumei_smart_log?timezone=Asia/Beijing&charset=utf-8
username: root username: root
password: taosdata password: taosdata
dbName: wumei_smart_log dbName: wumei_smart_log

View File

@@ -9,7 +9,7 @@ ruoyi:
# 实例演示开关 # 实例演示开关
demoEnabled: true demoEnabled: true
# 文件路径以uploadPath结尾 示例( Windows配置D:/wumei-smart/uploadPathLinux配置 /var/wumei-smart/java/uploadPath # 文件路径以uploadPath结尾 示例( Windows配置D:/wumei-smart/uploadPathLinux配置 /var/wumei-smart/java/uploadPath
profile: /var/wumei-smart/java/uploadPath profile: D:/wumei-smart/uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: true addressEnabled: true
# 验证码类型 math 数组计算 char 字符验证 # 验证码类型 math 数组计算 char 字符验证
@@ -59,13 +59,13 @@ spring:
# redis 配置 # redis 配置
redis: redis:
# 地址 # 地址
host: localhost host: wumei.live
# 端口默认为6379 # 端口默认为6379
port: 6379 port: 6379
# 数据库索引 # 数据库索引
database: 0 database: 0
# 密码 # 密码
password: wumei-smart password: 1a2b3c4D
# 连接超时时间 # 连接超时时间
timeout: 10s timeout: 10s
lettuce: lettuce:
@@ -82,7 +82,7 @@ spring:
mqtt: mqtt:
username: wumei-smart # 账号 username: wumei-smart # 账号
password: wumei-smart # 密码 password: wumei-smart # 密码
host-url: tcp://localhost:1883 # mqtt连接tcp地址 host-url: tcp://wumei.live:1883 # mqtt连接tcp地址
client-id: ${random.int} # 客户端Id不能相同采用随机数 ${random.value} client-id: ${random.int} # 客户端Id不能相同采用随机数 ${random.value}
default-topic: test # 默认主题 default-topic: test # 默认主题
timeout: 30000 # 超时时间 timeout: 30000 # 超时时间

View File

@@ -60,16 +60,9 @@ public class CategoryController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:category:list')") @PreAuthorize("@ss.hasPermi('iot:category:list')")
@GetMapping("/shortlist") @GetMapping("/shortlist")
@ApiOperation("分类简短列表") @ApiOperation("分类简短列表")
public AjaxResult shortlist(Category category) public AjaxResult shortlist()
{ {
List<IdAndName> list = new ArrayList<>(); return AjaxResult.success(categoryService.selectCategoryShortList());
if(category.getTenantName()==""||category.getTenantName()==null)
{
list = categoryService.selectCategoryShortList();
}else {
list = categoryService.selectCategoryShortListAccurate(category);
}
return AjaxResult.success(list);
} }
/** /**

View File

@@ -65,16 +65,9 @@ public class DeviceController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:device:list')") @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/all") @GetMapping("/all")
@ApiOperation("查询所有设备简短列表") @ApiOperation("查询所有设备简短列表")
public TableDataInfo allShortList(Device device) public TableDataInfo allShortList()
{ {
List<DeviceAllShortOutput> list = new ArrayList<>(); return getDataTable(deviceService.selectAllDeviceShortList());
if(device.getUserName()==null || device.getUserName().equals(""))
{
list = deviceService.selectAllDeviceShortList();
}else {
list = deviceService.selectAllDeviceShortListAccurate(device.getUserName());
}
return getDataTable(list);
} }
/** /**

View File

@@ -36,7 +36,7 @@ public interface CategoryMapper
* *
* @return 产品分类集合 * @return 产品分类集合
*/ */
public List<IdAndName> selectCategoryShortList(); public List<IdAndName> selectCategoryShortList(Category category);
/** /**
* 新增产品分类 * 新增产品分类
@@ -78,5 +78,4 @@ public interface CategoryMapper
*/ */
public int productCountInCategorys(Long[] categoryIds); public int productCountInCategorys(Long[] categoryIds);
List<IdAndName> selectCategoryShortListAccurate(Category category);
} }

View File

@@ -98,7 +98,7 @@ public interface DeviceMapper
* *
* @return 设备集合 * @return 设备集合
*/ */
public List<DeviceAllShortOutput> selectAllDeviceShortList(); public List<DeviceAllShortOutput> selectAllDeviceShortList(Device device);
/** /**
* 新增设备 * 新增设备
@@ -168,16 +168,4 @@ public interface DeviceMapper
*/ */
public int resetDeviceStatus(String deviceNum); public int resetDeviceStatus(String deviceNum);
/**
* 查询所有简短设备列表
* @return 结果
*/
List<DeviceAllShortOutput> selectAllDeviceShortListAccurate(String userName);
/**
* 精准查询
* @return 结果
*/
List<Device> selectDeviceListAccurate(Device device);
} }

View File

@@ -69,5 +69,4 @@ public interface ICategoryService
*/ */
public int deleteCategoryByCategoryId(Long categoryId); public int deleteCategoryByCategoryId(Long categoryId);
List<IdAndName> selectCategoryShortListAccurate(Category category);
} }

View File

@@ -158,18 +158,5 @@ public interface IDeviceService
*/ */
public int resetDeviceStatus(String deviceNum); public int resetDeviceStatus(String deviceNum);
/**
* 获取所有简短设备列表
* @param userName
* @return
*/
List<DeviceAllShortOutput> selectAllDeviceShortListAccurate(String userName);
/**
* 精准查询
* @param device
* @return
*/
List<Device> selectDeviceListAccurate(Device device);
} }

View File

@@ -65,7 +65,14 @@ public class CategoryServiceImpl implements ICategoryService
@Override @Override
public List<IdAndName> selectCategoryShortList() public List<IdAndName> selectCategoryShortList()
{ {
return categoryMapper.selectCategoryShortList(); Category category=new Category();
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
// 租户
if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
category.setTenantId(user.getUserId());
}
return categoryMapper.selectCategoryShortList(category);
} }
/** /**
@@ -103,11 +110,6 @@ public class CategoryServiceImpl implements ICategoryService
return categoryMapper.updateCategory(category); return categoryMapper.updateCategory(category);
} }
@Override
public List<IdAndName> selectCategoryShortListAccurate(Category category) {
return categoryMapper.selectCategoryShortListAccurate(category);
}
/** /**
* 批量删除产品分类 * 批量删除产品分类
* *

View File

@@ -240,8 +240,19 @@ public class DeviceServiceImpl implements IDeviceService {
*/ */
@Override @Override
public List<DeviceAllShortOutput> selectAllDeviceShortList() { public List<DeviceAllShortOutput> selectAllDeviceShortList() {
// TODO redis缓存 Device device=new Device();
return deviceMapper.selectAllDeviceShortList(); SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
for(int i=0;i<roles.size();i++){
if(roles.get(i).getRoleKey().equals("tenant")){
// 租户查看产品下所有设备
device.setTenantId(user.getUserId());
}else if (roles.get(i).getRoleKey().equals("general")){
// 用户查看自己设备
device.setUserId(user.getUserId());
}
}
return deviceMapper.selectAllDeviceShortList(device);
} }
/** /**
@@ -252,8 +263,6 @@ public class DeviceServiceImpl implements IDeviceService {
*/ */
@Override @Override
public List<DeviceShortOutput> selectDeviceShortList(Device device) { public List<DeviceShortOutput> selectDeviceShortList(Device device) {
// TODO 关联设备用户表
SysUser user = getLoginUser().getUser(); SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles(); List<SysRole> roles=user.getRoles();
for(int i=0;i<roles.size();i++){ for(int i=0;i<roles.size();i++){
@@ -568,16 +577,6 @@ public class DeviceServiceImpl implements IDeviceService {
return ""; return "";
} }
@Override
public List<DeviceAllShortOutput> selectAllDeviceShortListAccurate(String userName) {
return deviceMapper.selectAllDeviceShortListAccurate(userName);
}
// 精准查询 新增别人分享给自己的设备
@Override
public List<Device> selectDeviceListAccurate(Device device) {
return deviceMapper.selectDeviceListAccurate(device);
}
/** /**
* *

View File

@@ -33,12 +33,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
order by order_num order by order_num
</select> </select>
<select id="selectCategoryShortList" resultMap="CategoryShortResult"> <select id="selectCategoryShortList" resultMap="CategoryShortResult">
select category_id, category_name
from iot_category
order by order_num
</select>
<select id="selectCategoryShortListAccurate" resultMap="CategoryShortResult">
select category_id, category_name select category_id, category_name
from iot_category from iot_category
<where> <where>

View File

@@ -106,13 +106,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select device_id, device_name,product_id, serial_number, status,is_shadow ,is_custom_location,things_model_value, active_time from iot_device select device_id, device_name,product_id, serial_number, status,is_shadow ,is_custom_location,things_model_value, active_time from iot_device
</sql> </sql>
<select id="selectAllDeviceShortListAccurate" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceAllShortResult">
select device_id, device_name, product_name, user_name, serial_number, firmware_version, status,rssi,is_shadow ,
is_custom_location, active_time,network_address,longitude,latitude from iot_device
<where>
<if test="userName != null and userName != ''"> and user_name = #{userName}</if>
</where>
</select>
<select id="selectDeviceList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceResult"> <select id="selectDeviceList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceResult">
<include refid="selectDeviceVo"/> <include refid="selectDeviceVo"/>
<where> <where>
@@ -134,6 +127,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectAllDeviceShortList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceAllShortResult"> <select id="selectAllDeviceShortList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceAllShortResult">
select device_id, device_name, product_name, user_name, serial_number, firmware_version, status,rssi,is_shadow , select device_id, device_name, product_name, user_name, serial_number, firmware_version, status,rssi,is_shadow ,
is_custom_location, active_time,network_address,longitude,latitude from iot_device is_custom_location, active_time,network_address,longitude,latitude from iot_device
<where>
<if test="userId != null and userId != ''"> and user_id = #{userId}</if>
</where>
</select> </select>
<select id="selectDeviceThingsModelValueBySerialNumber" parameterType="String" resultMap="DeviceThingsValueResult"> <select id="selectDeviceThingsModelValueBySerialNumber" parameterType="String" resultMap="DeviceThingsValueResult">
@@ -145,34 +141,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<select id="selectDeviceShortList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceShortResult"> <select id="selectDeviceShortList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceShortResult">
<include refid="selectDeviceShortVo"/> select d.device_id, d.device_name, d.product_id, d.product_name,
d.user_id, d.user_name, d.tenant_id, d.tenant_name, d.serial_number,
d.firmware_version, d.status,d.rssi,d.is_shadow ,d.is_custom_location,
d.things_model_value, d.active_time,img_url
from iot_device d
left join iot_device_user u on u.device_id = d.device_id
<where> <where>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if> <if test="userId != null "> and u.user_id = #{userId}</if>
<if test="productId != null "> and product_id = #{productId}</if> <if test="deviceName != null and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if> <if test="productId != null "> and d.product_id = #{productId}</if>
<if test="userId != null "> and user_id = #{userId}</if> <if test="productName != null and productName != ''"> and d.product_name like concat('%', #{productName}, '%')</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if> <if test="userName != null and userName != ''"> and d.user_name like concat('%', #{userName}, '%')</if>
<if test="tenantId != null "> and tenant_id = #{tenantId}</if> <if test="tenantId != null "> and d.tenant_id = #{tenantId}</if>
<if test="tenantName != null and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if> <if test="tenantName != null and tenantName != ''"> and d.tenant_name like concat('%', #{tenantName}, '%')</if>
<if test="serialNumber != null and serialNumber != ''"> and serial_number = #{serialNumber}</if> <if test="serialNumber != null and serialNumber != ''"> and d.serial_number = #{serialNumber}</if>
<if test="status != null "> and status = #{status}</if> <if test="status != null "> and d.status = #{status}</if>
<if test="params.beginActiveTime != null and params.beginActiveTime != '' and params.endActiveTime != null and params.endActiveTime != ''"> and active_time between #{params.beginActiveTime} and #{params.endActiveTime}</if> <if test="params.beginActiveTime != null and params.beginActiveTime != '' and params.endActiveTime != null and params.endActiveTime != ''"> and d.active_time between #{params.beginActiveTime} and #{params.endActiveTime}</if>
</where> </where>
order by create_time desc order by d.create_time desc
</select>
<select id="selectDeviceShortListAccurate" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceShortResult">
select device.device_id, device.device_name, device.product_id, device.product_name,
device.user_id, device.user_name, device.tenant_id, device.tenant_name, device.serial_number,
device.firmware_version, device.status,device.rssi,device.is_shadow ,device.is_custom_location,
device.things_model_value, device.active_time,img_url
from iot_device_user device_user
inner join iot_device device on device_user.device_id = device.device_id
<where>
<if test="userId != null and userId != ''"> and device_user.user_id = #{userId} </if>
</where>
order by device.create_time desc
</select> </select>
<select id="selectDeviceByDeviceId" parameterType="Long" resultMap="DeviceResult"> <select id="selectDeviceByDeviceId" parameterType="Long" resultMap="DeviceResult">