package com.dayou.controller;

import com.dayou.dto.MajorTargetMergeNumberDTO;
import com.dayou.dto.TakeNumberDTO;
import com.dayou.dto.TaskRecordDTO;
import com.dayou.service.IMajorTargetService;
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 org.springframework.web.bind.annotation.RestController;
import com.dayou.entity.MajorTarget;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 大中型项目评估对象
 *
 * @author wucl
 * @since 2023-11-03
 */
@RestController
@RequestMapping("majorTarget")
@Slf4j
public class MajorTargetController extends BaseController {
    @Autowired
    private IMajorTargetService majorTargetService;

    /**
    * 大中型项目评估对象列表
    */
    @GetMapping("/list")
    public RestResponse<List<MajorTarget>> getList(MajorTarget majorTarget){
        List<MajorTarget> pages=majorTargetService.getList(majorTarget);
        return RestResponse.data(pages);
    }

    /**
     * 大中型项目评估对象详情
     */
    @GetMapping("/{id}")
    public RestResponse<MajorTarget> detail(@PathVariable Long id){
        MajorTarget xMajorTarget =majorTargetService.detail(id);
        return RestResponse.data(xMajorTarget);
     }

    /**
     * 大中型项目评估对象新增
     */
    @FinishTask
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody @Valid TaskRecordDTO<MajorTarget> majorTarget) {
        Boolean ret = majorTargetService.add(majorTarget);
        return RestResponse.data(ret);
    }

    /**
     * 大中型项目评估对象更新
     */
    @FinishTask
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody @Valid TaskRecordDTO<MajorTarget> majorTarget) {
        Boolean ret = majorTargetService.update(majorTarget);
        return RestResponse.data(ret);
    }

    /**
     * 大中型项目评估对象删除
     */
    @FinishTask
    @PutMapping("/delete")
    public RestResponse<Boolean> delete(@RequestBody @Valid TaskRecordDTO<Long> majorTarget) {
        Boolean ret = majorTargetService.delete(majorTarget);
        return RestResponse.data(ret);
    }

    /**
     * 初步定价/审核报价
     * @return
     */
    @FinishTask
    @PutMapping("/doTask")
    public RestResponse<Boolean> doTask(@RequestBody @Valid TaskRecordDTO<MajorTarget> taskRecordDTO){
        MajorTarget taskData = taskRecordDTO.getTaskData();
        Boolean ret = majorTargetService.xUpdate(taskData);
        return RestResponse.data(ret);
    }

    /**
     * 业务取号
     * @param takeNumberDTO
     * @return
     */
    @PostMapping("/takeNumber")
    public RestResponse<String>  takeNumber(@RequestBody @Valid TakeNumberDTO takeNumberDTO){
        String ret = majorTargetService.takeNumber(takeNumberDTO);
        return RestResponse.data(ret);
    }

    /**
     * 估价对象合并到已取的号中
     * @param mergeDTO
     * @return
     */
    @PostMapping("/merge")
    public RestResponse<Boolean> mergeNumber(@RequestBody @Valid MajorTargetMergeNumberDTO mergeDTO){
        Boolean ret =majorTargetService.mergeNumber(mergeDTO);
        return RestResponse.data(ret);
    }
}

