This commit is contained in:
2025-01-14 11:26:37 +08:00
parent 02548a3028
commit f2f7fa22c9
10 changed files with 129 additions and 73 deletions

View File

@ -33,6 +33,7 @@ public interface TemplateMapper {
int deleteConfigByTemplateId(Long templateId); int deleteConfigByTemplateId(Long templateId);
int deleteConfigById(Long id); int deleteConfigById(Long id);
List<TemplateEntity> listEnabledByScenicId(Long scenicId); List<TemplateEntity> listEnabledByScenicId(Long scenicId);
List<TemplateEntity> listEnabled();
List<Long> listEnabledTemplateIdByScenicId(Long scenicId); List<Long> listEnabledTemplateIdByScenicId(Long scenicId);
List<ContentPageVO> listFor(@Param("scenicId") Long scenicId); List<ContentPageVO> listFor(@Param("scenicId") Long scenicId);
} }

View File

@ -3,8 +3,11 @@ package com.ycwl.basic.model.task.req;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
public class TaskReqVo extends WorkerAuthReqVo { public class TaskReqVo extends WorkerAuthReqVo {
private ClientStatusReqVo clientStatus; private ClientStatusReqVo clientStatus;
private List<TemplateCheckVO> templateList;
} }

View File

@ -0,0 +1,11 @@
package com.ycwl.basic.model.task.req;
import lombok.Data;
import java.util.Date;
@Data
public class TemplateCheckVO {
private String id;
private Date updateTime;
}

View File

@ -18,16 +18,18 @@ public class OrderRepository {
public static final String ORDER_ITEM_CACHE_KEY = "order:user:%s:type:%s:id:%s"; public static final String ORDER_ITEM_CACHE_KEY = "order:user:%s:type:%s:id:%s";
public boolean checkUserBuyItem(Long userId, int goodsType, Long goodsId) { public boolean checkUserBuyItem(Long userId, int goodsType, Long goodsId) {
if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId))) { synchronized (this) {
return "1".equals(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId))); if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId))) {
return "1".equals(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId)));
}
OrderEntity orderEntity = orderMapper.getUserBuyItem(userId, goodsType, goodsId);
if (orderEntity == null) {
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "0", 60, TimeUnit.SECONDS);
return false;
}
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "1");
return true;
} }
OrderEntity orderEntity = orderMapper.getUserBuyItem(userId, goodsType, goodsId);
if (orderEntity == null) {
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "0", 60, TimeUnit.SECONDS);
return false;
}
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "1");
return true;
} }
public boolean checkUserBuyFaceSourceImage(Long userId, Long faceId) { public boolean checkUserBuyFaceSourceImage(Long userId, Long faceId) {

View File

@ -5,12 +5,14 @@ import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper; import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.TemplateMapper; import com.ycwl.basic.mapper.TemplateMapper;
import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity; import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
import com.ycwl.basic.model.pc.template.entity.TemplateEntity;
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO; import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
import com.ycwl.basic.utils.SnowFlakeUtil; import com.ycwl.basic.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -44,6 +46,14 @@ public class TemplateRepository {
} }
} }
public List<TemplateRespVO> getAllEnabledTemplateList() {
List<TemplateEntity> entityList = templateMapper.listEnabled();
if (entityList == null) {
return Collections.emptyList();
}
return entityList.stream().map(entity -> getTemplate(entity.getId())).collect(Collectors.toList());
}
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) { public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
List<Long> idList; List<Long> idList;
if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) { if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) {

View File

@ -144,41 +144,50 @@ public class AppScenicServiceImpl implements AppScenicService {
sourceReqQuery.setMemberId(userId); sourceReqQuery.setMemberId(userId);
//查询源素材 //查询源素材
List<SourceRespVO> sourceList = sourceMapper.queryByRelation(sourceReqQuery); List<SourceRespVO> sourceList = sourceMapper.queryByRelation(sourceReqQuery);
ContentPageVO sourceVideoContent = new ContentPageVO();
ContentPageVO sourceImageContent = new ContentPageVO();
sourceVideoContent.setName("原片集");
sourceImageContent.setName("照片集");
sourceVideoContent.setScenicId(faceRespVO.getScenicId());
sourceImageContent.setScenicId(faceRespVO.getScenicId());
sourceVideoContent.setContentType(2);
sourceImageContent.setContentType(2);
sourceVideoContent.setLockType(1);
sourceImageContent.setLockType(1);
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(faceRespVO.getScenicId()); ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(faceRespVO.getScenicId());
sourceList.stream().collect(Collectors.groupingBy(SourceRespVO::getType)).keySet() if (!Integer.valueOf(1).equals(scenicConfig.getDisableSourceVideo())) {
.stream() IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), 1, faceId);
.filter(type -> { sourceVideoContent.setSourceType(isBuyRespVO.getGoodsType());
if (Integer.valueOf(1).equals(type)) { sourceVideoContent.setContentId(isBuyRespVO.getGoodsId());
if (Integer.valueOf(1).equals(scenicConfig.getDisableSourceVideo())) { if (isBuyRespVO.isBuy()) {
return false; sourceVideoContent.setIsBuy(1);
} } else {
} else if (Integer.valueOf(2).equals(type)) { sourceVideoContent.setIsBuy(0);
if (Integer.valueOf(1).equals(scenicConfig.getDisableSourceImage())) { }
return false; contentList.add(sourceVideoContent);
} }
} if (!Integer.valueOf(1).equals(scenicConfig.getDisableSourceImage())) {
return true; IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), 2, faceId);
}) sourceImageContent.setSourceType(isBuyRespVO.getGoodsType());
.forEach(type -> { sourceImageContent.setContentId(isBuyRespVO.getGoodsId());
ContentPageVO contentPageVO = new ContentPageVO(); if (isBuyRespVO.isBuy()) {
if (type == 1) { sourceImageContent.setIsBuy(1);
contentPageVO.setName("原片集"); } else {
} else { sourceImageContent.setIsBuy(0);
contentPageVO.setName("照片集"); }
} contentList.add(sourceImageContent);
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), type, faceId); }
contentPageVO.setSourceType(isBuyRespVO.getGoodsType());
contentPageVO.setContentId(isBuyRespVO.getGoodsId()); sourceList.stream().collect(Collectors.groupingBy(SourceRespVO::getType)).forEach((type, list) -> {
if (isBuyRespVO.isBuy()) { ContentPageVO contentPageVO = new ContentPageVO();
contentPageVO.setIsBuy(1); if (type == 1) {
} else { sourceVideoContent.setLockType(0);
contentPageVO.setIsBuy(0); sourceVideoContent.setTemplateCoverUrl(list.get(0).getUrl());
} } else {
contentPageVO.setScenicId(faceRespVO.getScenicId()); sourceImageContent.setLockType(0);
contentPageVO.setTemplateCoverUrl(sourceList.get(0).getUrl()); sourceImageContent.setTemplateCoverUrl(list.get(0).getUrl());
contentPageVO.setContentType(2); }
contentList.add(contentPageVO); });
});
return ApiResponse.success(contentList); return ApiResponse.success(contentList);
} }

