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);
|
}
|
}
|
|
}
|