多租户测试调整

This commit is contained in:
kerwincui
2022-06-11 02:32:48 +08:00
parent 8571f899da
commit 33a7ba9645
18 changed files with 146 additions and 45 deletions

View File

@@ -37,7 +37,7 @@ public class AlertController extends BaseController
/**
* 查询设备告警列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
@PreAuthorize("@ss.hasPermi('iot:alert:list')")
@GetMapping("/list")
public TableDataInfo list(Alert alert)
{
@@ -49,7 +49,7 @@ public class AlertController extends BaseController
/**
* 导出设备告警列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:export')")
@PreAuthorize("@ss.hasPermi('iot:alert:export')")
@Log(title = "设备告警", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Alert alert)
@@ -62,7 +62,7 @@ public class AlertController extends BaseController
/**
* 获取设备告警详细信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
@PreAuthorize("@ss.hasPermi('iot:alert:query')")
@GetMapping(value = "/{alertId}")
public AjaxResult getInfo(@PathVariable("alertId") Long alertId)
{
@@ -72,7 +72,7 @@ public class AlertController extends BaseController
/**
* 新增设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:device:add')")
@PreAuthorize("@ss.hasPermi('iot:alert:add')")
@Log(title = "设备告警", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Alert alert)
@@ -83,7 +83,7 @@ public class AlertController extends BaseController
/**
* 修改设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
@PreAuthorize("@ss.hasPermi('iot:alert:edit')")
@Log(title = "设备告警", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Alert alert)
@@ -94,7 +94,7 @@ public class AlertController extends BaseController
/**
* 删除设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:device:remove')")
@PreAuthorize("@ss.hasPermi('iot:alert:remove')")
@Log(title = "设备告警", businessType = BusinessType.DELETE)
@DeleteMapping("/{alertIds}")
public AjaxResult remove(@PathVariable Long[] alertIds)

View File

@@ -37,7 +37,7 @@ public class AlertLogController extends BaseController
/**
* 查询设备告警列表
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:list')")
@PreAuthorize("@ss.hasPermi('iot:alert:list')")
@GetMapping("/list")
public TableDataInfo list(AlertLog alertLog)
{
@@ -49,7 +49,7 @@ public class AlertLogController extends BaseController
/**
* 导出设备告警列表
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:export')")
@PreAuthorize("@ss.hasPermi('iot:alert:export')")
@Log(title = "设备告警", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, AlertLog alertLog)
@@ -62,7 +62,7 @@ public class AlertLogController extends BaseController
/**
* 获取设备告警详细信息
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:query')")
@PreAuthorize("@ss.hasPermi('iot:alert:query')")
@GetMapping(value = "/{alertLogId}")
public AjaxResult getInfo(@PathVariable("alertLogId") Long alertLogId)
{
@@ -72,7 +72,7 @@ public class AlertLogController extends BaseController
/**
* 新增设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:add')")
@PreAuthorize("@ss.hasPermi('iot:alert:add')")
@Log(title = "设备告警", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody AlertLog alertLog)
@@ -83,7 +83,7 @@ public class AlertLogController extends BaseController
/**
* 修改设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:edit')")
@PreAuthorize("@ss.hasPermi('iot:alert:edit')")
@Log(title = "设备告警", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody AlertLog alertLog)
@@ -94,7 +94,7 @@ public class AlertLogController extends BaseController
/**
* 删除设备告警
*/
@PreAuthorize("@ss.hasPermi('iot:alertLog:remove')")
@PreAuthorize("@ss.hasPermi('iot:alert:remove')")
@Log(title = "设备告警", businessType = BusinessType.DELETE)
@DeleteMapping("/{alertLogIds}")
public AjaxResult remove(@PathVariable Long[] alertLogIds)

View File

