20260328:数据推送:列表查询用户隔离

This commit is contained in:
George 2026-03-28 21:35:37 +08:00
parent 8a16a35627
commit ef7158563e
6 changed files with 28 additions and 15 deletions

View File

@ -5,7 +5,6 @@ import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult; import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo; import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType; import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.iot.data.push.ThingsModelPushHandler; import com.fastbee.iot.data.push.ThingsModelPushHandler;
import com.fastbee.iot.domain.ThingsModelPushConfig; import com.fastbee.iot.domain.ThingsModelPushConfig;
import com.fastbee.iot.service.IThingsModelPushConfigService; import com.fastbee.iot.service.IThingsModelPushConfigService;
@ -57,7 +56,7 @@ public class ThingsModelPushController extends BaseController {
@Log(title = "推送配置", businessType = BusinessType.INSERT) @Log(title = "推送配置", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody @Validated ThingsModelPushConfig config) { public AjaxResult add(@RequestBody @Validated ThingsModelPushConfig config) {
config.setCreateBy(SecurityUtils.getUsername());
return toAjax(pushConfigService.insertConfig(config)); return toAjax(pushConfigService.insertConfig(config));
} }
@ -67,7 +66,6 @@ public class ThingsModelPushController extends BaseController {
@Log(title = "推送配置", businessType = BusinessType.UPDATE) @Log(title = "推送配置", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody ThingsModelPushConfig config) { public AjaxResult edit(@RequestBody ThingsModelPushConfig config) {
config.setUpdateBy(SecurityUtils.getUsername());
return toAjax(pushConfigService.updateConfig(config)); return toAjax(pushConfigService.updateConfig(config));
} }
@ -77,11 +75,7 @@ public class ThingsModelPushController extends BaseController {
@Log(title = "推送配置状态", businessType = BusinessType.UPDATE) @Log(title = "推送配置状态", businessType = BusinessType.UPDATE)
@PutMapping("/status") @PutMapping("/status")
public AjaxResult changeStatus(@RequestBody ThingsModelPushConfig config) { public AjaxResult changeStatus(@RequestBody ThingsModelPushConfig config) {
ThingsModelPushConfig update = new ThingsModelPushConfig(); return toAjax(pushConfigService.updateConfig(config));
update.setId(config.getId());
update.setStatus(config.getStatus());
update.setUpdateBy(SecurityUtils.getUsername());
return toAjax(pushConfigService.updateConfig(update));
} }
/** 删除 */ /** 删除 */

View File

@ -466,6 +466,6 @@ public class TSLCacheImpl implements ITSLCache {
.map(v -> JSON.parseObject(v.toString(), ValueItem.class)) .map(v -> JSON.parseObject(v.toString(), ValueItem.class))
.collect(Collectors.toMap(ValueItem::getId, Function.identity())); .collect(Collectors.toMap(ValueItem::getId, Function.identity()));
} }
return null; return Collections.emptyMap();
} }
} }

View File

