Browse Source

画图线条分析导出

sd
zhizhi wu 4 years ago
parent
commit
b1fc9acd0f
  1. 20
      ht/src/main/java/com/ccsens/ht/api/QuestionController.java
  2. 11
      ht/src/main/java/com/ccsens/ht/bean/dto/QuestionDto.java
  3. 8
      ht/src/main/java/com/ccsens/ht/service/IQuestionService.java
  4. 2
      ht/src/main/java/com/ccsens/ht/service/PatientReportService.java
  5. 70
      ht/src/main/java/com/ccsens/ht/service/QuestionService.java
  6. 4
      ht/src/main/resources/application.yml

20
ht/src/main/java/com/ccsens/ht/api/QuestionController.java

@ -1,8 +1,10 @@
package com.ccsens.ht.api;
import cn.hutool.core.util.CharsetUtil;
import com.ccsens.ht.annotation.DoctorAudit;
import com.ccsens.cloudutil.annotation.MustLogin;
import com.ccsens.ht.bean.dto.PatientReportDto;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.ht.bean.dto.QuestionDto;
import com.ccsens.ht.bean.vo.QuestionVo;
@ -11,13 +13,17 @@ import com.ccsens.util.CodeEnum;
import com.ccsens.util.JsonResponse;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
@ -128,4 +134,18 @@ public class QuestionController {
return JsonResponse.newInstance().ok();
}
@ApiOperation(value = "导出图片的题目画图每笔的长度等",notes = "导出图片的题目画图每笔的长度等")
@ApiImplicitParams({
@ApiImplicitParam(name = "json", value = "指定题目", required = true)
})
@RequestMapping(value="/exportLine", method = RequestMethod.GET)
public void exportLine(@ApiParam @Valid QuestionDto.ExportLine answer, HttpServletResponse response) throws IOException {
//查询报告单信息
log.info("导出图片的题目画图每笔的长度等:{}", answer);
Workbook workbook = questionService.exportLine(answer);
log.info("导出图片的题目画图每笔的长度结束");
String fileName = "笔画长度.xlsx";
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, CharsetUtil.UTF_8));
workbook.write(response.getOutputStream());
}
}

11
ht/src/main/java/com/ccsens/ht/bean/dto/QuestionDto.java

@ -145,5 +145,14 @@ public class QuestionDto {
@ApiModelProperty("轨迹的id")
private List<Long> pointId;
}
@Data
@ApiModel("导出线条长度")
public static class ExportLine {
@NotNull(message = "选项ID不能为空")
@ApiModelProperty("报告单id")
private Long patientReportId;
@NotNull(message = "测评试题id不能为空")
@ApiModelProperty("测评试题id")
private Long questionId;
}
}

8
ht/src/main/java/com/ccsens/ht/service/IQuestionService.java

@ -4,6 +4,7 @@ import com.ccsens.ht.bean.dto.QuestionDto;
import com.ccsens.ht.bean.vo.QuestionVo;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.NotSupportedFileTypeException;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.IOException;
import java.util.List;
@ -68,4 +69,11 @@ public interface IQuestionService {
* @param userId 用户ID
*/
void saveRecord(QuestionDto.Record records, Long userId);
/**
* 导出画图每一笔的长度
* @param answer
* @return
*/
Workbook exportLine(QuestionDto.ExportLine answer);
}

2
ht/src/main/java/com/ccsens/ht/service/PatientReportService.java