@@ -6,6 +6,8 @@ import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
@@ -27,6 +29,7 @@ import com.ruoyi.iot.service.impl.ThingsModelServiceImpl;
import com.ruoyi.iot.util.AESUtils;
import com.ruoyi.iot.util.VelocityInitializer;
import com.ruoyi.iot.util.VelocityUtils;
import com.ruoyi.system.service.ISysUserService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.swagger.annotations.Api;
@@ -42,6 +45,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -101,6 +105,17 @@ public class ToolController extends BaseController {
return StringUtils.isEmpty(msg) ? success() : error(msg);
}
/**
* 获取用户列表
*/
@GetMapping("/userList")
public TableDataInfo list(SysUser user)
{
startPage();
List<SysUser> list = toolService.selectUserList(user);
return getDataTable(list);
}
@ApiOperation("mqtt认证")
@PostMapping("/mqtt/auth")
public ResponseEntity mqttAuth(@RequestParam String clientid, @RequestParam String username, @RequestParam String password) throws Exception {

View File

@@ -105,6 +105,25 @@ public class Device extends BaseEntity
/** 分组ID用于分组查询 **/
private Long groupId;
/** 是否设备所有者,用于查询 **/
private Integer isOwner;
public Integer getLocationWay() {
return locationWay;
}
public void setLocationWay(Integer locationWay) {
this.locationWay = locationWay;
}
public Integer getIsOwner() {
return isOwner;
}
public void setIsOwner(Integer isOwner) {
this.isOwner = isOwner;
}
/** 删除标志0代表存在 2代表删除 */
private String delFlag;
@@ -124,14 +143,6 @@ public class Device extends BaseEntity
this.summary = summary;
}
public Integer getlocationWay() {
return locationWay;
}
public void setlocationWay(Integer locationWay) {
this.locationWay = locationWay;
}
public String getImgUrl() {
return imgUrl;
}

View File

@@ -58,6 +58,25 @@ public class DeviceAllShortOutput
/** 纬度 */
private BigDecimal latitude;
/** 是否设备所有者,用于查询 **/
private Integer isOwner;
public Integer getLocationWay() {
return locationWay;
}
public void setLocationWay(Integer locationWay) {
this.locationWay = locationWay;
}
public Integer getIsOwner() {
return isOwner;
}
public void setIsOwner(Integer isOwner) {
this.isOwner = isOwner;
}
public String getNetworkAddress() {
return networkAddress;
}
@@ -82,14 +101,6 @@ public class DeviceAllShortOutput
this.latitude = latitude;
}
public Integer getlocationWay() {
return locationWay;
}
public void setlocationWay(Integer locationWay) {
this.locationWay = locationWay;
}
public Integer getIsShadow() {
return isShadow;
}

View File

