当C端、社区、B端用户享受活动时,小程序首页弹出互动图片

This commit is contained in:
yuyang 2022-06-01 14:06:57 +08:00
parent fe05c3c6da
commit 5dbb6ee49f
5 changed files with 285 additions and 15 deletions

View File

@ -362,6 +362,23 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
//获取实时数据
Map<String, Object> 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<CacheRealtimeData> list = (List<CacheRealtimeData>) 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"));
}
}
}
}

View File

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

View File

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

View File

@ -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<String, Object> token = tokenService.createToken(userInfo);
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<appUserId>>>>>>>>>>>>"+appUserId);
logger.info("<<<<<<<<<<token>>>>>>>>>>>>"+token.toString());
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
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<String, Object> token = tokenService.createToken(userInfo);
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<appUserId>>>>>>>>>>>>"+user.getAppUserId());
logger.info("<<<<<<<<<<token>>>>>>>>>>>>"+token.toString());
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
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<String, Object> 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<String,Object> activityDiscountTime(Long userId,Date startTime,Integer source,Long chargingStationId,String tenantId){
Map<String,Object> map =new HashMap<>();
List<XhpcActivityDiscountDto> 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;
}
}

View File

@ -355,4 +355,43 @@
<update id="updateUserLoginTime">
update xhpc_user_login set status =0 where account=#{account} and status=1
</update>
<select id="getActivityDiscountTime" resultType="com.xhpc.user.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,
xat.background_url as backgroundUrl
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
<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>