/**
   * 공통상세코드를 수정한다.
   *
   * @param loginVO
   * @param cmmnDetailCode
   * @param bindingResult
   * @param commandMap
   * @param model
   * @return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeModify"
   * @throws Exception
   */
  @RequestMapping(value = "/sym/ccm/cde/EgovCcmCmmnDetailCodeModify.do")
  public String updateCmmnDetailCode(
      @ModelAttribute("loginVO") LoginVO loginVO,
      @ModelAttribute("cmmnDetailCode") CmmnDetailCode cmmnDetailCode,
      BindingResult bindingResult,
      @RequestParam Map<?, ?> commandMap,
      ModelMap model)
      throws Exception {
    String sCmd = commandMap.get("cmd") == null ? "" : (String) commandMap.get("cmd");
    if (sCmd.equals("")) {
      CmmnDetailCode vo = cmmnDetailCodeManageService.selectCmmnDetailCodeDetail(cmmnDetailCode);
      model.addAttribute("cmmnDetailCode", vo);

      return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeModify";
    } else if (sCmd.equals("Modify")) {
      beanValidator.validate(cmmnDetailCode, bindingResult);
      if (bindingResult.hasErrors()) {
        CmmnDetailCode vo = cmmnDetailCodeManageService.selectCmmnDetailCodeDetail(cmmnDetailCode);
        model.addAttribute("cmmnDetailCode", vo);

        return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeModify";
      }

      cmmnDetailCode.setLastUpdusrId(loginVO.getUniqId());
      cmmnDetailCodeManageService.updateCmmnDetailCode(cmmnDetailCode);
      return "forward:/sym/ccm/cde/EgovCcmCmmnDetailCodeList.do";
    } else {
      return "forward:/sym/ccm/cde/EgovCcmCmmnDetailCodeList.do";
    }
  }
  /**
   * 공통상세코드를 등록한다.
   *
   * @param loginVO
   * @param cmmnDetailCode
   * @param cmmnCode
   * @param bindingResult
   * @param model
   * @return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeRegist"
   * @throws Exception
   */
  @RequestMapping(value = "/sym/ccm/cde/EgovCcmCmmnDetailCodeRegist.do")
  public String insertCmmnDetailCode(
      @ModelAttribute("loginVO") LoginVO loginVO,
      @ModelAttribute("cmmnDetailCode") CmmnDetailCode cmmnDetailCode,
      @ModelAttribute("cmmnCode") CmmnCode cmmnCode,
      BindingResult bindingResult,
      @RequestParam Map<?, ?> commandMap,
      ModelMap model)
      throws Exception {

    String sCmd = commandMap.get("cmd") == null ? "" : (String) commandMap.get("cmd");
    if (cmmnDetailCode.getCodeId() == null
        || cmmnDetailCode.getCodeId().equals("")
        || cmmnDetailCode.getCode() == null
        || cmmnDetailCode.getCode().equals("")
        || sCmd.equals("")) {

      CmmnClCodeVO searchClCodeVO;
      searchClCodeVO = new CmmnClCodeVO();
      searchClCodeVO.setRecordCountPerPage(999999);
      searchClCodeVO.setFirstIndex(0);
      searchClCodeVO.setSearchCondition("CodeList");
      List<?> CmmnClCodeList = cmmnClCodeManageService.selectCmmnClCodeList(searchClCodeVO);
      model.addAttribute("cmmnClCodeList", CmmnClCodeList);

      CmmnCodeVO searchCodeVO;
      searchCodeVO = new CmmnCodeVO();
      searchCodeVO.setRecordCountPerPage(999999);
      searchCodeVO.setFirstIndex(0);
      searchCodeVO.setSearchCondition("clCode");
      if (cmmnCode.getClCode().equals("")) {
        EgovMap emp = (EgovMap) CmmnClCodeList.get(0);
        cmmnCode.setClCode(emp.get("clCode").toString());
      }
      searchCodeVO.setSearchKeyword(cmmnCode.getClCode());

      List<?> CmmnCodeList = cmmnCodeManageService.selectCmmnCodeList(searchCodeVO);
      model.addAttribute("cmmnCodeList", CmmnCodeList);

      return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeRegist";
    } else if (sCmd.equals("Regist")) {

      beanValidator.validate(cmmnDetailCode, bindingResult);
      if (bindingResult.hasErrors()) {
        CmmnClCodeVO searchClCodeVO;
        searchClCodeVO = new CmmnClCodeVO();
        searchClCodeVO.setRecordCountPerPage(999999);
        searchClCodeVO.setFirstIndex(0);
        List<?> CmmnClCodeList = cmmnClCodeManageService.selectCmmnClCodeList(searchClCodeVO);
        model.addAttribute("cmmnClCodeList", CmmnClCodeList);

        CmmnCodeVO searchCodeVO;
        searchCodeVO = new CmmnCodeVO();
        searchCodeVO.setRecordCountPerPage(999999);
        searchCodeVO.setFirstIndex(0);
        searchCodeVO.setSearchCondition("clCode");
        if (cmmnCode.getClCode().equals("")) {
          EgovMap emp = (EgovMap) CmmnClCodeList.get(0);
          cmmnCode.setClCode(emp.get("clCode").toString());
        }
        searchCodeVO.setSearchKeyword(cmmnCode.getClCode());

        List<?> CmmnCodeList = cmmnCodeManageService.selectCmmnCodeList(searchCodeVO);
        model.addAttribute("cmmnCodeList", CmmnCodeList);

        return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeRegist";
      }

      CmmnDetailCode vo = cmmnDetailCodeManageService.selectCmmnDetailCodeDetail(cmmnDetailCode);
      if (vo != null) {
        model.addAttribute("message", "이미 등록된 코드가 존재합니다.");

        CmmnClCodeVO searchClCodeVO;
        searchClCodeVO = new CmmnClCodeVO();
        searchClCodeVO.setRecordCountPerPage(999999);
        searchClCodeVO.setFirstIndex(0);
        List<?> CmmnClCodeList = cmmnClCodeManageService.selectCmmnClCodeList(searchClCodeVO);
        model.addAttribute("cmmnClCodeList", CmmnClCodeList);

        CmmnCodeVO searchCodeVO;
        searchCodeVO = new CmmnCodeVO();
        searchCodeVO.setRecordCountPerPage(999999);
        searchCodeVO.setFirstIndex(0);
        searchCodeVO.setSearchCondition("clCode");
        if (cmmnCode.getClCode().equals("")) {
          EgovMap emp = (EgovMap) CmmnClCodeList.get(0);
          cmmnCode.setClCode(emp.get("clCode").toString());
        }
        searchCodeVO.setSearchKeyword(cmmnCode.getClCode());

        List<?> CmmnCodeList = cmmnCodeManageService.selectCmmnCodeList(searchCodeVO);
        model.addAttribute("cmmnCodeList", CmmnCodeList);

        return "egovframework/com/sym/ccm/cde/EgovCcmCmmnDetailCodeRegist";
      }
      cmmnDetailCode.setFrstRegisterId(loginVO.getUniqId());
      cmmnDetailCodeManageService.insertCmmnDetailCode(cmmnDetailCode);
      return "forward:/sym/ccm/cde/EgovCcmCmmnDetailCodeList.do";
    } else {
      return "forward:/sym/ccm/cde/EgovCcmCmmnDetailCodeList.do";
    }
  }