@@ -93,6 +93,9 @@ public class DeviceShortOutput
/** 图片地址 */
private String imgUrl;
/** 是否设备所有者,用于查询 **/
private Integer isOwner;
private List<StringModelOutput> stringList;
private List<IntegerModelOutput> integerList;
private List<DecimalModelOutput> decimalList;
@@ -101,14 +104,22 @@ public class DeviceShortOutput
private List<BoolModelOutput> boolList;
private List<ReadOnlyModelOutput> readOnlyList;
public Integer getlocationWay() {
public Integer getLocationWay() {
return locationWay;
}
public void setlocationWay(Integer locationWay) {
public void setLocationWay(Integer locationWay) {
this.locationWay = locationWay;
}
public Integer getIsOwner() {
return isOwner;
}
public void setIsOwner(Integer isOwner) {
this.isOwner = isOwner;
}
public String getImgUrl() {
return imgUrl;
}

View File

@@ -133,7 +133,7 @@ public class EmqxService {
device.setProductId(productId);
device.setSerialNumber(deviceNum);
// 未采用设备定位则清空定位,定位方式(1=ip自动定位2=设备定位3=自定义)
if(device.getlocationWay()!=2){
if(device.getLocationWay()!=2){
device.setLatitude(null);
device.setLongitude(null);
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.iot.service;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.iot.domain.ProductAuthorize;
import com.ruoyi.iot.model.MqttAuthenticationModel;
@@ -8,6 +9,8 @@ import com.ruoyi.iot.model.RegisterUserInput;
import com.ruoyi.iot.util.AESUtils;
import org.springframework.http.ResponseEntity;
import java.util.List;
/**
*
* @author kerwincui
@@ -20,6 +23,14 @@ public interface IToolService
*/
public String register(RegisterUserInput registerBody);
/**
* 根据条件分页查询用户列表
*
* @param user 用户信息
* @return 用户信息集合信息
*/
public List<SysUser> selectUserList(SysUser user);
/**
* 生成随机数字和字母
*/

View File

@@ -304,8 +304,16 @@ public class DeviceServiceImpl implements IDeviceService {
*/
@Override
public List<Device> selectDeviceListByGroup(Device device) {
if(device.getUserId()==null || device.getUserId()==0){
return new ArrayList<>();
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.selectDeviceListByGroup(device);
}
@@ -564,7 +572,7 @@ public class DeviceServiceImpl implements IDeviceService {
device.setActiveTime(DateUtils.getNowDate());
device.setIsShadow(0);
device.setRssi(0);
device.setlocationWay(1); // 1-自动定位2-设备定位3-自定义位置
device.setLocationWay(1); // 1-自动定位2-设备定位3-自定义位置
device.setCreateTime(DateUtils.getNowDate());
device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
// 随机位置
@@ -713,7 +721,7 @@ public class DeviceServiceImpl implements IDeviceService {
device.setActiveTime(DateUtils.getNowDate());
}
// 定位方式(1=ip自动定位2=设备定位3=自定义)
if (device.getlocationWay() == 1) {
if (device.getLocationWay() == 1) {
device.setNetworkIp(ipAddress);
setLocation(ipAddress, device);
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.iot.service.impl;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
@@ -32,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.iot.mqtt.MqttConfig;
import java.util.List;
import java.util.Random;
/**
@@ -156,6 +158,18 @@ public class ToolServiceImpl implements IToolService
return msg;
}
/**
* 根据条件分页查询用户列表
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@Override
public List<SysUser> selectUserList(SysUser user)
{
return userMapper.selectUserList(user);
}
/**
* 校验手机号码是否唯一
*

View File

@@ -38,9 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select category_id, category_name
from iot_category
<where>
<if test="categoryName != null and categoryName != ''"> and category_name = #{categoryName}</if>
<if test="tenantName != null and tenantName != ''"> and tenant_name = #{tenantName} or is_sys = 1</if>
<if test="isSys != null "> and is_sys = #{isSys}</if>
<if test="tenantId != null and tenantId != ''"> and (tenant_id = #{tenantId} or is_sys = 1)</if>
</where>
order by order_num
</select>

View File

@@ -30,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="imgUrl" column="img_url" />
<result property="summary" column="summary" />
<result property="isOwner" column="is_owner" />
</resultMap>
<resultMap type="com.ruoyi.iot.model.DeviceShortOutput" id="DeviceShortResult">
@@ -50,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="locationWay" column="location_way" />
<result property="thingsModelValue" column="things_model_value" />
<result property="imgUrl" column="img_url" />
<result property="isOwner" column="is_owner" />
</resultMap>
<resultMap type="com.ruoyi.iot.model.DeviceAllShortOutput" id="DeviceAllShortResult">
@@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="networkAddress" column="network_address" />
<result property="longitude" column="longitude" />
<result property="latitude" column="latitude" />
<result property="isOwner" column="is_owner" />
</resultMap>
<resultMap type="com.ruoyi.iot.model.ProductAuthenticateModel" id="DeviceAuthenticateResult">
@@ -153,13 +156,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDeviceListByGroup" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceResult">
select d.device_id, d.device_name, d.product_name, d.user_name, d.serial_number, d.firmware_version, d.status,d.rssi,d.is_shadow ,
d.location_way, d.active_time,d.network_address,d.longitude,latitude
d.location_way, d.active_time,d.network_address,d.longitude,d.latitude,u.is_owner
from iot_device d
inner join iot_device_user u on u.device_id = d.device_id
<where>
<if test="userId != null "> and u.user_id = #{userId}</if>
<if test="deviceName != null and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
<if test="productId != null "> and d.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 d.product_name like concat('%', #{productName}, '%')</if>
<if test="serialNumber != null and serialNumber != ''"> and d.serial_number = #{serialNumber}</if>
<if test="status != null "> and d.status = #{status}</if>
@@ -172,7 +175,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectAllDeviceShortList" parameterType="com.ruoyi.iot.domain.Device" resultMap="DeviceAllShortResult">
select d.device_id, d.device_name, d.product_name, d.user_name, d.serial_number, d.firmware_version, d.status,d.rssi,d.is_shadow ,
d.location_way, d.active_time,d.network_address,d.longitude,latitude
d.location_way, d.active_time,d.network_address,d.longitude,d.latitude,u.is_owner
from iot_device d
inner join iot_device_user u on u.device_id = d.device_id
<where>
@@ -195,7 +198,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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.location_way,
d.things_model_value, d.active_time,d.img_url,u.user_id
d.things_model_value, d.active_time,d.img_url,u.is_owner
from iot_device d
inner join iot_device_user u on u.device_id = d.device_id
<if test="groupId != null and groupId !=0 "> left join iot_device_group g on g.device_id=d.device_id </if>