|
@@ -1,9 +1,14 @@
|
|
|
package com.nationrel.modules.pdsc.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.nationrel.modules.pdsc.constant.PDSCConstant;
|
|
@@ -16,9 +21,16 @@ import com.nationrel.modules.pdsc.req.ProjectInfoReleaseReq;
|
|
|
import com.nationrel.modules.pdsc.service.*;
|
|
|
import com.nationrel.modules.pdsc.vo.ProjectInfoListVo;
|
|
|
import com.nationrel.modules.pdsc.vo.ProjectInfoVo;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import jakarta.servlet.ServletOutputStream;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.CommonAPI;
|
|
|
import org.jeecg.common.api.IPageExtField;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.constant.SymbolConstant;
|
|
|
+import org.jeecg.common.constant.enums.FileTypeEnum;
|
|
|
+import org.jeecg.common.system.vo.DictModel;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.WrapperUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -57,6 +69,8 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
|
|
|
private IPdscMaturityService pdscMaturityService;
|
|
|
@Autowired
|
|
|
private ProjectInfoMapper projectInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private CommonAPI commonApi;
|
|
|
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -225,6 +239,122 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param response servlet响应
|
|
|
+ * @param req 请求
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportXls(HttpServletResponse response, ProjectInfoListReq req) throws Exception {
|
|
|
+ ServletOutputStream out = null;
|
|
|
+ try (ExcelWriter writer = ExcelUtil.getWriter(true)) {
|
|
|
+ LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ req.setUserId(user.getId());
|
|
|
+ List<ProjectInfoListVo> projectInfoListVos = projectInfoMapper.list(req).stream().map(v -> {
|
|
|
+ ProjectInfoListVo vo = new ProjectInfoListVo();
|
|
|
+ BeanUtil.copyProperties(v, vo);
|
|
|
+ return vo;
|
|
|
+ }).toList();
|
|
|
+ writer.write(buildExportExcelRows(projectInfoListVos), true);
|
|
|
+ setExportExcelColumnWidth(projectInfoListVos, writer);
|
|
|
+ String fileName = "项目信息" + FileTypeEnum.xlsx.getType();
|
|
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + fileName);
|
|
|
+ response.setContentType("application/msexcel");
|
|
|
+ out = response.getOutputStream();
|
|
|
+ writer.flush(out, true);
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(out);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置excel导出列宽度
|
|
|
+ *
|
|
|
+ * @param projectInfoListVos 数据
|
|
|
+ */
|
|
|
+ private void setExportExcelColumnWidth(List<ProjectInfoListVo> projectInfoListVos, ExcelWriter writer) {
|
|
|
+ if (CollUtil.isEmpty(projectInfoListVos)) return;
|
|
|
+ writer.setColumnWidth(0, 10);
|
|
|
+ writer.setColumnWidth(1, 25);
|
|
|
+ writer.setColumnWidth(2, 20);
|
|
|
+ writer.setColumnWidth(3, 20);
|
|
|
+ writer.setColumnWidth(4, 20);
|
|
|
+ writer.setColumnWidth(5, 20);
|
|
|
+ writer.setColumnWidth(6, 20);
|
|
|
+ writer.setColumnWidth(7, 20);
|
|
|
+ writer.setColumnWidth(8, 20);
|
|
|
+ writer.setColumnWidth(9, 20);
|
|
|
+ writer.setColumnWidth(10, 20);
|
|
|
+ writer.setColumnWidth(11, 20);
|
|
|
+ writer.setColumnWidth(12, 20);
|
|
|
+ writer.setColumnWidth(13, 20);
|
|
|
+ writer.setColumnWidth(14, 20);
|
|
|
+ writer.setColumnWidth(15, 20);
|
|
|
+ writer.setColumnWidth(16, 20);
|
|
|
+ writer.setColumnWidth(17, 20);
|
|
|
+ writer.setColumnWidth(18, 20);
|
|
|
+ writer.setColumnWidth(19, 20);
|
|
|
+ writer.setColumnWidth(20, 20);
|
|
|
+ writer.setColumnWidth(21, 20);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建excel导出数据
|
|
|
+ *
|
|
|
+ * @param projectInfoListVos 数据
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> buildExportExcelRows(List<ProjectInfoListVo> projectInfoListVos) {
|
|
|
+ List<Map<String, Object>> rows = CollUtil.newArrayList();
|
|
|
+ int num = 1;
|
|
|
+ Map<String, String> projectTypeMap = commonApi.queryDictItemsByCode("nationrel_pdsc_project_type")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ Map<String, String> ctqGradeMap = commonApi.queryDictItemsByCode("nationrel_pdsc_ctq_grade")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ Map<String, String> statusMap = commonApi.queryDictItemsByCode("nationrel_pdsc_status")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ String createBy = projectInfoListVos.stream().map(ProjectInfoListVo::getCreateBy).distinct().collect(Collectors.joining(SymbolConstant.COMMA));
|
|
|
+ Map<String, String> usernameMap = commonApi.translateDictFromTableByKeys("sys_user", "realname", "username", createBy, "master")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ String owner = projectInfoListVos.stream().map(ProjectInfoListVo::getOwner).distinct().collect(Collectors.joining(SymbolConstant.COMMA));
|
|
|
+ Map<String, String> ownerMap = commonApi.translateDictFromTableByKeys("sys_user", "realname", "id", owner, "master")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ String sysOrgCode = projectInfoListVos.stream().map(ProjectInfoListVo::getSysOrgCode).distinct().collect(Collectors.joining(SymbolConstant.COMMA));
|
|
|
+ Map<String, String> sysOrgCodeMap = commonApi.translateDictFromTableByKeys("sys_depart", "depart_name", "org_code", sysOrgCode, "master")
|
|
|
+ .stream().collect(Collectors.toMap(DictModel::getValue, DictModel::getText));
|
|
|
+ for (ProjectInfoListVo v : projectInfoListVos) {
|
|
|
+ int finalNum = num;
|
|
|
+ rows.add(new LinkedHashMap<>() {{
|
|
|
+ put("序号", finalNum);
|
|
|
+ put("PDSC编号", v.getCode());
|
|
|
+ put("PDSC名称", v.getName());
|
|
|
+ put("项目名称", v.getProjectName());
|
|
|
+ put("产品名称", v.getProductName());
|
|
|
+ put("项目类型", projectTypeMap.getOrDefault(v.getProjectType(), StrUtil.EMPTY));
|
|
|
+ put("项目阶段", v.getProjectStage());
|
|
|
+ put("CTQ级别", ctqGradeMap.getOrDefault(v.getCtqGrade(), StrUtil.EMPTY));
|
|
|
+ put("Owner", ownerMap.getOrDefault(v.getOwner(), StrUtil.EMPTY));
|
|
|
+ put("创建人", usernameMap.getOrDefault(v.getCreateBy(), StrUtil.EMPTY));
|
|
|
+ put("部门", sysOrgCodeMap.getOrDefault(v.getSysOrgCode(), StrUtil.EMPTY));
|
|
|
+ put("状态", statusMap.getOrDefault(v.getStatus(), StrUtil.EMPTY));
|
|
|
+ put("版本", v.getVersion());
|
|
|
+ put("第零关卡时间", DateUtil.formatDate(v.getZeroLevelTime()));
|
|
|
+ put("第一关卡时间", DateUtil.formatDate(v.getOneLevelTime()));
|
|
|
+ put("第二关卡时间", DateUtil.formatDate(v.getTwoLevelTime()));
|
|
|
+ put("第三关卡时间", DateUtil.formatDate(v.getThreeLevelTime()));
|
|
|
+ put("第四关卡时间", DateUtil.formatDate(v.getFourLevelTime()));
|
|
|
+ put("第五关卡时间", DateUtil.formatDate(v.getFiveLevelTime()));
|
|
|
+ put("第六关卡时间", DateUtil.formatDate(v.getSixLevelTime()));
|
|
|
+ put("创建日期", DateUtil.formatDate(v.getCreateTime()));
|
|
|
+ put("更新日期", DateUtil.formatDate(v.getUpdateTime()));
|
|
|
+ }});
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 拷贝项目信息-团队成员
|
|
|
*
|