|
@@ -0,0 +1,551 @@
|
|
|
+package com.qunzhixinxi.hnqz.report.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDictItem;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmDaDrugEnt;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReport;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.enums.ReportEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmScorePackage;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmTask;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmTaskType;
|
|
|
+import com.qunzhixinxi.hnqz.report.mapper.SysDictItemMapper;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.ExcelReportExportService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.NewReportService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.SysDeptService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.SysFileService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.SysUserService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmDaDrugEntService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmReportService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmScorePackageService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmScorePackageStatusService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmTaskService;
|
|
|
+import com.qunzhixinxi.hnqz.report.service.WmTaskTypeService;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: lixuesong
|
|
|
+ * @createTime: 2022/11/28 13:18
|
|
|
+ * @description: 创建excel表格数据
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class ExcelReportExportServiceImpl implements ExcelReportExportService {
|
|
|
+
|
|
|
+ private final WmScorePackageService wmScorePackageService;
|
|
|
+
|
|
|
+ private final WmScorePackageStatusService wmScorePackageStatusService;
|
|
|
+
|
|
|
+ private final WmTaskService wmTaskService;
|
|
|
+
|
|
|
+ private final WmReportService wmReportService;
|
|
|
+
|
|
|
+ private final WmTaskTypeService wmTaskTypeService;
|
|
|
+
|
|
|
+ private final WmDaDrugEntService wmDaDrugEntService;
|
|
|
+
|
|
|
+ private final SysDeptService sysDeptService;
|
|
|
+
|
|
|
+ private final SysUserService sysUserService;
|
|
|
+
|
|
|
+ private final SysDictItemMapper sysDictItemMapper;
|
|
|
+
|
|
|
+ private final SysFileService sysFileService;
|
|
|
+
|
|
|
+ @Resource(name = "newCommonExcelReportServiceImpl")
|
|
|
+ private final NewReportService newReportService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人承接任务-按积分值,个人承接任务-按任务量,个人承接任务-通用,个人报告管理-个人报告导出的导出
|
|
|
+ *
|
|
|
+ * @param wmTask
|
|
|
+ * @param username
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R newExportZb(WmTask wmTask, String username) throws IOException {
|
|
|
+ String packageId = wmTask.getScorePackageDrugId();
|
|
|
+ if (null == packageId) {
|
|
|
+ return R.failed("积分包ID不能为空");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<WmTask> queryWrapper = new LambdaQueryWrapper();
|
|
|
+ queryWrapper.in(WmTask::getScorePackageId, Arrays.asList(packageId.split(",")));
|
|
|
+ queryWrapper.eq(WmTask::getTaskStatus, "3");
|
|
|
+ queryWrapper.eq(WmTask::getDelFlag, "0");
|
|
|
+ queryWrapper.eq(WmTask::getEnableFlag, "0");
|
|
|
+ queryWrapper.eq(WmTask::getRealFlag, "0");
|
|
|
+ List<WmTask> taskList = wmTaskService.list(queryWrapper);
|
|
|
+ if (taskList.isEmpty()) {
|
|
|
+ return R.failed("未查询到审核通过的任务");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.export(packageId, taskList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业承接任务的导出、任务中心单的导出
|
|
|
+ *
|
|
|
+ * @param wmScorePackage
|
|
|
+ * @param deptId
|
|
|
+ * @param username
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R newExportNba(WmScorePackage wmScorePackage, Integer deptId, String username) throws IOException {
|
|
|
+ wmScorePackage = wmScorePackageService.getById(wmScorePackage.getId());
|
|
|
+
|
|
|
+ HashSet<String> idSet = new HashSet<>();
|
|
|
+ idSet.add(wmScorePackage.getId());
|
|
|
+ int size = idSet.size();
|
|
|
+ do {
|
|
|
+ Set<String> collect = wmScorePackageService.list(Wrappers.<WmScorePackage>lambdaQuery().in(WmScorePackage::getRelationScoreId, idSet))
|
|
|
+ .stream()
|
|
|
+ .map(WmScorePackage::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ idSet.addAll(collect);
|
|
|
+ size += collect.size();
|
|
|
+ } while (size != idSet.size());
|
|
|
+
|
|
|
+ List<WmTask> taskList = wmTaskService.list(Wrappers.<WmTask>lambdaQuery().in(WmTask::getScorePackageId, idSet)
|
|
|
+ .eq(WmTask::getTaskStatus, 3)
|
|
|
+ .and(item -> item.in(WmTask::getReportDrugApprovalStatus, Arrays.asList(5, 6)).eq(WmTask::getReportDrugApprovalOpinion, 1)
|
|
|
+ .or(item2 -> item2.in(WmTask::getReportOneApprovalStatus, Arrays.asList(5, 6)).eq(WmTask::getReportOneApprovalOpinion, 1))));
|
|
|
+
|
|
|
+ //更新任务表审批意见
|
|
|
+ WmTask wmTask = new WmTask();
|
|
|
+ wmTask.setDelFlag("0");
|
|
|
+ wmTask.setEnableFlag("0");
|
|
|
+
|
|
|
+ if (null == taskList || taskList.size() <= 0) {
|
|
|
+ return R.failed("ERROR_未查询到该报告关联的审批通过的任务");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.export(wmScorePackage.getId(), taskList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业承接任务的导出、任务中心单的导出History
|
|
|
+ *
|
|
|
+ * @param wmScorePackage
|
|
|
+ * @param deptId
|
|
|
+ * @param username
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R newExportNbaHistory(WmScorePackage wmScorePackage, Integer deptId, String username) throws IOException {
|
|
|
+ wmScorePackage = wmScorePackageService.getById(wmScorePackage.getId());
|
|
|
+ if (wmScorePackage == null) {
|
|
|
+ return R.failed("未查询到积分包信息");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<WmTask> queryWrapper = new LambdaQueryWrapper();
|
|
|
+ queryWrapper.eq(WmTask::getScorePackageDrugId, wmScorePackage.getId());
|
|
|
+ queryWrapper.eq(WmTask::getTaskStatus, "3");
|
|
|
+ queryWrapper.eq(WmTask::getDelFlag, "0");
|
|
|
+ queryWrapper.eq(WmTask::getEnableFlag, "0");
|
|
|
+ queryWrapper.eq(WmTask::getRealFlag, "0");
|
|
|
+ List<WmTask> taskList = wmTaskService.list(queryWrapper);
|
|
|
+ //List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
|
|
|
+ //更新任务表审批意见
|
|
|
+ WmTask wmTask = new WmTask();
|
|
|
+ wmTask.setDelFlag("0");
|
|
|
+ wmTask.setEnableFlag("0");
|
|
|
+
|
|
|
+ if (null == taskList || taskList.size() <= 0) {
|
|
|
+ return R.failed("ERROR_未查询到该报告关联的审批通过的任务");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.export(wmScorePackage.getId(), taskList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算报告管理,结算报告审批的导出
|
|
|
+ *
|
|
|
+ * @param wmReport
|
|
|
+ * @param deptId
|
|
|
+ * @param username
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R newExportNb(WmReport wmReport, Integer deptId, String username) throws IOException {
|
|
|
+ wmReport = wmReportService.getById(wmReport.getId());
|
|
|
+ List<WmTask> taskList = new ArrayList<>();//该报告关联的所有未提交的任务
|
|
|
+ //更新任务表审批意见
|
|
|
+ WmScorePackage scorePackage = wmScorePackageService.getById(wmReport.getScoreId());
|
|
|
+ WmTask wmTask = new WmTask();
|
|
|
+ wmTask.setDelFlag("0");
|
|
|
+ wmTask.setEnableFlag("0");
|
|
|
+ wmTask.setRealFlag("0");
|
|
|
+
|
|
|
+ SysDept sysDept = sysDeptService.getById(scorePackage.getSendPackageDeptId());
|
|
|
+
|
|
|
+
|
|
|
+ if ("0".equals(scorePackage.getTypeid())) {//药企
|
|
|
+ wmTask.setReportDrugId(wmReport.getId());
|
|
|
+ wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
|
|
|
+ taskList = wmTaskService.list(Wrappers.query(wmTask));
|
|
|
+ } else if ("1".equals(scorePackage.getTypeid())) {//一级代理商类型
|
|
|
+ wmTask.setReportOneId(wmReport.getId());
|
|
|
+ if (sysDept.getLevel() == 2) {
|
|
|
+ wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
|
|
|
+ } else {
|
|
|
+ wmTask.setReportOneApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
|
|
|
+ }
|
|
|
+
|
|
|
+ taskList = wmTaskService.list(Wrappers.query(wmTask));
|
|
|
+ } else if ("2".equals(scorePackage.getTypeid())) {//二级代理商类型
|
|
|
+ wmTask.setReportSecondId(wmReport.getId());
|
|
|
+ wmTask.setReportSecondApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
|
|
|
+ taskList = wmTaskService.list(Wrappers.query(wmTask));
|
|
|
+ }
|
|
|
+ if (null == taskList || taskList.size() <= 0) {
|
|
|
+ return R.failed("ERROR_未查询到该报告关联的审批通过的任务");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.export(wmReport.getScoreId().toString(), taskList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出
|
|
|
+ *
|
|
|
+ * @param packageId 积分包id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private R<?> export(String packageId, List<WmTask> taskList) {
|
|
|
+ try {
|
|
|
+// // 创建excel模板数据
|
|
|
+// Map<String, Object> excelData = this.createExcelData(packageId, taskList);
|
|
|
+// // 基础路径
|
|
|
+// String workPath = (String) OsEnvUtils.getEachEnvPaths().get("EXCEL_FILE_PATH");
|
|
|
+// // 模板路径
|
|
|
+// String templateFile = workPath + "task_summary_template.xlsx";
|
|
|
+// // 目标路径
|
|
|
+// String targetFile = workPath +
|
|
|
+// String.format("out/任务汇总报告(%s)-%s.xlsx", packageId, DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN));
|
|
|
+// ;
|
|
|
+//
|
|
|
+// // 填充模板
|
|
|
+// this.createExcel(templateFile, targetFile, excelData);
|
|
|
+//
|
|
|
+// // 上传oss
|
|
|
+// FileInputStream input = new FileInputStream(targetFile);
|
|
|
+// MultipartFile multipartFile = new MockMultipartFile(String.format("任务汇总报告(%s)", packageId),
|
|
|
+// String.format("任务汇总报告(%s).xlsx", packageId),
|
|
|
+// "text/plain", IOUtils.toByteArray(input));
|
|
|
+// return sysFileService.uploadFileAllUrlRealName(multipartFile, null);
|
|
|
+ Map<String, String> nbaExportResult = newReportService.export(StrUtil.split(packageId, ","), "3", 1);
|
|
|
+ return R.ok(nbaExportResult);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("任务汇总报告导出异常", e);
|
|
|
+ return R.failed("任务汇总报告导出异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建excel表格数据
|
|
|
+ *
|
|
|
+ * @param packageId
|
|
|
+ * @param taskList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, Object> createExcelData(String packageId, List<WmTask> taskList) {
|
|
|
+ Map<String, Object> textParams = new HashMap<>();
|
|
|
+
|
|
|
+ WmScorePackage wmScorePackage = wmScorePackageService.getById(packageId);
|
|
|
+
|
|
|
+ List<WmScorePackage> wmScorePackages = wmScorePackageService.listByIds(Arrays.asList(packageId.split(",")));
|
|
|
+ String scoreIds = wmScorePackages.stream().map(WmScorePackage::getScorePackageName).collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ // 委托公司
|
|
|
+// SysDept sysDept = sysDeptService.getById(Integer.valueOf(wmScorePackage.getSendPackageDeptId()));
|
|
|
+// textParams.put("ent_name", sysDept.getName());
|
|
|
+
|
|
|
+ // 积分包名称
|
|
|
+ textParams.put("score_package_name", StrUtil.isBlank(scoreIds) ? wmScorePackage.getScorePackageName() : scoreIds);
|
|
|
+ // 积分包值
|
|
|
+// textParams.put("total_score_package_score", wmScorePackage.getScore());
|
|
|
+ // 结算金额
|
|
|
+// textParams.put("settle_amount",
|
|
|
+// wmScorePackage.getSettleStatus() != null && wmScorePackage.getSettleStatus() == 1 ? wmScorePackage.getScore() : "");
|
|
|
+
|
|
|
+ // 委托项目-年份
|
|
|
+// String belongDate = wmScorePackage.getBelongDate();
|
|
|
+// if (StrUtil.isNotBlank(belongDate)) {
|
|
|
+// textParams.put("year", belongDate.substring(0, 4));
|
|
|
+// }
|
|
|
+ // 委托项目-月份
|
|
|
+// String monthStr = belongDate.substring(5, 7);
|
|
|
+
|
|
|
+ if (taskList.isEmpty()) {
|
|
|
+ log.warn("未查询到审核通过的任务packageId={}", packageId);
|
|
|
+ return textParams;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 任务承接人
|
|
|
+ Set<String> taskUserIdSet = taskList.stream().map(WmTask::getTaskUserId).collect(Collectors.toSet());
|
|
|
+ List<SysUser> userList = sysUserService.listByIds(taskUserIdSet);
|
|
|
+ textParams.put("report_users", userList.stream().map(SysUser::getRealname).collect(Collectors.joining(StrUtil.COMMA)));
|
|
|
+
|
|
|
+
|
|
|
+ String minDateStr = null;
|
|
|
+ String maxDateStr = null;
|
|
|
+ // 服务周期
|
|
|
+ Map<String, String> serviceTimeRangeMap = wmScorePackageStatusService.getServiceTimeRange(wmScorePackage);
|
|
|
+ textParams.put("service_date", serviceTimeRangeMap.get("service_start_date") + "至" + serviceTimeRangeMap.get("service_end_date"));
|
|
|
+ minDateStr = serviceTimeRangeMap.get("service_start_date").substring(5, 7);
|
|
|
+ maxDateStr = serviceTimeRangeMap.get("service_end_date").substring(5, 7);
|
|
|
+
|
|
|
+// if (StrUtil.isAllNotBlank(minDateStr, maxDateStr)) {
|
|
|
+// if (minDateStr.equals(maxDateStr)) {
|
|
|
+// monthStr = minDateStr;
|
|
|
+// } else {
|
|
|
+// // 跨年情况判断
|
|
|
+// if (!belongDate.substring(0, 4).equals(serviceTimeRangeMap.get("service_end_date").substring(0, 4))) {
|
|
|
+// monthStr = String.format("%s月至%s年%s", minDateStr, serviceTimeRangeMap.get("service_end_date").substring(0, 4), maxDateStr);
|
|
|
+// } else {
|
|
|
+// monthStr = minDateStr + "月至" + maxDateStr;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if (StrUtil.isNotBlank(minDateStr)) {
|
|
|
+// monthStr = minDateStr;
|
|
|
+// } else if (StrUtil.isNotBlank(maxDateStr)) {
|
|
|
+// monthStr = maxDateStr;
|
|
|
+// }
|
|
|
+
|
|
|
+ // 委托项目-月份
|
|
|
+// textParams.put("month", monthStr);
|
|
|
+
|
|
|
+ // 任务完成时间
|
|
|
+// WmTask maxLookIntoDateTask = taskList.stream()
|
|
|
+// .filter(wmTask -> wmTask.getLookintoDate() != null)
|
|
|
+// .max(Comparator.comparing(WmTask::getLookintoDate)).get();
|
|
|
+// LocalDateTime maxTime = maxLookIntoDateTask.getLookintoDate();
|
|
|
+// textParams.put("finish_year", maxTime.getYear() + "");
|
|
|
+// Integer month = maxTime.getMonthValue();
|
|
|
+// if (month < 10) {
|
|
|
+// textParams.put("finish_month", "0" + maxTime.getMonthValue() + "");
|
|
|
+// } else {
|
|
|
+// textParams.put("finish_month", maxTime.getMonthValue() + "");
|
|
|
+// }
|
|
|
+// Integer day = maxTime.getDayOfMonth();
|
|
|
+// if (day < 10) {
|
|
|
+// textParams.put("finish_day", "0" + maxTime.getDayOfMonth() + "");
|
|
|
+// } else {
|
|
|
+// textParams.put("finish_day", maxTime.getDayOfMonth() + "");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// int taskScoreSum = taskList.stream().mapToInt(WmTask::getScore).sum();
|
|
|
+ // 已提交总值
|
|
|
+// textParams.put("total_submit_score", taskScoreSum);
|
|
|
+ // 审核通过总值
|
|
|
+// textParams.put("total_approved_score", taskScoreSum);
|
|
|
+
|
|
|
+ // 查询字典score_task_type
|
|
|
+ List<SysDictItem> scoreTaskTypeDictList = sysDictItemMapper.selectList(Wrappers.<SysDictItem>lambdaQuery()
|
|
|
+ .eq(SysDictItem::getType, "score_task_type")
|
|
|
+ .eq(SysDictItem::getDelFlag, "0"));
|
|
|
+ Map<String, String> scoreTaskTypeDictMap = scoreTaskTypeDictList.stream()
|
|
|
+ .collect(Collectors.toMap(SysDictItem::getValue, SysDictItem::getLabel));
|
|
|
+
|
|
|
+ // 查询taskType
|
|
|
+ List<WmTaskType> taskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
|
|
|
+ .eq(WmTaskType::getTaskTypeLevel, "1")
|
|
|
+ .eq(WmTaskType::getDelFlag, "0")
|
|
|
+// .eq(WmTaskType::getEnableFlag, "0")
|
|
|
+ );
|
|
|
+ // taskType通过parentId分组(key为parentId,value为taskTypeId的set)
|
|
|
+ Map<String, WmTaskType> taskTypeIdMap = taskTypeList.stream()
|
|
|
+ .collect(Collectors.toMap(WmTaskType::getId, taskType -> taskType));
|
|
|
+ // taskList添加parentId
|
|
|
+ taskList.forEach(wmTask -> wmTask.setTaskTypeParentId(taskTypeIdMap.get(wmTask.getTaskTypeId()).getParentId()));
|
|
|
+
|
|
|
+ // task通过taskTypeParentId分组
|
|
|
+ Map<String, List<WmTask>> taskParantMap = taskList.stream()
|
|
|
+ .collect(Collectors.groupingBy(WmTask::getTaskTypeParentId, Collectors.toList()));
|
|
|
+
|
|
|
+ // 封装brief table1数据(统计每个大类任务的积分、任务数)
|
|
|
+ List<Map<String, Object>> briefTable1List = new ArrayList<>();
|
|
|
+ taskParantMap.forEach((parentId, wmTasks) -> {
|
|
|
+ Map<String, Object> briefTable1Params = new HashMap<>();
|
|
|
+ briefTable1Params.put("task_type_name", scoreTaskTypeDictMap.get(parentId));
|
|
|
+ briefTable1Params.put("task_count", wmTasks.size());
|
|
|
+ briefTable1Params.put("task_sum", wmTasks.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable1List.add(briefTable1Params);
|
|
|
+ });
|
|
|
+ Map<String, Object> briefTable1TotalParams = new HashMap<>();
|
|
|
+ briefTable1TotalParams.put("task_type_name", "合计");
|
|
|
+ briefTable1TotalParams.put("task_count", taskList.size());
|
|
|
+ briefTable1TotalParams.put("task_sum", taskList.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable1List.add(briefTable1TotalParams);
|
|
|
+
|
|
|
+ // task通过taskTypeId分组
|
|
|
+ Map<String, List<WmTask>> taskTypeMap = taskList.stream()
|
|
|
+ .collect(Collectors.groupingBy(WmTask::getTaskTypeId, Collectors.toList()));
|
|
|
+ // 封装brief table1数据(统计每个小类任务的积分、任务数)
|
|
|
+ List<Map<String, Object>> briefTable1bList = new ArrayList<>();
|
|
|
+ taskTypeMap.forEach((taskTypeId, wmTasks) -> {
|
|
|
+ Map<String, Object> briefTable1Params = new HashMap<>();
|
|
|
+ briefTable1Params.put("task_type_name", taskTypeIdMap.get(taskTypeId).getTaskTypeName());
|
|
|
+ briefTable1Params.put("task_count", wmTasks.size());
|
|
|
+ briefTable1Params.put("task_sum", wmTasks.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable1bList.add(briefTable1Params);
|
|
|
+ });
|
|
|
+ Map<String, Object> briefTable11TotalParams = new HashMap<>();
|
|
|
+ briefTable11TotalParams.put("task_type_name", "合计");
|
|
|
+ briefTable11TotalParams.put("task_count", taskList.size());
|
|
|
+ briefTable11TotalParams.put("task_sum", taskList.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable1bList.add(briefTable11TotalParams);
|
|
|
+
|
|
|
+ // 封装brief table2数据(统计每个人任务积分、任务数)
|
|
|
+ Map<String, List<WmTask>> taskUserMap = taskList.stream().collect(Collectors.groupingBy(WmTask::getTaskUserId));
|
|
|
+ List<Map<String, Object>> briefTable2List = new ArrayList<>();
|
|
|
+ taskUserMap.forEach((userId, wmTasks) -> {
|
|
|
+ SysUser sysUser = sysUserService.getById(userId);
|
|
|
+ Map<String, Object> briefTable2Map = new HashMap<>();
|
|
|
+ briefTable2Map.put("user_name", sysUser.getRealname());
|
|
|
+ briefTable2Map.put("user_task_count", wmTasks.size());
|
|
|
+ briefTable2Map.put("user_task_sum", wmTasks.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable2List.add(briefTable2Map);
|
|
|
+ });
|
|
|
+ Map<String, Object> briefTable2TotalParams = new HashMap<>();
|
|
|
+ briefTable2TotalParams.put("user_name", "合计");
|
|
|
+ briefTable2TotalParams.put("user_task_count", taskList.size());
|
|
|
+ briefTable2TotalParams.put("user_task_sum", taskList.stream().map(WmTask::getScore).reduce(0, Integer::sum));
|
|
|
+ briefTable2List.add(briefTable2TotalParams);
|
|
|
+
|
|
|
+ // 查询所有涉及到的userId
|
|
|
+ Set<String> userIdSet = taskList.stream().map(WmTask::getTaskUserId).collect(Collectors.toSet());
|
|
|
+ List<SysUser> sysUsers = sysUserService.listByIds(userIdSet);
|
|
|
+ // userMap
|
|
|
+ Map<Integer, String> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getRealname));
|
|
|
+
|
|
|
+ // dept
|
|
|
+ WmDaDrugEnt wmDaDrugEnt = wmDaDrugEntService.getById(wmScorePackage.getDrugEntId());
|
|
|
+ SysDept sysDept = sysDeptService.getById(wmScorePackage.getDeptId());
|
|
|
+
|
|
|
+ // 封装detailTable数据(任务详情)
|
|
|
+ List<Map<String, Object>> detailTableList = new ArrayList<>();
|
|
|
+ Map<String, Map<String, List<WmTask>>> collect = taskList.stream().collect(Collectors.groupingBy(WmTask::getTaskUserId, Collectors.groupingBy(WmTask::getTaskTypeParentId)));
|
|
|
+
|
|
|
+ collect.forEach((k, v) -> {
|
|
|
+ v.forEach((x, y) -> {
|
|
|
+ Map<String, Object> detailTableMap = new HashMap<>();
|
|
|
+ detailTableMap.put("user_name", userMap.get(Integer.valueOf(k)));
|
|
|
+ detailTableMap.put("task_type", scoreTaskTypeDictMap.get(x));
|
|
|
+ detailTableMap.put("score", y.stream().mapToInt(WmTask::getScore).sum());
|
|
|
+ detailTableMap.put("finish_time", DateUtil.format(y.stream().max(Comparator.comparing(WmTask::getCreateTime)).get().getCreateTime(), DatePattern.NORM_DATE_PATTERN));
|
|
|
+ detailTableMap.put("ent_name", (wmDaDrugEnt == null) ? ((sysDept == null) ? "无" : sysDept.getName()) : wmDaDrugEnt.getEntname());
|
|
|
+ detailTableList.add(detailTableMap);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 封装detailTable2数据(任务详情)
|
|
|
+ List<Map<String, Object>> detailTable2List = new ArrayList<>();
|
|
|
+ for (int i = 0; i < taskList.size(); i++) {
|
|
|
+ WmTask wmTask = taskList.get(i);
|
|
|
+ Map<String, Object> detailTableMap = new HashMap<>();
|
|
|
+ detailTableMap.put("user_name", userMap.get(Integer.valueOf(wmTask.getTaskUserId())));
|
|
|
+ detailTableMap.put("task_type", scoreTaskTypeDictMap.get(wmTask.getTaskTypeId()));
|
|
|
+ detailTableMap.put("score", wmTask.getScore());
|
|
|
+ detailTableMap.put("create_time", DateUtil.format(wmTask.getCreateTime(), DatePattern.NORM_DATE_PATTERN));
|
|
|
+ detailTableMap.put("index", i + 1);
|
|
|
+ detailTable2List.add(detailTableMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("textParams", textParams);
|
|
|
+ params.put("briefTable1Params", briefTable1List);
|
|
|
+ params.put("briefTable1bParams", briefTable1bList);
|
|
|
+ params.put("briefTable2Params", briefTable2List);
|
|
|
+ params.put("detailTableParams", detailTableList);
|
|
|
+ params.put("detailTable2Params", detailTable2List);
|
|
|
+
|
|
|
+ log.info("模板数据创建成功packageId={}, data={}", packageId, params);
|
|
|
+
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createExcel(final String templateFile, final String targetFile, final Map<String, Object> params) {
|
|
|
+ // 这里 指定文件
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(targetFile).withTemplate(templateFile).build()) {
|
|
|
+
|
|
|
+ // 填充列表开启自动换行,自动换行表示每次写入一条list数据是都会重新生成一行空行,此选项默认是关闭的,需要提前设置为true
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
|
|
|
+
|
|
|
+ // 每次都要创建writeSheet 这里注意必须指定sheetNo 而且sheetName必须不一样。
|
|
|
+ // sheet0
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet(0, "学术推广服务整体概况").build();
|
|
|
+
|
|
|
+ // sheet0填充标题
|
|
|
+ Map<String, Object> sheet0TitleMap = (Map<String, Object>) params.get("textParams");
|
|
|
+ excelWriter.fill(sheet0TitleMap, writeSheet);
|
|
|
+
|
|
|
+ // sheet0-table1填充数据
|
|
|
+ List<Map<String, Object>> briefTable1Params = (List<Map<String, Object>>) params.get("briefTable1Params");
|
|
|
+ excelWriter.fill(new FillWrapper("table1", briefTable1Params), fillConfig, writeSheet);
|
|
|
+
|
|
|
+ // sheet0-table2填充数据
|
|
|
+ List<Map<String, Object>> briefTable1bParams = (List<Map<String, Object>>) params.get("briefTable1bParams");
|
|
|
+ excelWriter.fill(new FillWrapper("table2", briefTable1bParams), fillConfig, writeSheet);
|
|
|
+
|
|
|
+ // sheet0-table3填充数据
|
|
|
+ List<Map<String, Object>> briefTable2Params = (List<Map<String, Object>>) params.get("briefTable2Params");
|
|
|
+ excelWriter.fill(new FillWrapper("table3", briefTable2Params), fillConfig, writeSheet);
|
|
|
+
|
|
|
+ // sheet1
|
|
|
+ WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "学术推广服务明细").build();
|
|
|
+
|
|
|
+ // sheet1填充标题
|
|
|
+ excelWriter.fill(sheet0TitleMap, writeSheet1);
|
|
|
+
|
|
|
+ // sheet1-table1填充数据
|
|
|
+ List<Map<String, Object>> detailTableParams = (List<Map<String, Object>>) params.get("detailTableParams");
|
|
|
+ excelWriter.fill(new FillWrapper("table1", detailTableParams), fillConfig, writeSheet1);
|
|
|
+
|
|
|
+ // sheet2
|
|
|
+ WriteSheet writeSheet2 = EasyExcel.writerSheet(2, "学术推广服务任务明细").build();
|
|
|
+
|
|
|
+ // sheet2填充标题
|
|
|
+ excelWriter.fill(sheet0TitleMap, writeSheet2);
|
|
|
+
|
|
|
+ // sheet1-table1填充数据
|
|
|
+ List<Map<String, Object>> detailTable2Params = (List<Map<String, Object>>) params.get("detailTable2Params");
|
|
|
+ excelWriter.fill(new FillWrapper("table1", detailTable2Params), fillConfig, writeSheet2);
|
|
|
+
|
|
|
+ // 分页去数据库查询数据 这里可以去数据库查询每一页的数据
|
|
|
+// excelWriter.write(dataList(), writeSheet);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|