@ -71,6 +71,9 @@ public class ThingsModelPushConfig extends BaseEntity {
@ApiModelProperty("租户名称") @ApiModelProperty("租户名称")
private String tenantName; private String tenantName;
@ApiModelProperty("配置归属用户ID(列表按此过滤;与接收用户 userIds 不同)")
private Long userId;
/** 物模型项列表(非持久化,前端用) */ /** 物模型项列表(非持久化,前端用) */
private List<PushModelItem> items; private List<PushModelItem> items;

View File

@ -1,6 +1,8 @@
package com.fastbee.iot.service.impl; package com.fastbee.iot.service.impl;
import com.fastbee.common.core.domain.model.LoginUser;
import com.fastbee.common.utils.DateUtils; import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.iot.domain.PushModelItem; import com.fastbee.iot.domain.PushModelItem;
import com.fastbee.iot.domain.PushUser; import com.fastbee.iot.domain.PushUser;
import com.fastbee.iot.domain.ThingsModelPushConfig; import com.fastbee.iot.domain.ThingsModelPushConfig;
@ -35,6 +37,7 @@ public class ThingsModelPushConfigServiceImpl implements IThingsModelPushConfigS
@Override @Override
public List<ThingsModelPushConfig> selectList(ThingsModelPushConfig query) { public List<ThingsModelPushConfig> selectList(ThingsModelPushConfig query) {
query.setUserId(SecurityUtils.getUserId());
return mapper.selectList(query); return mapper.selectList(query);
} }
@ -51,6 +54,9 @@ public class ThingsModelPushConfigServiceImpl implements IThingsModelPushConfigS
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insertConfig(ThingsModelPushConfig config) { public int insertConfig(ThingsModelPushConfig config) {
LoginUser loginUser = SecurityUtils.getLoginUser();
config.setUserId(loginUser.getUserId());
config.setCreateBy(loginUser.getUsername());
config.setCreateTime(DateUtils.getNowDate()); config.setCreateTime(DateUtils.getNowDate());
config.setStatus(config.getStatus() == null ? 1 : config.getStatus()); config.setStatus(config.getStatus() == null ? 1 : config.getStatus());
config.setDeviceId(config.getDeviceId() == null ? 0L : config.getDeviceId()); config.setDeviceId(config.getDeviceId() == null ? 0L : config.getDeviceId());
@ -63,8 +69,12 @@ public class ThingsModelPushConfigServiceImpl implements IThingsModelPushConfigS
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int updateConfig(ThingsModelPushConfig config) { public int updateConfig(ThingsModelPushConfig config) {
config.setUpdateTime(DateUtils.getNowDate()); ThingsModelPushConfig update = new ThingsModelPushConfig();
int rows = mapper.update(config); update.setId(config.getId());
update.setStatus(config.getStatus());
update.setUpdateBy(SecurityUtils.getUsername());
update.setUpdateTime(DateUtils.getNowDate());
int rows = mapper.update(update);
mapper.deleteItemsByConfigId(config.getId()); mapper.deleteItemsByConfigId(config.getId());
mapper.deleteUsersByConfigId(config.getId()); mapper.deleteUsersByConfigId(config.getId());
saveItemsAndUsers(config); saveItemsAndUsers(config);

View File

@ -19,6 +19,7 @@
<result property="status" column="status"/> <result property="status" column="status"/>
<result property="tenantId" column="tenant_id"/> <result property="tenantId" column="tenant_id"/>
<result property="tenantName" column="tenant_name"/> <result property="tenantName" column="tenant_name"/>
<result property="userId" column="config_owner_user_id"/>
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
@ -53,7 +54,7 @@
<sql id="baseColumns"> <sql id="baseColumns">
c.id, c.config_name, c.product_id, c.device_id, c.serial_number, c.id, c.config_name, c.product_id, c.device_id, c.serial_number,
c.template_id, c.push_interval, c.last_push_time, c.status, c.template_id, c.push_interval, c.last_push_time, c.status,
c.tenant_id, c.tenant_name, c.create_by, c.create_time, c.tenant_id, c.tenant_name, c.user_id AS config_owner_user_id, c.create_by, c.create_time,
c.update_by, c.update_time,p.product_name, p.device_type, c.update_by, c.update_time,p.product_name, p.device_type,
d.device_name,d.network_address AS device_address, nt.name AS template_name d.device_name,d.network_address AS device_address, nt.name AS template_name
</sql> </sql>
@ -90,6 +91,9 @@
<if test="tenantId != null"> <if test="tenantId != null">
AND c.tenant_id = #{tenantId} AND c.tenant_id = #{tenantId}
</if> </if>
<if test="userId != null">
AND c.user_id = #{userId}
</if>
ORDER BY c.create_time DESC ORDER BY c.create_time DESC
</select> </select>
@ -110,11 +114,11 @@
INSERT INTO iot_things_model_push_config INSERT INTO iot_things_model_push_config
(config_name, product_id, device_id, serial_number, template_id, (config_name, product_id, device_id, serial_number, template_id,
push_interval, status, push_interval, status,
tenant_id, tenant_name, create_by, create_time, del_flag) tenant_id, tenant_name, user_id, create_by, create_time, del_flag)
VALUES VALUES
(#{configName}, #{productId}, #{deviceId}, #{serialNumber}, #{templateId}, (#{configName}, #{productId}, #{deviceId}, #{serialNumber}, #{templateId},
#{pushInterval}, #{status}, #{pushInterval}, #{status},
#{tenantId}, #{tenantName}, #{createBy}, #{createTime}, '0') #{tenantId}, #{tenantName}, #{userId}, #{createBy}, #{createTime}, '0')
</insert> </insert>
<update id="update"> <update id="update">

View File

@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `iot_things_model_push_config` (
`status` TINYINT DEFAULT 1 COMMENT '状态:0=停用 1=启用', `status` TINYINT DEFAULT 1 COMMENT '状态:0=停用 1=启用',
`tenant_id` BIGINT DEFAULT NULL COMMENT '租户ID', `tenant_id` BIGINT DEFAULT NULL COMMENT '租户ID',
`tenant_name` VARCHAR(64) DEFAULT NULL COMMENT '租户名称', `tenant_name` VARCHAR(64) DEFAULT NULL COMMENT '租户名称',
`user_id` BIGINT DEFAULT NULL COMMENT '配置归属用户ID',
`create_by` VARCHAR(64) DEFAULT NULL COMMENT '创建者', `create_by` VARCHAR(64) DEFAULT NULL COMMENT '创建者',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间', `create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
`update_by` VARCHAR(64) DEFAULT NULL COMMENT '更新者', `update_by` VARCHAR(64) DEFAULT NULL COMMENT '更新者',
@ -22,7 +23,8 @@ CREATE TABLE IF NOT EXISTS `iot_things_model_push_config` (
`del_flag` CHAR(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)', `del_flag` CHAR(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `idx_device_id` (`device_id`), KEY `idx_device_id` (`device_id`),
KEY `idx_template_id` (`template_id`) KEY `idx_template_id` (`template_id`),
KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='物模型数据推送配置'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='物模型数据推送配置';