|
|
@ -1,13 +1,16 @@ |
|
|
|
package com.ccsens.yanyuan.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.ccsens.util.CodeError; |
|
|
|
import com.ccsens.yanyuan.bean.dto.TrainPlanDto; |
|
|
|
import com.ccsens.yanyuan.bean.po.TrainResult; |
|
|
|
import com.ccsens.yanyuan.bean.po.*; |
|
|
|
import com.ccsens.yanyuan.bean.vo.TaskVo; |
|
|
|
import com.ccsens.yanyuan.bean.vo.TrainContentVo; |
|
|
|
import com.ccsens.yanyuan.persist.dao.*; |
|
|
|
import com.ccsens.yanyuan.persist.mapper.ToolEquipmentMapper; |
|
|
|
import com.ccsens.yanyuan.persist.mapper.TrainEquipmentMapper; |
|
|
|
import com.ccsens.yanyuan.util.YanYuanCodeError; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -28,6 +31,8 @@ import java.util.List; |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class TrainPlanService implements ITrainPlanService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private TrainRecordDao trainRecordDao; |
|
|
|
@Resource |
|
|
@ -36,6 +41,10 @@ public class TrainPlanService implements ITrainPlanService { |
|
|
|
private TrainCardDao trainCardDao; |
|
|
|
@Resource |
|
|
|
private TrainResultDao trainResultDao; |
|
|
|
@Resource |
|
|
|
private ToolEquipmentMapper toolEquipmentMapper; |
|
|
|
@Resource |
|
|
|
private TrainEquipmentMapper trainEquipmentMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public TaskVo.Train queryDetail(TrainPlanDto.TrainPlanId param, Long userId) { |
|
|
@ -66,8 +75,36 @@ public class TrainPlanService implements ITrainPlanService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public YanYuanCodeError chooseTool(TrainPlanDto.ChooseTool param, Long userId) { |
|
|
|
return null; |
|
|
|
public YanYuanCodeError.Code chooseTool(TrainPlanDto.ChooseTool param, Long userId) { |
|
|
|
// 判断recordId存在
|
|
|
|
TrainRecord record = trainRecordDao.selectByPrimaryKey(param.getRecordId()); |
|
|
|
if (record == null) { |
|
|
|
log.info("训练计划:{}未找到", param.getRecordId()); |
|
|
|
return YanYuanCodeError.PARAM_ERROR; |
|
|
|
} |
|
|
|
// 判断设备存在
|
|
|
|
ToolEquipment toolEquipment = toolEquipmentMapper.selectByPrimaryKey(param.getEquipmentId()); |
|
|
|
if (toolEquipment == null) { |
|
|
|
log.info("设备:{}未找到", param.getEquipmentId()); |
|
|
|
return YanYuanCodeError.PARAM_ERROR; |
|
|
|
} |
|
|
|
// 判断该训练计划是否已经存在
|
|
|
|
TrainEquipmentExample trainEquipmentExample = new TrainEquipmentExample(); |
|
|
|
trainEquipmentExample.createCriteria().andRecordIdEqualTo(param.getRecordId()); |
|
|
|
List<TrainEquipment> trainEquipments = trainEquipmentMapper.selectByExample(trainEquipmentExample); |
|
|
|
if (CollectionUtil.isNotEmpty(trainEquipments)) { |
|
|
|
TrainEquipment trainEquipment = new TrainEquipment(); |
|
|
|
trainEquipment.setId(trainEquipments.get(0).getId()); |
|
|
|
trainEquipment.setEquipmentId(param.getEquipmentId()); |
|
|
|
trainEquipmentMapper.updateByPrimaryKeySelective(trainEquipment); |
|
|
|
} else { |
|
|
|
TrainEquipment trainEquipment = new TrainEquipment(); |
|
|
|
trainEquipment.setId(snowflake.nextId()); |
|
|
|
trainEquipment.setRecordId(param.getRecordId()); |
|
|
|
trainEquipment.setEquipmentId(param.getEquipmentId()); |
|
|
|
trainEquipmentMapper.insertSelective(trainEquipment); |
|
|
|
} |
|
|
|
return YanYuanCodeError.SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|