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:
parent
3bfa34bab5
commit
e730c51be5
@ -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.framework.springEvent.TemperatureExceededEvent;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.repo.RecordDataRepository;
|
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.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.Event;
|
||||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
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 com.zsc.edu.gateway.modules.iot.tsl.repo.EventRepository;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -38,6 +40,8 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
|
|||||||
private final DeviceRepository deviceRepository;
|
private final DeviceRepository deviceRepository;
|
||||||
@Resource
|
@Resource
|
||||||
private final EventRepository eventRepository;
|
private final EventRepository eventRepository;
|
||||||
|
@Resource
|
||||||
|
private final ParamMapper paramMapper;
|
||||||
@Override
|
@Override
|
||||||
public RecordData recordData(String clientId, JSONObject data) {
|
public RecordData recordData(String clientId, JSONObject data) {
|
||||||
RecordData recordData = new RecordData();
|
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();
|
Double defaultValue = param.getDefaultValue();
|
||||||
String identifier = param.getIdentifier();
|
String identifier = param.getIdentifier();
|
||||||
|
@ -26,4 +26,8 @@ public class ParamDto {
|
|||||||
|
|
||||||
public Param.Type type;
|
public Param.Type type;
|
||||||
|
|
||||||
|
private Param.CompareType compareType;
|
||||||
|
|
||||||
|
private Double defaultValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class Event extends BaseParam {
|
|||||||
* 服务输出的参数
|
* 服务输出的参数
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<Param> outputs;
|
private List<ParamDto> outputs;
|
||||||
|
|
||||||
public enum Type implements IEnum<String>, IState<Type> {
|
public enum Type implements IEnum<String>, IState<Type> {
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +25,5 @@ public interface EventRepository extends BaseMapper<Event> {
|
|||||||
|
|
||||||
Event selectById(@Param("id") Long id);
|
Event selectById(@Param("id") Long id);
|
||||||
|
|
||||||
|
|
||||||
List<Event> selectByProductId(@Param("productId") Long id);
|
List<Event> selectByProductId(@Param("productId") Long id);
|
||||||
}
|
}
|
||||||
|
@ -938,6 +938,8 @@ ALTER TABLE iot_param
|
|||||||
ALTER COLUMN contrast_type SET DEFAULT NULL;
|
ALTER COLUMN contrast_type SET DEFAULT NULL;
|
||||||
|
|
||||||
ALTER TABLE iot_param
|
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;
|
||||||
|
|
||||||
|
@ -26,6 +26,26 @@
|
|||||||
</collection>
|
</collection>
|
||||||
</resultMap>
|
</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 id="selectById" resultMap="EventMap">
|
||||||
select e.*,
|
select e.*,
|
||||||
ip.id as param_id,
|
ip.id as param_id,
|
||||||
@ -40,7 +60,7 @@
|
|||||||
and ip.foreign_type = 1
|
and ip.foreign_type = 1
|
||||||
where e.id = #{id}
|
where e.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectByProductId" resultMap="EventMap">
|
<select id="selectByProductId" resultMap="EventMapper">
|
||||||
select e.*,
|
select e.*,
|
||||||
ip.id as param_id,
|
ip.id as param_id,
|
||||||
ip.data_type as param_data_type,
|
ip.data_type as param_data_type,
|
||||||
@ -50,7 +70,7 @@
|
|||||||
ip.name as param_name,
|
ip.name as param_name,
|
||||||
ip.remark as param_remark,
|
ip.remark as param_remark,
|
||||||
ip.compare_type as param_compare_type,
|
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
|
from iot_event e
|
||||||
left join iot_param ip on e.id = ip.foreign_id
|
left join iot_param ip on e.id = ip.foreign_id
|
||||||
and ip.foreign_type = 1
|
and ip.foreign_type = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user