Commit 8633e41d authored by ysongq's avatar ysongq

订单详情剩余有效期

parent 759b51d0
package com.jz.common.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -288,6 +290,40 @@ public class DateUtils {
return calendar.getTime();
}
//获取时间差方法
public static String getTime(Date currentTime,Date firstTime){
long diff = currentTime.getTime() - firstTime.getTime();//这样得到的差值是微秒级别
Calendar currentTimes =dataToCalendar(currentTime);//当前系统时间转Calendar类型
Calendar firstTimes =dataToCalendar(firstTime);//查询的数据时间转Calendar类型
int year = currentTimes.get(Calendar.YEAR) - firstTimes.get(Calendar.YEAR);//获取年
int month = currentTimes.get(Calendar.MONTH) - firstTimes.get(Calendar.MONTH);
int day = currentTimes.get(Calendar.DAY_OF_MONTH) - firstTimes.get(Calendar.DAY_OF_MONTH);
if (day < 0) {
month -= 1;
currentTimes.add(Calendar.MONTH, -1);
day = day + currentTimes.getActualMaximum(Calendar.DAY_OF_MONTH);//获取日
}
if (month < 0) {
month = (month + 12) % 12;//获取月
year--;
}
long days = diff / (1000 * 60 * 60 * 24);
long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60); //获取时
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60); //获取分钟
long s=(diff/1000-days*24*60*60-hours*60*60-minutes*60);//获取秒
String CountTime=""+month+"月"+day+"天"+hours+"小时"+minutes+"分";
// String CountTime=""+month+"月"+day+"天"+hours+"小时"+minutes+"分"+s+"秒";
return CountTime;
}
//Date类型转Calendar类型
public static Calendar dataToCalendar(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
public static void main(String[] args) {
try {
System.out.println("本周一" + parseDate2String(getThisWeekMonday()));
......
......@@ -37,7 +37,7 @@ public class DataGoodsApiController extends BaseController {
* @param id
* @return
*/
@GetMapping("/{id}")
@GetMapping("/getGoodsDetails/{id}")
@ApiOperation(value = "点击商品查看商品详情", notes = "api商品")
public Result<DataGoodsApiDto> findById(@PathVariable(value = "id") Long id) {
if (id != null) {
......
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
......@@ -95,6 +96,18 @@ public class DataGoodsApiDto implements Serializable {
@ApiModelProperty(value = "参数分类:01公共参数,02请求参数,03响应参数,04请求头参数,05状态码参数")
private String paramsDiff;
@ApiModelProperty(value = "年(元)")
private BigDecimal yearType;
@ApiModelProperty(value = "季(元)")
private BigDecimal seasonType;
@ApiModelProperty(value = "月(元)")
private BigDecimal monthType;
@ApiModelProperty(value = "次(元)")
private BigDecimal secondType;
/**
* 参数名称
*/
......
......@@ -102,6 +102,10 @@ public class OrderDto {
*/
@ApiModelProperty(value = "失效日期")
private Date invalidTime;
@ApiModelProperty(value = "有效期")
private String indate;
/**
* 价格类型:01免费,02收费
*/
......@@ -137,6 +141,13 @@ public class OrderDto {
@ApiModelProperty(value = "数据分类")
private String dataType;
public String getIndate() {
return indate;
}
public void setIndate(String indate) {
this.indate = indate;
}
public Long getOrderId() {
return orderId;
......@@ -337,4 +348,5 @@ public class OrderDto {
public void setDataType(String dataType) {
this.dataType = dataType;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jz.common.bean.PageInfoResponse;
import com.jz.common.constant.Constants;
import com.jz.common.utils.DateUtils;
import com.jz.dm.mall.moduls.controller.order.bean.*;
import com.jz.dm.mall.moduls.mapper.OrderDao;
import com.jz.dm.mall.moduls.service.OrderService;
......@@ -13,6 +14,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
/**
......@@ -71,14 +73,10 @@ public class OrderServiceImpl implements OrderService {
if (StringUtils.isNotEmpty(orderId)) {
orderDto = orderDao.getOrderDetail(orderId);
if (orderDto != null) {
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long effectTimes = orderDto.getTakeEffectTime().getTime(); //开始生效日期
long invalidTimes = orderDto.getInvalidTime().getTime(); //有效结束日期
long syTime = invalidTimes - effectTimes; //有效时间毫秒数
Date mtime = new Date(syTime);
int month = mtime.getMonth();*/
//getEffectTime(orderDto.getTakeEffectTime(), orderDto.getInvalidTime());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date endTime = orderDto.getInvalidTime();
String indate = DateUtils.getTime(endTime, DateUtils.getToday());
orderDto.setIndate(indate);
}
}
return orderDto;
......@@ -101,34 +99,4 @@ public class OrderServiceImpl implements OrderService {
return returnMap;
}
public void getEffectTime(Date takeEffectTime, Date invalidTime) {
Calendar startTime = Calendar.getInstance();
startTime.setTime(takeEffectTime); //开始日期
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(invalidTime); //结束日期
int hour = endCalendar.get(Calendar.HOUR_OF_DAY) - startTime.get(Calendar.HOUR_OF_DAY);
int day = endCalendar.get(Calendar.DAY_OF_MONTH) - startTime.get(Calendar.DAY_OF_MONTH);
int month = endCalendar.get(Calendar.MONTH) - startTime.get(Calendar.MONTH);
int year = endCalendar.get(Calendar.YEAR) - startTime.get(Calendar.YEAR);
// 按照减法原理,先day相减,不够向month借;然后month相减,不够向year借;最后year相减。
if (day < 0) {
month -= 1;
endCalendar.add(Calendar.MONTH, -1);// 得到上一个月,用来得到上个月的天数。
day = day + endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if (month < 0) {
month = (month + 12) % 12;
year--;
}
System.out.println("结果:" + year + "年" + month + "月" + day + "天");
/*for (int i = 0; i < month; i++) {
endCalendar.add(Calendar.MONTH, -1);// 得到上一个月,用来得到上个月的天数。
day = day + endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
System.out.println("过去时间与现在有:" + year + "年" + "" + day + "天");*/
}
}
\ No newline at end of file
......@@ -42,6 +42,10 @@
t4.params_desc AS paramsDesc,
t4.if_requird AS ifRequird,
t4.default_value AS defaultValue,
t2.year_type as yearType,
t2.season_type as seasonType,
t2.month_type as monthType,
t2.second_type as secondType,
( CASE WHEN t2.data_type = '01' THEN 'api' WHEN t2.data_type = '02' THEN '数据包' END ) AS dataType,
( CASE WHEN t2.price_type = '01' THEN '免费' WHEN t2.price_type = '02' THEN '收费' END ) AS priceType,
( CASE WHEN t4.params_diff = '01' THEN '公共参数' WHEN t4.params_diff = '02' THEN '请求参数' WHEN t4.params_diff = '03' THEN '响应参数' WHEN t4.params_diff = '04' THEN '请求头参数' WHEN t4.params_diff = '05' THEN '状态码参数' end ) AS paramsDiff
......
......@@ -268,8 +268,8 @@
t.order_time as orderTime,
(case when t.purchase_method ='01' then '年' when t.purchase_method ='02' then '季' when t.purchase_method ='03' then '月'
when t.purchase_method ='04' then '次' end) as purchaseMethod,
t.take_effect_time as takeEffectTime,
t.invalid_time as invalidTime,
(DATE_FORMAT(t.take_effect_time,'%Y-%m-%d %H:%i:%s')) as takeEffectTime,
(DATE_FORMAT(t.invalid_time,'%Y-%m-%d %H:%i:%s')) as invalidTime,
t.api_key as apiKey,
t2.data_name as dataName,
(case when t2.data_type ='01' then 'API' when t2.data_type ='02' then '数据包' end) as dataType
......
......@@ -33,7 +33,7 @@ public class DataGoodsApiController extends BaseController {
* @param id
* @return
*/
@GetMapping("/{id}")
@GetMapping("/getDataDetails/{id}")
@ApiOperation(value = "点击商品查看商品详情", notes = "api商品")
public Result<DataGoodsApiDto> findById(@PathVariable(value = "id") Long id) {
if (id != null) {
......
......@@ -3,6 +3,7 @@ package com.jz.manage.moduls.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsApiDto;
import com.jz.manage.moduls.entity.DataGoodsApi;
import org.apache.ibatis.annotations.Param;
/**
* api商品(TDataGoodsApi)表数据库访问层
......@@ -18,5 +19,5 @@ public interface DataGoodsApiDao extends BaseMapper<DataGoodsApi> {
* @param id
* @return
*/
DataGoodsApiDto findById(Long id);
DataGoodsApiDto findById(@Param("dataGoodsId") Long id);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment