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

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.maintain.PipeMfRecordService;
import com.tofly.pojo.maintain.PipeMfRecord;
import com.tofly.pojo.maintain.Repairorder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 管网设施维护保养记录
 *
 * @author admin
 * @date Tue Oct 26 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/pipemfrecord")
@Api(tags = "管网设施维护保养记录接口")
@Slf4j
public class PipeMfRecordController {

    private final PipeMfRecordService pipeMfRecordService;

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param pipeMfRecord 管网设施维护保养记录
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getPipeMfRecordPage(Page page, @ModelAttribute PipeMfRecord pipeMfRecord) {
        return ResultRespone.success(pipeMfRecordService.getPage(page, pipeMfRecord));
    }


    /**
     * 通过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(pipeMfRecordService.getById(id));
    }

    /**
     * 新增管网设施维护保养记录
     *
     * @param pipeMfRecord 管网设施维护保养记录
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "新增管网设施维护保养记录")
    @ApiOperation(value = "新增管网设施维护保养记录")
    @PostMapping
    public ResultRespone save(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, PipeMfRecord pipeMfRecord) {
       log.info("管网设施维护保养记录新增记录: {}",pipeMfRecord.toString());
        ResultRespone<Object> rest = new ResultRespone<>();
        try {
            pipeMfRecordService.saveInfoPipeMfRecord(fileList, pipeMfRecord);
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
        }
        return rest;
    }

//    /**
//     * 修改管网设施维护保养记录
//     * @param pipeMfRecord 管网设施维护保养记录
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="修改管网设施维护保养记录" )
//    @ApiOperation(value = "修改管网设施维护保养记录")
//    @PutMapping
//    public ResultRespone updateById(@RequestBody PipeMfRecord pipeMfRecord) {
//      return ResultRespone.success(pipeMfRecordService.updateById(pipeMfRecord));
//    }


    /**
     * 通过id批量删除管网设施维护保养记录
     *
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id批量删除管网设施维护保养记录")
    @ApiOperation(value = "通过ID批量删除管网设施维护保养记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(pipeMfRecordService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
