package com.goldenwater.slgc.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.slgc.domain.AttWagaBase;
import com.goldenwater.slgc.service.WagaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;

/**
 * 泵站信息管理
 *
 * @author goldenwater
 */
@Tag(name = "04. 泵站信息管理")
@RestController
@RequestMapping("/slgc/waga")
public class WagaController extends BaseController {
    @Autowired
    private WagaService wagaService;

    /**
     * 查询泵站信息列表
     *
     * @param attWagaBase 泵站信息查询条件
     * @return 分页列表数据
     */
    @Operation(summary = "04.01 查询泵站信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AttWagaBase attWagaBase) {
        startPage();
        List<AttWagaBase> list = wagaService.selectAttWagaBaseList(attWagaBase);
        return getDataTable(list);
    }

    /**
     * 获取泵站信息详细信息
     *
     * @param wagaCode 泵站编码
     * @return 泵站信息
     */
    @Operation(summary = "04.02 获取泵站信息详细信息")
    @GetMapping(value = "/{wagaCode}")
    public AjaxResult getInfo(@PathVariable String wagaCode) {
        return success(wagaService.selectAttWagaBaseById(wagaCode));
    }

    /**
     * 新增泵站信息
     *
     * @param attWagaBase 泵站信息
     * @return 操作结果
     */
    @Operation(summary = "04.03 新增泵站信息")
    @Log(title = "泵站管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttWagaBase attWagaBase) {
        return toAjax(wagaService.insertAttWagaBase(attWagaBase));
    }

    /**
     * 修改泵站信息
     *
     * @param attWagaBase 泵站信息
     * @return 操作结果
     */
    @Operation(summary = "04.04 修改泵站信息")
    @Log(title = "泵站管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttWagaBase attWagaBase) {
        return toAjax(wagaService.updateAttWagaBase(attWagaBase));
    }

    /**
     * 删除泵站信息
     *
     * @param wagaCodes 待删除的泵站编码数组
     * @return 操作结果
     */
    @Operation(summary = "04.05 删除泵站信息")
    @Log(title = "泵站管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wagaCodes}")
    public AjaxResult remove(@PathVariable String[] wagaCodes) {
        return toAjax(wagaService.deleteAttWagaBaseByIds(wagaCodes));
    }

    /**
     * 统计泵站等级分布
     *
     * @return 统计结果列表
     */
    @Operation(summary = "04.06 统计泵站等级分布")
    @GetMapping("/countType")
    public AjaxResult countType() {
        List<Map<String, Object>> list = wagaService.countType();
        return success(list);
    }

    /**
     * 导出泵站信息列表
     *
     * @param attWagaBase 查询条件
     */
    @Operation(summary = "04.07 导出泵站信息")
    @Log(title = "泵站管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(AttWagaBase attWagaBase, HttpServletResponse response) {
        List<AttWagaBase> list = wagaService.selectAttWagaBaseList(attWagaBase);
        ExcelUtil<AttWagaBase> util = new ExcelUtil<AttWagaBase>(AttWagaBase.class);
        util.exportExcel(response, list, "泵站信息数据");
    }

    /**
     * 导入泵站信息列表
     *
     * @param file 上传的Excel文件
     * @return 导入结果
     */
    @Operation(summary = "04.08 导入泵站信息")
    @Log(title = "泵站管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<AttWagaBase> util = new ExcelUtil<AttWagaBase>(AttWagaBase.class);
        List<AttWagaBase> list = util.importExcel(file.getInputStream());
        String message = wagaService.importWaga(list);
        return success(message);
    }

    /**
     * 下载导入模板
     */
    @Operation(summary = "04.09 下载泵站导入模板")
    @GetMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<AttWagaBase> util = new ExcelUtil<AttWagaBase>(AttWagaBase.class);
        util.importTemplateExcel(response, "泵站信息数据");
    }
}
