refactor(iot): 重构事件相关接口和数据库

- 修改 Event 实体类,将 outputs 字段类型从 List<Param> 改为 List<ParamDto>
- 更新 EventMapper.xml,增加新的 resultMap配置
- 调整 EventRepository 接口,修改查询方法的 resultMap
- 修改数据库结构,为 iot_param 表添加 default_value 字段并调整其类型
- 更新 ParamDto 类,增加 compareType 和 defaultValue 字段
- 修改 RecordDataServiceImpl 中的 processParam 方法,使用 ParamDto 作为参数
This commit is contained in:
zhuangtianxiang 2025-03-13 16:34:25 +08:00
parent 3bfa34bab5
commit e730c51be5
6 changed files with 36 additions and 6 deletions

View File

@ -14,8 +14,10 @@ import com.zsc.edu.gateway.modules.iot.record.entity.RecordDataStatusVo;
import com.zsc.edu.gateway.framework.springEvent.TemperatureExceededEvent;
import com.zsc.edu.gateway.modules.iot.record.repo.RecordDataRepository;
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
import com.zsc.edu.gateway.modules.iot.tsl.repo.EventRepository;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
@ -38,6 +40,8 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
private final DeviceRepository deviceRepository;
@Resource
private final EventRepository eventRepository;
@Resource
private final ParamMapper paramMapper;
@Override
public RecordData recordData(String clientId, JSONObject data) {
RecordData recordData = new RecordData();
@ -97,7 +101,8 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
}
}
private void processParam(RecordData recordData, Param param, Event event) {
private void processParam(RecordData recordData, ParamDto paramDto, Event event) {
Param param = paramMapper.toEntity(paramDto);
// 获取参数的默认值和比较类型
Double defaultValue = param.getDefaultValue();
String identifier = param.getIdentifier();

View File

@ -26,4 +26,8 @@ public class ParamDto {
public Param.Type type;
private Param.CompareType compareType;
private Double defaultValue;
}

View File

@ -39,7 +39,7 @@ public class Event extends BaseParam {
* 服务输出的参数
*/
@TableField(exist = false)
private List<Param> outputs;
private List<ParamDto> outputs;
public enum Type implements IEnum<String>, IState<Type> {
/**

View File

@ -25,6 +25,5 @@ public interface EventRepository extends BaseMapper<Event> {
Event selectById(@Param("id") Long id);
List<Event> selectByProductId(@Param("productId") Long id);
}

View File

@ -938,6 +938,8 @@ ALTER TABLE iot_param
ALTER COLUMN contrast_type SET DEFAULT NULL;
ALTER TABLE iot_param
ALTER COLUMN "default_value " SET DEFAULT NULL;
ALTER COLUMN default_value SET DEFAULT NULL;
ALTER TABLE iot_param
ADD COLUMN default_value DOUBLE PRECISION;

View File

@ -26,6 +26,26 @@
</collection>
</resultMap>
<resultMap id="EventMapper" type="com.zsc.edu.gateway.modules.iot.tsl.entity.Event">
<id column="id" property="id"/>
<result column="product_id" property="productId"/>
<result column="type" property="type"/>
<result column="identifier" property="identifier"/>
<result column="name" property="name"/>
<result column="remark" property="remark"/>
<collection property="outputs" ofType="com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto" autoMapping="true"
columnPrefix="param_">
<result column="data_type" property="dataType"/>
<result column="uint" property="uint"/>
<result column="type" property="type"/>
<result column="identifier" property="identifier"/>
<result column="name" property="name"/>
<result column="remark" property="remark"/>
<result column="compare_type" property="compareType"/>
<result column="default_value" property="defaultValue"/>
</collection>
</resultMap>
<select id="selectById" resultMap="EventMap">
select e.*,
ip.id as param_id,
@ -40,7 +60,7 @@
and ip.foreign_type = 1
where e.id = #{id}
</select>
<select id="selectByProductId" resultMap="EventMap">
<select id="selectByProductId" resultMap="EventMapper">
select e.*,
ip.id as param_id,
ip.data_type as param_data_type,
@ -50,7 +70,7 @@
ip.name as param_name,
ip.remark as param_remark,
ip.compare_type as param_compare_type,
ip."default_value " as param_default_value
ip.default_value as param_default_value
from iot_event e
left join iot_param ip on e.id = ip.foreign_id
and ip.foreign_type = 1