Commit f7877f02 authored by wangqiang's avatar wangqiang

Merge remote-tracking branch 'origin/master'

parents 89ee59f8 04dbb09d
......@@ -69,7 +69,7 @@ public interface ExtPlanService<V extends ExtPlanVO> extends ExtPlanServiceShado
* @param response
* @param ids
*/
void exportPlan(HttpServletResponse response, List<Long> ids);
void exportPlan(HttpServletResponse response, List<Long> ids) throws IOException;
/**
......
package com.yonde.dcs.plan.core.service.impl;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
import com.yonde.dcs.document.expand.entity.DxDocumentVOExpand;
import com.yonde.dcs.document.feign.expand.ExtDxDocumentServiceFeign;
......@@ -16,6 +15,7 @@ import com.yonde.dcs.plan.common.vo.*;
import com.yonde.dcs.plan.core.repository.ExtPlanRepository;
import com.yonde.dcs.plan.core.service.ExtDistributeRecordService;
import com.yonde.dcs.plan.core.service.ExtPlanService;
import com.yonde.dcs.plan.core.util.CommonUtils;
import com.yonde.dcs.plan.entity.po.ExtPlan;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
......@@ -28,8 +28,10 @@ import com.yonde.dex.basedata.utils.obj.DxEntityUtils;
import com.yonde.dex.bmodel.common.entity.vo.ModelDefinitionVO;
import com.yonde.dex.bmodel.feign.api.ModelDefinitionFeignService;
import com.yonde.dex.dao.service.util.DxPageUtils;
import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.dict.feign.DictDataFeignService;
import com.yonde.dex.dict.service.vo.DictDataVO;
import com.yonde.dex.systemfile.feign.SystemFileFeignService;
import com.yonde.dex.user.common.vo.DxOrganizationVO;
import com.yonde.dex.user.common.vo.DxUserInfoVO;
import com.yonde.dex.user.feign.DxOrganizationFeign;
......@@ -38,7 +40,6 @@ import com.yonde.dex.version.plugin.core.deleteType.IterationDeleteVO;
import com.yonde.dex.wfc.feign.api.WfcProcessFeign;
import dm.jdbc.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -50,7 +51,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
......@@ -98,6 +98,12 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
@Autowired
private WfcProcessFeign wfcProcessFeign;
@Autowired
private SystemFileFeignService systemFileFeignService;
@Autowired
private FileManagerFeignService fileManagerFeignService;
/**
* 通过userId获取组织名
*
......@@ -333,9 +339,9 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
buffer.append(String.format("第%s行,计划编号编号已存在", i + 1) + "</br>");
}
DxUserInfoVO userByName = dxUserInfoFeign.getUserByName(excelVO.getPlanExecutor());
if (StringUtils.isEmpty(userByName)){
if (StringUtils.isEmpty(userByName)) {
buffer.append(String.format("第%s行,计划执行人不存在", i + 1) + "</br>");
}else {
} else {
excelVO.setPlanExecutorId(userByName.getId());
}
......@@ -618,6 +624,19 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
return DxPageUtils.getFirst(recursion);
}
private List<ExtPlanVO> searchById(List<Long> id) {
//通过number查询id
SearchQueryCondition query = SearchQueryCondition.builder()
.searchItems(SearchItems.builder().item(
new SearchItem("id", SearchItem.Operator.IN, id, null))
.operator(SearchItems.BooleanOperator.AND).build()).build();
DxPageImpl<V> recursion = this.findRecursion(query);
if (CollectionUtils.isEmpty(recursion.getContent())) {
return null;
}
return (List<ExtPlanVO>) recursion.getContent();
}
/**
* 校验计划答复状态
*
......@@ -674,69 +693,67 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
* @param ids
*/
@Override
public void exportPlan(HttpServletResponse response, List<Long> ids) {
public void exportPlan(HttpServletResponse response, List<Long> ids) throws IOException {
//跟据id获取计划
List<PlanExcelVO> planExcelVOS = new ArrayList<>();
for (Long id : ids) {
//通过id查询
ExtPlanVO extPlanVO = this.searchById(id);
PlanExcelVO excelPlanVO = new PlanExcelVO();
//转成excelVo对象
BeanUtils.copyProperties(extPlanVO, excelPlanVO);
excelPlanVO.setName(extPlanVO.getName());
excelPlanVO.setNumber(extPlanVO.getNumber());
excelPlanVO.setHasPlanTasks(extPlanVO.getHasPlanTasks() == true ? "是" : "否");
planExcelVOS.add(excelPlanVO);
List<ExtPlanVO> extPlanVOS = this.searchById(ids);
List<Map<String, Object>> mapList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(extPlanVOS)) {
for (ExtPlanVO extPlanVO : extPlanVOS) {
Map<String, Object> exportMap = new HashMap<>();
exportMap.put("name", extPlanVO.getName());
exportMap.put("number", extPlanVO.getNumber());
exportMap.put("superPlanCode", extPlanVO.getSuperPlanCode());
exportMap.put("businessPlanType", extPlanVO.getBusinessPlanType());
exportMap.put("feedbackType", extPlanVO.getFeedbackType());
exportMap.put("hasPlanTasks", extPlanVO.getHasPlanTasks());
exportMap.put("contractNo", extPlanVO.getContractNo());
exportMap.put("planExecutor", extPlanVO.getPlanExecutor());
exportMap.put("constructPeriod", extPlanVO.getConstructPeriod());
exportMap.put("startTime", extPlanVO.getStartTime());
exportMap.put("completeTime", extPlanVO.getCompleteTime());
String secretCode = CommonUtils.searchDictDataValueByDictCode(Constants.SECRET_CODE, extPlanVO.getSecretCode());
exportMap.put("secretCode", secretCode);
mapList.add(exportMap);
}
}
//获取外部资源配置
Properties prop = ResourceHelper.getResource();
//下载模板文件路径
String exportPlanTemplatePath = prop.getProperty("ExportPlanTemplate");
ExcelWriter writer = ExcelUtil.getWriter(exportPlanTemplatePath, "sheet1");
// 通过工具类创建writer并且进行别名
this.assembleWriter(writer);
//指定样式
StyleSet style = writer.getStyleSet();
CellStyle cellStyle = style.getCellStyleForDate();
//14 代表的时间格式是 yyyy/MM/dd
cellStyle.setDataFormat((short) 14);
writer.setStyle(cellStyle, "M2");
writer.setStyle(cellStyle, "N2");
//out为OutputStream,需要写出到的目标流
//response为HttpServletResponse对象
response.setContentType(Constants.EXCEL_TYPE);
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + "计划导出数据.xlsx");
ServletOutputStream out = null;
ExcelWriter writerResult = null;
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("name", "计划名称");
writer.addHeaderAlias("number", "计划编号");
writer.addHeaderAlias("superPlanCode", "父级计划编号");
writer.addHeaderAlias("businessPlanType", "业务计划类型");
writer.addHeaderAlias("feedbackType", "反馈类型");
writer.addHeaderAlias("hasPlanTasks", "是否产生计划任务");
writer.addHeaderAlias("contractNo", "合同编号");
writer.addHeaderAlias("planExecutor", "计划执行人");
writer.addHeaderAlias("constructPeriod", "工期");
writer.addHeaderAlias("startTime", "开始时间");
writer.addHeaderAlias("completeTime", "完成时间");
writer.addHeaderAlias("secretCode", "密级");
writer.write(mapList, true);
ServletOutputStream outputStream = null;
try {
out = response.getOutputStream();
String exportPlanDataPath = prop.getProperty("ExportPlanData");
File file = new File(exportPlanDataPath);
writer.flush(file);
// 关闭writer,释放内存
writer.close();
writerResult = ExcelUtil.getWriter(file, "sheet1");
this.assembleWriter(writerResult);
writerResult.write(planExcelVOS, true);
//指定样式
StyleSet styleResult = writerResult.getStyleSet();
CellStyle cellStyleResult = styleResult.getCellStyleForDate();
writerResult.setStyle(cellStyleResult, "M2");
writerResult.setStyle(cellStyleResult, "N2");
//14 代表的时间格式是 yyyy/MM/dd
cellStyleResult.setDataFormat((short) 14);
writerResult.flush(out, true);
} catch (IOException e) {
e.printStackTrace();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
String fileName = URLEncoder.encode("进度计划数据", "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
outputStream = response.getOutputStream();
writer.flush(outputStream, true);
} catch (Exception e) {
throw new DxBusinessException("500", "导出进度计划出错!错误原因:" + e.getMessage());
} finally {
// 关闭writer,释放内存
writerResult.close();
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
// 关闭输出流出错
throw new DxBusinessException("500", "关闭输出流出错!" + e.getMessage());
}
}
writer.close();
}
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
/**
......
......@@ -69,7 +69,7 @@ public interface ExtPlanServiceFeign<V extends ExtPlanVO> extends ExtPlanService
*/
@ApiOperation(value = "导出计划", notes = "导出计划", httpMethod = "GET")
@GetMapping(value = "/exportPlan")
void exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids);
void exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids) throws IOException;
@ApiOperation(value = "通过文件分类查询", notes = "通过文件分类查询", httpMethod = "post")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment