diff --git a/sql/20221114-wei-training2-progress.sql b/sql/20221114-wei-training2-progress.sql new file mode 100644 index 000000000..6858f8bcb --- /dev/null +++ b/sql/20221114-wei-training2-progress.sql @@ -0,0 +1,12 @@ +CREATE TABLE `rts_draft_training2_progress` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `training_id` bigint DEFAULT NULL COMMENT '实训ID', + `description` text COMMENT '描述', + `create_time` datetime DEFAULT NULL, + `map_location_json` text COMMENT '地图定位', + `bg_scene_json` text COMMENT '背景JSON', + `step_json` text COMMENT '步骤列表json', + `scoring_rule_json` text COMMENT '打分规则列表json', + `creator_id` bigint DEFAULT NULL COMMENT '创建人', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='实训草稿存档表'; \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftProgressController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftProgressController.java new file mode 100644 index 000000000..827111cd2 --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftProgressController.java @@ -0,0 +1,56 @@ +package club.joylink.rtss.controller.training2; + + +import club.joylink.rtss.services.training2.Training2DraftProgressService; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.training2.draft.DraftTraining2ProgressVo; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + + +/** + * 实训草稿存档功能 + */ +@Slf4j +@RestController +@RequestMapping("/api/v2/draft/training/{trainingId}/progress") +public class TrainingDraftProgressController { + + @Autowired + private Training2DraftProgressService training2DraftProgressService; + + /** + * 存档 + */ + @PostMapping("{group}/save") + public void saveProgress(@RequestBody DraftTraining2ProgressVo progressVo + ,@PathVariable Long trainingId, @PathVariable String group, @RequestAttribute AccountVO user){ + training2DraftProgressService.saveProgress(progressVo, trainingId, group, user); + } + + /** + * 读档 + */ + @PostMapping("{group}/read/{id}") + public DraftTraining2ProgressVo readProgress(@PathVariable String group, @PathVariable Long trainingId, @PathVariable Long id){ + return training2DraftProgressService.readProgress(id, trainingId, group); + } + + + @GetMapping("/list") + public PageVO queryProgressList(@PathVariable Long trainingId, PageVO pageVO){ + return training2DraftProgressService.queryProgressList(trainingId, pageVO); + } + + @DeleteMapping("/delete/{id}") + public void deleteProgress(@PathVariable Long trainingId,@PathVariable Long id){ + training2DraftProgressService.deleteProgressById(trainingId, id); + } + + @DeleteMapping("/deleteAll") + public void deleteAllProgress(@PathVariable Long trainingId){ + training2DraftProgressService.deleteAllProgress(trainingId); + } +} diff --git a/src/main/java/club/joylink/rtss/dao/DraftTraining2ProgressDao.java b/src/main/java/club/joylink/rtss/dao/DraftTraining2ProgressDao.java new file mode 100644 index 000000000..f697cb770 --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/DraftTraining2ProgressDao.java @@ -0,0 +1,36 @@ +package club.joylink.rtss.dao; + +import club.joylink.rtss.entity.training2.DraftTraining2Progress; +import club.joylink.rtss.entity.training2.DraftTraining2ProgressExample; +import club.joylink.rtss.entity.training2.DraftTraining2ProgressWithBLOBs; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface DraftTraining2ProgressDao { + int deleteByPrimaryKey(Long id); + + int deleteByTrainingId(Long trainingId); + + int insert(DraftTraining2ProgressWithBLOBs record); + + int insertSelective(DraftTraining2ProgressWithBLOBs record); + + List selectByExampleWithBLOBs(DraftTraining2ProgressExample example); + + List selectByExample(DraftTraining2ProgressExample example); + + DraftTraining2ProgressWithBLOBs selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") DraftTraining2ProgressWithBLOBs record, @Param("example") DraftTraining2ProgressExample example); + + int updateByExampleWithBLOBs(@Param("record") DraftTraining2ProgressWithBLOBs record, @Param("example") DraftTraining2ProgressExample example); + + int updateByExample(@Param("record") DraftTraining2Progress record, @Param("example") DraftTraining2ProgressExample example); + + int updateByPrimaryKeySelective(DraftTraining2ProgressWithBLOBs record); + + int updateByPrimaryKeyWithBLOBs(DraftTraining2ProgressWithBLOBs record); + + int updateByPrimaryKey(DraftTraining2Progress record); +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2Progress.java b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2Progress.java new file mode 100644 index 000000000..26668e77c --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2Progress.java @@ -0,0 +1,45 @@ +package club.joylink.rtss.entity.training2; + +import java.util.Date; + +public class DraftTraining2Progress { + private Long id; + + private Long trainingId; + + private Date createTime; + + private Long creatorId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTrainingId() { + return trainingId; + } + + public void setTrainingId(Long trainingId) { + this.trainingId = trainingId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Long getCreatorId() { + return creatorId; + } + + public void setCreatorId(Long creatorId) { + this.creatorId = creatorId; + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressExample.java b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressExample.java new file mode 100644 index 000000000..964fe6027 --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressExample.java @@ -0,0 +1,441 @@ +package club.joylink.rtss.entity.training2; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class DraftTraining2ProgressExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public DraftTraining2ProgressExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andTrainingIdIsNull() { + addCriterion("training_id is null"); + return (Criteria) this; + } + + public Criteria andTrainingIdIsNotNull() { + addCriterion("training_id is not null"); + return (Criteria) this; + } + + public Criteria andTrainingIdEqualTo(Long value) { + addCriterion("training_id =", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdNotEqualTo(Long value) { + addCriterion("training_id <>", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdGreaterThan(Long value) { + addCriterion("training_id >", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdGreaterThanOrEqualTo(Long value) { + addCriterion("training_id >=", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdLessThan(Long value) { + addCriterion("training_id <", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdLessThanOrEqualTo(Long value) { + addCriterion("training_id <=", value, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdIn(List values) { + addCriterion("training_id in", values, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdNotIn(List values) { + addCriterion("training_id not in", values, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdBetween(Long value1, Long value2) { + addCriterion("training_id between", value1, value2, "trainingId"); + return (Criteria) this; + } + + public Criteria andTrainingIdNotBetween(Long value1, Long value2) { + addCriterion("training_id not between", value1, value2, "trainingId"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreatorIdIsNull() { + addCriterion("creator_id is null"); + return (Criteria) this; + } + + public Criteria andCreatorIdIsNotNull() { + addCriterion("creator_id is not null"); + return (Criteria) this; + } + + public Criteria andCreatorIdEqualTo(Long value) { + addCriterion("creator_id =", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotEqualTo(Long value) { + addCriterion("creator_id <>", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThan(Long value) { + addCriterion("creator_id >", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThanOrEqualTo(Long value) { + addCriterion("creator_id >=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThan(Long value) { + addCriterion("creator_id <", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThanOrEqualTo(Long value) { + addCriterion("creator_id <=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdIn(List values) { + addCriterion("creator_id in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotIn(List values) { + addCriterion("creator_id not in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdBetween(Long value1, Long value2) { + addCriterion("creator_id between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotBetween(Long value1, Long value2) { + addCriterion("creator_id not between", value1, value2, "creatorId"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressWithBLOBs.java b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressWithBLOBs.java new file mode 100644 index 000000000..b9676e4fe --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/training2/DraftTraining2ProgressWithBLOBs.java @@ -0,0 +1,53 @@ +package club.joylink.rtss.entity.training2; + +public class DraftTraining2ProgressWithBLOBs extends DraftTraining2Progress { + private String description; + + private String mapLocationJson; + + private String bgSceneJson; + + private String stepJson; + + private String scoringRuleJson; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + public String getMapLocationJson() { + return mapLocationJson; + } + + public void setMapLocationJson(String mapLocationJson) { + this.mapLocationJson = mapLocationJson == null ? null : mapLocationJson.trim(); + } + + public String getBgSceneJson() { + return bgSceneJson; + } + + public void setBgSceneJson(String bgSceneJson) { + this.bgSceneJson = bgSceneJson == null ? null : bgSceneJson.trim(); + } + + public String getStepJson() { + return stepJson; + } + + public void setStepJson(String stepJson) { + this.stepJson = stepJson == null ? null : stepJson.trim(); + } + + public String getScoringRuleJson() { + return scoringRuleJson; + } + + public void setScoringRuleJson(String scoringRuleJson) { + this.scoringRuleJson = scoringRuleJson == null ? null : scoringRuleJson.trim(); + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2DraftProgressService.java b/src/main/java/club/joylink/rtss/services/training2/Training2DraftProgressService.java new file mode 100644 index 000000000..62747b35b --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/training2/Training2DraftProgressService.java @@ -0,0 +1,144 @@ +package club.joylink.rtss.services.training2; + +import club.joylink.rtss.dao.DraftTraining2DAO; +import club.joylink.rtss.dao.DraftTraining2ProgressDao; +import club.joylink.rtss.entity.Training; +import club.joylink.rtss.entity.training2.*; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService; +import club.joylink.rtss.simulation.cbtc.data.storage.StorageSimulation; +import club.joylink.rtss.simulation.cbtc.exception.SimulationException; +import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; +import club.joylink.rtss.simulation.cbtc.member.SimulationMemberPO; +import club.joylink.rtss.util.JsonUtils; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.simulationv1.SimulationMemberVO; +import club.joylink.rtss.vo.client.training.TrainingNewVO; +import club.joylink.rtss.vo.client.training2.ScoringRuleVO; +import club.joylink.rtss.vo.client.training2.Step2VO; +import club.joylink.rtss.vo.training2.draft.*; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.netty.util.internal.StringUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 实训草稿存档功能 + */ +@Service +@Slf4j +public class Training2DraftProgressService { + + @Autowired + private DraftTraining2DAO trainingDao; + + @Autowired + private DraftTraining2ProgressDao training2ProgressDao; + + @Autowired + private GroupSimulationService groupSimulationService; + + @Autowired + private SimulationLifeCycleService simulationLifeCycleService; + + /** + * 存档操作 + */ + public void saveProgress(DraftTraining2ProgressVo progressVo, Long trainingId, String group, AccountVO user) { + DraftTraining2WithBLOBs draftTraining2 = trainingDao.selectByPrimaryKey(progressVo.getTrainingId()); + if (draftTraining2 == null) { + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "实训不存在"); + } + DraftTraining2ProgressExample example = new DraftTraining2ProgressExample(); + example.createCriteria().andTrainingIdEqualTo(progressVo.getTrainingId()); + example.setOrderByClause("create_time desc limit 1"); + List progressesList = training2ProgressDao.selectByExampleWithBLOBs(example); + boolean saveFlag = !CollectionUtils.isEmpty(progressesList); + if (saveFlag) { + long lastTime = progressesList.get(0).getCreateTime().getTime(); + long nowTime = new Date().getTime(); + saveFlag = (lastTime + 5000) > nowTime; // 5s内的重复点击直接返回 + if (saveFlag) { + return; + } + } + DraftTraining2ProgressWithBLOBs progressWithBLOBs = new DraftTraining2ProgressWithBLOBs(); + progressWithBLOBs.setTrainingId(progressVo.getTrainingId()); + progressWithBLOBs.setDescription(progressVo.getDescription()); + progressWithBLOBs.setCreateTime(new Date()); + // 地图定位 + progressWithBLOBs.setMapLocationJson(progressVo.getMapLocationJson()); + // 背景 + Simulation simulation = this.groupSimulationService.getSimulationByGroup(group); + StorageSimulation scenesSaving = new StorageSimulation(simulation, false); + progressWithBLOBs.setBgSceneJson(JsonUtils.writeValueAsString(scenesSaving)); + progressWithBLOBs.setStepJson(JsonUtils.writeValueAsString(draftTraining2.getStepJson())); + progressWithBLOBs.setScoringRuleJson(draftTraining2.getScoringRuleJson()); + progressWithBLOBs.setCreatorId(user.getId()); + training2ProgressDao.insertSelective(progressWithBLOBs); + } + + /** + * 读档操作 + */ + public DraftTraining2ProgressVo readProgress(Long id, Long trainingId, String group) { + DraftTraining2ProgressWithBLOBs progresses = training2ProgressDao.selectByPrimaryKey(id); + if (!trainingId.equals(progresses.getTrainingId())) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非实训存档"); + } + if (!StringUtils.isEmpty(progresses.getBgSceneJson())) { + groupSimulationService.loadScenes(group, progresses.getBgSceneJson()); + } else { + Simulation simulation = groupSimulationService.getSimulationByGroup(group); + // 重置仿真状态 + simulationLifeCycleService.reset(simulation); + } + return DraftTraining2ProgressVo.convert2Vo(progresses); + } + + /** + * 存档列表 + */ + public PageVO queryProgressList(Long trainingId, PageVO pageVO) { + PageHelper.startPage(pageVO.getPageNum(), pageVO.getPageSize()); + DraftTraining2ProgressExample example = new DraftTraining2ProgressExample(); + example.createCriteria().andTrainingIdEqualTo(trainingId); + example.setOrderByClause("create_time desc"); + Page pageInfo = (Page) training2ProgressDao.selectByExampleWithBLOBs(example); + return PageVO.convert(pageInfo, pageInfo.getResult().stream().map(p -> DraftTraining2ProgressVo.convert2Vo(p)).collect(Collectors.toList())); + } + + /** + * 根据ID删除存档 + */ + public void deleteProgressById(Long trainingId, Long id) { + DraftTraining2ProgressExample example = new DraftTraining2ProgressExample(); + example.createCriteria().andTrainingIdEqualTo(trainingId).andIdEqualTo(id); + List list = training2ProgressDao.selectByExampleWithBLOBs(example); + if (CollectionUtils.isEmpty(list)) { + return; + } + training2ProgressDao.deleteByPrimaryKey(id); + } + + /** + * 删除该实训下所有的存档 + */ + public void deleteAllProgress(Long trainingId) { + training2ProgressDao.deleteByTrainingId(trainingId); + } +} diff --git a/src/main/java/club/joylink/rtss/vo/training2/draft/DraftTraining2ProgressVo.java b/src/main/java/club/joylink/rtss/vo/training2/draft/DraftTraining2ProgressVo.java new file mode 100644 index 000000000..a9561e0ff --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/training2/draft/DraftTraining2ProgressVo.java @@ -0,0 +1,45 @@ +package club.joylink.rtss.vo.training2.draft; + +import club.joylink.rtss.entity.training2.DraftTraining2ProgressWithBLOBs; +import club.joylink.rtss.util.JsonUtils; +import club.joylink.rtss.vo.client.training2.Step2VO; +import lombok.Data; +import org.springframework.util.StringUtils; + +import java.util.Date; +import java.util.List; + +/** + * 存档时 + */ +@Data +public class DraftTraining2ProgressVo { + private Long id; + + private Long trainingId; + + private Date createTime; + + private String description; + + private String mapLocationJson; + + private List step2List; + + public static DraftTraining2ProgressVo convert2Vo(DraftTraining2ProgressWithBLOBs progress){ + if (progress == null) { + return null; + } + DraftTraining2ProgressVo vo = new DraftTraining2ProgressVo(); + vo.setId(progress.getId()); + vo.setTrainingId(progress.getTrainingId()); + vo.setMapLocationJson(progress.getMapLocationJson()); + if (StringUtils.isEmpty(progress.getStepJson())) { + vo.setStep2List(JsonUtils.readCollection(progress.getStepJson(),List.class,Step2VO.class)); + } + vo.setDescription(progress.getDescription()); + vo.setCreateTime(progress.getCreateTime()); + return vo; + } + +} \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/DraftTraining2ProgressDAO.xml b/src/main/resources/mybatis/mapper/DraftTraining2ProgressDAO.xml new file mode 100644 index 000000000..52369f5ff --- /dev/null +++ b/src/main/resources/mybatis/mapper/DraftTraining2ProgressDAO.xml @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, training_id, create_time, creator_id + + + description, map_location_json, bg_scene_json, step_json, scoring_rule_json + + + + + + delete from rts_draft_training2_progress + where id = #{id,jdbcType=BIGINT} + + + delete from rts_draft_training2_progress + where training_id = #{trainingId,jdbcType=BIGINT} + + + insert into rts_draft_training2_progress (id, training_id, create_time, + creator_id, description, map_location_json, + bg_scene_json, step_json, scoring_rule_json + ) + values (#{id,jdbcType=BIGINT}, #{trainingId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, + #{creatorId,jdbcType=BIGINT}, #{description,jdbcType=LONGVARCHAR}, #{mapLocationJson,jdbcType=LONGVARCHAR}, + #{bgSceneJson,jdbcType=LONGVARCHAR}, #{stepJson,jdbcType=LONGVARCHAR}, #{scoringRuleJson,jdbcType=LONGVARCHAR} + ) + + + insert into rts_draft_training2_progress + + + id, + + + training_id, + + + create_time, + + + creator_id, + + + description, + + + map_location_json, + + + bg_scene_json, + + + step_json, + + + scoring_rule_json, + + + + + #{id,jdbcType=BIGINT}, + + + #{trainingId,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{creatorId,jdbcType=BIGINT}, + + + #{description,jdbcType=LONGVARCHAR}, + + + #{mapLocationJson,jdbcType=LONGVARCHAR}, + + + #{bgSceneJson,jdbcType=LONGVARCHAR}, + + + #{stepJson,jdbcType=LONGVARCHAR}, + + + #{scoringRuleJson,jdbcType=LONGVARCHAR}, + + + + + update rts_draft_training2_progress + + + id = #{record.id,jdbcType=BIGINT}, + + + training_id = #{record.trainingId,jdbcType=BIGINT}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + creator_id = #{record.creatorId,jdbcType=BIGINT}, + + + description = #{record.description,jdbcType=LONGVARCHAR}, + + + map_location_json = #{record.mapLocationJson,jdbcType=LONGVARCHAR}, + + + bg_scene_json = #{record.bgSceneJson,jdbcType=LONGVARCHAR}, + + + step_json = #{record.stepJson,jdbcType=LONGVARCHAR}, + + + scoring_rule_json = #{record.scoringRuleJson,jdbcType=LONGVARCHAR}, + + + + + + + + update rts_draft_training2_progress + set id = #{record.id,jdbcType=BIGINT}, + training_id = #{record.trainingId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + creator_id = #{record.creatorId,jdbcType=BIGINT}, + description = #{record.description,jdbcType=LONGVARCHAR}, + map_location_json = #{record.mapLocationJson,jdbcType=LONGVARCHAR}, + bg_scene_json = #{record.bgSceneJson,jdbcType=LONGVARCHAR}, + step_json = #{record.stepJson,jdbcType=LONGVARCHAR}, + scoring_rule_json = #{record.scoringRuleJson,jdbcType=LONGVARCHAR} + + + + + + update rts_draft_training2_progress + set id = #{record.id,jdbcType=BIGINT}, + training_id = #{record.trainingId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + creator_id = #{record.creatorId,jdbcType=BIGINT} + + + + + + update rts_draft_training2_progress + + + training_id = #{trainingId,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + creator_id = #{creatorId,jdbcType=BIGINT}, + + + description = #{description,jdbcType=LONGVARCHAR}, + + + map_location_json = #{mapLocationJson,jdbcType=LONGVARCHAR}, + + + bg_scene_json = #{bgSceneJson,jdbcType=LONGVARCHAR}, + + + step_json = #{stepJson,jdbcType=LONGVARCHAR}, + + + scoring_rule_json = #{scoringRuleJson,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update rts_draft_training2_progress + set training_id = #{trainingId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + creator_id = #{creatorId,jdbcType=BIGINT}, + description = #{description,jdbcType=LONGVARCHAR}, + map_location_json = #{mapLocationJson,jdbcType=LONGVARCHAR}, + bg_scene_json = #{bgSceneJson,jdbcType=LONGVARCHAR}, + step_json = #{stepJson,jdbcType=LONGVARCHAR}, + scoring_rule_json = #{scoringRuleJson,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=BIGINT} + + + update rts_draft_training2_progress + set training_id = #{trainingId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + creator_id = #{creatorId,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file