package org.dromara.system.controller.info;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.info.XiaoyuanInfo;
import org.dromara.system.domain.info.bo.InfoPingLunBo;
import org.dromara.system.domain.info.vo.XiaoyuanInfoVo;
import org.dromara.system.service.info.IXiaoyuanInfoService;
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.system.domain.bo.XiaoyuanInfoBo;


/**
 * 校园安全信息
 *
 * @author boman
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xiaoYuan/info")
public class XiaoyuanInfoController extends BaseController {

    private final IXiaoyuanInfoService xiaoyuanInfoService;

    /**
     * 查询校园安全信息列表
     */
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:list")
    @GetMapping("/list")
    public TableDataInfo<XiaoyuanInfoVo> list(XiaoyuanInfoBo bo, PageQuery pageQuery) {
        return xiaoyuanInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出校园安全信息列表
     */
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:export")
    @Log(title = "校园安全信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XiaoyuanInfoBo bo, HttpServletResponse response) {
        List<XiaoyuanInfoVo> list = xiaoyuanInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "校园安全信息", XiaoyuanInfoVo.class, response);
    }

    /**
     * 获取校园安全信息详细信息
     *
     * @param infoId 主键
     */
    @SaIgnore
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:query")
    @GetMapping("/{infoId}")
    public R<XiaoyuanInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long infoId) {
        return R.ok(xiaoyuanInfoService.queryById(infoId));
    }

    /**
     * 新增校园安全信息
     */
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:add")
    @Log(title = "校园安全信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XiaoyuanInfoBo bo) {
        return toAjax(xiaoyuanInfoService.insertByBo(bo));
    }

    /**
     * 修改校园安全信息
     */
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:edit")
    @Log(title = "校园安全信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XiaoyuanInfoBo bo) {
        return toAjax(xiaoyuanInfoService.updateByBo(bo));
    }

    /**
     * 删除校园安全信息
     *
     * @param infoIds 主键串
     */
    @SaCheckPermission("xiaoYuanInfo:xiaoYuanInfo:remove")
    @Log(title = "校园安全信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{infoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] infoIds) {
        return toAjax(xiaoyuanInfoService.deleteWithValidByIds(List.of(infoIds), true));
    }
    /**
     * 新增校园安全信息评论
     */
    @PostMapping("/pingLun")
    public  R<Void> pingLun(@RequestBody InfoPingLunBo bo)
    {
        return toAjax(xiaoyuanInfoService.insertInfoPingLun(bo));
    }

    /**
     * 删除校园安全信息评论
     */
    @PostMapping("/delete/pingLun")
    public  R<Void> deletePingLun(@RequestBody InfoPingLunBo bo)
    {
        return toAjax(xiaoyuanInfoService.deletePingLun(bo));
    }

    /**
     * 新增校园安全信息点赞接口/取消点赞
     */
    @PostMapping("/dianZan")
    public  R<Void> dianZan(@RequestBody XiaoyuanInfoBo xiaoyuanInfo)
    {
        return toAjax(xiaoyuanInfoService.dianZan(xiaoyuanInfo));
    }

    /**
     * 新增校园安全信息转发接口
     */
    @PostMapping("/zhuanFa")
    public  R<Void> zhuanFa(@RequestBody XiaoyuanInfoBo xiaoyuanInfo)
    {
        return toAjax(xiaoyuanInfoService.zhuanFa(xiaoyuanInfo));
    }
}
