|
@@ -0,0 +1,135 @@
|
|
|
+package com.bosshand.virgo.file.controller;
|
|
|
+
|
|
|
+import com.bosshand.virgo.core.response.Response;
|
|
|
+import com.bosshand.virgo.exception.BadRequestException;
|
|
|
+import com.bosshand.virgo.exception.Constant;
|
|
|
+import com.bosshand.virgo.file.model.WorkarkContract;
|
|
|
+import com.bosshand.virgo.file.service.WorkarkContractService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+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 javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping({"workarkContract"})
|
|
|
+@Api(tags = {"WORKARK合同"})
|
|
|
+public class WorkarkContractController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WorkarkContractService workarkContractService;
|
|
|
+
|
|
|
+ @ApiOperation("下载原合同文件")
|
|
|
+ @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
|
|
|
+ public void getFile(@PathVariable int id, final HttpServletResponse response) throws Exception {
|
|
|
+ byte[] data = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ WorkarkContract workarkContract = workarkContractService.get(id);
|
|
|
+ data = workarkContractService.getByte(id);
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/x-msdownload");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(workarkContract.getName(), "UTF-8"));
|
|
|
+ OutputStream outputSream = response.getOutputStream();
|
|
|
+ outputSream.write(data);
|
|
|
+ outputSream.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BadRequestException("Fail to write stream", Constant.RET_DOCUMENT_ERROR, e);
|
|
|
+ } finally {
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("展示合同PDF")
|
|
|
+ @RequestMapping(value = "/pdf/{id}", method = RequestMethod.GET)
|
|
|
+ public void getPDF(@PathVariable long id, final HttpServletResponse response) {
|
|
|
+ byte[] data = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ data = workarkContractService.getPDF(id);
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/x-msdownload");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("合同.PDF", "UTF-8"));
|
|
|
+ OutputStream outputSream = response.getOutputStream();
|
|
|
+ outputSream.write(data);
|
|
|
+ outputSream.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BadRequestException("Fail to write stream", Constant.RET_DOCUMENT_ERROR, e);
|
|
|
+ } finally {
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("合同列表")
|
|
|
+ @RequestMapping(value = "/{organizationId}", method = RequestMethod.GET)
|
|
|
+ public Response getFile(@PathVariable long organizationId) {
|
|
|
+ return Response.ok(workarkContractService.getList(organizationId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("上传合同")
|
|
|
+ @RequestMapping(value = "/{organizationId}", method = RequestMethod.POST)
|
|
|
+ public Response uploadFile(@ApiParam(name = "uploadFile", required = true) MultipartFile uploadFile, @PathVariable long organizationId) {
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = uploadFile.getInputStream();
|
|
|
+ return Response.ok(workarkContractService.create(inputStream, uploadFile.getOriginalFilename(), organizationId));
|
|
|
+ } catch (IOException e) {
|
|
|
+ return Response.fail(Constant.CODE_BAD_REQUEST, Constant.RET_INPUT_ERROR);
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("删除合同")
|
|
|
+ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
|
|
+ public Response deleteFile(@PathVariable long id) {
|
|
|
+ workarkContractService.delete(id);
|
|
|
+ return Response.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("更新合同")
|
|
|
+ @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
|
|
+ public Response updateFile(@ApiParam(name = "uploadFile", required = true) MultipartFile uploadFile, @PathVariable long id) {
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = uploadFile.getInputStream();
|
|
|
+ return Response.ok(workarkContractService.update(inputStream, uploadFile.getOriginalFilename(), id));
|
|
|
+ } catch (IOException e) {
|
|
|
+ return Response.fail(Constant.CODE_BAD_REQUEST, Constant.RET_INPUT_ERROR);
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|