package com.jeeplus.test.workContract.controller;

import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.test.workContract.domain.WorkContractBorrow;
import com.jeeplus.test.workContract.domain.WorkContractBorrowMessage;
import com.jeeplus.test.workContract.service.dto.WorkContractBorrowDto;
import com.jeeplus.test.workContract.service.WorkContractBorrowService;
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;

@Slf4j
@Api(tags ="合同登记")
@RestController
@RequestMapping(value = "/workContract/workContractBorrow")
public class WorkContractBorrowController {

    @Resource
    private WorkContractBorrowService workContractBorrowService;

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

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

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

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

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

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

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

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