package com.dayou.controller;

import com.dayou.dto.TaskRecordDTO;
import com.dayou.vo.BusinessProductionPerformanceVO;
import com.dayou.workflow.annotation.FinishTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IBusinessProductionPerformanceService;
import com.dayou.entity.BusinessProductionPerformance;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 业务产品绩效分配
 *
 * @author wucl
 * @since 2023-11-07
 */
@RestController
@RequestMapping("businessProductionPerformance")
@Slf4j
public class BusinessProductionPerformanceController extends BaseController {
    @Autowired
    private IBusinessProductionPerformanceService businessProductionPerformanceService;

    /**
    * 业务产品绩效分配列表
    */
    @GetMapping("")
    public RestResponse<Page<BusinessProductionPerformance>> page(BusinessProductionPerformance businessProductionPerformance, Page page){
        Page<BusinessProductionPerformance> pages=businessProductionPerformanceService.selectPage(page,businessProductionPerformance);
        return RestResponse.data(pages);
    }

    /**
     * 业务产品绩效分配详情
     */
    @GetMapping("/detail")
    public RestResponse<BusinessProductionPerformanceVO> detail(BusinessProductionPerformanceVO performance){
        BusinessProductionPerformanceVO businessProductionPerformanceVO =businessProductionPerformanceService.getDetail(performance);
        return RestResponse.data(businessProductionPerformanceVO);
     }

    /**
     * 业务产品绩效分配新增
     */
    @FinishTask
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody @Valid TaskRecordDTO<BusinessProductionPerformance> taskRecordDTO) {
        Boolean ret = businessProductionPerformanceService.add(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 业务产品绩效分配更新
     */
    @FinishTask
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody TaskRecordDTO<BusinessProductionPerformance> taskRecordDTO) {
        Boolean ret = businessProductionPerformanceService.update(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 业务产品绩效分配删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = businessProductionPerformanceService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 根据业务类型,产品id及checkLoop获取质检信息
     * @param dto 查询条件
     * @return RestResponse<BusinessProductionPerformance>
     */
    @GetMapping("/getProductionPerformance")
    public RestResponse<BusinessProductionPerformance> getProductionPerformance(BusinessProductionPerformance dto) {
        return RestResponse.data(businessProductionPerformanceService.getProductionPerformance(dto));
    }


}

