private String getOrgFileName(MultipartFile fName) {
logger.info("[" + new Object(){}.getClass().getEnclosingMethod().getName() + "]"); //현재 실행중인 메소드명
String orgFileName = "";
String oFileName = fName.getOriginalFilename();
if(!oFileName.equals("")) {
UUID uid = UUID.randomUUID();
orgFileName = uid + "_" + oFileName;
}
return orgFileName;
}
// QR코드 생성화면 이동(URL 등록폼)
@RequestMapping(value="/qrCode", method=RequestMethod.GET)
public String qrCodeGet() {
logger.info("[" + new Object(){}.getClass().getEnclosingMethod().getName() + "]"); //현재 실행중인 메소드명
return "qrCode/qrCode";
}
// QR코드 생성 -- 화일명에 한글지원하는 produces의 출처: https://tomining.tistory.com/202 [마이너의 일상:티스토리]
@SuppressWarnings("deprecation")
@ResponseBody
@RequestMapping(value="/qrCreate", method=RequestMethod.POST, produces="application/text;charset=utf8")
public String qrCreatePost(HttpServletRequest request, HttpSession session, String qrCodeStartNobodyOrMoveUrls, String extention) {
logger.info("[" + new Object(){}.getClass().getEnclosingMethod().getName() + "]"); //현재 실행중인 메소드명
String uploadPath = request.getSession().getServletContext().getRealPath("/resources/data/qrCode/");
String qrCodeName = customCompService.qrCreate(qrCodeStartNobodyOrMoveUrls, (String) session.getAttribute("sLoginId"), (int) session.getAttribute("sCustomId"),
uploadPath, (String) session.getAttribute("sCustomName"), extention); // qr코드가 저장될 서버경로와 qr코드 찍었을때 이동할 url을 서비스객체로 넘겨서 qr코드를 생성하게 한다.
return qrCodeName;
}
@SuppressWarnings("deprecation")
@RequestMapping(value="/loginQrCode", method=RequestMethod.POST)
public String loginQrCodePost(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartFile customImgFileName) {
logger.info("[" + new Object(){}.getClass().getEnclosingMethod().getName() + "]"); //현재 실행중인 메소드명
logger.info("<Request Param> qrFName = " + customImgFileName);
//고객사진 upload보관
String orgFileName = this.getOrgFileName(customImgFileName);
ProjectSupport ps = new ProjectSupport();
ps.writeFile(customImgFileName, orgFileName, "qrCode");
QrCodeVO qrVo = customCompService.loginQrCode(
request.getSession().getServletContext().getRealPath("/resources/data/qrCode/"),
customImgFileName.getOriginalFilename());
if (null == qrVo) return "qrCode/qrCode";
// --------------------------------------------------
// 로그인 성공시 처리 내용 : 로그인정보 세션저장
// --------------------------------------------------
// 1.오늘방문횟수, 전체방문횟수 1씩 증가
// 2.포인터 증가(1일 10회까지 방문시마다 100포인트씩 증가)
// 3.주요자료 세션 저장
// 4.아이디 저장유무에 따라 쿠키 저장
// --------------------------------------------------
CustomCompLoginDTO loginDto = customCompService.searchLogin2(qrVo.getCustomId());
if (null == loginDto) return "qrCode/qrCode";
setLoginSession(request, response, session, loginDto, "");//로그인정보 세션저장
return "redirect:/msgCustomComp/LoginOk";
}
private void setLoginSession(HttpServletRequest request, HttpServletResponse response, HttpSession session, CustomCompLoginDTO loginDto, String idSave) {
logger.info("[" + new Object(){}.getClass().getEnclosingMethod().getName() + "]"); //현재 실행중인 메소드명
//로그인 아이디,비밀번호로 회원조회가 됬을 경우, HttpSession에 조회된 회원정보 설정
session.setAttribute("sLoginId", loginDto.getLogin_id());
session.setAttribute("sGradeCode", loginDto.getCustom_grade());//고객등급
session.setAttribute("sGradeName", loginDto.getGrade_name());//고객등급명
session.setAttribute("sCustomId", loginDto.getCustom_id());//고객ID -- SEQ로 바꾸자
session.setAttribute("sCustomName", loginDto.getCustom_name());//고객명
session.setAttribute("sAddress", loginDto.getAddress());//고객회사소개-kakaoMap검색용(도로명주소)
session.setAttribute("sLoginDate", loginDto.getLogin_date());//로그인날짜
// --------------------------------------------------
// DB 저장 : 오늘방문횟수, 전체방문횟수, 포인터 100씩 증가
// --------------------------------------------------
//최종방문일과 오늘날짜 비교해서 다른 경우, 오늘방문횟수(todayCnt)값을 0으로 초기화
String todayYmdhms = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
String todayYmd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
if (null == loginDto.getLogin_date() || ! loginDto.getLogin_date().substring(0, 10).equals(todayYmd)) {
customCompService.updateTodayCnt(loginDto.getLogin_id(), loginDto.getCustom_id());//DB저장(오늘방문횟수 '0', 로그인날짜 default now())
loginDto.setToday_cnt(0);
loginDto.setLogin_date(todayYmdhms);
}
//1.오늘방문횟수, 전체방문횟수 1씩 증가
customCompService.updateVisitCntAndTodayCnt(loginDto.getLogin_id(), loginDto.getCustom_id());//DB 방문횟수 증가
loginDto.setToday_cnt(loginDto.getToday_cnt() + 1);
loginDto.setVisit_cnt(loginDto.getVisit_cnt() + 1);
if (10 >= loginDto.getToday_cnt()) {
//2.포인터 100씩 증가(방문시마다 100포인트씩 증가<DB저장>, 1일 10회 이하)
customCompService.updatePoint(loginDto.getLogin_id(), loginDto.getCustom_id());//DB 포인트 100포인트 증가
loginDto.setPoint(loginDto.getPoint() + 100);
}
// --------------------------------------------------
// 세션 저장(Mypage 회원전용방 출력용) : 오늘방문횟수, 전체방문횟수, 포인트
// --------------------------------------------------
session.setAttribute("sTodayVCnt", loginDto.getToday_cnt());
session.setAttribute("sVCnt", loginDto.getVisit_cnt());
session.setAttribute("sPoint", loginDto.getPoint());
//idSave 저장 : 쿠키에 아이디(id)를 저장 checkbox checked 클릭 여부 - on/null
if (idSave.equals("on")) {
Cookie cookie = new Cookie("cLoginId", loginDto.getLogin_id());
cookie.setMaxAge(60*60*24*7); //쿠키저장기간 : 7일(단위:초)
response.addCookie(cookie);
} else {
Cookie[] cookies = request.getCookies();
for (int i=0; i<cookies.length; i++) {
if (cookies[i].getName().equals("cLoginId")) {
cookies[i].setMaxAge(0); //쿠키저장기간 : 0일(단위:초) -> 삭제
response.addCookie(cookies[i]);
break;
}
}
}
}