/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.gpsboot.controller.maintain;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;

import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.gpsboot.controller.BaseController;
import com.tofly.pojo.maintain.dto.RepairplandetailDto;
import com.tofly.pojo.maintain.dto.RepairplandetailSaveDto;
import com.tofly.pojo.maintain.vo.RepairplandetailVo;

import com.tofly.gpsboot.service.maintain.RepairplandetailService;
import com.tofly.pojo.maintain.Repairplandetail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

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

/**
 * 抢维修月计划内容信息表
 *
 * @author admin
 * @date Tue Apr 06 00:00:00 CST 2021
 */
//@RestController
//@RequestMapping("/repairplandetail")
//@Api(tags="抢维修月计划内容信息表接口")
public class RepairplandetailController extends BaseController<Repairplandetail, RepairplandetailVo> {

    @Autowired
    private RepairplandetailService service;

    @Autowired
    public RepairplandetailController(RepairplandetailService service) {
        init(service);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询抢维修月计划内容")
    public ResultRespone<Page<RepairplandetailVo>> getRepairplandetailPage(Page page, @ModelAttribute RepairplandetailDto parDto) {
        return ResultRespone.success(service.getRepairPlanPage(page, parDto));
    }

    @ApiOperation(value = "新增基本信息对象")
    @PostMapping("/save")
    @ToFlyAppLog(title = "新增抢维修月计划内容")
    public ResultRespone<Object> saveRepairplandetail(@Valid @RequestBody RepairplandetailSaveDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        List<RepairplandetailDto> dtoList = parDto.getDtoList();
        if(null!=dtoList && dtoList.size()>0){
            dtoList.forEach(info->{
                Repairplandetail repairplandetail = JSON.parseObject(JSON.toJSONString(info), Repairplandetail.class);
                super.save(repairplandetail);
            });
        }

        return rest;

    }

    @ApiOperation(value = "修改基本信息")
    @PutMapping("/updata")
    @ToFlyAppLog(title = "修改抢月计划内容")
    public ResultRespone<Object> updateByIdRepairplandetail(@Valid @RequestBody RepairplandetailDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        return Optional.ofNullable(super.validRest(rest, result)).orElseGet(() -> super.updateById(JSON.parseObject(JSON.toJSONString(parDto), Repairplandetail.class)));

    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过ID查询抢维修月计划内容")
    public ResultRespone<Repairplandetail> getByIdRepairplandetail(@PathVariable Long id) {
        return super.getById(id);
    }



    @ApiOperation(value = "通过ID批量删除基本信息对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    @ToFlyAppLog(title = "通过ID批量删除抢维修月计划内容")
    public ResultRespone<Object> removeByIdListRepairplandetail(String ids) {
        return super.removeByIdList(ids);
    }


}
