BusinessFileController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.chinaitop.depot.business.controller;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.servlet.http.HttpServletRequest;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.http.MediaType;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import com.chinaitop.depot.business.model.BusinessFile;
  15. import com.chinaitop.depot.business.model.BusinessFileExample;
  16. import com.chinaitop.depot.business.model.BusinessFileExample.Criteria;
  17. import com.chinaitop.depot.business.service.BusinessFileService;
  18. import com.fasterxml.jackson.core.JsonParseException;
  19. import com.fasterxml.jackson.databind.JsonMappingException;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiImplicitParam;
  22. import io.swagger.annotations.ApiImplicitParams;
  23. import io.swagger.annotations.ApiOperation;
  24. /**
  25. * 粮库业务管理-文件
  26. * <p>Title: BusinessFileController</p>
  27. *
  28. */
  29. @RestController
  30. @RequestMapping(value="/depot/business/file")
  31. @Api(value= "BusinessFileController", description = "文件")
  32. public class BusinessFileController {
  33. @Autowired
  34. private BusinessFileService businessFileService;
  35. /**
  36. * 删除.
  37. * @param id
  38. * @return
  39. * @throws JsonParseException
  40. * @throws JsonMappingException
  41. * @throws IOException
  42. */
  43. @RequestMapping(value="/remove", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
  44. @ApiOperation(value="删除", notes = "根据id删除")
  45. @ApiImplicitParams({
  46. @ApiImplicitParam(name = "id", value = "id", paramType = "form")
  47. })
  48. public Map<String, Object> remove(Integer id, HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException {
  49. Map<String, Object> modelMap = new HashMap<String, Object>();
  50. // 服务器路径
  51. String rootPath = request.getSession().getServletContext().getRealPath("");
  52. if (id != null) {
  53. businessFileService.remove(id, rootPath);
  54. }
  55. modelMap.put("status", "success");
  56. return modelMap;
  57. }
  58. @RequestMapping(value="/uploadFile")
  59. public BusinessFile uploadFile(MultipartFile file, String type, Integer bid, Integer userId,Integer orgId,HttpServletRequest request) throws IllegalStateException, IOException {
  60. BusinessFile businessFile = businessFileService.uploadFile(file,type,bid, userId, orgId);
  61. return businessFile;
  62. }
  63. @RequestMapping(value="/updateFile", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
  64. @ApiOperation(value="修改数据", notes = "修改数据保存的文件数据")
  65. @ApiImplicitParams({
  66. @ApiImplicitParam(name = "fileIds", value = "文件ID集合", paramType = "form"),
  67. @ApiImplicitParam(name = "bid", value = "主键id", paramType = "form")
  68. })
  69. public void updateFile(String fileIds, String bid, String fileType){
  70. businessFileService.updateFileByFileIdsAndBid(fileIds,bid,fileType);
  71. }
  72. @RequestMapping(value="/getList", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
  73. @ApiOperation(value="按条件查询附件数据", notes = "按条件查询附件数据")
  74. @ApiImplicitParams({
  75. @ApiImplicitParam(name = "bid", value = "主表id", paramType = "query"),
  76. @ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query"),
  77. @ApiImplicitParam(name = "order", value = "排序方式", paramType = "query"),
  78. @ApiImplicitParam(name = "orgId", value = "单位id", paramType = "query")
  79. })
  80. public List<BusinessFile> getList(Integer bid, String fileType, String order, Integer orgId){
  81. List<BusinessFile> list = null;
  82. list = businessFileService.getByBid(bid, fileType, orgId, order);
  83. return list;
  84. }
  85. @RequestMapping(value="/addChangeFile", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
  86. @ApiOperation(value="合同变更时,增加附件", notes = "合同变更时,增加附件")
  87. @ApiImplicitParams({
  88. @ApiImplicitParam(name = "bid", value = "主表id", paramType = "query"),
  89. @ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query"),
  90. @ApiImplicitParam(name = "orgId", value = "单位id", paramType = "query")
  91. })
  92. public List<Integer> addChangeFile(Integer bid, String fileType,Integer orgId){
  93. //根据合同的id查询原来合同的附件信息
  94. List<BusinessFile> list = businessFileService.getByBid(bid, fileType, orgId, null);
  95. List<Integer> idList = new ArrayList<Integer>();
  96. for (int i = 0; i < list.size(); i++) {
  97. BusinessFile file = new BusinessFile();
  98. file.setType(list.get(i).getType());
  99. file.setFileName(list.get(i).getFileName());
  100. file.setOriginalFileName(list.get(i).getOriginalFileName());
  101. file.setFilePath(list.get(i).getFilePath());
  102. file.setCreateTime(list.get(i).getCreateTime());
  103. file.setCreater(list.get(i).getCreater());
  104. file.setOrgId(list.get(i).getOrgId());
  105. Integer contractChangeId = businessFileService.save(file);
  106. idList.add(contractChangeId);
  107. }
  108. return idList;
  109. }
  110. @RequestMapping(value="/getListByIds", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
  111. @ApiOperation(value="按条件查询附件数据", notes = "按条件查询附件数据")
  112. @ApiImplicitParams({
  113. @ApiImplicitParam(name = "id", value = "主键id", paramType = "query"),
  114. })
  115. public List<BusinessFile> getListByIds(String ids){
  116. List<BusinessFile> fileList = null;
  117. if(null != ids && "" != ids && ids.length()>0){
  118. if (ids.contains("[]")) {
  119. // 去除开头结尾.
  120. ids = ids.substring(1, ids.length());
  121. ids = ids.substring(0, ids.length() - 1);
  122. }
  123. String[] idArray = ids.split(",");
  124. List<Integer> idList = new ArrayList<Integer>();
  125. if(idArray.length>0 && idArray!=null){
  126. for (String id : idArray) {
  127. id = id.replaceAll("\\p{P}", "");
  128. idList.add(Integer.parseInt(id));
  129. }
  130. }
  131. BusinessFileExample example = new BusinessFileExample();
  132. Criteria createCriteria = example.createCriteria();
  133. createCriteria.andIdIn(idList);
  134. fileList= businessFileService.selectByExample(example);
  135. }
  136. return fileList;
  137. }
  138. }