Commit d0a5ece1 authored by wangqiang's avatar wangqiang

ExtPlanController:业务代码迁入(2.x版本->4.1版本)--已全部编译通过

parent d15e5f24
......@@ -100,6 +100,12 @@ public class ExtDistributeRecordVO extends IdOnlyVO implements IdVO ,DxObjFileLi
@JsonIgnore
private DxLogicDeleteVOEmbeddable dxLogicDeleteEmbeddable;
/**
* 分发记录对象Link模型集合
*/
@RelationProperty(refProperty = "source")
private List<ExtDisReocredLinkVO> extDisReocredLink;
/**
* 显示名称
*/
......
......@@ -57,6 +57,45 @@ public class ExtPlanController<V extends ExtPlanVO, S extends ExtPlanService<V>>
return apiResult;
}
/**
* 修改计划状态
*
* @param state
* @param ids
* @return
*/
@ApiOperation("计划驱动编制任务")
@GetMapping(value = "/changeState")
public ApiResult changeState(@RequestParam String state, @RequestParam List<Long> ids) {
extPlanService.extChangeState(state, ids);
return ApiResult.ok("启动计划成功");
}
/**
* 校验计划答复状态
*
* @param id
* @return
*/
@ApiOperation("校验计划答复状态")
@GetMapping(value = "/checkReplayState")
public ApiResult checkReplayState(@RequestParam Long id) {
return extPlanService.checkReplayState(id);
}
/**
* 导出计划
* @param response
* @param ids
* @throws IOException
*/
@ApiOperation(value = "导出计划", notes = "导出计划", httpMethod = "GET")
@GetMapping(value = "/exportPlan")
public void exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids){
extPlanService.exportPlan(response, ids);
}
}
......@@ -43,4 +43,28 @@ public interface ExtPlanService<V extends ExtPlanVO> extends ExtPlanServiceShado
ApiResult insertPlan(MultipartFile uploadFile, Long projectId);
/**
* 计划驱动编制任务
*
* @param state
* @param ids
*/
void extChangeState(String state, List<Long> ids);
/**
* 校验答复状态
*
* @param id
* @return
*/
ApiResult checkReplayState(Long id);
/**
* 导出计划
*
* @param response
* @param ids
*/
void exportPlan(HttpServletResponse response, List<Long> ids);
}
package com.yonde.dcs.plan.core.service.impl;
import cn.hutool.core.io.IoUtil;
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.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.utils.ExcelUtils;
import com.yonde.dcs.plan.common.utils.FileUtils;
import com.yonde.dcs.plan.common.utils.ResourceHelper;
import com.yonde.dcs.plan.common.vo.ExtPlanDocLinkVO;
import com.yonde.dcs.plan.common.vo.PlanExcelVO;
import com.yonde.dcs.plan.common.vo.*;
import com.yonde.dcs.plan.core.service.ExtDistributeRecordService;
import com.yonde.dcs.plan.core.service.ExtPlanDocLinkService;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
......@@ -22,17 +26,18 @@ import com.yonde.dex.dict.service.vo.DictDataVO;
import com.yonde.dex.user.common.vo.DxOrganizationVO;
import com.yonde.dex.version.plugin.core.deleteType.IterationDeleteVO;
import dm.jdbc.util.StringUtil;
import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import io.swagger.annotations.ApiOperation;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
import com.yonde.dcs.plan.common.vo.ExtPlanVO;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
......@@ -47,6 +52,7 @@ import com.yonde.dcs.plan.entity.po.ExtPlan;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
/**
......@@ -68,6 +74,9 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
@Autowired
private DictDataFeignService dictDataService;
@Autowired
private ExtDistributeRecordService extDistributeRecordService;
/**
* 通过userId获取组织名
*
......@@ -586,6 +595,195 @@ public class ExtPlanServiceImpl<V extends ExtPlanVO> implements ExtPlanService<V
public void batchCheckIn(List<ExtPlanVO> planList) {
this.checkin((V) planList);
}
/**
* 计划驱动编制任务
*
* @param state
* @param ids
*/
@Override
@Transactional
public void extChangeState(String state, List<Long> ids) {
//通过计划id查询,修改状态,启动工作流
for (Long id : ids) {
ExtPlanVO extPlanVO = this.searchById(id);
extPlanVO.setState(state);
//todo wq:(V) extPlanVO
ExtPlanVO savePlan = this.changeStatus((V) extPlanVO);
}
}
/**
* 通过id查询计划
*
* @param id
*/
private ExtPlanVO searchById(Long id) {
//通过number查询id
SearchQueryCondition query = SearchQueryCondition.builder()
.searchItems(SearchItems.builder().item(
new SearchItem("id", SearchItem.Operator.EQ, id, null))
.operator(SearchItems.BooleanOperator.AND).build()).build();
DxPageImpl<V> recursion = this.findRecursion(query);
if (CollectionUtils.isEmpty(recursion.getContent())) {
return null;
}
return DxPageUtils.getFirst(recursion);
}
/**
* 校验计划答复状态
*
* @param id
* @return
*/
@Override
public ApiResult checkReplayState(Long id) {
//通过id查询
ExtDistributeRecordVO recordVO = this.recursionDisRecordVO(id);
List<ExtDisReocredLinkVO> sourceDisReocredLink = recordVO.getExtDisReocredLink();
if (!CollectionUtils.isEmpty(sourceDisReocredLink)) {
sourceDisReocredLink.stream().forEach(item -> {
if ("ExtPlan".equals(item.getTargetIdType())) {
ExtPlanVO extPlanVO = (ExtPlanVO) item.getTarget();
//判断状态(计划反馈完成情况)
if (!"true".equals(extPlanVO.getCompletion())) {
throw new DxBusinessException("-1", "请先完成计划任务");
}
}
});
//修改状态
recordVO.setCompleted(true);
//todo wq:recordVO.setSender(null); recordVO.setHandler(null); 在4.1中如何设置该参数?
// recordVO.setSender(null);
// recordVO.setHandler(null);
recordVO.setOperator(OperatorType.MODIFY);
extDistributeRecordService.saveRecursion(recordVO);
}
return ApiResult.ok("任务关闭");
}
/**
* 通过id查询分发记录
*
* @param id
*/
private ExtDistributeRecordVO recursionDisRecordVO(Long id) {
SearchQueryCondition condition = SearchQueryCondition.builder()
.openProp(SearchQueryCondition.builder().name("sourceDisReocredLink")
.openProp(SearchQueryCondition.builder().name("target").build()).build())
.searchItems(SearchItems.builder()
.item(new SearchItem("id", SearchItem.Operator.EQ, id, null)).build()).build();
DxPageImpl recursion = extDistributeRecordService.findRecursion(condition);
if (!ObjectUtils.isEmpty(recursion)) {
return (ExtDistributeRecordVO) recursion.getContent().get(0);
}
return null;
}
/**
* 导出计划
*
* @param response
* @param ids
*/
@Override
public void exportPlan(HttpServletResponse response, List<Long> ids) {
//跟据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);
}
//获取外部资源配置
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;
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();
} finally {
// 关闭writer,释放内存
writerResult.close();
}
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
/**
* 设置计划值
*/
private void assembleWriter(ExcelWriter writer) {
writer.addHeaderAlias("operate", "操作");
writer.addHeaderAlias("planLevel", "计划级别");
writer.addHeaderAlias("superPlanCode", "父级计划编号");
writer.addHeaderAlias("number", "计划编号");
writer.addHeaderAlias("name", "计划名称");
writer.addHeaderAlias("businessPlanType", "业务计划类型");
writer.addHeaderAlias("phaseState", "阶段状态");
writer.addHeaderAlias("feedbackType", "反馈类型");
writer.addHeaderAlias("hasPlanTasks", "是否产生计划任务");
writer.addHeaderAlias("contractNo", "合同编号");
writer.addHeaderAlias("planExecutor", "计划执行人");
writer.addHeaderAlias("constructPeriod", "工期");
writer.addHeaderAlias("startTime", "开始时间");
writer.addHeaderAlias("completeTime", "完成时间");
//文件分类
writer.addHeaderAlias("fileType", "文件分类");
writer.addHeaderAlias("fileName", "文件名称");
writer.addHeaderAlias("fileNumber", "文件编号");
writer.addHeaderAlias("fileCode", "文件代号");
writer.addHeaderAlias("projectCode", "项目代号");
writer.addHeaderAlias("systemCode", "管理信息系统编码");
writer.addHeaderAlias("review", "审核者");
writer.addHeaderAlias("approver", "批准者");
writer.addHeaderAlias("verifier", "审定者");
writer.addHeaderAlias("secretCode", "密级");
}
}
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