| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- package com.style24.admin.biz.service;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Date;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.style24.persistence.domain.*;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.fasterxml.jackson.core.type.TypeReference;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.style24.admin.biz.dao.TsaCouponDao;
- import com.style24.admin.support.security.session.TsaSession;
- import lombok.extern.slf4j.Slf4j;
- /**
- * 쿠폰 Service
- *
- * @author xyzp1539
- * @since 2021. 01. 11
- */
- @Service
- @Slf4j
- public class TsaCouponService {
- @Autowired
- private TsaCouponDao couponDao;
- @Autowired
- private TsaCommonService commonService;
- /**
- * 쿠폰 저장
- * @param params
- * @author xyzp1539
- * @since 2021-01-11
- */
- @Transactional("shopTxnManager")
- public void saveCoupon(Coupon params) {
- String cpnId = ""; // 쿠폰ID
- params.setRegNo(TsaSession.getInfo().getUserNo());
- params.setUpdNo(TsaSession.getInfo().getUserNo());
- // 자동생성이면 시퀀스 가져오기
- if(StringUtils.isBlank(params.getCpnId())) {
- Integer sequence = commonService.getNextSequence("SEQ_COUPON");
- cpnId = "CPN"+sequence;
- } else {
- cpnId = params.getCpnId();
- }
- params.setCpnId(cpnId);
- couponDao.couponInsert(params);
- Gson gson = new Gson();
- Integer sequence;
- // 적용대상 - 공급업체
- Collection<CouponRefval> supplyCompList = gson.fromJson(params.getSupplyCompList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
- for(CouponRefval supplyComp : supplyCompList) {
- sequence = null;
- if(supplyComp.getCpnRefvalSq() != null && supplyComp.getCpnRefvalSq() > 0){
- sequence = supplyComp.getCpnRefvalSq();
- }
- supplyComp.setCpnId(cpnId);
- supplyComp.setCpnRefvalSq(sequence);
- supplyComp.setCpnTarget("G260_13");
- supplyComp.setRefVal(supplyComp.getSupplyCompCd());
- supplyComp.setRegNo(TsaSession.getInfo().getUserNo());
- supplyComp.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponRefVal(supplyComp);
- }
- // 적용대상 - 브랜드
- Collection<CouponRefval> brandList = gson.fromJson(params.getBrandList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
- for(CouponRefval brand : brandList) {
- sequence = null;
- if(brand.getCpnRefvalSq() != null && brand.getCpnRefvalSq() > 0){
- sequence = brand.getCpnRefvalSq();
- }
- brand.setCpnId(cpnId);
- brand.setCpnRefvalSq(sequence);
- brand.setCpnTarget("G260_12");
- brand.setRefVal(brand.getBrandCd());
- brand.setRegNo(TsaSession.getInfo().getUserNo());
- brand.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponRefVal(brand);
- }
- // 적용대상 - 적용상품
- Collection<CouponRefval> applyGoodsList = gson.fromJson(params.getApplyGoodsList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
- for(CouponRefval applyGoods : applyGoodsList ) {
- sequence = null;
- if(applyGoods.getCpnRefvalSq() != null && applyGoods.getCpnRefvalSq() > 0){
- sequence = applyGoods.getCpnRefvalSq();
- }
- applyGoods.setCpnId(cpnId);
- applyGoods.setCpnRefvalSq(sequence);
- applyGoods.setCpnTarget("G260_10");
- applyGoods.setRefVal(applyGoods.getGoodsCd());
- applyGoods.setRegNo(TsaSession.getInfo().getUserNo());
- applyGoods.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponRefVal(applyGoods);
- }
- // 적용대상 - 카테고리
- Collection<CouponRefval> cateList = gson.fromJson(params.getCateList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
- for(CouponRefval cate : cateList ) {
- sequence = null;
- if(cate.getCpnRefvalSq() != null && cate.getCpnRefvalSq() > 0){
- sequence = cate.getCpnRefvalSq();
- }
- cate.setCpnId(cpnId);
- cate.setCpnRefvalSq(sequence);
- cate.setCpnTarget("G260_11");
- cate.setRefVal(cate.getCateNo());
- cate.setRefFormalGb(cate.getFormalGb());
- cate.setRefBrandCd(cate.getBrandCd()); // ag-grid 브랜드코드
- cate.setRegNo(TsaSession.getInfo().getUserNo());
- cate.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponRefVal(cate);
- }
- // 적용대상 - 제외상품
- Collection<CouponRefval> exceptGoodsList = gson.fromJson(params.getExceptGoodsList() , new TypeToken<Collection<CouponRefval>>(){}.getType());
- for(CouponRefval exceptGoods: exceptGoodsList ) {
- sequence = null;
- if(exceptGoods.getCpnRefvalSq() != null && exceptGoods.getCpnRefvalSq() > 0){
- sequence = exceptGoods.getCpnRefvalSq();
- }
- exceptGoods.setCpnId(cpnId);
- exceptGoods.setCpnRefvalSq(sequence);
- exceptGoods.setCpnTarget("G260_14");
- exceptGoods.setRefVal(exceptGoods.getGoodsCd());
- exceptGoods.setRegNo(TsaSession.getInfo().getUserNo());
- exceptGoods.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponRefVal(exceptGoods);
- }
- // 입점업체분담율
- Collection<CouponBurden> burdenList = gson.fromJson(params.getBurdenList() , new TypeToken<Collection<CouponBurden>>(){}.getType());
- for(CouponBurden burden: burdenList ) {
- burden.setCpnId(cpnId);
- burden.setRegNo(TsaSession.getInfo().getUserNo());
- burden.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponBurden(burden);
- }
- // 수정모드이고 변경된 쿠폰상태가 대기 , 중지 인경우 고객이 발급받은 내용도 변경
- if(!StringUtils.isBlank(params.getCpnId()) &&
- (params.getCpnStat().equals("G232_10") || params.getCpnStat().equals("G232_12")) ) {
- CustCoupon custCoupon = new CustCoupon();
- custCoupon.setCpnId(params.getCpnId());
- custCoupon.setUseYn("Y");
- ArrayList<CustCoupon> custList = couponDao.getCouponIssueCustList(custCoupon);
- if(custList != null && custList.size() > 0 ) {
- for(CustCoupon issueCust : custList) {
- issueCust.setAvailEddt(params.getAvailEddt());
- issueCust.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.updateCustCouponAvailEddt(issueCust);
- }
- }
- }
- }
- /**
- * 쿠폰 리스트 조회
- * @param param
- * @return ArrayList<Coupon>
- * @author xyzp1539
- * @since 2020-12-22
- */
- public ArrayList<Coupon> getCouponList(Coupon param) {
- return couponDao.getCouponList(param);
- }
- /**
- * 쿠폰리스트 카운트 조회
- * @param param
- * @return int
- * @author xyzp1539
- * @since 2020-12-22
- */
- public int getCouponListCnt(Coupon param) {
- return couponDao.getCouponListCnt(param);
- }
- /**
- * 쿠폰조회 목록
- * @param coupon - 쿠폰 정보
- * @return
- * @author gagamel
- * @since 2021. 1. 8
- */
- public Collection<Coupon> getCouponRetrieveList(Coupon coupon) {
- return couponDao.getCouponRetrieveList(coupon);
- }
- /**
- * 쿠폰조회 목록
- * @param
- * @return
- * @author gagamel
- * @since 2021. 1. 8
- */
- public Collection<CommonCode> getSelfBrandList() {
- return couponDao.getSelfBrandList();
- }
- /**
- * 쿠폰 상세 조회
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-15
- */
- public Coupon getCouponDetail(String cpnId) { return couponDao.getCouponDetail(cpnId);}
- /**
- * 쿠폰 발급 개수 조회
- * @param cpnId
- * @return cnt
- * @author xyzp1539
- * @since 2021-01-15
- */
- public int getCouponIssueCnt(String cpnId) {
- return couponDao.getCouponIssueCnt(cpnId);
- }
- /**
- * 쿠폰 적용 대상 - 제외상품
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<CouponRefval> getCouponRefvalExceptGoodsList(String cpnId ) {
- CouponRefval cpnRefval = new CouponRefval();
- cpnRefval.setCpnId(cpnId);
- cpnRefval.setCpnTarget("G260_14");
- return couponDao.getCouponRefvalExceptGoodsList(cpnRefval);
- }
- /**
- * 쿠폰 적용 대상 - 브랜드
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<CouponRefval> getCouponRefvalBrandList(String cpnId ) {
- CouponRefval cpnRefval = new CouponRefval();
- cpnRefval.setCpnId(cpnId);
- cpnRefval.setCpnTarget("G260_12");
- return couponDao.getCouponRefvalBrandList(cpnRefval);
- }
- /**
- * 쿠폰 적용 대상 - 카테고리
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<CouponRefval> getCouponRefvalCategoryList(String cpnId) {
- CouponRefval cpnRefval = new CouponRefval();
- cpnRefval.setCpnId(cpnId);
- cpnRefval.setCpnTarget("G260_11");
- return couponDao.getCouponRefvalCategoryList(cpnRefval);
- }
- /**
- * 쿠폰 적용 대상 - 적용상품
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<CouponRefval> getCouponRefvalGoodsList(String cpnId , String cpnTarget) {
- CouponRefval cpnRefval = new CouponRefval();
- cpnRefval.setCpnId(cpnId);
- cpnRefval.setCpnTarget(cpnTarget);
- return couponDao.getCouponRefvalGoodsList(cpnRefval);
- }
- /**
- * 쿠폰 적용 대상 - 공급처
- * @param cpnId
- * @return Coupon
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<CouponRefval> getCouponRefvalSupplyCompList(String cpnId) {
- CouponRefval cpnRefval = new CouponRefval();
- cpnRefval.setCpnId(cpnId);
- cpnRefval.setCpnTarget("G260_13");
- return couponDao.getCouponRefvalSupplyCompList(cpnRefval);
- }
- /**
- * 쿠폰 입점업체 분담율 조회
- * @param
- * @return
- * @author xyzp1539
- * @since 2021-01-18
- */
- public ArrayList<Coupon> getCouponBurdenList(String cpnId) {
- return couponDao.getCouponBurdenList(cpnId);
- }
- /**
- * 쿠폰 적용대상 삭제
- * @param couponRefval
- * @return
- * @author xyzp1539
- * @since 2021-01-19
- */
- @Transactional("shopTxnManager")
- public void updateCouponRefval(CouponRefval couponRefval) {
- couponRefval.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.updateCouponRefval(couponRefval);
- }
- /**
- * 고객 쿠폰
- * @param
- * @return
- * @author xyzp1539
- * @since 2021-01-21
- */
- @Transactional("shopTxnManager")
- public void saveCouponCustPub(CustCoupon custCoupon) {
- Gson gson = new Gson();
- Collection<CustCoupon> custPubList = gson.fromJson(custCoupon.getCustList() , new TypeToken<Collection<CustCoupon>>(){}.getType());
- for(CustCoupon custPub : custPubList ) {
- custPub.setCpnId(custCoupon.getCpnId());
- custPub.setAvailStdt(custCoupon.getAvailStdt());
- custPub.setAvailEddt(custCoupon.getAvailEddt());
- custPub.setPubReason(custCoupon.getPubReason());
- custPub.setPubReasonDtl(custCoupon.getPubReasonDtl());
- custPub.setEndAlimSendYn(custCoupon.getEndAlimSendYn());
- custPub.setRegNo(TsaSession.getInfo().getUserNo());
- custPub.setUpdNo(TsaSession.getInfo().getUserNo());
- couponDao.saveCouponCustPub(custPub);
- }
- }
- }
|