Browse Source

详情数据数组处理

master
xyiege 4 years ago
parent
commit
111944f777
  1. 43
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  2. 16
      src/test/java/cn/chjyj/szwh/ApiTest.java

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

@ -87,6 +87,7 @@ public class GoodsServiceImpl implements GoodsService {
/** /**
* 根据类型查找用户信息 * 根据类型查找用户信息
*
* @param type * @param type
* @return * @return
*/ */
@ -510,26 +511,26 @@ public class GoodsServiceImpl implements GoodsService {
String goodsId = nsdjson.getString("identifier"); String goodsId = nsdjson.getString("identifier");
// 以identifier为主键查询详情 // 以identifier为主键查询详情
JSONObject rqjson = new JSONObject(); JSONObject rqjson = new JSONObject();
rqjson.put("isliCode",goodsId); rqjson.put("isliCode", goodsId);
JSONObject gdJson=SzwhApiUtils.apiGoodsDetail(rqjson.toJSONString()); JSONObject gdJson = SzwhApiUtils.apiGoodsDetail(rqjson.toJSONString());
log.info(goodsId + "详情:" + gdJson); log.info(goodsId + "详情:" + gdJson);
//处理返回的结果 //处理返回的结果
//JSONArray gdArr = gdJson.getJSONArray("data"); JSONArray gdArr = gdJson.getJSONArray("data");
// 如果goods表中存在记录,不进行操作 // 如果goods表中存在记录,不进行操作
Goods tgoods = goodsMapper.getGoodsByIsli(goodsId); Goods tgoods = goodsMapper.getGoodsByIsli(goodsId);
if (tgoods != null) { if (tgoods != null) {
continue; continue;
} }
// add goodsSource,循环插入 商品资源 // add goodsSource,循环插入 商品资源
// for (int x = 0; x < gdArr.size(); x++) { for (int x = 0; x < gdArr.size(); x++) {
// 从里面取出数据 // 从里面取出数据
JSONObject gditem = gdJson.getJSONObject("data"); JSONObject gditem = (JSONObject) gdArr.get(i);
// 商品详情json非空时候 // 商品详情json非空时候
if (gditem != null) { if (gditem != null) {
GoodsSource goodsSource = ApiGoodsUtils.jsonToGoodsSource(gditem, goodsId); GoodsSource goodsSource = ApiGoodsUtils.jsonToGoodsSource(gditem, goodsId);
goodsSourceMapper.add(goodsSource); goodsSourceMapper.add(goodsSource);
}
} }
// }
// insertGoodsDetail // insertGoodsDetail
GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson); GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson);
// 返回商品详情 // 返回商品详情
@ -564,7 +565,7 @@ public class GoodsServiceImpl implements GoodsService {
//转换为date //转换为date
String cend = nsdjson.getString("contractualPeriodEnd"); String cend = nsdjson.getString("contractualPeriodEnd");
if (StringUtils.isBlank(cend) && day!=null) { if (StringUtils.isBlank(cend) && day != null) {
//如果是一次性授权或单次授权,存在托管结束时间 //如果是一次性授权或单次授权,存在托管结束时间
if (iperiod == 2) { if (iperiod == 2) {
try { try {
@ -575,30 +576,30 @@ public class GoodsServiceImpl implements GoodsService {
int wkday = calendar.get(Calendar.DAY_OF_WEEK); int wkday = calendar.get(Calendar.DAY_OF_WEEK);
//周末顺延 //周末顺延
// notice:在节假日调休时候,会有变动 // notice:在节假日调休时候,会有变动
day=wkday>5?(wkday-5+1):0; day = wkday > 5 ? (wkday - 5 + 1) : 0;
// 委托终止时间 // 委托终止时间
Date wtEnd = DateUtils.daysAgoOrAfter(wtStart, day); Date wtEnd = DateUtils.daysAgoOrAfter(wtStart, day);
// 统计该时间段内的节假日 // 统计该时间段内的节假日
int fdays = festivalsMapper.countDayBetweenDays(wtStart,wtEnd,iyear); int fdays = festivalsMapper.countDayBetweenDays(wtStart, wtEnd, iyear);
// 节假日顺眼后的日期 // 节假日顺眼后的日期
Date fwtEnd= DateUtils.daysAgoOrAfter(wtEnd,fdays); Date fwtEnd = DateUtils.daysAgoOrAfter(wtEnd, fdays);
cend = fwtEnd.toString(); cend = fwtEnd.toString();
} catch (Exception ex) { } catch (Exception ex) {
log.error("一次性委托日期转码出错:"+ex.getStackTrace()); log.error("一次性委托日期转码出错:" + ex.getStackTrace());
} }
} }
// 周期委托 // 周期委托
if(iperiod==3){ if (iperiod == 3) {
//当前时间 //当前时间
SimpleDateFormat nowDateSdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat nowDateSdf = new SimpleDateFormat("yyyy-MM-dd");
String nowStr = nowDateSdf.format(new Date()); String nowStr = nowDateSdf.format(new Date());
// 判断是否为当前时间 上架状态 // 判断是否为当前时间 上架状态
if(nowStr.equals(cstart)){ if (nowStr.equals(cstart)) {
istatus=1; istatus = 1;
} }
// 到期自动下架 // 到期自动下架
if(nowStr.equals(cend)){ if (nowStr.equals(cend)) {
istatus=2; istatus = 2;
} }
} }
} }

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

@ -146,10 +146,18 @@ public class ApiTest {
//商品详情 //商品详情
@Test @Test
public void gdtest(){ public void gdtest(){
String islicode ="010007-00000000260899999999-2";
JSONObject rqjson = new JSONObject(); JSONObject rqjson = new JSONObject();
rqjson.put("isliCode","010005-000000000000032730001001-1"); rqjson.put("isliCode","010007-00000000262799999999-9");
JSONObject retjson = SzwhApiUtils.apiGoodsDetail(rqjson.toJSONString()); // rqjson.put("isliCode","010005-000000000000032730001001-1");
System.out.println(retjson); JSONObject gdJson = SzwhApiUtils.apiGoodsDetail(rqjson.toJSONString());
System.out.println(gdJson);
// 抽取出data
JSONArray gdArr = gdJson.getJSONArray("data");
int len = gdArr.size();
System.out.println("数组长度:"+len);
for(int i=0;i<gdArr.size();i++){
JSONObject gditem = (JSONObject) gdArr.get(i);
System.out.println(gditem);
}
} }
} }

Loading…
Cancel
Save