/*
 * Author: Zev
 * 生成controller
 */
package com.tofly.gpsboot.controller.plan.daily;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.pojo.plan.dto.PlanchildDto;

import com.tofly.pojo.plan.Planchild;

import com.tofly.gpsboot.service.paln.task.PlanchildService;

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;

/**
 * 巡检子计划信息
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/planchild")
@Api(tags = "巡检子计划信息")
public class PlanchildController {

    @Autowired
    private PlanchildService service;


    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询巡检子计划信息")
    public ResultRespone<Page<Planchild>> getPlanchildPage(Page page, @ModelAttribute PlanchildDto parDto) {
        return ResultRespone.success(service.page(page, new QueryWrapper<Planchild>().lambda().setEntity(JSON.parseObject(JSON.toJSONString(parDto), Planchild.class))));
    }

    @ApiOperation(value = "新增基本信息对象")
    @PostMapping("/save")
    @ToFlyAppLog(title = "新增巡检子计划信息")
    public ResultRespone<Object> savePlanchild(@Valid @RequestBody PlanchildDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        rest.setResult(service.save(JSON.parseObject(JSON.toJSONString(parDto), Planchild.class)));
        return rest;

    }

    @ApiOperation(value = "修改基本信息")
    @PutMapping("/updata")
    @ToFlyAppLog(title = "修改巡检子计划信息")
    public ResultRespone<Object> updateByIdPlanchild(@Valid @RequestBody PlanchildDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        boolean b = service.updateById(JSON.parseObject(JSON.toJSONString(parDto), Planchild.class));
        rest.setResult(b);
        return rest;

    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过ID查询巡检子计划信息")
    public ResultRespone<Planchild> getByIdPlanchild(@PathVariable Long id) {
        return ResultRespone.success(service.getById(id));
    }


    @ApiOperation(value = "通过ID批量删除基本信息对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    @ToFlyAppLog(title = "通过ID批量删除巡检子计划信息")
    public ResultRespone<Object> removeByIdListPlanchild(String ids) {
        return ResultRespone.success(service.removeById(ids));
    }

}
