This commit is contained in:
Jerry Yan 2024-12-30 20:47:34 +08:00
parent 2031b77f12
commit cfd48861d5
17 changed files with 134 additions and 61 deletions

View File

@ -32,6 +32,7 @@ import com.ycwl.basic.utils.IpUtils;
import com.ycwl.basic.utils.SnowFlakeUtil; import com.ycwl.basic.utils.SnowFlakeUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -40,6 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -86,7 +88,6 @@ public class ViidController {
device.setId(SnowFlakeUtil.getLongId()); device.setId(SnowFlakeUtil.getLongId());
deviceMapper.addEntity(device); deviceMapper.addEntity(device);
} }
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHHmmss");
return new VIIDBaseResp( return new VIIDBaseResp(
new ResponseStatusObject(serverId, "/VIID/System/Register", "0", "注册成功", sdfTime.format(new Date())) new ResponseStatusObject(serverId, "/VIID/System/Register", "0", "注册成功", sdfTime.format(new Date()))
); );
@ -125,7 +126,6 @@ public class ViidController {
} }
log.info("已经解析过的心跳信息:{}", keepaliveObject); log.info("已经解析过的心跳信息:{}", keepaliveObject);
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHHmmss");
return new VIIDBaseResp( return new VIIDBaseResp(
new ResponseStatusObject(deviceId, "/VIID/System/UnRegister", "0", "注销成功", sdfTime.format(new Date())) new ResponseStatusObject(deviceId, "/VIID/System/UnRegister", "0", "注销成功", sdfTime.format(new Date()))
); );
@ -152,7 +152,6 @@ public class ViidController {
device.setKeepaliveAt(new Date()); device.setKeepaliveAt(new Date());
int update = deviceMapper.updateEntity(device); int update = deviceMapper.updateEntity(device);
} }
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHHmmss");
return new VIIDBaseResp( return new VIIDBaseResp(
new ResponseStatusObject(deviceId, "/VIID/System/UnRegister", "0", "注销成功", sdfTime.format(new Date())) new ResponseStatusObject(deviceId, "/VIID/System/UnRegister", "0", "注销成功", sdfTime.format(new Date()))
); );
@ -178,6 +177,7 @@ public class ViidController {
@Autowired @Autowired
private TaskFaceService taskFaceService; private TaskFaceService taskFaceService;
private final SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHHmmss");
/** /**
@ -202,6 +202,14 @@ public class ViidController {
if (device == null) { if (device == null) {
continue; continue;
} }
Date shotTime = new Date();
if (StringUtils.isNotBlank(face.getShotTime())) {
try {
shotTime = sdfTime.parse(face.getShotTime());
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
Long scenicId = device.getScenicId(); Long scenicId = device.getScenicId();
if (scenicId == null) { if (scenicId == null) {
continue; continue;
@ -229,7 +237,7 @@ public class ViidController {
faceSample.setScenicId(scenicId); faceSample.setScenicId(scenicId);
faceSample.setDeviceId(device.getId()); faceSample.setDeviceId(device.getId());
faceSample.setStatus(0); faceSample.setStatus(0);
faceSample.setCreateAt(new Date()); faceSample.setCreateAt(shotTime);
String url = adapter.uploadFile(file, "user-face", UUID.randomUUID() + "." + ext); String url = adapter.uploadFile(file, "user-face", UUID.randomUUID() + "." + ext);
faceSample.setFaceUrl(url); faceSample.setFaceUrl(url);
faceSampleMapper.add(faceSample); faceSampleMapper.add(faceSample);
@ -245,6 +253,7 @@ public class ViidController {
source.setDeviceId(device.getId()); source.setDeviceId(device.getId());
source.setScenicId(device.getScenicId()); source.setScenicId(device.getScenicId());
source.setFaceSampleId(newFaceSampleId); source.setFaceSampleId(newFaceSampleId);
source.setCreateTime(shotTime);
source.setType(2); source.setType(2);
// 上传oss // 上传oss
String url = adapter.uploadFile(file, "user-photo", UUID.randomUUID() + "." + ext); String url = adapter.uploadFile(file, "user-photo", UUID.randomUUID() + "." + ext);
@ -257,7 +266,6 @@ public class ViidController {
log.info("设备ID{}", deviceID); log.info("设备ID{}", deviceID);
} }
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHHmmss");
return new VIIDBaseResp( return new VIIDBaseResp(
new ResponseStatusObject(faceId, "/VIID/Faces", "0", "OK", sdfTime.format(new Date())) new ResponseStatusObject(faceId, "/VIID/Faces", "0", "OK", sdfTime.format(new Date()))
); );

View File

@ -55,4 +55,8 @@ public interface SourceMapper {
int updateRelation(MemberSourceEntity memberSourceEntity); int updateRelation(MemberSourceEntity memberSourceEntity);
List<SourceRespVO> queryByRelation(SourceReqQuery sourceReqQuery); List<SourceRespVO> queryByRelation(SourceReqQuery sourceReqQuery);
SourceEntity querySameVideo(Long faceSampleId, Long deviceId);
int hasRelationTo(Long memberId, Long sourceId, int type);
} }

View File

@ -33,5 +33,5 @@ public interface TemplateMapper {
int deleteConfigById(Long id); int deleteConfigById(Long id);
List<TemplateEntity> listEnabledByScenicId(Long scenicId); List<TemplateEntity> listEnabledByScenicId(Long scenicId);
List<ContentPageVO> listFor(@Param("scenicId") Long scenicId, @Param("faceId") Long faceId); List<ContentPageVO> listFor(@Param("scenicId") Long scenicId);
} }

View File

@ -30,4 +30,6 @@ public interface VideoMapper {
int updateRelation(MemberVideoEntity memberVideoEntity); int updateRelation(MemberVideoEntity memberVideoEntity);
List<VideoRespVO> queryByRelation(VideoReqQuery videoReqQuery); List<VideoRespVO> queryByRelation(VideoReqQuery videoReqQuery);
List<MemberVideoEntity> userFaceTemplateVideo(Long userId, Long faceId, Long templateId);
} }

View File

@ -8,6 +8,8 @@ import lombok.Data;
public class MemberSourceEntity { public class MemberSourceEntity {
private Long id; private Long id;
private Long memberId; private Long memberId;
private Long scenicId;
private Long faceId;
private Integer type; private Integer type;
private Long sourceId; private Long sourceId;
private Integer isBuy; private Integer isBuy;

View File

@ -26,10 +26,6 @@ public class SourceEntity {
* 来源设备id * 来源设备id
*/ */
private Long deviceId; private Long deviceId;
/**
* 所属用户
*/
private Long memberId;
/** /**
* 人脸样本id * 人脸样本id
*/ */

View File

@ -44,7 +44,7 @@ public class SourceReqQuery extends BaseQueryParameterReq {
private String url; private String url;
@ApiModelProperty("是否被购买0未购买1已购买") @ApiModelProperty("是否被购买0未购买1已购买")
private Integer isBuy; private Integer isBuy;
private Integer faceId; private Long faceId;
private Date startTime; private Date startTime;
private Date endTime; private Date endTime;
} }

