diff --git a/ruoyi-modules/rouyi-scale/pom.xml b/ruoyi-modules/rouyi-scale/pom.xml index 0762e32..b7f18ea 100644 --- a/ruoyi-modules/rouyi-scale/pom.xml +++ b/ruoyi-modules/rouyi-scale/pom.xml @@ -85,6 +85,10 @@ ruoyi-common-websocket + + com.deepoove + poi-tl + diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/EvaluationRecordController.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/EvaluationRecordController.java index 9ad7585..fb84eb8 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/EvaluationRecordController.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/EvaluationRecordController.java @@ -1,23 +1,28 @@ package org.dromara.scale.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.util.PoitlIOUtils; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.R; -import org.dromara.common.excel.utils.ExcelUtil; +import org.dromara.common.core.utils.file.FileUtils; import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessType; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.web.core.BaseController; +import org.dromara.scale.domain.bo.BaseQueryBo; import org.dromara.scale.domain.bo.SysEvaluationRecordBo; import org.dromara.scale.domain.vo.SysEvaluationRecordVo; import org.dromara.scale.service.ISysEvaluationRecordService; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.List; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; /** * 量测记录 @@ -48,9 +53,17 @@ public class EvaluationRecordController extends BaseController { @SaCheckPermission("evaluation:record:export") @Log(title = "量测记录", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(SysEvaluationRecordBo bo, HttpServletResponse response) { - List list = sysEvaluationRecordService.queryList(bo); - ExcelUtil.exportExcel(list, "量测记录", SysEvaluationRecordVo.class, response); + public void export(BaseQueryBo bo, HttpServletResponse response) throws IOException { + XWPFTemplate template = sysEvaluationRecordService.getWordTemplate(bo); + //ExcelUtil.exportExcel(list, "量测记录", SysEvaluationRecordVo.class, response); + FileUtils.setAttachmentResponseHeader(response, bo.getNickName() + "的报告" + "-" + bo.getScaleName()); + response.setContentType("application/octet-stream"); + OutputStream out = response.getOutputStream(); + BufferedOutputStream bos = new BufferedOutputStream(out); + template.write(bos); + bos.flush(); + out.flush(); + PoitlIOUtils.closeQuietlyMulti(template, bos, out); } /** @@ -65,5 +78,4 @@ public class EvaluationRecordController extends BaseController { } - } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/EvaluationEecordWordData.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/EvaluationEecordWordData.java new file mode 100644 index 0000000..8ac4347 --- /dev/null +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/EvaluationEecordWordData.java @@ -0,0 +1,24 @@ +package org.dromara.scale.domain; + +import com.deepoove.poi.data.TableRenderData; +import lombok.Data; + +/** + *

TODO

+ * + * @author cjw + * @version V1.0.0 + * @date 2024/4/29 11:09 + */ +@Data +public class EvaluationEecordWordData { + + private String nickName; + private String deptName; + private String sex; + private String scaleName; + private String scaleDetails; + private TableRenderData factor; + private TableRenderData intervene; + +} diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/BaseQueryBo.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/BaseQueryBo.java index 3cedaed..4e02009 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/BaseQueryBo.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/BaseQueryBo.java @@ -15,9 +15,11 @@ public class BaseQueryBo { private Long batchNo; private String sessionName; private Long scaleId; + private String scaleName; private Long deptId; private Long userId; private String nickName; + private Long recordId; private Integer status; private Integer situation; } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/TimeAxisVo.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/TimeAxisVo.java index 73071eb..8ce2aa6 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/TimeAxisVo.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/TimeAxisVo.java @@ -21,4 +21,6 @@ public class TimeAxisVo { private String type; private Integer situation; + + private String note; } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/WordEvaluationAnswerVo.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/WordEvaluationAnswerVo.java new file mode 100644 index 0000000..cdf8a03 --- /dev/null +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/WordEvaluationAnswerVo.java @@ -0,0 +1,21 @@ +package org.dromara.scale.domain.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + *

TODO

