|
|
|
@ -144,6 +144,7 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
String cstart = sdjson.getString("contractualPeriodStart"); |
|
|
|
String curTime = new SimpleDateFormat("HH:mm:ss").format(new Date()); |
|
|
|
String ncstart = cstart + " " + curTime; |
|
|
|
|
|
|
|
//
|
|
|
|
String cend = nsdjson.getString("contractualPeriodEnd"); |
|
|
|
String ncend = cend + " 23:59:59"; |
|
|
|
@ -554,4 +555,126 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 手动导入商品信息 |
|
|
|
* @param jsonObject |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int manuImportGoods(JSONObject jsonObject) { |
|
|
|
// 日期时间格式
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
int count = 0; //统计更新数量
|
|
|
|
String host = ProperUtils.getSzwhProp("ENTRUST_URL"); |
|
|
|
//创建签名
|
|
|
|
String sign = SignUtils.createSign("entrust"); |
|
|
|
// 请求头
|
|
|
|
Map<String, Object> hmap = new HashMap(); |
|
|
|
hmap.put("entrust_token", sign); |
|
|
|
|
|
|
|
// 产品详情地址
|
|
|
|
String gdurl = host + "/consign/exchange/v1/selectEntrustDetails"; |
|
|
|
// 循环查询商品的详情
|
|
|
|
if(jsonObject!=null && jsonObject.containsKey("data") ) { |
|
|
|
// json的data节点
|
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("data"); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
// 获取到sourceData字段信息
|
|
|
|
JSONObject sdjson = (JSONObject) jsonArray.get(i); |
|
|
|
String nsdstr = sdjson.getString("sourceData"); |
|
|
|
if (nsdstr == null) { |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
JSONObject nsdjson = JSONObject.parseObject(nsdstr); |
|
|
|
// 从sourcedata节点中提取商品唯一编号
|
|
|
|
String goodsId = nsdjson.getString("identifier"); |
|
|
|
// 以identifier为主键查询详情
|
|
|
|
String gdetailUrl = gdurl + "/" + goodsId; |
|
|
|
// 请求商品的详情
|
|
|
|
JSONObject gdJson = RequestUtils.GetData(gdetailUrl, hmap,true); |
|
|
|
log.info(goodsId + "详情:" + gdJson); |
|
|
|
//处理返回的结果
|
|
|
|
//JSONArray gdArr = gdJson.getJSONArray("data");
|
|
|
|
// 如果goods表中存在记录,不进行操作
|
|
|
|
Goods tgoods = goodsMapper.getGoodsByIsli(goodsId); |
|
|
|
if (tgoods != null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// add goodsSource,循环插入 商品资源
|
|
|
|
// for (int x = 0; x < gdArr.size(); x++) {
|
|
|
|
// 从里面取出数据
|
|
|
|
JSONObject gditem = gdJson.getJSONObject("data"); |
|
|
|
// 商品详情json非空时候
|
|
|
|
if(gditem!=null){ |
|
|
|
GoodsSource goodsSource = ApiGoodsUtils.jsonToGoodsSource(gditem, goodsId); |
|
|
|
goodsSourceMapper.add(goodsSource); |
|
|
|
} |
|
|
|
// }
|
|
|
|
// insertGoodsDetail
|
|
|
|
GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson); |
|
|
|
// 返回商品详情
|
|
|
|
int gdid = goodsDetailMapper.addGoodsDetail(goodsDetail); |
|
|
|
|
|
|
|
//抽取target 字段中的json,转为jsonobject
|
|
|
|
JSONObject targetJson = sdjson.getJSONObject("targetData"); |
|
|
|
//处理状态
|
|
|
|
int istatus = 0; |
|
|
|
if (sdjson.getInteger("status") == 1 || sdjson.getInteger("status") == 4 || |
|
|
|
sdjson.getInteger("status") == 5) { |
|
|
|
istatus = 1; |
|
|
|
} else if (sdjson.getInteger("status") == 2) { |
|
|
|
istatus = 2; |
|
|
|
} else { |
|
|
|
istatus = 4; |
|
|
|
} |
|
|
|
Goods goods = new Goods(); |
|
|
|
//商品起止时间
|
|
|
|
String cstart = sdjson.getString("contractualPeriodStart"); |
|
|
|
String curTime = new SimpleDateFormat("HH:mm:ss").format(new Date()); |
|
|
|
String ncstart = cstart + " " + curTime; |
|
|
|
//转换为date
|
|
|
|
String cend = nsdjson.getString("contractualPeriodEnd"); |
|
|
|
String ncend = cend + " 23:59:59"; |
|
|
|
try { |
|
|
|
//起止时间转为timestamp
|
|
|
|
SimpleDateFormat tsdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
//开始
|
|
|
|
Timestamp ncst = new Timestamp(tsdf.parse(ncstart).getTime()); |
|
|
|
//截至
|
|
|
|
Timestamp ncet = new Timestamp(tsdf.parse(ncend).getTime()); |
|
|
|
goods.setContractualStartTime(ncst); |
|
|
|
goods.setContractualtimeEndTime(ncet); |
|
|
|
}catch (Exception ex){ |
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
goods.setGoodsDetailId(goodsDetail.getId()); |
|
|
|
goods.setContractStatus(nsdjson.getInteger("contractStatus")); |
|
|
|
goods.setGoodsStatus(istatus); |
|
|
|
goods.setOldStatus(0); // 默认为0
|
|
|
|
goods.setEntrustStatus(sdjson.getInteger("status")); |
|
|
|
//
|
|
|
|
goods.setUserIslicode(targetJson.getString("identifier")); |
|
|
|
goods.setUsername(targetJson.getString("titleName")); |
|
|
|
goods.setIsLicode(sdjson.getString("isliCode")); |
|
|
|
goods.setGoodsIslicode(nsdjson.getString("identifier")); |
|
|
|
goods.setRecommendSort(1); // 默认排序1
|
|
|
|
// 添加,返回当前的编号
|
|
|
|
int ret_gid = goodsMapper.addGoods(goods); |
|
|
|
//添加操作日志
|
|
|
|
OperationLog oplog = new OperationLog(); |
|
|
|
oplog.setLogid(goods.getId()); |
|
|
|
String nowStr = sdf.format(new Date()); |
|
|
|
String message = nowStr + " 发布标的成功"; |
|
|
|
oplog.setMessage(message); |
|
|
|
oplog.setType("goods"); |
|
|
|
// 日志入库
|
|
|
|
operationLogMapper.addLog(oplog); |
|
|
|
} |
|
|
|
// 计算器增加1
|
|
|
|
count++; |
|
|
|
} |
|
|
|
} |
|
|
|
return count; |
|
|
|
} |
|
|
|
} |
|
|
|
|