小程序首页、站点详情、时间段增加优惠金额显示

This commit is contained in:
yuyang 2022-05-31 11:33:15 +08:00
parent 4ab77c7fa9
commit fe05c3c6da
4 changed files with 347 additions and 9 deletions

View File

@ -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;
}

View File

@ -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<XhpcActivityDiscountDto> getActivityDiscountTime(@Param("internetUserId")Long internetUserId, @Param("startTime")String startTime, @Param("userType")Integer userType, @Param("chargingStationId")Long chargingStationId, @Param("tenantId")String tenantId);
}

View File

@ -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<String> 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<String, Object> map = list.get(i);
BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString());
BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString());
if(loginUser !=null){
//判断是否享受活动
Map<String, Object> 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<String, Object> 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<String, Object> map = xhpcChargingStationMapper.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude);
//空闲和使用从redis获取
LoginUser loginUser = tokenService.getLoginUser();
Map<String, Object> 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<String, Object> 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<String, Object> 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<Map<String, Object>> getWXXhpcRateTimeMassage(Long chargingStationId) {
return xhpcChargingStationMapper.getWXXhpcRateTimeMassage(chargingStationId);
List<Map<String, Object>> list = xhpcChargingStationMapper.getWXXhpcRateTimeMassage(chargingStationId);
LoginUser loginUser = tokenService.getLoginUser();
for (int i = 0; i <list.size() ; i++) {
Map<String, Object> map = list.get(i);
BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString());
BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString());
if(loginUser !=null){
//判断是否享受活动
Map<String, Object> 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<String,Object> activityDiscountTime(Long userId,Date startTime,Integer source,Long chargingStationId,String tenantId){
Map<String,Object> map =new HashMap<>();
List<XhpcActivityDiscountDto> 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;
}
}

View File

@ -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 &lt;= #{date}
and replace(end_time, '00:00:00', '24:00:00') &gt;= #{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 &lt;= #{date}
and replace(end_time, '00:00:00', '24:00:00') &gt;= #{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 @@
</if>
)
</insert>
<select id="getActivityDiscountTime" resultType="com.xhpc.charging.station.dto.XhpcActivityDiscountDto">
select
xad.activity_id as activityId,
xad.activity_name as activityName,
xad.template_id as templateId,
xad.app_user_list as appUserList,
xad.com_user_list as comUserList,
xad.cus_user_list as cusUserList,
xad.station_list as stationList,
xad.tenant_id as tenantId,
xad.start_time as startTime,
xad.end_time as endTime,
xad.status as status,
xad.del_flag as delFlag,
xad.create_by as createBy,
xad.create_time as createTime,
xad.update_by as updateBy,
xad.update_time as updateTime,
xad.check_by as checkBy,
xad.check_time as checkTime,
xat.discount_type discountType,
xat.discount_rate discountRate
from xhpc_activity_discount as xad
join xhpc_activity_template as xat on xat.activity_template_id = xad.template_id and xat.del_flag =0 and xat.status=1
where xad.tenant_id=#{tenantId} and xad.status=3 and xad.del_flag =0
and find_in_set(#{chargingStationId}, xad.station_list)
<if test="userType ==0">
and (find_in_set(#{internetUserId}, xad.app_user_list) or xad.app_user_list='-1')
</if>
<if test="userType ==2">
and (find_in_set(#{internetUserId}, xad.com_user_list) or xad.com_user_list='-1')
</if>
<if test="userType ==3">
and (find_in_set(#{internetUserId}, xad.cus_user_list) or xad.cus_user_list='-1')
</if>
and xad.start_time &lt;=#{startTime} and xad.end_time &gt; #{startTime}
order by xad.start_time asc
</select>
</mapper>