许鹏程
2023-06-29 69da583c3a1ebb923c5023c5e2b42f094ccb1b53
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
package com.product.print.controller;
 
import com.product.common.lang.StringUtils;
import com.product.core.config.CoreConst;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.module.sys.version.ApiVersion;
import com.product.print.config.CmnCode;
import com.product.print.config.CmnConst;
import com.product.print.service.ide.IPrintRealizeService;
import com.product.util.support.AbstractBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * @ClassName PrintRealizeService
 * @Description 打印实现 控制层
 * @Author cheng
 * @Date 2021/12/1 9:50
 */
@RestController
@RequestMapping("/api/print/realize")
public class PrintRealizeController extends AbstractBaseController {
 
    @Autowired
    IPrintRealizeService printRealizeService;
 
    @PostMapping("/print/{version}")
    @ApiVersion(1)
    public String print(HttpServletRequest request, HttpServletResponse response) {
        try {
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            if (bean == null || fse == null) {
                return this.error(CmnCode.SYSTEM_FORM_NODATA);
            }
//            if (!CmnConst.TABLE_PRINT_CONFIG.equals(fse.getTableName())) {
//                return error(CmnCode.SYSTEM_TABLE_NODATA);
//            }
            if (StringUtils.isEmpty(CmnConst.PRINT_TEMP)) {
                return error(CmnCode.SYSTEM_FORM_COUNT);
            }
            printRealizeService.print(fse, response, true);
            return OK();
        } catch (BaseException e) {
            return error(e);
        } catch (Exception e) {
            return error(CmnCode.GET_PRINT_CONFIG_LIST_FAIL, e);
        }
    }
 
    @PostMapping("/printWord/{version}")
    @ApiVersion(1)
    public String printWord(HttpServletRequest request, HttpServletResponse response) {
        try {
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            if (bean == null || fse == null) {
                return this.error(CmnCode.SYSTEM_FORM_NODATA);
            }
//            if (!CmnConst.TABLE_PRINT_CONFIG.equals(fse.getTableName())) {
//                return error(CmnCode.SYSTEM_TABLE_NODATA);
//            }
            if (StringUtils.isEmpty(CmnConst.PRINT_TEMP)) {
                return error(CmnCode.SYSTEM_FORM_COUNT);
            }
            printRealizeService.print(fse, response, false);
            return OK();
        } catch (BaseException e) {
            return error(e);
        } catch (Exception e) {
            return error(CmnCode.GET_PRINT_CONFIG_LIST_FAIL, e);
        }
    }
 
}