refactor(task): 重构任务拍摄时间获取逻辑

- 将 getTaskShotDate 方法从 TaskTaskServiceImpl 移至 VideoTaskRepository
- 删除对 TaskService 和 TaskTaskServiceImpl 的依赖注入
- 更新 LyCompatibleController 和 GoodsServiceImpl 中的调用方式
- 简化日期解析逻辑,提高代码可读性
- 移除冗余的 VideoMapper 和 TaskService 接口方法声明
- 统一使用 VideoTaskRepository 处理任务相关数据查询
This commit is contained in:
2025-12-15 17:33:40 +08:00
parent 832f6a2339
commit c0f07ee9f4
5 changed files with 28 additions and 63 deletions

View File

@@ -58,10 +58,6 @@ public class LyCompatibleController {
@Autowired
private VideoRepository videoRepository;
@Autowired
private VideoMapper videoMapper;
@Autowired
private TaskTaskServiceImpl taskTaskServiceImpl;
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private VideoTaskRepository videoTaskRepository;
@@ -217,7 +213,7 @@ public class LyCompatibleController {
map.put("face_id", String.valueOf(videoRespVO.getFaceId()));
}
map.put("template_cover_image", contentPageVO.getTemplateCoverUrl());
Date taskShotDate = taskTaskServiceImpl.getTaskShotDate(videoRespVO.getTaskId());
Date taskShotDate = videoTaskRepository.getTaskShotDate(videoRespVO.getTaskId());
map.put("shoottime", DateUtil.format(taskShotDate, "yyyy-MM-dd HH:mm"));
map.put("openid", openId);
map.put("scenicname", contentPageVO.getScenicName());

View File

@@ -53,29 +53,6 @@ public class VideoTaskRepository {
redisTemplate.delete(String.format(TASK_CACHE_KEY, taskId));
}
public Date getTaskShotDate(Long taskId) {
TaskRespVO taskRespVO = taskMapper.getById(taskId);
if (taskRespVO == null) {
return null;
}
Date shotTime = taskRespVO.getCreateTime();
JacksonUtil.JSONObjectCompat paramJson = JacksonUtil.JSONObjectCompat.parseObject(taskRespVO.getTaskParams());
if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) {
var jsonArray = paramJson.getJSONArray(any.get());
if (jsonArray != null && !jsonArray.isEmpty()) {
JacksonUtil.JSONObjectCompat jsonObject = jsonArray.get(0);
if (jsonObject.getString("createTime") != null) {
shotTime = DateUtil.parse(jsonObject.getString("createTime"));
}
}
}
}
return shotTime;
}
public Integer getTaskDeviceNum(Long taskId) {
TaskEntity task = getTaskById(taskId);
if (task == null) {
@@ -131,6 +108,32 @@ public class VideoTaskRepository {
return deviceCount.get();
}
public Date getTaskShotDate(Long taskId) {
TaskEntity task = getTaskById(taskId);
if (task == null) {
return null;
}
Date shotTime = task.getCreateTime();
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> jsonArray = (List<Map<String, Object>>) paramJson.get(any.get());
if (jsonArray != null && !jsonArray.isEmpty()) {
Map<String, Object> jsonObject = jsonArray.get(0);
if (jsonObject.containsKey("createTime")) {
Object createTimeObj = jsonObject.get("createTime");
if (createTimeObj instanceof Number) {
shotTime = new Date(((Number) createTimeObj).longValue());
}
}
}
}
}
return shotTime;
}
/**
* 检查任务是否可以更新
* @param taskId 任务ID

View File

@@ -46,7 +46,6 @@ import com.ycwl.basic.service.mobile.GoodsService;
import com.ycwl.basic.repository.TemplateRepository;
import com.ycwl.basic.config.VideoUpdateConfig;
import com.ycwl.basic.model.repository.TaskUpdateResult;
import com.ycwl.basic.service.task.TaskService;
import com.ycwl.basic.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter;
import com.ycwl.basic.storage.enums.StorageAcl;
@@ -88,8 +87,6 @@ public class GoodsServiceImpl implements GoodsService {
@Autowired
private VideoTaskRepository videoTaskRepository;
@Autowired
private TaskService taskTaskService;
@Autowired
private ScenicRepository scenicRepository;
@Autowired
private OrderBiz orderBiz;
@@ -244,7 +241,7 @@ public class GoodsServiceImpl implements GoodsService {
goodsDetailVO.setIsBuy(1);
}
}
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(video.getTaskId()));
goodsDetailVO.setShotTime(videoTaskRepository.getTaskShotDate(video.getTaskId()));
goodsDetailVO.setLensNum(videoTaskRepository.getTaskLensNum(video.getTaskId()));
goodsDetailVO.setDevicesNum(videoTaskRepository.getTaskDeviceNum(video.getTaskId()));
CouponRecordQueryResp couponRecord = couponBiz.queryUserCouponRecord(video.getScenicId(), userId, video.getFaceId(), video.getTemplateId().toString());

View File

@@ -7,8 +7,6 @@ import com.ycwl.basic.model.task.req.TaskSuccessReqVo;
import com.ycwl.basic.model.task.req.WorkerAuthReqVo;
import com.ycwl.basic.model.task.resp.TaskSyncRespVo;
import java.util.Date;
public interface TaskService {
TaskSyncRespVo handleSyncTask(TaskReqVo req);
@@ -28,8 +26,6 @@ public interface TaskService {
void autoCreateTaskByFaceId(Long faceId);
Date getTaskShotDate(Long taskId);
void sendVideoGeneratedServiceNotification(Long taskId, Long memberId);
TaskRespVO taskInfo(Long taskId);

View File

@@ -591,33 +591,6 @@ public class TaskTaskServiceImpl implements TaskService {
memberVideo.forEach(item -> sendVideoGeneratedServiceNotification(taskId, item.getMemberId()));
}
@Override
public Date getTaskShotDate(Long taskId) {
TaskRespVO taskRespVO = taskMapper.getById(taskId);
if (taskRespVO == null) {
return null;
}
Date shotTime = taskRespVO.getCreateTime();
Map<String, Object> paramJson = JacksonUtil.parseObject(taskRespVO.getTaskParams(), Map.class);
if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> jsonArray = (List<Map<String, Object>>) paramJson.get(any.get());
if (jsonArray != null && !jsonArray.isEmpty()) {
Map<String, Object> jsonObject = jsonArray.get(0);
if (jsonObject.containsKey("createTime")) {
Object createTimeObj = jsonObject.get("createTime");
if (createTimeObj instanceof Number) {
shotTime = new Date(((Number) createTimeObj).longValue());
}
}
}
}
}
return shotTime;
}
@Override
public void sendVideoGeneratedServiceNotification(Long taskId, Long memberId) {
MemberVideoEntity item = videoMapper.queryRelationByMemberTask(memberId, taskId);