package com.zksy.controller.info;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.info.domain.EWaterCustomer;
import com.zksy.info.service.EWaterCustomerService;
import com.zksy.utils.AjaxResult;
import com.zksy.utils.ExcelExportUtil;
import com.zksy.utils.ExcelImportUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description
 * @date 2025/10/15 13:49:30
 */
@RestController
@RequestMapping("/eWaterCustomer")
@Api(tags = "用水信息",description = "用水信息desc")
public class EWaterCustomerController {
    @Autowired
    private EWaterCustomerService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "用水信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize){
        return AjaxResult.success(service.page(new Page<>(pageNum, pageSize)));
    }
    @GetMapping("/getEWaterCustomerList")
    @ApiOperation(value = "用水信息查询")
    public AjaxResult getEWaterCustomerList(){
        return AjaxResult.success(service.list());
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询用水信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "用水信息保存")
    public AjaxResult save(@RequestBody EWaterCustomer egas) {
        return service.save(egas) ? AjaxResult.success(egas) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "用水信息修改")
    public AjaxResult update(@RequestBody EWaterCustomer egas) {
        return service.updateById(egas) ? AjaxResult.success(egas) : AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "用水信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据")
    public AjaxResult importData(MultipartFile file) {
        return AjaxResult.success(service.saveOrUpdateBatch(ExcelImportUtil.importExcel(file, EWaterCustomer.class)));
    }
    @GetMapping("/exportData")
    @ApiOperation(value = "导出数据")
    public void exportData(HttpServletResponse response) {
        ExcelExportUtil.exportExcel(response,service.list(), EWaterCustomer.class, "用水信息","用水信息");
    }
}
