|
@@ -1,29 +1,75 @@
|
|
package com.jpsoft.picc.modules.base.controller;
|
|
package com.jpsoft.picc.modules.base.controller;
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import com.jpsoft.picc.modules.base.entity.Company;
|
|
|
|
+import com.jpsoft.picc.modules.base.entity.CompanyMember;
|
|
|
|
+import com.jpsoft.picc.modules.base.entity.InsuranceDefinitionLimit;
|
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyMemberService;
|
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
|
+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.OSSConfig;
|
|
import com.jpsoft.picc.modules.common.config.OSSConfig;
|
|
|
|
+import com.jpsoft.picc.modules.common.config.PdfConfig;
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
-import com.jpsoft.picc.modules.common.utils.Uploader;
|
|
|
|
|
|
+import com.jpsoft.picc.modules.common.utils.ItextPDFUtil;
|
|
|
|
+import com.jpsoft.picc.modules.common.utils.OSSUtil;
|
|
|
|
+import com.jpsoft.picc.modules.common.utils.Watermark;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.joda.time.DateTime;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
@Api(description="附件管理")
|
|
@Api(description="附件管理")
|
|
-@RestController
|
|
|
|
-@RequestMapping("/base/attachment")
|
|
|
|
|
|
+@Controller
|
|
@Slf4j
|
|
@Slf4j
|
|
public class AttachmentController {
|
|
public class AttachmentController {
|
|
@Autowired
|
|
@Autowired
|
|
private OSSConfig ossConfig;
|
|
private OSSConfig ossConfig;
|
|
|
|
|
|
- @PostMapping("upload")
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PdfConfig pdfConfig;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private InsuranceApplicationService insuranceApplicationService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private InsuranceDefinitionLimitService insuranceDefinitionLimitService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private InsurancePolicyMemberService insurancePolicyMemberService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyService companyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyMemberService companyMemberService;
|
|
|
|
+
|
|
|
|
+ @PostMapping("/base/attachment/upload")
|
|
@ApiOperation(value="附件上传")
|
|
@ApiOperation(value="附件上传")
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParam(name = "fileName",value = "文件名", required = false, paramType = "form"),
|
|
@ApiImplicitParam(name = "fileName",value = "文件名", required = false, paramType = "form"),
|
|
@@ -38,7 +84,7 @@ public class AttachmentController {
|
|
fileName = uploadFile.getOriginalFilename();
|
|
fileName = uploadFile.getOriginalFilename();
|
|
}
|
|
}
|
|
|
|
|
|
- String retFileUrl = Uploader.ossUpload(ossConfig,subFolder,fileName,uploadFile.getInputStream());
|
|
|
|
|
|
+ String retFileUrl = OSSUtil.upload(ossConfig,subFolder,fileName,uploadFile.getInputStream());
|
|
|
|
|
|
messageResult.setResult(true);
|
|
messageResult.setResult(true);
|
|
messageResult.setData(retFileUrl);
|
|
messageResult.setData(retFileUrl);
|
|
@@ -52,4 +98,122 @@ public class AttachmentController {
|
|
|
|
|
|
return messageResult;
|
|
return messageResult;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="pdf文档生成与下载")
|
|
|
|
+ @RequestMapping(value = "/pub/attachment/downloadPolicyPDF",method = RequestMethod.GET)
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name="applicationId",value = "投保单ID",required = true,paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name="policyId",value = "每月投保单ID",required = true,paramType = "query")
|
|
|
|
+ })
|
|
|
|
+ public ResponseEntity downloadPolicyPDF(String applicationId, String policyId){
|
|
|
|
+ String logoUrl = pdfConfig.getLogoUrl();
|
|
|
|
+ ResponseEntity entity;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ InsuranceApplication insuranceApplication = insuranceApplicationService.get(applicationId);
|
|
|
|
+ Company company = companyService.get(insuranceApplication.getCompanyId());
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ String outputPath = folder + File.separator + DateTime.now().toString("yyyyMMddHHmmssSSS") + "-watermark.pdf";
|
|
|
|
+
|
|
|
|
+ //pdf文档添加图片水印
|
|
|
|
+ if (StringUtils.isNotEmpty(company.getCompanyStampFile())) {
|
|
|
|
+ Watermark.imageWatermark(filePath, outputPath, company.getCompanyStampFile());
|
|
|
|
+ filePath = outputPath;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="身份证附件打包下载")
|
|
|
|
+ @RequestMapping(value = "/pub/attachment/downloadIdCardZip",method = RequestMethod.GET)
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name="policyId",value = "每月投保单ID",required = true,paramType = "query")
|
|
|
|
+ })
|
|
|
|
+ public void downloadIdCardZip(String policyId, HttpServletResponse response){
|
|
|
|
+ try {
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
+
|
|
|
|
+ //设置编码 为了解决中文名称乱码问题
|
|
|
|
+ String fileName = "身份证";
|
|
|
|
+ String zipFileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=" + zipFileName + ".zip");
|
|
|
|
+
|
|
|
|
+ List<InsurancePolicyMember> policyMemberList = insurancePolicyMemberService.findByPolicyId(policyId);
|
|
|
|
+
|
|
|
|
+ List<Map<String,String>> fileList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (InsurancePolicyMember policyMember : policyMemberList) {
|
|
|
|
+ CompanyMember member = companyMemberService.get(policyMember.getMemberId());
|
|
|
|
+
|
|
|
|
+ String urls = member.getCardFiles();
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(urls)){
|
|
|
|
+ String[] arr = urls.split("\\|");
|
|
|
|
+
|
|
|
|
+ for(int i=0;i<arr.length;i++) {
|
|
|
|
+ String url = arr[i];
|
|
|
|
+
|
|
|
|
+ String ext = url.substring(url.lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
|
+ map.put("fileUrl",url);
|
|
|
|
+ map.put("fileName", member.getCardNo() + "-" + (i+1) + ext);
|
|
|
|
+
|
|
|
|
+ fileList.add(map);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
|
+
|
|
|
|
+ OSSUtil.batchDownload(fileList,output);
|
|
|
|
+
|
|
|
|
+ output.flush();
|
|
|
|
+ output.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex){
|
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|