package org.dromara.ems.base.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.base.domain.EmsBaseSharePrice;
import org.dromara.ems.base.service.IEmsBaseSharePriceService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分时电价维护Controller
 *
 * @author Yinq
 * @date 2024-06-11
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseSharePrice")
public class EmsBaseSharePriceController extends EmsBaseController {

    private final IEmsBaseSharePriceService emsBaseSharePriceService;

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

    /**
     * 导出分时电价维护列表
     */
    @SaCheckPermission("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.exportExcel(list, "分时电价维护数据", EmsBaseSharePrice.class, response);
    }

    /**
     * 获取分时电价维护详细信息
     */
    @SaCheckPermission("ems/base:baseSharePrice:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseSharePriceService.selectEmsBaseSharePriceByObjId(objId));
    }

    /**
     * 新增分时电价维护
     */
    @SaCheckPermission("ems/base:baseSharePrice:add")
    @Log(title = "分时电价维护", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseSharePrice emsBaseSharePrice) {
        return toAjax(emsBaseSharePriceService.insertEmsBaseSharePrice(emsBaseSharePrice));
    }

    /**
     * 修改分时电价维护
     */
    @SaCheckPermission("ems/base:baseSharePrice:edit")
    @Log(title = "分时电价维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseSharePrice emsBaseSharePrice) {
        return toAjax(emsBaseSharePriceService.updateEmsBaseSharePrice(emsBaseSharePrice));
    }

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