郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.gkhy.safePlatform.specialWork.service.impl;
 
 
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.specialWork.entity.*;
import com.gkhy.safePlatform.specialWork.enums.*;
import com.gkhy.safePlatform.specialWork.service.*;
import com.gkhy.safePlatform.specialWork.util.WorkExportPdfUtil;
import com.gkhy.safePlatform.specialWork.util.WorkExportUtil;
import com.itextpdf.text.DocumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
 
@Service("WorkPrintService")
public class WorkPrintServiceImpl implements WorkPrintService {
 
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private WorkHotPrintService workHotPrintService;
    @Autowired
    private WorkBlindPlatePluggingPrintService workBlindPlatePluggingPrintService;
    @Autowired
    private WorkAtHeightPrintService workAtHeightPrintService;
    @Autowired
    private WorkConfinedSpacePrintService workConfinedSpacePrintService;
    @Autowired
    private WorkBrokenCircuitPrintService workBrokenCircuitPrintService;
    @Autowired
    private WorkGroundBreakingPrintService workGroundBreakingPrintService;
    @Autowired
    private WorkHoistingPrintService workHoistingPrintService;
    @Autowired
    private WorkTemporaryPowerPrintService workTemporaryPowerPrintService;
 
    /**
     * 作业打印
     * @param workApplyInfo
     */
   /* public void workPrint(HttpServletResponse response, WorkApplyInfo workApplyInfo){
        switch (WorkTypeEnum.parse(workApplyInfo.getWorkType())) {
            case WORK_FIRE:
                exportWork(response,workHotPrintService.workHotPrint(workApplyInfo));
                break;
            case WORK_CLOSE_SPACE:
                exportWork(response,workConfinedSpacePrintService.workConfinedSpacePrint(response,workApplyInfo));
                break;
            case WORK_BLIND_PLATE:
                exportWork(response,workBlindPlatePluggingPrintService.workBlindPlatePluggingPrint(response,workApplyInfo));
                break;
            case WORK_BROKE_ROAD:
                exportWork(response,workBrokenCircuitPrintService.workBrokenCircuitPrint(response,workApplyInfo));
                break;
            case WORK_DIF_SOLI:
                exportWork(response,workGroundBreakingPrintService.workGroundBreakingPrint(response,workApplyInfo));
                break;
            case WORK_HIGH_SPACE:
                exportWork(response,workAtHeightPrintService.workAtHeightPrint(response,workApplyInfo));
                break;
            case WORK_HANG:
                exportWork(response,workHoistingPrintService.workHoistingPrint(response,workApplyInfo));
                break;
            case WORK_TEMP_ELECTRIC:
                exportWork(response,workTemporaryPowerPrintService.workTemporaryPowerPrint(response,workApplyInfo));
                break;
        }
 
    }*/
 
    @Override
    public void workPrintPdf(HttpServletResponse response, WorkApplyInfo workApplyInfo,WorkInfo workInfo) throws DocumentException, IOException {
        switch (WorkTypeEnum.parse(workApplyInfo.getWorkType())) {
            case WORK_FIRE:
                exportWorkPdf(response,workHotPrintService.workHotPrint(workApplyInfo,workInfo));
                break;
            case WORK_CLOSE_SPACE:
                exportWorkPdf(response,workConfinedSpacePrintService.workConfinedSpacePrint(workApplyInfo, workInfo));
                break;
            case WORK_BLIND_PLATE:
                exportWorkPdf(response,workBlindPlatePluggingPrintService.workBlindPlatePluggingPrint(workApplyInfo,workInfo));
                break;
            case WORK_BROKE_ROAD:
                exportWorkPdf(response,workBrokenCircuitPrintService.workBrokenCircuitPrint(workApplyInfo,workInfo));
                break;
            case WORK_DIF_SOLI:
                exportWorkPdf(response,workGroundBreakingPrintService.workGroundBreakingPrint(workApplyInfo,workInfo));
                break;
            case WORK_HIGH_SPACE:
                exportWorkPdf(response,workAtHeightPrintService.workAtHeightPrint(workApplyInfo,workInfo));
                break;
            case WORK_HANG:
                exportWorkPdf(response,workHoistingPrintService.workHoistingPrint(workApplyInfo,workInfo));
                break;
            case WORK_TEMP_ELECTRIC:
                exportWorkPdf(response,workTemporaryPowerPrintService.workTemporaryPowerPrint(workApplyInfo,workInfo));
                break;
        }
 
    }
    public void exportWork(HttpServletResponse response,Map<String, Object> dataMap){
        try{
            WorkExportUtil workExportUtil = new WorkExportUtil();
            workExportUtil.setTempLocalPath((String)dataMap.get("filePath"));    //设置模板的路径
            workExportUtil.init();            //初始化工具类
            workExportUtil.export(dataMap);   //写入相关数据
            workExportUtil.responseWord(response,(String)dataMap.get("fileName"),(String)dataMap.get("workCode"));
        }catch (AusinessException e) {
            e.printStackTrace();
            throw new AusinessException(e.getCode(), e.getMessage());
        }catch (BusinessException e) {
            e.printStackTrace();
            throw new BusinessException(e.getCode(), e.getMessage());
        }catch (Exception e){
            logger.error("导出失败!",e);
            throw new AusinessException(E.EXPORT_FAIL,"导出失败!");
        }
    }
    public void exportWorkPdf(HttpServletResponse response,Map<String, Object> dataMap) throws DocumentException, IOException {
        WorkExportPdfUtil workExportPdfUtil01 = new WorkExportPdfUtil();
        workExportPdfUtil01.generate(response,dataMap);
    }
 
}