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

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.exception.BusinessException;
import com.tofly.gpsboot.service.paln.PlanMtService;
import com.tofly.pojo.plan.PlanMt;
import com.tofly.pojo.plan.Planpoint;
import lombok.AllArgsConstructor;
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 org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 计划维护记录表
 *
 * @author admin
 * @date Tue Jan 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/planmt")
@Api(tags = "计划维护记录表接口")
public class PlanMtController {

    private final PlanMtService planMtService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param planMt 计划维护记录表
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getPlanMtPage(Page page, @ModelAttribute PlanMt planMt) {
        return ResultRespone.success(planMtService.page(page, Wrappers.query(planMt)));
    }


    /**
     * 通过id查询计划维护记录表
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
    })
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(planMtService.getById(id));
    }

    /**
     * 新增计划维护记录表
     *
     * @param planMt 计划维护记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "新增计划维护记录表")
    @ApiOperation(value = "新增计划维护记录表")
    @PostMapping
    public ResultRespone<Boolean> save(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, PlanMt planMt) {
        ResultRespone<Boolean> rest = new ResultRespone<>();

        try {
            boolean b = planMtService.saveInfo(fileList, planMt);
            rest.setResult(b);
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
        }

        return rest;
    }

    /**
     * 修改计划维护记录表
     *
     * @param planMt 计划维护记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "修改计划维护记录表")
    @ApiOperation(value = "修改计划维护记录表")
    @PutMapping
    public ResultRespone updateById(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, PlanMt planMt) {
        ResultRespone<Boolean> rest = new ResultRespone<>();

        try {
            boolean b = planMtService.updateInfo(fileList, planMt);
            rest.setResult(b);
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
        }

        return rest;
    }

}
