| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- package com.style24.admin.biz.web;
- import java.util.ArrayList;
- import java.util.Collection;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.env.Environment;
- import org.springframework.core.io.InputStreamResource;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.style24.admin.biz.service.TsaRendererService;
- import com.style24.admin.biz.service.TsaSettleService;
- import com.style24.admin.support.controller.TsaBaseController;
- import com.style24.admin.support.security.session.TsaSession;
- import com.style24.core.biz.thirdparty.HansaeErp;
- import com.style24.core.support.message.TscMessageByLocale;
- import com.style24.persistence.domain.AflinkFee;
- import com.style24.persistence.domain.DelvFeeSettle;
- import com.style24.persistence.domain.Erp;
- import com.style24.persistence.domain.GiftcardSettle;
- import com.style24.persistence.domain.GoodsSettle;
- import com.style24.persistence.domain.SettleConfirm;
- import lombok.extern.slf4j.Slf4j;
- import com.gagaframework.excel.GagaExcelUtil;
- import com.gagaframework.web.parameter.GagaMap;
- import com.gagaframework.web.rest.server.GagaResponse;
- import com.gagaframework.web.util.GagaFileUtil;
- import com.gagaframework.web.util.GagaStringUtil;
- /**
- * 정산 Controller
- *
- * @author jaewonHo
- * @since 2020. 10. 22
- */
- @Controller
- @RequestMapping("/settle")
- @Slf4j
- public class TsaSettleController extends TsaBaseController {
- @Autowired
- private TsaSettleService settleService;
- @Autowired
- private TsaRendererService rendererService;
- @Autowired
- private ObjectMapper mapper;
- @Autowired
- private TscMessageByLocale message;
- @Autowired
- private Environment env;
- @Autowired
- private HansaeErp hansaeErp;
- /**
- * 상품정산 화면
- * @return
- * @author gagamel
- * @since 2020. 10. 22
- */
- @GetMapping("/goods/form")
- public ModelAndView goodsSettleForm() {
- ModelAndView mav = new ModelAndView();
- // 몰구분
- mav.addObject("mallGbList", rendererService.getCommonCodeList("G011"));
- // 외부몰벤더 콤보박스 목록
- mav.addObject("vendorList", rendererService.getCommonCodeList("G003"));
- // 공급업체
- mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
- // 유통구분
- mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
- mav.setViewName("settle/GoodsSettleForm");
- return mav;
- }
- /**
- * 상품정산 목록
- * @param goodsSettle - 상품정산 정보
- * @return
- * @author gagamel
- * @since 2021. 7. 5
- */
- @PostMapping("/goods/list")
- @ResponseBody
- public Collection<GoodsSettle> getGoodsSettleList(@RequestBody GoodsSettle goodsSettle) {
- if (!StringUtils.isBlank(goodsSettle.getSupplyCompList())) {
- try {
- String[] arrSupplyComp = mapper.readValue(goodsSettle.getSupplyCompList(), String[].class);
- goodsSettle.setMultiSupplyComp(arrSupplyComp);
- } catch (Exception e) {
- throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
- }
- }
- if (!StringUtils.isBlank(goodsSettle.getBrandList())) {
- try {
- String[] arrBrandCd = mapper.readValue(goodsSettle.getBrandList(), String[].class);
- goodsSettle.setMultiBrand(arrBrandCd);
- } catch (Exception e) {
- throw new IllegalStateException("브랜드코드 검색중 오류로 인해 조회되지 않았습니다.");
- }
- }
- return settleService.getGoodsSettleList(goodsSettle);
- }
- /**
- * 정산확정 처리 - 업체별정산데이터 생성
- * @param settleConfirm - 정산확정 정보
- * @return
- * @author gagamel
- * @since 2021. 7. 30
- */
- @PostMapping("/confirm/save")
- @ResponseBody
- public GagaResponse saveSettleConfirm(@RequestBody SettleConfirm settleConfirm) {
- settleConfirm.setRegNo(TsaSession.getInfo().getUserNo());
- settleService.saveSettleConfirm(settleConfirm);
- return super.ok(message.getMessage("SUCC_0004"));
- }
- /**
- * 배송비정산 화면
- * @return
- * @author gagamel
- * @since 2020. 10. 22
- **/
- @GetMapping("/delivery/fee/form")
- public ModelAndView deliveryFeeSettleForm() {
- ModelAndView mav = new ModelAndView();
- // 공급업체
- mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
- // 유통구분
- mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
- mav.setViewName("settle/DeliveryFeeSettleForm");
- return mav;
- }
- /**
- * 배송비정산 목록
- * @param delvFeeSettle - 배송비정산 정보
- * @return
- * @author gagamel
- * @since 2021. 7. 6
- */
- @PostMapping("/delivery/fee/list")
- @ResponseBody
- public Collection<DelvFeeSettle> getDeliveryFeeSettleList(@RequestBody DelvFeeSettle delvFeeSettle) {
- if (!StringUtils.isBlank(delvFeeSettle.getSupplyCompList())) {
- try {
- String[] arrSupplyComp = mapper.readValue(delvFeeSettle.getSupplyCompList(), String[].class);
- delvFeeSettle.setMultiSupplyComp(arrSupplyComp);
- } catch (Exception e) {
- e.printStackTrace();
- throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
- }
- }
- if (!StringUtils.isBlank(delvFeeSettle.getBrandList())) {
- try {
- String[] arrBrandCd = mapper.readValue(delvFeeSettle.getBrandList(), String[].class);
- delvFeeSettle.setMultiBrand(arrBrandCd);
- } catch (Exception e) {
- e.printStackTrace();
- throw new IllegalStateException("브랜드코드 검색중 오류로 인해 조회되지 않았습니다.");
- }
- }
- return settleService.getDeliveryFeeSettleList(delvFeeSettle);
- }
- /**
- * 정산확정관리 화면
- * @return
- * @author gagamel
- * @since 2020. 10. 22
- */
- @GetMapping("/confirm/form")
- public ModelAndView settleConfirmForm() {
- ModelAndView mav = new ModelAndView();
- // 공급업체
- mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
- // 유통구분
- mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065"));
- // 은행
- mav.addObject("bankList", rendererService.getCommonCodeList("G940"));
- mav.setViewName("settle/SettleConfirmForm");
- return mav;
- }
- /**
- * 정산확정 목록
- * @param settleConfirm - 정산확정 정보
- * @return
- * @author gagamel
- * @since 2021. 7. 26
- */
- @PostMapping("/confirm/list")
- @ResponseBody
- public Collection<SettleConfirm> getSettleConfirmList(@RequestBody SettleConfirm settleConfirm) {
- if (!StringUtils.isBlank(settleConfirm.getSupplyCompList())) {
- try {
- String[] arrSupplyComp = mapper.readValue(settleConfirm.getSupplyCompList(), String[].class);
- settleConfirm.setMultiSupplyComp(arrSupplyComp);
- } catch (Exception e) {
- throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
- }
- }
- return settleService.getSettleConfirmList(settleConfirm);
- }
- /**
- * 정산확정 기타차감 엑셀 업로드
- * @param goodsMass
- * @return
- * @throws Exception
- * @author eskim
- * @since 2021. 8. 16
- */
- @PostMapping("/etc/deduct/amt/upload")
- @ResponseBody
- public GagaResponse uploadEtcDeductAmtList(@RequestBody SettleConfirm settleConfirm) throws Exception {
- String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
- // DB 처리 시 사용되는 셀명 설정
- String[] cellNames = {"occurYm", "custId", "custNm", "ordNo", "cateNm", "supplyVendorCd", "supplyVendorNm", "chargeNm", "ordGoods", "currPrice", "rewardAmt", "reason"};
- Collection<GagaMap> ecxelList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, settleConfirm.getExcelFileNm()), 0, cellNames, 0);
- if (ecxelList == null || ecxelList.isEmpty()) {
- throw new IllegalStateException(message.getMessage("FAIL_1001"));
- }
- for (GagaMap dataMap : ecxelList) {
- settleService.saveEtcDeductAmt(dataMap);
- }
- // 파일 삭제
- GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, settleConfirm.getExcelFileNm()));
- return super.ok(message.getMessage("SUCC_0007"));
- }
- /**
- * 정산확정 미수금 목록 저장 처리
- * @param settleConfirmList - 정산확정 목록
- * @return
- * @author gagamel
- * @since 2021. 8. 16
- */
- @PostMapping("/receievable/amt/list/save")
- @ResponseBody
- public GagaResponse saveReceivableAmtList(@RequestBody Collection<SettleConfirm> settleConfirmList) {
- if (settleConfirmList == null || settleConfirmList.isEmpty()) {
- throw new IllegalStateException(message.getMessage("FAIL_1001"));
- }
- settleService.saveReceivableAmtList(settleConfirmList);
- return super.ok(message.getMessage("SUCC_0004"));
- }
- /**
- * 세금계산서용 엑셀다운로드
- * @param settleConfirm - 정산확정 정보
- * @return
- * @author gagamel
- * @since 2021. 8. 16
- */
- @GetMapping("/tax/bill/excel/download")
- public ResponseEntity<InputStreamResource> downloadTaxBillSettleExcel(HttpServletRequest request, SettleConfirm settleConfirm) throws Exception {
- String excelFileName = GagaStringUtil.replace(settleConfirm.getSettleYm(), "-", "") + "_세금계산서.xlsx";
- String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelFileName);
- settleService.createTaxBillSettleExcel(settleConfirm, excelFilenameWithPath);
- return GagaFileUtil.writeFile(request, excelFilenameWithPath);
- }
- // /**
- // * 업체별정산내역 화면
- // * @return
- // * @author gagamel
- // * @since 2020. 10. 22
- // */
- // @GetMapping("/supply/company/form")
- // public ModelAndView supplyCompanySettleForm() {
- // ModelAndView mav = new ModelAndView();
- //
- // // 공급업체
- // mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
- //
- // mav.setViewName("settle/SupplyCompanySettleForm");
- //
- // return mav;
- // }
- //
- // /**
- // * PG입금정산 화면
- // * @return
- // * @author gagamel
- // * @since 2020. 10. 22
- // */
- // @GetMapping("/pg/deposit/form")
- // public ModelAndView paygateDepositForm() {
- // ModelAndView mav = new ModelAndView();
- //
- // // 공급업체
- // mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));
- //
- // // PG구분
- // mav.addObject("pgGbList", rendererService.getCommonCodeList("G015"));
- //
- // // 결제수단
- // mav.addObject("payMeansList", rendererService.getCommonCodeList("G014"));
- //
- // mav.setViewName("settle/PgDepositSettleForm");
- //
- // return mav;
- // }
- /**
- * 상품권정산 화면
- * @return
- * @author gagamel
- * @since 2020. 10. 22
- */
- @GetMapping("/giftcard/form")
- public ModelAndView giftcardSettleForm() {
- ModelAndView mav = new ModelAndView();
- mav.setViewName("settle/GiftcardSettleForm");
- return mav;
- }
- /**
- * 상품권정산 목록
- * @param giftcardSettle - 상품권정산 정보
- * @return
- * @author gagamel
- * @since 2021. 8. 16
- */
- @PostMapping("/giftcard/list")
- @ResponseBody
- public Collection<GiftcardSettle> getGiftcardSettleList(@RequestBody GiftcardSettle giftcardSettle) {
- Collection<GiftcardSettle> dataList = new ArrayList<GiftcardSettle>();
- if (giftcardSettle.getTermGb().equals("SETTLE_YM")) { // 기간조건이 "정산월"이면
- // 상품권정산 목록
- dataList = settleService.getGiftcardSettleList(giftcardSettle);
- } else {
- // 상품권현황 목록
- dataList = settleService.getGiftcardStatusList(giftcardSettle);
- }
- return dataList;
- }
- /**
- * 제휴채널정산 화면
- * @return
- * @author gagamel
- * @since 2021. 1. 20
- */
- @GetMapping("/aflink/fee/form")
- public ModelAndView afLinkFeeForm() {
- ModelAndView mav = new ModelAndView("settle/AfLinkSettleForm");
- // 제휴채널 목록
- mav.addObject("afChannelList", rendererService.getAvailCommonCodeList("G053"));
- return mav;
- }
- /**
- * 제휴채널정산 목록
- * @param aflinkFee - 제휴채널수수료 정보
- * @return
- * @author gagamel
- * @since 2021. 1. 20
- */
- @PostMapping("/aflink/fee/list")
- @ResponseBody
- public Collection<AflinkFee> getAfLinkFeeList(@RequestBody AflinkFee aflinkFee) {
- return settleService.getAfLinkFeeList(aflinkFee);
- }
- /**
- * 한세ERP매출반영 화면
- * @return
- * @author gagamel
- * @since 2021. 11. 1
- */
- @GetMapping("/hansae/sales/upload/form")
- public ModelAndView hansaeSalesUploadForm() {
- ModelAndView mav = new ModelAndView();
- mav.setViewName("settle/HansaeSalesUploadForm");
- return mav;
- }
- /**
- * 한세ERP매출반영 목록
- * @param erp - 한세ERP 정보
- * @return
- * @author gagamel
- * @since 2021. 11. 1
- */
- @PostMapping("/hansae/sales/upload/list")
- @ResponseBody
- public Collection<Erp> getHansaeSalesUploadList(@RequestBody Erp erp) {
- return settleService.getHansaeSalesUploadList(erp);
- }
- /**
- * 한세스타일매핑 화면
- * @param erpGb - ERP구분(hsmk: 한세MK, hsdr: 한세드림)
- * @param cdStyle - 스타일코드
- * @param color - 색상코드
- * @param sizeCd - 사이즈코드
- * @param dsError - 실패메시지
- * @return
- * @author gagamel
- * @since 2021. 11. 1
- */
- @GetMapping("/hansae/style/mapping/form")
- 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) {
- ModelAndView mav = new ModelAndView();
- Erp erp = new Erp();
- erp.setErpGb(erpGb);
- erp.setCdStyle(cdStyle);
- erp.setCdColor(cdColor);
- erp.setCdSize(cdSize);
- Erp styleInfo = settleService.getHansaeStyleMapping(erp);
- if (styleInfo == null) {
- styleInfo = new Erp();
- styleInfo.setErpGb(erpGb);
- styleInfo.setCdStyle(cdStyle);
- styleInfo.setCdColor(cdColor);
- styleInfo.setCdSize(cdSize);
- }
- styleInfo.setDsError(dsError);
- mav.addObject("styleInfo", styleInfo);
- mav.setViewName("settle/HansaeStyleMappingForm");
- return mav;
- }
- /**
- * 한세스타일매핑 저장 처리
- * @param erp - 한세ERP 정보
- * @return
- * @author gagamel
- * @since 2021. 11. 1
- */
- @PostMapping("/hansae/style/mapping/save")
- @ResponseBody
- public GagaResponse saveHansaeStyleMapping(@RequestBody Erp erp) {
- settleService.saveHansaeStyleMapping(erp);
- return super.ok(message.getMessage("SUCC_0001"));
- }
- /**
- * 한세ERP 매출실패건 업로드 처리
- * @param erp - 한세ERP 정보
- * @return
- * @author gagamel
- * @since 2021. 11. 1
- */
- @PostMapping("/hansae/failedSales/upload")
- @ResponseBody
- public GagaResponse uploadHansaeFailedSales(@RequestBody Erp erp) {
- log.info("{}", erp);
- // 매출반영 실패한 브랜드 목록 (브랜드 단위로 처리를 위해)
- Collection<String> brandList = settleService.getFailedSalesUploadBrandList(erp);
- if (brandList == null || brandList.isEmpty()) {
- throw new IllegalStateException((HansaeErp.ErpGb.HANSAE_MK.value().equals(erp.getErpGb()) ? "한세MK" : "한세드림")
- + "의 판매기간(" + erp.getStartDt() + "~" + erp.getEndDt() + ") 내에 매출반영 실패건이 없습니다.");
- }
- // 매출반영 실패건 ERP 옵션 정보로 Update
- int updCnt = settleService.updateFailedSalesUploadListToErpInfo(erp);
- // if (updCnt == 0) {
- // throw new IllegalStateException("매출반영 실패건 중 ERP 옵션 정보가 변경된 건이 없습니다.");
- // }
- for (String brandCd : brandList) {
- erp.setBrandCd(brandCd);
- // 매출반영 실패한 목록 (브랜드 단위로 조회)
- Collection<GagaMap> uploadList = settleService.getFailedSalesUploadList(erp);
- if (uploadList == null || uploadList.isEmpty()) {
- log.error("{}-{} 브랜드의 매출반영 실패한 데이터가 없습니다.", erp.getErpGb(), brandCd);
- continue;
- }
- // 매출반영I/F번호 조회
- String noIf = settleService.getSalesUploadInterfaceNo(erp.getErpGb());
- log.info("매출반영I/F번호: {}", noIf);
- for (GagaMap dataMap : uploadList) {
- // 매출반영목록 I/F번호 Update
- dataMap.setString("ERP_GB", erp.getErpGb());
- dataMap.setString("NO_IF", noIf);
- settleService.updateSalesUploadListInterfaceNo(dataMap);
- }
- // 매출업로드
- GagaMap salesMap = hansaeErp.uploadErpSales(erp.getErpGb(), uploadList);
- if (salesMap == null || salesMap.isEmpty()) {
- log.error("{}-{} 브랜드의 매출반영결과 데이터가 없습니다. 한세 ERP 시스템담당자에게 문의해 주세요.", erp.getErpGb(), brandCd);
- continue;
- }
- // 매출반영결과 처리
- settleService.updateSalesUploadResult(erp.getErpGb(), salesMap);
- log.info("{}-{} 브랜드의 매출반영 업로드 성공", erp.getErpGb(), brandCd);
- }
- return super.ok(message.getMessage("SUCC_0001"));
- }
- }
|