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

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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.xrtygis.entity.TfWaterInfo;
import com.tofly.xrtygis.service.TfWaterInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 水厂信息表
 *
 * @author admin
 * @date Fri Mar 11 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfwaterinfo")
@Api(tags="水厂信息表接口")
public class TfWaterInfoController {

    private final  TfWaterInfoService tfWaterInfoService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfWaterInfo 水厂信息表
    * @return
    */
    @GetMapping("/page" )
    @ToFlyAppLog(title="分页查询" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfWaterInfoPage(Page page, @ModelAttribute TfWaterInfo tfWaterInfo) {
        try{
            return ResultRespone.success(tfWaterInfoService.page(page, Wrappers.query(tfWaterInfo)
                    .like(StringUtils.isNotBlank(tfWaterInfo.getLikeStr()),"NAME",tfWaterInfo.getLikeStr()).or()
                    .like(StringUtils.isNotBlank(tfWaterInfo.getLikeStr()),"ADDRESS",tfWaterInfo.getLikeStr())));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }


    /**
     * 通过id查询水厂信息表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ToFlyAppLog(title="通过ID查询" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
        try{
            return ResultRespone.success(tfWaterInfoService.getById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 新增水厂信息表
     * @param tfWaterInfo 水厂信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增水厂信息表" )
    @ApiOperation(value = "新增水厂信息表")
    @PostMapping
    public ResultRespone save(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, TfWaterInfo tfWaterInfo) {
        try{
            return ResultRespone.success(tfWaterInfoService.saveWaterInfo(fileList, tfWaterInfo));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 修改水厂信息表
     * @param tfWaterInfo 水厂信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改水厂信息表" )
    @ApiOperation(value = "修改水厂信息表")
    @PutMapping
    public ResultRespone updateById(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, TfWaterInfo tfWaterInfo) {
        try{
            return ResultRespone.success(tfWaterInfoService.updateWaterInfo(fileList, tfWaterInfo));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 通过id删除水厂信息表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除水厂信息表" )
    @ApiOperation(value = "通过ID删除水厂信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
        try{
            return ResultRespone.success(tfWaterInfoService.removeById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 通过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) {

        try{
            return ResultRespone.success(tfWaterInfoService.removeWaterInfoByIds(ids));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }
}
