package com.tofly.water.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.water.entity.BasePump;
import com.tofly.water.entity.BasePumpDetail;
import com.tofly.water.entity.DevicePump;
import com.tofly.water.entity.dto.BasePumpDto;
import com.tofly.water.service.BasePumpService;
import com.tofly.water.service.DevicePumpService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 泵站信息管理(BasePump)表控制层
 *
 * @author HaiQiu
 * @since 2022-11-22 11:34:20
 */
@Api(tags = "泵站信息管理")
@RestController
@RequestMapping("basePump")
public class BasePumpController {
    /**
     * 服务对象
     */
    @Resource
    private BasePumpService basePumpService;

    @Autowired
    private DevicePumpService devicePumpService;

    /**
     * 分页查询数据
     *
     * @param page     分页对象
     * @param basePump 查询实体
     * @return 所有数据
     */
    @ToFlyAppLog(title = "泵站信息管理-分页查询数据")
    @ApiOperation(value = "分页查询数据")
    @GetMapping("/page")
    public ResultRespone<Page<BasePump>> pageList(Page page, BasePump basePump) {
        return ResultRespone.success(basePumpService.pageList(page, basePump), "查询成功");
    }

    /**
     * 查询所有数据
     *
     * @param basePump 查询实体
     * @return 所有数据
     */
    @ToFlyAppLog(title = "泵站信息管理-查询所有数据")
    @ApiOperation(value = "查询所有数据")
    @GetMapping("/list")
    public ResultRespone<List<BasePump>> allList(BasePump basePump) {
        return ResultRespone.success(basePumpService.allList(basePump), "查询成功");
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ToFlyAppLog(title = "泵站信息管理-通过主键查询单条数据")
    @ApiOperation(value = "通过主键查询单条数据")
    @ApiImplicitParam(name = "id", value = "数据ID")
    @GetMapping("{id}")
    public ResultRespone<BasePump> get(@PathVariable Serializable id) {
        return ResultRespone.success(basePumpService.get(id), "查询成功");
    }

    /**
     * 新增数据
     *
     * @param basePumpDto 实体
     * @param files       上传文件附件
     * @return 新增结果
     */
    @ToFlyAppLog(title = "泵站信息管理-新增数据")
    @ApiOperation(value = "新增数据")
    @PostMapping
    public ResultRespone insert(@RequestPart @Validated BasePumpDto basePumpDto,
                                @RequestPart(required = false) @ApiParam("附件列表") List<MultipartFile> files) {
        basePumpService.insert(basePumpDto, files);
        return ResultRespone.success(null, "新增成功");
    }

    /**
     * 修改数据
     *
     * @param basePumpDto 实体
     * @param files       上传文件附件
     * @return 修改结果
     */
    @ToFlyAppLog(title = "泵站信息管理-修改数据")
    @ApiOperation(value = "修改数据")
    @PutMapping
    public ResultRespone edit(@RequestPart @Validated BasePumpDto basePumpDto,
                              @RequestPart(required = false) @ApiParam("附件列表") List<MultipartFile> files) {
        basePumpService.edit(basePumpDto, files);
        return ResultRespone.success(null, "修改成功");
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ToFlyAppLog(title = "泵站信息管理-删除数据")
    @ApiOperation(value = "删除数据")
    @ApiImplicitParam(name = "idList", value = "数据ID数组集合")
    @DeleteMapping
    public ResultRespone delete(@RequestParam("idList") List<Long> idList) {
        basePumpService.delete(idList);
        return ResultRespone.success(null, "删除成功");
    }

    /**
     * 数据导入Excel模板下载
     */
    @ToFlyAppLog(title = "泵站信息管理-模版下载")
    @ApiOperation(value = "模版下载")
    @GetMapping("/template")
    public void template() {
        basePumpService.template();
    }

    /**
     * Excel数据导入
     *
     * @param file 导入的Excel数据文件
     * @return 导入结果
     */
    @ToFlyAppLog(title = "泵站信息管理-Excel数据导入")
    @ApiOperation(value = "数据导入")
    @ApiImplicitParam(name = "file", value = "Excel文件", required = true)
    @PostMapping("/import")
    public ResultRespone importData(@RequestParam(name = "file") MultipartFile file) {
        basePumpService.importData(file);
        return ResultRespone.success(null, "导入成功");
    }


    /**
     * 数据导出
     *
     * @param page     分页
     * @param basePump 查询模型
     * @param isAll    是否导出全部数据，true是，false否
     */
    @ToFlyAppLog(title = "泵站信息管理-数据导出")
    @ApiOperation(value = "数据导出")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "isAll", value = "是否导出全部数据，true是，false不是"),
    })
    @GetMapping("/export")
    public void export(Page page, BasePump basePump, Boolean isAll) {
        basePumpService.export(page, basePump, isAll);
    }
}