+ * + * @author cjw + * @version V1.0.0 + * @date 2024/4/29 13:41 + */ +@Data +public class WordEvaluationAnswerVo { + + private String factorName; + private String questionContent; + private String answerOption; + private BigDecimal score; +} diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/mapper/SysEvaluationRecordMapper.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/mapper/SysEvaluationRecordMapper.java index ba345e4..d920540 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/mapper/SysEvaluationRecordMapper.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/mapper/SysEvaluationRecordMapper.java @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.scale.domain.SysEvaluationRecord; +import org.dromara.scale.domain.vo.WordEvaluationAnswerVo; import org.dromara.scale.domain.vo.SysEvaluationRecordVo; import org.dromara.scale.domain.vo.SysScalePublishVo; @@ -27,4 +28,6 @@ public interface SysEvaluationRecordMapper extends BaseMapperPlus selectRecordVoPage(@Param("page") Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper); + List selectAnswer4Word(Long recordId); + } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/ISysEvaluationRecordService.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/ISysEvaluationRecordService.java index ced23ff..7c6090c 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/ISysEvaluationRecordService.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/ISysEvaluationRecordService.java @@ -1,11 +1,14 @@ package org.dromara.scale.service; +import com.deepoove.poi.XWPFTemplate; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.scale.domain.SysScalePublish; +import org.dromara.scale.domain.bo.BaseQueryBo; import org.dromara.scale.domain.bo.SysEvaluationRecordBo; import org.dromara.scale.domain.vo.SysEvaluationRecordVo; +import java.io.IOException; import java.util.List; /** @@ -34,6 +37,8 @@ public interface ISysEvaluationRecordService { void insertBathByPublish(SysScalePublish add); + XWPFTemplate getWordTemplate(BaseQueryBo bo) throws IOException; + diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysEvaluationRecordServiceImpl.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysEvaluationRecordServiceImpl.java index 3ae9984..c73a4c9 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysEvaluationRecordServiceImpl.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysEvaluationRecordServiceImpl.java @@ -3,22 +3,39 @@ package org.dromara.scale.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.data.RowRenderData; +import com.deepoove.poi.data.Rows; +import com.deepoove.poi.data.TableRenderData; +import com.deepoove.poi.data.Tables; +import com.deepoove.poi.data.style.BorderStyle; import lombok.RequiredArgsConstructor; +import org.apache.poi.xwpf.usermodel.XWPFTable; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.scale.constant.StatusEnum; +import org.dromara.scale.domain.EvaluationEecordWordData; import org.dromara.scale.domain.SysEvaluationRecord; import org.dromara.scale.domain.SysScalePublish; +import org.dromara.scale.domain.bo.BaseQueryBo; import org.dromara.scale.domain.bo.SysEvaluationRecordBo; import org.dromara.scale.domain.vo.SysEvaluationRecordVo; +import org.dromara.scale.domain.vo.SysScaleVo; +import org.dromara.scale.domain.vo.TimeAxisVo; +import org.dromara.scale.domain.vo.WordEvaluationAnswerVo; import org.dromara.scale.mapper.SysEvaluationRecordMapper; +import org.dromara.scale.mapper.SysInterveneRecordMapper; +import org.dromara.scale.mapper.SysScaleMapper; import org.dromara.scale.service.ISysEvaluationRecordService; import org.dromara.system.domain.SysUser; +import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.mapper.SysUserMapper; +import org.springframework.core.io.ClassPathResource; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -36,6 +53,12 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi private final SysUserMapper userMapper; + private final SysScaleMapper scaleMapper; + + private final SysInterveneRecordMapper interveneMapper; + + private final String resource = "word/personalTemplate.docx"; + /** * 查询量测记录 */ @@ -96,4 +119,45 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi } baseMapper.insertBatch(recordList, 100); } + + @Override + public XWPFTemplate getWordTemplate(BaseQueryBo bo) throws IOException { + Long userId = bo.getUserId(); + Long recordId = bo.getRecordId(); + Long scaleId = bo.getScaleId(); + EvaluationEecordWordData wordData = new EvaluationEecordWordData(); + SysUserVo user = userMapper.selectUserById(userId); + wordData.setNickName(user.getNickName()); + wordData.setDeptName(user.getDept().getDeptName()); + wordData.setSex("1".equals(user.getSex()) ? "男" : "女"); + SysScaleVo scale = scaleMapper.selectVoById(scaleId); + wordData.setScaleName(scale.getScaleName()); + wordData.setScaleDetails(scale.getScaleDetails()); + List answerVos = baseMapper.selectAnswer4Word(recordId); + BorderStyle borderStyle = new BorderStyle(); + borderStyle.setColor("A6A6A6"); + borderStyle.setSize(4); + borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE); + RowRenderData factorHeader = Rows.of("因子项", "题目", "选项", "得分").bgColor("F2F2F2").center() + .textColor("7F7f7F").textFontFamily("Hei").textFontSize(9).create(); + TableRenderData factorTable = Tables.ofA4MediumWidth().addRow(factorHeader).border(borderStyle).center().create(); + for (WordEvaluationAnswerVo answerVo : answerVos) { + RowRenderData one = Rows.of(answerVo.getFactorName(), answerVo.getQuestionContent(), + answerVo.getAnswerOption(), answerVo.getScore().toString()).center().create(); + factorTable.addRow(one); + } + wordData.setFactor(factorTable); + List timeAxisVos = interveneMapper.selectTimeList(userId); + RowRenderData interveneHeader = Rows.of("干预标题", "干预时间", "诊断详情").bgColor("F2F2F2").center() + .textColor("7F7f7F").textFontFamily("Hei").textFontSize(9).create(); + TableRenderData interveneTable = Tables.ofA4MediumWidth().addRow(interveneHeader).border(borderStyle).center().create(); + for (TimeAxisVo timeAxisVo : timeAxisVos) { + RowRenderData one = Rows.of(timeAxisVo.getName(), timeAxisVo.getTime(), + timeAxisVo.getNote()).center().create(); + interveneTable.addRow(one); + } + wordData.setIntervene(interveneTable); + ClassPathResource classPathResource = new ClassPathResource(resource); + return XWPFTemplate.compile(classPathResource.getInputStream()).render(wordData); + } } diff --git a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/ArchiveMapper.xml b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/ArchiveMapper.xml index ce08c69..26f0ad1 100644 --- a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/ArchiveMapper.xml +++ b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/ArchiveMapper.xml @@ -22,7 +22,7 @@ sp.session_name, s.scale_id, s.scale_name, - MAX(sfr.situation), + MAX(sfr.situation) as `situation`, er.create_time from sys_evaluation_record er left join sys_scale s on s.scale_id = er.scale_id diff --git a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysEvaluationRecordMapper.xml b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysEvaluationRecordMapper.xml index 08d98be..5fdd6ff 100644 --- a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysEvaluationRecordMapper.xml +++ b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysEvaluationRecordMapper.xml @@ -23,4 +23,17 @@ left join sys_scale s on s.scale_id = er.scale_id ${ew.getCustomSqlSegment} + + diff --git a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysInterveneRecordMapper.xml b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysInterveneRecordMapper.xml index 066c297..071b1d3 100644 --- a/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysInterveneRecordMapper.xml +++ b/ruoyi-modules/rouyi-scale/src/main/resources/mapper/scale/SysInterveneRecordMapper.xml @@ -4,10 +4,11 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">