TsaCouponService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. package com.style24.admin.biz.service;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Collection;
  6. import java.util.Date;
  7. import com.google.gson.Gson;
  8. import com.google.gson.reflect.TypeToken;
  9. import com.style24.persistence.domain.*;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import com.fasterxml.jackson.core.type.TypeReference;
  15. import com.fasterxml.jackson.databind.ObjectMapper;
  16. import com.style24.admin.biz.dao.TsaCouponDao;
  17. import com.style24.admin.support.security.session.TsaSession;
  18. import lombok.extern.slf4j.Slf4j;
  19. /**
  20. * 쿠폰 Service
  21. *
  22. * @author xyzp1539
  23. * @since 2021. 01. 11
  24. */
  25. @Service
  26. @Slf4j
  27. public class TsaCouponService {
  28. @Autowired
  29. private TsaCouponDao couponDao;
  30. @Autowired
  31. private TsaCommonService commonService;
  32. /**
  33. * 쿠폰 저장
  34. * @param params
  35. * @author xyzp1539
  36. * @since 2021-01-11
  37. */
  38. @Transactional("shopTxnManager")
  39. public void saveCoupon(Coupon params) {
  40. String cpnId = ""; // 쿠폰ID
  41. params.setRegNo(TsaSession.getInfo().getUserNo());
  42. params.setUpdNo(TsaSession.getInfo().getUserNo());
  43. // 자동생성이면 시퀀스 가져오기
  44. if(StringUtils.isBlank(params.getCpnId())) {
  45. Integer sequence = commonService.getNextSequence("SEQ_COUPON");
  46. cpnId = "CPN"+sequence;
  47. } else {
  48. cpnId = params.getCpnId();
  49. }
  50. params.setCpnId(cpnId);
  51. couponDao.couponInsert(params);
  52. Gson gson = new Gson();
  53. Integer sequence;
  54. // 적용대상 - 공급업체
  55. Collection<CouponRefval> supplyCompList = gson.fromJson(params.getSupplyCompList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
  56. for(CouponRefval supplyComp : supplyCompList) {
  57. sequence = null;
  58. if(supplyComp.getCpnRefvalSq() != null && supplyComp.getCpnRefvalSq() > 0){
  59. sequence = supplyComp.getCpnRefvalSq();
  60. }
  61. supplyComp.setCpnId(cpnId);
  62. supplyComp.setCpnRefvalSq(sequence);
  63. supplyComp.setCpnTarget("G260_13");
  64. supplyComp.setRefVal(supplyComp.getSupplyCompCd());
  65. supplyComp.setRegNo(TsaSession.getInfo().getUserNo());
  66. supplyComp.setUpdNo(TsaSession.getInfo().getUserNo());
  67. couponDao.saveCouponRefVal(supplyComp);
  68. }
  69. // 적용대상 - 브랜드
  70. Collection<CouponRefval> brandList = gson.fromJson(params.getBrandList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
  71. for(CouponRefval brand : brandList) {
  72. sequence = null;
  73. if(brand.getCpnRefvalSq() != null && brand.getCpnRefvalSq() > 0){
  74. sequence = brand.getCpnRefvalSq();
  75. }
  76. brand.setCpnId(cpnId);
  77. brand.setCpnRefvalSq(sequence);
  78. brand.setCpnTarget("G260_12");
  79. brand.setRefVal(brand.getBrandCd());
  80. brand.setRegNo(TsaSession.getInfo().getUserNo());
  81. brand.setUpdNo(TsaSession.getInfo().getUserNo());
  82. couponDao.saveCouponRefVal(brand);
  83. }
  84. // 적용대상 - 적용상품
  85. Collection<CouponRefval> applyGoodsList = gson.fromJson(params.getApplyGoodsList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
  86. for(CouponRefval applyGoods : applyGoodsList ) {
  87. sequence = null;
  88. if(applyGoods.getCpnRefvalSq() != null && applyGoods.getCpnRefvalSq() > 0){
  89. sequence = applyGoods.getCpnRefvalSq();
  90. }
  91. applyGoods.setCpnId(cpnId);
  92. applyGoods.setCpnRefvalSq(sequence);
  93. applyGoods.setCpnTarget("G260_10");
  94. applyGoods.setRefVal(applyGoods.getGoodsCd());
  95. applyGoods.setRegNo(TsaSession.getInfo().getUserNo());
  96. applyGoods.setUpdNo(TsaSession.getInfo().getUserNo());
  97. couponDao.saveCouponRefVal(applyGoods);
  98. }
  99. // 적용대상 - 카테고리
  100. Collection<CouponRefval> cateList = gson.fromJson(params.getCateList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
  101. for(CouponRefval cate : cateList ) {
  102. sequence = null;
  103. if(cate.getCpnRefvalSq() != null && cate.getCpnRefvalSq() > 0){
  104. sequence = cate.getCpnRefvalSq();
  105. }
  106. cate.setCpnId(cpnId);
  107. cate.setCpnRefvalSq(sequence);
  108. cate.setCpnTarget("G260_11");
  109. cate.setRefVal(cate.getCateNo());
  110. cate.setRefFormalGb(cate.getFormalGb());
  111. cate.setRefBrandCd(cate.getBrandCd()); // ag-grid 브랜드코드
  112. cate.setRegNo(TsaSession.getInfo().getUserNo());
  113. cate.setUpdNo(TsaSession.getInfo().getUserNo());
  114. couponDao.saveCouponRefVal(cate);
  115. }
  116. // 적용대상 - 제외상품
  117. Collection<CouponRefval> exceptGoodsList = gson.fromJson(params.getExceptGoodsList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
  118. for(CouponRefval exceptGoods: exceptGoodsList ) {
  119. sequence = null;
  120. if(exceptGoods.getCpnRefvalSq() != null && exceptGoods.getCpnRefvalSq() > 0){
  121. sequence = exceptGoods.getCpnRefvalSq();
  122. }
  123. exceptGoods.setCpnId(cpnId);
  124. exceptGoods.setCpnRefvalSq(sequence);
  125. exceptGoods.setCpnTarget("G260_14");
  126. exceptGoods.setRefVal(exceptGoods.getGoodsCd());
  127. exceptGoods.setRegNo(TsaSession.getInfo().getUserNo());
  128. exceptGoods.setUpdNo(TsaSession.getInfo().getUserNo());
  129. couponDao.saveCouponRefVal(exceptGoods);
  130. }
  131. // 입점업체분담율
  132. Collection<CouponBurden> burdenList = gson.fromJson(params.getBurdenList() , new TypeToken<Collection<CouponBurden>>(){}.getType());
  133. for(CouponBurden burden: burdenList ) {
  134. burden.setCpnId(cpnId);
  135. burden.setRegNo(TsaSession.getInfo().getUserNo());
  136. burden.setUpdNo(TsaSession.getInfo().getUserNo());
  137. couponDao.saveCouponBurden(burden);
  138. }
  139. // 수정모드이고 변경된 쿠폰상태가 대기 , 중지 인경우 고객이 발급받은 내용도 변경
  140. if(!StringUtils.isBlank(params.getCpnId()) &&
  141. (params.getCpnStat().equals("G232_10") || params.getCpnStat().equals("G232_12")) ) {
  142. CustCoupon custCoupon = new CustCoupon();
  143. custCoupon.setCpnId(params.getCpnId());
  144. custCoupon.setUseYn("Y");
  145. ArrayList<CustCoupon> custList = couponDao.getCouponIssueCustList(custCoupon);
  146. if(custList != null && custList.size() > 0 ) {
  147. for(CustCoupon issueCust : custList) {
  148. issueCust.setAvailEddt(params.getAvailEddt());
  149. issueCust.setUpdNo(TsaSession.getInfo().getUserNo());
  150. couponDao.updateCustCouponAvailEddt(issueCust);
  151. }
  152. }
  153. }
  154. }
  155. /**
  156. * 쿠폰 리스트 조회
  157. * @param param
  158. * @return ArrayList<Coupon>
  159. * @author xyzp1539
  160. * @since 2020-12-22
  161. */
  162. public ArrayList<Coupon> getCouponList(Coupon param) {
  163. return couponDao.getCouponList(param);
  164. }
  165. /**
  166. * 쿠폰리스트 카운트 조회
  167. * @param param
  168. * @return int
  169. * @author xyzp1539
  170. * @since 2020-12-22
  171. */
  172. public int getCouponListCnt(Coupon param) {
  173. return couponDao.getCouponListCnt(param);
  174. }
  175. /**
  176. * 쿠폰조회 목록
  177. * @param coupon - 쿠폰 정보
  178. * @return
  179. * @author gagamel
  180. * @since 2021. 1. 8
  181. */
  182. public Collection<Coupon> getCouponRetrieveList(Coupon coupon) {
  183. return couponDao.getCouponRetrieveList(coupon);
  184. }
  185. /**
  186. * 쿠폰조회 목록
  187. * @param
  188. * @return
  189. * @author gagamel
  190. * @since 2021. 1. 8
  191. */
  192. public Collection<CommonCode> getSelfBrandList() {
  193. return couponDao.getSelfBrandList();
  194. }
  195. /**
  196. * 쿠폰 상세 조회
  197. * @param cpnId
  198. * @return Coupon
  199. * @author xyzp1539
  200. * @since 2021-01-15
  201. */
  202. public Coupon getCouponDetail(String cpnId) { return couponDao.getCouponDetail(cpnId);}
  203. /**
  204. * 쿠폰 발급 개수 조회
  205. * @param cpnId
  206. * @return cnt
  207. * @author xyzp1539
  208. * @since 2021-01-15
  209. */
  210. public int getCouponIssueCnt(String cpnId) {
  211. return couponDao.getCouponIssueCnt(cpnId);
  212. }
  213. /**
  214. * 쿠폰 적용 대상 - 제외상품
  215. * @param cpnId
  216. * @return Coupon
  217. * @author xyzp1539
  218. * @since 2021-01-18
  219. */
  220. public ArrayList<CouponRefval> getCouponRefvalExceptGoodsList(String cpnId ) {
  221. CouponRefval cpnRefval = new CouponRefval();
  222. cpnRefval.setCpnId(cpnId);
  223. cpnRefval.setCpnTarget("G260_14");
  224. return couponDao.getCouponRefvalExceptGoodsList(cpnRefval);
  225. }
  226. /**
  227. * 쿠폰 적용 대상 - 브랜드
  228. * @param cpnId
  229. * @return Coupon
  230. * @author xyzp1539
  231. * @since 2021-01-18
  232. */
  233. public ArrayList<CouponRefval> getCouponRefvalBrandList(String cpnId ) {
  234. CouponRefval cpnRefval = new CouponRefval();
  235. cpnRefval.setCpnId(cpnId);
  236. cpnRefval.setCpnTarget("G260_12");
  237. return couponDao.getCouponRefvalBrandList(cpnRefval);
  238. }
  239. /**
  240. * 쿠폰 적용 대상 - 카테고리
  241. * @param cpnId
  242. * @return Coupon
  243. * @author xyzp1539
  244. * @since 2021-01-18
  245. */
  246. public ArrayList<CouponRefval> getCouponRefvalCategoryList(String cpnId) {
  247. CouponRefval cpnRefval = new CouponRefval();
  248. cpnRefval.setCpnId(cpnId);
  249. cpnRefval.setCpnTarget("G260_11");
  250. return couponDao.getCouponRefvalCategoryList(cpnRefval);
  251. }
  252. /**
  253. * 쿠폰 적용 대상 - 적용상품
  254. * @param cpnId
  255. * @return Coupon
  256. * @author xyzp1539
  257. * @since 2021-01-18
  258. */
  259. public ArrayList<CouponRefval> getCouponRefvalGoodsList(String cpnId , String cpnTarget) {
  260. CouponRefval cpnRefval = new CouponRefval();
  261. cpnRefval.setCpnId(cpnId);
  262. cpnRefval.setCpnTarget(cpnTarget);
  263. return couponDao.getCouponRefvalGoodsList(cpnRefval);
  264. }
  265. /**
  266. * 쿠폰 적용 대상 - 공급처
  267. * @param cpnId
  268. * @return Coupon
  269. * @author xyzp1539
  270. * @since 2021-01-18
  271. */
  272. public ArrayList<CouponRefval> getCouponRefvalSupplyCompList(String cpnId) {
  273. CouponRefval cpnRefval = new CouponRefval();
  274. cpnRefval.setCpnId(cpnId);
  275. cpnRefval.setCpnTarget("G260_13");
  276. return couponDao.getCouponRefvalSupplyCompList(cpnRefval);
  277. }
  278. /**
  279. * 쿠폰 입점업체 분담율 조회
  280. * @param
  281. * @return
  282. * @author xyzp1539
  283. * @since 2021-01-18
  284. */
  285. public ArrayList<Coupon> getCouponBurdenList(String cpnId) {
  286. return couponDao.getCouponBurdenList(cpnId);
  287. }
  288. /**
  289. * 쿠폰 적용대상 삭제
  290. * @param couponRefval
  291. * @return
  292. * @author xyzp1539
  293. * @since 2021-01-19
  294. */
  295. @Transactional("shopTxnManager")
  296. public void updateCouponRefval(CouponRefval couponRefval) {
  297. couponRefval.setUpdNo(TsaSession.getInfo().getUserNo());
  298. couponDao.updateCouponRefval(couponRefval);
  299. }
  300. /**
  301. * 고객 쿠폰
  302. * @param
  303. * @return
  304. * @author xyzp1539
  305. * @since 2021-01-21
  306. */
  307. @Transactional("shopTxnManager")
  308. public void saveCouponCustPub(CustCoupon custCoupon) {
  309. Gson gson = new Gson();
  310. Collection<CustCoupon> custPubList = gson.fromJson(custCoupon.getCustList() , new TypeToken<Collection<CustCoupon>>(){}.getType());
  311. for(CustCoupon custPub : custPubList ) {
  312. custPub.setCpnId(custCoupon.getCpnId());
  313. custPub.setAvailStdt(custCoupon.getAvailStdt());
  314. custPub.setAvailEddt(custCoupon.getAvailEddt());
  315. custPub.setPubReason(custCoupon.getPubReason());
  316. custPub.setPubReasonDtl(custCoupon.getPubReasonDtl());
  317. custPub.setEndAlimSendYn(custCoupon.getEndAlimSendYn());
  318. custPub.setRegNo(TsaSession.getInfo().getUserNo());
  319. custPub.setUpdNo(TsaSession.getInfo().getUserNo());
  320. couponDao.saveCouponCustPub(custPub);
  321. }
  322. }
  323. }