package org.dromara.controller.illegalParking;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.illegalParking.IllegalParking;
import org.dromara.domain.illegalParking.bo.IllegalParkingBo;
import org.dromara.domain.illegalParking.vo.IllegalParkingVo;
import org.dromara.service.IIllegalParkingService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 违章停车登记
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/illegalParking")
public class IllegalParkingController extends BaseController {

    private final IIllegalParkingService illegalParkingService;

    /**
     * 查询违章停车登记列表
     */
    @SaCheckPermission("wuYe:illegalParking:list")
    @GetMapping("/list")
    public TableDataInfo<IllegalParkingVo> list(IllegalParkingBo bo, PageQuery pageQuery) {
        return illegalParkingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出违章停车登记列表
     */
    @SaCheckPermission("wuYe:illegalParking:export")
    @Log(title = "违章停车登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IllegalParkingBo bo, HttpServletResponse response) {
        List<IllegalParkingVo> list = illegalParkingService.queryList(bo);
        ExcelUtil.exportExcel(list, "违章停车登记", IllegalParkingVo.class, response);
    }

    /**
     * 获取违章停车登记详细信息
     *
     * @param illegalParkingId 主键
     */
    @SaCheckPermission("wuYe:illegalParking:query")
    @GetMapping("/{illegalParkingId}")
    public R<IllegalParkingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long illegalParkingId) {
        return R.ok(illegalParkingService.queryById(illegalParkingId));
    }

    /**
     * 新增违章停车登记
     */
    @SaCheckPermission("wuYe:illegalParking:add")
    @Log(title = "违章停车登记", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IllegalParkingBo bo) {
        return toAjax(illegalParkingService.insertByBo(bo));
    }

    /**
     * 修改违章停车登记
     */
    @SaCheckPermission("wuYe:illegalParking:edit")
    @Log(title = "违章停车登记", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IllegalParkingBo bo) {
        return toAjax(illegalParkingService.updateByBo(bo));
    }

    /**
     * 删除违章停车登记
     *
     * @param illegalParkingIds 主键串
     */
    @SaCheckPermission("wuYe:illegalParking:remove")
    @Log(title = "违章停车登记", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{illegalParkingIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] illegalParkingIds) {
        return toAjax(illegalParkingService.deleteWithValidByIds(List.of(illegalParkingIds), true));
    }

    /**
     * 解除黑名单
     */
    @SaCheckPermission("wuYe:illegalParking:cancel")
    @PostMapping("/cancel")
    public R<Void> cancel(@RequestBody IllegalParkingBo bo) {
        return illegalParkingService.cancel(bo);
    }
}
