From c011bdd7f4fba1e3db7996511f3e4bc956f2ffdd Mon Sep 17 00:00:00 2001 From: gaoben Date: Tue, 7 Jun 2022 16:30:12 +0800 Subject: [PATCH] =?UTF-8?q?v4.0=20=E4=BC=98=E5=8C=96=E6=AF=8F=E5=B0=8F?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96=E8=AF=86=E5=88=AB=E4=B8=AA=E6=95=B0?= =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/job/task/HourRecordTask.java | 82 +++++++++++++++++++ .../modules/ten/dao/TenRecordDao.java | 2 + .../modules/ten/service/TenRecordService.java | 2 + .../service/impl/TenRecordServiceImpl.java | 22 ++++- .../resources/mapper/ten/TenRecordDao.xml | 46 ++++++++++- 5 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/job/task/HourRecordTask.java diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/HourRecordTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/HourRecordTask.java new file mode 100644 index 0000000..341dc1e --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/HourRecordTask.java @@ -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 allSysTenUser = this.sysUserService.findAllSysTenUser(); + + + Date now = new Date(); + + for (SysUserEntity sysTenUser : allSysTenUser) { + List allCells = this.tenCellService.list((Wrapper)(new QueryWrapper()) + .eq("tenant_id", sysTenUser.getTenantId())); + Long tenantId = sysTenUser.getTenantId(); + Map 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("按小时统计识别记录个数"); + } +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java index 9e5a294..74f96bd 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java @@ -31,6 +31,8 @@ public interface TenRecordDao { int findHourAll(@Param("cellIds") List cellIds, @Param("params") Map params); + int findCellHourAll(@Param("params") Map params); + IPage findPageBlackRecord(Page page, @Param("cellIds") List cellIds, @Param("params") Map params); IPage findPageRoomRecord(Page page, @Param("params") Map params); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java index 0f5357a..2dace6b 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java @@ -32,6 +32,8 @@ public interface TenRecordService { int getCount(Map params); int getHourCount(Map params); + int getCellHourCount(Map params); + List getLastRecord(Map params); List getNotSync(Long cellId, Long tenantId); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java index a8965fc..7db8240 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java @@ -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 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 params) { + return tenRecordDao.findCellHourAll(params); + } + private void publishRecordToWeb(TenRecordEntity entity){ TenRecordVo vo = new TenRecordVo(); vo.setRecordId(entity.getRecordId()); diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml index c117ee4..450456b 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml @@ -264,7 +264,36 @@ - select r.*,t.name from ten_record_${params.tenantId} r left join ten_person t on r.person_id = t.person_id + + + + + + + + + + + + + + + + + + + + + + + + + + + select r.* from ten_record_${params.tenantId} r + + left join ten_person t on r.person_id = t.person_id + where 1 = 1 and r.cell_id = #{params.cellId} @@ -388,6 +417,21 @@ + + + +