/**
   * 부서업무 정보를 수정한다.
   *
   * @param DeptJob
   * @return String
   * @param deptJob
   */
  @RequestMapping("/cop/smt/djm/updateDeptJob.do")
  public String updateDeptJob(
      final MultipartHttpServletRequest multiRequest,
      Map commandMap,
      @ModelAttribute("deptJobVO") DeptJobVO deptJobVO,
      BindingResult bindingResult,
      ModelMap model)
      throws Exception {
    LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();

    beanValidator.validate(deptJobVO, bindingResult);
    if (bindingResult.hasErrors()) {
      DeptJob deptJob = deptJobService.selectDeptJob(deptJobVO);
      model.addAttribute("deptJob", deptJob);
      return "egovframework/com/cop/smt/djm/EgovDeptJobUpdt";
    }

    if (isAuthenticated) {
      /* *****************************************************************
           	// 첨부파일 관련 ID 생성 start....
      ****************************************************************** */
      String _atchFileId = deptJobVO.getAtchFileId();

      final Map<String, MultipartFile> files = multiRequest.getFileMap();

      if (!files.isEmpty()) {
        String atchFileAt =
            commandMap.get("atchFileAt") == null ? "" : (String) commandMap.get("atchFileAt");
        if ("N".equals(atchFileAt)) {
          List<FileVO> _result = fileUtil.parseFileInf(files, "DSCH_", 0, _atchFileId, "");
          _atchFileId = fileMngService.insertFileInfs(_result);

          // 첨부파일 ID 셋팅
          deptJobVO.setAtchFileId(_atchFileId); // 첨부파일 ID

        } else {
          FileVO fvo = new FileVO();
          fvo.setAtchFileId(_atchFileId);
          int _cnt = fileMngService.getMaxFileSN(fvo);
          List<FileVO> _result = fileUtil.parseFileInf(files, "DSCH_", _cnt, _atchFileId, "");
          fileMngService.updateFileInfs(_result);
        }
      }

      deptJobVO.setLastUpdusrId(user.getUniqId());
      deptJobService.updateDeptJob(deptJobVO);
    }

    return "forward:/cop/smt/djm/selectDeptJobList.do";
  }
  /**
   * 부서업무함 등록시 표시순서를 조회한다.
   *
   * @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
   */
  @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 DeptVO
   * @return String
   * @param deptVO
   */
  @RequestMapping("/cop/smt/djm/selectDeptList.do")
  public String selectDeptList(@ModelAttribute("searchVO") DeptVO deptVO, ModelMap model)
      throws Exception {
    // LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();

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

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

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

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

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

    return "egovframework/com/cop/smt/djm/EgovDeptList";
  }
 /**
  * 부서업무함 정보를 삭제한다.
  *
  * @param DeptJobBx
  * @return String
  * @param DeptJobBx
  */
 @RequestMapping("/cop/smt/djm/deleteDeptJobBx.do")
 public String deleteDeptJobBx(@ModelAttribute("deptJobBxVO") DeptJobBx deptJobBx, 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";
   }
   deptJobService.deleteDeptJobBx(deptJobBx);
   return "forward:/cop/smt/djm/selectDeptJobBxList.do";
 }
  /**
   * 부서업무함 정보를 등록한다.
   *
   * @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 DeptJobVO
   * @return String
   * @param deptJobVO
   */
  @IncludedInfo(name = "부서업무정보", order = 401, gid = 40)
  @RequestMapping("/cop/smt/djm/selectDeptJobList.do")
  public String selectDeptJobList(@ModelAttribute("searchVO") DeptJobVO deptJobVO, ModelMap model)
      throws Exception {
    // LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();

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

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

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

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

    if (deptJobVO.getSearchDeptId() == null || deptJobVO.getSearchDeptId().equals("")) {
      deptJobVO.setSearchDeptId(loginVO.getOrgnztId());
    }

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

    model.addAttribute("resultBxList", deptJobService.selectDeptJobBxListAll());
    // model.addAttribute("deptId", loginVO.getOrgnztId());
    model.addAttribute("resultList", map.get("resultList"));
    model.addAttribute("resultCnt", map.get("resultCnt"));
    model.addAttribute("paginationInfo", paginationInfo);

    return "egovframework/com/cop/smt/djm/EgovDeptJobList";
  }
  /**
   * 부서업무 정보를 등록한다.
   *
   * @param DeptJob
   * @return String
   * @param deptJob
   */
  @RequestMapping("/cop/smt/djm/insertDeptJob.do")
  public String insertDeptJob(
      final MultipartHttpServletRequest multiRequest,
      @ModelAttribute("deptJobVO") DeptJobVO deptJobVO,
      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/EgovDeptJobRegist";

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

    // 첨부파일 관련 첨부파일ID 생성
    List<FileVO> _result = null;
    String _atchFileId = "";

    final Map<String, MultipartFile> files = multiRequest.getFileMap();

    if (!files.isEmpty()) {
      _result = fileUtil.parseFileInf(files, "DSCH_", 0, "", "");
      _atchFileId = fileMngService.insertFileInfs(_result); // 파일이 생성되고나면 생성된 첨부파일 ID를 리턴한다.
    }

    // 리턴받은 첨부파일ID를 셋팅한다..
    deptJobVO.setAtchFileId(_atchFileId); // 첨부파일 ID

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

    deptJobService.insertDeptJob(deptJobVO);
    sLocationUrl = "forward:/cop/smt/djm/selectDeptJobList.do";

    return sLocationUrl;
  }
  /**
   * 부서업무 정보를 조회한다.
   *
   * @param DeptJobVO
   * @return String
   * @param deptJobVO
   */
  @RequestMapping("/cop/smt/djm/selectDeptJob.do")
  public String selectDeptJob(@ModelAttribute("deptJobVO") DeptJobVO deptJobVO, ModelMap model)
      throws Exception {
    DeptJob deptJob = deptJobService.selectDeptJob(deptJobVO);
    model.addAttribute("deptJob", deptJob);

    /*
     * 공통코드
     * 우선순위 조회
     */
    ComDefaultCodeVO voComCode = new ComDefaultCodeVO();
    voComCode.setCodeId("COM059");
    List<CmmnDetailCode> listComCode = cmmUseService.selectCmmCodeDetail(voComCode);
    model.addAttribute("priort", listComCode);

    return "egovframework/com/cop/smt/djm/EgovDeptJobDetail";
  }
  /**
   * 부서업무 정보의 등록화면으로 이동한다.
   *
   * @param DeptJob
   * @return String
   * @param deptJob
   */
  @RequestMapping("/cop/smt/djm/addDeptJob.do")
  public String addDeptJob(@ModelAttribute("deptJobVO") DeptJobVO deptJobVO, ModelMap model)
      throws Exception {
    String sLocationUrl = "egovframework/com/cop/smt/djm/EgovDeptJobRegist";

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

    deptJobVO.setDeptId(deptJobVO.getSearchDeptId());
    deptJobVO.setDeptNm(deptJobService.selectDept(deptJobVO.getSearchDeptId()));
    deptJobVO.setDeptJobBxId(deptJobVO.getSearchDeptJobBxId());

    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 DeptJob
   * @return String
   * @param deptJob
   */
  @RequestMapping("/cop/smt/djm/modifyDeptJob.do")
  public String modifyDeptJob(@ModelAttribute("deptJobVO") DeptJobVO deptJobVO, 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";
    }

    DeptJobVO resultVO = deptJobService.selectDeptJob(deptJobVO);
    resultVO.setSearchCnd(deptJobVO.getSearchCnd());
    resultVO.setSearchWrd(deptJobVO.getSearchWrd());
    resultVO.setSearchDeptId(deptJobVO.getSearchDeptId());
    resultVO.setSearchDeptJobBxId(deptJobVO.getSearchDeptJobBxId());
    resultVO.setPageIndex(deptJobVO.getPageIndex());
    model.addAttribute("deptJobVO", resultVO);

    return "egovframework/com/cop/smt/djm/EgovDeptJobUpdt";
  }
  /**
   * 부서업무 정보를 삭제한다.
   *
   * @param DeptJob
   * @return String
   * @param deptJob
   */
  @RequestMapping("/cop/smt/djm/deleteDeptJob.do")
  public String deleteDeptJob(@ModelAttribute("deptJobVO") DeptJob deptJob, 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";
    }

    // 첨부파일 삭제를 위한 ID 생성 start....
    String _atchFileId = deptJob.getAtchFileId();

    // 첨부파일을 삭제하기 위한  Vo
    FileVO fvo = new FileVO();
    fvo.setAtchFileId(_atchFileId);

    fileMngService.deleteAllFileInf(fvo);
    // 첨부파일 삭제 End.............

    deptJobService.deleteDeptJob(deptJob);
    return "forward:/cop/smt/djm/selectDeptJobList.do";
  }
  /**
   * 부서업무함 정보를 수정한다.
   *
   * @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";
  }