|
@@ -1,6 +1,12 @@
|
|
|
package com.jpsoft.picc.modules.auth.controller;
|
|
|
|
|
|
-import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.jpsoft.picc.config.CasConfig;
|
|
|
+import com.jpsoft.picc.modules.base.entity.Company;
|
|
|
+import com.jpsoft.picc.modules.base.entity.CompanyMember;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyMemberService;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyMemberService;
|
|
|
import com.jpsoft.picc.modules.common.config.OSSConfig;
|
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.picc.modules.common.utils.OSSUtil;
|
|
@@ -9,22 +15,46 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jasig.cas.client.authentication.AttributePrincipal;
|
|
|
+import org.omg.CORBA.Environment;
|
|
|
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 org.springframework.http.MediaType;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Api(description="附件管理")
|
|
|
-@RestController
|
|
|
+@Controller
|
|
|
@RequestMapping("/auth/attachment")
|
|
|
@Slf4j
|
|
|
public class AttachmentController {
|
|
|
@Autowired
|
|
|
private OSSConfig ossConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CasConfig casConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyMemberService insurancePolicyMemberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyMemberService companyMemberService;
|
|
|
+
|
|
|
@PostMapping("upload")
|
|
|
@ApiOperation(value="附件上传")
|
|
|
+ @ResponseBody
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "fileName",value = "文件名", required = false, paramType = "form"),
|
|
|
@ApiImplicitParam(name = "subFolder",value = "子目录名(如/test)", required = false, paramType = "form"),
|
|
@@ -52,4 +82,68 @@ public class AttachmentController {
|
|
|
|
|
|
return messageResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="身份证附件打包下载")
|
|
|
+ @RequestMapping(value = "downloadIdCardZip",method = RequestMethod.GET)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="policyId",value = "每月投保单ID",required = true,paramType = "query")
|
|
|
+ })
|
|
|
+ public void downloadIdCardZip(String policyId, HttpServletRequest request,HttpServletResponse response){
|
|
|
+ try {
|
|
|
+ Long lastDownloadIdCardTime = (Long)request.getSession().getAttribute("lastDownloadIdCardTime");
|
|
|
+
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+
|
|
|
+ if (lastDownloadIdCardTime!=null && (System.currentTimeMillis() - lastDownloadIdCardTime)<5000){
|
|
|
+ response.setContentType("text/html; charset=UTF-8");
|
|
|
+ response.getWriter().println("下载过于频繁,请稍后再试!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 + "?x-oss-process=image/resize,l_1024,limit_1");
|
|
|
+ map.put("fileName", member.getCardNo() + "-" + (i+1) + ext);
|
|
|
+
|
|
|
+ fileList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
+
|
|
|
+ OSSUtil.batchDownload(fileList,output);
|
|
|
+
|
|
|
+ output.flush();
|
|
|
+ output.close();
|
|
|
+
|
|
|
+ request.getSession().setAttribute("lastDownloadIdCardTime",System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|