郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.gk.hotwork.Service.ServiceImpl;
 
import com.gk.hotwork.Domain.Utils.WordTemplate;
import com.gk.hotwork.Service.WordService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.util.*;
 
@Service("wordService")
public class WordServiceImpl implements WordService {
 
    private static final WordTemplate.FontCustomize task_table_1 = new WordTemplate.FontCustomize(7, "宋体");
    private static final WordTemplate.FontCustomize task_table_2 = new WordTemplate.FontCustomize(12, "仿宋");
 
    @Value("${taskPath}")
    private String taskPath;
    @Value("${taskPathPrefix}")
    private String taskPathPrefix;
    /**
     * @Description: 生成真实word @Params tables:里表格, simpleData:单一数据
     * @date 2021/8/26 14:43
     */
    public void generateAllTaskCert(Map<String,Map<String,List<String>>> taskTypeMap,
                                    Map<String,Map<String,List<WordTemplate.Attribute>>> type,
                                    Map<String, WordTemplate.Table> tables,
                                    Map<String, WordTemplate.MergeTable> mergeTables,
                                    Map<String, String> simpleData,
                                    Map<String,String> nameMapGraph,
                                    WordTemplate template) throws IOException, XmlException, InvalidFormatException, InterruptedException {
 
        //自检列表重新生成变量
        template.generateSelfCheckTableParam(0,taskTypeMap,task_table_1.fontSize, task_table_1.fontFamily);
        //找到type及其模板行生成相关
        template.generateOwnTypeAndAttrs(0,type,task_table_1.fontSize, task_table_1.fontFamily);
        //二维码
        template.replaceQRCode(taskPath,simpleData.get("code"),40,40,350,0);
        //替换签名
        template.replaceAutoGraph(taskPathPrefix,nameMapGraph,50,30,0,0);
        //第一个table替换相应样式
        template.replace(0, tables,mergeTables, simpleData, task_table_1.fontSize, task_table_1.fontFamily);
//        //第二个table替换相应样式
        template.replace(1, tables,new HashMap<>(), simpleData, task_table_2.fontSize, task_table_2.fontFamily);
    }
}