v4.0 优化每小时获取识别个数大屏显示
This commit is contained in:
parent
52928d854e
commit
c011bdd7f4
|
@ -0,0 +1,82 @@
|
|||
package net.shapelight.modules.job.task;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.shapelight.common.utils.DateUtils;
|
||||
import net.shapelight.common.utils.RedisUtils;
|
||||
import net.shapelight.modules.sys.entity.SysUserEntity;
|
||||
import net.shapelight.modules.sys.service.SysUserService;
|
||||
import net.shapelight.modules.ten.entity.TenCellEntity;
|
||||
import net.shapelight.modules.ten.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component("hourRecordTask")
|
||||
@Slf4j
|
||||
public class HourRecordTask implements ITask {
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private TenCellService tenCellService;
|
||||
@Autowired
|
||||
private TenRecordService tenRecordService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public void run(String params){
|
||||
|
||||
List<SysUserEntity> allSysTenUser = this.sysUserService.findAllSysTenUser();
|
||||
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
for (SysUserEntity sysTenUser : allSysTenUser) {
|
||||
List<TenCellEntity> allCells = this.tenCellService.list((Wrapper)(new QueryWrapper())
|
||||
.eq("tenant_id", sysTenUser.getTenantId()));
|
||||
Long tenantId = sysTenUser.getTenantId();
|
||||
Map<String, Object> paramsRes = new HashMap<>();
|
||||
paramsRes.put("tenantId",tenantId);
|
||||
for (TenCellEntity cellEntity : allCells) {
|
||||
paramsRes.put("cellId",cellEntity.getCellId());
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
// 时
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
// 分
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
// 秒
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
// 毫秒
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
//24小时
|
||||
for(int i = 0;i<24;i++){
|
||||
|
||||
calendar.set(Calendar.HOUR_OF_DAY,i);
|
||||
String recordTimeStart = DateUtils.format(calendar.getTime(),DateUtils.DATE_TIME_PATTERN);
|
||||
calendar.set(Calendar.HOUR_OF_DAY,i+1);
|
||||
String recordTimeEnd = DateUtils.format(calendar.getTime(),DateUtils.DATE_TIME_PATTERN);
|
||||
|
||||
if(calendar.getTime().after(now)){
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = cellEntity.getCellId()+"-"+recordTimeStart;
|
||||
Integer countRedis = (Integer) redisUtils.get(key);
|
||||
if(countRedis==null){
|
||||
paramsRes.put("recordTimeStart",recordTimeStart);
|
||||
paramsRes.put("recordTimeEnd",recordTimeEnd);
|
||||
int count = tenRecordService.getCellHourCount(paramsRes);
|
||||
redisUtils.set(key,count,2880l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("按小时统计识别记录个数");
|
||||
}
|
||||
}
|
|
@ -31,6 +31,8 @@ public interface TenRecordDao {
|
|||
|
||||
int findHourAll(@Param("cellIds") List<Long> cellIds, @Param("params") Map params);
|
||||
|
||||
int findCellHourAll(@Param("params") Map params);
|
||||
|
||||
IPage<TenRecordEntity> findPageBlackRecord(Page page, @Param("cellIds") List<Long> cellIds, @Param("params") Map params);
|
||||
|
||||
IPage<TenRecordEntity> findPageRoomRecord(Page page, @Param("params") Map params);
|
||||
|
|
|
@ -32,6 +32,8 @@ public interface TenRecordService {
|
|||
int getCount(Map<String, Object> params);
|
||||
int getHourCount(Map<String, Object> params);
|
||||
|
||||
int getCellHourCount(Map<String, Object> params);
|
||||
|
||||
List<TenRecordEntity> getLastRecord(Map<String, Object> params);
|
||||
|
||||
List<TenRecordEntity> getNotSync(Long cellId, Long tenantId);
|
||||
|
|
|
@ -56,6 +56,8 @@ public class TenRecordServiceImpl implements TenRecordService {
|
|||
private TenBuildService tenBuildService;
|
||||
// @Autowired
|
||||
// private EmqHttpApi emqHttpApi;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
|
@ -311,10 +313,28 @@ public class TenRecordServiceImpl implements TenRecordService {
|
|||
if (cellIds.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
int c = tenRecordDao.findHourAll(cellIds, params);
|
||||
|
||||
//数据库获取方式
|
||||
// int c = tenRecordDao.findHourAll(cellIds, params);
|
||||
|
||||
//redis获取方式
|
||||
String recordTimeStart = (String)params.get("recordTimeStart");
|
||||
int c = 0;
|
||||
for(Long cId:cellIds){
|
||||
String key = cId+"-"+recordTimeStart;
|
||||
Integer cC = (Integer) redisUtils.get(key);
|
||||
if(cC!=null){
|
||||
c+=cC;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellHourCount(Map<String, Object> params) {
|
||||
return tenRecordDao.findCellHourAll(params);
|
||||
}
|
||||
|
||||
private void publishRecordToWeb(TenRecordEntity entity){
|
||||
TenRecordVo vo = new TenRecordVo();
|
||||
vo.setRecordId(entity.getRecordId());
|
||||
|
|
|
@ -264,7 +264,36 @@
|
|||
<!--order by record_time desc-->
|
||||
|
||||
|
||||
select r.*,t.name from ten_record_${params.tenantId} r left join ten_person t on r.person_id = t.person_id
|
||||
<!-- select r.*,t.name from ten_record_${params.tenantId} r left join ten_person t on r.person_id = t.person_id-->
|
||||
<!-- where 1 = 1-->
|
||||
<!-- <if test="params.cellId != null and params.cellId!=''">-->
|
||||
<!-- and r.cell_id = #{params.cellId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.sn != null and params.sn!=''">-->
|
||||
<!-- and r.device_sn = #{params.sn}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.name != null and params.name!=''">-->
|
||||
<!-- and `name` like CONCAT('%', '${params.name}', '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.recordTimeStart != null and params.recordTimeStart!=''">-->
|
||||
<!-- and `record_time` >= #{params.recordTimeStart}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.recordTimeEnd != null and params.recordTimeEnd!=''">-->
|
||||
<!-- and `record_time` < #{params.recordTimeEnd}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="cellIds != null">-->
|
||||
<!-- and r.cell_id in-->
|
||||
<!-- <foreach item="cellId" collection="cellIds" open="(" separator="," close=")">-->
|
||||
<!-- #{cellId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </if>-->
|
||||
<!-- order by record_time desc-->
|
||||
|
||||
|
||||
select r.* from ten_record_${params.tenantId} r
|
||||
<if test="params.name != null and params.name!=''">
|
||||
left join ten_person t on r.person_id = t.person_id
|
||||
</if>
|
||||
where 1 = 1
|
||||
<if test="params.cellId != null and params.cellId!=''">
|
||||
and r.cell_id = #{params.cellId}
|
||||
|
@ -388,6 +417,21 @@
|
|||
</select>
|
||||
|
||||
|
||||
|
||||
<select id="findCellHourAll" resultType="int">
|
||||
select count(*) from ten_record_${params.tenantId} where 1 = 1
|
||||
<if test="params.cellId != null and params.cellId!=''">
|
||||
and cell_id = #{params.cellId}
|
||||
</if>
|
||||
<if test="params.recordTimeStart != null and params.recordTimeStart!=''">
|
||||
and `record_time` >= #{params.recordTimeStart}
|
||||
</if>
|
||||
<if test="params.recordTimeEnd != null and params.recordTimeStart!=''">
|
||||
and `record_time` < #{params.recordTimeEnd}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findPageBlackRecord" resultMap="tenRecordMap">
|
||||
<!--SELECT alias.* from (-->
|
||||
<!--<foreach collection="cellIds" item="item" index="index" separator="union all">-->
|
||||
|
|
Loading…
Reference in New Issue