View File

@ -21,6 +21,7 @@ import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO; import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
import com.ycwl.basic.model.pc.source.req.SourceReqQuery; import com.ycwl.basic.model.pc.source.req.SourceReqQuery;
import com.ycwl.basic.model.pc.source.resp.SourceRespVO; import com.ycwl.basic.model.pc.source.resp.SourceRespVO;
import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity;
import com.ycwl.basic.model.pc.video.req.VideoReqQuery; import com.ycwl.basic.model.pc.video.req.VideoReqQuery;
import com.ycwl.basic.model.pc.video.resp.VideoRespVO; import com.ycwl.basic.model.pc.video.resp.VideoRespVO;
import com.ycwl.basic.service.mobile.AppScenicService; import com.ycwl.basic.service.mobile.AppScenicService;
@ -133,20 +134,15 @@ public class AppScenicServiceImpl implements AppScenicService {
FaceRespVO faceRespVO = faceMapper.getById(faceId); FaceRespVO faceRespVO = faceMapper.getById(faceId);
if (StringUtils.isBlank(faceRespVO.getMatchSampleIds())) { if (StringUtils.isBlank(faceRespVO.getMatchSampleIds())) {
return ApiResponse.success(new ArrayList<>()); // return ApiResponse.success(new ArrayList<>());
} }
List<ContentPageVO> contentList = templateMapper.listFor(faceRespVO.getScenicId(), faceId); List<ContentPageVO> contentList = templateMapper.listFor(faceRespVO.getScenicId());
contentList.forEach(contentPageVO -> { contentList.forEach(contentPageVO -> {
if (contentPageVO.getContentType() == 1) { List<MemberVideoEntity> memberVideoEntityList = videoMapper.userFaceTemplateVideo(worker.getUserId(), faceId, contentPageVO.getTemplateId());
VideoReqQuery videoReqQuery = new VideoReqQuery(); if (!memberVideoEntityList.isEmpty()) {
videoReqQuery.setScenicId(contentPageVO.getScenicId()); contentPageVO.setIsBuy(memberVideoEntityList.get(0).getIsBuy());
videoReqQuery.setTemplateId(contentPageVO.getTemplateId()); contentPageVO.setContentId(memberVideoEntityList.get(0).getId());
videoReqQuery.setMemberId(worker.getUserId());
List<VideoRespVO> videoList = videoMapper.list(videoReqQuery);
if (!videoList.isEmpty()) {
contentPageVO.setContentId(videoList.get(0).getId());
}
} }
}); });
@ -180,17 +176,12 @@ public class AppScenicServiceImpl implements AppScenicService {
if (StringUtils.isBlank(faceRespVO.getMatchSampleIds())) { if (StringUtils.isBlank(faceRespVO.getMatchSampleIds())) {
return ApiResponse.success(new ArrayList<>()); return ApiResponse.success(new ArrayList<>());
} }
List<ContentPageVO> contentList = templateMapper.listFor(faceRespVO.getScenicId(), faceId); List<ContentPageVO> contentList = templateMapper.listFor(faceRespVO.getScenicId());
contentList.forEach(contentPageVO -> { contentList.forEach(contentPageVO -> {
if (contentPageVO.getContentType() == 1) { List<MemberVideoEntity> memberVideoEntityList = videoMapper.userFaceTemplateVideo(userId, faceId, contentPageVO.getTemplateId());
VideoReqQuery videoReqQuery = new VideoReqQuery(); if (!memberVideoEntityList.isEmpty()) {
videoReqQuery.setScenicId(contentPageVO.getScenicId()); contentPageVO.setIsBuy(memberVideoEntityList.get(0).getIsBuy());
videoReqQuery.setTemplateId(contentPageVO.getTemplateId()); contentPageVO.setContentId(memberVideoEntityList.get(0).getId());
videoReqQuery.setMemberId(userId);
List<VideoRespVO> videoList = videoMapper.list(videoReqQuery);
if (!videoList.isEmpty()) {
contentPageVO.setContentId(videoList.get(0).getId());
}
} }
}); });

View File

@ -79,12 +79,12 @@ public class GoodsServiceImpl implements GoodsService {
GoodsPageVO goodsPageVO = new GoodsPageVO(); GoodsPageVO goodsPageVO = new GoodsPageVO();
if (type == 1) { if (type == 1) {
goodsPageVO.setGoodsName("原片集"); goodsPageVO.setGoodsName("原片集");
goodsPageVO.setGoodsType(2);
} else { } else {
goodsPageVO.setGoodsName("照片集"); goodsPageVO.setGoodsName("照片集");
goodsPageVO.setGoodsType(3);
} }
goodsPageVO.setScenicId(query.getScenicId()); goodsPageVO.setScenicId(query.getScenicId());
goodsPageVO.setGoodsType(2);
goodsPageVO.setSourceType(type);
goodsList.add(goodsPageVO); goodsList.add(goodsPageVO);
}); });
@ -99,6 +99,7 @@ public class GoodsServiceImpl implements GoodsService {
sourceReqQuery.setIsBuy(query.getIsBuy()); sourceReqQuery.setIsBuy(query.getIsBuy());
sourceReqQuery.setMemberId(query.getMemberId()); sourceReqQuery.setMemberId(query.getMemberId());
sourceReqQuery.setType(sourceType); sourceReqQuery.setType(sourceType);
sourceReqQuery.setFaceId(query.getFaceId());
List<SourceRespVO> list = sourceMapper.listUser(sourceReqQuery); List<SourceRespVO> list = sourceMapper.listUser(sourceReqQuery);
List<GoodsDetailVO> goodsDetailVOList = new ArrayList<>(); List<GoodsDetailVO> goodsDetailVOList = new ArrayList<>();

View File

@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.ycwl.basic.enums.StatisticEnum; import com.ycwl.basic.enums.StatisticEnum;
import com.ycwl.basic.exception.BaseException; import com.ycwl.basic.exception.BaseException;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.SourceMapper; import com.ycwl.basic.mapper.SourceMapper;
import com.ycwl.basic.mapper.StatisticsMapper; import com.ycwl.basic.mapper.StatisticsMapper;
import com.ycwl.basic.mapper.FaceMapper; import com.ycwl.basic.mapper.FaceMapper;
@ -13,6 +14,7 @@ import com.ycwl.basic.model.mobile.statistic.req.StatisticsRecordAddReq;
import com.ycwl.basic.model.pc.face.entity.FaceEntity; import com.ycwl.basic.model.pc.face.entity.FaceEntity;
import com.ycwl.basic.model.pc.face.req.FaceReqQuery; import com.ycwl.basic.model.pc.face.req.FaceReqQuery;
import com.ycwl.basic.model.pc.face.resp.FaceRespVO; import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity; import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
import com.ycwl.basic.model.pc.source.entity.SourceEntity; import com.ycwl.basic.model.pc.source.entity.SourceEntity;
import com.ycwl.basic.model.task.resp.SearchFaceRespVo; import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
@ -22,6 +24,7 @@ import com.ycwl.basic.service.task.TaskService;
import com.ycwl.basic.storage.StorageFactory; import com.ycwl.basic.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter; import com.ycwl.basic.storage.adapters.IStorageAdapter;
import com.ycwl.basic.storage.utils.StorageUtil; import com.ycwl.basic.storage.utils.StorageUtil;
import com.ycwl.basic.task.VideoPieceGetter;
import com.ycwl.basic.utils.*; import com.ycwl.basic.utils.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -58,6 +61,8 @@ public class FaceServiceImpl implements FaceService {
private TaskService taskTaskService; private TaskService taskTaskService;
@Autowired @Autowired
private SourceMapper sourceMapper; private SourceMapper sourceMapper;
@Autowired
private FaceSampleMapper faceSampleMapper;
@Override @Override
public ApiResponse<PageInfo<FaceRespVO>> pageQuery(FaceReqQuery faceReqQuery) { public ApiResponse<PageInfo<FaceRespVO>> pageQuery(FaceReqQuery faceReqQuery) {
@ -141,11 +146,11 @@ public class FaceServiceImpl implements FaceService {
throw new BaseException("人脸照片校验失败,请重新上传"); throw new BaseException("人脸照片校验失败,请重新上传");
} }
// 2通过人脸查找用户库 // 2通过人脸查找用户库
SearchFaceRespVo userDbSearchResult = faceService.searchFace(USER_FACE_DB_NAME, faceUrl);
Long newFaceId = SnowFlakeUtil.getLongId(); Long newFaceId = SnowFlakeUtil.getLongId();
FaceEntity faceEntity = new FaceEntity(); FaceEntity faceEntity = new FaceEntity();
faceEntity.setScore(scenicDbSearchResult.getScore()); faceEntity.setScore(scenicDbSearchResult.getScore());
faceEntity.setMatchResult(scenicDbSearchResult.getSearchResultJson()); faceEntity.setMatchResult(scenicDbSearchResult.getSearchResultJson());
SearchFaceRespVo userDbSearchResult = faceService.searchFace(USER_FACE_DB_NAME, faceUrl);
if (userDbSearchResult == null) { if (userDbSearchResult == null) {
// 都是null了那得是新的 // 都是null了那得是新的
faceService.addFaceSample(USER_FACE_DB_NAME, newFaceId.toString(), faceUrl, newFaceId.toString()); faceService.addFaceSample(USER_FACE_DB_NAME, newFaceId.toString(), faceUrl, newFaceId.toString());
@ -158,8 +163,13 @@ public class FaceServiceImpl implements FaceService {
} else { } else {
// 有匹配结果且能匹配旧的数据 // 有匹配结果且能匹配旧的数据
Long oldFaceId = userDbSearchResult.getSampleListIds().get(0); Long oldFaceId = userDbSearchResult.getSampleListIds().get(0);
FaceRespVO oldFace = faceMapper.getById(oldFaceId);
if (oldFace == null) {
faceService.deleteFaceSample(USER_FACE_DB_NAME, oldFaceId.toString());
} else {
faceEntity.setId(oldFaceId); faceEntity.setId(oldFaceId);
} }
}
if (scenicDbSearchResult.getFirstMatchRate() != null) { if (scenicDbSearchResult.getFirstMatchRate() != null) {
faceEntity.setFirstMatchRate(BigDecimal.valueOf(scenicDbSearchResult.getFirstMatchRate())); faceEntity.setFirstMatchRate(BigDecimal.valueOf(scenicDbSearchResult.getFirstMatchRate()));
} }
@ -173,14 +183,6 @@ public class FaceServiceImpl implements FaceService {
List<Long> sampleListIds = scenicDbSearchResult.getSampleListIds(); List<Long> sampleListIds = scenicDbSearchResult.getSampleListIds();
// 匹配原片照片 // 匹配原片照片
List<SourceEntity> sourceEntities = sourceMapper.listBySampleIds(sampleListIds); List<SourceEntity> sourceEntities = sourceMapper.listBySampleIds(sampleListIds);
List<MemberSourceEntity> memberSourceEntityList = sourceEntities.stream().map(sourceEntity -> {
MemberSourceEntity memberSourceEntity = new MemberSourceEntity();
memberSourceEntity.setMemberId(userId);
memberSourceEntity.setSourceId(sourceEntity.getId());
memberSourceEntity.setType(sourceEntity.getType());
memberSourceEntity.setIsBuy(0);
return memberSourceEntity;
}).collect(Collectors.toList());
if (faceEntity.getId()==null) { if (faceEntity.getId()==null) {
//新增人脸 //新增人脸
faceEntity.setId(newFaceId); faceEntity.setId(newFaceId);
@ -191,7 +193,26 @@ public class FaceServiceImpl implements FaceService {
faceMapper.update(faceEntity); faceMapper.update(faceEntity);
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId()); taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
} }
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());
memberSourceEntity.setIsBuy(0);
return memberSourceEntity;
}).collect(Collectors.toList());
sourceMapper.addRelations(memberSourceEntityList); sourceMapper.addRelations(memberSourceEntityList);
List<FaceSampleRespVO> faceSampleList = faceSampleMapper.listByIds(sampleListIds);
for (FaceSampleRespVO sampleRespVO : faceSampleList) {
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
task.faceId = faceEntity.getId();
task.faceSampleId = sampleRespVO.getId();
task.memberId = userId;
task.createTime = sampleRespVO.getCreateAt();
VideoPieceGetter.addTask(task);
}
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);

View File

@ -339,6 +339,21 @@ public class TaskFaceServiceImpl implements TaskFaceService {
} }
} }
@Override
public boolean deleteFaceSample(String dbName, String entityId) {
DeleteFaceEntityRequest deleteFaceEntityRequest = new DeleteFaceEntityRequest();
deleteFaceEntityRequest.setDbName(dbName);
deleteFaceEntityRequest.setEntityId(entityId);
try {
IAcsClient client = getClient();
client.getAcsResponse(deleteFaceEntityRequest);
return true;
} catch (ClientException e) {
log.error("删除人脸样本失败!", e);
return false;
}
}
public void addFaceDBCache(String dbName) { public void addFaceDBCache(String dbName) {
redisTemplate.opsForValue().set(FaceConstant.FACE_DB_NAME_PFX + dbName, "1"); redisTemplate.opsForValue().set(FaceConstant.FACE_DB_NAME_PFX + dbName, "1");
} }

