package com.hw.ems.base.controller;

import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.web.page.TableDataInfo;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseMeterInfo;
import com.hw.ems.base.service.IBaseMeterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

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

/**
 * 计量仪表信息Controller
 *
 * @author YinQ
 * @date 2023-03-31
 */
@RestController
@RequestMapping("/base/meterInfo")
public class BaseMeterInfoController extends BaseController {
    private String prefix = "base/meterInfo";

    @Autowired
    private IBaseMeterInfoService baseMeterInfoService;

    @RequiresPermissions("base:meterInfo:view")
    @GetMapping()
    public String meterInfo() {
        return prefix + "/meterInfo";
    }

    /**
     * 查询计量仪表信息列表
     */
    @RequiresPermissions("base:meterInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseMeterInfo baseMeterInfo) {
        startPage();
        List<BaseMeterInfo> list = baseMeterInfoService.selectBaseMeterInfoList(baseMeterInfo);
        return getDataTable(list);
    }

    /**
     * 导出计量仪表信息列表
     */
    @RequiresPermissions("base:meterInfo:export")
    @Log(title = "计量仪表信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseMeterInfo baseMeterInfo) {
        List<BaseMeterInfo> list = baseMeterInfoService.selectBaseMeterInfoList(baseMeterInfo);
        ExcelUtil<BaseMeterInfo> util = new ExcelUtil<BaseMeterInfo>(BaseMeterInfo.class);
        util.exportExcel(response, list, "计量仪表信息数据");
    }

    /**
     * 新增计量仪表信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存计量仪表信息
     */
    @RequiresPermissions("base:meterInfo:add")
    @Log(title = "计量仪表信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(BaseMeterInfo baseMeterInfo) {
        return toAjax(baseMeterInfoService.insertBaseMeterInfo(baseMeterInfo));
    }

    /**
     * 修改计量仪表信息
     */
    @RequiresPermissions("base:meterInfo:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap) {
        BaseMeterInfo baseMeterInfo = baseMeterInfoService.selectBaseMeterInfoByObjid(objid);
        mmap.put("baseMeterInfo", baseMeterInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存计量仪表信息
     */
    @RequiresPermissions("base:meterInfo:edit")
    @Log(title = "计量仪表信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editSave(BaseMeterInfo baseMeterInfo) {
        return toAjax(baseMeterInfoService.updateBaseMeterInfo(baseMeterInfo));
    }

    /**
     * 删除计量仪表信息
     */
    @RequiresPermissions("base:meterInfo:remove")
    @Log(title = "计量仪表信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(String ids) {
        return toAjax(baseMeterInfoService.deleteBaseMeterInfoByObjids(ids));
    }
}
