File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.mjo.addr.web;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import itn.com.cmm.EgovMessageSource;
import itn.com.cmm.JsonResult;
import itn.com.cmm.LoginVO;
import itn.com.cmm.util.RedirectUrlMaker;
import itn.com.cmm.util.StringUtil;
import itn.com.utl.fcc.service.EgovStringUtil;
import itn.let.mjo.addr.service.AddrGroupService;
import itn.let.mjo.addr.service.AddrGroupVO;
import itn.let.mjo.addr.service.AddrService;
import itn.let.mjo.addr.service.AddrTransHistVO;
import itn.let.mjo.addr.service.AddrVO;
import itn.let.mjo.msgdata.service.PhoneVO;
/**
* 주소록 관한 controller 클래스를 정의한다.
* @author ITN
* @since 2021.04.08
* @version 1.0
* @see
*
* <pre>
* << 개정이력(Modification Information) >>
*
* 수정일 수정자 수정내용
* ------- -------- ---------------------------
* 2021.04.08 ITN 최초 생성
*
* </pre>
*/
@Controller
public class AddrController {
@Resource (name = "AddrService")
private AddrService addrService;
@Resource (name = "AddrGroupService")
private AddrGroupService addrGroupService;
/** EgovMessageSource */
@Resource(name="egovMessageSource")
EgovMessageSource egovMessageSource;
/**
* 주소록 리스트
* @param addrVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/selectAddrList.do")
public String selectAddrList(@ModelAttribute("searchVO") AddrVO addrVO
,ModelMap model) throws Exception {
if(addrVO.getPageUnit() != 10) {
addrVO.setPageUnit(addrVO.getPageUnit());
}
/** pageing */
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(addrVO.getPageIndex());
paginationInfo.setRecordCountPerPage(addrVO.getPageUnit());
paginationInfo.setPageSize(addrVO.getPageSize());
addrVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
addrVO.setLastIndex(paginationInfo.getLastRecordIndex());
addrVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
if("".equals(addrVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrVO.setSearchSortCnd("addrId");
addrVO.setSearchSortOrd("desc");
}
List<AddrVO> addrList = addrService.selectAddrNewList(addrVO);
int totCnt = 0;
if(addrList.size() > 0) {
totCnt = addrList.get(0).getTotcnt();
}
paginationInfo.setTotalRecordCount(totCnt);
model.addAttribute("addrList", addrList);
model.addAttribute("paginationInfo", paginationInfo);
return "/uss/ion/addr/AddrList";
}
/**
* 주소록 등록 페이지 이동
* @param addrVO
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/registAddr.do")
public String registAddr(ModelMap model) throws Exception {
return "/uss/ion/addr/AddrRegist";
}
/**
* 주소록 추가 로직
* @param addrVO
* @param redirectAttributes
* @param request
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/insertAddr.do")
public String insertAddr(AddrVO addrVO
,RedirectAttributes redirectAttributes
,HttpServletRequest request) throws Exception {
try {
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
if( addrVO.getMberId() == null || "".equals(addrVO.getMberId()) ) {
addrVO.setMberId(user.getId());
}
// 자주 보내는 번호
if("bookmark".equals(addrVO.getAddrGrpId())) {
addrVO.setBookmark("Y");
addrVO.setAddrGrpId("0");
}
// 주소록 그룹 내 휴대폰번호 중복체크
int usedCnt = addrService.selectDuplAddrCnt(addrVO);
if (usedCnt > 0) {
redirectAttributes.addFlashAttribute("message", "해당 그룹내 중복된 휴대폰 번호가 있습니다.");
}
else {
addrService.insertAddr(addrVO);
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.insert"));
}
}catch (Exception e) {
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("fail.common.insert"));
}
RedirectUrlMaker redirectUrlMaker = new RedirectUrlMaker("/uss/ion/addr/selectAddrList.do");
return redirectUrlMaker.getRedirectUrl();
}
/**
* 주소록 수정 로직
*
* @param addrVO
* @param redirectAttributes
* @param request
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/updateAddrByAdminAjax.do")
public ModelAndView updateAddrByAdminAjax(AddrVO addrVO
,RedirectAttributes redirectAttributes
,HttpServletRequest request
) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
try {
addrService.updateAddrByAdmin(addrVO);
}
catch(Exception e) {
System.out.println("");
isSuccess = false;
msg = "에러메시지 : " + e.getMessage();
e.printStackTrace();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
return modelAndView;
}
/**
* 주소록 수정 페이지 이동
*
* @param addrVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/editAddr.do")
public String editAddr(AddrVO addrVO
, ModelMap model ) throws Exception {
AddrVO addrInfo = addrService.selectAddrDetail(addrVO);
model.addAttribute("addrInfo", addrInfo);
return "/uss/ion/addr/AddrEdit";
}
/**
* 주소록 삭제 로직
*
* @param request
* @param addrVO
* @param redirectAttributes
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/deleteAddr.do")
public String deleteAddr (HttpServletRequest request, @ModelAttribute("searchVO") AddrVO addrVO
,RedirectAttributes redirectAttributes
,ModelMap model) throws Exception {
int result = addrService.deleteAddrByAdminAll(addrVO);
if (result > 0) {
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.delete"));
} else {
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("fail.common.delete"));
}
redirectAttributes.addAttribute("pageIndex", addrVO.getPageIndex());
redirectAttributes.addAttribute("searchCondition", addrVO.getSearchCondition());
redirectAttributes.addAttribute("searchKeyword", addrVO.getSearchKeyword());
return "redirect:/uss/ion/addr/selectAddrList.do";
}
/**
* 주소록 타 회원으로 이전(복사) 처리
* @param addrVO
* @param addrGroupVO
* @param addrTransHistVO
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/transAddrGroupAjax.do")
public ModelAndView transAddrGroupAjax(AddrVO addrVO, AddrGroupVO addrGroupVO, AddrTransHistVO addrTransHistVO) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
try {
String successCd = addrService.updateAddrAnotherMember(addrVO, addrGroupVO, addrTransHistVO);
modelAndView.addObject("status", "success");
modelAndView.addObject("result", successCd);
}catch(Exception e) {
e.printStackTrace();
modelAndView.addObject("status", "fail");
return modelAndView;
}
return modelAndView;
}
/**
* 주소록 사용자 화면 껍데기
* @param addrVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/selectAddrList.do")
public String selectAddrWebList(@ModelAttribute("searchVO") AddrVO addrVO
,AddrGroupVO addrGroupVO, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId == "") {
/*redirectAttributes.addFlashAttribute("fail", true);*/
//redirectAttributes.addFlashAttribute("message", "문자온 서비스는 로그인 후 이용 가능합니다.");
return "redirect:/web/user/login/login.do";
}
return "/web/addr/AddrList";
}
/**
* 사용자 주소록 리스트 Ajax
* @param request
* @param model
* @param addrVO
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/selectAddrAjax.do")
public String selectAddrAjax(HttpServletRequest request, ModelMap model,
@ModelAttribute("searchVO") AddrVO addrVO) throws Exception {
//로그인 권한정보 불러오기
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
}
if(addrVO.getPageUnit() != 10) {
addrVO.setPageUnit(addrVO.getPageUnit());
}
/** pageing */
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(addrVO.getPageIndex());
paginationInfo.setRecordCountPerPage(addrVO.getPageUnit());
paginationInfo.setPageSize(addrVO.getPageSize());
addrVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
addrVO.setLastIndex(paginationInfo.getLastRecordIndex());
addrVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
if("".equals(addrVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrVO.setSearchSortCnd("addrId");
addrVO.setSearchSortOrd("desc");
}
List<AddrVO> addrList = addrService.selectAddrList(addrVO);
int totCnt = 0;
if(addrList.size() > 0) {
totCnt = addrList.get(0).getTotcnt();
}
paginationInfo.setTotalRecordCount(totCnt);
model.addAttribute("paginationInfo", paginationInfo);
model.addAttribute("addrList", addrList);
model.addAttribute("startKeyword",addrVO.getStartKeyword());
model.addAttribute("userId", userId);
return "/web/addr/AddrListAjax";
}
/**
* 사용자 주소록 중복 리스트 Ajax
* @param request
* @param model
* @param addrVO
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/selectAddrDupliAjax.do")
public String selectAddrDupliAjax(HttpServletRequest request, ModelMap model,
@ModelAttribute("searchVO") AddrVO addrVO) throws Exception {
//로그인 권한정보 불러오기
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
}
if(addrVO.getPageUnit() != 10) {
addrVO.setPageUnit(addrVO.getPageUnit());
}
/** pageing */
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(addrVO.getPageIndex());
paginationInfo.setRecordCountPerPage(addrVO.getPageUnit());
paginationInfo.setPageSize(addrVO.getPageSize());
addrVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
addrVO.setLastIndex(paginationInfo.getLastRecordIndex());
addrVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
if("".equals(addrVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrVO.setSearchSortCnd("addrId");
addrVO.setSearchSortOrd("desc");
}
List<AddrVO> addrDupliList = addrService.selectAddrDupliListByAll(addrVO);
int totCnt = 0;
if(addrDupliList.size() > 0) {
totCnt = addrDupliList.get(0).getTotcnt();
}
paginationInfo.setTotalRecordCount(totCnt);
model.addAttribute("paginationInfo2", paginationInfo);
model.addAttribute("addrDupliList", addrDupliList);
return "/web/addr/AddrListDupliAjax";
}
@RequestMapping("/web/mjon/addr/selectAddrPrint.do")
public String selectAddrPrint(@RequestParam("cellCheck2") String[] cellCheck,
AddrVO addrVO,
HttpServletRequest request,
HttpServletResponse response ,
ModelMap model) throws Exception {
//로그인 권한정보 불러오기
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
}
addrVO.setRecordCountPerPage(100000);
addrVO.setFirstIndex(0);
List<AddrVO> addrList = addrService.selectAddrList(addrVO);
String chk = "";
for(int i=0; i<cellCheck.length; i++ ) {
chk += cellCheck[i] + ",";
}
model.addAttribute("chk", chk);
model.addAttribute("addrList", addrList);
return "/web/addr/AddrListPrint";
}
/**
* 주소록 상세정보 ajax
* @param addrCheck
* @param request
* @param addrVO
* @param model
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/selectAddrDetailAjax.do")
public ModelAndView selectAddrDetailAjax(HttpServletRequest request,
AddrVO addrVO, Model model) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
AddrVO addrInfo = null;
try {
addrInfo = addrService.selectAddrDetail(addrVO);
} catch (Exception e) {
isSuccess = false;
msg = e.getMessage();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
modelAndView.addObject("addrInfo", addrInfo);
return modelAndView;
}
/**
* 주소록 그룹 삭제 로직 ajax
*
* @param request
* @param addrGroupVO
* @param redirectAttributes
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/deleteAddrAjax.do")
public ModelAndView deleteAddrAjax(@RequestParam(value="addrCheck", defaultValue="0") String[] addrCheck, HttpServletRequest request,
AddrVO addrVO, Model model
,RedirectAttributes redirectAttributes
) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
addrVO.setLastUpdusrId(user.getId());
addrVO.setMberId(user.getId());
//단일삭제
if(!"".equals(addrVO.getAddrId())) {
addrCheck[0] = addrVO.getAddrId();
}
for(String id:addrCheck) {
try {
addrVO.setAddrId(id);
addrService.deleteAddr(addrVO);
modelAndView.addObject("result", "success");
} catch (Exception e) {
e.printStackTrace();
modelAndView.addObject("result", "fail");
return modelAndView;
}
}
return modelAndView;
}
/**
* 주소록 등록 로직 (ajax)
* @param addrVO
* @param request
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/insertAddrAjax.do")
public ModelAndView insertAddrAjax(HttpServletRequest request, ModelMap model,
AddrVO addrVO
) throws Exception {
ModelAndView mv = new ModelAndView();
mv.setViewName("jsonView");
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
addrVO.setMberId(userId);
if("bookmark".equals(addrVO.getAddrGrpId())) {
addrVO.setBookmark("Y");
addrVO.setAddrGrpId("0");
}
int usedCnt = addrService.selectDuplAddrCnt(addrVO);
if(usedCnt > 0) {
mv.addObject("result","dupl");
}else {
if(userId != "") {
try {
addrService.insertAddr(addrVO);
mv.addObject("result","success");
} catch (Exception e) {
e.printStackTrace();
mv.addObject("result","fail");
}
} else {
mv.addObject("result","fail");
}
}
return mv;
}
/**
* 주소록 다중수정 ajax
* @param addrCheck
* @param request
* @param addrVO
* @param model
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/updateAddrListAjax.do")
public ModelAndView updateAddrListAjax(HttpServletRequest request,
AddrVO addrVO, Model model
,RedirectAttributes redirectAttributes
) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
addrVO.setLastUpdusrId(user.getId());
addrVO.setMberId(user.getId());
int listSize = addrVO.getAddrIds().length;
for(int i=0; i<listSize; i++) {
try {
// JSP 2023.04.07 => 주소록그룹 수정 추가
if (addrVO.getAddrGrpIds()[i].equals("bookmark")) {
// 자주보내는 번호
addrVO.setAddrGrpId("0");
addrVO.setBookmark("Y");
}
else {
addrVO.setAddrGrpId(addrVO.getAddrGrpIds()[i]);
addrVO.setBookmark("N");
}
addrVO.setAddrId(addrVO.getAddrIds()[i]);
if(addrVO.getAddrPhones().length > 0) {
addrVO.setAddrPhoneNo(addrVO.getAddrPhones()[i]);
}
else {
addrVO.setAddrPhoneNo(null);
}
if(addrVO.getAddrNms().length > 0) {
addrVO.setAddrNm(addrVO.getAddrNms()[i]);
}
else {
addrVO.setAddrNm(null);
}
if(!addrVO.getAddrInfo1s()[i].equals(null) || !"".equals(addrVO.getAddrInfo1s()[i])) {
addrVO.setAddrInfo1(addrVO.getAddrInfo1s()[i]);
}else {
addrVO.setAddrInfo1("");
}
if(!addrVO.getAddrInfo2s()[i].equals(null) || !"".equals(addrVO.getAddrInfo2s()[i])) {
addrVO.setAddrInfo2(addrVO.getAddrInfo2s()[i]);
}else {
addrVO.setAddrInfo2("");
}
if(!addrVO.getAddrInfo3s()[i].equals(null) || !"".equals(addrVO.getAddrInfo3s()[i])) {
addrVO.setAddrInfo3(addrVO.getAddrInfo3s()[i]);
}else {
addrVO.setAddrInfo3("");
}
if(!addrVO.getAddrInfo4s()[i].equals(null) || !"".equals(addrVO.getAddrInfo4s()[i])) {
addrVO.setAddrInfo4(addrVO.getAddrInfo4s()[i]);
}else {
addrVO.setAddrInfo4("");
}
addrService.updateAddr(addrVO);
modelAndView.addObject("result", "success");
} catch (Exception e) {
e.printStackTrace();
modelAndView.addObject("result", "fail");
return modelAndView;
}
}
return modelAndView;
}
/**
* 주소록 다중수정 ajax
* @param addrCheck
* @param request
* @param addrVO
* @param model
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/updateAddrAjax.do")
public ModelAndView updateAddrAjax(@RequestParam("addrCheck") String[] addrCheck, HttpServletRequest request,
AddrVO addrVO, Model model
,RedirectAttributes redirectAttributes
) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
addrVO.setLastUpdusrId(user.getId());
addrVO.setMberId(user.getId());
for(String id:addrCheck) {
try {
if("0".equals (addrVO.getAddrGrpId())) {
addrVO.setBookmark("Y");
} else if(addrVO.getAddrGrpId() != null && !"".equals(addrVO.getAddrGrpId())) {
addrVO.setBookmark("N");
}
addrVO.setAddrId(id);
addrService.updateMemoAddr(addrVO);
modelAndView.addObject("result", "success");
} catch (Exception e) {
e.printStackTrace();
modelAndView.addObject("result", "fail");
return modelAndView;
}
}
return modelAndView;
}
/**
* 주소록 그룹이동 ajax
* @param addrCheck
* @param request
* @param addrVO
* @param model
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/updateAddrMoveGrpAjax.do")
public ModelAndView updateAddrMoveGrpAjax(@RequestParam("addrCheck") String[] addrCheck,
@RequestParam("addrPhoneNos") String[] addrPhoneNos,
HttpServletRequest request,
AddrVO addrVO, Model model,
RedirectAttributes redirectAttributes
) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
addrVO.setLastUpdusrId(user.getId());
addrVO.setMberId(user.getId());
// 그룹미지정, 자주보내는 번호 구분처리
if("0".equals (addrVO.getAddrGrpId())) {
// 그룹미지정
addrVO.setBookmark("N");
}
else if("bookmark".equals (addrVO.getAddrGrpId())) {
// 자주보내는 번호
addrVO.setBookmark("Y");
addrVO.setAddrGrpId("0");
}
else if(addrVO.getAddrGrpId() != null && !"".equals(addrVO.getAddrGrpId())) {
addrVO.setBookmark("N");
}
/**
* 보내려는 그룹에 등록되어있는 전화번호를 변수에 담아둠
*/
List<?> addrPhoneList = addrService.selectPhoneNumInAddrGroup(addrVO);
String phoneNos = "";
for(int i=0; i<addrPhoneList.size(); i++) {
if(i == 0) {
phoneNos = ((AddrVO)addrPhoneList.get(i)).getAddrPhoneNo();
} else {
phoneNos = phoneNos + "," + ((AddrVO)addrPhoneList.get(i)).getAddrPhoneNo();
}
}
/**
* 2. 넘어온 주소록 id를 db조회하여 리스트로 받아옴
*/
String duplYn = "N";
for(String phoneNo:addrPhoneNos) {
if(phoneNos != null && phoneNos.contains(phoneNo)) {
modelAndView.addObject("result","dupl");
duplYn = "Y";
break;
}
}
if(duplYn == "N") {
for(String id:addrCheck) {
try {
addrVO.setAddrId(id);
addrService.updateAddrGrp(addrVO);
modelAndView.addObject("result", "success");
} catch (Exception e) {
e.printStackTrace();
modelAndView.addObject("result", "fail");
return modelAndView;
}
}
}
return modelAndView;
}
/**
* 주소록 복사 ajax
* @param addrCheck
* @param request
* @param addrVO
* @param model
* @param redirectAttributes
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/insertCopyAddrAjax.do")
public ModelAndView insertCopyAddrAjax(@RequestParam("addrCheck") String[] addrCheck,
@RequestParam("addrPhoneNos") String[] addrPhoneNos,
HttpServletRequest request,
AddrVO addrVO, Model model,
RedirectAttributes redirectAttributes
) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
addrVO.setMberId(user.getId());
// 그룹미지정, 자주보내는 번호 구분처리
if("0".equals (addrVO.getAddrGrpId())) {
// 그룹미지정
addrVO.setBookmark("N");
}
else if("bookmark".equals (addrVO.getAddrGrpId())) {
// 자주보내는 번호
addrVO.setBookmark("Y");
addrVO.setAddrGrpId("0");
}
else if(addrVO.getAddrGrpId() != null && !"".equals(addrVO.getAddrGrpId())) {
addrVO.setBookmark("N");
}
/**
* 복사하려는 그룹에 등록되어있는 전화번호를 변수에 담아둠
*/
List<?> addrPhoneList = addrService.selectPhoneNumInAddrGroup(addrVO);
String phoneNos = "";
for(int i=0; i<addrPhoneList.size(); i++) {
if(i == 0) {
phoneNos = ((AddrVO)addrPhoneList.get(i)).getAddrPhoneNo();
} else {
phoneNos = phoneNos + "," + ((AddrVO)addrPhoneList.get(i)).getAddrPhoneNo();
}
}
/**
* 2. 넘어온 주소록 id를 db조회하여 리스트로 받아옴
*/
String duplYn = "N";
for(String phoneNo:addrPhoneNos) {
if(phoneNos != null && phoneNos.contains(phoneNo)) {
modelAndView.addObject("result","dupl");
duplYn = "Y";
break;
}
}
if(duplYn == "N") {
for(String id:addrCheck) {
try {
addrVO.setAddrId(id);
addrService.insertCopyAddr(addrVO);
modelAndView.addObject("result", "success");
} catch (Exception e) {
e.printStackTrace();
modelAndView.addObject("result", "fail");
return modelAndView;
}
}
}
return modelAndView;
}
/**
* 주소록 그룹 내 휴대폰번호 중복체크
*
* @param addrVO
* @return
* @throws Exception
*/
@RequestMapping("/uss/ion/addr/selectDuplAddrAjax.do")
public ModelAndView selectDuplAddrAjax(AddrVO addrVO) throws Exception {
ModelAndView mv = new ModelAndView();
mv.setViewName("jsonView");
int usedCnt = addrService.selectDuplAddrCnt(addrVO);
mv.addObject("usedCnt", usedCnt);
return mv;
}
/**
* 주소록 폰주소록 가이드 이동
*
* @param addrVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/web/mjon/addr/addrMobGuide.do")
public String addrMobGuide(ModelMap model) throws Exception {
return "/web/addr/AddrMobGuide";
}
/**
* 선택한 주소록을 문자전송 화면으로 보내기
* @param addrVO
* @param req
* @param model
* @return
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/selectAddrDataListAjax.do"})
public ModelAndView selectAddrDataListAjax(
AddrVO addrVO,
HttpServletRequest req,
ModelMap model) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId.equals("")) {
modelAndView.addObject("status", "loginFail");
modelAndView.addObject("message", "로그인이 필요합니다.");
return modelAndView;
}else {
addrVO.setMberId(userId);
}
List<String> addrIdList = addrVO.getAddrIdList();
List<String> tempList = new ArrayList<String>();
for(String seqStr : addrIdList) {
String seqId = seqStr.replace("[", "");
seqId = seqId.replace("]", "");
tempList.add(seqId);
}
addrVO.setAddrIdList(tempList);
List<AddrVO> resultList = addrService.selectAddrDataList(addrVO);
if(resultList == null) {
modelAndView.addObject("status", "emptyList");
modelAndView.addObject("message", "가져온 주소록 목록이 없습니다.");
}else {
modelAndView.addObject("status", "success");
modelAndView.addObject("resultList", resultList);
modelAndView.addObject("resultListCnt", resultList.size());
}
return modelAndView;
}
//주소록 엑셀 다운로드
@RequestMapping("/web/mjon/addr/addrExcelDownload.do")
public void addrExcelDownload(@RequestParam("cellCheck") String[] cellCheck,
AddrVO addrVO,
HttpServletRequest request,
HttpServletResponse response ,
ModelMap model) throws Exception {
addrVO.setRecordCountPerPage(100000);
addrVO.setFirstIndex(0);
if("".equals(addrVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrVO.setSearchSortCnd("addrId");
addrVO.setSearchSortOrd("desc");
}
LoginVO loginVO = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
SXSSFWorkbook wb = new SXSSFWorkbook(100);
CellStyle styleHeader = wb.createCellStyle();
styleHeader.setBorderBottom(CellStyle.BORDER_THIN); //테두리 두껍게
styleHeader.setBorderLeft(CellStyle.BORDER_THIN);
styleHeader.setBorderRight(CellStyle.BORDER_THIN);
styleHeader.setBorderTop(CellStyle.BORDER_THIN);
CellStyle styleList = wb.createCellStyle();
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD); //글씨 bold
Cell cell = null;
Row row = null;
String fileName ="주소록";
String sheetTitle = "";
try{
if("".equals(addrVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrVO.setSearchSortOrd("desc");
}
addrVO.setMberId(loginVO.getId());
List<AddrVO> addrList = addrService.selectAddrList(addrVO);
{
// row, cell 개수 순서대로 증가용 필드
int rowNumber = 0;
int celNumber = 0;
//화면 리스트
sheetTitle = "주소록" ; //제목
Sheet sheet = wb.createSheet(sheetTitle);
row = sheet.createRow(rowNumber++);
row = sheet.createRow(rowNumber++); //줄추가
//cell = row.createCell(celNumber++);
//cell.setCellValue("번호");
//cell.setCellStyle(style);
int y = 0;
for(String field : cellCheck) {
//셀 칼럼 크기 설정
sheet.setColumnWidth(y, 4000);
cell = row.createCell(celNumber++);
cell.setCellValue(addrVO.getHeaderName(field));
cell.setCellStyle(styleHeader);
y++;
}
for(int i=0; i < addrList.size(); i++){
row = sheet.createRow(rowNumber++); //줄추가
celNumber = 0;
//cell = row.createCell(celNumber++);
//cell.setCellStyle(style);
//cell.setCellValue(i+1); //번호
for(String field : cellCheck) {
cell = row.createCell(celNumber++);
cell.setCellStyle(styleList);
cell.setCellValue(((AddrVO)addrList.get(i)).getFieldValue(field));
}
}
}
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat ( "yyyy_MM_dd_HH_mm_ss", Locale.KOREA );
Date currentTime = new Date ();
String mTime = mSimpleDateFormat.format ( currentTime );
fileName = fileName+"("+mTime+")";
response.setHeader("Content-Disposition", String.format("attachment; filename=\""+new String((fileName).getBytes("KSC5601"),"8859_1")+".xlsx"));
wb.write(response.getOutputStream());
}catch(Exception e) {
response.setHeader("Set-Cookie", "fileDownload=false; path=/");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Content-Type","text/html; charset=utf-8");
OutputStream out = null;
try {
out = response.getOutputStream();
byte[] data = new String("fail..").getBytes();
out.write(data, 0, data.length);
} catch(Exception ignore) {
ignore.printStackTrace();
} finally {
if(out != null) try { out.close(); } catch(Exception ignore) {}
}
}finally {
// 디스크 적었던 임시파일을 제거합니다.
wb.dispose();
try { wb.close(); } catch(Exception ignore) {}
}
}
/**
* 주소록 대량등록 - 엑셀파일 불러오기
* @param body
* @param uploadFile
* @param search
* @param result
* @param model
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "/web/mjon/addr/sendExelFilePhoneNumAjax.do")
@ResponseBody
public Object sendExelFilePhoneNumAjax(final MultipartHttpServletRequest multiRequest) throws Exception {
JsonResult jr = new JsonResult();
jr.setSuccess(false);
jr.setMessage("엑셀 파일만 업로드할 수 있습니다.");
//final Map<String, MultipartFile> files = multiRequest.getFileMap();
List<MultipartFile> files = (List<MultipartFile>) multiRequest.getFiles("file0");
// 파일명에 .이 있을경우 오류 => Ex) 테스트6.20.xlsx
int fileNameSplitCnt = 0;
if(!files.isEmpty()) {
fileNameSplitCnt = files.get(0).getOriginalFilename().split("[.]").length;
//System.out.println("fileNameSplitCnt : " + fileNameSplitCnt);
if (files.get(0).getSize() > 0
&& (files.get(0).getContentType().indexOf("spreadsheetml") > -1)
|| files.get(0).getContentType().indexOf("ms-excel") > -1
|| files.get(0).getOriginalFilename().split("[.]")[fileNameSplitCnt-1].indexOf("xlsx") > -1
|| files.get(0).getOriginalFilename().split("[.]")[fileNameSplitCnt-1].indexOf("xls") > -1) {
// 엑셀 파일 용량 3MB이상 시 10만건 이상으로 서버가 다운되는 증상 발생
long fileSize = multiRequest.getFile("file0").getSize();
if(fileSize > 3374653) {
jr.setMessage("엑셀 파일은 3MB를 넘을수 없습니다.");
return jr;
}
String Ext = files.get(0).getOriginalFilename().split("[.]")[1];
String errMessage = "";
String cellValue = "";
//String phoneRegExp = "^01(?:0|1|[6-9])[.-]?(\\d{3}|\\d{4})[.-]?(\\d{4})$";
String phoneRegExp = "^(050[234567]{1}|01[016789]{1})-?[0-9]{3,4}-?[0-9]{4}$";
int errPhoneCnt = 0;
int errNameCnt = 0;
int errRep1Cnt = 0;
int errRep2Cnt = 0;
int errRep3Cnt = 0;
int errRep4Cnt = 0;
int errMemoCnt = 0;
//엑셀 확장자에 따른 처리 로직 분리
if(Ext.equals("xls")) {
HSSFWorkbook workbook = new HSSFWorkbook(files.get(0).getInputStream());
HSSFSheet sheet = workbook.getSheetAt(0);
if(sheet.getLastRowNum() > 20000) { //
errMessage = "2만줄 이상의 업로드는 데이터 부하로 업로드 할수 없습니다.";
jr.setSuccess(false);
jr.setMessage(errMessage);
return jr;
}
List<HashMap<String, String>> json = new ArrayList<HashMap<String, String>>();
PhoneVO pVO = new PhoneVO();
for(int i=2; i< sheet.getLastRowNum() + 2; i++){ //먼저 밸리데이션 체크(1줄은 생략)
HSSFRow row = sheet.getRow(i); //열읽기
if(null == row) {
continue;
}
HashMap<String, String> jm = new HashMap<>();
// 행의 두번째 열(이름부터 받아오기)
HSSFCell cell = null;
boolean errSts = true;
for(int j = 0 ; j < 7; j++){ //행읽기(6행까지나 2행까지만 필요)
cellValue = "";
cell = row.getCell(j); //이름/핸드폰/info1/info2/info3/info4/메모
if(null == cell || "".equals(cell.toString().trim())) { //셀에 값이 없으면
if(j == 1) {
if (sheet.getLastRowNum() == i) {
continue;
}
//errPhoneCnt++;
//errSts = false;
break;
}
}
if(null != cell){
switch(cell.getCellType()){ //숫자타임을 문자로 변환
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
}
cellValue = StringUtil.getString(cell.getStringCellValue().trim()) ;
}
if(j == 0) {
//이름
boolean nmChk = getNameRepLenChk("name", cellValue);
if(nmChk && errSts) {
jm.put("name", cellValue);
}else {
errNameCnt++;
errSts = false;
break;
}
}
if(j == 1) {
// 문자열에서 숫자만 추출
cellValue = getOnlyNumber(cellValue);
//전화번호
if(cellValue.matches(phoneRegExp) && errSts) {
jm.put("phone", cellValue);
}else {
errPhoneCnt++;
errSts = false;
break;
}
}
if(j == 2) {
//치환1
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info1", cellValue);
}else {
errRep1Cnt++;
errSts = false;
break;
}
}
if(j == 3) {
//치환2
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info2", cellValue);
}else {
errRep2Cnt++;
errSts = false;
break;
}
}
if(j == 4) {
//치환3
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info3", cellValue);
}else {
errRep3Cnt++;
errSts = false;
break;
}
}
if(j == 5) {
//치환4
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info4", cellValue);
}else {
errRep4Cnt++;
errSts = false;
break;
}
}
if(j == 6) {
//메모
boolean repChk = getNameRepLenChk("memo", cellValue);
if(repChk && errSts) {
jm.put("memo", cellValue);
}else {
errMemoCnt++;
errSts = false;
break;
}
}
}
if(null != jm.get("phone")) {
json.add(jm);
}
}
int resultErrCnt = errPhoneCnt + errNameCnt + errRep1Cnt + errRep2Cnt + errRep3Cnt + errRep4Cnt + errMemoCnt;
jr.setData(json);
jr.setSuccess(true);
if(resultErrCnt > 0) {
jr.setMessage("올바르지 않은 휴대폰 번호가 "+ resultErrCnt +" 건 있습니다.");
}else {
jr.setMessage("");
}
}else { //확장자가 xlsx
OPCPackage opcPackage = OPCPackage.open(files.get(0).getInputStream());
XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
XSSFSheet sheet = workbook.getSheetAt(0); // 첫번째 시트 불러오기
opcPackage.close();
int totRowDataCnt = 0;
for(int r=1; r<sheet.getPhysicalNumberOfRows(); r++) {
XSSFRow tmpRow = sheet.getRow(r);
//System.out.println("=================r:"+r);
XSSFCell cell = null;
if(tmpRow.getCell(1) != null) {
cell = tmpRow.getCell(1); //이름/핸드폰/변환1/변환2/변환3/변환4/변환5
if(cell != null && !cell.toString().trim().equals("")) {
//System.out.println("value-" + r + ":" +cell.getStringCellValue());
totRowDataCnt++;
//System.out.println("tmpRowCnt:"+totRowDataCnt);
}
}
}
System.out.println("+++++++++++++++++ totRowDataCnt ::: "+totRowDataCnt);
//if(sheet.getLastRowNum() > 20000) { //
if(totRowDataCnt > 20001) {
System.out.println("totRowDataCnt : " + totRowDataCnt);
errMessage = "2만줄 이상의 업로드는 데이터 부하로 업로드 할수 없습니다.";
jr.setSuccess(false);
jr.setMessage(errMessage);
return jr;
}
List<HashMap<String, String>> json = new ArrayList<HashMap<String, String>>();
PhoneVO pVO = new PhoneVO();
System.out.println("sheet.getLastRowNum() : " + sheet.getLastRowNum());
for(int i=2; i< sheet.getLastRowNum() + 2; i++){ //먼저 밸리데이션 체크(1줄은 생략)
XSSFRow row = sheet.getRow(i); //열읽기
if(null == row) {
continue;
}
HashMap<String, String> jm = new HashMap<>();
// 행의 두번째 열(핸드폰부터 받아오기)
XSSFCell cell = null;
boolean errSts = true;
for(int j = 0 ; j < 7; j++){ //행읽기(6행까지나 2행까지만 필요)
cellValue = "";
cell = row.getCell(j); //이름/핸드폰/변환1/변환2/변환3/변환4/변환5/메모
if(null == cell || "".equals(cell.toString().trim())) { //셀에 값이 없으면
if(j == 1) {
if (sheet.getLastRowNum() == i) {
continue;
}
//errPhoneCnt++;
//errSts = false;
break;
}
}
if(null != cell){
switch(cell.getCellType()){ //숫자타임을 문자로 변환
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
}
cellValue = StringUtil.getString(cell.getStringCellValue().trim()) ;
}
if(j == 0) {
//이름
boolean nmChk = getNameRepLenChk("name", cellValue);
if(nmChk && errSts) {
jm.put("name", cellValue);
}else {
errNameCnt++;
errSts = false;
break;
}
}
if(j == 1) {
// 문자열에서 숫자만 추출
cellValue = getOnlyNumber(cellValue);
//전화번호
if(cellValue.matches(phoneRegExp) && errSts) {
jm.put("phone", cellValue);
}else {
errPhoneCnt++;
errSts = false;
break;
}
}
if(j == 2) {
//치환1
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info1", cellValue);
}else {
errRep1Cnt++;
errSts = false;
break;
}
}
if(j == 3) {
//치환2
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info2", cellValue);
}else {
errRep2Cnt++;
errSts = false;
break;
}
}
if(j == 4) {
//치환3
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info3", cellValue);
}else {
errRep3Cnt++;
errSts = false;
break;
}
}
if(j == 5) {
//치환4
boolean repChk = getNameRepLenChk("rep", cellValue);
if(repChk && errSts) {
jm.put("info4", cellValue);
}else {
errRep4Cnt++;
errSts = false;
break;
}
}
if(j == 6) {
//메모
boolean repChk = getNameRepLenChk("memo", cellValue);
if(repChk && errSts) {
jm.put("memo", cellValue);
}else {
errMemoCnt++;
errSts = false;
break;
}
}
}
if(null != jm.get("phone") && errSts) {
json.add(jm);
}
}
int resultErrCnt = errPhoneCnt + errNameCnt + errRep1Cnt + errRep2Cnt + errRep3Cnt + errRep4Cnt;
jr.setData(json);
jr.setSuccess(true);
if(resultErrCnt > 0) {
jr.setMessage("올바르지 않은 휴대폰 번호가 "+ resultErrCnt +" 건 있습니다.");
}else {
jr.setMessage("");
}
} //xlsx 처리 끝
}
else {
String ttt = files.get(0).getSize() + "_" +
files.get(0).getContentType() + "_" +
files.get(0).getOriginalFilename().split("[.]")[fileNameSplitCnt-1];
jr.setSuccess(false);
jr.setMessage("엑셀파일 인식오류.");
//jr.setMessage("엑셀파일 인식오류" + ttt);
}
}
else {
jr.setSuccess(false);
jr.setMessage("엑셀파일 인식오류.");
}
return jr;
}
/**
* 주소록 대량등록 - TXT파일 불러오기
* @param body
* @param uploadFile
* @param search
* @param result
* @param model
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "/web/mjon/addr/sendTxtFilePhoneNumAjax.do")
@ResponseBody
public Object sendTxtFilePhoneNumAjax(final MultipartHttpServletRequest multiRequest) throws Exception {
JsonResult jr = new JsonResult();
jr.setSuccess(false);
jr.setMessage("TXT 파일만 업로드할 수 있습니다.");
List<MultipartFile> files = (List<MultipartFile>) multiRequest.getFiles("file0");
if(!files.isEmpty()) {
if (files.get(0).getSize() > 0
|| files.get(0).getOriginalFilename().split("[.]")[1].indexOf("txt") > -1) {
// txt 파일 용량 3MB이상 시 10만건 이상으로 서버가 다운되는 증상 발생
long fileSize = multiRequest.getFile("file0").getSize();
if(fileSize > 3374653) {
jr.setMessage("txt 파일은 3MB를 넘을수 없습니다.");
return jr;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(multiRequest.getFile("file0").getInputStream()));
String line = null;
String[] splitedStr = null;
String[] tempStr = null;
int errPhoneCnt = 0;
int totRowNum = 0;
//String phoneRegExp = "^01(?:0|1|[6-9])[.-]?(\\d{3}|\\d{4})[.-]?(\\d{4})$";
String phoneRegExp = "^(050[234567]{1}|01[016789]{1})-?[0-9]{3,4}-?[0-9]{4}$";
List<HashMap<String, String>> json = new ArrayList<HashMap<String, String>>();
//파일 읽어서 탭으로 구분해주기
while ((line = reader.readLine()) != null) {
HashMap<String, String> jm = new HashMap<>();
splitedStr = null;
tempStr = null;
//txt 파일의 데이터가 탭 혹은 콤마로 구분되어 있는지 구분처리
tempStr = line.split("\\,");
if(tempStr.length > 1) {
splitedStr = line.split("\\,");
}else {
splitedStr = line.split("\t");;
}
for (int i = 0; i < splitedStr.length; i++) {
splitedStr[i] = splitedStr[i].trim();
if(i == 0) {
//이름
jm.put("name", splitedStr[i]);
}
if(i == 1) {
// 문자열에서 숫자만 추출
splitedStr[i] = getOnlyNumber(splitedStr[i]);
if(splitedStr[i].matches(phoneRegExp)) {
//휴대폰 번호
jm.put("phone", splitedStr[i]);
}else {
errPhoneCnt++;
}
}
if(i == 2) {
//info1
jm.put("info1", splitedStr[i]);
}
if(i == 3) {
//info2
jm.put("info2", splitedStr[i]);
}
if(i == 4) {
//info3
jm.put("info3", splitedStr[i]);
}
if(i == 5) {
//info4
jm.put("info4", splitedStr[i]);
}
if(i == 6) {
//메모
jm.put("memo", splitedStr[i]);
}
}
if(jm.get("phone") != null) {
json.add(jm);
}
totRowNum++;
} // end while
jr.setData(json);
jr.setSuccess(true);
if (totRowNum > 20000) {
jr.setMessage("20000");
}
else {
if(errPhoneCnt > 0) {
jr.setMessage("올바르지 않은 휴대폰 번호가 "+ errPhoneCnt +" 건 있습니다.");
}else {
jr.setMessage("");
}
}
}
}
return jr;
}
/**
* 주소록 대량등록 저장
* @param searchVO
* @param model
* @return "/web/mjon/addr/addrMassInsertByTempAjax.do"
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/addrMassInsertByTempAjax.do"})
public ModelAndView addrMassInsertByTempAjax(@ModelAttribute("searchVO") AddrVO addrVO,
RedirectAttributes redirectAttributes,
ModelMap model) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
//String phoneRegExp = "^01(?:0|1|[6-9])[.-]?(\\d{3}|\\d{4})[.-]?(\\d{4})$";
String phoneRegExp = "^(050[234567]{1}|01[016789]{1})-?[0-9]{3,4}-?[0-9]{4}$";
String charset = "euc-kr";
boolean isSuccess = true;
String msg = "";
int resultCnt = 0;
int dupliCnt = 0; // 중복 데이터 수
int errPhoneCnt = 0;
List<AddrVO> addrMassDupliList = new ArrayList<AddrVO>(); // 중복 휴대폰번호
try {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId.equals("")) {
isSuccess = false;
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", "로그인 후 이용이 가능합니다.");
return modelAndView;
}
else {
addrVO.setMberId(userId);
}
//회원별 주소록 전체 갯수 조회
int addrBefAfterCnt = 0;
int addrBefCnt = addrService.selectAddrTotalCount(addrVO);
int addrNewCnt = addrVO.getPhoneList().length; //신규 추가할 주소록 갯수
int sumAddrCnt = addrBefCnt + addrNewCnt; //기존 + 신규 주소록 합산
// 신규 주소록 여부 체크
if (addrVO.getAddrGrpId().equals("NEW")) {
AddrGroupVO addrGroupVO = new AddrGroupVO();
addrGroupVO.setMberId(userId);
addrGroupVO.setAddrGrpNm(addrVO.getAddrGrpNm());
// 정렬순서
int nextOrderNumber = addrGroupService.selectMaxOrderNumber(addrGroupVO);
addrGroupVO.setGrpOrder(nextOrderNumber);
addrGroupService.insertAddrGroup(addrGroupVO);
// 신규 추가한 그룹아이디
addrVO.setAddrGrpId(addrGroupVO.getAddrGrpId());
}
// 그룹미지정, 자주보내는 번호 구분처리
if("bookmark".equals (addrVO.getAddrGrpId())) {
// 자주보내는 번호
addrVO.setBookmark("Y");
addrVO.setAddrGrpId("0");
}
else {
addrVO.setBookmark("N");
}
List<AddrVO> addrDataInfo = new ArrayList<AddrVO>();
if(addrBefCnt < 100000) { // 기존 등록된 주소록이 10만건 미만이면
//받는사람 리스트 건수 체크해주기
if(sumAddrCnt > 100000) {
isSuccess = false;
msg = "주소록은 총 10만개까지만 등록이 가능합니다.";
}
else {
for(int i=0; i < addrNewCnt; i++) {
AddrVO tempAddrVO = new AddrVO();
if(addrVO.getNameList().length > 0) {
if(addrVO.getNameList()[i].equals("-")) {
tempAddrVO.setAddrNm(null);
}else {
String tmpNm = addrVO.getNameList()[i].trim().replaceAll("§", ",");
int nmLen = tmpNm.getBytes(charset).length;
if(nmLen >= 20) {
//isSuccess = false;
//msg = "이름 항목의 내용(\" " + tmpNm + " \")이 길이를 초과하여 입력되었습니다. 12글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrNm(subStringBytes(addrVO.getNameList()[i].replaceAll("§", ","), 20, 2));
}else {
tempAddrVO.setAddrNm(addrVO.getNameList()[i].trim().replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrNm(null);
}
if(addrVO.getPhoneList().length > 0) {
if(addrVO.getPhoneList()[i].equals("-")) {
tempAddrVO.setAddrPhoneNo(null);
}else {
tempAddrVO.setAddrPhoneNo(addrVO.getPhoneList()[i].trim().replaceAll("§", ","));
}
}
else {
tempAddrVO.setAddrPhoneNo(null);
}
if(addrVO.getInfo1List().length > 0) {
if(addrVO.getInfo1List()[i].equals("-")) {
tempAddrVO.setAddrInfo1(null);
}else {
String tmpInfo1 = addrVO.getInfo1List()[i].replaceAll("§", ",");
int info1Len = tmpInfo1.getBytes(charset).length;
if(info1Len >= 40) {
//isSuccess = false;
//msg = "[*1*] 항목의 내용(\" " + tmpInfo1 + " \")이 길이를 초과하여 입력되었습니다. 20글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrInfo1(subStringBytes(addrVO.getInfo1List()[i].replaceAll("§", ","), 40, 2));
}else {
tempAddrVO.setAddrInfo1(addrVO.getInfo1List()[i].replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrInfo1(null);
}
if(addrVO.getInfo2List().length > 0) {
if(addrVO.getInfo2List()[i].equals("-")) {
tempAddrVO.setAddrInfo2(null);
}else {
String tmpInfo2 = addrVO.getInfo2List()[i].replaceAll("§", ",");
int info2Len = tmpInfo2.getBytes(charset).length;
if(info2Len >= 40) {
//isSuccess = false;
//msg = "[*2*] 항목의 내용(\" " + tmpInfo2 + " \")이 길이를 초과하여 입력되었습니다. 20글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrInfo2(subStringBytes(addrVO.getInfo2List()[i].replaceAll("§", ","), 40, 2));
}else {
tempAddrVO.setAddrInfo2(addrVO.getInfo2List()[i].replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrInfo2(null);
}
if(addrVO.getInfo3List().length > 0) {
if(addrVO.getInfo3List()[i].equals("-")) {
tempAddrVO.setAddrInfo3(null);
}else {
String tmpInfo3 = addrVO.getInfo3List()[i].replaceAll("§", ",");
int info3Len = tmpInfo3.getBytes(charset).length;
if(info3Len >= 40) {
//isSuccess = false;
//msg = "[*3*] 항목의 내용(\" " + tmpInfo3 + " \")이 길이를 초과하여 입력되었습니다. 20글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrInfo3(subStringBytes(addrVO.getInfo3List()[i].replaceAll("§", ","), 40, 2));
}else {
tempAddrVO.setAddrInfo3(addrVO.getInfo3List()[i].replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrInfo3(null);
}
if(addrVO.getInfo4List().length > 0) {
if(addrVO.getInfo4List()[i].equals("-")) {
tempAddrVO.setAddrInfo4(null);
}else {
String tmpInfo4 = addrVO.getInfo4List()[i].replaceAll("§", ",");
int info4Len = tmpInfo4.getBytes(charset).length;
if(info4Len >= 40) {
//isSuccess = false;
//msg = "[*4*] 항목의 내용(\" " + tmpInfo4 + " \")이 길이를 초과하여 입력되었습니다. 20글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrInfo4(subStringBytes(addrVO.getInfo4List()[i].replaceAll("§", ","), 40, 2));
}else {
tempAddrVO.setAddrInfo4(addrVO.getInfo4List()[i].replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrInfo4(null);
}
if(addrVO.getMemoList().length > 0) {
if(addrVO.getMemoList()[i].equals("-")) {
tempAddrVO.setAddrComment(null);
}else {
String tmpComment = addrVO.getMemoList()[i].replaceAll("§", ",");
int commLen = tmpComment.getBytes(charset).length;
if(commLen >= 200) {
//isSuccess = false;
//msg = "메모 항목의 내용(\" " + tmpComment + " \")이 길이를 초과하여 입력되었습니다. 100글자 이하로 입력해 주세요.";
//break;
tempAddrVO.setAddrComment(subStringBytes(addrVO.getMemoList()[i].replaceAll("§", ","), 200, 2));
}else {
tempAddrVO.setAddrComment(addrVO.getMemoList()[i].replaceAll("§", ","));
}
}
}
else {
tempAddrVO.setAddrComment(null);
}
tempAddrVO.setMberId(userId);
tempAddrVO.setFrstRegisterId(userId);
tempAddrVO.setAddrGrpId(addrVO.getAddrGrpId()); // 그룹 지정
// 그룹미지정, 자주보내는 번호 구분처리
if("Y".equals (addrVO.getBookmark())) {
// 자주보내는 번호
tempAddrVO.setBookmark("Y");
tempAddrVO.setAddrGrpId("0");
}
else {
tempAddrVO.setBookmark("N");
}
AddrVO addrVO2 = new AddrVO();
addrVO2.setMberId(userId);
addrVO2.setAddrGrpId(addrVO.getAddrGrpId()); // 그룹 지정
addrVO2.setAddrPhoneNo(addrVO.getPhoneList()[i]); // 연락처
// 휴대폰 유효성 검사
boolean isPhoneNoErr = true;
if(addrVO.getPhoneList()[i].matches(phoneRegExp)) {
isPhoneNoErr = false; // 유효성 통과
}else {
errPhoneCnt++;
}
//int usedCnt = addrService.selectDuplAddrCnt(addrVO2);
if(isPhoneNoErr == false) {
//주소록 리스트에 데이터 추가해 주기
addrDataInfo.add(tempAddrVO);
}
}
System.out.println("======================================================");
System.out.println("+++++++++++++++++++++++++ isSuccess ::: "+isSuccess);
System.out.println("======================================================");
//주소록에 데이터 추가해 주기
if (isSuccess == true && addrDataInfo.size() > 0) {
// 주소록 대량등록 By Temp 주소록 All
resultCnt = addrService.insertAddrByTempAddrAll(addrDataInfo, addrVO);
addrBefAfterCnt = addrService.selectAddrTotalCount(addrVO);
addrMassDupliList = addrService.selectTempAddrDupliList(addrVO);
resultCnt = addrBefAfterCnt - addrBefCnt;
dupliCnt = addrNewCnt - resultCnt;
}
}
}
else {
isSuccess = false;
msg = "주소록은 총 10만개까지만 등록이 가능합니다.";
}
}
catch(Exception e) {
isSuccess = false;
msg = "주소록 저장에 오류가 발생하였습니다. 시스템 관리자에게 문의 바랍니다.";
System.out.println("==============================================");
System.out.println("+++++++++++++++++++ addrMassInsertByTempAjax Error ::: "+e.getMessage());
System.out.println("==============================================");
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
modelAndView.addObject("resultCnt", resultCnt);
modelAndView.addObject("dupliCnt", dupliCnt);
modelAndView.addObject("errPhoneCnt", errPhoneCnt);
modelAndView.addObject("addrMassDupliList", addrMassDupliList);
return modelAndView;
}
/* 바이트 자르기
UTF-8일 경우
subStringBytes("블라블라블라라", 10, 3);
EUC-KR일 경우
subStringBytes("블라블라블라라", 10, 2);
*/
public String subStringBytes(String str, int byteLength, int sizePerLetter) {
int retLength = 0;
int tempSize = 0;
int asc;
if (str == null || "".equals(str) || "null".equals(str)) {
str = "";
}
int length = str.length();
for (int i = 1; i <= length; i++) {
asc = (int) str.charAt(i - 1);
if (asc > 127) {
if (byteLength >= tempSize + sizePerLetter) {
tempSize += sizePerLetter;
retLength++;
}
} else {
if (byteLength > tempSize) {
tempSize++;
retLength++;
}
}
}
return str.substring(0, retLength);
}
/**
* 주소록 그룹 목록
* @param searchVO
* @param model
* @return "/web/mjon/addr/addrGroupListAjax.do"
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/addrGroupListAjax.do"})
public ModelAndView addrGroupListAjax(@ModelAttribute("searchVO") AddrGroupVO addrGroupVO,
RedirectAttributes redirectAttributes,
ModelMap model) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
List<AddrGroupVO> addrGroupList = null;
try {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrGroupVO.setMberId(userId);
if(addrGroupVO.getPageUnit() != 10) {
addrGroupVO.setPageUnit(addrGroupVO.getPageUnit());
}
if("".equals(addrGroupVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
addrGroupVO.setSearchSortCnd("grpOrder");
addrGroupVO.setSearchSortOrd("desc");
}
addrGroupVO.setSiteId("web");
addrGroupList = addrGroupService.selectAddrGroupList(addrGroupVO);
}
}
catch(Exception e) {
isSuccess = false;
msg = e.getMessage();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
model.addAttribute("addrGroupList", addrGroupList);
return modelAndView;
}
/**
* 주소록 그룹별 중복 연락처 목록
* @param searchVO
* @param model
* @return "/web/mjon/addr/addrDupliListAjax.do"
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/addrDupliListAjax.do"})
public ModelAndView addrDupliListAjax(@ModelAttribute("searchVO") AddrVO addrVO,
RedirectAttributes redirectAttributes,
ModelMap model) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
List<AddrVO> addrDupliList = null;
try {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
// 주소록 그룹별 중복 연락처 목록
addrDupliList = addrService.selectAddrDupliList(addrVO);
}
}
catch(Exception e) {
isSuccess = false;
msg = e.getMessage();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
model.addAttribute("addrDupliList", addrDupliList);
return modelAndView;
}
/**
* 주소록 그룹별 중복 연락처 삭제
* @param searchVO
* @param model
* @return "/web/mjon/addr/deleteAddrDupliList.do"
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/deleteAddrDupliListAjax.do"})
public ModelAndView deleteAddrDupliListAjax(@ModelAttribute("searchVO") AddrVO addrVO,
RedirectAttributes redirectAttributes,
ModelMap model) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
try {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
// 주소록 그룹별 중복 연락처 삭제
addrService.deleteAddrDupliList(addrVO);
}
else {
isSuccess = false;
msg = "로그인후 이용하세요.";
}
}
catch(Exception e) {
isSuccess = false;
msg = e.getMessage();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
return modelAndView;
}
/**
* 주소록 그룹별 중복 연락처 삭제
* @param searchVO
* @param model
* @return "/web/mjon/addr/deleteAddrByAllDupliListAjax.do"
* @throws Exception
*/
@RequestMapping(value= {"/web/mjon/addr/deleteAddrByAllDupliListAjax.do"})
public ModelAndView deleteAddrByAllDupliListAjax(@ModelAttribute("searchVO") AddrVO addrVO,
RedirectAttributes redirectAttributes,
ModelMap model) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
boolean isSuccess = true;
String msg = "";
try {
LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
if(userId != "") {
addrVO.setMberId(userId);
// 주소록 그룹별 중복 연락처 삭제
addrService.deleteAddrDupliListByAll(addrVO);
}
else {
isSuccess = false;
msg = "로그인후 이용하세요.";
}
}
catch(Exception e) {
isSuccess = false;
msg = e.getMessage();
}
modelAndView.addObject("isSuccess", isSuccess);
modelAndView.addObject("msg", msg);
return modelAndView;
}
public boolean getNameRepLenChk(String type, String value) {
boolean rtnValue = true;
// JSPark 2023.02.17 : 글자길이체크 주석처리 => 저장시 절삭하기 때문
/*
if(type.equals("name")) {
String tmpNm = value;
int nmLen = tmpNm.length();
if(nmLen > 12) {
rtnValue = false;
}
}else if(type.equals("rep")) {
String tmpRep = value;
int repLen = tmpRep.length();
if(repLen > 20) {
rtnValue = false;
}
}else if(type.equals("memo")) {
String tmpRep = value;
int repLen = tmpRep.length();
if(repLen > 120) {
rtnValue = false;
}
}
*/
return rtnValue;
}
// 문자열에서 숫자만 추출
public String getOnlyNumber(String str) {
//String str = "aaa1234, ^&*2233pp";
String intStr = str.replaceAll("[^\\d]", "");
return intStr;
}
}