package com.jiayue.ipfcst.console.controller;

import com.jiayue.ipfcst.common.core.exception.BusinessException;
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.OverhaulPlanOne;
import com.jiayue.ipfcst.console.service.OverHaulPlanOneService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 检修计划信息restful接口
 *
 * @author tl
 * @version 3.0
 * @since 2020/03/27 10:12
 */
@RestController
@RequestMapping("overHaulPlanOne")
public class OverHaulOlanOneController {
  final private OverHaulPlanOneService overHaulPlanOneService;
  @Autowired
  public OverHaulOlanOneController(OverHaulPlanOneService overHaulPlanOneService){
    this.overHaulPlanOneService = overHaulPlanOneService;
  }
  /**
   * 新增 检修计划接口
   *
   * @param overhaulPlan
   * @return 操作结果
   */

  @PostMapping
  public ResponseVO insert(@RequestBody OverhaulPlanOne overhaulPlan){
    this.overHaulPlanOneService.add(overhaulPlan);
    return ResponseVO.success(1);
  }

  /**
   * 修改 检修计划接口
   */
  @PutMapping
  public ResponseVO update(@RequestBody OverhaulPlanOne overhaulPlan) throws BusinessException {
    this.overHaulPlanOneService.save(overhaulPlan);
    return ResponseVO.success(1);
  }

  /**
   * 删除 检修计划接口
   * @param overhaulPlan
   * @return 操作结果
   */
  @DeleteMapping
  public ResponseVO delete(@RequestBody OverhaulPlanOne overhaulPlan){
    this.overHaulPlanOneService.delete(overhaulPlan.getId());
    return ResponseVO.success(1);
  }

  /**
   * 获取 检修计划接口
   * @param page 页码
   * @param size 条数
   * @return 操作结果
   */
  @SneakyThrows
  @GetMapping(value = "/{page}/{size}")
  public ResponseVO get(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
    OverhaulPlanOne overhaulPlan = new OverhaulPlanOne();
    Page<OverhaulPlanOne> overhaulPlanCalendarPage = this.overHaulPlanOneService.get(overhaulPlan, page, size);
    return ResponseVO.success(overhaulPlanCalendarPage);
  }

  /**
   * 获取全部 检修计划接口
   * @return 操作结果
   */
  @SneakyThrows
  @GetMapping()
  public ResponseVO getAll() {
    List<OverhaulPlanOne> list = this.overHaulPlanOneService.getAll();
    return ResponseVO.success(list);
  }

  @GetMapping("/generateOverHaulPlanCodeContent")
  public ResponseVO generateOverHaulPlanCodeContent() throws IOException, BusinessException {
    List<String> list = this.overHaulPlanOneService.generateOverHaulPlanCodeContent();
    return ResponseVO.success(list);
  }

//
//  @GetMapping("/getAllOpGroup")
//  public ResponseVO get(){
//    List<OpGroup> allOpGroup = overHaulPlanService.getAllOpGroup();
//
//    return ResponseVO.success(allOpGroup);
//  }
//
//
//  @GetMapping("/getMaintenanceInformation")
//  public ResponseVO getMaintenanceInformation(){
//    return ResponseVO.success(overHaulPlanService.getMaintenanceInformation());
//  }


}
