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