AttachmnetUploadController.java 2.15 KB
Newer Older
kangxiaoshan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
package common.controller;


import common.model.DmpIncome;
import common.model.PdAttachment;
import common.model.User;
import common.service.DmpIncomeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import security.annotation.CurrentAccount;
import util.ResultModel;

@Controller
@RequestMapping("{platform}")
public class AttachmnetUploadController {

    @Autowired
    DmpIncomeService dmpIncomeService;

    //上传附件
    @PostMapping("/upload/attachment")
    @ResponseBody
    public ResultModel uploadAttach(@RequestParam("file") MultipartFile[] files, String contractCode, @CurrentAccount User user) {

        String erroNames = "";
        for (MultipartFile file : files) {
            PdAttachment attachment = dmpIncomeService.uploadPdAttach(file, contractCode, user);
            if (attachment.getFaild()) {
                erroNames += " " + attachment.getFileOrginName();
            }
        }

        if (!StringUtils.isEmpty(erroNames)) {
            return ResultModel.ERROR(5001, "文件:" + erroNames + "上传失败");
        }

        return ResultModel.OK();
    }

    //下载附加
    @RequestMapping(value = "/download/attachment/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public ResponseEntity<byte[]> getDownloadResponseEntity(@PathVariable Long id) {
        return dmpIncomeService.downloadAttach(id);
    }

    //删除附件
    @PostMapping("/delete/attachment/{id}")
    @ResponseBody
    public ResultModel deleteAttach(@PathVariable Long id) {
        return ResultModel.OK(dmpIncomeService.deleteAttach(id));
    }


    //附件列表
    @GetMapping("/list/attachment")
    @ResponseBody
    public ResultModel attachList(String code,String startDate,String endDate, @PathVariable String platform) {
        return dmpIncomeService.attachList(code,startDate,endDate, platform);
    }
}