Browse Source

代码更新

master
xyiege 3 years ago
parent
commit
de774da610
  1. 30
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  2. 1
      src/main/java/cn/chjyj/szwh/task/TaskInit.java
  3. 67
      src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtisl.java
  4. 1
      src/main/resources/application.properties
  5. 31
      src/test/java/cn/chjyj/szwh/ApiTest.java

30
src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

@ -80,13 +80,35 @@ public class GoodsServiceImpl implements GoodsService {
// hmap.put("Content-Type", "application/json");
// get 方式获取
JSONObject jsonObject = RequestUtils.GetData(apiurl, hmap);
log.info("goods api result : " + jsonObject);
// 检索出对象
// json的data节点
JSONArray jsonArray = jsonObject.getJSONArray("data");
log.info("goods jsonarray: " + jsonArray);
// 产品详情地址
String gdurl = host + "/consign/exchange/v1/selectEntrustDetails";
// 循环查询商品的详情
for(int i=0;i<jsonArray.size();i++){
// 获取到sourceData字段信息
JSONObject sdjson = (JSONObject) jsonArray.get(i);
String nsdstr = sdjson.getString("sourceData");
JSONObject nsdjson = JSONObject.parseObject(nsdstr);
// 从sourcedata节点中提取商品唯一编号
String goodsId= nsdjson.getString("identifier");
// 以identifier为主键查询详情
String gdetailUrl = gdurl+"/"+goodsId;
// 增加日志信息
// 执行get请求
JSONObject gdJson = RequestUtils.GetData(gdetailUrl, hmap);
//处理返回的结果
JSONArray gdArr = jsonObject.getJSONArray("data");
// 如果goods表中存在记录,不进行操作
Goods tgoods = goodsMapper.getGoodsByIsli(goodsId);
if(tgoods!=null){
continue;
}
// add goodsSource
// insertGoodsDetail
}
return count;
}

1
src/main/java/cn/chjyj/szwh/task/TaskInit.java

@ -25,6 +25,7 @@ public class TaskInit implements ApplicationRunner {
.storeDurably()
.build();
// cron 构建
// 10十分钟执行一次
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
.cronSchedule("0/10 * * * * ? *");
// 创建任务触发器

67
src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtisl.java

@ -0,0 +1,67 @@
package cn.chjyj.szwh.utils;
import cn.chjyj.szwh.bean.GoodsSource;
import com.alibaba.fastjson.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 处理api数据转为bean
*/
public class ApiGoodsUtisl {
/**
* 从json字符串中抽取对象
* @param innerJson
* @param islicode
* @return
*/
public static GoodsSource jsonToGoodsSource(JSONObject innerJson,String islicode){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
GoodsSource goodsSource = new GoodsSource();
goodsSource.setServicecode(innerJson.getString("'serviceCode'"));
goodsSource.setLinkcode(innerJson.getString("linkCode"));
// 发布 id
String pubid = innerJson.getString("publisherId");
goodsSource.setPublisherid(Integer.valueOf(pubid));
goodsSource.setRegistrant(innerJson.getString("register"));
goodsSource.setResolutionUrl(innerJson.getString("resolutionUrl"));
goodsSource.setSourceType(innerJson.getString("sourceType"));
goodsSource.setSourceNameType(innerJson.getString("sourceNameType"));
goodsSource.setSourceName(innerJson.getString("sourceName"));
//
goodsSource.setSourceidentify(innerJson.getString("sourceIdentify"));
goodsSource.setSourceFragment(innerJson.getString("sourceFragment"));
goodsSource.setTargetName(innerJson.getString("targetName"));
goodsSource.setTargetNameType(innerJson.getString("targetNameType"));
goodsSource.setTargetidentify(innerJson.getString("targetIdentify"));
//
goodsSource.setTargetFragment(innerJson.getString("targetFragment"));
goodsSource.setTargetformat(innerJson.getString("targetFormat"));
// 存放了json字符串
goodsSource.setSourceData(innerJson.getString("sourceData"));
goodsSource.setTargetData(innerJson.getString("targetData"));
//
goodsSource.setMetadataxml(innerJson.getString("metadataXml"));
goodsSource.setCancellationReason(innerJson.getString("cancellationReason"));
// 字符串转为日期时间格式
String aldate =innerJson.getString("allocationDate");
try {
Date ndate = sdf.parse(aldate);
goodsSource.setAllocationtime(ndate);
}catch (Exception ex){
// do nothing
}
goodsSource.setSourceType(innerJson.getString("dataType"));
try{
String cldate = innerJson.getString("cancellationDate");
Date cndate =sdf.parse(cldate);
goodsSource.setCancellationtime(cndate);
}catch (Exception ex){
//do nothing
}
// 产品主键
goodsSource.setGoodsIsliCode(islicode);
return goodsSource;
}
}

1
src/main/resources/application.properties

@ -24,6 +24,7 @@ spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-wait=-1
# 暂使用单机模式进行任务管理
spring.quartz.scheduler-name=szwhQuartz
spring.quartz.job-store-type=memory
# quartz 自动启动
spring.quartz.auto-startup=true

31
src/test/java/cn/chjyj/szwh/ApiTest.java

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save