Commit e676dd19 authored by Quxl's avatar Quxl

x

parent 7c27fdd2
......@@ -41,77 +41,79 @@ public class ProductsTask {
@Scheduled(cron="${pds.cron.products_download}")
public void execute() {
log.debug(DateUtil.format(new Date()) + " PdsProductsUpdateTask RUN");
boolean boo = true;
int loopCount = 0;
while(boo) {
boo = executeUpdateTask() > 0 && loopCount++ < 10;
}
log.debug(DateUtil.format(new Date()) + " PdsProductsUpdateTask RUN START");
this.executeUpdateTask();
log.debug(DateUtil.format(new Date()) + " PdsProductsUpdateTask RUN END");
}
private int executeUpdateTask() {
private void executeUpdateTask() {
Map<String, String> headers = new HashMap<String, String>();
headers.put(authKey, authValue);
String responseBody = HttpUtil.get(urlQuery, headers);
JSONObject jsonObject = JSON.parseObject(responseBody);
JSONArray jsonArray = jsonObject.getJSONArray("data");
if(jsonArray != null) {
for(int i = 0; i < jsonArray.size(); i++) {
JSONObject productJsonObject = jsonArray.getJSONObject(i);
String article_description = productJsonObject.getString("article_description");
String article_group_no = productJsonObject.getString("article_group_no");
String article_short_description = productJsonObject.getString("article_short_description");
String article_type = productJsonObject.getString("article_type");
String barcode = productJsonObject.getString("barcode");
String buying_price = productJsonObject.getString("buying_price");
String buying_price_with_tax = productJsonObject.getString("buying_price_with_tax");
Integer case_qty = productJsonObject.getInteger("case_qty");
String deduction = productJsonObject.getString("deduction");
String made_in = productJsonObject.getString("made_in");
String order_way = productJsonObject.getString("order_way");
String pack_unit = productJsonObject.getString("pack_unit");
String selling_price = productJsonObject.getString("selling_price");
String specification = productJsonObject.getString("specification");
String stores = productJsonObject.getString("stores");
String supplier_article_no = productJsonObject.getString("supplier_article_no");
String supplier_no = productJsonObject.getString("supplier_no");
String tax_rate = productJsonObject.getString("tax_rate");
String trade_mode = productJsonObject.getString("trade_mode");
String weight_article = productJsonObject.getString("weight_article");
Object transactionId = productJsonObject.get("transaction_id");
Map<String, Object> productMap = new HashMap<String, Object>();
productMap.put("article_description", article_description);
productMap.put("article_group_no", article_group_no);
productMap.put("article_short_description", article_short_description);
productMap.put("article_type", article_type);
productMap.put("barcode", barcode);
productMap.put("buying_price", buying_price);
productMap.put("buying_price_with_tax", buying_price_with_tax);
productMap.put("case_qty", case_qty);
productMap.put("deduction", deduction);
productMap.put("made_in", made_in);
productMap.put("order_way", order_way);
productMap.put("pack_unit", pack_unit);
productMap.put("selling_price", selling_price);
productMap.put("specification", specification);
productMap.put("stores", stores);
productMap.put("supplier_article_no", supplier_article_no);
productMap.put("supplier_no", supplier_no);
productMap.put("tax_rate", tax_rate);
productMap.put("trade_mode", trade_mode);
productMap.put("weight_article", weight_article);
productMap.put("dLastUpdateTime", new Date());
try {
pdsService.savePdsProduct(transactionId, productMap);;
} catch (Throwable e) {
log.error("", e);
emailService.sendForasync("PDS TASK ERROR", productJsonObject.toJSONString(), e);
boolean isFinishd = false;
while(!isFinishd) {
String responseBody = HttpUtil.get(urlQuery, headers);
JSONObject jsonObject = JSON.parseObject(responseBody);
JSONArray jsonArray = jsonObject.getJSONArray("data");
if(jsonArray == null || jsonArray.size() == 0) {
isFinishd = true;
} else {
for(int i = 0; i < jsonArray.size(); i++) {
JSONObject productJsonObject = jsonArray.getJSONObject(i);
String article_description = productJsonObject.getString("article_description");
String article_group_no = productJsonObject.getString("article_group_no");
String article_short_description = productJsonObject.getString("article_short_description");
String article_type = productJsonObject.getString("article_type");
String barcode = productJsonObject.getString("barcode");
String buying_price = productJsonObject.getString("buying_price");
String buying_price_with_tax = productJsonObject.getString("buying_price_with_tax");
Integer case_qty = productJsonObject.getInteger("case_qty");
String deduction = productJsonObject.getString("deduction");
String made_in = productJsonObject.getString("made_in");
String order_way = productJsonObject.getString("order_way");
String pack_unit = productJsonObject.getString("pack_unit");
String selling_price = productJsonObject.getString("selling_price");
String specification = productJsonObject.getString("specification");
String stores = productJsonObject.getString("stores");
String supplier_article_no = productJsonObject.getString("supplier_article_no");
String supplier_no = productJsonObject.getString("supplier_no");
String tax_rate = productJsonObject.getString("tax_rate");
String trade_mode = productJsonObject.getString("trade_mode");
String weight_article = productJsonObject.getString("weight_article");
Object transactionId = productJsonObject.get("transaction_id");
Map<String, Object> productMap = new HashMap<String, Object>();
productMap.put("article_description", article_description);
productMap.put("article_group_no", article_group_no);
productMap.put("article_short_description", article_short_description);
productMap.put("article_type", article_type);
productMap.put("barcode", barcode);
productMap.put("buying_price", buying_price);
productMap.put("buying_price_with_tax", buying_price_with_tax);
productMap.put("case_qty", case_qty);
productMap.put("deduction", deduction);
productMap.put("made_in", made_in);
productMap.put("order_way", order_way);
productMap.put("pack_unit", pack_unit);
productMap.put("selling_price", selling_price);
productMap.put("specification", specification);
productMap.put("stores", stores);
productMap.put("supplier_article_no", supplier_article_no);
productMap.put("supplier_no", supplier_no);
productMap.put("tax_rate", tax_rate);
productMap.put("trade_mode", trade_mode);
productMap.put("weight_article", weight_article);
productMap.put("dLastUpdateTime", new Date());
try {
pdsService.savePdsProduct(transactionId, productMap);;
} catch (Throwable e) {
log.error("", e);
emailService.sendForasync("PDS TASK ERROR", productJsonObject.toJSONString(), e);
}
}
}
}
return jsonArray == null ? 0 : jsonArray.size();
}
public static void main(String[] args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment