|
@@ -1919,6 +1919,281 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
return R.ok("导入成功");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R wordExportPrj(Map<String, Object> map, HttpServletResponse response) {
|
|
|
+ Object projectObj = map.get("projectId");
|
|
|
+ Object exportObj = map.get("exportType");
|
|
|
+ String day = DateUtils.format(new Date());
|
|
|
+ String projectId = (String) projectObj;
|
|
|
+ String exportType = (String) exportObj;
|
|
|
+ ZhcxProjectManageDo projectManageDo = zhcxProjectManageService.getById(projectId);
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById("52f8f612f1ab43e58d9e3b46ceef6c2c");
|
|
|
+ final Document[] indexDoc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
|
|
|
+ FormData formData = new FormData();
|
|
|
+ List<Map<String,Object>> mainDataList = new ArrayList<>();
|
|
|
+ Map<String,Object> mainMap = new HashMap<>(16);
|
|
|
+ String projectEnName = "";
|
|
|
+ if (StringUtils.isNotBlank(projectManageDo.getProjectEnName())){
|
|
|
+ projectEnName = projectManageDo.getProjectEnName();
|
|
|
+ }
|
|
|
+ mainMap.put("projectNames",projectManageDo.getProjectName()+projectEnName);
|
|
|
+ mainMap.put("projectCode",projectManageDo.getProjectCode());
|
|
|
+ mainMap.put("projectName",projectManageDo.getProjectName());
|
|
|
+ mainMap.put("currentDate",day);
|
|
|
+ mainDataList.add(mainMap);
|
|
|
+ formData.setMainDataList(mainDataList);
|
|
|
+ indexDoc[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
|
|
|
+ List<ZhcxCommissionCheckDetailDo> list = zhcxCommissionCheckDetailDao.listData(map);
|
|
|
+ List<ZhcxCommissionCheckDetailTreeDo> checkTreeList = zhcxCommissionCheckDetailTreeService.listCheckDetailTreeData(map);
|
|
|
+ Document doc = null;
|
|
|
+ DocumentBuilder builder = null;
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/检查内容明细模版.doc");
|
|
|
+ try {
|
|
|
+ doc = new Document(classPathResource.getInputStream());
|
|
|
+ builder = new DocumentBuilder(doc);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.printExceptionDetail(e,"空模板获取出现异常");
|
|
|
+ return R.error("空模板获取出现异常");
|
|
|
+ }
|
|
|
+ //移动到页眉
|
|
|
+ try {
|
|
|
+ builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); // 主页眉
|
|
|
+ // 如果有多个页眉,可以选择HeaderFooterType.HEADER_FIRST, HeaderFooterType.HEADER_EVEN等
|
|
|
+ for (com.aspose.words.Field field : doc.getRange().getFields()) {
|
|
|
+ if ("«projectName»".equals(field.getResult())) { // 替换FieldName为你的字段名称
|
|
|
+ // 在这里操作field对象
|
|
|
+ builder.moveToField(field, true);
|
|
|
+ builder.write(projectManageDo.getProjectName());
|
|
|
+ field.setResult("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.printExceptionDetail(e,"页面参数赋值异常");
|
|
|
+ return R.error("页面参数赋值异常");
|
|
|
+ }
|
|
|
+ if(list.isEmpty()||checkTreeList.isEmpty()){
|
|
|
+ return R.error("该检查内容没有数据");
|
|
|
+ }else {
|
|
|
+ //设置word导出目录
|
|
|
+ Map<String, ZhcxCommissionCheckDetailWordVO> resMap = new HashMap<>();
|
|
|
+ for (ZhcxCommissionCheckDetailTreeDo item : checkTreeList) {
|
|
|
+ ZhcxCommissionCheckDetailWordVO checkDetailWordVO = new ZhcxCommissionCheckDetailWordVO();
|
|
|
+ checkDetailWordVO.setTitleContent(item.getName());
|
|
|
+ checkDetailWordVO.setLevel(item.getLevel());
|
|
|
+ checkDetailWordVO.setDetailList(new LinkedList<>());
|
|
|
+ if (!"-1".equals(item.getPid())){
|
|
|
+ //目前标题最多到三级
|
|
|
+ if (item.getLevel()==2){
|
|
|
+ String oldPid = item.getPid();
|
|
|
+ //树等级为二级处理章节号
|
|
|
+ List<ZhcxCommissionCheckDetailTreeDo> parentList = checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(oldPid.split("_")[0])).collect(Collectors.toList());
|
|
|
+ if (!parentList.isEmpty()){
|
|
|
+ String parentTreeCode = parentList.get(0).getTreecode();
|
|
|
+ if (StringUtils.isBlank(parentTreeCode)){
|
|
|
+ return R.error(item.getName()+"该树的父节点的编码不能为空");
|
|
|
+ }else {
|
|
|
+ //设置二级树节点的章节号规则:取出一级树编码.号后面的放在二级编码的第一位
|
|
|
+ int i = parentTreeCode.indexOf(".");
|
|
|
+ if (i!= -1){
|
|
|
+ String key = parentTreeCode.substring(i+1);
|
|
|
+ String result = item.getTreecode().replaceAll(".*\\.", key+".");
|
|
|
+ checkDetailWordVO.setChapterno(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ String[] fullIds = item.getFullpid().split(",");
|
|
|
+ if (fullIds.length>2){
|
|
|
+ //树等级为三级处理章节号
|
|
|
+ String oneLevelKey = "";
|
|
|
+ //根据当前节点过滤出一级树的列表
|
|
|
+ List<ZhcxCommissionCheckDetailTreeDo> oneLevelList = checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(fullIds[1])).collect(Collectors.toList());
|
|
|
+ if (!oneLevelList.isEmpty()){
|
|
|
+ //取出一级树节点编码
|
|
|
+ String oneLevelTreeCode = oneLevelList.get(0).getTreecode();
|
|
|
+ if (StringUtils.isBlank(oneLevelTreeCode)){
|
|
|
+ return R.error(item.getName()+"该树的一级节点的编码不能为空");
|
|
|
+ }else {
|
|
|
+ String oldPid = item.getPid();
|
|
|
+ //设置三级树节点的章节号规则:取出一级树编码.号后面的加上二级树编码.号后面的再加上自身.号后面的数据
|
|
|
+ int i = oneLevelTreeCode.indexOf(".");
|
|
|
+ if (i!= -1){
|
|
|
+ oneLevelKey = oneLevelTreeCode.substring(i+1);
|
|
|
+ String twoLevelKey = "";
|
|
|
+ List<ZhcxCommissionCheckDetailTreeDo> parentList = checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(oldPid.split("_")[0])).collect(Collectors.toList());
|
|
|
+ if (!parentList.isEmpty()){
|
|
|
+ //取出父树节点编码
|
|
|
+ String parentTreeCode = parentList.get(0).getTreecode();
|
|
|
+ if (StringUtils.isBlank(parentTreeCode)){
|
|
|
+ return R.error(item.getName()+"该树的父节点的编码不能为空");
|
|
|
+ }
|
|
|
+ int j = parentTreeCode.indexOf(".");
|
|
|
+ if (j!= -1){
|
|
|
+ twoLevelKey = parentTreeCode.substring(j+1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String result = item.getTreecode().replaceAll(".*\\.", oneLevelKey+"."+twoLevelKey+".");
|
|
|
+ checkDetailWordVO.setChapterno(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String oldPid = item.getPid();
|
|
|
+ String oldId = item.getId();
|
|
|
+ resMap.put(oldPid.split("_")[0]+","+oldId.split("_")[0],checkDetailWordVO);
|
|
|
+ }else {
|
|
|
+ String oldId = item.getId();
|
|
|
+ //树等级为一级处理章节号
|
|
|
+ if (StringUtils.isBlank(item.getTreecode())){
|
|
|
+ return R.error(item.getName()+"树编码不能为空");
|
|
|
+ }else {
|
|
|
+ //设置一级树节点的章节号规则:去除.号前面的就行
|
|
|
+ int i = item.getTreecode().indexOf(".");
|
|
|
+ if (i!= -1){
|
|
|
+ String key = item.getTreecode().substring(i+1);
|
|
|
+ checkDetailWordVO.setChapterno(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resMap.put(oldId.split("_")[0],checkDetailWordVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //子表数据
|
|
|
+ for (ZhcxCommissionCheckDetailDo item : list) {
|
|
|
+ String key = "";
|
|
|
+ String treeFullId = item.getTreefullid();
|
|
|
+ if (StringUtils.isBlank(treeFullId)){
|
|
|
+ log.error("该内容节点treeFullId值为空:{}", item.getChtestcontent());
|
|
|
+ return R.error(item.getChtestcontent()+"该内容节点数据有误");
|
|
|
+ }
|
|
|
+ int fillIdLength = treeFullId.split(",").length;
|
|
|
+ int i = treeFullId.indexOf(",");
|
|
|
+ if (fillIdLength<=3){
|
|
|
+ key = treeFullId.substring(i+1);
|
|
|
+ if(!resMap.containsKey(key)){
|
|
|
+ log.error("不能导出树表的id:{}的报告", treeFullId);
|
|
|
+ log.error("不能导出树表的key:{}的报告", key);
|
|
|
+ log.error("该内容节点有错误:{}的报告", item.getChtestcontent());
|
|
|
+ return R.error(item.getChtestcontent()+"该内容节点数据有误");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 从第一个逗号之后开始找第二个逗号
|
|
|
+ int j = treeFullId.indexOf(',', i + 1);
|
|
|
+ key = treeFullId.substring(j+1);
|
|
|
+ if(!resMap.containsKey(key)){
|
|
|
+ log.error("不能导出树表的id:{}的报告", treeFullId);
|
|
|
+ log.error("不能导出树表的key:{}的报告", key);
|
|
|
+ log.error("章节号有无误:{}的报告", item.getChapterno());
|
|
|
+ return R.error(item.getChtestcontent()+"该内容节点数据有误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ZhcxCommissionCheckDetailWordVO checkDetailWordVO = resMap.get(key);
|
|
|
+ List<ZhcxCommissionCheckDetailDo> detailList = checkDetailWordVO.getDetailList();
|
|
|
+ detailList.add(item);
|
|
|
+ }
|
|
|
+ List<ZhcxCommissionCheckDetailWordVO> resList = new LinkedList<>();
|
|
|
+ for (String s : resMap.keySet()) {
|
|
|
+ resList.add(resMap.get(s));
|
|
|
+ }
|
|
|
+ resList.sort((a,b)->{
|
|
|
+ LinkedList<String> a1 = new LinkedList<>(Arrays.asList(a.getChapterno().split("\\.")));
|
|
|
+ LinkedList<String> b1 = new LinkedList<>(Arrays.asList(b.getChapterno().split("\\.")));
|
|
|
+ return sort1(a1,b1);
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ builder.moveToDocumentStart();
|
|
|
+ for (ZhcxCommissionCheckDetailWordVO res : resList) {
|
|
|
+ if (res.getLevel()==1){
|
|
|
+ buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_1, 15, true, res.getChapterno()+"."+res.getTitleContent(), null);
|
|
|
+ }else {
|
|
|
+ if (res.getLevel()==2){
|
|
|
+ buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_2, 15, true,res.getChapterno()+"."+res.getTitleContent(), null);
|
|
|
+ }else {
|
|
|
+ buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_3, 15, true, res.getChapterno()+"."+res.getTitleContent(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(res.getDetailList())){
|
|
|
+ // 插入表头
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,30,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"NO.",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,40,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"模式1",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,40,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"模式2",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,60,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"测试内容中文",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,60,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"测试内容英文",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,60,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"标准测试方法",null);
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTitleContent(builder,60,20,HeightRule.EXACTLY,TextOrientation.HORIZONTAL,DEFAULT_FONT_NAME,StyleIdentifier.NORMAL,
|
|
|
+ 9, true,"测试地点",null);
|
|
|
+ builder.endRow();
|
|
|
+ int count =0;
|
|
|
+ for (ZhcxCommissionCheckDetailDo detailWordVO:res.getDetailList()){
|
|
|
+ count++;
|
|
|
+ // 插入表格的第一行
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,30,9,DEFAULT_FONT_NAME,false,String.valueOf(count));
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false,detailWordVO.getClassification());
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false,detailWordVO.getClassificationtwo());
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getChtestcontent());
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getEntestcontent());
|
|
|
+ builder.insertCell();
|
|
|
+ buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getTestmethod());
|
|
|
+ builder.insertCell();
|
|
|
+ String testAddress = "";
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getTestaddress())){
|
|
|
+ // 10-> CX BASE长兴基地 20-> USER SITE码头现场
|
|
|
+ if("20".equals(detailWordVO.getTestaddress())){
|
|
|
+ testAddress = "USER SITE码头现场";
|
|
|
+ }
|
|
|
+ if ("10".equals(detailWordVO.getTestaddress())){
|
|
|
+ testAddress = "CX BASE长兴基地";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,testAddress);
|
|
|
+ builder.endRow();
|
|
|
+ // 设置行高为自适应
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);
|
|
|
+ }
|
|
|
+ // 结束表格
|
|
|
+ builder.endTable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.printExceptionDetail(e,"移动至表头异常");
|
|
|
+ return R.error("移动至表头异常");
|
|
|
+ }
|
|
|
+ // 创建模板A的副本
|
|
|
+ Document cloneDocA = indexDoc[0].deepClone();
|
|
|
+ // 在副本上合并文档B
|
|
|
+ try {
|
|
|
+ cloneDocA.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
|
|
|
+ if("export".equals(exportType)){
|
|
|
+ exportWord(cloneDocA, response);
|
|
|
+ }else {
|
|
|
+ previewWord(cloneDocA, response);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.printExceptionDetail(e,"合并模版异常");
|
|
|
+ return R.error("合并模版异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
private void insertDetailData(List<ZhcxCommissionCheckBaseInfoTreeDo> treeList, List<ZhcxCommissionCheckBaseInfoDetailDo> detailList) {
|
|
|
//设置标准库子表的三级分类的id和树的全路径treefullid字段
|
|
|
if (!treeList.isEmpty()&&!detailList.isEmpty()){
|