/**
   * 부서업무함 정보에 대한 목록을 조회한다.
   *
   * @param DeptJobBxVO
   * @return String
   * @param deptJobBxVO
   */
  @IncludedInfo(name = "부서업무함관리", order = 400, gid = 40)
  @RequestMapping("/cop/smt/djm/selectDeptJobBxList.do")
  public String selectDeptJobBxList(
      @ModelAttribute("searchVO") DeptJobBxVO deptJobBxVO, ModelMap model) throws Exception {
    // LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
    String sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobBxList";

    if (deptJobBxVO.getPopupCnd() != null && !deptJobBxVO.getPopupCnd().equals(""))
      sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobBxListS";

    deptJobBxVO.setPageUnit(propertyService.getInt("pageUnit"));
    deptJobBxVO.setPageSize(propertyService.getInt("pageSize"));

    PaginationInfo paginationInfo = new PaginationInfo();
    paginationInfo.setCurrentPageNo(deptJobBxVO.getPageIndex());
    paginationInfo.setRecordCountPerPage(deptJobBxVO.getPageUnit());
    paginationInfo.setPageSize(deptJobBxVO.getPageSize());

    deptJobBxVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
    deptJobBxVO.setLastIndex(paginationInfo.getLastRecordIndex());
    deptJobBxVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());

    Map<String, Object> map = deptJobService.selectDeptJobBxList(deptJobBxVO);
    int totCnt = Integer.parseInt((String) map.get("resultCnt"));
    paginationInfo.setTotalRecordCount(totCnt);

    List<DeptJobBxVO> list = (List<DeptJobBxVO>) map.get("resultList");

    model.addAttribute("resultList", map.get("resultList"));
    model.addAttribute("resultCnt", map.get("resultCnt"));
    model.addAttribute("resultNum", list.size());
    model.addAttribute("paginationInfo", paginationInfo);

    return sLocationUrl;
  }
  /**
   * 부서업무함 등록시 표시순서를 조회한다.
   *
   * @param DeptJobBx
   * @return String
   * @param DeptJobBx
   */
  @RequestMapping("/cop/smt/djm/getDeptJobBxOrdr.do")
  public String getDeptJobBxOrdr(
      final HttpServletRequest request,
      @ModelAttribute("deptJobBxVO") DeptJobBxVO deptJobBxVO,
      ModelMap model)
      throws Exception {

    String sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobBxRegist";

    if (request.getHeader("Referer").indexOf("addDeptJobBx.do") < 0) {
      sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobBxUpdt";
    }

    // 0. Spring Security 사용자권한 처리
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
      model.addAttribute("message", egovMessageSource.getMessage("fail.common.login"));
      return "egovframework/com/uat/uia/EgovLoginUsr";
    }

    // System.out.println(deptJobService.selectDeptJobBxOrdr(deptJobBxVO.getDeptId()));
    // deptJobBxVO.setIndictOrdr(deptJobService.selectDeptJobBxOrdr(deptJobBxVO.getDeptId()) + 1);

    model.addAttribute(
        "indictOrdrValue", deptJobService.selectDeptJobBxOrdr(deptJobBxVO.getDeptId()) + 1);
    return sLocationUrl;
  }
  /**
   * 부서업무함 정보를 등록한다.
   *
   * @param DeptJobBxVO
   * @return String
   * @param deptJobBxVO
   */
  @RequestMapping("/cop/smt/djm/insertDeptJobBx.do")
  public String insertDeptJobBx(
      @ModelAttribute("deptJobBxVO") DeptJobBxVO deptJobBxVO,
      BindingResult bindingResult,
      ModelMap model)
      throws Exception {
    // 0. Spring Security 사용자권한 처리
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
      model.addAttribute("message", egovMessageSource.getMessage("fail.common.login"));
      return "egovframework/com/uat/uia/EgovLoginUsr";
    }

    // 로그인 객체 선언
    LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    String sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobBxRegist";

    // 서버  validate 체크
    beanValidator.validate(deptJobBxVO, bindingResult);
    if (bindingResult.hasErrors()) {
      return sLocationUrl;
    }

    // 아이디 설정
    deptJobBxVO.setFrstRegisterId((String) loginVO.getUniqId());
    deptJobBxVO.setLastUpdusrId((String) loginVO.getUniqId());

    // 부서내 부서업무함명 중복체크
    if (deptJobService.selectDeptJobBxCheck(deptJobBxVO) > 0) {
      model.addAttribute("deptJobBxNmDuplicated", "true");
      sLocationUrl = "forward:/cop/smt/djm/addDeptJobBx.do";
    } else {
      deptJobService.insertDeptJobBx(deptJobBxVO);
      sLocationUrl = "forward:/cop/smt/djm/selectDeptJobBxList.do";
    }
    return sLocationUrl;
  }
  /**
   * 부서업무함 정보의 표시순서를 수정한다.
   *
   * @param DeptJobBx
   * @return String
   * @param deptJobBx
   */
  @RequestMapping("/cop/smt/djm/updateDeptJobBxOrdr.do")
  public String updateDeptJobBxOrdr(
      @ModelAttribute("searchVO") DeptJobBxVO deptJobBxVO, ModelMap model) throws Exception {
    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    boolean changed = false;

    if (isAuthenticated) {
      deptJobBxVO.setLastUpdusrId(user.getUniqId());
      changed = deptJobService.updateDeptJobBxOrdr(deptJobBxVO);
    }

    if (!changed) {
      model.addAttribute("indictOrdrChanged", "false");
    }

    return "forward:/cop/smt/djm/selectDeptJobBxList.do";
  }
  /**
   * 부서업무함 정보의 수정화면으로 이동한다.
   *
   * @param DeptJobBx
   * @return String
   * @param DeptJobBx
   */
  @RequestMapping("/cop/smt/djm/modifyDeptJobBx.do")
  public String modifyDeptJobBx(
      @ModelAttribute("deptJobBxVO") DeptJobBxVO deptJobBxVO, ModelMap model) throws Exception {
    // 0. Spring Security 사용자권한 처리
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
      model.addAttribute("message", egovMessageSource.getMessage("fail.common.login"));
      return "egovframework/com/uat/uia/EgovLoginUsr";
    }

    DeptJobBxVO resultVO = deptJobService.selectDeptJobBx(deptJobBxVO);
    resultVO.setSearchCnd(deptJobBxVO.getSearchCnd());
    resultVO.setSearchWrd(deptJobBxVO.getSearchWrd());
    resultVO.setPageIndex(deptJobBxVO.getPageIndex());

    model.addAttribute("indictOrdrValue", resultVO.getIndictOrdr());
    model.addAttribute("deptJobBxVO", resultVO);

    return "egovframework/com/cop/smt/djm/EgovDeptJobBxUpdt";
  }
  /**
   * 부서업무함 정보를 수정한다.
   *
   * @param DeptJobBxVO
   * @return String
   * @param deptJobBxVO
   */
  @RequestMapping("/cop/smt/djm/updateDeptJobBx.do")
  public String updateDeptJobBx(
      @ModelAttribute("deptJobBxVO") DeptJobBxVO deptJobBxVO,
      BindingResult bindingResult,
      ModelMap model)
      throws Exception {
    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();

    beanValidator.validate(deptJobBxVO, bindingResult);
    if (bindingResult.hasErrors()) {
      // DeptJobBx result = deptJobService.selectDeptJobBx(deptJobBxVO);
      // model.addAttribute("deptJobBx", result);
      return "egovframework/com/cop/smt/djm/EgovDeptJobBxUpdt";
    }

    if (isAuthenticated) {
      deptJobBxVO.setLastUpdusrId(user.getUniqId());
      deptJobService.updateDeptJobBx(deptJobBxVO);
    }

    return "forward:/cop/smt/djm/selectDeptJobBxList.do";
  }