Authored by csgyoho

优惠券查询优化

... ... @@ -66,7 +66,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
CouponQueryReq req = JSONObject.parseObject(param, CouponQueryReq.class);
req.setSize(-1);//目的是查询所有数据
List<Coupon> coupons = couponMapper.selectByCondition(req);
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons);
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons,req.getCurTime());
return couponQueryResps;
}
if("userCoupon".equals(method)){
... ... @@ -108,7 +108,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
return new ApiResponse.ApiResponseBuilder().data(jsonObject).build();
}
List<Coupon> coupons = couponMapper.selectByCondition(req);
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons);
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons,req.getCurTime());
jsonObject.put("coupons",couponQueryResps);
return new ApiResponse.ApiResponseBuilder().data(jsonObject).build();
}
... ... @@ -234,7 +234,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
return true;
}
private List<CouponQueryResp> initCouponQueryResps(List<Coupon> coupons) {
private List<CouponQueryResp> initCouponQueryResps(List<Coupon> coupons,int curTime) {
List<CouponQueryResp> resps = new ArrayList<>();
if(CollectionUtils.isEmpty(coupons)){
return resps;
... ... @@ -243,18 +243,17 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
String useTime = com.yoho.ufo.util.DateUtil.int2DateStr(coupon.getStartTime(),"yyyy-MM-dd HH:mm:ss")+"至"+
com.yoho.ufo.util.DateUtil.int2DateStr(coupon.getEndTime(),"yyyy-MM-dd HH:mm:ss");
CouponQueryResp resp = new CouponQueryResp(coupon.getId(),coupon.getCouponName(),coupon.getCouponNum(),
useTime,coupon.getRemark(), getStatusDesc(coupon),coupon.getStatus(),coupon.getCouponToken());
useTime,coupon.getRemark(), getStatusDesc(coupon,curTime),coupon.getStatus(),coupon.getCouponToken());
resps.add(resp);
}
return resps;
}
private String getStatusDesc(Coupon coupon){
private String getStatusDesc(Coupon coupon,int curTime){
if(Coupon.CouponStatusEnum.INVALID.getValue()==coupon.getStatus()){
return Coupon.CouponStatusEnum.INVALID.getKey();
}
//0:未生效,1:生效中,2:已过期
int curTime = DateUtil.getCurrentTimeSecond();
if(coupon.getStartTime()>curTime){
return "未生效";
}
... ...