package com.jeeplus.finance.contractRegistration.controller;

import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.finance.contractRegistration.domain.CwWorkContractBorrow;
import com.jeeplus.finance.contractRegistration.domain.CwWorkContractBorrowMessage;
import com.jeeplus.finance.contractRegistration.service.CwWorkContractBorrowService;
import com.jeeplus.finance.contractRegistration.service.dto.CwWorkContractBorrowDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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 = "/contract/workContractBorrow")
public class CwContractBorrowController {

    @Resource
    private CwWorkContractBorrowService borrowService;

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

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

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

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

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

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态借用表status")
    @PostMapping(value = "updateMessageStatusById")
    public void updateMessageStatusById(@RequestBody CwWorkContractBorrowDto 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<CwWorkContractBorrowMessage> findMessageList(@RequestParam String id) {
        return borrowService.findMessageList(id);
    }
}
