|
@@ -0,0 +1,103 @@
|
|
|
+package com.jpsoft.picc.modules.pub.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.jpsoft.picc.modules.base.entity.InsuranceDefinitionLimit;
|
|
|
+import com.jpsoft.picc.modules.base.service.InsuranceDefinitionLimitService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsuranceApplicationService;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyMemberService;
|
|
|
+import com.jpsoft.picc.modules.common.config.PdfConfig;
|
|
|
+import com.jpsoft.picc.modules.common.utils.ItextPDFUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Api(description="投保单pdf下载")
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "/pub/policyPdf")
|
|
|
+@Slf4j
|
|
|
+public class PolicyPdfController {
|
|
|
+ @Autowired
|
|
|
+ private PdfConfig pdfConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceApplicationService insuranceApplicationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceDefinitionLimitService insuranceDefinitionLimitService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyMemberService insurancePolicyMemberService;
|
|
|
+
|
|
|
+ @ApiOperation(value="pdf文档生成与下载")
|
|
|
+ @RequestMapping(value = "download",method = RequestMethod.GET)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="applicationId",value = "投保单ID",required = true,paramType = "query"),
|
|
|
+ @ApiImplicitParam(name="policyId",value = "每月投保单ID",required = true,paramType = "query")
|
|
|
+ })
|
|
|
+ public ResponseEntity download(String applicationId, String policyId){
|
|
|
+ String logoUrl = pdfConfig.getLogoUrl();
|
|
|
+ ResponseEntity entity = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ InsuranceApplication insuranceApplication = insuranceApplicationService.get(applicationId);
|
|
|
+ List<InsuranceDefinitionLimit> insuranceDefinitionLimitList = insuranceDefinitionLimitService.findByDefinitionId(insuranceApplication.getDefinitionId());
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
|
|
|
+
|
|
|
+ for (InsuranceDefinitionLimit insuranceDefinitionLimit : insuranceDefinitionLimitList) {
|
|
|
+ Map<String, Object> map1 = new HashMap<String, Object>();
|
|
|
+ map1.put("id", insuranceDefinitionLimit.getId());
|
|
|
+ map1.put("name", insuranceDefinitionLimit.getName());
|
|
|
+ map1.put("limit", insuranceDefinitionLimit.getLimit());
|
|
|
+ map1.put("unit", insuranceDefinitionLimit.getUnit());
|
|
|
+ mapList.add(map1);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<InsurancePolicyMember> list = insurancePolicyMemberService.findByPolicyId(policyId);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
+
|
|
|
+ //设置编码 为了解决中文名称乱码问题
|
|
|
+ String fileName = "投保单电子版.pdf";
|
|
|
+ String downloadFileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
|
|
|
+
|
|
|
+ //将编码加到http头信息中
|
|
|
+ headers.setContentDispositionFormData("attachment", downloadFileName);
|
|
|
+
|
|
|
+ String folder=System.getProperty("java.io.tmpdir");
|
|
|
+
|
|
|
+ String filePath = folder + File.separator + DateTime.now().toString("yyyyMMddHHmmssSSS") + ".pdf";
|
|
|
+
|
|
|
+ ItextPDFUtil.createPdf(insuranceApplication, mapList, list, logoUrl,filePath);
|
|
|
+
|
|
|
+ byte[] buffer = FileUtil.readBytes(filePath);
|
|
|
+
|
|
|
+ entity = new ResponseEntity<byte[]>(buffer, headers, HttpStatus.OK);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ entity = new ResponseEntity<String>(ex.getMessage(),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+}
|