Browse Source

优化托管周期时间问题

master
xyiege 3 years ago
parent
commit
18c42e1f79
  1. 39
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  2. 2
      src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java

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

@ -503,10 +503,12 @@ public class GoodsServiceImpl implements GoodsService {
} else {
JSONObject nsdjson = JSONObject.parseObject(nsdstr);
// 从sourcedata节点中提取商品唯一编号
String goodsId = nsdjson.getString("identifiers");
String identifiers = nsdjson.getString("identifiers");
//
String goodsId = nsdjson.getString("identifier");
// 以identifiers为主键查询详情
JSONObject gdJson = SzwhApiUtils.apiGoodsDetail(goodsId);
log.info(goodsId + "详情:" + gdJson);
JSONObject gdJson = SzwhApiUtils.apiGoodsDetail(identifiers);
log.info(identifiers + "详情:" + gdJson);
//处理返回的结果
JSONArray gdArr = gdJson.getJSONArray("data");
// 如果goods表中存在记录,不进行操作
@ -548,6 +550,7 @@ public class GoodsServiceImpl implements GoodsService {
Goods goods = new Goods();
//提取和处理,委托周期
String contractualPeriod = nsdjson.getString("contractualPeriod");
// 判断委托类型,一次性委托(永久委托)\阶段性委托
int iperiod = ApiGoodsUtils.convertProid(contractualPeriod);
//商品起止时间
String cstart = nsdjson.getString("contractualPeriodStart");
@ -558,12 +561,18 @@ public class GoodsServiceImpl implements GoodsService {
//转换为date
String cend = nsdjson.getString("contractualPeriodEnd");
//委托开始时间
Timestamp ncst=new Timestamp(0l);
//委托结束时间
Timestamp ncet=new Timestamp(0l);
// 未设置结束委托时间
if (StringUtils.isBlank(cend) && day != null) {
//如果是一次性授权或单次授权,存在托管结束时间
if (iperiod == 2) {
try {
// 委托开始时间 匹配时间格式,防止转码出错
Date wtStart = sdf.parse(ncstart);
ncst = new Timestamp(wtStart.getTime());
// 判断周几
calendar.setTime(wtStart);
int wkday = calendar.get(Calendar.DAY_OF_WEEK);
@ -574,14 +583,15 @@ public class GoodsServiceImpl implements GoodsService {
Date wtEnd = DateUtils.daysAgoOrAfter(wtStart, day);
// 统计该时间段内的节假日
int fdays = festivalsMapper.countDayBetweenDays(wtStart, wtEnd, iyear);
// 节假日顺后的日期
// 节假日顺后的日期
Date fwtEnd = DateUtils.daysAgoOrAfter(wtEnd, fdays);
cend = fwtEnd.toString();
ncet=new Timestamp(fwtEnd.getTime());
} catch (Exception ex) {
log.error("一次性委托日期转码出错:" + ex.getLocalizedMessage());
}
}
// 周期委托
// 一次性委托时候,判断开始时间是否结束
if (iperiod == 3) {
//当前时间
SimpleDateFormat nowDateSdf = new SimpleDateFormat("yyyy-MM-dd");
@ -596,20 +606,11 @@ public class GoodsServiceImpl implements GoodsService {
}
}
}
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
}
//String ncend = cend + " 23:59:59";
goods.setContractualStartTime(ncst);
goods.setContractualtimeEndTime(ncet);
// 查询goodsdetail的自编号
goods.setGoodsDetailId(goodsDetail.getId());
goods.setContractStatus(nsdjson.getInteger("contractStatus"));

2
src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java

@ -72,7 +72,6 @@ public class ApiGoodsUtils {
}catch (Exception ex){
// do nothing
}
//Integer dataType =innerJson.getInteger("dataType");
goodsSource.setDatatype(innerJson.getInteger("dataType"));
try{
String cldate = innerJson.getString("cancellationDate");
@ -81,6 +80,7 @@ public class ApiGoodsUtils {
}catch (Exception ex){
//do nothing
}
goodsSource.setIsDeleted(0);
// 产品主键
goodsSource.setGoodsIsliCode(islicode);
return goodsSource;

Loading…
Cancel
Save