32 changed files with 1066 additions and 21 deletions
@ -0,0 +1,57 @@ |
|||||
|
package com.ccsens.yanyuan.api; |
||||
|
|
||||
|
import com.ccsens.cloudutil.annotation.MustLogin; |
||||
|
import com.ccsens.util.JsonResponse; |
||||
|
import com.ccsens.util.bean.dto.QueryDto; |
||||
|
import com.ccsens.yanyuan.bean.dto.TrainBelongDto; |
||||
|
import com.ccsens.yanyuan.bean.vo.TrainBelongVo; |
||||
|
import com.ccsens.yanyuan.service.ITrainBelongService; |
||||
|
import com.ccsens.yanyuan.util.YanYuanCodeError; |
||||
|
import com.github.pagehelper.PageInfo; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/12/6 9:29 |
||||
|
*/ |
||||
|
@Api(tags = "训练归属" ) |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@RequestMapping("/trainBelong") |
||||
|
public class TrainBelongController { |
||||
|
|
||||
|
@Resource |
||||
|
private ITrainBelongService trainBelongService; |
||||
|
|
||||
|
@MustLogin |
||||
|
@ApiOperation(value = "查询无主的训练过程", notes = "查询无主的训练过程") |
||||
|
@RequestMapping(value = "/queryUnknown", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
||||
|
public JsonResponse<TrainBelongVo.Content> queryUnknown(@ApiParam @Validated @RequestBody QueryDto<TrainBelongDto.QueryUnknown> params) { |
||||
|
log.info("查询无主的训练过程:{}",params); |
||||
|
PageInfo<TrainBelongVo.Content> contents = trainBelongService.queryUnknown(params.getParam(), params.getUserId()); |
||||
|
log.info("查询无主的训练过程结束{}", contents); |
||||
|
return JsonResponse.newInstance().ok(contents); |
||||
|
} |
||||
|
|
||||
|
@MustLogin |
||||
|
@ApiOperation(value = "选择老人", notes = "选择老人") |
||||
|
@RequestMapping(value = "/chooseRecord", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
||||
|
public JsonResponse chooseRecord(@ApiParam @Validated @RequestBody QueryDto<TrainBelongDto.ChooseTrainee> params) { |
||||
|
log.info("选择老人:{}",params); |
||||
|
YanYuanCodeError.Code code = trainBelongService.chooseRecord(params.getParam(), params.getUserId()); |
||||
|
log.info("选择老人结束{}"); |
||||
|
return JsonResponse.newInstance().ok(code); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
package com.ccsens.yanyuan.bean.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.Max; |
||||
|
import javax.validation.constraints.Min; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/12/6 9:50 |
||||
|
*/ |
||||
|
public class TrainBelongDto { |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("查询无主训练-请求") |
||||
|
public static class QueryUnknown{ |
||||
|
@ApiModelProperty("页码") |
||||
|
private Integer pageNum = 1; |
||||
|
@ApiModelProperty("分页大小") |
||||
|
private Integer pageSize = 10; |
||||
|
} |
||||
|
@Data |
||||
|
@ApiModel("选择老人-请求") |
||||
|
public static class ChooseTrainee { |
||||
|
@NotNull |
||||
|
@ApiModelProperty("训练结果id") |
||||
|
private Long trainRecordId; |
||||
|
@Min(0) |
||||
|
@Max(1) |
||||
|
@ApiModelProperty("训练结果类型0:训练结果 1:过程记录") |
||||
|
private byte resultType; |
||||
|
@NotNull |
||||
|
@ApiModelProperty("训练计划ID") |
||||
|
private Long recordId; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,138 @@ |
|||||
|
package com.ccsens.yanyuan.bean.dto.message; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author 逗 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TalkingPenDto { |
||||
|
/** |
||||
|
* 点读笔编号 |
||||
|
*/ |
||||
|
private String authId; |
||||
|
/** |
||||
|
* 类型 |
||||
|
*/ |
||||
|
private Byte type; |
||||
|
/** |
||||
|
* 寄存器地址 |
||||
|
*/ |
||||
|
private int addr; |
||||
|
/** |
||||
|
* 类型对应的值, |
||||
|
*/ |
||||
|
private Long value; |
||||
|
/** |
||||
|
* 时间 |
||||
|
*/ |
||||
|
private Long time; |
||||
|
|
||||
|
public Byte getType(){ |
||||
|
if(this.type != null){ |
||||
|
return type; |
||||
|
} |
||||
|
switch (addr){ |
||||
|
case Addr.STATUS: |
||||
|
return Type.STATUS; |
||||
|
case Addr.WIFI: |
||||
|
return Type.WIFI; |
||||
|
case Addr.ELECTRIC: |
||||
|
return Type.ELECTRIC; |
||||
|
case Addr.QUESTION: |
||||
|
return Type.QUESTION; |
||||
|
case Addr.INDEX_1: |
||||
|
case Addr.INDEX_2: |
||||
|
return Type.INDEX; |
||||
|
case Addr.PACKAGE: |
||||
|
return Type.PACKAGE; |
||||
|
case Addr.FRAME: |
||||
|
return Type.FRAME; |
||||
|
default: |
||||
|
return Type.PROCESS; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static class Type { |
||||
|
/** |
||||
|
* 点读笔状态 |
||||
|
*/ |
||||
|
public static final byte STATUS = 0; |
||||
|
/** |
||||
|
* 联网状态 |
||||
|
*/ |
||||
|
public static final byte WIFI = 1; |
||||
|
/** |
||||
|
* 电池电量 |
||||
|
*/ |
||||
|
public static final byte ELECTRIC = 2; |
||||
|
/** |
||||
|
* 题目查询 |
||||
|
*/ |
||||
|
public static final byte QUESTION = 3; |
||||
|
/** |
||||
|
* 序号/结果通知(oid3普通码) |
||||
|
*/ |
||||
|
public static final byte INDEX = 4; |
||||
|
/** |
||||
|
* 包序号 |
||||
|
*/ |
||||
|
public static final byte PACKAGE = 5; |
||||
|
/** |
||||
|
* 帧序号 |
||||
|
*/ |
||||
|
public static final byte FRAME = 6; |
||||
|
/** |
||||
|
* 过程 |
||||
|
*/ |
||||
|
public static final byte PROCESS = 7; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public static class Addr{ |
||||
|
/** |
||||
|
* 点读笔状态 |
||||
|
*/ |
||||
|
public static final int STATUS = 0; |
||||
|
/** |
||||
|
* 联网状态 |
||||
|
*/ |
||||
|
public static final int WIFI = 1; |
||||
|
/** |
||||
|
* 电池电量 |
||||
|
*/ |
||||
|
public static final int ELECTRIC = 2; |
||||
|
/** |
||||
|
* 题目 |
||||
|
*/ |
||||
|
public static final int QUESTION = 3; |
||||
|
/** |
||||
|
* 语音(仅服务端通知点读笔,无点读笔通知服务端) |
||||
|
*/ |
||||
|
public static final int VOICE = 4; |
||||
|
/** |
||||
|
* 序号通知1 |
||||
|
*/ |
||||
|
public static final int INDEX_1 = 5; |
||||
|
/** |
||||
|
* 序号通知2 |
||||
|
*/ |
||||
|
public static final int INDEX_2 = 6; |
||||
|
/** |
||||
|
* 包序号 |
||||
|
*/ |
||||
|
public static final int PACKAGE = 7; |
||||
|
/** |
||||
|
* 帧序号 |
||||
|
*/ |
||||
|
public static final int FRAME = 8; |
||||
|
/** |
||||
|
* 过程起始坐标时间 |
||||
|
*/ |
||||
|
public static final int PROCESS_START = 9; |
||||
|
/** |
||||
|
* 过程一组寄存器数量 |
||||
|
*/ |
||||
|
public static final int PROCESS_NUM = 6; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,69 @@ |
|||||
|
package com.ccsens.yanyuan.bean.vo; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/12/6 9:49 |
||||
|
*/ |
||||
|
public class TrainBelongVo { |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("无主训练内容-返回") |
||||
|
public static class Content{ |
||||
|
@ApiModelProperty("结果id") |
||||
|
private Long trainRecordId; |
||||
|
@ApiModelProperty("训练结果类型0:训练结果 1:过程记录") |
||||
|
private byte resultType; |
||||
|
@ApiModelProperty("操作时间") |
||||
|
private Date createTime; |
||||
|
@ApiModelProperty("点读笔ID") |
||||
|
private Long equipmentId; |
||||
|
@ApiModelProperty("工具箱ID") |
||||
|
private Long toolId; |
||||
|
@ApiModelProperty("工具箱码") |
||||
|
private String toolCode; |
||||
|
// 结果
|
||||
|
@ApiModelProperty("训练结果 0:非常困难 1:略有困难 2:轻松完成") |
||||
|
private BigDecimal finishResult; |
||||
|
@ApiModelProperty("训练完成时间 单位:秒") |
||||
|
private Long finishTime; |
||||
|
// 记录
|
||||
|
@ApiModelProperty("卡片ID") |
||||
|
private Long assistId; |
||||
|
@ApiModelProperty("卡片类型 0:迷宫 1:找不同") |
||||
|
private byte cardType; |
||||
|
@ApiModelProperty("卡片路径") |
||||
|
private String cardUrl; |
||||
|
@ApiModelProperty("过程记录") |
||||
|
private List<Line> lines; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("记录点") |
||||
|
public static class Line{ |
||||
|
@ApiModelProperty("线中有多个点,不同点之间使用;分割,点信息:x,y,time") |
||||
|
private String line; |
||||
|
@ApiModelProperty("操作时间") |
||||
|
private Long operateTime; |
||||
|
} |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("记录和线条") |
||||
|
public static class RecordLine{ |
||||
|
@ApiModelProperty("结果id") |
||||
|
private Long trainRecordId; |
||||
|
@ApiModelProperty("记录") |
||||
|
private List<Line> lines; |
||||
|
} |
||||
|
} |
||||
@ -1,11 +1,27 @@ |
|||||
package com.ccsens.yanyuan.bean.vo; |
package com.ccsens.yanyuan.bean.vo; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
/** |
/** |
||||
* @description: |
* @description: |
||||
* @author: whj |
* @author: whj |
||||
* @time: 2021/11/18 9:01 |
* @time: 2021/11/18 9:01 |
||||
*/ |
*/ |
||||
public class TrainPlanVo { |
public class TrainPlanVo { |
||||
public static class Detail { |
|
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("简单训练计划-返回") |
||||
|
public static class Simple { |
||||
|
@ApiModelProperty("训练计划ID") |
||||
|
private Long recordId; |
||||
|
@ApiModelProperty("训练题目") |
||||
|
private String content; |
||||
|
@ApiModelProperty("训练等级 训练内容是几星级") |
||||
|
private byte level; |
||||
|
@ApiModelProperty("训练计划时间") |
||||
|
private Long startTime; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,221 @@ |
|||||
|
package com.ccsens.yanyuan.mq; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.ccsens.util.bean.message.common.OutMessage; |
||||
|
import com.ccsens.util.bean.message.common.OutMessageSet; |
||||
|
import com.ccsens.yanyuan.bean.dto.message.TalkingPenDto; |
||||
|
import com.ccsens.yanyuan.bean.vo.TraineeVo; |
||||
|
import com.ccsens.yanyuan.persist.mapper.TrainEquipmentMapper; |
||||
|
import com.ccsens.yanyuan.util.YanYuanConstant; |
||||
|
import lombok.Data; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.*; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/12/2 10:38 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@RabbitListener(queues = YanYuanConstant.Mq.TALKING_PEN) |
||||
|
public class TalkingPenReceive { |
||||
|
|
||||
|
@Resource |
||||
|
private TrainEquipmentMapper trainEquipmentMapper; |
||||
|
|
||||
|
@RabbitHandler |
||||
|
public void process(String messageJson){ |
||||
|
log.info("接收到消息系统点读笔相关的消息:{}", messageJson); |
||||
|
OutMessageSet outMessageSet = JSONObject.parseObject(messageJson, OutMessageSet.class); |
||||
|
if (ObjectUtil.isNull(outMessageSet)) { |
||||
|
return; |
||||
|
} |
||||
|
Set<OutMessage> messageSet = outMessageSet.getMessageSet(); |
||||
|
if (CollectionUtil.isEmpty(messageSet)) { |
||||
|
return; |
||||
|
} |
||||
|
// 计算并分类
|
||||
|
Map<Byte, List<TalkingPenDto>> messageMap = dealMessage(messageSet); |
||||
|
|
||||
|
// 根据类型处理数据
|
||||
|
for (Byte type: messageMap.keySet()) { |
||||
|
switch (type) { |
||||
|
case TalkingPenDto.Type.STATUS: |
||||
|
dealStatus(messageMap.get(type).get(0)); |
||||
|
break; |
||||
|
case TalkingPenDto.Type.WIFI: |
||||
|
dealWifi(messageMap.get(type).get(0)); |
||||
|
break; |
||||
|
case TalkingPenDto.Type.ELECTRIC: |
||||
|
dealElectric(messageMap.get(type).get(0)); |
||||
|
break; |
||||
|
case TalkingPenDto.Type.QUESTION: |
||||
|
dealQuestion(messageMap.get(type).get(0)); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
// 处理过程通知
|
||||
|
|
||||
|
|
||||
|
log.info("点读笔消息处理完成"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理查询试题 |
||||
|
* @param talkingPen 试题 |
||||
|
*/ |
||||
|
private void dealQuestion(TalkingPenDto talkingPen) { |
||||
|
// 查找使用者
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理电量状态 |
||||
|
* @param talkingPenDto 电量状态 |
||||
|
*/ |
||||
|
private void dealElectric(TalkingPenDto talkingPenDto) { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理wifi |
||||
|
* @param talkingPen wifi |
||||
|
*/ |
||||
|
private void dealWifi(TalkingPenDto talkingPen) { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理点读笔状态 |
||||
|
* @param talkingPen 状态 |
||||
|
*/ |
||||
|
private void dealStatus(TalkingPenDto talkingPen) { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 计算寄存器的值,并按照类型分类 |
||||
|
* @param messageSet 原始数据 |
||||
|
* @return map key:类型 value:类型数据对应的数组 |
||||
|
*/ |
||||
|
private Map<Byte, List<TalkingPenDto>> dealMessage(Set<OutMessage> messageSet) { |
||||
|
Map<Byte, List<TalkingPenDto>> penMessages = new HashMap<>(16); |
||||
|
Map<Integer, ValueUse> penMap = new HashMap<>(messageSet.size()); |
||||
|
messageSet.forEach(set -> { |
||||
|
TalkingPenDto dto = JSONObject.parseObject(set.getData(), TalkingPenDto.class); |
||||
|
penMap.put(dto.getAddr(), new ValueUse(dto)); |
||||
|
}); |
||||
|
for (Integer addr: penMap.keySet()) { |
||||
|
ValueUse valueUse = penMap.get(addr); |
||||
|
// 数据已经处理
|
||||
|
if (valueUse.used) { |
||||
|
continue; |
||||
|
} |
||||
|
// 根据类型,计算对应的值
|
||||
|
TalkingPenDto talkingPen = valueUse.talkingPen; |
||||
|
Byte type = talkingPen.getType(); |
||||
|
List<TalkingPenDto> pens = penMessages.getOrDefault(type, new ArrayList<>()); |
||||
|
switch (type) { |
||||
|
case TalkingPenDto.Type.STATUS: |
||||
|
case TalkingPenDto.Type.WIFI: |
||||
|
case TalkingPenDto.Type.ELECTRIC: |
||||
|
case TalkingPenDto.Type.QUESTION: |
||||
|
case TalkingPenDto.Type.PACKAGE: |
||||
|
case TalkingPenDto.Type.FRAME: |
||||
|
pens.add(talkingPen); |
||||
|
penMessages.put(type, pens); |
||||
|
break; |
||||
|
case TalkingPenDto.Type.INDEX: |
||||
|
getIndex(penMap, talkingPen); |
||||
|
pens.add(talkingPen); |
||||
|
penMessages.put(type, pens); |
||||
|
break; |
||||
|
case TalkingPenDto.Type.PROCESS: |
||||
|
getProcess(penMap, talkingPen); |
||||
|
pens.add(talkingPen); |
||||
|
penMessages.put(type, pens); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return penMessages; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 计算画图过程的值 |
||||
|
* @param penMap 全部寄存器 |
||||
|
* @param talkingPen 某个过程寄存器 |
||||
|
*/ |
||||
|
private void getProcess(Map<Integer, ValueUse> penMap, TalkingPenDto talkingPen) { |
||||
|
int addr = talkingPen.getAddr(); |
||||
|
int position = (addr - TalkingPenDto.Addr.PROCESS_START) % TalkingPenDto.Addr.PROCESS_NUM; |
||||
|
TalkingPenDto high; |
||||
|
TalkingPenDto low; |
||||
|
switch (position) { |
||||
|
case 0: |
||||
|
case 2: |
||||
|
case 4: |
||||
|
high = talkingPen; |
||||
|
low = penMap.get(addr + 1).talkingPen; |
||||
|
break; |
||||
|
default: |
||||
|
high = penMap.get(addr + 1).talkingPen; |
||||
|
low = talkingPen; |
||||
|
break; |
||||
|
} |
||||
|
// 计算序号或结果值
|
||||
|
long value = high.getValue() << YanYuanConstant.Equipment.REGISTER_BIT | low.getValue(); |
||||
|
talkingPen.setValue(value); |
||||
|
penMap.get(high.getAddr()).used = true; |
||||
|
penMap.get(low.getAddr()).used = true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 计算序号的值 |
||||
|
* @param penMap 所有的寄存器 |
||||
|
* @param index 当前寄存器 |
||||
|
*/ |
||||
|
private void getIndex(Map<Integer, ValueUse> penMap, TalkingPenDto index) { |
||||
|
int addr = index.getAddr(); |
||||
|
// 获取序号高位和低位的值
|
||||
|
TalkingPenDto high; |
||||
|
TalkingPenDto low; |
||||
|
if (addr == TalkingPenDto.Addr.INDEX_1) { |
||||
|
high = index; |
||||
|
low = penMap.get(TalkingPenDto.Addr.INDEX_2).talkingPen; |
||||
|
} else { |
||||
|
high = penMap.get(TalkingPenDto.Addr.INDEX_1).talkingPen; |
||||
|
low = index; |
||||
|
} |
||||
|
// 计算序号或结果值
|
||||
|
long value = high.getValue() << YanYuanConstant.Equipment.REGISTER_BIT | low.getValue(); |
||||
|
index.setValue(value); |
||||
|
penMap.get(high.getAddr()).used = true; |
||||
|
penMap.get(low.getAddr()).used = true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static class ValueUse{ |
||||
|
TalkingPenDto talkingPen; |
||||
|
boolean used = false; |
||||
|
|
||||
|
public ValueUse(){} |
||||
|
public ValueUse(TalkingPenDto talkingPen){ |
||||
|
this(); |
||||
|
this.talkingPen = talkingPen; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.ccsens.yanyuan.persist.dao; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.vo.TrainBelongVo; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author whj |
||||
|
*/ |
||||
|
public interface TrainProcessCardDao { |
||||
|
/** |
||||
|
* 查询线条 |
||||
|
* @param recordIds 点读笔卡片ID |
||||
|
* @return |
||||
|
*/ |
||||
|
List<TrainBelongVo.RecordLine> queryLines(@Param("recordIds") List<Long> recordIds); |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import com.ccsens.util.CodeError; |
||||
|
import com.ccsens.yanyuan.bean.dto.TrainBelongDto; |
||||
|
import com.ccsens.yanyuan.bean.vo.TrainBelongVo; |
||||
|
import com.github.pagehelper.PageInfo; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @author whj |
||||
|
*/ |
||||
|
public interface ITrainBelongService { |
||||
|
/** |
||||
|
* 查询没有归属的记录 |
||||
|
* @param param 分页 |
||||
|
* @param userId 用户ID |
||||
|
* @return 归属 |
||||
|
*/ |
||||
|
PageInfo<TrainBelongVo.Content> queryUnknown(TrainBelongDto.QueryUnknown param, Long userId); |
||||
|
|
||||
|
/** |
||||
|
* 选择训练计划 |
||||
|
* @param param 训练结果和训练计划 |
||||
|
* @param userId 操作者ID |
||||
|
* @return 选择结果 |
||||
|
*/ |
||||
|
CodeError.Code chooseRecord(TrainBelongDto.ChooseTrainee param, Long userId); |
||||
|
} |
||||
@ -0,0 +1,103 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import com.ccsens.util.CodeError; |
||||
|
import com.ccsens.yanyuan.bean.dto.TrainBelongDto; |
||||
|
import com.ccsens.yanyuan.bean.po.TrainCard; |
||||
|
import com.ccsens.yanyuan.bean.po.TrainProcessCard; |
||||
|
import com.ccsens.yanyuan.bean.po.TrainRecord; |
||||
|
import com.ccsens.yanyuan.bean.po.TrainResult; |
||||
|
import com.ccsens.yanyuan.bean.vo.TrainBelongVo; |
||||
|
import com.ccsens.yanyuan.persist.dao.TrainCardDao; |
||||
|
import com.ccsens.yanyuan.persist.dao.TrainProcessCardDao; |
||||
|
import com.ccsens.yanyuan.persist.dao.TrainRecordDao; |
||||
|
import com.ccsens.yanyuan.persist.dao.TrainResultDao; |
||||
|
import com.ccsens.yanyuan.util.YanYuanCodeError; |
||||
|
import com.ccsens.yanyuan.util.YanYuanConstant; |
||||
|
import com.github.pagehelper.Page; |
||||
|
import com.github.pagehelper.PageHelper; |
||||
|
import com.github.pagehelper.PageInfo; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Propagation; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/12/6 9:47 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
||||
|
public class TrainBelongService implements ITrainBelongService { |
||||
|
|
||||
|
@Resource |
||||
|
private TrainCardDao trainCardDao; |
||||
|
@Resource |
||||
|
private TrainProcessCardDao trainProcessCardDao; |
||||
|
@Resource |
||||
|
private TrainRecordDao trainRecordDao; |
||||
|
@Resource |
||||
|
private TrainResultDao trainResultDao; |
||||
|
|
||||
|
@Override |
||||
|
public PageInfo<TrainBelongVo.Content> queryUnknown(TrainBelongDto.QueryUnknown param, Long userId) { |
||||
|
PageHelper.startPage(param.getPageNum(), param.getPageSize()); |
||||
|
List<TrainBelongVo.Content> list = trainCardDao.queryUnknown(userId); |
||||
|
if (CollectionUtil.isEmpty(list)) { |
||||
|
return new PageInfo<>(list); |
||||
|
} |
||||
|
// 查询迷宫和找不同对应的过程记录
|
||||
|
List<Long> lineIds = new ArrayList<>(); |
||||
|
Map<Long, TrainBelongVo.Content> lineMap = new HashMap<>(); |
||||
|
list.forEach(content -> { |
||||
|
// 训练结果,不处理
|
||||
|
if (content.getResultType() == YanYuanConstant.Train.RECORD_RESULT) { |
||||
|
return; |
||||
|
} |
||||
|
lineIds.add(content.getTrainRecordId()); |
||||
|
lineMap.put(content.getTrainRecordId(), content); |
||||
|
}); |
||||
|
if (CollectionUtil.isEmpty(lineIds)) { |
||||
|
return new PageInfo<>(list); |
||||
|
} |
||||
|
log.info("查询过程点"); |
||||
|
List<TrainBelongVo.RecordLine> lines = trainProcessCardDao.queryLines(lineIds); |
||||
|
if (CollectionUtil.isNotEmpty(lines)) { |
||||
|
lines.forEach(line -> lineMap.get(line.getTrainRecordId()).setLines(line.getLines())); |
||||
|
} |
||||
|
return new PageInfo<>(list); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CodeError.Code chooseRecord(TrainBelongDto.ChooseTrainee param, Long userId) { |
||||
|
// 校验训练计划存在
|
||||
|
TrainRecord record = trainRecordDao.selectByPrimaryKey(param.getRecordId()); |
||||
|
if (record == null) { |
||||
|
return YanYuanCodeError.PARAM_ERROR; |
||||
|
} |
||||
|
if (param.getResultType() == YanYuanConstant.Train.RECORD_RESULT) { |
||||
|
// 训练结果
|
||||
|
TrainResult result = new TrainResult(); |
||||
|
result.setId(param.getTrainRecordId()); |
||||
|
result.setRecordId(param.getRecordId()); |
||||
|
result.setOperator(userId); |
||||
|
trainResultDao.updateByPrimaryKeySelective(result); |
||||
|
} else { |
||||
|
// 训练计划
|
||||
|
TrainCard card = new TrainCard(); |
||||
|
card.setId(param.getTrainRecordId()); |
||||
|
card.setRecordId(param.getRecordId()); |
||||
|
card.setOperator(userId); |
||||
|
trainCardDao.updateByPrimaryKeySelective(card); |
||||
|
} |
||||
|
return YanYuanCodeError.SUCCESS; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.ccsens.yanyuan.persist.dao.TrainProcessCardDao"> |
||||
|
<resultMap id="recordLineMap" type="com.ccsens.yanyuan.bean.vo.TrainBelongVo$RecordLine"> |
||||
|
<id column="card_id" property="trainRecordId"/> |
||||
|
<collection property="lines" ofType="com.ccsens.yanyuan.bean.vo.TrainBelongVo$Line"> |
||||
|
<id column="id"/> |
||||
|
<result property="line" column="points"/> |
||||
|
<result property="operateTime" column="operate_time"/> |
||||
|
</collection> |
||||
|
</resultMap> |
||||
|
|
||||
|
<select id="queryLines" resultMap="recordLineMap"> |
||||
|
SELECT |
||||
|
card_id, |
||||
|
operate_time, |
||||
|
points |
||||
|
FROM |
||||
|
u_train_process_card |
||||
|
WHERE |
||||
|
card_id IN |
||||
|
<foreach collection="recordIds" item="cardId" separator="," open="(" close=")"> |
||||
|
#{cardId} |
||||
|
</foreach> |
||||
|
and rec_status = 0 |
||||
|
ORDER BY |
||||
|
card_id, |
||||
|
operate_time |
||||
|
</select> |
||||
|
</mapper> |
||||
Loading…
Reference in new issue