package com.cpp.web.controller.overhaulPlan;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.web.domain.overhaulplan.OverhaulPlan;
import com.cpp.web.service.overhaulplan.OverhaulPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/overhaulplan")
@Api(value = "overhaulplan", tags = "cpp_overhaul_plan管理")
public class OverhaulPlanController {

    private final OverhaulPlanService overhaulPlanService;

    @ApiOperation(value = "分页查询所有", notes = "分页查询")
    @GetMapping("/getList")
    public R getList(Long currentPage,Long pageSize) {
        Page page = new Page(currentPage, pageSize);
        page.setMaxLimit((long) -1);
        System.out.println(overhaulPlanService.page(page, overhaulPlanService.getList()));
        return R.ok(overhaulPlanService.page(page, overhaulPlanService.getList()));
    }


    @ApiOperation(value = "新增检修计划信息", notes = "新增检修计划信息")
    @PostMapping("/save")
    public R save(@RequestBody OverhaulPlan overhaulPlan) {
        return R.ok(overhaulPlanService.save(overhaulPlan));
    }


    @ApiOperation(value = "修改检修计划信息", notes = "修改检修计划信息")
    @PostMapping("/updateById")
    public R updateById(@RequestBody OverhaulPlan overhaulPlan) {
        return R.ok(overhaulPlanService.updateById(overhaulPlan));
    }


    @ApiOperation(value = "删除检修计划", notes = "删除检修计划")
    @PostMapping("/remove")
    public R removeById(@RequestBody OverhaulPlan overhaulPlan) {
        return R.ok(overhaulPlanService.removeById(overhaulPlan.getId()));
    }


    /**
     * @param stationCode
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "通过场站编号查询检修计划（分页查询）", notes = "通过场站编号查询检修计划（分页查询）")
    @GetMapping("/stationCode")
    public R getByStationCode( String stationCode,Long currentPage,Long pageSize,Integer status) {
        Page page = new Page(currentPage,pageSize);
        page.setMaxLimit((long)-1);
        return R.ok(overhaulPlanService.page(page,overhaulPlanService.getByStationCode(stationCode,status)));
    }

    @ApiOperation(value = "通过场站编号查询检修计划", notes = "通过场站编号查询检修计划")
    @GetMapping("/stationCode/noPage")
    public R findByStationCode( String stationCode) {
        return R.ok(overhaulPlanService.findByStationCode(stationCode));
    }

    @ApiOperation(value = "修改检修计划信息", notes = "修改检修计划信息")
    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody OverhaulPlan overhaulPlan) {
        overhaulPlan.setStatus(2);
        overhaulPlan.setMcTime(new Date());
        return R.ok(overhaulPlanService.updateById(overhaulPlan));
    }
}