@ -890,7 +890,7 @@ public class PatientReportService implements IPatientReportService {
initSimple(row, analyse, simpleTwentyId, 101);
}
public String pxToMm(double length, Integer height) {
public static String pxToMm(double length, Integer height) {
return new BigDecimal(144).multiply(new BigDecimal(length)).divide(new BigDecimal(height), 2, BigDecimal.ROUND_HALF_UP).toString();
}
public String pxToSquare(double length, Integer height) {

70
ht/src/main/java/com/ccsens/ht/service/QuestionService.java

@ -18,6 +18,7 @@ import com.ccsens.ht.persist.mapper.HtPatientQuestionRecordMapper;
import com.ccsens.ht.persist.mapper.HtPatientReportMapper;
import com.ccsens.ht.uitl.Constant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.PoiUtil;
import com.ccsens.util.bean.message.common.InMessage;
import com.ccsens.util.bean.message.common.MessageRule;
import com.ccsens.util.config.RabbitMQConfig;
@ -26,6 +27,8 @@ import io.swagger.annotations.ApiModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -614,10 +617,9 @@ public class QuestionService implements IQuestionService {
public List<QuestionVo.PatientCanvas> getCanvas(QuestionDto.QueryPatientCanvas param, Long userId) {
List<QuestionVo.PatientCanvas> canvasList = new ArrayList<>();
log.info("报告单id:{},试题id:{}",param.getPatientReportId(),param.getQuestionId());
HtPatientCanvasExample canvasExample = new HtPatientCanvasExample();
canvasExample.createCriteria().andPatientReportIdEqualTo(param.getPatientReportId()).andQuestionIdEqualTo(param.getQuestionId());
canvasExample.setOrderByClause("create_time DESC");
List<HtPatientCanvas> patientCanvasList = patientCanvasDao.selectByExample(canvasExample);
Long patientReportId = param.getPatientReportId();
Long questionId = param.getQuestionId();
List<HtPatientCanvas> patientCanvasList = getHtPatientCanvas(patientReportId, questionId);
log.info("查询画图记录:{}",patientCanvasList);
if(CollectionUtil.isEmpty(patientCanvasList)){
return canvasList;
@ -666,6 +668,13 @@ public class QuestionService implements IQuestionService {
return canvasList;
}
private List<HtPatientCanvas> getHtPatientCanvas(Long patientReportId, Long questionId) {
HtPatientCanvasExample canvasExample = new HtPatientCanvasExample();
canvasExample.createCriteria().andPatientReportIdEqualTo(patientReportId).andQuestionIdEqualTo(questionId);
canvasExample.setOrderByClause("create_time DESC");
return patientCanvasDao.selectByExample(canvasExample);
}
private List<QuestionVo.Point> getCanvasPoints(HtPatientCanvas htPatientCanvas) {
List<QuestionVo.Point> canvasPoints = patientCanvasDao.getCanvasPoints(htPatientCanvas.getId());
int num = 16;
@ -1187,4 +1196,57 @@ public class QuestionService implements IQuestionService {
log.info("保存新答案");
}
@Override
public Workbook exportLine(QuestionDto.ExportLine answer) {
int total = 4;
List<List<PoiUtil.PoiUtilCell>> rows = new ArrayList<>();
// 标题
List<PoiUtil.PoiUtilCell> title = new ArrayList<>();
title.add(new PoiUtil.PoiUtilCell("序号"));
title.add(new PoiUtil.PoiUtilCell("长度"));
title.add(new PoiUtil.PoiUtilCell("完成时间"));
title.add(new PoiUtil.PoiUtilCell("思考时间"));
rows.add(title);
// 查询画图记录
List<HtPatientCanvas> patientCanvasList = getHtPatientCanvas(answer.getPatientReportId(), answer.getQuestionId());
log.info("查询画图记录:{}",patientCanvasList);
if(CollectionUtil.isEmpty(patientCanvasList)){
Workbook workbook = new XSSFWorkbook();
PoiUtil.exportWB("笔画长度", rows, workbook);
return workbook;
}
AtomicInteger index = new AtomicInteger(1);
patientCanvasList.forEach(canvas -> {
Integer height = canvas.getCanvasHeight();
List<QuestionVo.Point> canvasPoints = patientCanvasDao.getCanvasPoints(canvas.getId());
for (int i = 0; i < canvasPoints.size(); i++) {
// 坐标点
QuestionVo.Point point = canvasPoints.get(i);
String[] points = point.getValue().split(";");
// 组装单元格
List<PoiUtil.PoiUtilCell> content = new ArrayList<>();
// 长度计算
content.add(new PoiUtil.PoiUtilCell(index.get() + ""));
double length = getLengthByCanvas(points);
content.add(new PoiUtil.PoiUtilCell(PatientReportService.pxToMm(length, height) + "mm"));
// 画图时间计算
content.add(new PoiUtil.PoiUtilCell(Long.parseLong(points[points.length - 1].split(",")[2]) - Long.parseLong(points[0].split(",")[2]) + "ms"));
// 间隔时长
long time;
if (i == 0) {
time = canvas.getBeginTime() - canvas.getOpenCanvasTime() + Long.parseLong(points[0].split(",")[2]);
} else {
String[] prevPoints = canvasPoints.get(i - 1).getValue().split(";");
time = Long.parseLong(points[0].split(",")[2]) - Long.parseLong(prevPoints[prevPoints.length - 1].split(",")[2]);
}
content.add(new PoiUtil.PoiUtilCell(time + "ms"));
rows.add(content);
index.incrementAndGet();
}
});
Workbook workbook = new XSSFWorkbook();
PoiUtil.exportWB("笔画长度", rows, workbook);
return workbook;
}
}

4
ht/src/main/resources/application.yml

@ -1,5 +1,5 @@
spring:
profiles:
active: test
include: common, util-test
active: prod
include: common, util-prod

Loading…
Cancel
Save