package common.controller;


import common.model.PdIncome;
import common.model.User;
import common.service.DmpIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import security.annotation.CurrentAccount;
import util.ResultModel;

//私有化项目管理
@RestController
@RequestMapping("pd")
public class PdController {
    @Autowired
    DmpIncomeService dmpIncomeService;


    //收入记录
    @GetMapping("/income/list/bycode")
    public ResultModel listByContract(String code) {
        //按合同查询
        return ResultModel.OK(dmpIncomeService.listpdIncomeByCode(code));
    }

    //录入收入
    @PostMapping("/income/save")
    public ResultModel create(@RequestBody PdIncome income, @CurrentAccount User account) {
        //按合同查询
        return ResultModel.OK(dmpIncomeService.pdCreate(income, account));
    }

    //更新
    @PostMapping("/income/update")
    public ResultModel update(@RequestBody PdIncome income, @CurrentAccount User account) {
        //按合同查询
        return ResultModel.OK(dmpIncomeService.pdUpdate(income));
    }

    //删除
    @PostMapping("/income/delete")
    public ResultModel delete(@RequestBody PdIncome income) {
        //按合同查询
        return ResultModel.OK(dmpIncomeService.pdDelete(income));
    }

    ////上传附件
    //@PostMapping("/upload/attachment")
    //public ResultModel uploadAttach(@RequestParam("file") MultipartFile file, String contractCode, @CurrentAccount User user) {
    //
    //    return ResultModel.OK(dmpIncomeService.uploadPdAttach(file, contractCode, user));
    //}
    //
    ////下载附加
    //@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/load/attachment/{id}")
    //public ResultModel deleteAttach(@PathVariable Long id) {
    //    return ResultModel.OK(dmpIncomeService.deleteAttach(id));
    //}

}
