package jnpf.notice.controller.web;


import jnpf.base.ActionResult;
import jnpf.model.notice.dto.FtbNoticeUserGroupsDto;
import jnpf.model.notice.req.group.AddUserGroupReq;
import jnpf.model.notice.req.group.UpdateUserGroupReq;
import jnpf.notice.service.FtbNoticeUserGroupsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * web用户分组表模块
 *
 * @author xgl
 * @since 2024-05-08 09:51:36
 */
@RestController
@RequestMapping("/web/noticeUserGroup")
public class FtbNoticeUserGroupsController {
    /**
     * 服务对象
     */
    @Autowired
    private FtbNoticeUserGroupsService ftbNoticeUserGroupsService;


    /**
     * 查询分组列表
     *
     * @return {@link ActionResult}<{@link FtbNoticeUserGroupsDto}>
     */
    @GetMapping("/queryAllGroup")
    public ActionResult<List<FtbNoticeUserGroupsDto>> queryAllGroup() {
        return ActionResult.success("成功", ftbNoticeUserGroupsService.queryWebAllGroup());
    }


    /**
     * 添加分组
     *
     * @param req 参数
     * @return {@link ActionResult}<{@link String}>
     */
    @PostMapping("/add")
    public ActionResult<String> add(@Validated @RequestBody AddUserGroupReq req) {
        return ActionResult.success("操作成功", ftbNoticeUserGroupsService.insertData(req));
    }


    /**
     * 编辑分组
     *
     * @param id  分组主键ID
     * @param req
     * @return {@link ActionResult}
     */
    @PutMapping("/update/{id}")
    public ActionResult update(@PathVariable("id") String id, @Validated @RequestBody UpdateUserGroupReq req) {
        ftbNoticeUserGroupsService.updateData(id, req);
        return ActionResult.success("操作成功");
    }


    /**
     * 查询分组详情
     *
     * @param id 分组主键ID
     * @return {@link ActionResult}
     */
    @GetMapping("/get/{id}")
    public ActionResult<FtbNoticeUserGroupsDto> get(@PathVariable("id") String id) {
        return ActionResult.success("成功", ftbNoticeUserGroupsService.getInfo(id));
    }

    /**
     * 批量查询分组的人员列表
     *
     * @param groupIds 分组主键ID,逗号分开
     * @return {@link ActionResult}
     */
    @GetMapping("/queryBatchGroupUser/{groupIds}")
    public ActionResult<List<String>> queryBatchGroupUser(@PathVariable("groupIds") String groupIds) {
        return ActionResult.success("成功", ftbNoticeUserGroupsService.queryBatchGroupUser(groupIds));
    }

    /**
     * 删除分组
     *
     * @param id 分组主键ID，必传
     * @return {@link ActionResult}
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        ftbNoticeUserGroupsService.deleteData(id);
        return ActionResult.success();
    }


}

