package common.controller;


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

//DMP 收入管理
@RestController
@RequestMapping("dmp/income")
public class DmpIncomeController {

    @Autowired
    DmpIncomeService dmpIncomeService;


    @GetMapping("/list/bycode")
    public ResultModel listByContract(String code) {
        //按合同查询
        return ResultModel.OK(dmpIncomeService.listByCode(code));
    }

    @GetMapping("/list/byds")
    public ResultModel listByDs(String start, String end) {
        //按日期范围查询
        return ResultModel.OK(dmpIncomeService.listByDs(start, end));
    }

    @PostMapping("/update")
    public ResultModel updateItem(@RequestBody DmpIncome dmpIncome) {
        //更新数据
        return ResultModel.OK(dmpIncomeService.update(dmpIncome));
    }

    @PostMapping("/delete")
    public ResultModel deleteItem(Long id) {
        //删除数据
        return ResultModel.OK(dmpIncomeService.delete(id));
    }


    @PostMapping("/upload")
    public ResultModel uploadList(@RequestParam("file") MultipartFile file, @CurrentAccount User loginAccount) {
        //上传收入数据
        return dmpIncomeService.uploadFile(file, "dmp", loginAccount);
    }


}
