2
This commit is contained in:
parent
25d563cb2b
commit
348a3801df
@ -10,6 +10,7 @@ import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
|
|||||||
import com.ycwl.basic.repository.FaceRepository;
|
import com.ycwl.basic.repository.FaceRepository;
|
||||||
import com.ycwl.basic.repository.SourceRepository;
|
import com.ycwl.basic.repository.SourceRepository;
|
||||||
import com.ycwl.basic.repository.TemplateRepository;
|
import com.ycwl.basic.repository.TemplateRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class TemplateBiz {
|
public class TemplateBiz {
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -29,8 +31,11 @@ public class TemplateBiz {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SourceRepository sourceRepository;
|
private SourceRepository sourceRepository;
|
||||||
|
|
||||||
|
|
||||||
public boolean determineTemplateCanGenerate(Long templateId, Long faceId) {
|
public boolean determineTemplateCanGenerate(Long templateId, Long faceId) {
|
||||||
|
return determineTemplateCanGenerate(templateId, faceId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean determineTemplateCanGenerate(Long templateId, Long faceId, boolean scanSource) {
|
||||||
List<String> placeholderList = templateRepository.getTemplatePlaceholder(templateId);
|
List<String> placeholderList = templateRepository.getTemplatePlaceholder(templateId);
|
||||||
TemplateConfigEntity templateConfig = templateRepository.getTemplateConfig(templateId);
|
TemplateConfigEntity templateConfig = templateRepository.getTemplateConfig(templateId);
|
||||||
int minimalPlaceholderFill = 1;
|
int minimalPlaceholderFill = 1;
|
||||||
@ -47,8 +52,65 @@ public class TemplateBiz {
|
|||||||
if (faceSampleList.isEmpty()) {
|
if (faceSampleList.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<SourceEntity> sourceEntities = sourceMapper.listVideoByScenicFaceRelation(face.getScenicId(), faceId);
|
long count;
|
||||||
long count = sourceEntities.stream().map(SourceEntity::getDeviceId).filter(deviceId -> placeholderList.contains(deviceId.toString())).count();
|
if (scanSource) {
|
||||||
|
List<SourceEntity> sourceEntities = sourceMapper.listVideoByScenicFaceRelation(face.getScenicId(), faceId);
|
||||||
|
count = sourceEntities.stream()
|
||||||
|
.map(SourceEntity::getDeviceId)
|
||||||
|
.distinct()
|
||||||
|
.filter(deviceId -> placeholderList.contains(deviceId.toString()))
|
||||||
|
.count();
|
||||||
|
} else {
|
||||||
|
count = faceSampleList.stream()
|
||||||
|
.map(FaceSampleEntity::getDeviceId)
|
||||||
|
.distinct()
|
||||||
|
.filter(deviceId -> placeholderList.contains(deviceId.toString()))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
return count >= minimalPlaceholderFill;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean determineTemplateCanAutoGenerate(Long templateId, Long faceId) {
|
||||||
|
return determineTemplateCanAutoGenerate(templateId, faceId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean determineTemplateCanAutoGenerate(Long templateId, Long faceId, boolean scanSource) {
|
||||||
|
List<String> placeholderList = templateRepository.getTemplatePlaceholder(templateId);
|
||||||
|
TemplateConfigEntity templateConfig = templateRepository.getTemplateConfig(templateId);
|
||||||
|
Integer minimalPlaceholderFill = null;
|
||||||
|
if (null != templateConfig) {
|
||||||
|
if (null != templateConfig.getAutomaticPlaceholderFill()) {
|
||||||
|
minimalPlaceholderFill = templateConfig.getAutomaticPlaceholderFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (minimalPlaceholderFill == null) {
|
||||||
|
// 未开启
|
||||||
|
log.info("模板:{},未配置最小自动生成功能,默认不生成", templateId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (minimalPlaceholderFill <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
FaceEntity face = faceRepository.getFace(faceId);
|
||||||
|
List<FaceSampleEntity> faceSampleList = faceRepository.getFaceSampleList(faceId);
|
||||||
|
if (faceSampleList.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
long count;
|
||||||
|
if (scanSource) {
|
||||||
|
List<SourceEntity> sourceEntities = sourceMapper.listVideoByScenicFaceRelation(face.getScenicId(), faceId);
|
||||||
|
count = sourceEntities.stream()
|
||||||
|
.map(SourceEntity::getDeviceId)
|
||||||
|
.distinct()
|
||||||
|
.filter(deviceId -> placeholderList.contains(deviceId.toString()))
|
||||||
|
.count();
|
||||||
|
} else {
|
||||||
|
count = faceSampleList.stream()
|
||||||
|
.map(FaceSampleEntity::getDeviceId)
|
||||||
|
.distinct()
|
||||||
|
.filter(deviceId -> placeholderList.contains(deviceId.toString()))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
return count >= minimalPlaceholderFill;
|
return count >= minimalPlaceholderFill;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,4 +32,5 @@ public class FaceReqQuery extends BaseQueryParameterReq {
|
|||||||
private String matchResult;
|
private String matchResult;
|
||||||
private Date startTime;
|
private Date startTime;
|
||||||
private Date endTime;
|
private Date endTime;
|
||||||
|
private Integer finishedJourney;
|
||||||
}
|
}
|
||||||
|
@ -380,15 +380,12 @@ public class WxPayServiceImpl implements WxPayService {
|
|||||||
*/
|
*/
|
||||||
public String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) throws GeneralSecurityException, IOException {
|
public String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) throws GeneralSecurityException, IOException {
|
||||||
try {
|
try {
|
||||||
Cipher cipher = Cipher.getInstance(HttpConstant.AES_GCM_NoPadding);
|
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||||
|
SecretKeySpec key = new SecretKeySpec(wechatConfig.getApiV3().getBytes(), "AES");
|
||||||
SecretKeySpec key = new SecretKeySpec(wechatConfig.getKeyPath().getBytes(), HttpConstant.AES);
|
GCMParameterSpec spec = new GCMParameterSpec(128, nonce);
|
||||||
GCMParameterSpec spec = new GCMParameterSpec(NumberConstant.ONE_HUNDRED_TWENTY_EIGHT, nonce);// 规定为128
|
|
||||||
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, key, spec);
|
cipher.init(Cipher.DECRYPT_MODE, key, spec);
|
||||||
cipher.updateAAD(associatedData);
|
cipher.updateAAD(associatedData);
|
||||||
|
return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), StandardCharsets.UTF_8);
|
||||||
return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), String.valueOf(StandardCharsets.UTF_8));
|
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
|
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
|
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||||
|
@ -170,6 +170,13 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
faceEntity.setFaceUrl(faceUrl);
|
faceEntity.setFaceUrl(faceUrl);
|
||||||
faceEntity.setId(newFaceId);
|
faceEntity.setId(newFaceId);
|
||||||
faceMapper.add(faceEntity);
|
faceMapper.add(faceEntity);
|
||||||
|
} else {
|
||||||
|
//更新人脸
|
||||||
|
FaceEntity faceEntity = new FaceEntity();
|
||||||
|
faceEntity.setId(oldFaceId);
|
||||||
|
faceEntity.setFaceUrl(faceUrl);
|
||||||
|
faceMapper.update(faceEntity);
|
||||||
|
faceRepository.clearFaceCache(oldFaceId);
|
||||||
}
|
}
|
||||||
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
|
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
|
||||||
statisticsRecordAddReq.setMemberId(userId);
|
statisticsRecordAddReq.setMemberId(userId);
|
||||||
|
@ -371,10 +371,6 @@ public class TaskTaskServiceImpl implements TaskService {
|
|||||||
memberVideoEntity.setIsBuy(1);
|
memberVideoEntity.setIsBuy(1);
|
||||||
}
|
}
|
||||||
memberVideoEntity.setVideoId(video.getId());
|
memberVideoEntity.setVideoId(video.getId());
|
||||||
// 已经生成了
|
|
||||||
new Thread(() -> {
|
|
||||||
sendVideoGeneratedServiceNotification(list.get(0).getId(), face.getMemberId());
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
videoMapper.addRelation(memberVideoEntity);
|
videoMapper.addRelation(memberVideoEntity);
|
||||||
|
59
src/main/java/com/ycwl/basic/task/VideoTaskGenerator.java
Normal file
59
src/main/java/com/ycwl/basic/task/VideoTaskGenerator.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package com.ycwl.basic.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.ycwl.basic.biz.TemplateBiz;
|
||||||
|
import com.ycwl.basic.mapper.FaceMapper;
|
||||||
|
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||||
|
import com.ycwl.basic.mapper.TemplateMapper;
|
||||||
|
import com.ycwl.basic.model.pc.face.req.FaceReqQuery;
|
||||||
|
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
|
||||||
|
import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
|
||||||
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
|
import com.ycwl.basic.repository.TemplateRepository;
|
||||||
|
import com.ycwl.basic.service.task.TaskFaceService;
|
||||||
|
import com.ycwl.basic.service.task.impl.TaskTaskServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@EnableScheduling
|
||||||
|
@Component
|
||||||
|
public class VideoTaskGenerator {
|
||||||
|
@Autowired
|
||||||
|
private FaceMapper faceMapper;
|
||||||
|
@Autowired
|
||||||
|
private TaskFaceService taskFaceService;
|
||||||
|
@Autowired
|
||||||
|
private ScenicRepository scenicRepository;
|
||||||
|
@Autowired
|
||||||
|
private TemplateMapper templateMapper;
|
||||||
|
@Autowired
|
||||||
|
private TemplateBiz templateBiz;
|
||||||
|
@Autowired
|
||||||
|
private FaceSampleMapper faceSampleMapper;
|
||||||
|
@Autowired
|
||||||
|
private TaskTaskServiceImpl taskTaskService;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 18 * * *")
|
||||||
|
public void generateVideoTask() {
|
||||||
|
// 指定,获取指定日期的未完成人脸样本,并生成任务
|
||||||
|
Long scenicId = 3946669713328836608L;
|
||||||
|
Long templateId = 3947461229940969472L;
|
||||||
|
FaceReqQuery query = new FaceReqQuery();
|
||||||
|
query.setScenicId(scenicId);
|
||||||
|
query.setStartTime(DateUtil.beginOfDay(new Date()));
|
||||||
|
query.setEndTime(DateUtil.endOfDay(new Date()));
|
||||||
|
List<FaceRespVO> list = faceMapper.list(query);
|
||||||
|
list.stream().parallel().forEach(face -> {
|
||||||
|
taskFaceService.searchFace(face.getId());
|
||||||
|
boolean canAutoGenerate = templateBiz.determineTemplateCanAutoGenerate(templateId, face.getId(), false);
|
||||||
|
if (canAutoGenerate) {
|
||||||
|
taskTaskService.autoCreateTaskByFaceId(face.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user