From 5dbb6ee49f2079f6934451fedd1a617299ce2a8d Mon Sep 17 00:00:00 2001 From: yuyang Date: Wed, 1 Jun 2022 14:06:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93C=E7=AB=AF=E3=80=81=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E3=80=81B=E7=AB=AF=E7=94=A8=E6=88=B7=E4=BA=AB=E5=8F=97?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E6=97=B6=EF=BC=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=BC=B9=E5=87=BA=E4=BA=92=E5=8A=A8=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/XhpcRealTimeOrderServiceImpl.java | 19 +++ .../user/dto/XhpcActivityDiscountDto.java | 125 ++++++++++++++++++ .../xhpc/user/mapper/XhpcAppUserMapper.java | 6 + .../service/impl/XhpcAppUserServiceImpl.java | 111 +++++++++++++--- .../resources/mapper/XhpcAppUserMapper.xml | 39 ++++++ 5 files changed, 285 insertions(+), 15 deletions(-) create mode 100644 xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/dto/XhpcActivityDiscountDto.java diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java index 88174af3..065134dd 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java @@ -362,6 +362,23 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe //获取实时数据 Map cacheMap = redisService.getCacheMap("order:"+xhpcChargeOrder.getSerialNumber()); if(cacheMap !=null){ + CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData"); + if(cacheOrderData !=null){ + //获取 + xhpcChargeOrder.setStartSoc(cacheOrderData.getStartSoc()+""); + xhpcChargeOrder.setEndSoc(cacheOrderData.getEndSoc()+""); + DateTime startTime = DateUtil.parse(cacheOrderData.getStartTime()); + DateTime endTime = DateUtil.parse(cacheOrderData.getEndTime()); + xhpcChargeOrder.setStartTime(startTime); + xhpcChargeOrder.setEndTime(endTime); + if(cacheOrderData.getStopReason() !=null && !"".equals(cacheOrderData.getStopReason())){ + xhpcChargeOrder.setType(cacheOrderData.getStopReason()); + } + BigDecimal bigDecimal = new BigDecimal(10000); + BigDecimal divide = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal,2, BigDecimal.ROUND_HALF_UP); + xhpcChargeOrder.setChargingDegree(divide); + } + if(cacheMap.get("realtimeDataList") !=null){ List list = (List) cacheMap.get("realtimeDataList"); if(list !=null && list.size()>0){ @@ -373,6 +390,8 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe xhpcChargeOrder.setEndTime(DateUtil.parse(cacheMap.get("startTime").toString(), "yyyy-MM-dd HH:mm:ss")); } } + + } } diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/dto/XhpcActivityDiscountDto.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/dto/XhpcActivityDiscountDto.java new file mode 100644 index 00000000..f06be839 --- /dev/null +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/dto/XhpcActivityDiscountDto.java @@ -0,0 +1,125 @@ +package com.xhpc.user.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author yuyang + * @date 2022/4/19 13:57 + */ +@Data +public class XhpcActivityDiscountDto implements Serializable { + /** + * 活动ID + */ + private Integer activityId; + + /** + * 活动名称 + */ + private String activityName; + + /** + * 模板ID + */ + private Integer templateId; + + /** + * C端用户列表(以逗号分隔,-1表示全部用户) + */ + private String appUserList; + + /** + * 社区用户列表(以逗号分隔,-1表示全部用户) + */ + private String comUserList; + + /** + * B端用户列表(以逗号分隔,-1表示全部用户) + */ + private String cusUserList; + + /** + * 场站列表 + */ + private String stationList; + + /** + * 租户ID + */ + private String tenantId; + + + /** + * 开始时间 + */ + private Date startTime; + + /** + * 结束时间 + */ + private Date endTime; + + /** + * 状态(0-编辑,1-提交待审核,2-审核失败,3-审核通过,4-立即失效) + */ + private Short status = 0; + + /** + * 删除标识(0-正常,2-删除) + */ + private Short delFlag = 0; + + /** + * 创建人 + */ + private String createBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新人 + */ + private String updateBy; + + /** + * 更新时间 + */ + private Date updateTime; + + + /** + * 审核人 + */ + private String checkBy; + + /** + * 审核时间 + */ + private Date checkTime; + + /** + * 优惠类型(1-总金额,2-服务费,3-电量) + */ + private Integer discountType; + + /** + * 优惠比率 + */ + private BigDecimal discountRate; + + /** + * 活动背景图 + */ + private String backgroundUrl; + + + + private static final long serialVersionUID = 1L; +} diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/mapper/XhpcAppUserMapper.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/mapper/XhpcAppUserMapper.java index 090b478d..e5dff2e5 100644 --- a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/mapper/XhpcAppUserMapper.java +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/mapper/XhpcAppUserMapper.java @@ -1,6 +1,7 @@ package com.xhpc.user.mapper; import com.xhpc.user.domain.XhpcAppUser; +import com.xhpc.user.dto.XhpcActivityDiscountDto; import org.apache.ibatis.annotations.Param; import java.util.Date; @@ -107,4 +108,9 @@ public interface XhpcAppUserMapper { * @return */ int updateUserLoginTime(@Param("account")String account); + + /** + * 查询开始时间是否在活动中 + */ + List getActivityDiscountTime(@Param("internetUserId")Long internetUserId, @Param("startTime")String startTime, @Param("userType")Integer userType, @Param("chargingStationId")Long chargingStationId, @Param("tenantId")String tenantId); } diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java index ea23b176..1c7f1153 100644 --- a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java @@ -19,6 +19,7 @@ import com.xhpc.system.api.domain.SysUser; import com.xhpc.system.api.model.LoginUser; import com.xhpc.user.controller.XhpcCommonController; import com.xhpc.user.domain.XhpcAppUser; +import com.xhpc.user.dto.XhpcActivityDiscountDto; import com.xhpc.user.mapper.XhpcAppUserMapper; import com.xhpc.user.service.IXhpcAppUserUserService; import org.slf4j.Logger; @@ -28,7 +29,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -285,12 +288,6 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU // 获取登录token Map token = tokenService.createToken(userInfo); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"+appUserId); - logger.info("<<<<<<<<<>>>>>>>>>>>"+token.toString()); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"); return R.ok(token); }else{ return R.fail(HttpStatus.DATA_ERROR, "无此账号,请重新输入账号登录"); @@ -351,12 +348,6 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU xhpcAppUserMapper.addUserLoginTime(user.getAppUserId(),username,userInfo.getUserType(),openid,Integer.valueOf(type),UserConstants.LOGIN,tenantId,new Date()); // 获取登录token Map token = tokenService.createToken(userInfo); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"+user.getAppUserId()); - logger.info("<<<<<<<<<>>>>>>>>>>>"+token.toString()); - logger.info("<<<<<<<<<>>>>>>>>>>>"); - logger.info("<<<<<<<<<>>>>>>>>>>>"); return R.ok(token); } @@ -496,9 +487,17 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU map.put("guestbook","0"); map.put("version",version); map.put("servicePhone",servicePhone); - map.put("activity",0); - map.put("activitySize",1); - map.put("activityImg","https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/bunengshanchu/1.png"); + //获取最优的活动图片显示 + Map objectMap = activityDiscountTime(loginUser.getUserid(), new Date(), loginUser.getUserType(), null, loginUser.getTenantId()); + if("1".equals(objectMap.get("state").toString())){ + map.put("activity",1); + map.put("activitySize",1); + map.put("activityImg","https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"+objectMap.get("totalBackgroundUrl").toString()); + }else{ + map.put("activity",0); + map.put("activitySize",1); + map.put("activityImg","https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/bunengshanchu/1.png"); + } map.put("socSize",redisService.getCacheObject("global:"+tenantId+":SOC")); return AjaxResult.success(map); }else{ @@ -596,5 +595,87 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU return R.fail(HttpStatus.ERROR_STATUS, "设置失败"); } + //获取用户的活动 + public Map activityDiscountTime(Long userId,Date startTime,Integer source,Long chargingStationId,String tenantId){ + + Map map =new HashMap<>(); + List activityDiscountTime = xhpcAppUserMapper.getActivityDiscountTime(userId, DateUtil.formatDateTime(startTime), source, chargingStationId, tenantId); + if(activityDiscountTime !=null && activityDiscountTime.size()>0){ + //折扣电费、服务费 + BigDecimal totalDiscountRate =new BigDecimal(0); + int totalDiscountType = 0; + String totalBackgroundUrl=""; + for (int i = 0; i < activityDiscountTime.size(); i++) { + XhpcActivityDiscountDto activity = activityDiscountTime.get(i); + BigDecimal discountRate = activity.getDiscountRate(); + Integer discountType = activity.getDiscountType(); + String backgroundUrl = activity.getBackgroundUrl(); + if(discountType.equals(1)){ + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 1; + totalBackgroundUrl =backgroundUrl; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType=1; + totalBackgroundUrl =backgroundUrl; + } + }else{ + if(totalDiscountRate.compareTo(discountRate.multiply(new BigDecimal(2)))<0){ + totalDiscountRate =discountRate; + totalDiscountType = 1; + totalBackgroundUrl =backgroundUrl; + } + } + }else if(discountType.equals(2)){ + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 2; + totalBackgroundUrl =backgroundUrl; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.multiply(new BigDecimal(2)).compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 2; + totalBackgroundUrl =backgroundUrl; + } + }else { + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalBackgroundUrl =backgroundUrl; + } + } + }else{ + //电量抽成 + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + totalBackgroundUrl =backgroundUrl; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + totalBackgroundUrl =backgroundUrl; + } + }else{ + if(totalDiscountRate.multiply(new BigDecimal(2)).compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + totalBackgroundUrl =backgroundUrl; + } + } + } + } + map.put("state","1"); + map.put("totalDiscountRate",totalDiscountRate); + map.put("totalDiscountType",totalDiscountType+""); + map.put("totalBackgroundUrl",totalBackgroundUrl); + }else{ + map.put("state","0"); + } + return map; + } + + } diff --git a/xhpc-modules/xhpc-user/src/main/resources/mapper/XhpcAppUserMapper.xml b/xhpc-modules/xhpc-user/src/main/resources/mapper/XhpcAppUserMapper.xml index afa6194a..404e4bd6 100644 --- a/xhpc-modules/xhpc-user/src/main/resources/mapper/XhpcAppUserMapper.xml +++ b/xhpc-modules/xhpc-user/src/main/resources/mapper/XhpcAppUserMapper.xml @@ -355,4 +355,43 @@ update xhpc_user_login set status =0 where account=#{account} and status=1 + +