|
|
@@ -4,14 +4,18 @@ import com.uas.eis.config.LingXingConfig;
|
|
|
import com.uas.eis.sdk.entity.Result;
|
|
|
import com.uas.eis.sdk.okhttp.AKRestClient;
|
|
|
import com.uas.eis.sdk.resp.AccessTokenGetResp;
|
|
|
+import com.uas.eis.sdk.resp.Order;
|
|
|
import com.uas.eis.sdk.resp.SellerGetResp;
|
|
|
import com.uas.eis.service.LingxingService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author: zhouy
|
|
|
@@ -23,39 +27,166 @@ public class LingxingServiceImpl implements LingxingService {
|
|
|
@Resource
|
|
|
private LingXingConfig lingXingConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+
|
|
|
+ /** 接口请求成功状态码 */
|
|
|
+ private final static Integer SUCCESS_CODE = 0;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@Async("taskExecutor")
|
|
|
public void getSellerOrders(String appId) {
|
|
|
String appSecret = lingXingConfig.getApps().get(appId);
|
|
|
try {
|
|
|
- /**
|
|
|
- * 获取Token
|
|
|
- * */
|
|
|
- AccessTokenGetResp accessTokenGetResp = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getAccessToken(appId, appSecret);
|
|
|
- System.out.println(accessTokenGetResp.getData());
|
|
|
- /**
|
|
|
- * 获取店铺信息
|
|
|
- * */
|
|
|
- SellerGetResp sellerGetResp = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getSellers(appId,
|
|
|
- String.valueOf(accessTokenGetResp.getData().get("access_token")) );
|
|
|
- //待完善记录店铺信息
|
|
|
+ List<String> sssqls = new ArrayList<>();
|
|
|
+ String startdate = null;
|
|
|
+ String enddate = "";
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
+ //判断是否有对接记录13
|
|
|
+ int count = baseDao.getCountByCondition("MESSAGELOGLX", "MLL_RESULT='对接订单完成'");
|
|
|
+ if (count == 0) {
|
|
|
+ startdate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
|
+ enddate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
|
+ } else {
|
|
|
+ Object start = baseDao.getFieldDataByCondition("MESSAGELOGLX", "max(to_char(MLL_DATE,'yyyy-mm-dd'))", "MLL_RESULT='对接订单完成'");
|
|
|
+ startdate = start.toString();
|
|
|
+ enddate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ //判断最新获取日期是否小于当前日期前一天
|
|
|
+ if ((sdf.parse(enddate).compareTo(sdf.parse(startdate)) > 0 && count > 0) || (sdf.parse(startdate).compareTo(sdf.parse(enddate)) == 0 && count == 0)) {
|
|
|
+ sssqls.add("insert into MESSAGELOGLX (MLL_ID,MLL_DATE,MLL_CONTENT,MLL_RESULT,MLL_APPID) " +
|
|
|
+ "values(MESSAGELOGLX_SEQ.nextval,sysdate,'对接订单开始','对接订单开始','" + appId + "')");
|
|
|
+ /**
|
|
|
+ * 获取Token
|
|
|
+ * */
|
|
|
+ AccessTokenGetResp accessTokenGetResp = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getAccessToken(appId, appSecret);
|
|
|
+ //System.out.println(accessTokenGetResp.getData());
|
|
|
+ sssqls.add("insert into MESSAGELOGLX (MLL_ID,MLL_DATE,MLL_CONTENT,MLL_RESULT,MLL_APPID) " +
|
|
|
+ "values(MESSAGELOGLX_SEQ.nextval,sysdate,'获取Token','获取Token成功','" + appId + "')");
|
|
|
+ /**
|
|
|
+ * 获取店铺信息
|
|
|
+ * */
|
|
|
+ SellerGetResp sellerGetResp = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getSellers(appId,
|
|
|
+ String.valueOf(accessTokenGetResp.getData().get("access_token")));
|
|
|
+ sssqls.add("insert into MESSAGELOGLX (MLL_ID,MLL_DATE,MLL_CONTENT,MLL_RESULT,MLL_APPID) " +
|
|
|
+ "values(MESSAGELOGLX_SEQ.nextval,sysdate,'获取店铺信息','获取店铺信息成功','" + appId + "')");
|
|
|
+ //待完善记录店铺信息
|
|
|
+ // todo 判断是否存在数据,没有直接返回
|
|
|
+ if (!this.isEmpty(sellerGetResp) && !this.isEmpty(sellerGetResp.getData()) && sellerGetResp.getData().size() > 0) {
|
|
|
+
|
|
|
+ String finalStartdate = startdate;
|
|
|
+ String finalEnddate = enddate;
|
|
|
+ sellerGetResp.getData().stream().forEach(seller -> {
|
|
|
+ //循环封装获取到得商店数据信息
|
|
|
+ //System.out.println(seller.toString());
|
|
|
+ //批量向数据库添加数据
|
|
|
+ sssqls.add("insert into SALESHOP (SS_ID,SS_SID,SS_MID,SS_NAME,SS_REGION,SS_COUNTRY,SS_SELLERID,SS_DATE) " +
|
|
|
+ "values(SALESHOP_SEQ.nextval," + seller.getSid() + "," + seller.getMid() + ",'" + seller.getName() + "','" + seller.getRegion()
|
|
|
+ + "','" + seller.getCountry() + "','" + seller.getSeller_account_id() + "',sysdate)");
|
|
|
|
|
|
|
|
|
- //订单信息
|
|
|
+ //订单信息
|
|
|
+ Map<String, Object> requestParam = new HashMap<>();
|
|
|
+ requestParam.put("sid", 622);
|
|
|
+ requestParam.put("start_date", finalStartdate);
|
|
|
+ requestParam.put("end_date", finalEnddate);
|
|
|
+ //上次同步时间
|
|
|
|
|
|
- Map<String ,Object> requestParam = new HashMap<>();
|
|
|
- requestParam.put("sid", 622);
|
|
|
- requestParam.put("start_date", "2021-07-03");
|
|
|
- requestParam.put("end_date", "2021-08-04");
|
|
|
- //上次同步时间
|
|
|
+ Order o1 = null;
|
|
|
+ try {
|
|
|
+ o1 = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getSellerOrders(appId,
|
|
|
+ String.valueOf(accessTokenGetResp.getData().get("access_token")), requestParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!this.isEmpty(o1) && !this.isEmpty(o1.getData()) && o1.getData().size() > 0) {
|
|
|
|
|
|
- Object o1 = AKRestClient.builder().endpoint(lingXingConfig.getApiUrl()).build().getSellerOrders(appId,
|
|
|
- String.valueOf(accessTokenGetResp.getData().get("access_token")), requestParam);
|
|
|
+ o1.getData().stream().forEach(orderDetail -> {
|
|
|
+ int soid = baseDao.getSeqId("SALEORDER_SEQ");
|
|
|
+ sssqls.add("insert into SALEORDER (SO_ID,SO_CODE,SO_DATE,SO_CURRENCY," +
|
|
|
+ "SO_AMOUNT,SO_FULFILLMENT,SO_BUYERNAME,SO_BUYEREMAIL,SO_RETURN," +
|
|
|
+ "SO_ISMCFORDER,SO_ISASSESSED,SO_EARLIESTDATE,SO_SHIPDATE,SO_UPDATEDATE," +
|
|
|
+ "SO_RECEIVINGNAME,SO_RECEIVINGADDRESS,SO_SELLERNAME,SO_TRACKINGNUMBER,SO_POSTALCODE," +
|
|
|
+ "SO_PHONE,SO_POSTEDDATE,SO_TOTALQTY,SO_DJDATE) " +
|
|
|
+ "values (" + soid + ",'" + orderDetail.getAmazon_order_id() + "',to_date('" + orderDetail.getPurchase_date_local() + "','yyyy-mm-dd hh24:mi:ss'),'" + orderDetail.getOrder_total_currency_code() + "'," +
|
|
|
+ orderDetail.getOrder_total_amount() + ",'" + orderDetail.getFulfillment_channel() + "','" + orderDetail.getBuyer_name() + "','" + orderDetail.getBuyer_email() + "','" + orderDetail.getIs_return() + "'," +
|
|
|
+ "'" + orderDetail.getIs_mcf_order() + "','" + orderDetail.getIs_assessed() + "',to_date('" + this.dateFormatTo(orderDetail.getEarliest_ship_date()) + "','yyyy-mm-dd hh24:mi:ss'),to_date('" + this.dateFormatTo(orderDetail.getShipment_date()) + "','yyyy-mm-dd hh24:mi:ss'),to_date('" + this.dateFormatTo(orderDetail.getLast_update_date()) + "','yyyy-mm-dd hh24:mi:ss')," +
|
|
|
+ "'" + orderDetail.getName() + "','" + orderDetail.getAddress() + "','" + orderDetail.getSeller_name() + "'," + "'" + orderDetail.getTracking_number() + "','" + orderDetail.getPostal_code() + "'," +
|
|
|
+ "'" + orderDetail.getPhone() + "',to_date('" + orderDetail.getPosted_date() + "','yyyy-mm-dd hh24:mi:ss')," + orderDetail.getTotal() + ",sysdate)");
|
|
|
+ if (!this.isEmpty(orderDetail) && !this.isEmpty(orderDetail.getItem_list()) && orderDetail.getItem_list().size() > 0) {
|
|
|
+ orderDetail.getItem_list().stream().forEach(orderItem -> {
|
|
|
+ sssqls.add("insert into SALEITEM(SI_ID,SI_SOID,SI_ASIN,SI_QUANTITYORDERED,SI_SELLERSKU)" +
|
|
|
+ "values(SALEITEM_SEQ.nextval," + soid + ",'" + orderItem.getAsin() + "','" + orderItem.getQuantity_ordered() + "','" + orderItem.getSeller_sku() + "')");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ sssqls.add("insert into MESSAGELOGLX (MLL_ID,MLL_DATE,MLL_CONTENT,MLL_RESULT,MLL_APPID) " +
|
|
|
+ "values(MESSAGELOGLX_SEQ.nextval,sysdate,'获取订单信息','获取订单信息成功','" + appId + "')");
|
|
|
+ sssqls.add("insert into MESSAGELOGLX (MLL_ID,MLL_DATE,MLL_CONTENT,MLL_RESULT,MLL_APPID) " +
|
|
|
+ "values(MESSAGELOGLX_SEQ.nextval,sysdate,'对接订单完成','对接订单完成','" + appId + "')");
|
|
|
+ baseDao.execute(sssqls);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public String dateFormatTo(Date date){
|
|
|
+ if(date != null) {
|
|
|
+ Date ship_date = null;
|
|
|
+ String formatDate = null;
|
|
|
+ try {
|
|
|
+ String ship = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
|
|
|
+ .format(date);
|
|
|
+ ship_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
|
|
|
+ .parse(ship);
|
|
|
+ formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ship_date);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return formatDate;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断对象空
|
|
|
+ * */
|
|
|
+ public static boolean isEmpty(Object obj)
|
|
|
+
|
|
|
+ {
|
|
|
+ if (obj == null)
|
|
|
+
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((obj instanceof List))
|
|
|
+
|
|
|
+ {
|
|
|
+ return ((List) obj).size() == 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((obj instanceof String))
|
|
|
+
|
|
|
+ {
|
|
|
+ return ((String) obj).trim().equals("");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|