package org.dromara.system.controller.project;

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.system.domain.bo.BusProjectPunchrangeBo;
import org.dromara.system.domain.vo.projectpunchrange.BusProjectPunchrangeVo;
import org.dromara.system.service.IBusProjectPunchrangeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目打卡范围
 *
 * @author Lion Li
 * @date 2025-07-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/projectPunchrange")
public class BusProjectPunchrangeController extends BaseController {

    private final IBusProjectPunchrangeService busProjectPunchrangeService;

    /**
     * 查询项目打卡范围列表
     */
    @SaCheckPermission("project:projectPunchrange:list")
    @GetMapping("/list")
    public TableDataInfo<BusProjectPunchrangeVo> list(BusProjectPunchrangeBo bo, PageQuery pageQuery) {
        return busProjectPunchrangeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目打卡范围列表
     */
    @SaCheckPermission("project:projectPunchrange:export")
    @Log(title = "项目打卡范围", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusProjectPunchrangeBo bo, HttpServletResponse response) {
        List<BusProjectPunchrangeVo> list = busProjectPunchrangeService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目打卡范围", BusProjectPunchrangeVo.class, response);
    }

    /**
     * 获取项目打卡范围详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:projectPunchrange:query")
    @GetMapping("/{id}")
    public R<BusProjectPunchrangeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(busProjectPunchrangeService.queryById(id));
    }

    /**
     * 新增项目打卡范围
     */
    @SaCheckPermission("project:projectPunchrange:add")
    @Log(title = "项目打卡范围", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BusProjectPunchrangeBo bo) {
        return toAjax(busProjectPunchrangeService.insertByBo(bo));
    }

    /**
     * 修改项目打卡范围
     */
    @SaCheckPermission("project:projectPunchrange:edit")
    @Log(title = "项目打卡范围", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusProjectPunchrangeBo bo) {
        return toAjax(busProjectPunchrangeService.updateByBo(bo));
    }

    /**
     * 删除项目打卡范围
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:projectPunchrange:remove")
    @Log(title = "项目打卡范围", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busProjectPunchrangeService.deleteWithValidByIds(List.of(ids), true));
    }
}
