|
|
@@ -1,11 +1,178 @@
|
|
|
package com.chuanghai.student_portrait.service.impl;
|
|
|
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.chuanghai.student_portrait.entity.AffinityScore;
|
|
|
+import com.chuanghai.student_portrait.entity.Consume;
|
|
|
+import com.chuanghai.student_portrait.entity.FaceDiscern;
|
|
|
+import com.chuanghai.student_portrait.entity.NewSchooluser;
|
|
|
import com.chuanghai.student_portrait.mapper.AffinityScoreMapper;
|
|
|
+import com.chuanghai.student_portrait.response.BaseResponse;
|
|
|
+import com.chuanghai.student_portrait.response.enums.StatusEnum;
|
|
|
import com.chuanghai.student_portrait.service.AffinityScoreService;
|
|
|
+import com.chuanghai.student_portrait.service.ConsumeService;
|
|
|
+import com.chuanghai.student_portrait.service.FaceDiscernService;
|
|
|
+import com.chuanghai.student_portrait.service.NewSchooluserService;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
public class AffinityScoreServiceImpl extends ServiceImpl<AffinityScoreMapper, AffinityScore> implements AffinityScoreService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FaceDiscernService faceDiscernService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ConsumeService consumeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ NewSchooluserService newSchooluserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseResponse getAffinityScore(String id) {
|
|
|
+ if (ObjectUtils.isEmpty(id)) {
|
|
|
+ return BaseResponse.error(StatusEnum.FAIL, "参数异常");
|
|
|
+ }
|
|
|
+ List<AffinityScore> list = this.list(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, id).orderByDesc(AffinityScore::getCount));
|
|
|
+
|
|
|
+ return BaseResponse.ok(StatusEnum.SUCCESS, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 29 17 * * ? ")
|
|
|
+ public void saveAndUpdateFaceAffinityScore() {
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
+ LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
|
|
|
+ String startTime = start.minusDays(1).format(pattern);
|
|
|
+
|
|
|
+ LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59);
|
|
|
+ String endTime = end.minusDays(1).format(pattern);
|
|
|
+// ArrayList<AffinityScore> saves = new ArrayList<>();
|
|
|
+// ArrayList<AffinityScore> updates = new ArrayList<>();
|
|
|
+ List<FaceDiscern> list = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, startTime, endTime).orderByAsc(FaceDiscern::getFacediscernTime));
|
|
|
+ if (ObjectUtils.isNotEmpty(list) && list.size() > 0) {
|
|
|
+ for (FaceDiscern faceDiscern : list) {
|
|
|
+ Date facediscernTime = faceDiscern.getFacediscernTime();
|
|
|
+ Date date1 = new Date(facediscernTime.getTime() + 10 * 1000);
|
|
|
+ Date date2 = new Date(facediscernTime.getTime() - 10 * 1000);
|
|
|
+ String shooluserId = faceDiscern.getShooluserId();
|
|
|
+
|
|
|
+ List<FaceDiscern> list1 = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, date2, date1));
|
|
|
+ if (ObjectUtils.isNotEmpty(list1) && list1.size() > 0) {
|
|
|
+ for (FaceDiscern discern : list1) {
|
|
|
+ String shooluserId1 = discern.getShooluserId();
|
|
|
+ if (!shooluserId.equals(shooluserId1)) {
|
|
|
+ AffinityScore one = this.getOne(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, shooluserId).eq(AffinityScore::getNameSchooluserId, shooluserId1));
|
|
|
+ if (ObjectUtils.isEmpty(one)) {
|
|
|
+ AffinityScore affinityScore = new AffinityScore();
|
|
|
+ affinityScore.setSchooluserId(shooluserId);
|
|
|
+ affinityScore.setDateTime(facediscernTime);
|
|
|
+ affinityScore.setNameSchooluserId(shooluserId1);
|
|
|
+ NewSchooluser newSchooluser = newSchooluserService.getById(shooluserId1);
|
|
|
+ affinityScore.setCount(1);
|
|
|
+ affinityScore.setName(newSchooluser.getName());
|
|
|
+ affinityScore.setStudentId(newSchooluser.getStudentId());
|
|
|
+ affinityScore.setProfession(newSchooluser.getProfession());
|
|
|
+ affinityScore.setClazz(newSchooluser.getClazz());
|
|
|
+ this.save(affinityScore);
|
|
|
+// saves.add(affinityScore);
|
|
|
+ } else {
|
|
|
+// long time = one.getDateTime().getTime();
|
|
|
+// long time1 = facediscernTime.getTime();
|
|
|
+// if (time1 > time) {
|
|
|
+ one.setDateTime(facediscernTime);
|
|
|
+ one.setCount(one.getCount() + 1);
|
|
|
+ AffinityScore affinityScore = new AffinityScore();
|
|
|
+ BeanUtils.copyProperties(one, affinityScore);
|
|
|
+// updates.add(affinityScore);
|
|
|
+ this.updateById(affinityScore);
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// this.saveBatch(saves);
|
|
|
+// this.updateBatchById(updates);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 34 17 * * ? ")
|
|
|
+ public void saveAndUpdateConsumeAffinityScore() {
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
+ LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
|
|
|
+ String startTime = start.minusDays(1).format(pattern);
|
|
|
+
|
|
|
+ LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59);
|
|
|
+ String endTime = end.minusDays(1).format(pattern);
|
|
|
+// ArrayList<AffinityScore> saves = new ArrayList<>();
|
|
|
+// ArrayList<AffinityScore> updates = new ArrayList<>();
|
|
|
+ List<Consume> list = consumeService.list(Wrappers.<Consume>lambdaQuery().between(Consume::getConsumeTime, startTime, endTime).orderByAsc(Consume::getConsumeTime));
|
|
|
+ if (ObjectUtils.isNotEmpty(list) && list.size() > 0) {
|
|
|
+ for (Consume consume1 : list) {
|
|
|
+ Date consumeTime = consume1.getConsumeTime();
|
|
|
+ Date date1 = new Date(consumeTime.getTime() + 30 * 1000);
|
|
|
+ Date date2 = new Date(consumeTime.getTime() - 30 * 1000);
|
|
|
+ String shooluserId = consume1.getIdCard();
|
|
|
+ if (ObjectUtils.isNotEmpty(shooluserId)) {
|
|
|
+ List<Consume> list1 = consumeService.list(Wrappers.<Consume>lambdaQuery().between(Consume::getConsumeTime, date2, date1));
|
|
|
+ if (ObjectUtils.isNotEmpty(list1) && list1.size() > 0) {
|
|
|
+ for (Consume consume : list1) {
|
|
|
+ String idCard = consume.getIdCard();
|
|
|
+ if (ObjectUtils.isNotEmpty(idCard)) {
|
|
|
+ if (!shooluserId.equals(idCard)) {
|
|
|
+ AffinityScore one = this.getOne(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, shooluserId).eq(AffinityScore::getNameSchooluserId, idCard));
|
|
|
+ if (ObjectUtils.isEmpty(one)) {
|
|
|
+ AffinityScore affinityScore = new AffinityScore();
|
|
|
+ affinityScore.setSchooluserId(shooluserId);
|
|
|
+ affinityScore.setDateTime(consumeTime);
|
|
|
+ affinityScore.setNameSchooluserId(idCard);
|
|
|
+ NewSchooluser newSchooluser = newSchooluserService.getById(idCard);
|
|
|
+ affinityScore.setCount(1);
|
|
|
+ affinityScore.setName(newSchooluser.getName());
|
|
|
+ affinityScore.setStudentId(newSchooluser.getStudentId());
|
|
|
+ affinityScore.setProfession(newSchooluser.getProfession());
|
|
|
+ affinityScore.setClazz(newSchooluser.getClazz());
|
|
|
+ this.save(affinityScore);
|
|
|
+// saves.add(affinityScore);
|
|
|
+ } else {
|
|
|
+// long time = one.getDateTime().getTime();
|
|
|
+// long time1 = consumeTime.getTime();
|
|
|
+// if (time1 > time) {
|
|
|
+ one.setDateTime(consumeTime);
|
|
|
+ one.setCount(one.getCount() + 1);
|
|
|
+ AffinityScore affinityScore = new AffinityScore();
|
|
|
+ BeanUtils.copyProperties(one, affinityScore);
|
|
|
+// updates.add(affinityScore);
|
|
|
+ this.updateById(affinityScore);
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// this.saveBatch(saves);
|
|
|
+// this.updateBatchById(updates);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|