TsfCustomerService.java 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. package com.style24.front.biz.service;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpSession;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.security.core.authority.SimpleGrantedAuthority;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import com.gagaframework.web.parameter.GagaMap;
  14. import com.gagaframework.web.security.GagaPasswordEncoder;
  15. import com.style24.core.biz.service.TscCustomerService;
  16. import com.style24.core.biz.service.TscKakaotalkService;
  17. import com.style24.core.biz.service.TscMailService;
  18. import com.style24.core.support.env.TscConstants;
  19. import com.style24.core.support.session.TscSession;
  20. import com.style24.core.support.util.MaskingUtils;
  21. import com.style24.front.biz.dao.TsfCustomerDao;
  22. import com.style24.front.support.security.TsfLoginDetails;
  23. import com.style24.front.support.security.session.TsfSession;
  24. import com.style24.persistence.domain.Coupon;
  25. import com.style24.persistence.domain.CustAccount;
  26. import com.style24.persistence.domain.CustContactHst;
  27. import com.style24.persistence.domain.CustDeliveryAddr;
  28. import com.style24.persistence.domain.CustGrade;
  29. import com.style24.persistence.domain.CustSnsInfo;
  30. import com.style24.persistence.domain.Customer;
  31. import com.style24.persistence.domain.Login;
  32. import com.style24.persistence.domain.WishList;
  33. import lombok.extern.slf4j.Slf4j;
  34. /**
  35. * 고객(회원) Service
  36. *
  37. * @author gagamel
  38. * @since 2020. 12. 29
  39. */
  40. @Service
  41. @Slf4j
  42. public class TsfCustomerService {
  43. @Autowired
  44. private TsfCustomerDao customerDao;
  45. @Autowired
  46. private TscCustomerService coreCustomerService;
  47. @Autowired
  48. private GagaPasswordEncoder passwordEncoder;
  49. @Autowired
  50. private TsfLoginService loginService;
  51. @Autowired
  52. private TsfCouponService couponService;
  53. @Autowired
  54. private TscKakaotalkService kakaotalkService;
  55. @Autowired
  56. private TscMailService mailService;
  57. @Autowired
  58. private ObjectMapper objectMapper;
  59. /**
  60. * 고객아이디 찾기
  61. *
  62. * @param customer - 고객정보
  63. * @return Customer
  64. * @author jsshin
  65. * @since 2021. 02. 08
  66. */
  67. public Customer getCustomerFindId(Customer customer) {
  68. TsfSession.setAttribute("maskingYn", "Y");
  69. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  70. customer.encryptData(); // 데이터 암호하
  71. return customerDao.getCustomerActiveAndDormant(customer);
  72. }
  73. /**
  74. * 고객정보찾기
  75. *
  76. * @param custNo - 고객번호
  77. * @return Customer 고객정보
  78. * @author jsshin
  79. * @since 2021. 02. 24
  80. */
  81. public Customer getCustomerFindByCustNo(Integer custNo) {
  82. Customer customer = new Customer();
  83. customer.setCustNo(custNo);
  84. customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
  85. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  86. customer.encryptData();
  87. return coreCustomerService.getCustomerInfo(customer);
  88. }
  89. /**
  90. * 휴면고객 정보 찾기
  91. *
  92. * @param custNo - 고객번호
  93. * @return Customer 고객정보
  94. * @author jsshin
  95. * @since 2021. 03. 10
  96. */
  97. public Customer getDormantCustomerFindByCustNo(Integer custNo) {
  98. Customer customer = new Customer();
  99. customer.setCustNo(custNo);
  100. customer.setCustStat(TscConstants.CustStat.DORMANT.value());
  101. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  102. customer.encryptData();
  103. return coreCustomerService.getCustomerInfo(customer);
  104. }
  105. /**
  106. * 임시비밀번호 조회
  107. * @param length - 비밀번호 자릿수
  108. * @return 임시비밀번호
  109. * @author jsshin
  110. * @since 2021. 02. 15
  111. */
  112. public String getTemporaryPassword(int length) {
  113. return coreCustomerService.getTemporaryPassword(length);
  114. }
  115. /**
  116. * 고객 비밀번호 수정
  117. * @param customer - 고객정보
  118. * @author jsshin
  119. * @since 2021. 02. 15
  120. */
  121. @Transactional("shopTxnManager")
  122. public void saveCustomerPassword(Customer customer) {
  123. customer.setEncodedPasswd(passwordEncoder.encodeSha256(customer.getPasswd()));
  124. coreCustomerService.saveCustomerPassword(customer);
  125. }
  126. /**
  127. * 해당 아이디로 가입된 이력이 있는지 확인
  128. * @param custId - 아이디
  129. * @return boolean - 있으면 TRUE/ 없으면 FALSE
  130. * @author jsshin
  131. * @since 2021. 02. 15
  132. */
  133. public boolean getCustomerFindByCustIdCount(String custId) {
  134. Customer customer = new Customer();
  135. customer.setCustId(custId);
  136. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  137. customer.encryptData();
  138. int result = customerDao.getCustomerInfoCount(customer);
  139. return result > 0;
  140. }
  141. /**
  142. * 해당 이메일로 가입된 이력이 있는지 확인
  143. * @param email - 이메일
  144. * @return boolean - 있으면 TRUE/ 없으면 FALSE
  145. * @author jsshin
  146. * @since 2021. 02. 15
  147. */
  148. public boolean getCustomerFindByEmailCount(String email) {
  149. Customer customer = new Customer();
  150. customer.setEmail(email);
  151. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  152. customer.encryptData();
  153. int result = customerDao.getCustomerInfoCount(customer);
  154. return result > 0;
  155. }
  156. /**
  157. * 해당 휴대전화로 가입된 이력이 있는지 확인
  158. * @param cellPhnno - 휴대전화
  159. * @return boolean - 있으면 TRUE/ 없으면 FALSE
  160. * @author jsshin
  161. * @since 2021. 02. 15
  162. */
  163. public boolean getCustomerFindByCellPhnnoCount(String cellPhnno) {
  164. Customer customer = new Customer();
  165. customer.setCellPhnno(cellPhnno);
  166. customer.setHypenCellPhone(); // 010-0000-0000
  167. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  168. customer.encryptData();
  169. int result = customerDao.getCustomerInfoCount(customer);
  170. return result > 0;
  171. }
  172. /**
  173. * 해당 CI로 가입된 이력이 있는지 확인
  174. * @param ci - 연계정보
  175. * @return boolean - 있으면 TRUE/ 없으면 FALSE
  176. * @author jsshin
  177. * @since 2021. 02. 15
  178. */
  179. public boolean getCustomerFindByCiCount(String ci) {
  180. Customer customer = new Customer();
  181. customer.setCi(ci);
  182. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  183. customer.encryptData();
  184. int result = customerDao.getCustomerInfoCount(customer);
  185. return result > 0;
  186. }
  187. /**
  188. * 해당 CI로 가입된 이력이 있는지 확인
  189. * @param ci - 연계정보
  190. * @return boolean - 있으면 TRUE/ 없으면 FALSE
  191. * @author jsshin
  192. * @since 2021. 02. 15
  193. */
  194. public Customer getCustomerFindByCi(String ci) {
  195. TscSession.setAttribute("maskingYn", "Y");
  196. Customer customer = new Customer();
  197. customer.setCi(ci);
  198. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  199. customer.encryptData();
  200. return customerDao.getCustomerInfo(customer);
  201. }
  202. /**
  203. * 해당 휴대폰 번호로 가입된 이력이 있는지 확인
  204. * @param cellPhnno - 휴대전화번호
  205. * @return Customer - 고객정보
  206. * @author jsshin
  207. * @since 2021. 02. 15
  208. */
  209. public Customer getCustomerFindByCellPhnno(String cellPhnno) {
  210. TscSession.setAttribute("maskingYn", "Y");
  211. Customer customer = new Customer();
  212. customer.setCellPhnno(cellPhnno);
  213. customer.setHypenCellPhone(); // 010-0000-0000
  214. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  215. customer.encryptData();
  216. return customerDao.getCustomerInfo(customer);
  217. }
  218. /**
  219. * 회원가입 처리 - 일반가입
  220. * @param customer - 일반가입
  221. * @return boolean - 가입 성공 true / 실패 false
  222. * @author jsshin
  223. * @since 2021. 02. 19
  224. */
  225. @Transactional("shopTxnManager")
  226. public boolean saveJoinCustomer(Customer customer) {
  227. boolean isJoin = true;
  228. customer.initBirthMm();
  229. customer.setHypenCellPhone();
  230. customer.encryptData();
  231. customer.setEncodedPasswd(passwordEncoder.encodeSha256(customer.getPasswd()));
  232. customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
  233. customer.setCustGb(TscConstants.CustGb.NORMAL.value());
  234. customer.setCustGrade(TscConstants.CustGrade.WELCOME.value());
  235. int custCnt = customerDao.createCustomer(customer);
  236. if (custCnt > 0) {
  237. saveJoinPostProcessing(customer);
  238. } else {
  239. isJoin = false;
  240. }
  241. if(isJoin) {
  242. Coupon coupon = couponService.getJoinCouponInfo();
  243. // 알림톡 발송
  244. try {
  245. if (StringUtils.isNotBlank(customer.getCellPhnno())) {
  246. kakaotalkService.sendJoinCongrat(customer, coupon, customer.getCustNo());
  247. }
  248. } catch (Exception e) {
  249. log.error("error", e);
  250. }
  251. // 이메일 발송
  252. try {
  253. if (StringUtils.isNotBlank(customer.getEmail())) {
  254. mailService.sendJoinCongrat(customer, coupon, customer.getCustNo());
  255. }
  256. } catch (Exception e) {
  257. log.error("error", e);
  258. }
  259. }
  260. return isJoin;
  261. }
  262. /**
  263. * 회원가입 처리 - SNS 간편가입
  264. * @param customer - SNS 정보
  265. * @return boolean - 가입 성공 true / 실패 false
  266. * @author jsshin
  267. * @since 2021. 02. 19
  268. */
  269. @Transactional("shopTxnManager")
  270. public boolean saveJoinCustomerSns(Customer customer) {
  271. boolean isJoin = true;
  272. String snsId = customer.getSnsType().equals(TscConstants.SnsType.YES24.value()) ? customer.getMemNo() : customer.getSnsId();
  273. customer.initBirthMm();
  274. customer.setEncodedPasswd(" ");
  275. customer.setCustId(customer.getSnsType() + "_" + snsId);
  276. customer.setHypenCellPhone();
  277. customer.encryptData();
  278. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  279. customer.setFrontGb(TsfSession.getFrontGb());
  280. customer.setAfLinkCd(TsfSession.getAttribute("afLinkCd"));
  281. customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
  282. customer.setCustGb(TscConstants.CustGb.NORMAL.value());
  283. customer.setCustGrade(TscConstants.CustGrade.WELCOME.value());
  284. int custCnt = customerDao.createCustomer(customer);
  285. customerDao.createCustomerSns(customer);
  286. if (custCnt > 0) {
  287. saveJoinPostProcessing(customer);
  288. TsfSession.setAttribute("custNo", String.valueOf(customer.getCustNo()));
  289. } else {
  290. isJoin = false;
  291. }
  292. if (isJoin) {
  293. Coupon coupon = couponService.getJoinCouponInfo();
  294. // 알림톡 발송
  295. try {
  296. if (StringUtils.isNotBlank(customer.getCellPhnno())) {
  297. kakaotalkService.sendJoinCongrat(customer, coupon, customer.getCustNo());
  298. }
  299. } catch (Exception e) {
  300. log.error("error", e);
  301. }
  302. // 이메일 발송
  303. try {
  304. if (StringUtils.isNotBlank(customer.getEmail())) {
  305. mailService.sendJoinCongrat(customer, coupon, customer.getCustNo());
  306. }
  307. } catch (Exception e) {
  308. log.error("error", e);
  309. }
  310. }
  311. return isJoin;
  312. }
  313. /**
  314. * 가입 후 처리 혜택(쿠폰)
  315. * @param customer - 일반가입, SNS 가입
  316. * @author jsshin
  317. * @since 2021. 02. 19
  318. */
  319. @Transactional("shopTxnManager")
  320. public void saveJoinPostProcessing(Customer customer) {
  321. // 1. 쿠폰지급 : 운영관리 > 회원등급정책관리 > WELCOME 등급
  322. Coupon coupon = new Coupon();
  323. coupon.setCustNo(customer.getCustNo());
  324. coupon.setFrontGb(customer.getFrontGb());
  325. coupon.setCustGrade(customer.getCustGrade());
  326. coupon.setCustNo(customer.getCustNo());
  327. coupon.setSiteCd(TscConstants.Site.STYLE24.value());
  328. couponService.saveJoinCoupon(coupon);
  329. }
  330. /**
  331. * Sns 정보에대한 상태 처리
  332. *
  333. * @param custSnsInfo - SNS 고객 정보
  334. * @author jsshin
  335. * @since 2021. 02. 19
  336. */
  337. @Transactional("shopTxnManager")
  338. public GagaMap customerSnsProcessing(CustSnsInfo custSnsInfo) {
  339. GagaMap resultMap = new GagaMap();
  340. Customer custInfo;
  341. // 1. snsId, snsType 값으로 연동되어져 있는지 확인
  342. custInfo = customerDao.getCusomterSnsFind(custSnsInfo);
  343. if (custInfo != null) {
  344. resultMap.setString("custStat", "SUCC_CUST");
  345. return resultMap;
  346. }
  347. if (StringUtils.isBlank(custSnsInfo.getCi())) {
  348. resultMap.setString("custStat","EMPTY_CI_CUST");
  349. return resultMap;
  350. }
  351. // 2. CI(연계정보)로 가입 되어져 있는 고객이 확인
  352. custInfo = getCustomerFindByCi(custSnsInfo.getCi());
  353. if (custInfo != null) { // 2-1. 고객정보 있는경우
  354. if (TscConstants.CustStat.SECEDE.value().equals(custInfo.getCustStat())) {
  355. resultMap.setString("custStat", "SECEDE_CUST"); // 탈퇴 회원
  356. return resultMap;
  357. }
  358. if (TscConstants.CustStat.DORMANT.value().equals(custInfo.getCustStat())) {
  359. resultMap.setString("custStat", "DORMANT_CUST"); // 휴면 회원
  360. return resultMap;
  361. }
  362. if (TscConstants.CustStat.ACTIVE.value().equals(custInfo.getCustStat())) {
  363. custInfo.setSnsId(custSnsInfo.getSnsId());
  364. custInfo.setSnsType(custSnsInfo.getSnsType());
  365. customerDao.createCustomerSns(custInfo);
  366. resultMap.setString("custStat", "SUCC_CUST");
  367. resultMap.setString("snsId", custSnsInfo.getSnsId());
  368. resultMap.setString("snsType", custSnsInfo.getSnsType());
  369. return resultMap;
  370. }
  371. } else { // 2-2. 고객정보 없는 경우
  372. if (StringUtils.isBlank(custSnsInfo.getCellPhnno())) { // 휴대전화번호가 없는 경우
  373. resultMap.setString("custStat", "EMPTY_PHONE_CUST");
  374. return resultMap;
  375. }
  376. boolean isFindByPhone = getCustomerFindByCellPhnnoCount(custSnsInfo.getCellPhnno().replace("-", ""));
  377. if (isFindByPhone) {
  378. resultMap.setString("custStat", "DUP_PHONE_CUST"); // 휴대폰 중복
  379. return resultMap;
  380. }
  381. boolean isFindByEmail = getCustomerFindByEmailCount(custSnsInfo.getEmail());
  382. if (isFindByEmail) {
  383. resultMap.setString("custStat", "DUP_EMAIL_CUST"); // 이메일 중복
  384. return resultMap;
  385. }
  386. Customer customer = objectMapper.convertValue(custSnsInfo, Customer.class);
  387. boolean isJoin = saveJoinCustomerSns(customer);
  388. if (!isJoin) {
  389. resultMap.setString("custStat", "FAIL_CUST");
  390. return resultMap;
  391. }
  392. resultMap.setString("custNo", String.valueOf(customer.getCustNo()));
  393. resultMap.setString("custStat", "NEW_CUST");
  394. }
  395. return resultMap;
  396. }
  397. /**
  398. * 로그인 처리
  399. * @param custNo- 고객번호
  400. * @param request - 요청
  401. * @author jsshin
  402. * @since 2021. 02. 18
  403. */
  404. public void getLogin(Integer custNo, HttpServletRequest request) {
  405. if (custNo == null) {
  406. throw new IllegalStateException("고객번호가 없습니다.");
  407. }
  408. Login loginParam = new Login();
  409. loginParam.setCustNo(custNo);
  410. Login loginInfo = loginService.getLoginCheckInfo(loginParam);
  411. // 권한 설정
  412. List<SimpleGrantedAuthority> authorities = new ArrayList<>();
  413. authorities.add(new SimpleGrantedAuthority(loginInfo.getCustGb()));
  414. TsfLoginDetails loginDetails = new TsfLoginDetails(loginInfo, authorities);
  415. // 최종로그인일시 Update
  416. loginService.updateLastLoginDate(loginInfo.getCustNo());
  417. // 로그인이력 생성
  418. loginService.createLoginHistory(loginInfo.getCustNo());
  419. // 세션 생성
  420. this.createSession(request, loginDetails);
  421. }
  422. /**
  423. * Session 생성
  424. *
  425. * @param request - HttpServletRequest
  426. * @param loginDetails - 로그인 상세 정보
  427. * @author jsshin
  428. * @since 2021. 02. 18
  429. */
  430. private void createSession(HttpServletRequest request, TsfLoginDetails loginDetails) {
  431. HttpSession session = request.getSession(true);
  432. session.setMaxInactiveInterval(1800);
  433. session.setAttribute("session", loginDetails);
  434. }
  435. /**
  436. * 일반고객 정보 유효성
  437. *
  438. * @param customer - 고객정보
  439. * @return GagaMap - 유효성 결과 값
  440. * @author jsshin
  441. * @since 2021. 02. 18
  442. */
  443. public GagaMap generalCustomerValidation(Customer customer) {
  444. GagaMap resultMap = new GagaMap();
  445. String maskingCustId;
  446. String custId;
  447. if (StringUtils.isNotBlank(customer.getSnsType()) && StringUtils.isNotBlank(customer.getSnsId())) {
  448. String snsId = customer.getSnsType().equals(TscConstants.SnsType.YES24.value()) ? customer.getMemNo() : customer.getSnsId();
  449. custId = customer.getSnsType() + "_" + snsId;
  450. } else {
  451. custId = customer.getCustId();
  452. }
  453. // 1. 아이디 확인
  454. boolean boolCustId = getCustomerFindByCustIdCount(custId);
  455. if (boolCustId) {
  456. maskingCustId = getMaxCustIdById(customer.getCustId());
  457. resultMap.setBoolean("isPossibe", false);
  458. resultMap.setString("maskingCustId", maskingCustId);
  459. return resultMap;
  460. }
  461. // 2. 이메일 확인
  462. boolean boolEmail = getCustomerFindByEmailCount(customer.getEmail());
  463. if (boolEmail) {
  464. maskingCustId = getMaxCustIdByEmail(customer.getEmail());
  465. resultMap.setBoolean("isPossibe", false);
  466. resultMap.setString("maskingCustId", maskingCustId);
  467. return resultMap;
  468. }
  469. // 3. 휴대전화
  470. boolean boolPhone = getCustomerFindByCellPhnnoCount(customer.getCellPhnno());
  471. if (boolPhone) {
  472. maskingCustId = getMaxCustIdByCellPhnno(customer.getCellPhnno());
  473. resultMap.setBoolean("isPossibe", false);
  474. resultMap.setString("maskingCustId", maskingCustId);
  475. return resultMap;
  476. }
  477. // 4. CI(연계정보)
  478. boolean boolCi = getCustomerFindByCiCount(customer.getCi());
  479. if (boolCi) {
  480. maskingCustId = getMaxCustIdByCi(customer.getCi());
  481. resultMap.setBoolean("isPossibe", false);
  482. resultMap.setString("maskingCustId", maskingCustId);
  483. return resultMap;
  484. }
  485. resultMap.setBoolean("isPossibe", true);
  486. return resultMap;
  487. }
  488. /**
  489. * SNS 정보로 고객 테이블 조회
  490. * @param custSnsInfo - 고객정보
  491. * @return 고객정보
  492. * @author jsshin
  493. * @since 2021. 02. 26
  494. */
  495. public Customer getCusomterSnsFind(CustSnsInfo custSnsInfo) {
  496. return customerDao.getCusomterSnsFind(custSnsInfo);
  497. }
  498. /**
  499. * 가입된 아이디 가져오기
  500. * @param custId - 고객아이디
  501. * @return String - 가입된 고객 아이디
  502. * @author jsshin
  503. * @since 2021. 03. 02
  504. */
  505. public String getMaxCustIdById(String custId) {
  506. Customer customer = new Customer();
  507. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  508. customer.setCustId(custId);
  509. String maskingCustId = customerDao.getCustomerMaxCustId(customer);
  510. return MaskingUtils.id(maskingCustId);
  511. }
  512. /**
  513. * 가입된 아이디 가져오기
  514. * @param email - 이메일
  515. * @return String - 가입된 고객 아이디
  516. * @author jsshin
  517. * @since 2021. 03. 02
  518. */
  519. public String getMaxCustIdByEmail(String email) {
  520. Customer customer = new Customer();
  521. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  522. customer.setEmail(email);
  523. customer.encryptData();
  524. String maskingCustId = customerDao.getCustomerMaxCustId(customer);
  525. return MaskingUtils.id(maskingCustId);
  526. }
  527. /**
  528. * 가입된 아이디 가져오기
  529. * @param cellPhnno - 전화번호
  530. * @return String - 가입된 고객 아이디
  531. * @author jsshin
  532. * @since 2021. 03. 02
  533. */
  534. public String getMaxCustIdByCellPhnno(String cellPhnno) {
  535. Customer customer = new Customer();
  536. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  537. customer.setCellPhnno(cellPhnno);
  538. customer.encryptData();
  539. String maskingCustId = customerDao.getCustomerMaxCustId(customer);
  540. return MaskingUtils.id(maskingCustId);
  541. }
  542. /**
  543. * 가입된 아이디 가져오기
  544. * @param ci - 연계정보
  545. * @return String - 가입된 고객 아이디
  546. * @author jsshin
  547. * @since 2021. 03. 02
  548. */
  549. public String getMaxCustIdByCi(String ci) {
  550. Customer customer = new Customer();
  551. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  552. customer.setCi(ci);
  553. customer.encryptData();
  554. String maskingCustId = customerDao.getCustomerMaxCustId(customer);
  555. return MaskingUtils.id(maskingCustId);
  556. }
  557. /**
  558. * 위시리스트 등록
  559. *
  560. * @return void
  561. * @author eskim
  562. * @since 2021. 03. 08
  563. */
  564. @Transactional("shopTxnManager")
  565. public void createWishList(Collection<WishList> wishlist) {
  566. for (WishList wishInfo : wishlist) {
  567. wishInfo.setCustNo(TsfSession.getInfo().getCustNo());
  568. wishInfo.setAfLinkCd(TsfSession.getAttribute("afLinkCd"));
  569. //wishInfo.setIthrCd(GagaCookieUtil.getCookie(TsfSession.getHttpServletRequest(), TsfConstants.CK_PREFIX + "_ithrCd"));
  570. //wishInfo.setContentsLoc(GagaCookieUtil.getCookie(TsfSession.getHttpServletRequest(), TsfConstants.CK_PREFIX + "_contentsLoc"));
  571. wishInfo.setRegNo(TsfSession.getInfo().getCustNo());
  572. customerDao.createWishList(wishInfo);
  573. }
  574. // 위시상품목록 50개만 남게 처리
  575. String goodsCd = customerDao.getDeleteGoodsWish(TsfSession.getInfo().getCustNo());
  576. WishList delWishInfo = new WishList();
  577. delWishInfo.setCustNo(TsfSession.getInfo().getCustNo());
  578. if (!StringUtils.isBlank(goodsCd)) {
  579. delWishInfo.setArrGoodsCd(goodsCd.split("\\,"));
  580. customerDao.deleteWishList(delWishInfo);
  581. }
  582. }
  583. /**
  584. * 위시리스트 삭제처리
  585. *
  586. * @param wishlist - 고객 일련번호
  587. * @return void
  588. * @author eskim
  589. * @since 2021. 03. 08
  590. */
  591. @Transactional("shopTxnManager")
  592. public void deleteWishList(Collection<WishList> wishlist) {
  593. for (WishList wishInfo : wishlist) {
  594. wishInfo.setCustNo(TsfSession.getInfo().getCustNo());
  595. customerDao.deleteWishList(wishInfo);
  596. }
  597. }
  598. /**
  599. * 휴면해제
  600. *
  601. * @param customer - 고객정보
  602. * @return GagaMap - 결과
  603. * @author jsshin
  604. * @since 2021. 03. 08
  605. */
  606. @Transactional("shopTxnManager")
  607. public GagaMap releaseDormantCustomer(Customer customer) {
  608. GagaMap result = new GagaMap();
  609. Customer custInfo = getDormantCustomerFindByCustNo(customer.getCustNo());
  610. if (!customer.getCi().equals(custInfo.getCi())) {
  611. result.setBoolean("isRelase", false);
  612. result.setString("errorType", "DIFFERENT_CI"); // 계정이 등록된 CI랑 인증한 CI가 다를떄
  613. return result;
  614. }
  615. customer.setRegNo(customer.getCustNo());
  616. customer.setUpdNo(customer.getCustNo());
  617. boolean isRelase = coreCustomerService.saveDormantCustomerRelease(customer);
  618. result.setBoolean("isRelase", isRelase);
  619. return result;
  620. }
  621. /**
  622. * 본인인증 처리
  623. *
  624. * @param customer - 본인인증키
  625. * @return GagaMap - 결과
  626. * @author jsshin
  627. * @since 2021. 03. 11
  628. */
  629. @Transactional("shopTxnManager")
  630. public GagaMap saveCertification(Customer customer) {
  631. GagaMap resultMap = new GagaMap();
  632. customer.initBirthMm();
  633. customer.setRegNo(customer.getCustNo());
  634. customer.setUpdNo(customer.getCustNo());
  635. customer.setHypenCellPhone();
  636. customer.encryptData();
  637. boolean isSuccess = false;
  638. // CI 유효성 체크
  639. Customer custInfo = getCustomerFindByCi(customer.getCi());
  640. if (custInfo != null) {
  641. TsfSession.setAttribute("maskingCustId", custInfo.getMaskingCustId());
  642. resultMap.setBoolean("isSuccess", isSuccess);
  643. return resultMap;
  644. }
  645. // 1.이력 쌓고
  646. coreCustomerService.createCustomerHistory(customer);
  647. // 2.CI 업데이트
  648. int resultCnt = customerDao.updateCustomerCi(customer);
  649. if (resultCnt > 0) {
  650. isSuccess = true;
  651. }
  652. resultMap.setBoolean("isSuccess", isSuccess);
  653. return resultMap;
  654. }
  655. /**
  656. * 비밀번호 변경 날짜 업데이트
  657. *
  658. * @param customer - 고객번호
  659. * @return GagaMap - 결과
  660. * @author jsshin
  661. * @since 2021. 03. 11
  662. */
  663. @Transactional("shopTxnManager")
  664. public GagaMap updatePasswordDate(Customer customer) {
  665. GagaMap resultMap = new GagaMap();
  666. boolean isSuccess = false;
  667. customer.setRegNo(customer.getCustNo());
  668. customer.setUpdNo(customer.getCustNo());
  669. customer.setPwdChangeDay(60); //30일간 안보여야 하기때문에 (오늘날짜 - 60) 처리
  670. // 1.이력 쌓고
  671. coreCustomerService.createCustomerHistory(customer);
  672. // 2.비밀번호 변경일자 업데이트
  673. int resultCnt = customerDao.updatePasswordDate(customer);
  674. if (resultCnt > 0) {
  675. isSuccess = true;
  676. }
  677. resultMap.setBoolean("isSuccess", isSuccess);
  678. return resultMap;
  679. }
  680. /**
  681. * 비밀번호 맞는지 확인
  682. *
  683. * @param customer - 고객정보
  684. * @return boolean
  685. * @author jsshin
  686. * @since 2021. 03. 15
  687. */
  688. public boolean customerPasswordConfirm(Customer customer) {
  689. boolean isMatch = false;
  690. Login login = new Login();
  691. login.setCustNo(TsfSession.getInfo().getCustNo());
  692. Login loginCheckInfo = loginService.getLoginCheckInfo(login);
  693. if (loginCheckInfo != null) {
  694. isMatch = passwordEncoder.matchesSha256(customer.getPasswd(), loginCheckInfo.getPasswd());
  695. }
  696. return isMatch;
  697. }
  698. /**
  699. * 본인인증을 통한 이름, 휴대전화번호 수정
  700. *
  701. * @param customer - 고객정보
  702. * @return GagaMap
  703. * @author jsshin
  704. * @since 2021. 03. 15
  705. */
  706. @Transactional("shopTxnManager")
  707. public GagaMap updateCustomerAuth(Customer customer) {
  708. GagaMap result = new GagaMap();
  709. customer.initBirthMm();
  710. customer.setRegNo(customer.getCustNo());
  711. customer.setUpdNo(customer.getCustNo());
  712. customer.setHypenCellPhone();
  713. customer.encryptData();
  714. // 1. 이력쌓고
  715. coreCustomerService.createCustomerHistory(customer);
  716. // 2. 이름, 휴대전화 번호, 생년월일 저장
  717. int updateCnt = customerDao.updateCustomerAuth(customer);
  718. boolean isSuccess = updateCnt > 0; // 변경 성공시 true
  719. result.setBoolean("isSuccess", isSuccess);
  720. return result;
  721. }
  722. /**
  723. * 고객계좌 정보
  724. *
  725. * @param custNo - 고객번호
  726. * @return CustAccount - 고객계과 정보
  727. * @author jsshin
  728. * @since 2021. 03. 18
  729. */
  730. public CustAccount getCustomerAccuontInfo(Integer custNo) {
  731. return coreCustomerService.getCustomerAccuontInfo(custNo);
  732. }
  733. /**
  734. * 고객정보 수정
  735. *
  736. * @param customer - 고객정보
  737. * @return GagaMap - 결과
  738. * @author jsshin
  739. * @since 2021. 03. 19
  740. */
  741. @Transactional("shopTxnManager")
  742. public GagaMap saveCustomerInfo(Customer customer) {
  743. GagaMap result = new GagaMap();
  744. Integer custNo = TsfSession.getInfo().getCustNo();
  745. customer.setCustNo(custNo);
  746. customer.setRegNo(custNo);
  747. customer.setUpdNo(custNo);
  748. customer.setSiteCd(TscConstants.Site.STYLE24.value());
  749. // 1. 이메일 변경여부 체크 및 변경시 유효성 체크
  750. if ("Y".equals(customer.getEmailModifyYn())) {
  751. customer.encryptData();
  752. boolean isFind = getCustomerByEmail(customer);
  753. if (isFind) {
  754. result.setBoolean("isSuccess", false);
  755. result.setString("resultType", "DUP_EMAIL");
  756. return result;
  757. }
  758. }
  759. // 2. 계좌정보 수정여부 체크
  760. if ("Y".equals(customer.getAccountModifyYn())) {
  761. CustAccount custAccount = new CustAccount();
  762. custAccount.setCustNo(custNo);
  763. custAccount.setRegNo(custNo);
  764. custAccount.setUpdNo(custNo);
  765. custAccount.setAccountNo(customer.getAccountNo());
  766. custAccount.setAccountNm(customer.getAccountNm());
  767. custAccount.setBankCd(customer.getBankCd());
  768. coreCustomerService.saveCustomerAccountInfo(custAccount);
  769. }
  770. // 3. 마케팅 수정 여부 체크
  771. if ("Y".equals(customer.getMarketingModifyYn())) {
  772. coreCustomerService.createCustomerMarketHst(customer);
  773. }
  774. // 4. 고객이력 생성
  775. coreCustomerService.createCustomerHistory(customer);
  776. // 5. 고객정보 수정
  777. customerDao.updateCustomerInfo(customer);
  778. result.setBoolean("isSuccess", true);
  779. return result;
  780. }
  781. /**
  782. * 이메일 유효성 체크 -
  783. * 본인이 사용하고 있는 이메일 제외 하고 다른 사람이
  784. * 변경하려는 이메일 사용하느지 체크
  785. *
  786. * @param customer - 이메일, 고객번호
  787. * @return GagaMap - 결과
  788. * @author jsshin
  789. * @since 2021. 03. 19
  790. */
  791. public boolean getCustomerByEmail(Customer customer) {
  792. customer.encryptData();
  793. int resultCnt = coreCustomerService.getCustomerByEmail(customer);
  794. return resultCnt > 0;
  795. }
  796. /**
  797. * 회원탈퇴 처리
  798. *
  799. * @param customer - 고객번호
  800. * @return GagaMap - 결과
  801. * @author jsshin
  802. * @since 2021. 03. 24
  803. */
  804. @Transactional("shopTxnManager")
  805. public GagaMap saveCustomerSecede(Customer customer) {
  806. return coreCustomerService.saveCustomerSecede(customer);
  807. }
  808. /**
  809. * 마이페이지 - 비밀번호 변경
  810. *
  811. * @param customer - 고객번호
  812. * @return GagaMap - 결과
  813. * @author jsshin
  814. * @since 2021. 04. 01
  815. */
  816. @Transactional("shopTxnManager")
  817. public GagaMap changePassword(Customer customer) {
  818. GagaMap resultMap = new GagaMap();
  819. boolean isSuccess = false;
  820. Login login = new Login();
  821. login.setCustNo(customer.getCustNo());
  822. Login loginCheckInfo = loginService.getLoginCheckInfo(login);
  823. if (loginCheckInfo != null) {
  824. isSuccess = passwordEncoder.matchesSha256(customer.getOrgPasswd(), loginCheckInfo.getPasswd());
  825. }
  826. if (!isSuccess) {
  827. resultMap.setBoolean("isSuccess", isSuccess);
  828. resultMap.setString("resultType", "WRONG_PWD");
  829. return resultMap;
  830. } else {
  831. customer.setTempPasswdYn("N"); // 임시비밀번호여부
  832. saveCustomerPassword(customer); // 비밀번호 수정
  833. }
  834. resultMap.setBoolean("isSuccess", isSuccess);
  835. return resultMap;
  836. }
  837. /**
  838. * 마이페이지 - 배송지 목록
  839. *
  840. * @param custDeliveryAddr - 고객번호
  841. * @return Collection<CustDeliveryAddr> - 배송목록
  842. * @author jsshin
  843. * @since 2021. 04. 01
  844. */
  845. public Collection<CustDeliveryAddr> getCustomerDeliveryAddrList(CustDeliveryAddr custDeliveryAddr) {
  846. return coreCustomerService.getCustomerDeliveryAddrList(custDeliveryAddr);
  847. }
  848. /**
  849. * 마이페이지 - 배송지 삭제
  850. *
  851. * @param custDeliveryAddr - 고객번호
  852. * @return Collection<CustDeliveryAddr> - 배송목록
  853. * @author jsshin
  854. * @since 2021. 04. 01
  855. */
  856. @Transactional("shopTxnManager")
  857. public GagaMap deleteCustDeliveryAddr(CustDeliveryAddr custDeliveryAddr) {
  858. GagaMap resultMap = new GagaMap();
  859. Integer custNo = TsfSession.getInfo().getCustNo();
  860. custDeliveryAddr.setCustNo(custNo);
  861. custDeliveryAddr.setRegNo(custNo);
  862. custDeliveryAddr.setUpdNo(custNo);
  863. int resultCnt = coreCustomerService.deleteCustDeliveryAddr(custDeliveryAddr);
  864. boolean isSuccess = resultCnt > 0;
  865. resultMap.setBoolean("isSuccess", isSuccess);
  866. return resultMap;
  867. }
  868. /**
  869. * 고객 예상등급
  870. *
  871. * @param customer - 고객번호
  872. * @return GagaMap - 예상등급
  873. * @author jsshin
  874. * @since 2021. 04. 06
  875. */
  876. public GagaMap getExpectedCustGrde(Customer customer) {
  877. GagaMap result = new GagaMap();
  878. CustGrade params = new CustGrade();
  879. params.setCustNo(customer.getCustNo());
  880. params.setSiteCd(customer.getSiteCd());
  881. Collection<CustGrade> custGradePolicy = customerDao.getCustGradePolicy(params);
  882. CustGrade expctCustGrade;
  883. for (CustGrade grade : custGradePolicy) {
  884. grade.setCustNo(customer.getCustNo());
  885. expctCustGrade = customerDao.getExpectedCustGrde(grade);
  886. if (expctCustGrade != null) {
  887. result.set("expctCustGrade", expctCustGrade);
  888. return result;
  889. }
  890. }
  891. return result;
  892. }
  893. /**
  894. * 고객 정책정보
  895. *
  896. * @param custGrade - 고객번호
  897. * @return Collection<CustGrade>
  898. * @author jsshin
  899. * @since 2021. 04. 12
  900. */
  901. public Collection<CustGrade> getCustGradePolicy(CustGrade custGrade) {
  902. return customerDao.getCustGradePolicy(custGrade);
  903. }
  904. /**
  905. * SMS수신거부 처리
  906. * @param custNo - 고객번호
  907. * @author gagamel
  908. * @since 2021. 5. 11
  909. */
  910. @Transactional("shopTxnManager")
  911. public void updateSmsReceptionRefuse(Integer custNo) {
  912. // 수신거부 처리
  913. int result = customerDao.updateSmsReceptionRefuse(custNo);
  914. if (result > 0) {
  915. Customer customer = new Customer();
  916. customer.setCustNo(custNo);
  917. customer.setSmsAgreeYn("N");
  918. customer.setRegNo(custNo);
  919. // 마케팅수신동의이력 생성
  920. coreCustomerService.createCustomerMarketHst(customer);
  921. // 고객이력 생성
  922. coreCustomerService.createCustomerHistory(customer);
  923. }
  924. }
  925. /**
  926. * 메일수신거부 처리
  927. * @param custNo - 고객번호
  928. * @author gagamel
  929. * @since 2021. 5. 11
  930. */
  931. @Transactional("shopTxnManager")
  932. public void updateEmailReceptionRefuse(Integer custNo) {
  933. // 수신거부 처리
  934. int result = customerDao.updateEmailReceptionRefuse(custNo);
  935. if (result > 0) {
  936. Customer customer = new Customer();
  937. customer.setCustNo(custNo);
  938. customer.setEmailAgreeYn("N");
  939. customer.setRegNo(custNo);
  940. // 마케팅수신동의이력 생성
  941. coreCustomerService.createCustomerMarketHst(customer);
  942. // 고객이력 생성
  943. coreCustomerService.createCustomerHistory(customer);
  944. }
  945. }
  946. /**
  947. * 고객 예상등급 이후 정보
  948. *
  949. * @param custGrade - 고객번호
  950. * @return GagaMap
  951. * @author jsshin
  952. * @since 2021. 05. 11
  953. */
  954. public GagaMap getNextCustGradeInfo(CustGrade custGrade) {
  955. GagaMap result = new GagaMap();
  956. // 1.고객 예상등급 이후 정보
  957. List<CustGrade> custGradePolicy = (List<CustGrade>) customerDao.getCustGradePolicy(custGrade);
  958. CustGrade nextCustGradePolicy = custGradePolicy.get(0);
  959. nextCustGradePolicy.setCustNo(custGrade.getCustNo());
  960. // 2.고객 예상등급 이후 정보로 주문금액 확인
  961. CustGrade nextCustGrade = customerDao.getCustGradeOrderInfo(nextCustGradePolicy);
  962. if (nextCustGrade != null) {
  963. nextCustGradePolicy.setOrdCnt(nextCustGrade.getOrdCnt());
  964. nextCustGradePolicy.setSumRealOrdAmt(nextCustGrade.getSumRealOrdAmt());
  965. } else {
  966. nextCustGradePolicy.setOrdCnt(0);
  967. nextCustGradePolicy.setSumRealOrdAmt(0);
  968. }
  969. result.set("nextCustGradePolicy", nextCustGradePolicy);
  970. return result;
  971. }
  972. /**
  973. * 앱푸시수신여부
  974. *
  975. * @return String - 앱수신여부
  976. * @author jsshin
  977. * @since 2021. 05. 20
  978. */
  979. public String getAppAgreeYn() {
  980. if (!TsfSession.isLogin()) {
  981. return "N";
  982. }
  983. Customer customer = getCustomerFindByCustNo(TsfSession.getInfo().getCustNo());
  984. if (customer != null) {
  985. return customer.getAppAgreeYn();
  986. }
  987. return "N";
  988. }
  989. /**
  990. * 앱마케팅수신여부
  991. *
  992. * @return String - 앱수신여부
  993. * @author jsshin
  994. * @since 2021. 05. 20
  995. */
  996. public String getAppMkAgreeYn() {
  997. if (!TsfSession.isLogin()) {
  998. return "N";
  999. }
  1000. Customer customer = getCustomerFindByCustNo(TsfSession.getInfo().getCustNo());
  1001. if (customer != null) {
  1002. return customer.getMkAgreeYn();
  1003. }
  1004. return "N";
  1005. }
  1006. /**
  1007. * 앱푸시수신동의여부 변경
  1008. *
  1009. * @param appAppAgreeYn - 앱푸시수신여부
  1010. * @return int - 결과
  1011. * @author jsshin
  1012. * @since 2021. 05. 20
  1013. */
  1014. @Transactional("shopTxnManager")
  1015. public int updateAppAgreeYn(String appAppAgreeYn) {
  1016. if (!TsfSession.isLogin()) {
  1017. throw new IllegalStateException("로그인 후 다시 시도하시기 바랍니다.");
  1018. }
  1019. Integer custNo = TsfSession.getInfo().getCustNo();
  1020. Customer customer = getCustomerFindByCustNo(custNo);
  1021. int resultCnt = 0;
  1022. if (customer != null) {
  1023. if (!customer.getAppAgreeYn().equals(appAppAgreeYn)) {
  1024. Customer custInfo = new Customer();
  1025. custInfo.setCustNo(custNo);
  1026. custInfo.setAppAgreeYn(appAppAgreeYn);
  1027. custInfo.setRegNo(custNo);
  1028. custInfo.setUpdNo(custNo);
  1029. coreCustomerService.createCustomerMarketHst(custInfo);
  1030. coreCustomerService.createCustomerHistory(custInfo);
  1031. resultCnt = customerDao.updateAppAgreeYn(custInfo);
  1032. }
  1033. }
  1034. return resultCnt;
  1035. }
  1036. /**
  1037. * 앱마케팅수신여부 변경
  1038. *
  1039. * @param mkAgreeYn - 마케팅 수신여부
  1040. * @return int - 결과
  1041. * @author jsshin
  1042. * @since 2021. 05. 20
  1043. */
  1044. @Transactional("shopTxnManager")
  1045. public int updateMkAgreeYn(String mkAgreeYn) {
  1046. if (!TsfSession.isLogin()) {
  1047. throw new IllegalStateException("로그인 후 다시 시도하시기 바랍니다.");
  1048. }
  1049. Integer custNo = TsfSession.getInfo().getCustNo();
  1050. Customer customer = getCustomerFindByCustNo(custNo);
  1051. int resultCnt = 0;
  1052. if (customer != null) {
  1053. if (!customer.getMkAgreeYn().equals(mkAgreeYn)) {
  1054. Customer custInfo = new Customer();
  1055. custInfo.setCustNo(custNo);
  1056. custInfo.setMkAgreeYn(mkAgreeYn);
  1057. custInfo.setRegNo(custNo);
  1058. custInfo.setUpdNo(custNo);
  1059. coreCustomerService.createCustomerMarketHst(custInfo);
  1060. coreCustomerService.createCustomerHistory(custInfo);
  1061. resultCnt = customerDao.updateMkAgreeYn(custInfo);
  1062. }
  1063. }
  1064. return resultCnt;
  1065. }
  1066. /**
  1067. * 선물하기 알림톡 발송 정보 조회
  1068. *
  1069. * @param CustContactHst
  1070. * @return int
  1071. * @author card007
  1072. * @since 2021. 06. 04
  1073. */
  1074. public int getGiftKakaoSendInfo(CustContactHst custContactHst) {
  1075. return customerDao.getGiftKakaoSendInfo(custContactHst);
  1076. }
  1077. }