|
@@ -10,17 +10,21 @@ import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
-import com.style24.persistence.domain.ErpStock;
|
|
|
|
|
|
|
+import com.style24.persistence.domain.Erp;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import com.gagaframework.web.parameter.GagaMap;
|
|
import com.gagaframework.web.parameter.GagaMap;
|
|
|
|
|
+import com.gagaframework.web.util.GagaStringUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 한세MK와 한세드림 ERP
|
|
* 한세MK와 한세드림 ERP
|
|
@@ -33,10 +37,13 @@ import com.gagaframework.web.parameter.GagaMap;
|
|
|
public class HansaeErp {
|
|
public class HansaeErp {
|
|
|
|
|
|
|
|
// 상품 URL
|
|
// 상품 URL
|
|
|
- private String goodsUrl = "http://erp.hansaemk.com:96/api/hsdr/Shop/GoodsInfo";
|
|
|
|
|
|
|
+ private String goodsUrl = "http://erp.hansaemk.com:96/api/#{erpGb}/Shop/GoodsInfo";
|
|
|
|
|
|
|
|
// 재고 URL
|
|
// 재고 URL
|
|
|
- private String stockUrl = "http://erp.hansaemk.com:96/api/hsdr/Shop/StockCheck";
|
|
|
|
|
|
|
+ private String stockUrl = "http://erp.hansaemk.com:96/api/#{erpGb}/Shop/StockCheck";
|
|
|
|
|
+
|
|
|
|
|
+ // 매출반영 URL
|
|
|
|
|
+ private String salesUrl = "http://erp.hansaemk.com:96/api/#{erpGb}/Shop/SaleIF";
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
@@ -46,21 +53,38 @@ public class HansaeErp {
|
|
|
log.info("\n\n---- HansaeErp initialization started ----");
|
|
log.info("\n\n---- HansaeErp initialization started ----");
|
|
|
log.info("goodsUrl: [{}]", goodsUrl);
|
|
log.info("goodsUrl: [{}]", goodsUrl);
|
|
|
log.info("stockUrl: [{}]", stockUrl);
|
|
log.info("stockUrl: [{}]", stockUrl);
|
|
|
|
|
+ log.info("salesUrl: [{}]", salesUrl);
|
|
|
log.info("\n--- HansaeErp initialization completed ----\n");
|
|
log.info("\n--- HansaeErp initialization completed ----\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ERP구분
|
|
|
|
|
+ public enum ErpGb {
|
|
|
|
|
+ HANSAE_MK("hsmk"), // 한세MK
|
|
|
|
|
+ HANSAE_DR("hsdr"); // 한세드림
|
|
|
|
|
+
|
|
|
|
|
+ private String value;
|
|
|
|
|
+
|
|
|
|
|
+ ErpGb(String value) {
|
|
|
|
|
+ this.value = value;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String value() {
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* ERP 상품별 매장재고 목록
|
|
* ERP 상품별 매장재고 목록
|
|
|
- * @param Delivery
|
|
|
|
|
|
|
+ * @param erpGb - ERP구분(hsmk:한세MK, hsdr:한세드림)
|
|
|
* @return
|
|
* @return
|
|
|
* @author moon
|
|
* @author moon
|
|
|
* @since 2021. 03. 28
|
|
* @since 2021. 03. 28
|
|
|
*/
|
|
*/
|
|
|
- public Collection<ErpStock> getErpGoodsStockList() {
|
|
|
|
|
- Collection<ErpStock> stockList = new ArrayList<>();
|
|
|
|
|
|
|
+ public Collection<Erp> getErpGoodsStockList(String erpGb) {
|
|
|
|
|
+ Collection<Erp> stockList = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- String requestUrl = goodsUrl;
|
|
|
|
|
|
|
+ String requestUrl = GagaStringUtil.replace(goodsUrl, "#{erpGb}", erpGb);
|
|
|
log.info("requestUrl: {}", requestUrl);
|
|
log.info("requestUrl: {}", requestUrl);
|
|
|
|
|
|
|
|
URI url = URI.create(requestUrl);
|
|
URI url = URI.create(requestUrl);
|
|
@@ -75,23 +99,25 @@ public class HansaeErp {
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
GagaMap resultMap = gson.fromJson(jsonResult, GagaMap.class);
|
|
GagaMap resultMap = gson.fromJson(jsonResult, GagaMap.class);
|
|
|
|
|
|
|
|
- // 상품별 매장재고 정보
|
|
|
|
|
- String goodsInfo = resultMap.get("GoodsInfo").toString();
|
|
|
|
|
- log.info("goodsInfo: {}", goodsInfo);
|
|
|
|
|
-
|
|
|
|
|
- if (StringUtils.isNotBlank(goodsInfo)) {
|
|
|
|
|
- List<Map<String, Object>> dataList = gson.fromJson(goodsInfo, new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
- }.getType());
|
|
|
|
|
-
|
|
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
- Map<String, Object> data = dataList.get(i);
|
|
|
|
|
- ErpStock stock = new ErpStock();
|
|
|
|
|
- stock.setCD_STYLE(data.get("CD_STYLE").toString());
|
|
|
|
|
- stock.setCD_COLOR(data.get("CD_COLOR").toString());
|
|
|
|
|
- stock.setCD_SIZE(data.get("CD_SIZE").toString());
|
|
|
|
|
- stock.setCD_SHOP(data.get("CD_SHOP").toString());
|
|
|
|
|
- stock.setQT_STOCK((int)Double.parseDouble(data.get("QT_STOCK").toString()));
|
|
|
|
|
- stockList.add(stock);
|
|
|
|
|
|
|
+ if (resultMap.containsKey("GoodsInfo")) {
|
|
|
|
|
+ // 상품별 매장재고 정보
|
|
|
|
|
+ String goodsInfo = resultMap.get("GoodsInfo").toString();
|
|
|
|
|
+ log.info("goodsInfo: {}", goodsInfo);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(goodsInfo)) {
|
|
|
|
|
+ List<Map<String, Object>> dataList = gson.fromJson(goodsInfo, new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
+ }.getType());
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> data = dataList.get(i);
|
|
|
|
|
+ Erp stock = new Erp();
|
|
|
|
|
+ stock.setCD_STYLE(data.get("CD_STYLE").toString());
|
|
|
|
|
+ stock.setCD_COLOR(data.get("CD_COLOR").toString());
|
|
|
|
|
+ stock.setCD_SIZE(data.get("CD_SIZE").toString());
|
|
|
|
|
+ stock.setCD_SHOP(data.get("CD_SHOP").toString());
|
|
|
|
|
+ stock.setQT_STOCK((int)Double.parseDouble(data.get("QT_STOCK").toString()));
|
|
|
|
|
+ stockList.add(stock);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -103,6 +129,7 @@ public class HansaeErp {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* ERP 매장 실재고 목록
|
|
* ERP 매장 실재고 목록
|
|
|
|
|
+ * @param erpGb - ERP구분(hsmk:한세MK, hsdr:한세드림)
|
|
|
* @param styleCd - 스타일코드
|
|
* @param styleCd - 스타일코드
|
|
|
* @param colorCd - 색상코드
|
|
* @param colorCd - 색상코드
|
|
|
* @param sizeCd - 사이즈코드
|
|
* @param sizeCd - 사이즈코드
|
|
@@ -110,11 +137,11 @@ public class HansaeErp {
|
|
|
* @author moon
|
|
* @author moon
|
|
|
* @since 2021. 03. 29
|
|
* @since 2021. 03. 29
|
|
|
*/
|
|
*/
|
|
|
- public Collection<ErpStock> getErpRealStockList(String styleCd, String colorCd, String sizeCd) {
|
|
|
|
|
- Collection<ErpStock> stockList = new ArrayList<>();
|
|
|
|
|
|
|
+ public Collection<Erp> getErpRealStockList(String erpGb, String styleCd, String colorCd, String sizeCd) {
|
|
|
|
|
+ Collection<Erp> stockList = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- String requestUrl = stockUrl + "?CD_STYLE=" + styleCd + "&CD_COLOR=" + colorCd + "&CD_SIZE=" + sizeCd;
|
|
|
|
|
|
|
+ String requestUrl = GagaStringUtil.replace(stockUrl, "#{erpGb}", erpGb) + "?CD_STYLE=" + styleCd + "&CD_COLOR=" + colorCd + "&CD_SIZE=" + sizeCd;
|
|
|
log.info("requestUrl: {}", requestUrl);
|
|
log.info("requestUrl: {}", requestUrl);
|
|
|
|
|
|
|
|
URI url = URI.create(requestUrl);
|
|
URI url = URI.create(requestUrl);
|
|
@@ -129,27 +156,132 @@ public class HansaeErp {
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
GagaMap resultMap = gson.fromJson(jsonResult, GagaMap.class);
|
|
GagaMap resultMap = gson.fromJson(jsonResult, GagaMap.class);
|
|
|
|
|
|
|
|
- // 재고 정보
|
|
|
|
|
- String stockCheck = resultMap.get("StockCheck").toString();
|
|
|
|
|
- log.info("stockCheck: {}", stockCheck);
|
|
|
|
|
|
|
+ if (resultMap.containsKey("StockCheck")) {
|
|
|
|
|
+ // 재고 정보
|
|
|
|
|
+ String stockCheck = resultMap.get("StockCheck").toString();
|
|
|
|
|
+ log.info("stockCheck: {}", stockCheck);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(stockCheck)) {
|
|
|
|
|
+ List<Map<String, Object>> dataList = gson.fromJson(stockCheck, new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
+ }.getType());
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> data = dataList.get(i);
|
|
|
|
|
+ Erp stock = new Erp();
|
|
|
|
|
+ stock.setStockLoc(data.get("CD_SHOP").toString());
|
|
|
|
|
+ stock.setLocQty((int)Double.parseDouble(data.get("QT_STOCK").toString()));
|
|
|
|
|
+ stockList.add(stock);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("{}", e.getMessage().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return stockList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * ERP 매출반영
|
|
|
|
|
+ * @param erpGb - ERP구분(hsmk:한세MK, hsdr:한세드림)
|
|
|
|
|
+ * @param salesList - 매출 목록
|
|
|
|
|
+ * @return 매출반영 결과
|
|
|
|
|
+ * 사용예)
|
|
|
|
|
+ * GagaMap salesMap = HansaeErp.uploadErpSales(HansaeErp.ErpGb.HANSAE_MK.value(), salesList);
|
|
|
|
|
+ * Collection<Erp> succList = (Collection<Erp>) salesMap.get("succList");
|
|
|
|
|
+ * if (succList != null && !succList.isEmpty()) {
|
|
|
|
|
+ * ...
|
|
|
|
|
+ * }
|
|
|
|
|
+ * Collection<Erp> failList = (Collection<Erp>) salesMap.get("failList");
|
|
|
|
|
+ * if (failList != null && !failList.isEmpty()) {
|
|
|
|
|
+ * ...
|
|
|
|
|
+ * }
|
|
|
|
|
+ * @author gagamel
|
|
|
|
|
+ * @since 2021. 6. 8
|
|
|
|
|
+ */
|
|
|
|
|
+ public GagaMap uploadErpSales(String erpGb, Collection<Erp> salesList) {
|
|
|
|
|
+ GagaMap salesMap = new GagaMap();
|
|
|
|
|
|
|
|
- if (StringUtils.isNotBlank(stockCheck)) {
|
|
|
|
|
- List<Map<String, Object>> dataList = gson.fromJson(stockCheck, new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
- }.getType());
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // Parameter
|
|
|
|
|
+ String requestData = (new Gson()).toJson(salesList, new TypeToken<Collection<Erp>>() {
|
|
|
|
|
+ }.getType());
|
|
|
|
|
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
|
|
|
|
+ params.add("DATA", requestData);
|
|
|
|
|
+ log.info("params: {}", params);
|
|
|
|
|
+
|
|
|
|
|
+ String requestUrl = GagaStringUtil.replace(salesUrl, "#{erpGb}", erpGb);
|
|
|
|
|
+ log.info("requestUrl: {}", requestUrl);
|
|
|
|
|
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
- Map<String, Object> data = dataList.get(i);
|
|
|
|
|
- ErpStock stock = new ErpStock();
|
|
|
|
|
- stock.setStockLoc(data.get("CD_SHOP").toString());
|
|
|
|
|
- stock.setLocQty((int)Double.parseDouble(data.get("QT_STOCK").toString()));
|
|
|
|
|
- stockList.add(stock);
|
|
|
|
|
|
|
+ HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params);
|
|
|
|
|
+ URI url = URI.create(requestUrl);
|
|
|
|
|
+
|
|
|
|
|
+ // POST방식으로 호출
|
|
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
|
|
|
|
|
+ log.info("responseEntity.getStatusCode(): {} ", responseEntity.getStatusCode());
|
|
|
|
|
+
|
|
|
|
|
+ String jsonResult = responseEntity.getBody();
|
|
|
|
|
+ log.info("responseEntity.getBody(): {}", jsonResult);
|
|
|
|
|
+
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ GagaMap resultMap = gson.fromJson(jsonResult, GagaMap.class);
|
|
|
|
|
+
|
|
|
|
|
+ if (resultMap.containsKey("Message")) { // 전체에 대한 실패 메시지가 있으면
|
|
|
|
|
+ log.error("Message: {}", resultMap.get("Message").toString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (resultMap.containsKey("SuccessCount")) { // 성공건수가 있으면
|
|
|
|
|
+ // 성공 목록
|
|
|
|
|
+ int succCnt = Integer.parseInt(resultMap.get("SuccessCount").toString());
|
|
|
|
|
+ log.info("succCnt: {}", succCnt);
|
|
|
|
|
+
|
|
|
|
|
+ if (succCnt > 0) {
|
|
|
|
|
+ List<Map<String, Object>> dataList = gson.fromJson(resultMap.get("Success").toString(), new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
+ }.getType());
|
|
|
|
|
+
|
|
|
|
|
+ Collection<Erp> succList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> data = dataList.get(i);
|
|
|
|
|
+ Erp erp = new Erp();
|
|
|
|
|
+ erp.setCD_SALEBILL(data.get("CD_SALEBILL").toString());
|
|
|
|
|
+ erp.setQT_SALE(Integer.parseInt(data.get("QT_SALE").toString()));
|
|
|
|
|
+ erp.setAM_ACSALE(Integer.parseInt(data.get("AM_ACSALE").toString()));
|
|
|
|
|
+ succList.add(erp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ salesMap.set("succList", succList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (resultMap.containsKey("FailureCount")) { // 실패건수가 있으면
|
|
|
|
|
+ // 실패 목록
|
|
|
|
|
+ int failCnt = Integer.parseInt(resultMap.get("FailureCount").toString());
|
|
|
|
|
+ log.info("failCnt: {}", failCnt);
|
|
|
|
|
+
|
|
|
|
|
+ if (failCnt > 0) {
|
|
|
|
|
+ List<Map<String, Object>> dataList = gson.fromJson(resultMap.get("Failure").toString(), new TypeToken<List<Map<String, Object>>>() {
|
|
|
|
|
+ }.getType());
|
|
|
|
|
+
|
|
|
|
|
+ Collection<Erp> failList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> data = dataList.get(i);
|
|
|
|
|
+ Erp erp = new Erp();
|
|
|
|
|
+ erp.setNO_IF(data.get("NO_IF").toString());
|
|
|
|
|
+ erp.setCD_STYLE(data.get("CD_STYLE").toString());
|
|
|
|
|
+ erp.setCD_COLOR(data.get("CD_COLOR").toString());
|
|
|
|
|
+ erp.setCD_SIZE(data.get("CD_SIZE").toString());
|
|
|
|
|
+ erp.setDS_ERROR(data.get("DS_ERROR").toString());
|
|
|
|
|
+ failList.add(erp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ salesMap.set("failList", failList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("{}", e.getMessage().toString());
|
|
log.error("{}", e.getMessage().toString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return stockList;
|
|
|
|
|
|
|
+ return salesMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|