缓存优化

This commit is contained in:
zhanghan11 2024-09-27 10:53:05 +08:00
parent e759bebb84
commit 0af2a8b43b
5 changed files with 28 additions and 16 deletions

View File

@ -9,7 +9,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 运行状态记录对象 ipc_running_status_record
* 产线运行状态记录对象 ipc_running_status_record_dept
*
* @author inspur
* @date 2024-04-09
@ -31,8 +31,8 @@ public class IpcRunningStatusRecord extends BaseEntity {
/**
* 开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
private Long detpId;

View File

@ -67,6 +67,11 @@ public interface IIpcMonitorFieldService
*/
public List<IpcMonitorField> selectFieldDataByType(String fieldType);
/**
* 更新缓存
*/
public List<IpcMonitorField> updateFieldDataByType(String fieldType);
/**
* 获取监测设备
*/

View File

@ -101,12 +101,19 @@ public class IpcMonitorFieldServiceImpl implements IIpcMonitorFieldService {
public List<IpcMonitorField> selectFieldDataByType(String type) {
List<IpcMonitorField> list = redisCache.getCacheObject(CacheConstants.IPC_PREFIX + type);
if (list == null || list.isEmpty()) {
list = ipcMonitorFieldMapper.selectFieldDataByType(type);
redisCache.setCacheObject(CacheConstants.IPC_PREFIX + type, list);
list = this.updateFieldDataByType(type);
}
return list;
}
/**
* 更新缓存
*/
@Override
public List<IpcMonitorField> updateFieldDataByType(String fieldType){
List<IpcMonitorField> list = ipcMonitorFieldMapper.selectFieldDataByType(fieldType);
redisCache.setCacheObject(CacheConstants.IPC_PREFIX + fieldType, list);
return list;
}
/**
* 获取监测设备
*/

View File

@ -26,10 +26,10 @@ public class IpcRedisCacheConfiguration {
*/
@PostConstruct
public void preloadedRedisCache(){
iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_EQUIP_KEY);
iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.SENSOR_MONITOR_PARAMS_KEY);
iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY);
iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_READ_KEY);
iIpcMonitorFieldService.updateFieldDataByType(CacheConstants.MONITOR_EQUIP_KEY);
iIpcMonitorFieldService.updateFieldDataByType(CacheConstants.SENSOR_MONITOR_PARAMS_KEY);
iIpcMonitorFieldService.updateFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY);
iIpcMonitorFieldService.updateFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_READ_KEY);
iIpcAlarmRulesConfigService.updateRedisCache();
iIpcRunningStatusRecordService.selectLatestStatus();
}

View File

@ -12,7 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectIpcRunningStatusRecordVo">
select id, running_status, start_time,dept_id from ipc_running_status_record
select id, running_status, start_time,dept_id from ipc_running_status_record_dept
</sql>
<select id="selectIpcRunningStatusRecordList" parameterType="com.inspur.ipc.domain.IpcRunningStatusRecord" resultMap="IpcRunningStatusRecordResult">
@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<insert id="insertIpcRunningStatusRecord" parameterType="com.inspur.ipc.domain.IpcRunningStatusRecord" useGeneratedKeys="true" keyProperty="id">
insert into ipc_running_status_record
insert into ipc_running_status_record_dept
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="runningStatus != null">running_status,</if>
start_time,
@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<update id="updateIpcRunningStatusRecord" parameterType="com.inspur.ipc.domain.IpcRunningStatusRecord">
update ipc_running_status_record
update ipc_running_status_record_dept
<trim prefix="SET" suffixOverrides=",">
<if test="runningStatus != null">running_status = #{runningStatus},</if>
<if test="startTime != null">start_time = #{startTime},</if>
@ -54,17 +54,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteIpcRunningStatusRecordById" parameterType="Long">
delete from ipc_running_status_record where id = #{id}
delete from ipc_running_status_record_dept where id = #{id}
</delete>
<delete id="deleteIpcRunningStatusRecordByIds" parameterType="String">
delete from ipc_running_status_record where id in
delete from ipc_running_status_record_dept where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectLatestStatus" resultType="string">
SELECT running_status FROM `ipc_running_status_record` WHERE dept_id = #{deptId} ORDER BY start_time DESC LIMIT 1
SELECT running_status FROM `ipc_running_status_record_dept` WHERE dept_id = #{deptId} ORDER BY start_time DESC LIMIT 1
</select>
</mapper>