BusinessDeclareAction.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package com.fuzamei.web;
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.net.URLEncoder;
  9. import java.util.ArrayList;
  10. import java.util.Iterator;
  11. import java.util.LinkedHashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.Set;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17. import javax.validation.ConstraintViolation;
  18. import javax.validation.Valid;
  19. import javax.validation.Validation;
  20. import javax.validation.Validator;
  21. import javax.validation.ValidatorFactory;
  22. import org.apache.commons.io.FileUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.http.HttpHeaders;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.MediaType;
  27. import org.springframework.http.ResponseEntity;
  28. import org.springframework.stereotype.Controller;
  29. import org.springframework.validation.BindingResult;
  30. import org.springframework.validation.FieldError;
  31. import org.springframework.validation.annotation.Validated;
  32. import org.springframework.web.bind.annotation.RequestBody;
  33. import org.springframework.web.bind.annotation.RequestMapping;
  34. import org.springframework.web.bind.annotation.RequestMethod;
  35. import org.springframework.web.bind.annotation.RequestParam;
  36. import org.springframework.web.bind.annotation.ResponseBody;
  37. import org.springframework.web.multipart.MultipartFile;
  38. import com.alibaba.fastjson.JSON;
  39. import com.fuzamei.constant.HintMSG;
  40. import com.fuzamei.constant.Role;
  41. import com.fuzamei.entity.BusinessCheck;
  42. import com.fuzamei.entity.UserDetail;
  43. import com.fuzamei.service.AttachmentService;
  44. import com.fuzamei.service.BusinessDeclareService;
  45. import com.fuzamei.service.UserAuthoricationService;
  46. import com.fuzamei.utils.JSONUtil;
  47. import com.fuzamei.utils.PageDTO;
  48. import com.fuzamei.utils.RelativePathUtil;
  49. import com.fuzamei.utils.ValidationUtil;
  50. @Controller
  51. @RequestMapping("/business_declare")
  52. public class BusinessDeclareAction {
  53. @Autowired
  54. private BusinessDeclareService businessDeclareService;
  55. @Autowired
  56. private UserAuthoricationService userAuthoricationService;
  57. @Autowired
  58. private AttachmentService attachmentService;
  59. private static final String SP=File.separator;
  60. private static final int ROW_NUM = 10; // 分页每页显示数据的数量
  61. /**
  62. *
  63. * @Title: uploadValuationPOIByBank
  64. * @Description: TODO(业务申报功能,需要完成【业务核准表】【尽职调查报告】【产品核准表】【基础性资料】4个文件的上传,插入业务申报表1条数据,插入附件表4条数据,还有插入操作历史1条数据)
  65. * 前段以【表单】的形式传过来一组数据:
  66. * businessApproval:对应业务核准表的文件
  67. * responsibleInvestigation:对应尽职调查报告文件
  68. * productApproval:产品核准表文件
  69. * basicData:基础性资料文件
  70. * businessName:业务名称
  71. * @param @param files
  72. * @param @param request
  73. * @param @param businessName 由经办行写入的业务名称,例如:嘉实活期基金
  74. * @param @return 设定文件
  75. * @return Map<String,Object> 返回类型
  76. * @author ylx
  77. * @date 2017年12月19日 上午11:23:27
  78. * @throws
  79. */
  80. @RequestMapping(value="/uploadBusinessMaterialsByBranchBank",method=RequestMethod.POST)
  81. @ResponseBody
  82. private Map<String, Object> uploadValuationPOIByBank(@RequestParam("businessApproval") MultipartFile file1,
  83. @RequestParam("responsibleInvestigation") MultipartFile file2,
  84. @RequestParam("productApproval") MultipartFile file3,
  85. @RequestParam("basicData") MultipartFile file4,
  86. HttpServletRequest request,
  87. @RequestParam("businessName") String businessName,
  88. @RequestParam("userId") Object uId) {
  89. try {
  90. //首先校验用户权限问题
  91. int userId=ValidationUtil.checkAndAssignInt(uId);
  92. UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.TRAN_BRANCH_BANK);//查看用户非空和权限(只有【经办支行】有这个权限操作)
  93. //首先保证文件不能为空
  94. if(file1.isEmpty()||file2.isEmpty()||file3.isEmpty()||file4.isEmpty()){
  95. throw new RuntimeException("上传文件不能为空");
  96. }
  97. String filename1 = file1.getOriginalFilename(); //业务核准表的文件名
  98. String filename2 = file2.getOriginalFilename(); //尽职调查表的文件名
  99. String filename3 = file3.getOriginalFilename(); //产品核准表的文件名
  100. String filename4 = file4.getOriginalFilename(); //基础资料的文件名
  101. //判断上传文件格式是否正确
  102. if(!(filename1.endsWith(".xls")||filename1.endsWith("xlsx"))&&
  103. !(filename2.endsWith(".xls")||filename2.endsWith("xlsx"))&&
  104. !(filename3.endsWith(".xls")||filename3.endsWith("xlsx"))&&
  105. !(filename4.endsWith(".xls")||filename4.endsWith("xlsx"))){
  106. throw new RuntimeException("上传文件格式不对");
  107. }
  108. //四个文件名不能有相同的两个文件名(暂时考虑是将四个文件放在一个文件夹下面)
  109. if(filename1.equals(filename2)||
  110. filename1.equals(filename3)||
  111. filename1.equals(filename4)||
  112. filename2.equals(filename3)||
  113. filename2.equals(filename4)||
  114. filename3.equals(filename4)){
  115. throw new RuntimeException("文件名不能相同");
  116. }
  117. //确定好上传的文件的顶级父级路径=======================================================================>>待定TODO
  118. String path = request.getServletContext().getRealPath(""); //SP是系统分隔符
  119. String relativePath = RelativePathUtil.formatPath("/"+userId, ""); //生成文件的相对保存路径
  120. Integer businessId=businessDeclareService.generateBusinessId(); //新创建的业务申报生成的不重复id号=============================>>生成id号的机制要改TODO
  121. String bank=userDetail.getOrganization_name(); //银行名称,但是表的字段是银行id?????。。。。。。。=======>>暂且按照当前用户的组织名进行录入TODO
  122. businessName=ValidationUtil.checkBlankAndAssignString(businessName); //校验前端传过来的业务名称并进行赋值
  123. String busineeApprovalName=filename1; //业务员核准表的文件名
  124. String urlOfBusineeApproval=relativePath+filename1; //业务核准表的url地址
  125. String responsibleInvestigationName=filename2; //尽职调查表的文件名
  126. String urlOfResponsibleInvestigation=relativePath+filename2; //尽职调查表的url地址
  127. String productApprovalName=filename3; //产品核准表的文件名
  128. String urlOfProductApproval=relativePath+filename3; //产品核准表的url地址
  129. String basicDataName=filename4; //基础性资料的文件名
  130. String urlOfBasicData=relativePath+filename4; //基础性资料的url地址
  131. //一次性返回4个不同的id号,且不会和数据库中的重复
  132. List<Integer> attachmentIds = attachmentService.generateMultiAttachmentIds(4);
  133. Integer busineeApprovalId=attachmentIds.get(0); //业务核准表的id号=====================================>>生成id号的机制要改TODO
  134. Integer responsibleInvestigationId=attachmentIds.get(1); //尽职调查表id号=====================================>>生成id号的机制要改TODO
  135. Integer productApprovalId=attachmentIds.get(2); //产品核准表的id号=====================================>>生成id号的机制要改TODO
  136. Integer basicDataId=attachmentIds.get(3); //基础性资料的id号=====================================>>生成id号的机制要改TODO
  137. //---------------------------------------------------------------------------------------------------------------
  138. //处理整个业务生报表的一些信息
  139. Map<String, Object> map =new LinkedHashMap<String, Object>(); //这个map用于存储所有要去service的数据
  140. map.put("userDetail", userDetail); //用户详细信息
  141. map.put("businessId", businessId); //将业务id活♥
  142. map.put("bank", bank); //先将申报的支行名字写活♥
  143. map.put("businessName", businessName); //业务名称
  144. //---------------------------------------------------------------------------------------------------------------
  145. //处理businessApproval(业务核准表)文件信息
  146. map.put("busineeApprovalId", busineeApprovalId); //将业务核准表的id写活
  147. map.put("busineeApprovalName",busineeApprovalName); //业务核准表名称,用于存在attachment中的附件名
  148. map.put("urlOfBusineeApproval", urlOfBusineeApproval); //文件下载相对路径url
  149. //---------------------------------------------------------------------------------------------------------------
  150. //处理responsibleInvestigation(尽职调查报告)文件信息
  151. map.put("responsibleInvestigationId", responsibleInvestigationId); //将尽职调查报告的id先写活♥
  152. map.put("responsibleInvestigationName",responsibleInvestigationName); //业务核准表名称,用于存在attachment中的附件名
  153. map.put("urlOfResponsibleInvestigation", urlOfResponsibleInvestigation); //文件下载相对路径url
  154. //---------------------------------------------------------------------------------------------------------------
  155. //处理productApproval(产品核准表)文件信息
  156. map.put("productApprovalId", productApprovalId); //将产品核准表的id先写活♥
  157. map.put("productApprovalName",productApprovalName); //业务核准表名称,用于存在attachment中的附件名
  158. map.put("urlOfProductApproval", urlOfProductApproval); //文件下载相对路径url
  159. //---------------------------------------------------------------------------------------------------------------
  160. //处理basicData(基础性资料)文件的上传功能
  161. map.put("basicDataId", basicDataId); //将业务核准表的id先写活♥
  162. map.put("basicDataName",basicDataName); //业务核准表名称,用于存在attachment中的附件名
  163. map.put("urlOfBasicData", urlOfBasicData); //文件下载相对路径url
  164. //---------------------------------------------------------------------------------------------------------------
  165. //将经办支行提交的所有数据信息通过map传入service层
  166. businessDeclareService.insertInformationIntoTableByBranchBank(map);
  167. //---------------------------------------------------------------------------------------------------------------
  168. String pathFile1=path+relativePath+filename1;
  169. String pathFile2=path+relativePath+filename2;
  170. String pathFile3=path+relativePath+filename3;
  171. String pathFile4=path+relativePath+filename4;
  172. File newFile1=new File(pathFile1);
  173. File newFile2=new File(pathFile2);
  174. File newFile3=new File(pathFile3);
  175. File newFile4=new File(pathFile4);
  176. //==============文件上传开始================
  177. //文件夹和文件最后进行创建和创建,不然一旦事物报错,这些文件就变成垃圾数据了
  178. File dir=new File(path+relativePath);
  179. if(!dir.exists()){
  180. dir.mkdirs();
  181. }
  182. file1.transferTo(newFile1);
  183. file2.transferTo(newFile2);
  184. file3.transferTo(newFile3);
  185. file4.transferTo(newFile4);
  186. //==============文件上传结束================
  187. return JSONUtil.getJsonMap(200, true, HintMSG.UPLOAD_SUCCESS,null); //返回给前端一个map进行前段提示
  188. } catch (Exception e) {
  189. return JSONUtil.getJsonMap(500, false, HintMSG.UPLOAD_FAIL+":"+e.getMessage(),null); //返回给前端一个map进行前段提示
  190. }
  191. }
  192. /**
  193. *
  194. * @Title: queryBusinessDeclareInformation
  195. * @Description: TODO(业务申报的查看,将所有信息返还给界面)
  196. * @param @param data
  197. * 前端传来的数据json格式为
  198. * {
  199. * "userId":XXX,
  200. * "businessName":"",
  201. * "page":"",
  202. * "startTime":"",
  203. * "endTime":""
  204. * }
  205. * @param @return 设定文件
  206. * @return Map<String,Object> 返回类型
  207. * @author ylx
  208. * @date 2017年12月19日 下午4:01:02
  209. * @authority: 经办支行,二级支行,省分行
  210. */
  211. @RequestMapping(value="/queryBusinessDeclareInformation",method=RequestMethod.POST)
  212. @ResponseBody
  213. private Map<String,Object> queryBusinessDeclareInformation(@RequestBody String data){
  214. try {
  215. System.out.println("查询业务申请信息....");
  216. @SuppressWarnings("unchecked")
  217. Map<String, Object> map = JSON.parseObject(data, Map.class); //将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
  218. //首先校验用户权限问题
  219. int userId=ValidationUtil.checkAndAssignInt(map.get("userId"));
  220. //查看用户非空和权限(只有【经办支行,二级支行和省分行】有这个权限操作)
  221. UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.TRAN_BRANCH_BANK,Role.SEC_BRANCH_BANK,Role.BUSINESS_DEP_OF_PBB);
  222. int page = ValidationUtil.checkMinAndAssignInt(map.get("page"), 1); // 默认页是第一页
  223. String businessName=ValidationUtil.checkBlankStringAndAssignEmptyIfIsBlank(map.get("businessName")); //业务名默认为空
  224. long startTime = ValidationUtil.checkAndAssignDefaultLong(map.get("startTime"), 0L); //开始时间默认0
  225. long endTime = ValidationUtil.checkAndAssignDefaultLong(map.get("endTime"), Long.MAX_VALUE); //结束时间默认Long最大值
  226. Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
  227. mapToService.put("userDetail", userDetail);
  228. mapToService.put("startPage", (page - 1) * ROW_NUM);
  229. mapToService.put("businessName", businessName);
  230. //如果时间顺序错位,要重新进行排位
  231. if (startTime <= endTime) {
  232. mapToService.put("startTime", startTime);
  233. mapToService.put("endTime", endTime);
  234. } else {
  235. mapToService.put("startTime", startTime);
  236. mapToService.put("endTime", Long.MAX_VALUE);
  237. }
  238. mapToService.put("rowNum", ROW_NUM); // 默认每页显示数据是10条,可根据需求修改分页数量
  239. PageDTO pageDto = businessDeclareService.queryBusinessDeclareInformation(map);
  240. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, pageDto);
  241. } catch (Exception e) {
  242. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  243. }
  244. }
  245. /**
  246. *
  247. * @Title: queryBusinessDeclareInformation
  248. * @Description: TODO(审核记录的查询,当用户点击查看按钮后,不仅显示了业务申报的信息,还显示了审核记录的信息,这里业务申报的信息直接从前端获取,审核记录根据前端提供的业务id号business_id来进行查询)
  249. * 这个信息要去业务审核总表中去查询
  250. * 前端传过来的json格式
  251. {
  252. "businessId":32323
  253. "userId":xxx
  254. }
  255. * @param @param data
  256. * @param @return 设定文件
  257. * @return Map<String,Object> 返回类型
  258. * @author ylx
  259. * @date 2017年12月19日 下午7:46:44
  260. * @authority: 经办支行,二级支行,省分行
  261. */
  262. @RequestMapping(value="/queryBusinessCheckInformation",method=RequestMethod.POST)
  263. @ResponseBody
  264. private Map<String,Object> queryBusinessCheckInformation(@RequestBody String data){
  265. try {
  266. System.out.println("查询业务审核总表信息....");
  267. @SuppressWarnings("unchecked")
  268. Map<String, Object> map = JSON.parseObject(data, Map.class); //将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
  269. //首先校验用户权限问题
  270. int userId=ValidationUtil.checkAndAssignInt(map.get("userId"));
  271. //查看用户非空和权限(只有【经办支行,二级支行和省分行】有这个权限操作)
  272. UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.TRAN_BRANCH_BANK,Role.SEC_BRANCH_BANK,Role.BUSINESS_DEP_OF_PBB);
  273. Integer businessId=ValidationUtil.checkAndAssignInt(map.get("businessId")); //被审核的业务id号需要先被进行校验
  274. Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
  275. mapToService.put("userDetail", userDetail);
  276. mapToService.put("businessId", businessId);
  277. List<BusinessCheck> businessCheckList = businessDeclareService.queryBusinessCheckInformation(mapToService);
  278. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, businessCheckList);
  279. } catch (Exception e) {
  280. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  281. }
  282. }
  283. /**
  284. *
  285. * @Title: businessDeclareCheckedBy
  286. * @Description: TODO(审核意见的提交)
  287. * @param @param data
  288. * 数据json包含
  289. * {
  290. * "checkResult":结果(同意5或者不同意6---数字以状态表为准),
  291. * "checkOpinion":审核意见,
  292. * "businessId":业务id,
  293. * "userId":XXX
  294. * }
  295. * @param @return 设定文件
  296. * @return Map<String,Object> 返回类型
  297. * @author ylx
  298. * @date 2017年12月19日 下午8:52:35
  299. * @throws
  300. */
  301. @RequestMapping(value="/businessDeclareCheckedBy",method=RequestMethod.POST)
  302. @ResponseBody
  303. private Map<String,Object> businessDeclareCheckedBy(@RequestBody String data){
  304. try {
  305. System.out.println("添加到业务审核总表信息....");
  306. @SuppressWarnings("unchecked")
  307. Map<String, Object> map = JSON.parseObject(data, Map.class); //将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
  308. //首先校验用户权限问题
  309. int userId=ValidationUtil.checkAndAssignInt(map.get("userId"));
  310. //查看用户非空和权限(只有【二级支行和省分行】有这个权限操作)
  311. UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.SEC_BRANCH_BANK,Role.BUSINESS_DEP_OF_PBB);
  312. //审核结果进行校验并赋值
  313. Integer checkResult = ValidationUtil.checkAndAssignInt(map.get("checkResult"));
  314. if(!(checkResult==5||checkResult==6)){
  315. throw new RuntimeException("审核结果参数非法");
  316. }
  317. //审核意见进行校验并赋值
  318. String checkOpinion = ValidationUtil.checkBlankAndAssignString(map.get("checkOpinion"));
  319. //被审核的业务id号需要先被进行校验
  320. Integer businessId=ValidationUtil.checkAndAssignInt(map.get("businessId"));
  321. Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
  322. mapToService.put("userDetail", userDetail);
  323. mapToService.put("checkResult", checkResult);
  324. mapToService.put("checkOpinion", checkOpinion);
  325. mapToService.put("businessId", businessId);
  326. businessDeclareService.businessDeclareCheckedBy(mapToService);
  327. return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null);
  328. } catch (Exception e) {
  329. return JSONUtil.getJsonMap(500, false, HintMSG.OPERATION_FAIL+":"+e.getMessage(), null);
  330. }
  331. }
  332. /**
  333. *
  334. * @Title: uploadContractByProvincialBranchBank
  335. * @Description: TODO(省分行业务部门上传合同的功能实现)
  336. * 前端需要传递过来的数据(以表单形式)有以下几个:contract:合同文件
  337. * businessId:业务id号
  338. *
  339. *
  340. * @param @param file
  341. * @param @param request
  342. * @param @param businessId
  343. * @param @return 设定文件
  344. * @return Map<String,Object> 返回类型
  345. * @author ylx
  346. * @date 2017年12月20日 下午4:21:51
  347. * @throws
  348. */
  349. @RequestMapping(value="/uploadContractByProvincialBranchBank",method=RequestMethod.POST)
  350. @ResponseBody
  351. private Map<String, Object> uploadContractByProvincialBranchBank(@RequestParam("contract") MultipartFile file,
  352. HttpServletRequest request,
  353. @RequestParam("businessId") Object bId,
  354. @RequestParam("userId") Object uId) {
  355. try {
  356. //首先校验用户权限问题
  357. int userId=ValidationUtil.checkAndAssignInt(uId);
  358. UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.BUSINESS_DEP_OF_PBB);//查看用户非空和权限(只有【经办支行】有这个权限操作)
  359. //首先保证文件不能为空
  360. if(file.isEmpty()){
  361. throw new RuntimeException("上传文件不能为空");
  362. }
  363. //合同文件名
  364. String filename = file.getOriginalFilename();
  365. //判断上传文件格式是否正确
  366. if(!(filename.endsWith(".xls")||filename.endsWith("xlsx"))){
  367. throw new RuntimeException("上传文件格式不对");
  368. }
  369. //确定好上传的文件的顶级父级路径=======================================================================>>待定TODO
  370. String path = request.getServletContext().getRealPath(""); //SP是系统分隔符
  371. String relativePath = RelativePathUtil.formatPath("/"+userId, ""); //生成文件的相对保存路径
  372. Integer businessId = ValidationUtil.checkAndAssignInt(bId); //校验业务id并赋值
  373. Integer attachmentId = attachmentService.generateAtachmentId(); //生成不重复的附件id号
  374. Map<String, Object> mapToService =new LinkedHashMap<String, Object>(); //这个map用于存储所有要去service的数据
  375. mapToService.put("businessId", businessId); //将业务id先写死,到时候还要再进行修改。。。。。TODO
  376. mapToService.put("contractParty", "建行省分行&信托公司"); //合同的签约方。。。TODO。。。。【这里先写死,可能通过上传的合同文件获取签约方的信息】
  377. // mapToService.put("uploadDepartment", userDetail.getOrganization_name()); //上传部门按照组织名来写
  378. // mapToService.put("uploadPerson", userDetail.getPerson_name()); //上传人员写活♥
  379. mapToService.put("contractId", attachmentId); //将合同的id写活♥
  380. mapToService.put("contractName",filename); //合同名称,用于存在attachment中的附件名
  381. mapToService.put("url", relativePath+filename); //将文件下载路径url通过map传到service层进行校验
  382. mapToService.put("hash", "to be calculated"); //文件hash值先写死,到时候需要从服务器上的文件获取
  383. mapToService.put("userDetail", userDetail); //直接将用户详细信息传到service层
  384. businessDeclareService.uploadContractByProvincialBranchBank(mapToService); //将合同信息插入到【合同提交记录表contract_record、合同状态跟踪表contract_status_tracking、附件表attachment】
  385. String pathFile=path+relativePath+filename;
  386. File newFile = new File(pathFile);
  387. //==========文件上传开始============
  388. File dir=new File(path+relativePath);
  389. if(!dir.exists()){
  390. dir.mkdirs();
  391. }
  392. file.transferTo(newFile); //将---合同---文件上传到指定的文件夹下
  393. //==========文件上传结束============
  394. return JSONUtil.getJsonMap(200, true, HintMSG.UPLOAD_SUCCESS, null);
  395. }catch (Exception e) {
  396. return JSONUtil.getJsonMap(500, false, HintMSG.UPLOAD_FAIL+":"+e.getMessage(), null);
  397. }
  398. }
  399. /**
  400. * @Title: download
  401. * @Description: TODO(实现所有上传的文件的下载功能)=====>>仅局限于业务审核表,尽职调查表,产品核准表和基础性资料这4个文件的下载
  402. * 前段以【表单】的形式传过来一组数据:
  403. * @param url:下载地址
  404. * userId:用户id号
  405. * @param @return 设定文件
  406. * @return Map<String,Object> 返回类型
  407. * @author ylx
  408. * @date 2017年12月21日 下午2:05:13
  409. * @throws
  410. */
  411. @RequestMapping(value="/downloadBusinessDeclareFiles")
  412. @ResponseBody
  413. private Map<String, Object> downloadBusinessDeclareFiles(HttpServletRequest request,HttpServletResponse response,
  414. @RequestParam("url") String url,
  415. @RequestParam("userId") Object uId) {
  416. try {
  417. int userId=ValidationUtil.checkAndAssignInt(uId);
  418. userAuthoricationService.checkUserAuthority(userId,Role.TRAN_BRANCH_BANK,Role.SEC_BRANCH_BANK,Role.BUSINESS_DEP_OF_PBB); //查看用户非空和权限(经办支行,二级分行,省分行都有这个权限操作)
  419. url=ValidationUtil.checkBlankAndAssignString(url); //对传过来的url进行非空校验
  420. String fileName = request.getServletContext().getRealPath("")+url; //SP是系统分隔符
  421. //如果文件不存在直接抛出异常
  422. if(!new File(fileName).exists()){
  423. throw new RuntimeException(HintMSG.FILE_NOT_FOUND);
  424. }
  425. InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));
  426. String filename = url.substring(url.lastIndexOf("/")+1); //截取文件名
  427. filename = URLEncoder.encode(filename,"UTF-8");
  428. response.addHeader("Content-Disposition", "attachment;filename=" + filename);
  429. response.setContentType("multipart/form-data");
  430. BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
  431. int len = 0;
  432. while((len = bis.read()) != -1){
  433. out.write(len);
  434. out.flush();
  435. }
  436. out.close();
  437. bis.close();
  438. return JSONUtil.getJsonMap(200, true, HintMSG.DOWNLOAD_SUCCESS, null); //返回给前端一个map进行前段提示
  439. } catch (Exception e) {
  440. return JSONUtil.getJsonMap(500, false, HintMSG.DOWNLOAD_FAIL+":"+e.getMessage(), null); //返回给前端一个map进行前段提示
  441. }
  442. }
  443. /**
  444. * @Title: download
  445. * @Description: TODO(实现托管合同的下载功能)=====>>仅局限于托管合同这1个文件的下载
  446. * 前段以【表单】的形式传过来一组数据:
  447. * @param url:下载地址
  448. * userId:用户id号
  449. * @param @return 设定文件
  450. * @return Map<String,Object> 返回类型
  451. * @author ylx
  452. * @date 2017年12月21日 下午2:05:13
  453. * @throws
  454. */
  455. @RequestMapping(value="/downloadContractFiles")
  456. @ResponseBody
  457. private Map<String, Object> downloadContractFiles(HttpServletRequest request,HttpServletResponse response,
  458. @RequestParam("url") String url,
  459. @RequestParam("userId") Object uId) {
  460. try {
  461. int userId=ValidationUtil.checkAndAssignInt(uId);
  462. userAuthoricationService.checkUserAuthority(userId,Role.BUSINESS_DEP_OF_PBB); //查看用户非空和权限(在业务申报的模块中只有省分行才有权限下载这个合同)
  463. url=ValidationUtil.checkBlankAndAssignString(url); //对传过来的url进行非空校验
  464. String fileName = request.getServletContext().getRealPath("")+url; //SP是系统分隔符
  465. //如果文件不存在直接抛出异常
  466. if(!new File(fileName).exists()){
  467. throw new RuntimeException(HintMSG.FILE_NOT_FOUND);
  468. }
  469. InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));
  470. String filename = url.substring(url.lastIndexOf("/")+1); //截取文件名
  471. filename = URLEncoder.encode(filename,"UTF-8");
  472. response.addHeader("Content-Disposition", "attachment;filename=" + filename);
  473. response.setContentType("multipart/form-data");
  474. BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
  475. int len = 0;
  476. while((len = bis.read()) != -1){
  477. out.write(len);
  478. out.flush();
  479. }
  480. out.close();
  481. bis.close();
  482. return JSONUtil.getJsonMap(200, true, HintMSG.DOWNLOAD_SUCCESS, null); //返回给前端一个map进行前段提示
  483. } catch (Exception e) {
  484. return JSONUtil.getJsonMap(500, false, HintMSG.DOWNLOAD_FAIL+":"+e.getMessage(), null); //返回给前端一个map进行前段提示
  485. }
  486. }
  487. @RequestMapping(value="/test")
  488. @ResponseBody
  489. public Map<String, Object> test(@RequestBody String data){
  490. try {
  491. List<Integer> generateMultiAttachmentIds = attachmentService.generateMultiAttachmentIds(4);
  492. return JSONUtil.getJsonMap(200, true, "成功",generateMultiAttachmentIds);
  493. } catch (Exception e) {
  494. return JSONUtil.getJsonMap(200, true, "失败:"+e.getMessage(),null);
  495. }
  496. }
  497. /**
  498. * 上传文件功能模块
  499. * @param files
  500. * @param request
  501. * @return
  502. * @throws IllegalStateException
  503. * @throws IOException
  504. */
  505. /*
  506. @RequestMapping(value="/upload",method=RequestMethod.POST)
  507. @ResponseBody
  508. public String upload(@RequestParam("file") MultipartFile[] files,HttpServletRequest request) throws IllegalStateException, IOException{
  509. String path = request.getSession().getServletContext().getRealPath("content");
  510. File dir=new File(path);
  511. if(!dir.exists()){
  512. dir.mkdirs();
  513. }
  514. for (MultipartFile file : files) {
  515. String filename = file.getOriginalFilename();
  516. String pathFile=path+"/"+filename;
  517. File newFile=new File(pathFile);
  518. file.transferTo(newFile);
  519. }
  520. return "upload success";
  521. }
  522. */
  523. /**
  524. * 文件下载功能
  525. * @param request
  526. * @param response
  527. * @throws IOException
  528. */
  529. /*
  530. @RequestMapping(value="/download")
  531. public void download(HttpServletRequest request,HttpServletResponse response) throws IOException{
  532. String fileName = request.getSession().getServletContext().getRealPath("content")+"/"+"demo.sql";
  533. InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));
  534. String filename = "下载文件.jpg";
  535. filename = URLEncoder.encode(filename,"UTF-8");
  536. response.addHeader("Content-Disposition", "attachment;filename=" + filename);
  537. response.setContentType("multipart/form-data");
  538. BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
  539. int len = 0;
  540. while((len = bis.read()) != -1){
  541. out.write(len);
  542. out.flush();
  543. }
  544. out.close();
  545. bis.close();
  546. }
  547. */
  548. /**
  549. *
  550. * @Title: download
  551. * @Description: TODO(文件下载的另一种方法)
  552. * @param @param request
  553. * @param @return
  554. * @param @throws IOException 设定文件
  555. * @return ResponseEntity<byte[]> 返回类型
  556. * @author ylx
  557. * @date 2017年12月19日 上午10:21:33
  558. * @throws
  559. */
  560. /*
  561. @RequestMapping(value = "/download2",produces = "application/octet-stream;charset=UTF-8")
  562. public ResponseEntity<byte[]> download(HttpServletRequest request) throws IOException {
  563. // 指定文件,必须是绝对路径
  564. File file = new File(request.getSession().getServletContext().getRealPath("content")+"/"+"demo.sql");
  565. // 下载浏览器响应的那个文件名
  566. String dfileName = URLEncoder.encode("下载文件.jpg","UTF-8");;
  567. // 下面开始设置HttpHeaders,使得浏览器响应下载
  568. HttpHeaders headers = new HttpHeaders();
  569. // 设置响应方式
  570. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  571. // 设置响应文件
  572. headers.setContentDispositionFormData("attachment", dfileName);
  573. // 把文件以二进制形式写回
  574. return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
  575. }
  576. */
  577. }