From dcfa0c87728c87099d79fbacdcd61395173ea2db Mon Sep 17 00:00:00 2001 From: xyiege Date: Tue, 27 Sep 2022 23:48:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=80=A7=E5=A7=94=E6=89=98?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E8=8A=82=E5=81=87=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/chjyj/szwh/mapper/FestivalsMapper.java | 11 +++++++ .../szwh/service/impl/GoodsServiceImpl.java | 23 +++++++++----- .../resources/mapper/szwh/FestivalsMapper.xml | 8 +++++ src/test/java/cn/chjyj/szwh/ApiTest.java | 2 +- src/test/java/cn/chjyj/szwh/NewTest.java | 30 +++++++++++++++++++ 5 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/main/java/cn/chjyj/szwh/mapper/FestivalsMapper.java b/src/main/java/cn/chjyj/szwh/mapper/FestivalsMapper.java index 58878b2..9d30e16 100644 --- a/src/main/java/cn/chjyj/szwh/mapper/FestivalsMapper.java +++ b/src/main/java/cn/chjyj/szwh/mapper/FestivalsMapper.java @@ -1,8 +1,10 @@ package cn.chjyj.szwh.mapper; import cn.chjyj.szwh.bean.Festivals; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; +import java.util.Date; import java.util.List; @Component @@ -20,4 +22,13 @@ public interface FestivalsMapper { * @return */ int addFestival(Festivals festivals); + + /** + * 统计时间周期内的节假日天数 + * @param start 开始日期 + * @param end 结束日期 + * @param iyear 年份 + * @return + */ + int countDayBetweenDays(@Param("start") Date start, @Param("end") Date end, @Param("iyear") int iyear); } 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 6555e36..6b3f889 100644 --- a/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java +++ b/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java @@ -6,10 +6,7 @@ import cn.chjyj.szwh.bean.GoodsSource; import cn.chjyj.szwh.bean.OperationLog; import cn.chjyj.szwh.constant.ChConstant; import cn.chjyj.szwh.exception.ChException; -import cn.chjyj.szwh.mapper.GoodsDetailMapper; -import cn.chjyj.szwh.mapper.GoodsMapper; -import cn.chjyj.szwh.mapper.GoodsSourceMapper; -import cn.chjyj.szwh.mapper.OperationLogMapper; +import cn.chjyj.szwh.mapper.*; import cn.chjyj.szwh.service.GoodsService; import cn.chjyj.szwh.utils.*; import cn.chjyj.szwh.vo.GoodsDetailVo; @@ -46,8 +43,11 @@ public class GoodsServiceImpl implements GoodsService { // 操作日志 @Autowired private OperationLogMapper operationLogMapper; + // 节假日mapper + @Autowired + private FestivalsMapper festivalsMapper; /** - * springboot 自带事物 + * springboot 自带事务 */ @Autowired private PlatformTransactionManager platformTransactionManager; @@ -531,7 +531,7 @@ public class GoodsServiceImpl implements GoodsService { // insertGoodsDetail GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson); // 返回商品详情 - int gdid = goodsDetailMapper.addGoodsDetail(goodsDetail); + goodsDetailMapper.addGoodsDetail(goodsDetail); //抽取target 字段中的json,转为jsonobject JSONObject targetJson = sdjson.getJSONObject("targetData"); @@ -545,6 +545,10 @@ public class GoodsServiceImpl implements GoodsService { } else { istatus = 4; } + // 取今年的年份数字 + Calendar calendar = Calendar.getInstance(); + int iyear = calendar.get(Calendar.YEAR); + // 组装到goods对象 Goods goods = new Goods(); String contractualPeriod = nsdjson.getString("contractualPeriod"); int iperiod = 0; @@ -558,7 +562,6 @@ public class GoodsServiceImpl implements GoodsService { String cend = nsdjson.getString("contractualPeriodEnd"); if (StringUtils.isBlank(cend) && day!=null) { - //如果是一次性授权或单次授权,存在托管结束时间 if (iperiod == 2) { try { @@ -566,7 +569,11 @@ public class GoodsServiceImpl implements GoodsService { Date wtStart = sdf.parse(cstart); // 委托终止时间 Date wtEnd = DateUtils.daysAgoOrAfter(wtStart, day); - cend = wtEnd.toString(); + // 统计该时间段内的节假日 + int fdays = festivalsMapper.countDayBetweenDays(wtStart,wtEnd,iyear); + // 节假日顺眼后的日期 + Date fwtEnd= DateUtils.daysAgoOrAfter(wtEnd,fdays); + cend = fwtEnd.toString(); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/resources/mapper/szwh/FestivalsMapper.xml b/src/main/resources/mapper/szwh/FestivalsMapper.xml index b5a0ffc..7101916 100644 --- a/src/main/resources/mapper/szwh/FestivalsMapper.xml +++ b/src/main/resources/mapper/szwh/FestivalsMapper.xml @@ -19,6 +19,14 @@ ORDER BY id DESC; + + + insert into diff --git a/src/test/java/cn/chjyj/szwh/ApiTest.java b/src/test/java/cn/chjyj/szwh/ApiTest.java index f9af22b..7ddce0a 100644 --- a/src/test/java/cn/chjyj/szwh/ApiTest.java +++ b/src/test/java/cn/chjyj/szwh/ApiTest.java @@ -146,7 +146,7 @@ public class ApiTest { //商品详情 @Test public void gdtest(){ - String islicode ="010005-000000000000033057001001-4,010005-000000000000033057001002-3"; + String islicode ="010007-00000000260899999999-2"; JSONObject retjson = SzwhApiUtils.apiGoodsDetail(islicode); System.out.println(retjson); } diff --git a/src/test/java/cn/chjyj/szwh/NewTest.java b/src/test/java/cn/chjyj/szwh/NewTest.java index ab0367a..5731fcb 100644 --- a/src/test/java/cn/chjyj/szwh/NewTest.java +++ b/src/test/java/cn/chjyj/szwh/NewTest.java @@ -1,6 +1,7 @@ package cn.chjyj.szwh; import cn.chjyj.szwh.mapper.FestivalsMapper; +import cn.chjyj.szwh.utils.DateUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -8,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; @@ -16,6 +18,7 @@ import java.util.Date; public class NewTest { @Autowired private FestivalsMapper festivalsMapper; + @Test public void funTest() throws Exception{ Calendar calendar = Calendar.getInstance(); @@ -32,4 +35,31 @@ public class NewTest { Date afdate = calendar.getTime(); System.out.println(afdate); } + + /** + * 测试某个时间段后的日期 + * 遇节假日顺延 + */ + @Test + public void afterDate(){ + //今年年份 + Calendar calendar = Calendar.getInstance(); + //当前年份 + int iyear= calendar.get(1); + int day=40; + LocalDateTime localDateTime = LocalDateTime.now(); + System.out.println("localdatetime:"+localDateTime); + // 常规日期 + Date date =new Date(); + Date afdate0 = DateUtils.daysAgoOrAfter(date,day); + //计算时间周期内的节假日天数 + int days = festivalsMapper.countDayBetweenDays(date,afdate0,iyear); + Date afdate = DateUtils.daysAgoOrAfter(afdate0,days); + System.out.println(afdate+"以前的节假日天数:"+days); + + //转为localDateTime + LocalDateTime aflocal = DateUtils.convertDateToLocalDateTime(afdate); + System.out.println(day+"天后的日期:"+aflocal); + + } }