|
|
@@ -0,0 +1,190 @@
|
|
|
+package com.template.services.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.template.config.ScheduleConfig;
|
|
|
+import com.template.model.dto.WarningUserDto;
|
|
|
+import com.template.model.pojo.SmartAccess;
|
|
|
+import com.template.model.pojo.SmartFaceDiscern;
|
|
|
+import com.template.model.pojo.SmartRelation;
|
|
|
+import com.template.mapper.SmartRelationMapper;
|
|
|
+import com.template.model.pojo.SmartUser;
|
|
|
+import com.template.model.result.PageUtils;
|
|
|
+import com.template.model.vo.UserVo;
|
|
|
+import com.template.services.SmartAccessService;
|
|
|
+import com.template.services.SmartFaceDiscernService;
|
|
|
+import com.template.services.SmartRelationService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.template.services.SmartUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ceshi
|
|
|
+ * @since 2024-06-28
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, SmartRelation> implements SmartRelationService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ScheduleConfig scheduleConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SmartAccessService smartAccessService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SmartFaceDiscernService smartFaceDiscernService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SmartUserService smartUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SmartRelationMapper smartRelationMapper;
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 1 * * ? ")//每天凌晨一点
|
|
|
+ public void getAccessSmartRelation() {
|
|
|
+ if (scheduleConfig.getIsOpen().equals("1")) {
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0).minusDays(1);
|
|
|
+ LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59).minusDays(1);
|
|
|
+ String format = start.format(pattern);
|
|
|
+// 找到昨天的所有数据
|
|
|
+ List<SmartAccess> accessList = smartAccessService.toDatelist(start, end);
|
|
|
+
|
|
|
+ for (SmartAccess smartAccess : accessList) {
|
|
|
+ String dateTime = smartAccess.getDateTime();
|
|
|
+ LocalDateTime date = LocalDateTime.parse(dateTime, pattern);
|
|
|
+ LocalDateTime startTime = date.minusSeconds(10);
|
|
|
+ LocalDateTime endTime = date.plusSeconds(10);
|
|
|
+ Integer userId = smartAccess.getUserId();
|
|
|
+ SmartUser smartUser = smartUserService.getSmartById(userId);
|
|
|
+ List<SmartAccess> accesses = smartAccessService.toDatelist(startTime, endTime);
|
|
|
+ if (ObjectUtils.isNotEmpty(accesses) && accesses.size() > 0) {
|
|
|
+
|
|
|
+ for (SmartAccess access : accesses) {
|
|
|
+ Integer userId1 = access.getUserId();
|
|
|
+ SmartUser smartById = smartUserService.getSmartById(userId1);
|
|
|
+// 判断是否已添加,有的话则加1
|
|
|
+ LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SmartRelation::getUserId, userId)
|
|
|
+ .eq(SmartRelation::getRelationId, userId1)
|
|
|
+ .eq(SmartRelation::getDateTime,format);
|
|
|
+ SmartRelation one = this.getOne(wrapper);
|
|
|
+ if (ObjectUtils.isEmpty(one)) {
|
|
|
+ SmartRelation smartRelation = new SmartRelation();
|
|
|
+ smartRelation.setUserId(userId);
|
|
|
+ smartRelation.setRelationId(userId1);
|
|
|
+ if (ObjectUtils.isNotEmpty(smartUser)) {
|
|
|
+ smartRelation.setName(smartUser.getName());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(smartById)) {
|
|
|
+ smartRelation.setRelationName(smartById.getName());
|
|
|
+ }
|
|
|
+ smartRelation.setCount(0);
|
|
|
+ smartRelation.setDateTime(format);
|
|
|
+ this.save(smartRelation);
|
|
|
+ } else {
|
|
|
+ Integer count = one.getCount();
|
|
|
+ count = count + 1;
|
|
|
+ one.setCount(count);
|
|
|
+ this.updateById(one);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 2 * * ? ")//每天凌晨一点
|
|
|
+ public void getFaceDiscernListSmartRelation() {
|
|
|
+ if (scheduleConfig.getIsOpen().equals("1")) {
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0).minusDays(1);
|
|
|
+ LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59).minusDays(1);
|
|
|
+
|
|
|
+ String format = start.format(pattern);
|
|
|
+
|
|
|
+// 找到昨天的所有数据
|
|
|
+ List<SmartFaceDiscern> faceDiscernList = smartFaceDiscernService.toDateList(start, end);
|
|
|
+
|
|
|
+ for (SmartFaceDiscern faceDiscern : faceDiscernList) {
|
|
|
+ String dateTime = faceDiscern.getDateTime();
|
|
|
+ LocalDateTime date = LocalDateTime.parse(dateTime, pattern);
|
|
|
+ LocalDateTime startTime = date.minusSeconds(10);
|
|
|
+ LocalDateTime endTime = date.plusSeconds(10);
|
|
|
+ Integer userId = faceDiscern.getUserId();
|
|
|
+ SmartUser smartUser = smartUserService.getSmartById(userId);
|
|
|
+ List<SmartFaceDiscern> faceDiscerns = smartFaceDiscernService.toDateList(startTime, endTime);
|
|
|
+ if (ObjectUtils.isNotEmpty(faceDiscerns) && faceDiscerns.size() > 0) {
|
|
|
+
|
|
|
+ for (SmartFaceDiscern faceDiscern1 : faceDiscerns) {
|
|
|
+ Integer userId1 = faceDiscern1.getUserId();
|
|
|
+ SmartUser smartById = smartUserService.getSmartById(userId1);
|
|
|
+// 判断是否已添加,有的话则加1
|
|
|
+ LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SmartRelation::getUserId, userId)
|
|
|
+ .eq(SmartRelation::getRelationId, userId1)
|
|
|
+ .eq(SmartRelation::getDateTime,format);
|
|
|
+ SmartRelation one = this.getOne(wrapper);
|
|
|
+ if (ObjectUtils.isEmpty(one)) {
|
|
|
+ SmartRelation smartRelation = new SmartRelation();
|
|
|
+ smartRelation.setUserId(userId);
|
|
|
+ smartRelation.setRelationId(userId1);
|
|
|
+ if (ObjectUtils.isNotEmpty(smartUser)) {
|
|
|
+ smartRelation.setName(smartUser.getName());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(smartById)) {
|
|
|
+ smartRelation.setRelationName(smartById.getName());
|
|
|
+ }
|
|
|
+ smartRelation.setDateTime(format);
|
|
|
+ smartRelation.setCount(0);
|
|
|
+ this.save(smartRelation);
|
|
|
+ } else {
|
|
|
+ Integer count = one.getCount();
|
|
|
+ count = count + 1;
|
|
|
+ one.setCount(count);
|
|
|
+ this.updateById(one);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageUtils<SmartRelation> getPage(int currentPage, int pageCount, Integer userId) {
|
|
|
+// Page<UserVo> page = new Page<>();
|
|
|
+// page.setCurrent(currentPage);
|
|
|
+// page.setSize(pageCount);
|
|
|
+// IPage<WarningUserDto> result = smartUserMapper.warningUserList(page, name);
|
|
|
+// return new PageUtils(result);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|