package com.fuyuanshen.web.controller.device;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.equipment.domain.vo.DeviceChargeDischargeVo;
import com.fuyuanshen.equipment.domain.bo.DeviceChargeDischargeBo;
import com.fuyuanshen.equipment.service.IDeviceChargeDischargeService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 设备充放电记录
 *
 * @author Lion Li
 * @date 2025-08-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/equipment/chargeDischarge")
public class DeviceChargeDischargeController extends BaseController {

    private final IDeviceChargeDischargeService deviceChargeDischargeService;

    /**
     * 查询设备充放电记录列表
     */
    // @SaCheckPermission("equipment:chargeDischarge:list")
    @GetMapping("/list")
    public TableDataInfo<DeviceChargeDischargeVo> list(DeviceChargeDischargeBo bo, PageQuery pageQuery) {
        return deviceChargeDischargeService.queryPageList(bo, pageQuery);
    }

    /**
     * 设备充放电记录列表
     */
    // @SaCheckPermission("equipment:chargeDischarge:export")
    @Log(title = "设备充放电记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DeviceChargeDischargeBo bo, HttpServletResponse response) {
        List<DeviceChargeDischargeVo> list = deviceChargeDischargeService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备充放电记录", DeviceChargeDischargeVo.class, response);
    }

    /**
     * 获取设备充放电记录详细信息
     *
     * @param id 主键
     */
    // @SaCheckPermission("equipment:chargeDischarge:query")
    @GetMapping("/{id}")
    public R<DeviceChargeDischargeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(deviceChargeDischargeService.queryById(id));
    }

    /**
     * 新增设备充放电记录
     */
    // @SaCheckPermission("equipment:chargeDischarge:add")
    @Log(title = "设备充放电记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceChargeDischargeBo bo) {
        return toAjax(deviceChargeDischargeService.insertByBo(bo));
    }

    /**
     * 修改设备充放电记录
     */
    // @SaCheckPermission("equipment:chargeDischarge:edit")
    @Log(title = "设备充放电记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceChargeDischargeBo bo) {
        return toAjax(deviceChargeDischargeService.updateByBo(bo));
    }

    /**
     * 删除设备充放电记录
     *
     * @param ids 主键串
     */
    // @SaCheckPermission("equipment:chargeDischarge:remove")
    @Log(title = "设备充放电记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(deviceChargeDischargeService.deleteWithValidByIds(List.of(ids), true));
    }


}
