package org.dromara.controller.partyNews;

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.partyNews.bo.PartyNewsBo;
import org.dromara.domain.partyNews.vo.PartyNewsVo;
import org.dromara.service.IPartyNewsService;
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/partyNews")
public class PartyNewsController extends BaseController {

    private final IPartyNewsService partyNewsService;

    /**
     * 查询党建资讯列表
     */
    @SaCheckPermission("wuYe:partyNews:list")
    @GetMapping("/list")
    public TableDataInfo<PartyNewsVo> list(PartyNewsBo bo, PageQuery pageQuery) {
        return partyNewsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出党建资讯列表
     */
    @SaCheckPermission("wuYe:partyNews:export")
    @Log(title = "党建资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PartyNewsBo bo, HttpServletResponse response) {
        List<PartyNewsVo> list = partyNewsService.queryList(bo);
        ExcelUtil.exportExcel(list, "党建资讯", PartyNewsVo.class, response);
    }

    /**
     * 获取党建资讯详细信息
     *
     * @param partyId 主键
     */
    @SaCheckPermission("wuYe:partyNews:query")
    @GetMapping("/{partyId}")
    public R<PartyNewsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long partyId) {
        return R.ok(partyNewsService.queryById(partyId));
    }

    /**
     * 新增党建资讯
     */
    @SaCheckPermission("wuYe:partyNews:add")
    @Log(title = "党建资讯", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PartyNewsBo bo) {
        return toAjax(partyNewsService.insertByBo(bo));
    }

    /**
     * 修改党建资讯
     */
    @SaCheckPermission("wuYe:partyNews:edit")
    @Log(title = "党建资讯", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PartyNewsBo bo) {
        return toAjax(partyNewsService.updateByBo(bo));
    }

    /**
     * 删除党建资讯
     *
     * @param partyIds 主键串
     */
    @SaCheckPermission("wuYe:partyNews:remove")
    @Log(title = "党建资讯", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{partyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] partyIds) {
        return toAjax(partyNewsService.deleteWithValidByIds(List.of(partyIds), true));
    }
}
