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.redis.service.RedisService;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseEnergyType;
import com.hw.ems.base.service.IBaseEnergyTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 能源类型信息Controller
 *
 * @author sf
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/type")
public class BaseEnergyTypeController extends BaseController {
    @Autowired
    private IBaseEnergyTypeService baseEnergyTypeService;
    @Autowired
    private RedisService redisService;
    /**
     * 查询能源类型信息列表
     */
    @RequiresPermissions("energy:type:list")
    @GetMapping("/list")
//    @PoolDeptAuto
    public TableDataInfo list(BaseEnergyType baseEnergyType) {
        startPage();
        List<BaseEnergyType> list = baseEnergyTypeService.selectBaseEnergyTypeList(baseEnergyType);
        return getDataTable(list);
    }

    /**
     * 导出能源类型信息列表
     */
    @RequiresPermissions("energy:type:export")
    @Log(title = "能源类型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
//    @PoolDeptAuto
    public void export(HttpServletResponse response, BaseEnergyType baseEnergyType) {
        List<BaseEnergyType> list = baseEnergyTypeService.selectBaseEnergyTypeList(baseEnergyType);
        ExcelUtil<BaseEnergyType> util = new ExcelUtil<BaseEnergyType>(BaseEnergyType.class);
        util.exportExcel(response, list, "能源类型信息数据");
    }

    /**
     * 获取能源类型信息详细信息
     */
    @RequiresPermissions("energy:type:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        //String poolName = redisService.getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + SecurityUtils.getUsername());
        return success(baseEnergyTypeService.selectBaseEnergyTypeByObjid(objid));
    }

    /**
     * 新增能源类型信息
     */
    @RequiresPermissions("energy:type:add")
    @Log(title = "能源类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseEnergyType baseEnergyType) {
        return toAjax(baseEnergyTypeService.insertBaseEnergyType(baseEnergyType));
    }

    /**
     * 修改能源类型信息
     */
    @RequiresPermissions("energy:type:edit")
    @Log(title = "能源类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseEnergyType baseEnergyType) {
        return toAjax(baseEnergyTypeService.updateBaseEnergyType(baseEnergyType));
    }

    /**
     * 删除能源类型信息
     */
    @RequiresPermissions("energy:type:remove")
    @Log(title = "能源类型信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseEnergyTypeService.deleteBaseEnergyTypeByObjids(objids));
    }
}
