package com.ruoyi.ems.base.controller;

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

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ems.base.domain.EmsBaseSharePrice;
import com.ruoyi.ems.base.service.IEmsBaseSharePriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分时电价维护Controller
 *
 * @author Yinq
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/ems/base/baseSharePrice")
public class EmsBaseSharePriceController extends BaseController {
    @Autowired
    private IEmsBaseSharePriceService emsBaseSharePriceService;

    /**
     * 查询分时电价维护列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseSharePrice emsBaseSharePrice) {
        startPage();
        List<EmsBaseSharePrice> list = emsBaseSharePriceService.selectEmsBaseSharePriceList(emsBaseSharePrice);
        return getDataTable(list);
    }

    /**
     * 导出分时电价维护列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:export')")
    @Log(title = "分时电价维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseSharePrice emsBaseSharePrice) {
        List<EmsBaseSharePrice> list = emsBaseSharePriceService.selectEmsBaseSharePriceList(emsBaseSharePrice);
        ExcelUtil<EmsBaseSharePrice> util = new ExcelUtil<EmsBaseSharePrice>(EmsBaseSharePrice.class);
        util.exportExcel(response, list, "分时电价维护数据");
    }

    /**
     * 获取分时电价维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseSharePriceService.selectEmsBaseSharePriceByObjId(objId));
    }

    /**
     * 新增分时电价维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:add')")
    @Log(title = "分时电价维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseSharePrice emsBaseSharePrice) {
        emsBaseSharePrice.setCreateBy(getUsername());
        return toAjax(emsBaseSharePriceService.insertEmsBaseSharePrice(emsBaseSharePrice));
    }

    /**
     * 修改分时电价维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:edit')")
    @Log(title = "分时电价维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseSharePrice emsBaseSharePrice) {
        emsBaseSharePrice.setUpdateBy(getUsername());
        return toAjax(emsBaseSharePriceService.updateEmsBaseSharePrice(emsBaseSharePrice));
    }

    /**
     * 删除分时电价维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseSharePrice:remove')")
    @Log(title = "分时电价维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(emsBaseSharePriceService.deleteEmsBaseSharePriceByObjIds(objIds));
    }
}
