TsaMorebetterService.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package com.style24.admin.biz.service;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.style24.admin.support.security.session.TsaSession;
  5. import com.style24.core.support.message.TscMessageByLocale;
  6. import com.style24.persistence.domain.*;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.cache.annotation.CacheEvict;
  11. import org.springframework.core.env.Environment;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import com.style24.admin.biz.dao.TsaMorebetterDao;
  15. import java.util.ArrayList;
  16. import java.util.Collection;
  17. import java.util.List;
  18. /**
  19. *마케팅>다다익선 Service
  20. *
  21. * @author bin2107
  22. * @since 2021. 1. 12
  23. */
  24. @Service
  25. @Slf4j
  26. public class TsaMorebetterService {
  27. @Autowired
  28. private TscMessageByLocale message;
  29. @Autowired
  30. private Environment env;
  31. @Autowired
  32. private TsaMorebetterDao morebetterDao;
  33. @Autowired
  34. private TsaCommonService commonService;
  35. /* CSB 진행 */
  36. /**
  37. * 다다익선 리스트 건수
  38. * @param moreBetter
  39. * @return
  40. * @author bin2107
  41. * @since 2021. 1. 26
  42. */
  43. public int getMorebetterListCount(MoreBetter moreBetter) {
  44. return morebetterDao.getMorebetterListCount(moreBetter);
  45. }
  46. /**
  47. * 다다익선 리스트
  48. * @param param
  49. * @return
  50. * @author bin2107
  51. * @since 2020. 12. 28
  52. */
  53. public Collection<MoreBetter> getMorebetterList(MoreBetter param) {
  54. return morebetterDao.getMorebetterList(param);
  55. }
  56. /**
  57. * 다다익선 마스터 조회
  58. * @param
  59. * @return
  60. * @author bin2107
  61. * @since 2021. 1. 8
  62. */
  63. public MoreBetter getMorebetterMstInfo(Integer tmtbSq){
  64. return morebetterDao.getMorebetterMstInfo(tmtbSq);
  65. }
  66. /**
  67. * 다다익선 구간 조회
  68. * @param
  69. * @return
  70. * @author bin2107
  71. * @since 2021. 1. 8
  72. */
  73. public Collection<MoreBetterSection> getMorebetterSectionValList(Integer tmtbSq) {
  74. return morebetterDao.getMorebetterSectionValList(tmtbSq);
  75. }
  76. /**
  77. * 다다익선 구간 조회
  78. * @param
  79. * @return
  80. * @author bin2107
  81. * @since 2021. 1. 8
  82. */
  83. public Collection<MoreBetterGoods> getMorebetterSupplyCompList(Integer tmtbSq, String targetGb) {
  84. MoreBetterGoods merebetterGoods = new MoreBetterGoods();
  85. merebetterGoods.setTmtbSq(tmtbSq);
  86. merebetterGoods.setTargetGb(targetGb);
  87. return morebetterDao.getMorebetterSupplyCompList(merebetterGoods);
  88. }
  89. public Collection<MoreBetterGoods> getMorebetterBrandList(Integer tmtbSq, String targetGb) {
  90. MoreBetterGoods merebetterGoods = new MoreBetterGoods();
  91. merebetterGoods.setTmtbSq(tmtbSq);
  92. merebetterGoods.setTargetGb(targetGb);
  93. return morebetterDao.getMorebetterBrandList(merebetterGoods);
  94. }
  95. public Collection<MoreBetterGoods> getMorebetterApplyGoodsList(Integer tmtbSq, String targetGb) {
  96. MoreBetterGoods merebetterGoods = new MoreBetterGoods();
  97. merebetterGoods.setTmtbSq(tmtbSq);
  98. merebetterGoods.setTargetGb(targetGb);
  99. return morebetterDao.getMorebetterApplyGoodsList(merebetterGoods);
  100. }
  101. public Collection<MoreBetterGoods> getMorebetterExceptGoodsList(Integer tmtbSq, String targetGb) {
  102. MoreBetterGoods merebetterGoods = new MoreBetterGoods();
  103. merebetterGoods.setTmtbSq(tmtbSq);
  104. merebetterGoods.setTargetGb(targetGb);
  105. return morebetterDao.getMorebetterExceptGoodsList(merebetterGoods);
  106. }
  107. /**
  108. * 다다익선 구간 조회
  109. * @param
  110. * @return
  111. * @author bin2107
  112. * @since 2021. 1. 8
  113. */
  114. public Collection<MoreBetterBurden> getMorebetterBurdenList(Integer tmtbSq) {
  115. return morebetterDao.getMorebetterBurdenList(tmtbSq);
  116. }
  117. /**
  118. * 다다익선 저장
  119. * @param moreBetter
  120. * @return
  121. * @author bin2107
  122. * @since 2021. 1. 5
  123. */
  124. @Transactional("shopTxnManager")
  125. public void saveMoreBetterDetail(MoreBetter moreBetter) {
  126. // <,> replace 처리
  127. moreBetter.setRegNo(TsaSession.getInfo().getUserNo());
  128. moreBetter.setUpdNo(TsaSession.getInfo().getUserNo());
  129. Gson gson = new Gson();
  130. String jsonData = gson.toJson(moreBetter);
  131. // TMTB 마스터(TB_TMTB) 저장
  132. morebetterDao.saveMorebetterMst(moreBetter);
  133. // 공급업체
  134. for(MoreBetterGoods regSupplyComp : moreBetter.getSupplyCompList()){
  135. regSupplyComp.setTmtbSq(moreBetter.getTmtbSq());
  136. regSupplyComp.setGoodsGb("G800_20");
  137. regSupplyComp.setTargetVal(regSupplyComp.getSupplyCompCd());
  138. regSupplyComp.setRegNo(moreBetter.getRegNo());
  139. regSupplyComp.setUpdNo(moreBetter.getUpdNo());
  140. morebetterDao.saveMorebetterGoods(regSupplyComp);
  141. }
  142. // 브랜드
  143. for(MoreBetterGoods regBrand : moreBetter.getBrandList()){
  144. // 다다익선 적용대상 설정(TB_TMTB_GOODS) 저장
  145. regBrand.setTmtbSq(moreBetter.getTmtbSq());
  146. regBrand.setGoodsGb("G800_20");
  147. regBrand.setTargetVal(regBrand.getBrandCd());
  148. regBrand.setRegNo(moreBetter.getRegNo());
  149. regBrand.setUpdNo(moreBetter.getUpdNo());
  150. morebetterDao.saveMorebetterGoods(regBrand);
  151. }
  152. List<MoreBetterGoods> realApplyGoodsList = morebetterDao.getMorebetterRealApplyGoodsList(moreBetter);
  153. // 적용상품
  154. for(MoreBetterGoods realApplyGoods : realApplyGoodsList){
  155. for(MoreBetterGoods regApplyGoods : moreBetter.getApplyGoodsList()){
  156. if(regApplyGoods.getGoodsCd().equals(realApplyGoods.getGoodsCd())){
  157. // 다다익선 적용대상 설정(TB_TMTB_GOODS) 저장
  158. regApplyGoods.setTmtbSq(moreBetter.getTmtbSq());
  159. regApplyGoods.setTargetVal(realApplyGoods.getGoodsCd());
  160. regApplyGoods.setRegNo(moreBetter.getRegNo());
  161. regApplyGoods.setUpdNo(moreBetter.getUpdNo());
  162. morebetterDao.saveMorebetterGoods(regApplyGoods);
  163. morebetterDao.saveMorebetterApplyGoods(regApplyGoods);
  164. }
  165. }
  166. }
  167. // 제외상품
  168. for(MoreBetterGoods regExceptGoods : moreBetter.getExceptGoodsList()){
  169. // 다다익선 적용대상 설정(TB_TMTB_GOODS) 저장
  170. regExceptGoods.setTmtbSq(moreBetter.getTmtbSq());
  171. regExceptGoods.setTargetVal(regExceptGoods.getGoodsCd());
  172. regExceptGoods.setRegNo(moreBetter.getRegNo());
  173. regExceptGoods.setUpdNo(moreBetter.getUpdNo());
  174. morebetterDao.saveMorebetterGoods(regExceptGoods);
  175. morebetterDao.saveMorebetterApplyGoods(regExceptGoods);
  176. }
  177. // 다다익선 할인구간 저장
  178. for(MoreBetterSection regSection : moreBetter.getSectionGbList()){
  179. // 다다익선 할인구간설정 2차조건(TB_TMTB_SECTION) 저장
  180. regSection.setTmtbSq(moreBetter.getTmtbSq());
  181. regSection.setRegNo(moreBetter.getRegNo());
  182. regSection.setUpdNo(moreBetter.getUpdNo());
  183. morebetterDao.saveMorebetterSection(regSection);
  184. morebetterDao.saveMorebetterVal(regSection);
  185. }
  186. // 다다익선 업체분담율(TB_TMTB_BURDEN) 저장
  187. for (MoreBetterBurden regBurden : moreBetter.getBurdenList()) {
  188. regBurden.setTmtbSq(moreBetter.getTmtbSq());
  189. regBurden.setRegNo(moreBetter.getRegNo());
  190. regBurden.setUpdNo(moreBetter.getUpdNo());
  191. morebetterDao.saveMorebetterBurden(regBurden);
  192. }
  193. log.info("newBurdenSq = {}, newTmtbSq = {}, newSupplyCd = {}, newBurdenRate = {} , newUseYn = {}");
  194. }
  195. /**
  196. * 다다익선 공급업체 삭제
  197. * @param
  198. * @return
  199. * @author bin2107
  200. * @since 2021. 1. 5
  201. */
  202. @Transactional("shopTxnManager")
  203. public void deleteTmtbSupplyCompanyList(MoreBetterGoods moreBetterGoods) {
  204. if (moreBetterGoods == null || (moreBetterGoods.getArrCompanySq() == null && moreBetterGoods.getArrCompanySq().length <= 0)) {
  205. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  206. }
  207. if (moreBetterGoods.getArrCompanySq().length > 0) {
  208. morebetterDao.deleteTmtbSupplyCompanyList(moreBetterGoods);
  209. }
  210. }
  211. /**
  212. * 다다익선 브랜드 삭제
  213. * @param
  214. * @return
  215. * @author bin2107
  216. * @since 2021. 1. 16
  217. */
  218. @Transactional("shopTxnManager")
  219. public void deleteTmtbBrandList(MoreBetterGoods moreBetterGoods) {
  220. if (moreBetterGoods == null || (moreBetterGoods.getArrBrandSq() == null && moreBetterGoods.getArrBrandSq().length <= 0)) {
  221. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  222. }
  223. if (moreBetterGoods.getArrBrandSq().length > 0) {
  224. morebetterDao.deleteTmtbBrandList(moreBetterGoods);
  225. }
  226. }
  227. /**
  228. * 다다익선 적용상품 삭제
  229. * @param
  230. * @return
  231. * @author bin2107
  232. * @since 2021. 1. 16
  233. */
  234. @Transactional("shopTxnManager")
  235. public void deleteTmtbApplyGoodsList(MoreBetterGoods moreBetterGoods) {
  236. if (moreBetterGoods == null || (moreBetterGoods.getArrApplyGoodsSq() == null && moreBetterGoods.getArrApplyGoodsSq().length <= 0)) {
  237. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  238. }
  239. if (moreBetterGoods.getArrApplyGoodsSq().length > 0) {
  240. morebetterDao.deleteTmtbApplyGoodsList(moreBetterGoods);
  241. }
  242. }
  243. /**
  244. * 다다익선 제외상품 삭제
  245. * @param
  246. * @return
  247. * @author bin2107
  248. * @since 2021. 1. 16
  249. */
  250. @Transactional("shopTxnManager")
  251. public void deleteTmtbExceptGoodsList(MoreBetterGoods moreBetterGoods) {
  252. if (moreBetterGoods == null || (moreBetterGoods.getArrExceptGoodsSq() == null && moreBetterGoods.getArrExceptGoodsSq().length <= 0)) {
  253. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  254. }
  255. if (moreBetterGoods.getArrExceptGoodsSq().length > 0) {
  256. morebetterDao.deleteTmtbExceptGoodsList(moreBetterGoods);
  257. }
  258. }
  259. /**
  260. * 다다익선 다다익선 할인구간 삭제
  261. * @param
  262. * @return
  263. * @author bin2107
  264. * @since 2021. 1. 5
  265. */
  266. @Transactional("shopTxnManager")
  267. public void deleteTmtbSectionValList(MoreBetterSection moreBetterSection) {
  268. if (moreBetterSection == null || (moreBetterSection.getArrSectionSq() == null && moreBetterSection.getArrSectionSq().length <= 0)) {
  269. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  270. }
  271. if (moreBetterSection.getArrSectionSq().length > 0) {
  272. morebetterDao.deleteTmtbSectionList(moreBetterSection);
  273. morebetterDao.deleteTmtbValList(moreBetterSection);
  274. }
  275. }
  276. /**
  277. * 다다익선 제외상품 삭제
  278. * @param
  279. * @return
  280. * @author bin2107
  281. * @since 2021. 1. 16
  282. */
  283. @Transactional("shopTxnManager")
  284. public void deleteTmtbBurdenList(MoreBetterBurden moreBetterBurden) {
  285. if (moreBetterBurden == null || (moreBetterBurden.getArrBurdenSq() == null && moreBetterBurden.getArrBurdenSq().length <= 0)) {
  286. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  287. }
  288. if (moreBetterBurden.getArrBurdenSq().length > 0) {
  289. morebetterDao.deleteTmtbBurdenList(moreBetterBurden);
  290. }
  291. }
  292. /**
  293. * 다다익선 - 진행중인 다다익선 상품 TMEP 테이블 생성
  294. * @param
  295. * @return
  296. * @author bin2107
  297. * @since 2021. 1. 22
  298. */
  299. @Transactional("shopTxnManager")
  300. public void createMorebetterGoodsTemp(MoreBetterGoods moreBetterGoods){
  301. moreBetterGoods.setRegNo(TsaSession.getInfo().getUserNo());
  302. morebetterDao.deleteTmtbApplyGoodsTemp(moreBetterGoods);
  303. // 적용상품 그리드 데이터
  304. List<MoreBetterGoods> applyGoodsList = moreBetterGoods.getApplyGoodsList();
  305. if(moreBetterGoods.getMultiSupplyCompCd().length > 0 || moreBetterGoods.getMultiBrand().length > 0){
  306. // 공급업체, 브랜드에 해당하는 상품
  307. List<MoreBetterGoods> compBrandGoodsList = morebetterDao.getMorebetterCompBrandGoodsList(moreBetterGoods);
  308. if(compBrandGoodsList.size() > 0){
  309. for(int i=0; i<compBrandGoodsList.size(); i++){
  310. moreBetterGoods.setGoodsCd(compBrandGoodsList.get(i).getGoodsCd());
  311. morebetterDao.createTmtbApplyGoodsTemp(moreBetterGoods);
  312. applyGoodsList.add(compBrandGoodsList.get(i));
  313. }
  314. }
  315. }
  316. for(int i=0; i<moreBetterGoods.getMultiApplyGoods().length; i++){
  317. moreBetterGoods.setGoodsCd(moreBetterGoods.getMultiApplyGoods()[i]);
  318. morebetterDao.createTmtbApplyGoodsTemp(moreBetterGoods);
  319. }
  320. morebetterDao.deleteTmtbGoodsTemp(moreBetterGoods);
  321. morebetterDao.createTmtbGoodsTemp(moreBetterGoods);
  322. }
  323. /**
  324. * 다다익선 - 진행중인 다다익선 상품 조회
  325. * @param moreBetterGoods
  326. * @return
  327. * @author bin2107
  328. * @since 2021. 1. 22
  329. */
  330. public Collection<MoreBetterGoods> getMorebetterDuplicateList(MoreBetterGoods moreBetterGoods) {
  331. return morebetterDao.getMorebetterDuplicateList(moreBetterGoods);
  332. }
  333. /**
  334. * 다다익선 진행 상태 변경
  335. * @param
  336. * @return
  337. * @author bin2107
  338. * @since 2021. 1. 26
  339. */
  340. @Transactional("shopTxnManager")
  341. public void updateMorebetterStat(MoreBetter moreBetter) {
  342. moreBetter.setUpdNo(TsaSession.getInfo().getUserNo());
  343. morebetterDao.updateMorebetterStat(moreBetter);
  344. }
  345. /* // CSB 진행 */
  346. }