diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/dto/XhpcActivityDiscountDto.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/dto/XhpcActivityDiscountDto.java new file mode 100644 index 00000000..386adad6 --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/dto/XhpcActivityDiscountDto.java @@ -0,0 +1,122 @@ +package com.xhpc.charging.station.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 static final long serialVersionUID = 1L; +} diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java index a7ab2f73..f82644e0 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java @@ -1,6 +1,6 @@ package com.xhpc.charging.station.mapper; -import com.xhpc.common.api.dto.ChargingPileDto; +import com.xhpc.charging.station.dto.XhpcActivityDiscountDto; import com.xhpc.common.domain.XhpcChargingStation; import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.domain.XhpcRateModel; @@ -268,4 +268,12 @@ public interface XhpcChargingStationMapper { */ void insertXhpcUserPrivilege(@Param("userId") Long userId,@Param("chargingStationId") Long chargingStationId); + + /** + * 查询开始时间是否在活动中 + */ + 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-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index be6cc4dd..912971f2 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -2,6 +2,7 @@ package com.xhpc.charging.station.service; import cn.hutool.core.date.DateUtil; +import com.xhpc.charging.station.dto.XhpcActivityDiscountDto; import com.xhpc.charging.station.mapper.XhpcChargingStationMapper; import com.xhpc.charging.station.mapper.XhpcChargingStationPushStatusMapper; import com.xhpc.common.api.PowerPileService; @@ -761,6 +762,10 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc if(null==longitude||"".equals(longitude)||null==latitude||"".equals(latitude)){ longitude="104.065861"; latitude="30.657401"; } + //检查是否有用户登录 + LoginUser loginUser = tokenService.getLoginUser(); + + List stringList = new ArrayList<>(); if (serviceFacilities != null && serviceFacilities != "") { @@ -772,6 +777,32 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { Map map = list.get(i); + + BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString()); + BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString()); + + if(loginUser !=null){ + //判断是否享受活动 + Map objectMap = activityDiscountTime(loginUser.getUserid(), new Date(), loginUser.getUserType(), Long.valueOf(map.get("chargingStationId").toString()), loginUser.getTenantId()); + if("1".equals(objectMap.get("state").toString())){ + if("1".equals(objectMap.get("totalDiscountType").toString())||"3".equals(objectMap.get("totalDiscountType").toString())){ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + powerFee = powerFee.subtract(powerFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + }else{ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + } + } + }else{ + logger.info("==========loginUser========是空"); + } //桩(空闲和使用从redis获取) Map map1 =new HashMap<>(); map1 = getTerminalStatusSum(map1, Long.valueOf(map.get("chargingStationId").toString()), 0); @@ -793,8 +824,7 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc } //获取基本信息 Map map = xhpcChargingStationMapper.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude); - - //桩(空闲和使用从redis获取) + LoginUser loginUser = tokenService.getLoginUser(); Map map1 =new HashMap<>(); map1 = getTerminalStatusSum(map1, chargingStationId, 0); @@ -803,7 +833,6 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc }else{ map.put("free", 0); } - //图片信息 if (map !=null &&map.get("imgId") != null && map.get("imgId").toString() != "") { String[] split = map.get("imgId").toString().split(","); @@ -821,14 +850,34 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc map.put("imgIdList", new ArrayList<>()); } - - - //获取该时段电费 //HH:mm:ss String tiem = DateUtil.formatTime(new Date()); Map xhpcRateTime = xhpcRateTimeService.getXhpcRateTime(tiem, chargingStationId); if (xhpcRateTime != null) { + //桩(空闲和使用从redis获取) + BigDecimal serviceFee =new BigDecimal(xhpcRateTime.get("serviceFee").toString()); + BigDecimal powerFee =new BigDecimal(xhpcRateTime.get("powerFee").toString()); + if(loginUser !=null){ + //判断是否享受活动 + Map objectMap = activityDiscountTime(loginUser.getUserid(), new Date(), loginUser.getUserType(), Long.valueOf(map.get("chargingStationId").toString()), loginUser.getTenantId()); + if("1".equals(objectMap.get("state").toString())){ + if("1".equals(objectMap.get("totalDiscountType").toString())||"3".equals(objectMap.get("totalDiscountType").toString())){ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + powerFee = powerFee.subtract(powerFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + }else{ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + } + } + } map.putAll(xhpcRateTime); } return map; @@ -836,8 +885,34 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc @Override public List> getWXXhpcRateTimeMassage(Long chargingStationId) { - - return xhpcChargingStationMapper.getWXXhpcRateTimeMassage(chargingStationId); + List> list = xhpcChargingStationMapper.getWXXhpcRateTimeMassage(chargingStationId); + LoginUser loginUser = tokenService.getLoginUser(); + for (int i = 0; i map = list.get(i); + BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString()); + BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString()); + if(loginUser !=null){ + //判断是否享受活动 + Map objectMap = activityDiscountTime(loginUser.getUserid(), new Date(), loginUser.getUserType(), chargingStationId, loginUser.getTenantId()); + if("1".equals(objectMap.get("state").toString())){ + if("1".equals(objectMap.get("totalDiscountType").toString())||"3".equals(objectMap.get("totalDiscountType").toString())){ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + powerFee = powerFee.subtract(powerFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + }else{ + BigDecimal discountRate = new BigDecimal(objectMap.get("totalDiscountRate").toString()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP); + serviceFee = serviceFee.subtract(serviceFee.multiply(discountRate).setScale(2,BigDecimal.ROUND_HALF_UP)); + map.put("activityServiceFee", serviceFee); + map.put("activityPowerFee", powerFee); + map.put("activityMoney", serviceFee.add(powerFee)); + } + } + } + } + return list; } @Override @@ -1324,4 +1399,74 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc return xhpcChargingStation != null; } + //判断是否有活动 + public Map activityDiscountTime(Long userId,Date startTime,Integer source,Long chargingStationId,String tenantId){ + Map map =new HashMap<>(); + List activityDiscountTime = xhpcChargingStationMapper.getActivityDiscountTime(userId, DateUtil.formatDateTime(startTime), source, chargingStationId, tenantId); + if(activityDiscountTime !=null && activityDiscountTime.size()>0){ + + //折扣电费、服务费 + BigDecimal totalDiscountRate =new BigDecimal(0); + int totalDiscountType = 0; + for (int i = 0; i < activityDiscountTime.size(); i++) { + XhpcActivityDiscountDto activity = activityDiscountTime.get(i); + BigDecimal discountRate = activity.getDiscountRate(); + Integer discountType = activity.getDiscountType(); + if(discountType.equals(1)){ + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 1; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType=1; + } + }else{ + if(totalDiscountRate.compareTo(discountRate.multiply(new BigDecimal(2)))<0){ + totalDiscountRate =discountRate; + totalDiscountType = 1; + } + } + }else if(discountType.equals(2)){ + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 2; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.multiply(new BigDecimal(2)).compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 2; + } + }else { + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + } + } + }else{ + //电量抽成 + if(totalDiscountType==0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + }else if(totalDiscountType==1 || totalDiscountType==3){ + if(totalDiscountRate.compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + } + }else{ + if(totalDiscountRate.multiply(new BigDecimal(2)).compareTo(discountRate)<0){ + totalDiscountRate =discountRate; + totalDiscountType = 3; + } + } + } + } + map.put("state","1"); + map.put("totalDiscountRate",totalDiscountRate); + map.put("totalDiscountType",totalDiscountType+""); + }else{ + map.put("state","0"); + } + return map; + } + + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml index f21e890e..b4a0faa2 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -299,6 +299,30 @@ charging_station_id=cs.charging_station_id) as common, (select GROUP_CONCAT(serial_number) from xhpc_terminal where status=0 and del_flag =0 and charging_station_id=cs.charging_station_id) as serialNumbers, + (select (ra.service_fee) as serviceFee + from xhpc_rate as ra + where ra.status = 0 + and ra.del_flag = 0 + and ra.rate_id = ( + select rate_id from xhpc_rate_time + where charging_station_id = cs.charging_station_id + and cs.rate_model_id = rate_model_id + and start_time <= #{date} + and replace(end_time, '00:00:00', '24:00:00') >= #{date} + and status = 0 + and del_flag = 0)) serviceFee, + (select (ra.power_fee) as powerFee + from xhpc_rate as ra + where ra.status = 0 + and ra.del_flag = 0 + and ra.rate_id = ( + select rate_id from xhpc_rate_time + where charging_station_id = cs.charging_station_id + and cs.rate_model_id = rate_model_id + and start_time <= #{date} + and replace(end_time, '00:00:00', '24:00:00') >= #{date} + and status = 0 + and del_flag = 0)) powerFee, (select (ra.power_fee+ra.service_fee) as serviceFee from xhpc_rate as ra where ra.status = 0 @@ -937,4 +961,43 @@ ) + +