package com.fjhx.sale.controller.serviceContract;

import com.fjhx.sale.enums.ServiceContractEnum;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.sale.entity.serviceContract.vo.ServiceContractVo;
import com.fjhx.sale.entity.serviceContract.dto.ServiceContractSelectDto;
import com.fjhx.sale.entity.serviceContract.dto.ServiceContractDto;
import com.ruoyi.common.core.domain.BaseSelectDto;
import com.fjhx.sale.service.serviceContract.ServiceContractService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;


/**
 * <p>
 * 服务合同表 前端控制器
 * </p>
 *
 * @author
 * @since 2023-04-18
 */
@RestController
@RequestMapping("/serviceContract")
public class ServiceContractController {

    @Autowired
    private ServiceContractService serviceContractService;

    /**
     * 服务合同表分页
     */
    @PostMapping("/page")
    public Page<ServiceContractVo> page(@RequestBody ServiceContractSelectDto dto) {
        return serviceContractService.getPage(dto);
    }

    /**
     * 服务合同表明细
     */
    @PostMapping("/detail")
    public ServiceContractVo detail(@RequestBody BaseSelectDto dto) {
        return serviceContractService.detail(dto.getId());
    }

    /**
     * 作废功能（修改合同的状态为作废）
     */
    @PostMapping("/cancel")
    public void cancel(@RequestBody ServiceContractDto serviceContractDto){
        serviceContractDto.setStatus(ServiceContractEnum.CANCEL.getKey());
        serviceContractService.updateById(serviceContractDto);
    }

    /**
     * 服务合同统计（根据归属公司）
     */
    @PostMapping("/serviceContractStatistics")
    public Map<String, Object> serviceContractStatistics(@RequestBody ServiceContractDto serviceContractDto){
        return serviceContractService.serviceContractStatistics(serviceContractDto);
    }


}
