Browse Source

一次性委托加上节假日

master
xyiege 4 years ago
parent
commit
dcfa0c8772
  1. 11
      src/main/java/cn/chjyj/szwh/mapper/FestivalsMapper.java
  2. 23
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  3. 8
      src/main/resources/mapper/szwh/FestivalsMapper.xml
  4. 2
      src/test/java/cn/chjyj/szwh/ApiTest.java
  5. 30
      src/test/java/cn/chjyj/szwh/NewTest.java

11
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);
}

23
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();
}

8
src/main/resources/mapper/szwh/FestivalsMapper.xml

@ -19,6 +19,14 @@
ORDER BY id DESC;
</select>
<!-- 统计天数 -->
<select id="countDayBetweenDays" resultType="java.lang.Integer">
SELECT count(*)
FROM <include refid="tbName"/>
WHERE `year`=#{iyear}
AND (`date` BETWEEN #{start} AND #{end})
</select>
<!--新增用户-->
<insert id="addFestival" parameterType="cn.chjyj.szwh.bean.Festivals" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
insert into

2
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);
}

30
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);
}
}

Loading…
Cancel
Save