package org.dromara.ygpassport.controller;

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 org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ygpassport.domain.vo.CareerPlansVo;
import org.dromara.ygpassport.domain.bo.CareerPlansBo;
import org.dromara.ygpassport.service.ICareerPlansService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 生涯规划相关信息
 *
 * @author Lion Li
 * @date 2024-03-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ygpassport/careerPlans")
public class CareerPlansController extends BaseController {

    private final ICareerPlansService careerPlansService;

    /**
     * 查询生涯规划相关信息列表
     */
    @SaCheckPermission("ygpassport:careerPlans:list")
    @GetMapping("/list")
    public TableDataInfo<CareerPlansVo> list(CareerPlansBo bo, PageQuery pageQuery) {
        return careerPlansService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出生涯规划相关信息列表
     */
    @SaCheckPermission("ygpassport:careerPlans:export")
    @Log(title = "生涯规划相关信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CareerPlansBo bo, HttpServletResponse response) {
        List<CareerPlansVo> list = careerPlansService.queryList(bo);
        ExcelUtil.exportExcel(list, "生涯规划相关信息", CareerPlansVo.class, response);
    }

    /**
     * 获取生涯规划相关信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("ygpassport:careerPlans:query")
    @GetMapping("/{id}")
    public R<CareerPlansVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(careerPlansService.queryById(id));
    }

    /**
     * 新增生涯规划相关信息
     */
    @SaCheckPermission("ygpassport:careerPlans:add")
    @Log(title = "生涯规划相关信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CareerPlansBo bo) {
        return toAjax(careerPlansService.insertByBo(bo));
    }

    /**
     * 修改生涯规划相关信息
     */
    @SaCheckPermission("ygpassport:careerPlans:edit")
    @Log(title = "生涯规划相关信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CareerPlansBo bo) {
        return toAjax(careerPlansService.updateByBo(bo));
    }

    /**
     * 删除生涯规划相关信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("ygpassport:careerPlans:remove")
    @Log(title = "生涯规划相关信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(careerPlansService.deleteWithValidByIds(List.of(ids), true));
    }
}
