C端用户数据维度

This commit is contained in:
yuyang 2022-03-23 13:27:58 +08:00
parent 11f142e34b
commit 0f7906605c
6 changed files with 131 additions and 3 deletions

View File

@ -174,7 +174,10 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
DateTime parse1 = DateUtil.parse(DateUtil.format(endTime, "yyyy-MM-dd"), "yyyy-MM-dd");
//每分钟多少度电
BigDecimal decimal = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP);
BigDecimal divide =new BigDecimal(0);
if(decimal.compareTo(new BigDecimal(0))==1){
divide=chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP);
}
long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);
if(betweenDay==0){
powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime), DateUtil.formatTime(endTime), powerPriceTotal, divide);

View File

@ -9,7 +9,6 @@ import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.common.security.annotation.PreAuthorize;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.system.api.domain.SysRole;
import com.xhpc.system.api.domain.SysUser;
@ -22,7 +21,7 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -244,6 +243,34 @@ public class XhpcUserController extends BaseController {
return AjaxResult.success();
}
/**
* C端用户数据维度
* @param activity 活跃度
* @param frequency 充电次数
* @param amount 充电金额
* @param startTime 开始时间
* @param endTime 结束时间
* @param phone 手机号
* @return
*/
@GetMapping("/getUserDimension")
public TableDataInfo getUserDimension(Integer activity, Integer frequency, BigDecimal amount, String startTime, String endTime,String phone){
List<Map<String, Object>> userDimension = iXhpcUserService.getUserDimension(activity, frequency, amount, startTime, endTime,phone);
return getDataTable(userDimension);
}
private void addXhpcDataDimension(Long[] menuIds,Long userId){
if(menuIds !=null){
//添加数据维度

View File

@ -5,6 +5,7 @@ import com.xhpc.system.api.domain.SysUser;
import com.xhpc.user.domain.SysUserRole;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -144,4 +145,9 @@ public interface XhpcUserMapper {
* @param userId
*/
public void updateXhpcDataDimension(@Param("userId")Long userId);
public int getOrderTimeNumber(@Param("userId")String userId,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("tenantId")String tenantId);
List<Map<String,Object>> getUserDimension(@Param("number")Integer number,@Param("userId")String userId,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("tenantId")String tenantId,@Param("activity")Integer activity,@Param("frequency")Integer frequency,@Param("amount") BigDecimal amount,@Param("phone")String phone);
}

View File

@ -1,8 +1,10 @@
package com.xhpc.user.service;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.system.api.domain.SysRole;
import com.xhpc.system.api.domain.SysUser;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -128,4 +130,7 @@ public interface IXhpcUserService {
* @param userId
*/
public void updateXhpcDataDimension(Long userId);
List<Map<String, Object>> getUserDimension(Integer activity, Integer frequency, BigDecimal amount, String startTime, String endTime,String phone);
}

View File

@ -4,6 +4,7 @@ import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.constant.UserConstants;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.system.api.domain.SysRole;
@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -222,5 +224,19 @@ public class XhpcUserServiceImpl extends BaseService implements IXhpcUserService
xhpcUserMapper.updateXhpcDataDimension(userId);
}
@Override
public List<Map<String, Object>> getUserDimension(Integer activity, Integer frequency, BigDecimal amount, String startTime, String endTime,String phone) {
LoginUser loginUser = tokenService.getLoginUser();
String tenantId = loginUser.getTenantId();
//时间范围内的所有订单总数
int orderTimeNumber = xhpcUserMapper.getOrderTimeNumber(null, startTime, endTime, tenantId);
startPage();
List<Map<String, Object>> userDimension = xhpcUserMapper.getUserDimension(orderTimeNumber, null, startTime, endTime, tenantId,activity,frequency,amount,phone);
return userDimension;
}
}

View File

@ -304,4 +304,75 @@
<update id="updateXhpcDataDimension">
update xhpc_data_dimension set del_flag = 1 where user_id = #{userId}
</update>
<select id="getOrderTimeNumber" resultType="int">
select
count(history_order_id) number
from xhpc_history_order
where source = 0
<if test="tenantId !=null and tenantId !=''">
and tenant_id =#{tenantId}
</if>
<if test="startTime !=null and startTime !=''">
and end_time &gt;=#{startTime}
</if>
<if test="endTime !=null and endTime !=''">
and end_time &lt;= #{endTime}
</if>
<if test="userId !=null">
and end_time &lt;= #{endTime}
</if>
</select>
<select id="getUserDimension" resultType="map">
SELECT
us.number number,
us.totalPrice totalPrice,
us.activity activity,
us.appUserId appUserId,
us.phone phone
from xhpc_app_user AS xaus
JOIN (
SELECT
count(xho.history_order_id) number,
IFNULL(SUM(xho.total_price),0) totalPrice,
IFNULL(TRUNCATE((count(xho.history_order_id)/#{number})*100,0),0) activity,
xau.app_user_id appUserId,
xau.phone phone
from xhpc_app_user as xau
LEFT JOIN xhpc_history_order xho on xau.app_user_id = xho.user_id and xho.source = 0 and xho.tenant_id =#{tenantId}
where xau.del_flag =0
<if test="startTime !=null and startTime !=''">
and xho.end_time &gt;=#{startTime}
</if>
<if test="endTime !=null and endTime !=''">
and xho.end_time &lt;= #{endTime}
</if>
<if test="phone !=null and phone !=''">
and xau.phone like concat('%', #{phone}, '%')
</if>
GROUP BY xau.app_user_id
order by totalPrice desc) us on xaus.app_user_id = us.appUserId
where xaus.del_flag = 0
<if test="activity !=null">
and activity &gt;= #{activity}
</if>
<if test="frequency !=null">
and frequency &gt;= #{frequency}
</if>
<if test="amount !=null">
and amount &gt;= #{amount}
</if>
<if test="tenantId !=null and tenantId !=''">
and xaus.tenant_id =#{tenantId}
</if>
<if test="userId !=null">
and xaus.user_id = #{userId}
</if>
GROUP BY xaus.app_user_id
order by totalPrice desc,number desc,activity desc
</select>
</mapper>