diff --git a/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java b/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java index 8459ba4..d026eef 100644 --- a/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java +++ b/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java @@ -448,6 +448,7 @@ public class GoodsServiceImpl implements GoodsService { /** * 处理排序问题 * 与前一个元素的排序进行互换,需要同时更新两条记录 + * * @param goodsIsli * @param type * @return @@ -460,30 +461,30 @@ public class GoodsServiceImpl implements GoodsService { //List tmpRanklist = goodsMapper.getGoodsByCondition(where, 8, "recommend_sort", "DESC"); List tmpRanklist = queryRankList(); int ret = 0; - for(int i=0;i getTypeGoods(String type, String createtime, String goods_type) { List glist = new ArrayList<>(); - String where="";//查询条件 - if("1".equals(type)){ - glist = goodsMapper.getGoodsByCondition("1=1",10,"click_count","DESC"); + String where = "";//查询条件 + if ("1".equals(type)) { + glist = goodsMapper.getGoodsByCondition("1=1", 10, "click_count", "DESC"); } - if("2".equals(type)){ - glist = goodsMapper.getGoodsByCondition("1=1",10,"sale_count","DESC"); + if ("2".equals(type)) { + glist = goodsMapper.getGoodsByCondition("1=1", 10, "sale_count", "DESC"); } - if("3".equals(type)){ - where="is_recommend=1 and goods_status=1"; - glist = goodsMapper.getGoodsByCondition(where,8,"recommend_sort","DESC"); + if ("3".equals(type)) { + where = "is_recommend=1 and goods_status=1"; + glist = goodsMapper.getGoodsByCondition(where, 8, "recommend_sort", "DESC"); } return glist; @@ -527,10 +528,11 @@ public class GoodsServiceImpl implements GoodsService { /** * query rank list + * * @return */ - private List queryRankList(){ - String where="is_deleted=0 and is_recommend=1"; + private List queryRankList() { + String where = "is_deleted=0 and is_recommend=1"; List tmpRanklist = goodsMapper.getGoodsByCondition(where, 8, "recommend_sort", "DESC"); return tmpRanklist; } @@ -571,9 +573,9 @@ public class GoodsServiceImpl implements GoodsService { } //处理返回的结果 JSONArray gdArr = gdJson.getJSONArray("data"); - if(gdArr==null){ + if (gdArr == null) { continue; - }else { + } else { log.info(gdArr.size()); } // add goodsSource,循环插入 商品资源 @@ -618,53 +620,58 @@ public class GoodsServiceImpl implements GoodsService { String ncstart = cstart + " " + curTime; // 委托周期 Integer day = nsdjson.getInteger("contractualCycle"); - //转换为date + if (day == null) { + day = 40; // 默认40个工作日 + } + // 委托终止日期 String cend = nsdjson.getString("contractualPeriodEnd"); - + if (StringUtils.isBlank(cend)) { + cend = "2099-12-31"; + } //委托开始时间,取当前时间 - Timestamp ncst=new Timestamp(System.currentTimeMillis()); + Timestamp ncst = new Timestamp(System.currentTimeMillis()); //委托结束时间 default value 2099-12-31 23:59:59 - Timestamp ncet=new Timestamp(4102415999000l); - // 未设置结束委托时间 - if (StringUtils.isBlank(cend) && day != null) { - //如果是一次性授权或单次授权,存在托管结束时间 - if (iperiod == 2) { - try { - // 委托开始时间 匹配时间格式,防止转码出错 - Date wtStart = sdf.parse(ncstart); - // 委托开始时间戳 - ncst = new Timestamp(wtStart.getTime()); - // 委托终止时间 - Date wtEnd=WorkDayUtil.getWorkDay(wtStart,day); - // 统计该时间段内的节假日 - //int fdays = festivalsMapper.countDayBetweenDays(wtStart, wtEnd, iyear); - // 节假日顺延后的日期 - //Date fwtEnd = DateUtils.daysAgoOrAfter(wtEnd, fdays); - // 20221018 经咨询,不计算法定节假日的时长,故此暂作注释 - Date fwtEnd = wtEnd; - SimpleDateFormat ysdf =new SimpleDateFormat("yyyy-MM-dd"); - cend = ysdf.format(fwtEnd)+" 23:59:59"; - ncet=new Timestamp(sdf.parse(cend).getTime()); - } catch (Exception ex) { - log.error("一次性委托日期转码出错:" + ex.getLocalizedMessage()); - } + Timestamp ncet = new Timestamp(4102415999000l); + //如果是一次性授权或单次授权,存在托管结束时间 + if (iperiod == 2) { + try { + // 委托开始时间 匹配时间格式,防止转码出错 + Date wtStart = sdf.parse(ncstart); + // 委托开始时间戳 + ncst = new Timestamp(wtStart.getTime()); + // 委托终止时间 + Date wtEnd = WorkDayUtil.getWorkDay(wtStart, day); + // 统计该时间段内的节假日 + //int fdays = festivalsMapper.countDayBetweenDays(wtStart, wtEnd, iyear); + // 节假日顺延后的日期 + //Date fwtEnd = DateUtils.daysAgoOrAfter(wtEnd, fdays); + // 20221018 经咨询,不计算法定节假日的时长,故此暂作注释 + Date fwtEnd = wtEnd; + SimpleDateFormat ysdf = new SimpleDateFormat("yyyy-MM-dd"); + cend = ysdf.format(fwtEnd) + " 23:59:59"; + ncet = new Timestamp(sdf.parse(cend).getTime()); + } catch (Exception ex) { + log.error("一次性委托日期转码出错:" + ex.getLocalizedMessage()); } - // 一次性委托时候,判断开始时间是否结束 - if (iperiod == 3) { - //当前时间 - SimpleDateFormat nowDateSdf = new SimpleDateFormat("yyyy-MM-dd"); - String nowStr = nowDateSdf.format(new Date()); - // 判断是否为当前时间 上架状态 - if (nowStr.equals(cstart)) { - istatus = 1; - } - // 到期自动下架 - if (nowStr.equals("2099-12-31")) { - istatus = 2; - } + } + // 周期性托管,判断开始时间是否结束 + if (iperiod == 3) { + try{ + // 委托开始时间 匹配时间格式,防止转码出错 + Date wtStart = sdf.parse(ncstart); + // 委托开始时间戳 + ncst = new Timestamp(wtStart.getTime()); + // 委托终止时间 + Date wtEnd = sdf.parse(cend); + SimpleDateFormat ysdf = new SimpleDateFormat("yyyy-MM-dd"); + cend = ysdf.format(wtEnd) + " 23:59:59"; + // 委托终止时间时间戳 + ncet = new Timestamp(sdf.parse(cend).getTime()); + }catch (Exception ex){ + log.error("周期性委托日期转码错误:"+ex.getLocalizedMessage()); } } - //bind to goods properties + //绑定商品属性 goods.setContractualStartTime(ncst); goods.setContractualtimeEndTime(ncet); diff --git a/src/test/java/cn/chjyj/szwh/ApiTest.java b/src/test/java/cn/chjyj/szwh/ApiTest.java index 00be168..65b1de7 100644 --- a/src/test/java/cn/chjyj/szwh/ApiTest.java +++ b/src/test/java/cn/chjyj/szwh/ApiTest.java @@ -112,6 +112,49 @@ public class ApiTest { } } + /** + * 测试阶段性委托 + */ + @Test + public void jdxTest(){ + String tmpstr ="{\"resultCode\":\"00000000\",\"resultMsg\":\"SUCCESS\"," + + "\"data\":[{\"isliCode\":\"010007-00000000302500000001-6\",\"status\":\"1\",\"createTime\":\"2022-10-18T02:16:02.000+00:00\"," + + "\"exStatus\":\"0\",\"timeStamp\":1666059370000,\"sourceData\":{\"contractIsLiCode\":\"010007-00000000302500000001-6\"," + + "\"register\":\"北京玖扬博文文化发展有限公司\",\"entityName\":null,\"isliCode\":\"010007-00000000302599999999-5\",\"serviceCode\":\"010007\"," + + "\"titleName\":\"1018阶段\",\"releaseTime\":\"2022-10-18 10:14:37\",\"identifier\":\"010007-00000000302599999999-5\"," + + "\"identifiers\":\"000002-100000000192062-5\",\"systemIdentity\":\"ee6510c19fb643aabf336bbe9e014a82\",\"transactionType\":\"授权\"," + + "\"collectionType\":\"文化资源数据\",\"transactionKind\":\"权属\",\"otherIdentifiers\":\" \",\"contractualPeriod\":\"阶段性委托\",\"contractualCycle\":null," + + "\"price\":\"RMB 0.01\",\"rights\":\"放映权\",\"contractMoney\":\"交易全额的30%\",\"contractualPeriodStart\":\"2022-10-18\"," + + "\"contractualPeriodEnd\":\"2022-10-18\",\"contractStatus\":\"1\"," + + "\"cover\":\"http://aa.jpg\"}," + + "\"targetData\":{\"contractIsliCode\":\"010007-00000000302300000001-8\",\"register\":\"伏羲云\",\"entityName\":null," + + "\"isliCode\":\"899998-000000001161-2\",\"identifier\":\"899998-000000001161-2\",\"serviceCode\":\"899998\"," + + "\"titleName\":\"北京玖扬博文文化发展有限公司\",\"releaseTime\":null,\"otherIdentifiers\":\"91110108597748619P\"," + + "\"entityType\":\"组织\",\"certificate\":\"http://172.16.3.21:11000/file/cncbox/userself/7/16073304715399411.png\"," + + "\"date\":\"2022-08-05 15:17:24\",\"place\":\"中国\",\"description\":\"\",\"electronicSignature\":\"\",\"participants\":\"卖方\"}}]}"; + + JSONObject jsonObject = JSONObject.parseObject(tmpstr); + //提取数组 + JSONArray jsonArray = jsonObject.getJSONArray("data"); + JSONObject sdjson = (JSONObject) jsonArray.get(0); + // 抽取source data + String nsdstr = sdjson.getString("sourceData"); + JSONObject nsdjson = JSONObject.parseObject(nsdstr); + //提取和处理,委托周期 + String contractualPeriod = nsdjson.getString("contractualPeriod"); + // 判断委托类型,一次性委托(永久委托)\阶段性委托 + int iperiod = ApiGoodsUtils.convertProid(contractualPeriod); + System.out.println("托管周期:"+iperiod); + //商品起止时间 + String cstart = nsdjson.getString("contractualPeriodStart"); + String curTime = new SimpleDateFormat("HH:mm:ss").format(new Date()); + String ncstart = cstart + " " + curTime; + // 委托周期 + Integer day = nsdjson.getInteger("contractualCycle"); + //转换为date + String cend = nsdjson.getString("contractualPeriodEnd"); + } + @Test public void syncOrder(){ System.out.println("同步订单信息");