TsaSettleController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. package com.style24.admin.biz.web;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import javax.servlet.http.HttpServletRequest;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.core.env.Environment;
  8. import org.springframework.core.io.InputStreamResource;
  9. import org.springframework.http.ResponseEntity;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import org.springframework.web.servlet.ModelAndView;
  18. import com.fasterxml.jackson.databind.ObjectMapper;
  19. import com.style24.admin.biz.service.TsaRendererService;
  20. import com.style24.admin.biz.service.TsaSettleService;
  21. import com.style24.admin.support.controller.TsaBaseController;
  22. import com.style24.admin.support.security.session.TsaSession;
  23. import com.style24.core.biz.thirdparty.HansaeErp;
  24. import com.style24.core.support.message.TscMessageByLocale;
  25. import com.style24.persistence.domain.AflinkFee;
  26. import com.style24.persistence.domain.DelvFeeSettle;
  27. import com.style24.persistence.domain.Erp;
  28. import com.style24.persistence.domain.GiftcardSettle;
  29. import com.style24.persistence.domain.GoodsSettle;
  30. import com.style24.persistence.domain.SettleConfirm;
  31. import lombok.extern.slf4j.Slf4j;
  32. import com.gagaframework.excel.GagaExcelUtil;
  33. import com.gagaframework.web.parameter.GagaMap;
  34. import com.gagaframework.web.rest.server.GagaResponse;
  35. import com.gagaframework.web.util.GagaFileUtil;
  36. import com.gagaframework.web.util.GagaStringUtil;
  37. /**
  38. * 정산 Controller
  39. *
  40. * @author jaewonHo
  41. * @since 2020. 10. 22
  42. */
  43. @Controller
  44. @RequestMapping("/settle")
  45. @Slf4j
  46. public class TsaSettleController extends TsaBaseController {
  47. @Autowired
  48. private TsaSettleService settleService;
  49. @Autowired
  50. private TsaRendererService rendererService;
  51. @Autowired
  52. private ObjectMapper mapper;
  53. @Autowired
  54. private TscMessageByLocale message;
  55. @Autowired
  56. private Environment env;
  57. @Autowired
  58. private HansaeErp hansaeErp;
  59. /**
  60. * 상품정산 화면
  61. * @return
  62. * @author gagamel
  63. * @since 2020. 10. 22
  64. */
  65. @GetMapping("/goods/form")
  66. public ModelAndView goodsSettleForm() {
  67. ModelAndView mav = new ModelAndView();
  68. // 몰구분
  69. mav.addObject("mallGbList", rendererService.getCommonCodeList("G011"));
  70. // 외부몰벤더 콤보박스 목록
  71. mav.addObject("vendorList", rendererService.getCommonCodeList("G003"));
  72. // 공급업체
  73. mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
  74. // 유통구분
  75. mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
  76. mav.setViewName("settle/GoodsSettleForm");
  77. return mav;
  78. }
  79. /**
  80. * 상품정산 목록
  81. * @param goodsSettle - 상품정산 정보
  82. * @return
  83. * @author gagamel
  84. * @since 2021. 7. 5
  85. */
  86. @PostMapping("/goods/list")
  87. @ResponseBody
  88. public Collection<GoodsSettle> getGoodsSettleList(@RequestBody GoodsSettle goodsSettle) {
  89. if (!StringUtils.isBlank(goodsSettle.getSupplyCompList())) {
  90. try {
  91. String[] arrSupplyComp = mapper.readValue(goodsSettle.getSupplyCompList(), String[].class);
  92. goodsSettle.setMultiSupplyComp(arrSupplyComp);
  93. } catch (Exception e) {
  94. throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
  95. }
  96. }
  97. if (!StringUtils.isBlank(goodsSettle.getBrandList())) {
  98. try {
  99. String[] arrBrandCd = mapper.readValue(goodsSettle.getBrandList(), String[].class);
  100. goodsSettle.setMultiBrand(arrBrandCd);
  101. } catch (Exception e) {
  102. throw new IllegalStateException("브랜드코드 검색중 오류로 인해 조회되지 않았습니다.");
  103. }
  104. }
  105. return settleService.getGoodsSettleList(goodsSettle);
  106. }
  107. /**
  108. * 정산확정 처리 - 업체별정산데이터 생성
  109. * @param settleConfirm - 정산확정 정보
  110. * @return
  111. * @author gagamel
  112. * @since 2021. 7. 30
  113. */
  114. @PostMapping("/confirm/save")
  115. @ResponseBody
  116. public GagaResponse saveSettleConfirm(@RequestBody SettleConfirm settleConfirm) {
  117. settleConfirm.setRegNo(TsaSession.getInfo().getUserNo());
  118. settleService.saveSettleConfirm(settleConfirm);
  119. return super.ok(message.getMessage("SUCC_0004"));
  120. }
  121. /**
  122. * 배송비정산 화면
  123. * @return
  124. * @author gagamel
  125. * @since 2020. 10. 22
  126. **/
  127. @GetMapping("/delivery/fee/form")
  128. public ModelAndView deliveryFeeSettleForm() {
  129. ModelAndView mav = new ModelAndView();
  130. // 공급업체
  131. mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
  132. // 유통구분
  133. mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
  134. mav.setViewName("settle/DeliveryFeeSettleForm");
  135. return mav;
  136. }
  137. /**
  138. * 배송비정산 목록
  139. * @param delvFeeSettle - 배송비정산 정보
  140. * @return
  141. * @author gagamel
  142. * @since 2021. 7. 6
  143. */
  144. @PostMapping("/delivery/fee/list")
  145. @ResponseBody
  146. public Collection<DelvFeeSettle> getDeliveryFeeSettleList(@RequestBody DelvFeeSettle delvFeeSettle) {
  147. if (!StringUtils.isBlank(delvFeeSettle.getSupplyCompList())) {
  148. try {
  149. String[] arrSupplyComp = mapper.readValue(delvFeeSettle.getSupplyCompList(), String[].class);
  150. delvFeeSettle.setMultiSupplyComp(arrSupplyComp);
  151. } catch (Exception e) {
  152. e.printStackTrace();
  153. throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
  154. }
  155. }
  156. if (!StringUtils.isBlank(delvFeeSettle.getBrandList())) {
  157. try {
  158. String[] arrBrandCd = mapper.readValue(delvFeeSettle.getBrandList(), String[].class);
  159. delvFeeSettle.setMultiBrand(arrBrandCd);
  160. } catch (Exception e) {
  161. e.printStackTrace();
  162. throw new IllegalStateException("브랜드코드 검색중 오류로 인해 조회되지 않았습니다.");
  163. }
  164. }
  165. return settleService.getDeliveryFeeSettleList(delvFeeSettle);
  166. }
  167. /**
  168. * 정산확정관리 화면
  169. * @return
  170. * @author gagamel
  171. * @since 2020. 10. 22
  172. */
  173. @GetMapping("/confirm/form")
  174. public ModelAndView settleConfirmForm() {
  175. ModelAndView mav = new ModelAndView();
  176. // 공급업체
  177. mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
  178. // 유통구분
  179. mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
  180. // 은행
  181. mav.addObject("bankList", rendererService.getCommonCodeList("G940"));
  182. mav.setViewName("settle/SettleConfirmForm");
  183. return mav;
  184. }
  185. /**
  186. * 정산확정 목록
  187. * @param settleConfirm - 정산확정 정보
  188. * @return
  189. * @author gagamel
  190. * @since 2021. 7. 26
  191. */
  192. @PostMapping("/confirm/list")
  193. @ResponseBody
  194. public Collection<SettleConfirm> getSettleConfirmList(@RequestBody SettleConfirm settleConfirm) {
  195. if (!StringUtils.isBlank(settleConfirm.getSupplyCompList())) {
  196. try {
  197. String[] arrSupplyComp = mapper.readValue(settleConfirm.getSupplyCompList(), String[].class);
  198. settleConfirm.setMultiSupplyComp(arrSupplyComp);
  199. } catch (Exception e) {
  200. throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
  201. }
  202. }
  203. return settleService.getSettleConfirmList(settleConfirm);
  204. }
  205. /**
  206. * 정산확정 기타차감 엑셀 업로드
  207. * @param goodsMass
  208. * @return
  209. * @throws Exception
  210. * @author eskim
  211. * @since 2021. 8. 16
  212. */
  213. @PostMapping("/etc/deduct/amt/upload")
  214. @ResponseBody
  215. public GagaResponse uploadEtcDeductAmtList(@RequestBody SettleConfirm settleConfirm) throws Exception {
  216. String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
  217. // DB 처리 시 사용되는 셀명 설정
  218. String[] cellNames = {"occurYm", "custId", "custNm", "ordNo", "cateNm", "supplyVendorCd", "supplyVendorNm", "chargeNm", "ordGoods", "currPrice", "rewardAmt", "reason"};
  219. Collection<GagaMap> ecxelList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, settleConfirm.getExcelFileNm()), 0, cellNames, 0);
  220. if (ecxelList == null || ecxelList.isEmpty()) {
  221. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  222. }
  223. for (GagaMap dataMap : ecxelList) {
  224. settleService.saveEtcDeductAmt(dataMap);
  225. }
  226. // 파일 삭제
  227. GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, settleConfirm.getExcelFileNm()));
  228. return super.ok(message.getMessage("SUCC_0007"));
  229. }
  230. /**
  231. * 정산확정 미수금 목록 저장 처리
  232. * @param settleConfirmList - 정산확정 목록
  233. * @return
  234. * @author gagamel
  235. * @since 2021. 8. 16
  236. */
  237. @PostMapping("/receievable/amt/list/save")
  238. @ResponseBody
  239. public GagaResponse saveReceivableAmtList(@RequestBody Collection<SettleConfirm> settleConfirmList) {
  240. if (settleConfirmList == null || settleConfirmList.isEmpty()) {
  241. throw new IllegalStateException(message.getMessage("FAIL_1001"));
  242. }
  243. settleService.saveReceivableAmtList(settleConfirmList);
  244. return super.ok(message.getMessage("SUCC_0004"));
  245. }
  246. /**
  247. * 세금계산서용 엑셀다운로드
  248. * @param settleConfirm - 정산확정 정보
  249. * @return
  250. * @author gagamel
  251. * @since 2021. 8. 16
  252. */
  253. @GetMapping("/tax/bill/excel/download")
  254. public ResponseEntity<InputStreamResource> downloadTaxBillSettleExcel(HttpServletRequest request, SettleConfirm settleConfirm) throws Exception {
  255. String excelFileName = GagaStringUtil.replace(settleConfirm.getSettleYm(), "-", "") + "_세금계산서.xlsx";
  256. String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelFileName);
  257. settleService.createTaxBillSettleExcel(settleConfirm, excelFilenameWithPath);
  258. return GagaFileUtil.writeFile(request, excelFilenameWithPath);
  259. }
  260. // /**
  261. // * 업체별정산내역 화면
  262. // * @return
  263. // * @author gagamel
  264. // * @since 2020. 10. 22
  265. // */
  266. // @GetMapping("/supply/company/form")
  267. // public ModelAndView supplyCompanySettleForm() {
  268. // ModelAndView mav = new ModelAndView();
  269. //
  270. // // 공급업체
  271. // mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
  272. //
  273. // mav.setViewName("settle/SupplyCompanySettleForm");
  274. //
  275. // return mav;
  276. // }
  277. //
  278. // /**
  279. // * PG입금정산 화면
  280. // * @return
  281. // * @author gagamel
  282. // * @since 2020. 10. 22
  283. // */
  284. // @GetMapping("/pg/deposit/form")
  285. // public ModelAndView paygateDepositForm() {
  286. // ModelAndView mav = new ModelAndView();
  287. //
  288. // // 공급업체
  289. // mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
  290. //
  291. // // PG구분
  292. // mav.addObject("pgGbList", rendererService.getCommonCodeList("G015"));
  293. //
  294. // // 결제수단
  295. // mav.addObject("payMeansList", rendererService.getCommonCodeList("G014"));
  296. //
  297. // mav.setViewName("settle/PgDepositSettleForm");
  298. //
  299. // return mav;
  300. // }
  301. /**
  302. * 상품권정산 화면
  303. * @return
  304. * @author gagamel
  305. * @since 2020. 10. 22
  306. */
  307. @GetMapping("/giftcard/form")
  308. public ModelAndView giftcardSettleForm() {
  309. ModelAndView mav = new ModelAndView();
  310. mav.setViewName("settle/GiftcardSettleForm");
  311. return mav;
  312. }
  313. /**
  314. * 상품권정산 목록
  315. * @param giftcardSettle - 상품권정산 정보
  316. * @return
  317. * @author gagamel
  318. * @since 2021. 8. 16
  319. */
  320. @PostMapping("/giftcard/list")
  321. @ResponseBody
  322. public Collection<GiftcardSettle> getGiftcardSettleList(@RequestBody GiftcardSettle giftcardSettle) {
  323. Collection<GiftcardSettle> dataList = new ArrayList<GiftcardSettle>();
  324. if (giftcardSettle.getTermGb().equals("SETTLE_YM")) { // 기간조건이 "정산월"이면
  325. // 상품권정산 목록
  326. dataList = settleService.getGiftcardSettleList(giftcardSettle);
  327. } else {
  328. // 상품권현황 목록
  329. dataList = settleService.getGiftcardStatusList(giftcardSettle);
  330. }
  331. return dataList;
  332. }
  333. /**
  334. * 제휴채널정산 화면
  335. * @return
  336. * @author gagamel
  337. * @since 2021. 1. 20
  338. */
  339. @GetMapping("/aflink/fee/form")
  340. public ModelAndView afLinkFeeForm() {
  341. ModelAndView mav = new ModelAndView("settle/AfLinkSettleForm");
  342. // 제휴채널 목록
  343. mav.addObject("afChannelList", rendererService.getAvailCommonCodeList("G053"));
  344. return mav;
  345. }
  346. /**
  347. * 제휴채널정산 목록
  348. * @param aflinkFee - 제휴채널수수료 정보
  349. * @return
  350. * @author gagamel
  351. * @since 2021. 1. 20
  352. */
  353. @PostMapping("/aflink/fee/list")
  354. @ResponseBody
  355. public Collection<AflinkFee> getAfLinkFeeList(@RequestBody AflinkFee aflinkFee) {
  356. return settleService.getAfLinkFeeList(aflinkFee);
  357. }
  358. /**
  359. * 한세ERP매출반영 화면
  360. * @return
  361. * @author gagamel
  362. * @since 2021. 11. 1
  363. */
  364. @GetMapping("/hansae/sales/upload/form")
  365. public ModelAndView hansaeSalesUploadForm() {
  366. ModelAndView mav = new ModelAndView();
  367. mav.setViewName("settle/HansaeSalesUploadForm");
  368. return mav;
  369. }
  370. /**
  371. * 한세ERP매출반영 목록
  372. * @param erp - 한세ERP 정보
  373. * @return
  374. * @author gagamel
  375. * @since 2021. 11. 1
  376. */
  377. @PostMapping("/hansae/sales/upload/list")
  378. @ResponseBody
  379. public Collection<Erp> getHansaeSalesUploadList(@RequestBody Erp erp) {
  380. return settleService.getHansaeSalesUploadList(erp);
  381. }
  382. /**
  383. * 한세스타일매핑 화면
  384. * @param erpGb - ERP구분(hsmk: 한세MK, hsdr: 한세드림)
  385. * @param cdStyle - 스타일코드
  386. * @param color - 색상코드
  387. * @param sizeCd - 사이즈코드
  388. * @param dsError - 실패메시지
  389. * @return
  390. * @author gagamel
  391. * @since 2021. 11. 1
  392. */
  393. @GetMapping("/hansae/style/mapping/form")
  394. public ModelAndView hansaeStyleMappingForm(@RequestParam(value = "erpGb") String erpGb, @RequestParam(value = "cdStyle") String cdStyle, @RequestParam(value = "cdColor") String cdColor, @RequestParam(value = "cdSize") String cdSize, @RequestParam(value = "dsError") String dsError) {
  395. ModelAndView mav = new ModelAndView();
  396. Erp erp = new Erp();
  397. erp.setErpGb(erpGb);
  398. erp.setCdStyle(cdStyle);
  399. erp.setCdColor(cdColor);
  400. erp.setCdSize(cdSize);
  401. Erp styleInfo = settleService.getHansaeStyleMapping(erp);
  402. if (styleInfo == null) {
  403. styleInfo = new Erp();
  404. styleInfo.setErpGb(erpGb);
  405. styleInfo.setCdStyle(cdStyle);
  406. styleInfo.setCdColor(cdColor);
  407. styleInfo.setCdSize(cdSize);
  408. }
  409. styleInfo.setDsError(dsError);
  410. mav.addObject("styleInfo", styleInfo);
  411. mav.setViewName("settle/HansaeStyleMappingForm");
  412. return mav;
  413. }
  414. /**
  415. * 한세스타일매핑 저장 처리
  416. * @param erp - 한세ERP 정보
  417. * @return
  418. * @author gagamel
  419. * @since 2021. 11. 1
  420. */
  421. @PostMapping("/hansae/style/mapping/save")
  422. @ResponseBody
  423. public GagaResponse saveHansaeStyleMapping(@RequestBody Erp erp) {
  424. settleService.saveHansaeStyleMapping(erp);
  425. return super.ok(message.getMessage("SUCC_0001"));
  426. }
  427. /**
  428. * 한세ERP 매출실패건 업로드 처리
  429. * @param erp - 한세ERP 정보
  430. * @return
  431. * @author gagamel
  432. * @since 2021. 11. 1
  433. */
  434. @PostMapping("/hansae/failedSales/upload")
  435. @ResponseBody
  436. public GagaResponse uploadHansaeFailedSales(@RequestBody Erp erp) {
  437. log.info("{}", erp);
  438. // 매출반영 실패한 브랜드 목록 (브랜드 단위로 처리를 위해)
  439. Collection<String> brandList = settleService.getFailedSalesUploadBrandList(erp);
  440. if (brandList == null || brandList.isEmpty()) {
  441. throw new IllegalStateException((HansaeErp.ErpGb.HANSAE_MK.value().equals(erp.getErpGb()) ? "한세MK" : "한세드림")
  442. + "의 판매기간(" + erp.getStartDt() + "~" + erp.getEndDt() + ") 내에 매출반영 실패건이 없습니다.");
  443. }
  444. // 매출반영 실패건 ERP 옵션 정보로 Update
  445. int updCnt = settleService.updateFailedSalesUploadListToErpInfo(erp);
  446. // if (updCnt == 0) {
  447. // throw new IllegalStateException("매출반영 실패건 중 ERP 옵션 정보가 변경된 건이 없습니다.");
  448. // }
  449. for (String brandCd : brandList) {
  450. erp.setBrandCd(brandCd);
  451. // 매출반영 실패한 목록 (브랜드 단위로 조회)
  452. Collection<GagaMap> uploadList = settleService.getFailedSalesUploadList(erp);
  453. if (uploadList == null || uploadList.isEmpty()) {
  454. log.error("{}-{} 브랜드의 매출반영 실패한 데이터가 없습니다.", erp.getErpGb(), brandCd);
  455. continue;
  456. }
  457. // 매출반영I/F번호 조회
  458. String noIf = settleService.getSalesUploadInterfaceNo(erp.getErpGb());
  459. log.info("매출반영I/F번호: {}", noIf);
  460. for (GagaMap dataMap : uploadList) {
  461. // 매출반영목록 I/F번호 Update
  462. dataMap.setString("ERP_GB", erp.getErpGb());
  463. dataMap.setString("NO_IF", noIf);
  464. settleService.updateSalesUploadListInterfaceNo(dataMap);
  465. }
  466. // 매출업로드
  467. GagaMap salesMap = hansaeErp.uploadErpSales(erp.getErpGb(), uploadList);
  468. if (salesMap == null || salesMap.isEmpty()) {
  469. log.error("{}-{} 브랜드의 매출반영결과 데이터가 없습니다. 한세 ERP 시스템담당자에게 문의해 주세요.", erp.getErpGb(), brandCd);
  470. continue;
  471. }
  472. // 매출반영결과 처리
  473. settleService.updateSalesUploadResult(erp.getErpGb(), salesMap);
  474. log.info("{}-{} 브랜드의 매출반영 업로드 성공", erp.getErpGb(), brandCd);
  475. }
  476. return super.ok(message.getMessage("SUCC_0001"));
  477. }
  478. }