/**
   * 커뮤니티, 동호회에 사용되는 게시판 사용정보를 등록한다.
   *
   * @param bdUseVO
   * @param boardUseInf
   * @param status
   * @param model
   * @return
   * @throws Exception
   */
  @RequestMapping("/cop/com/insertBBSUseInfByTrget.do")
  public String insertBBSUseInfByTrget(
      @ModelAttribute("searchVO") BoardUseInfVO bdUseVO,
      @ModelAttribute("boardUseInf") BoardUseInf boardUseInf,
      @RequestParam Map<String, Object> commandMap,
      SessionStatus status,
      ModelMap model)
      throws Exception {

    checkAuthority(bdUseVO); // server-side 권한 확인

    String paramTrgetId = (String) commandMap.get("param_trgetId");
    String bbsId = (String) commandMap.get("bbsId");

    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();

    if (isAuthenticated) {
      boardUseInf.setUseAt("Y");
      boardUseInf.setFrstRegisterId(user.getUniqId());
      boardUseInf.setRegistSeCode("REGC07");
      boardUseInf.setBbsId(bbsId);
      boardUseInf.setTrgetId(paramTrgetId);

      bbsUseService.insertBBSUseInf(boardUseInf);
    }

    return "forward:/cop/com/selectCmyBBSUseInfsByTrget.do";
  }
  /**
   * 커뮤니티 관리자 및 동호회 운영자 권한을 확인한다.
   *
   * @param boardUseInf
   * @throws EgovBizException
   */
  protected void checkAuthority(BoardUseInf boardUseInf) throws Exception {
    String targetId = boardUseInf.getTrgetId();

    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    if (user == null) {
      throw new EgovBizException("인증된 사용자 정보가 존재하지 않습니다.");
    }

    if (targetId.startsWith("CMMNTY_")) {
      CommunityUser cmmntyUser = new CommunityUser();

      cmmntyUser.setCmmntyId(boardUseInf.getTrgetId());
      cmmntyUser.setEmplyrId(user.getUniqId());

      if (!cmmntyService.isManager(cmmntyUser)) {
        throw new EgovBizException("해당 커뮤니티 관리자만 사용하실 수 있습니다.");
      }
    } else if (targetId.startsWith("CLB_")) {
      ClubUser clubUser = new ClubUser();

      clubUser.setClbId(boardUseInf.getTrgetId());
      clubUser.setEmplyrId(user.getUniqId());

      if (!clbService.isOperator(clubUser)) {
        throw new EgovBizException("해당 동호회 운영자만 사용하실 수 있습니다.");
      }
    } else {
      throw new EgovBizException("대상ID 정보가 정확하지 않습니다.");
    }
  }
  /**
   * 게시판 사용정보를 등록한다.
   *
   * @param bdUseVO
   * @param bdUseInf
   * @param sessionVO
   * @param status
   * @param model
   * @return
   * @throws Exception
   */
  @RequestMapping("/cop/com/insertBBSUseInf.do")
  public String insertBBSUseInf(
      @ModelAttribute("searchVO") BoardUseInfVO bdUseVO,
      @ModelAttribute("boardUseInf") BoardUseInf boardUseInf,
      BindingResult bindingResult,
      Map<String, Object> commandMap,
      SessionStatus status,
      ModelMap model)
      throws Exception {

    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();

    beanValidator.validate(boardUseInf, bindingResult);

    if (bindingResult.hasErrors()) {
      return "egovframework/com/cop/com/EgovBoardUseInfRegist";
    }

    String trgetType = (String) commandMap.get("param_trgetType");
    String registSeCode = "";

    // CMMNTY 06/CLUB 05/SYSTEM(REGC01)
    if ("CMMNTY".equals(trgetType)) {
      registSeCode = "REGC06";
    } else if ("CLUB".equals(trgetType)) {
      registSeCode = "REGC05";
    } else {
      registSeCode = "REGC01";
    }

    boardUseInf.setUseAt("Y");
    boardUseInf.setFrstRegisterId(user.getUniqId());
    boardUseInf.setRegistSeCode(registSeCode);

    if (isAuthenticated) {
      bbsUseService.insertBBSUseInf(boardUseInf);
    }

    return "forward:/cop/com/selectBBSUseInfs.do";
  }