| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package com.chinaitop.depot.business.controller;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- 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.multipart.MultipartFile;
- import com.chinaitop.depot.business.model.BusinessFile;
- import com.chinaitop.depot.business.model.BusinessFileExample;
- import com.chinaitop.depot.business.model.BusinessFileExample.Criteria;
- import com.chinaitop.depot.business.service.BusinessFileService;
- import com.fasterxml.jackson.core.JsonParseException;
- import com.fasterxml.jackson.databind.JsonMappingException;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- /**
- * 粮库业务管理-文件
- * <p>Title: BusinessFileController</p>
- *
- */
- @RestController
- @RequestMapping(value="/depot/business/file")
- @Api(value= "BusinessFileController", description = "文件")
- public class BusinessFileController {
- @Autowired
- private BusinessFileService businessFileService;
-
- /**
- * 删除.
- * @param id
- * @return
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @RequestMapping(value="/remove", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
- @ApiOperation(value="删除", notes = "根据id删除")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "id", paramType = "form")
- })
- public Map<String, Object> remove(Integer id, HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException {
- Map<String, Object> modelMap = new HashMap<String, Object>();
- // 服务器路径
- String rootPath = request.getSession().getServletContext().getRealPath("");
- if (id != null) {
- businessFileService.remove(id, rootPath);
- }
- modelMap.put("status", "success");
- return modelMap;
- }
-
-
- @RequestMapping(value="/uploadFile")
- public BusinessFile uploadFile(MultipartFile file, String type, Integer bid, Integer userId,Integer orgId,HttpServletRequest request) throws IllegalStateException, IOException {
- BusinessFile businessFile = businessFileService.uploadFile(file,type,bid, userId, orgId);
- return businessFile;
- }
- @RequestMapping(value="/updateFile", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
- @ApiOperation(value="修改数据", notes = "修改数据保存的文件数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "fileIds", value = "文件ID集合", paramType = "form"),
- @ApiImplicitParam(name = "bid", value = "主键id", paramType = "form")
- })
- public void updateFile(String fileIds, String bid, String fileType){
- businessFileService.updateFileByFileIdsAndBid(fileIds,bid,fileType);
- }
- @RequestMapping(value="/getList", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
- @ApiOperation(value="按条件查询附件数据", notes = "按条件查询附件数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "bid", value = "主表id", paramType = "query"),
- @ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query"),
- @ApiImplicitParam(name = "order", value = "排序方式", paramType = "query"),
- @ApiImplicitParam(name = "orgId", value = "单位id", paramType = "query")
- })
- public List<BusinessFile> getList(Integer bid, String fileType, String order, Integer orgId){
- List<BusinessFile> list = null;
-
- list = businessFileService.getByBid(bid, fileType, orgId, order);
- return list;
- }
-
- @RequestMapping(value="/addChangeFile", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST)
- @ApiOperation(value="合同变更时,增加附件", notes = "合同变更时,增加附件")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "bid", value = "主表id", paramType = "query"),
- @ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query"),
- @ApiImplicitParam(name = "orgId", value = "单位id", paramType = "query")
- })
- public List<Integer> addChangeFile(Integer bid, String fileType,Integer orgId){
-
- //根据合同的id查询原来合同的附件信息
- List<BusinessFile> list = businessFileService.getByBid(bid, fileType, orgId, null);
- List<Integer> idList = new ArrayList<Integer>();
- for (int i = 0; i < list.size(); i++) {
- BusinessFile file = new BusinessFile();
- file.setType(list.get(i).getType());
- file.setFileName(list.get(i).getFileName());
- file.setOriginalFileName(list.get(i).getOriginalFileName());
- file.setFilePath(list.get(i).getFilePath());
- file.setCreateTime(list.get(i).getCreateTime());
- file.setCreater(list.get(i).getCreater());
- file.setOrgId(list.get(i).getOrgId());
- Integer contractChangeId = businessFileService.save(file);
- idList.add(contractChangeId);
- }
- return idList;
-
- }
-
-
- @RequestMapping(value="/getListByIds", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
- @ApiOperation(value="按条件查询附件数据", notes = "按条件查询附件数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "主键id", paramType = "query"),
-
- })
- public List<BusinessFile> getListByIds(String ids){
- List<BusinessFile> fileList = null;
- if(null != ids && "" != ids && ids.length()>0){
- if (ids.contains("[]")) {
- // 去除开头结尾.
- ids = ids.substring(1, ids.length());
- ids = ids.substring(0, ids.length() - 1);
- }
- String[] idArray = ids.split(",");
- List<Integer> idList = new ArrayList<Integer>();
- if(idArray.length>0 && idArray!=null){
- for (String id : idArray) {
- id = id.replaceAll("\\p{P}", "");
- idList.add(Integer.parseInt(id));
- }
- }
- BusinessFileExample example = new BusinessFileExample();
- Criteria createCriteria = example.createCriteria();
- createCriteria.andIdIn(idList);
- fileList= businessFileService.selectByExample(example);
- }
-
- return fileList;
- }
- }
|