/*
 * 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.RepairmaterialDto;
import com.tofly.pojo.maintain.vo.RepairmaterialVo;

import com.tofly.gpsboot.service.maintain.RepairmaterialService;

import com.tofly.pojo.maintain.Repairmaterial;

import com.tofly.pojo.maintain.vo.RepairtypeVo;
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.Optional;

/**
 * 维修材料类型信息表
 *
 * @author admin
 * @date Tue Apr 06 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/repairmaterial")
@Api(tags = "维修材料类型信息表接口")
public class RepairmaterialController extends BaseController<Repairmaterial, RepairmaterialVo> {

    @Autowired
    private RepairmaterialService service;

    @Autowired
    public RepairmaterialController(RepairmaterialService service) {
        init(service);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询维修材料类型信息")
    public ResultRespone<Page<RepairmaterialVo>> getRepairmaterialPage(Page page, @ModelAttribute RepairmaterialDto parDto) {
        ResultRespone<Page<RepairmaterialVo>> rest = new ResultRespone<>();
        Page<RepairmaterialVo> buildPage = service.getRepairMaterialPage(page, parDto);
        rest.setResult(buildPage);
        return rest;
    }

    @ApiOperation(value = "新增基本信息对象")
    @PostMapping("/save")
    @ToFlyAppLog(title = "新增维修材料类型信息")
    public ResultRespone<Object> saveRepairmaterial(@Valid @RequestBody RepairmaterialDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        return Optional.ofNullable(super.validRest(rest, result)).orElseGet(() -> super.save(JSON.parseObject(JSON.toJSONString(parDto), Repairmaterial.class)));

    }

    @ApiOperation(value = "修改基本信息")
    @PutMapping("/updata")
    @ToFlyAppLog(title = "修改维修材料类型信息")
    public ResultRespone<Object> updateByIdRepairmaterial(@Valid @RequestBody RepairmaterialDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        return Optional.ofNullable(super.validRest(rest, result)).orElseGet(() -> super.updateById(JSON.parseObject(JSON.toJSONString(parDto), Repairmaterial.class)));

    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过ID查询维修材料类型信息")
    public ResultRespone<Repairmaterial> getByIdRepairmaterial(@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> removeByIdListRepairmaterial(String ids) {
        return super.removeByIdList(ids);
    }

}
