输出请求参数
This commit is contained in:
parent
e9e23d1324
commit
e31be7fe70
@ -228,6 +228,11 @@
|
||||
<version>1.04</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.12</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/lennart/cpdetector -->
|
||||
<!-- <dependency>-->
|
||||
|
@ -4,16 +4,21 @@ import cn.keking.exception.KkFileException;
|
||||
import cn.keking.service.ContractService;
|
||||
import cn.keking.utils.Consts;
|
||||
import cn.keking.utils.ServiceResponse;
|
||||
import io.swagger.annotations.*;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author Hikaru
|
||||
@ -22,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@RestController
|
||||
@RequestMapping("/contract")
|
||||
@Slf4j
|
||||
@Api(tags = "合同模板操作" )
|
||||
@Api(tags = "合同模板操作")
|
||||
public class ContractController {
|
||||
|
||||
|
||||
@ -30,8 +35,6 @@ public class ContractController {
|
||||
private ContractService contractService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 合同生成
|
||||
* listTemplate
|
||||
@ -43,7 +46,7 @@ public class ContractController {
|
||||
@ApiOperation("根据模板生成合同")
|
||||
@PostMapping("/gen/{templateName}")
|
||||
public ServiceResponse<String> contractGen(
|
||||
@ApiParam( value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true ) @PathVariable String templateName,
|
||||
@ApiParam(value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true) @PathVariable String templateName,
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody()
|
||||
@RequestBody Map<String, Object> dataMap) {
|
||||
try {
|
||||
@ -93,7 +96,7 @@ public class ContractController {
|
||||
*/
|
||||
@ApiOperation("查询模板列表")
|
||||
@PostMapping("/list/template")
|
||||
public ServiceResponse<List<String>> listTemplate( @ApiParam( value = "默认列表: 销售合同: sellContract ; 销售框架合同: frameContract。 传空返回所有模板列表" ) @RequestBody(required = false) List<String> templateNames) {
|
||||
public ServiceResponse<List<String>> listTemplate(@ApiParam(value = "默认列表: 销售合同: sellContract ; 销售框架合同: frameContract。 传空返回所有模板列表") @RequestBody(required = false) List<String> templateNames) {
|
||||
try {
|
||||
templateNames = Optional.ofNullable(templateNames).orElse(Arrays.asList(Consts.FRAME_CONTRACT, Consts.SELL_CONTRACT));
|
||||
List<String> urls = this.contractService.listTemplate(templateNames);
|
||||
@ -111,24 +114,25 @@ public class ContractController {
|
||||
|
||||
/**
|
||||
* @return 下载合同pdf文件
|
||||
*
|
||||
* */
|
||||
*/
|
||||
@ApiParam("下载合同pdf文件")
|
||||
@PostMapping("/download/{templateName}")
|
||||
public ServiceResponse downloadcontract(
|
||||
@ApiParam( value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true ) @PathVariable String templateName,
|
||||
@ApiParam(value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true) @PathVariable String templateName,
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody()
|
||||
@RequestBody Map<String, Object> dataMap,
|
||||
HttpServletResponse response
|
||||
) {
|
||||
try {
|
||||
log.info(JSON.toJSONString(dataMap));
|
||||
|
||||
OutputStream outstream = null;
|
||||
|
||||
File file=contractService.download(templateName, dataMap);
|
||||
File file = contractService.download(templateName, dataMap);
|
||||
outstream = response.getOutputStream();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("application/octet-stream");
|
||||
String filename=dataMap.get("conCode")+".pdf";
|
||||
String filename = dataMap.get("conCode") + ".pdf";
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
|
||||
@ -143,7 +147,7 @@ public class ContractController {
|
||||
bufferedInputStream.close();
|
||||
outstream.flush();
|
||||
outstream.close();
|
||||
return new ServiceResponse<>( "success",
|
||||
return new ServiceResponse<>("success",
|
||||
ServiceResponse.RESULT_CODE_SUCCESS_CODE);
|
||||
} catch (Exception e) {
|
||||
log.error("生成错误:", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user