package com.bonus.material.lossAssessment.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.lossAssessment.service.LossAssessmentService;
import com.bonus.material.repair.domain.RepairPartDetails;
import com.bonus.material.repair.domain.RepairTask;
import com.bonus.material.repair.domain.RepairTaskDetails;
import com.bonus.material.repair.domain.vo.RepairDeviceSummaryVo;
import com.bonus.material.repair.domain.vo.RepairDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * @author hay
 */
@RestController
@RequestMapping("/lossAssessment")
@Api(tags = "定损管理")
public class LossAssessmentController extends BaseController {

    @Resource
    private LossAssessmentService service;

    /**
     * 获取定损任务列表
     */
    @ApiOperation(value = "获取定损任务列表")
    @GetMapping("/getLossAssessmentList")
    public AjaxResult getLossAssessmentList(RepairTask bean) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<RepairTask> list = service.getLossAssessmentList(bean);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 定损详情列表
     */
    @ApiOperation(value = "定损详情列表")
    @GetMapping("/getLossAssessmentDetailsList")
    public AjaxResult getLossAssessmentDetailsList(RepairTaskDetails bean) {
        List<RepairDeviceSummaryVo> list = service.getLossAssessmentDetailsList(bean);
        return AjaxResult.success(list);
    }

    /**
     * 获取详情的详情
     * @param bean
     * @return
     */
    @ApiOperation(value = "获取详情的详情")
    @GetMapping("/getDetailsListApp")
    public TableDataInfo getDetailsListApp(RepairPartDetails bean) {
        startPage();
        List<RepairPartDetails> list = service.getDetailsListApp(bean);
        return getDataTable(list);
    }

    /**
     * 定损完成
     */
    @ApiOperation(value = "定损完成")
    @PostMapping("/batchLossAssessmentApply")
    public AjaxResult batchLossAssessmentApply(@RequestBody @NotNull List<RepairDeviceVO> list) {
        return service.batchLossAssessmentApply(list);
    }

    /**
     * 定损取消，推至维修
     */
    @ApiOperation(value = "定损取消，推至维修")
    @PostMapping("/gotoRepair")
    public AjaxResult gotoRepair(@RequestBody RepairDeviceVO bean) {
        return service.gotoRepair(bean);
    }

    /**
     * 提交任务到维修
     */
    @ApiOperation(value = "提交任务到维修")
    @PostMapping("/endLossAssessmentTask")
    public AjaxResult endLossAssessmentTask(@RequestBody ArrayList<RepairTask> taskList) {
        return service.endLossAssessmentTask(taskList);
    }

    /**
     * 驳回退料--批量
     */
    @ApiOperation(value = "驳回退料--批量")
    @PostMapping("/reject")
    public AjaxResult rejectRepair(@RequestBody RepairTask bean) {
        return service.rejectRepair(bean);
    }

}