View File

@ -192,6 +192,9 @@ public class TaskTaskServiceImpl implements TaskService {
@Override @Override
public void autoCreateTaskByFaceId(Long id) { public void autoCreateTaskByFaceId(Long id) {
FaceRespVO faceRespVO = faceMapper.getById(id); FaceRespVO faceRespVO = faceMapper.getById(id);
if (faceRespVO == null) {
return;
}
if (!StringUtils.isNotBlank(faceRespVO.getMatchSampleIds())) { if (!StringUtils.isNotBlank(faceRespVO.getMatchSampleIds())) {
return; return;
} }
@ -244,7 +247,6 @@ public class TaskTaskServiceImpl implements TaskService {
VideoPieceGetter.Task task = new VideoPieceGetter.Task(); VideoPieceGetter.Task task = new VideoPieceGetter.Task();
task.setFaceSampleId(sample.getId()); task.setFaceSampleId(sample.getId());
task.setMemberId(faceRespVO.getMemberId()); task.setMemberId(faceRespVO.getMemberId());
task.setDeviceId(sample.getDeviceId());
task.setCreateTime(sample.getCreateAt()); task.setCreateTime(sample.getCreateAt());
return task; return task;
}).filter(Objects::nonNull).collect(Collectors.toList()); }).filter(Objects::nonNull).collect(Collectors.toList());

