package com.jeeplus.finance.projectReportArchive.controller;

import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.finance.projectReportArchive.domain.CwProjectReportBorrow;
import com.jeeplus.finance.projectReportArchive.domain.CwProjectReportBorrowMessage;
import com.jeeplus.finance.projectReportArchive.service.CwProjectReportBorrowService;
import com.jeeplus.finance.projectReportArchive.service.dto.CwProjectReportBorrowDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 王强
 * @create: 2022-11-27 13:50
 **/
@Api(tags ="财务-报告借用")
@RestController
@RequestMapping(value = "/project/report/borrow")
public class CwProjectReportBorrowController {

    @Resource
    private CwProjectReportBorrowService borrowService;

    /**
     * 合同登记新增/修改
     */
    @ApiOperation(value = "报告借用新增/修改")
    @PostMapping(value = "save")
    public ResponseEntity<String> save(@RequestBody CwProjectReportBorrowDto workContractBorrowDto) throws Exception{
        String id = borrowService.saveInfo(workContractBorrowDto);
        return ResponseUtil.newInstance().add("businessTable", "cw_project_report_borrow").add("businessId", id).ok ("操作成功");
    }

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusById")
    public void updateStatusById(@RequestBody CwProjectReportBorrowDto workContractBorrowDto) {
        borrowService.updateStatusById(workContractBorrowDto);
    }

    /**
     * 根据contractInfoId修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusByContractInfoId")
    public void updateStatusByContractInfoId(@RequestBody CwProjectReportBorrowDto workContractBorrowDto) {
        borrowService.updateStatusByContractInfoId(workContractBorrowDto);
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "findById")
    public CwProjectReportBorrow findById(@RequestParam String id) {
        return borrowService.findById(id);
    }

    /**
     * 根据contractInfoId查询
     */
    @ApiOperation(value = "根据contractInfoId查询")
    @GetMapping(value = "findByContractInfoId")
    public CwProjectReportBorrow findByContractInfoId(@RequestParam String id) {
        return borrowService.findByContractInfoId(id);
    }

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态借用表status")
    @PostMapping(value = "updateMessageStatusById")
    public void updateMessageStatusById(@RequestBody CwProjectReportBorrowDto workContractBorrowDto) {
        borrowService.updateMessageByBorrowId(workContractBorrowDto, workContractBorrowDto.getType());
    }

    @ApiOperation(value = "根据id删除借用表信息")
    @GetMapping(value = "deleteById")
    public void deleteById(@RequestParam String id) {
        borrowService.deleteById(id);
    }

    @ApiOperation(value = "根据id查询借用表信息")
    @GetMapping(value = "findMessageList")
    public List<CwProjectReportBorrowMessage> findMessageList(@RequestParam String id) {
        return borrowService.findMessageList(id);
    }
}