View File

@ -187,30 +187,6 @@ public class FaceServiceImpl implements FaceService {
faceMapper.update(faceEntity); faceMapper.update(faceEntity);
faceRepository.clearFaceCache(faceEntity.getId()); faceRepository.clearFaceCache(faceEntity.getId());
} }
if (sampleListIds == null) {
return ApiResponse.fail("请先游玩后再来获取视频吧");
}
// 匹配原片:照片
List<SourceEntity> sourceEntities = sourceMapper.listBySampleIds(sampleListIds);
List<MemberSourceEntity> memberSourceEntityList = sourceEntities.stream().map(sourceEntity -> {
MemberSourceEntity memberSourceEntity = new MemberSourceEntity();
memberSourceEntity.setScenicId(scenicId);
memberSourceEntity.setFaceId(faceEntity.getId());
memberSourceEntity.setMemberId(userId);
memberSourceEntity.setSourceId(sourceEntity.getId());
memberSourceEntity.setType(sourceEntity.getType());
IsBuyRespVO isBuy = orderBiz.isBuy(userId, scenicId, sourceEntity.getType(), sourceEntity.getId());
if (isBuy.isBuy()) { // 如果用户买过
memberSourceEntity.setIsBuy(1);
} else if (isBuy.isFree()) { // 全免费逻辑
memberSourceEntity.setIsBuy(1);
} else {
memberSourceEntity.setIsBuy(0);
}
return memberSourceEntity;
}).collect(Collectors.toList());
sourceMapper.addRelations(memberSourceEntityList);
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq(); StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
statisticsRecordAddReq.setMemberId(userId); statisticsRecordAddReq.setMemberId(userId);
statisticsRecordAddReq.setType(StatisticEnum.UPLOAD_FACE.code); statisticsRecordAddReq.setType(StatisticEnum.UPLOAD_FACE.code);
@ -220,11 +196,33 @@ public class FaceServiceImpl implements FaceService {
FaceRecognizeResp resp = new FaceRecognizeResp(); FaceRecognizeResp resp = new FaceRecognizeResp();
resp.setUrl(faceUrl); resp.setUrl(faceUrl);
resp.setFaceId(faceEntity.getId()); resp.setFaceId(faceEntity.getId());
VideoPieceGetter.Task task = new VideoPieceGetter.Task(); if (sampleListIds != null && !sampleListIds.isEmpty()) {// 匹配原片:照片
task.faceId = faceEntity.getId(); List<SourceEntity> sourceEntities = sourceMapper.listBySampleIds(sampleListIds);
task.faceSampleIds = sampleListIds; List<MemberSourceEntity> memberSourceEntityList = sourceEntities.stream().map(sourceEntity -> {
task.memberId = userId; MemberSourceEntity memberSourceEntity = new MemberSourceEntity();
VideoPieceGetter.addTask(task); memberSourceEntity.setScenicId(scenicId);
memberSourceEntity.setFaceId(faceEntity.getId());
memberSourceEntity.setMemberId(userId);
memberSourceEntity.setSourceId(sourceEntity.getId());
memberSourceEntity.setType(sourceEntity.getType());
IsBuyRespVO isBuy = orderBiz.isBuy(userId, scenicId, sourceEntity.getType(), sourceEntity.getId());
if (isBuy.isBuy()) { // 如果用户买过
memberSourceEntity.setIsBuy(1);
} else if (isBuy.isFree()) { // 全免费逻辑
memberSourceEntity.setIsBuy(1);
} else {
memberSourceEntity.setIsBuy(0);
}
return memberSourceEntity;
}).collect(Collectors.toList());
sourceMapper.addRelations(memberSourceEntityList);
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
task.faceId = faceEntity.getId();
task.faceSampleIds = sampleListIds;
task.memberId = userId;
VideoPieceGetter.addTask(task);
}
return ApiResponse.success(resp); return ApiResponse.success(resp);
} }