View File

@ -25,4 +25,6 @@ public interface TaskFaceService {
void assureFaceDB(String scenicId); void assureFaceDB(String scenicId);
String uploadFile(MultipartFile file, Long userId); String uploadFile(MultipartFile file, Long userId);
boolean deleteFaceSample(String dbName, String entityId);
} }

View File

@ -52,11 +52,11 @@ public class VideoPieceGetter {
@Data @Data
public static class Task { public static class Task {
public String type = "normal"; public String type = "normal";
public Long deviceId;
public Long faceSampleId; public Long faceSampleId;
public Date createTime; public Date createTime;
public Callback callback; public Callback callback;
public Long memberId; public Long memberId;
public Long faceId;
public static interface Callback { public static interface Callback {
void onInvoke(); void onInvoke();
@ -88,8 +88,27 @@ public class VideoPieceGetter {
return; return;
} }
FaceSampleRespVO faceSample = faceSampleMapper.getById(task.getFaceSampleId()); FaceSampleRespVO faceSample = faceSampleMapper.getById(task.getFaceSampleId());
DeviceEntity device = deviceMapper.getByDeviceId(task.getDeviceId()); DeviceEntity device = deviceMapper.getByDeviceId(faceSample.getDeviceId());
DeviceConfigEntity config = deviceMapper.getConfigByDeviceId(task.getDeviceId()); DeviceConfigEntity config = deviceMapper.getConfigByDeviceId(faceSample.getDeviceId());
SourceEntity source = sourceMapper.querySameVideo(faceSample.getId(), device.getId());
if (source != null) {
// 有原视频
int count = sourceMapper.hasRelationTo(task.getMemberId(), source.getId(), 1);
if (count > 0) {
return;
}
MemberSourceEntity videoSource = new MemberSourceEntity();
videoSource.setId(SnowFlakeUtil.getLongId());
videoSource.setScenicId(faceSample.getScenicId());
videoSource.setFaceId(task.getFaceId());
videoSource.setMemberId(task.getMemberId());
videoSource.setType(1);
videoSource.setIsBuy(0);
videoSource.setSourceId(source.getId());
sourceMapper.addRelation(videoSource);
return;
}
BigDecimal cutPre = BigDecimal.valueOf(5L); BigDecimal cutPre = BigDecimal.valueOf(5L);
BigDecimal cutPost = BigDecimal.valueOf(4L); BigDecimal cutPost = BigDecimal.valueOf(4L);
if (config == null) { if (config == null) {
@ -115,7 +134,7 @@ public class VideoPieceGetter {
log.warn("没有可用的文件"); log.warn("没有可用的文件");
return; return;
} }
long offset = task.getCreateTime().getTime() - listByDtRange.get(0).getCreateTime().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue(); long offset = task.getCreateTime().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue() - listByDtRange.get(0).getCreateTime().getTime();
FfmpegTask ffmpegTask = new FfmpegTask(); FfmpegTask ffmpegTask = new FfmpegTask();
ffmpegTask.setFileList(listByDtRange); ffmpegTask.setFileList(listByDtRange);
ffmpegTask.setDuration(duration); ffmpegTask.setDuration(duration);
@ -144,7 +163,6 @@ public class VideoPieceGetter {
} }
sourceEntity.setVideoUrl(url); sourceEntity.setVideoUrl(url);
sourceEntity.setFaceSampleId(faceSample.getId()); sourceEntity.setFaceSampleId(faceSample.getId());
sourceEntity.setMemberId(task.getMemberId());
sourceEntity.setScenicId(faceSample.getScenicId()); sourceEntity.setScenicId(faceSample.getScenicId());
sourceEntity.setDeviceId(faceSample.getDeviceId()); sourceEntity.setDeviceId(faceSample.getDeviceId());
sourceEntity.setType(1); sourceEntity.setType(1);

View File

@ -6,14 +6,14 @@
values (#{id}, #{scenicId}, #{deviceId}, #{url}, #{videoUrl}, #{type}, #{faceSampleId}, #{posJson}) values (#{id}, #{scenicId}, #{deviceId}, #{url}, #{videoUrl}, #{type}, #{faceSampleId}, #{posJson})
</insert> </insert>
<insert id="addRelation"> <insert id="addRelation">
replace member_source(member_id, source_id, is_buy, type, order_id) replace member_source(scenic_id, face_id, member_id, source_id, is_buy, type, order_id)
values (#{memberId}, #{sourceId}, #{isBuy}, #{type}, #{orderId}) values (#{scenicId}, #{faceId}, #{memberId}, #{sourceId}, #{isBuy}, #{type}, #{orderId})
</insert> </insert>
<insert id="addRelations"> <insert id="addRelations">
replace member_source(member_id, source_id, is_buy, type, order_id) replace member_source(scenic_id, face_id, member_id, source_id, is_buy, type, order_id)
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.memberId}, #{item.sourceId}, #{item.isBuy}, #{item.type}, #{orderId}) (#{item.scenicId}, #{item.faceId}, #{item.memberId}, #{item.sourceId}, #{item.isBuy}, #{item.type}, #{item.orderId})
</foreach> </foreach>
</insert> </insert>
<update id="update"> <update id="update">
@ -54,14 +54,13 @@
and is_buy = #{isBuy} and is_buy = #{isBuy}
</if> </if>
<if test="type!=null">and so.type = #{type} </if> <if test="type!=null">and so.type = #{type} </if>
<if test="faceId!=null">and FIND_IN_SET(so.face_sample_id, (select face.match_sample_ids from face where id = #{faceId})) </if>
<if test="startTime!= null">and so.create_time &gt;= #{startTime} </if> <if test="startTime!= null">and so.create_time &gt;= #{startTime} </if>
<if test="endTime!= null">and so.create_time &lt;= #{endTime} </if> <if test="endTime!= null">and so.create_time &lt;= #{endTime} </if>
</where> </where>
order by so.create_time desc order by so.create_time desc
</select> </select>
<select id="userGetById" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO"> <select id="userGetById" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
select so.id, scenic_id, device_id, ms.member_id, url, so.create_time, so.update_time,sc.`name` as scenicName select so.id, ms.scenic_id, device_id, ms.member_id, url, so.create_time, so.update_time,sc.`name` as scenicName
from member_source ms from member_source ms
left join source so on ms.source_id = so.id left join source so on ms.source_id = so.id
left join scenic sc on sc.id = so.scenic_id left join scenic sc on sc.id = so.scenic_id
@ -74,7 +73,7 @@
where so.id = #{id} where so.id = #{id}
</select> </select>
<select id="listGroupByType" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO"> <select id="listGroupByType" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
select so.id, scenic_id,sc.name scenicName, sc.longitude ,sc.latitude,so.type,so.is_buy select so.id, ms.scenic_id,sc.name scenicName, sc.longitude ,sc.latitude,so.type,so.is_buy
from member_source ms from member_source ms
left join source so on ms.source_id = so.id left join source so on ms.source_id = so.id
left join scenic sc on sc.id = so.scenic_id left join scenic sc on sc.id = so.scenic_id
@ -121,7 +120,7 @@
<if test="scenicId!= null">and ms.scenic_id = #{scenicId} </if> <if test="scenicId!= null">and ms.scenic_id = #{scenicId} </if>
<if test="isBuy!=null">and ms.is_buy = #{isBuy}</if> <if test="isBuy!=null">and ms.is_buy = #{isBuy}</if>
<if test="type!=null">and ms.type = #{type} </if> <if test="type!=null">and ms.type = #{type} </if>
<if test="faceId!=null">and FIND_IN_SET(so.face_sample_id, (select face.match_sample_ids from face where id = #{faceId})) </if> <if test="faceId!=null">and ms.face_id = #{faceId} </if>
order by so.create_time desc order by so.create_time desc
</select> </select>
<select id="queryByRelation" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO"> <select id="queryByRelation" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
@ -135,4 +134,15 @@
<if test="scenicId!= null">and ms.scenic_id = #{scenicId} </if> <if test="scenicId!= null">and ms.scenic_id = #{scenicId} </if>
<if test="isBuy!=null">and ms.is_buy = #{isBuy}</if> <if test="isBuy!=null">and ms.is_buy = #{isBuy}</if>
</select> </select>
<select id="querySameVideo" resultType="com.ycwl.basic.model.pc.source.entity.SourceEntity">
select *
from source
where device_id = #{deviceId} and face_sample_id = #{faceSampleId} and type = 1
limit 1
</select>
<select id="hasRelationTo" resultType="java.lang.Integer">
select count(1)
from member_source
where member_id = #{memberId} and source_id = #{sourceId} and type = #{type}
</select>
</mapper> </mapper>

View File

@ -99,9 +99,7 @@
</select> </select>
<select id="listFor" resultType="com.ycwl.basic.model.mobile.scenic.content.ContentPageVO"> <select id="listFor" resultType="com.ycwl.basic.model.mobile.scenic.content.ContentPageVO">
select t.id templateId, t.scenic_id, s.name as scenic_name, t.`name`, pid, t.cover_url templateCoverUrl, select t.id templateId, t.scenic_id, s.name as scenic_name, t.`name`, pid, t.cover_url templateCoverUrl,
1 as sourceType, 0 as sourceType,
(select IF(count(1) > 0,1,0) from video left join task on video.task_id = task.id where video.template_id=t.id and task.face_id = #{faceId}) contentType,
(select count(1) from video left join task on video.task_id = task.id where video.template_id=t.id and task.face_id = #{faceId} and video.is_buy = 1) isBuy,
t.create_time, t.price t.create_time, t.price
from template t left join scenic s on s.id = t.scenic_id from template t left join scenic s on s.id = t.scenic_id
where t.scenic_id = #{scenicId} and pid = 0 and t.status = 1 where t.scenic_id = #{scenicId} and pid = 0 and t.status = 1

View File

@ -102,4 +102,7 @@
</where> </where>
order by v.create_time desc order by v.create_time desc
</select> </select>
<select id="userFaceTemplateVideo" resultType="com.ycwl.basic.model.pc.video.entity.MemberVideoEntity">
select * from member_video where member_id = #{userId} and face_id = #{faceId} and template_id = #{templateId} order by id desc
</select>
</mapper> </mapper>