郑永安
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
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
package com.gk.hotwork.specialWork.service.impl;
 
 
 
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Exception.E;
import com.gk.hotwork.specialWork.entity.WorkApplyInfo;
import com.gk.hotwork.specialWork.enums.WorkTypeEnum;
import com.gk.hotwork.specialWork.service.*;
import com.gk.hotwork.specialWork.util.WorkExportUtil;
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.util.HashMap;
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){
        Map<String, Object> dataMap = new HashMap<>();
        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;
        }
 
    }
 
    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 (BusinessException e) {
            e.printStackTrace();
            throw new BusinessException(e.getCode(), e.getMessage());
        }catch (Exception e){
            logger.error("导出失败!",e);
            throw new BusinessException(E.EXPORT_FAIL,"导出失败!");
        }
    }
 
}