View File

@ -60,6 +60,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -143,8 +144,24 @@ public class TaskTaskServiceImpl implements TaskService {
renderWorkerMapper.update(worker); renderWorkerMapper.update(worker);
TaskSyncRespVo resp = new TaskSyncRespVo(); TaskSyncRespVo resp = new TaskSyncRespVo();
// Template // Template
List<TemplateRespVO> updTemplateList;
if (req.getTemplateList() != null) {
updTemplateList = new ArrayList<>();
// 上报了本地模板列表
req.getTemplateList().forEach(template -> {
if (StringUtils.isNumeric(template.getId())) {
TemplateRespVO dbTemplate = templateRepository.getTemplate(Long.parseLong(template.getId()));
if (!dbTemplate.getUpdateTime().equals(template.getUpdateTime())) {
updTemplateList.add(dbTemplate);
}
}
});
} else {
updTemplateList = templateRepository.getAllEnabledTemplateList();
}
List<TaskRespVO> taskList = taskMapper.selectNotRunning(); List<TaskRespVO> taskList = taskMapper.selectNotRunning();
resp.setTasks(taskList); resp.setTasks(taskList);
resp.setTemplates(updTemplateList);
taskList.forEach(task -> { taskList.forEach(task -> {
taskMapper.assignToWorker(task.getId(), worker.getId()); taskMapper.assignToWorker(task.getId(), worker.getId());
videoTaskRepository.clearTaskCache(task.getId()); videoTaskRepository.clearTaskCache(task.getId());

View File

@ -118,7 +118,7 @@ public class VideoPieceGetter {
DeviceConfigEntity config = deviceRepository.getDeviceConfig(faceSample.getDeviceId()); DeviceConfigEntity config = deviceRepository.getDeviceConfig(faceSample.getDeviceId());
SourceEntity source = sourceMapper.querySameVideo(faceSample.getId(), device.getId()); SourceEntity source = sourceMapper.querySameVideo(faceSample.getId(), device.getId());
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), faceSample.getScenicId(), 1, faceSample.getId()); IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), faceSample.getScenicId(), 1, task.getFaceId());
if (source == null) { if (source == null) {
BigDecimal cutPre = BigDecimal.valueOf(5L); BigDecimal cutPre = BigDecimal.valueOf(5L);
BigDecimal cutPost = BigDecimal.valueOf(4L); BigDecimal cutPost = BigDecimal.valueOf(4L);

View File

@ -115,4 +115,9 @@
from template from template
where id = #{id} where id = #{id}
</select> </select>
<select id="listEnabled" resultType="com.ycwl.basic.model.pc.template.entity.TemplateEntity">
select *
from template
where status = 1 and pid = 0
</select>
</mapper> </mapper>