igl 9 месяцев назад
Родитель
Сommit
0f67d1443f

+ 31 - 2
vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/dto/TeamDTO.java

@@ -17,9 +17,38 @@ public class TeamDTO implements Serializable {
 
 
     private static final long serialVersionUID = 830186969637948801L;
     private static final long serialVersionUID = 830186969637948801L;
 
 
-    private Long total;
+    /**
+     * 邀请总人数
+     */
+    private long total = 0;
 
 
-    private BigDecimal totalAmount;
+    /**
+     * 邀请总收益
+     */
+    private BigDecimal totalAmount = BigDecimal.ZERO;
 
 
+    /**
+     * 今日新增
+     */
+    private long today = 0;
+
+    /**
+     * 昨日新增
+     */
+    private long lastDay = 0;
+
+    /**
+     * 本月新增
+     */
+    private long toMonth = 0;
+
+    /**
+     * 上月新增
+     */
+    private long lastMonth = 0;
+
+    /**
+     * 邀请用户信息
+     */
     private List<TeamDetailsDTO> records;
     private List<TeamDetailsDTO> records;
 }
 }

+ 11 - 0
vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/dto/TeamDetailsDTO.java

@@ -7,6 +7,7 @@ import lombok.experimental.SuperBuilder;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 
 
 @Data
 @Data
 @SuperBuilder
 @SuperBuilder
@@ -49,4 +50,14 @@ public class TeamDetailsDTO implements Serializable {
      * 来源类型:1-用户分佣;2-商户分佣
      * 来源类型:1-用户分佣;2-商户分佣
      */
      */
     private Integer sourceType;
     private Integer sourceType;
+
+    /**
+     * 手机号
+     */
+    private String mobile;
+
+    /**
+     * 邀请时间
+     */
+    private LocalDateTime inviteTime;
 }
 }

+ 4 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/dao/UserInviteMapper.java

@@ -7,6 +7,7 @@ import com.chelvc.cloud.vehicle.server.entity.UserInvite;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 
 
 @Mapper
 @Mapper
@@ -14,7 +15,9 @@ public interface UserInviteMapper extends BaseMapper<UserInvite> {
     List<TeamDetailsDTO> teamList(@Param("type") Integer type, @Param("pageNum") int pageNum,
     List<TeamDetailsDTO> teamList(@Param("type") Integer type, @Param("pageNum") int pageNum,
                                               @Param("pageSize") int pageSize, @Param("userId") Long userId);
                                               @Param("pageSize") int pageSize, @Param("userId") Long userId);
 
 
-    TeamDTO teamTotalStatistics(@Param("type") Integer type, @Param("userId") Long userId);
+    TeamDTO teamTotalStatistics(@Param("type") Integer type, @Param("userId") Long userId,
+                                @Param("midnight") LocalDateTime midnight, @Param("yesterdayMidnight") LocalDateTime yesterdayMidnight,
+                                @Param("toMonth") LocalDateTime toMonth, @Param("lastMonth") LocalDateTime lastMonth);
 
 
 
 
     List<TeamDetailsDTO> inviteList(@Param("type") Integer type, @Param("pageNum") int pageNum,
     List<TeamDetailsDTO> inviteList(@Param("type") Integer type, @Param("pageNum") int pageNum,

+ 58 - 24
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/UserInviteServiceImpl.java

@@ -24,13 +24,15 @@ import com.chelvc.framework.common.function.Executor;
 import com.chelvc.framework.common.model.Paging;
 import com.chelvc.framework.common.model.Paging;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.TemporalAdjusters;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -105,7 +107,22 @@ public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInv
 
 
     @Override
     @Override
     public TeamDTO teamList(TeamInvitePageParam param, Long userId) {
     public TeamDTO teamList(TeamInvitePageParam param, Long userId) {
-        TeamDTO dto = new TeamDTO();
+        LocalDate today = LocalDate.now(); // 获取今天的日期
+        LocalDateTime midnight = LocalDateTime.of(today, LocalTime.MIDNIGHT); // 获取今天凌晨的时间
+        LocalDate yesterday = today.minusDays(1);
+        LocalDateTime yesterdayMidnight = LocalDateTime.of(yesterday, LocalTime.MIN);
+        LocalDateTime toMonth = LocalDateTime.of(LocalDate.from(LocalDateTime.now()
+                .with(TemporalAdjusters.firstDayOfMonth())), LocalTime.MIN);
+        LocalDateTime lastMonth = toMonth.minusMonths(1);
+        TeamDTO dto = baseMapper.teamTotalStatistics(param.getType(), userId,
+                midnight, yesterdayMidnight, toMonth, lastMonth);
+        if(dto == null){
+            return new TeamDTO();
+        }
+        BigDecimal totalAmount = dto.getTotalAmount();
+        if(totalAmount == null){
+            dto.setTotalAmount(BigDecimal.ZERO);
+        }
         Paging paging = param.getPaging();
         Paging paging = param.getPaging();
         int pageNum = (paging.getNumber() - 1) * paging.getSize();
         int pageNum = (paging.getNumber() - 1) * paging.getSize();
         if(pageNum < 0){
         if(pageNum < 0){
@@ -115,53 +132,69 @@ public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInv
         if(CollectionUtils.isEmpty(records)){
         if(CollectionUtils.isEmpty(records)){
             return dto;
             return dto;
         }
         }
-        List<Long> userList = records.stream().map(TeamDetailsDTO::getUserId).collect(Collectors.toList());
-        List<UserDTO> usersLists = this.userService.listUsers(userList);
-        Map<Long, String> userMap = usersLists.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
-        Map<Long, String> map = new HashMap<>();
-        Map<Long,String> avatar = new HashMap<>();
+        Map<Long, TeamDetailsDTO> userMap = new HashMap<>();
         if(param.getType() == null){
         if(param.getType() == null){
             List<Long> userIds = records.stream().filter(e -> e.getSourceType() == 1).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<Long> userIds = records.stream().filter(e -> e.getSourceType() == 1).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<UserDTO> users = this.userService.listUsers(userIds);
             List<UserDTO> users = this.userService.listUsers(userIds);
             if(!CollectionUtils.isEmpty(users)){
             if(!CollectionUtils.isEmpty(users)){
-                map = users.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
-                avatar = users.stream().filter(e -> StringUtils.isNotBlank(e.getAvatar())).collect(Collectors.toMap(UserDTO::getId, UserDTO::getAvatar));
+                users.forEach(e ->{
+                    TeamDetailsDTO detailsDTO = new TeamDetailsDTO();
+                    detailsDTO.setInviteUserAvatar(e.getAvatar());
+                    detailsDTO.setNickname(e.getNickname());
+                    detailsDTO.setMobile(e.getMobile());
+                    userMap.put(e.getId(), detailsDTO);
+                });
             }
             }
             List<Long> merchantIds = records.stream().filter(e -> e.getSourceType() == 2).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<Long> merchantIds = records.stream().filter(e -> e.getSourceType() == 2).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<MerchantDTO> merchants = this.merchantService.getMerchantByIds(merchantIds);
             List<MerchantDTO> merchants = this.merchantService.getMerchantByIds(merchantIds);
-            if(!CollectionUtils.isEmpty(users)){
-                map.putAll(merchants.stream().collect(Collectors.toMap(MerchantDTO::getId, MerchantDTO::getName)));
-                avatar.putAll(merchants.stream().collect(Collectors.toMap(MerchantDTO::getId, MerchantDTO::getLogo)));
+            if(!CollectionUtils.isEmpty(merchants)){
+                merchants.forEach(e ->{
+                    TeamDetailsDTO detailsDTO = new TeamDetailsDTO();
+                    detailsDTO.setInviteUserAvatar(e.getLogo());
+                    detailsDTO.setNickname(e.getName());
+                    detailsDTO.setMobile(e.getMobile());
+                    userMap.put(e.getId(), detailsDTO);
+                });
             }
             }
         } else if(param.getType() == 1){
         } else if(param.getType() == 1){
             List<Long> ids = records.stream().map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<Long> ids = records.stream().map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<UserDTO> users = this.userService.listUsers(ids);
             List<UserDTO> users = this.userService.listUsers(ids);
             if(!CollectionUtils.isEmpty(users)){
             if(!CollectionUtils.isEmpty(users)){
-                map = users.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
-                avatar = users.stream().filter(e -> StringUtils.isNotBlank(e.getAvatar())).collect(Collectors.toMap(UserDTO::getId, UserDTO::getAvatar));
+                users.forEach(e ->{
+                    TeamDetailsDTO detailsDTO = new TeamDetailsDTO();
+                    detailsDTO.setInviteUserAvatar(e.getAvatar());
+                    detailsDTO.setNickname(e.getNickname());
+                    detailsDTO.setMobile(e.getMobile());
+                    userMap.put(e.getId(), detailsDTO);
+                });
             }
             }
         } else if(param.getType() == 2){
         } else if(param.getType() == 2){
             List<Long> ids = records.stream().map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<Long> ids = records.stream().map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<MerchantDTO> merchants = this.merchantService.getMerchantByIds(ids);
             List<MerchantDTO> merchants = this.merchantService.getMerchantByIds(ids);
             if(!CollectionUtils.isEmpty(merchants)) {
             if(!CollectionUtils.isEmpty(merchants)) {
-                map = merchants.stream().collect(Collectors.toMap(MerchantDTO::getId, MerchantDTO::getName));
-                avatar = merchants.stream().filter(e -> StringUtils.isNotBlank(e.getLogo())).collect(Collectors.toMap(MerchantDTO::getId, MerchantDTO::getLogo));
+                merchants.forEach(e ->{
+                    TeamDetailsDTO detailsDTO = new TeamDetailsDTO();
+                    detailsDTO.setInviteUserAvatar(e.getLogo());
+                    detailsDTO.setNickname(e.getName());
+                    detailsDTO.setMobile(e.getMobile());
+                    userMap.put(e.getId(), detailsDTO);
+                });
             }
             }
         }
         }
         for(TeamDetailsDTO detailsDTO : records){
         for(TeamDetailsDTO detailsDTO : records){
-            detailsDTO.setName(map.get(detailsDTO.getInviteUserId()));
-            detailsDTO.setNickname(userMap.get(detailsDTO.getUserId()));
-            detailsDTO.setInviteUserAvatar(avatar.get(detailsDTO.getInviteUserId()));
+            Long id = detailsDTO.getInviteUserId();
+            TeamDetailsDTO teamDetailsDTO = userMap.get(id);
+            if(teamDetailsDTO != null){
+                detailsDTO.setName(teamDetailsDTO.getNickname());
+                detailsDTO.setNickname(teamDetailsDTO.getNickname());
+                detailsDTO.setInviteUserAvatar(teamDetailsDTO.getInviteUserAvatar());
+                detailsDTO.setMobile(teamDetailsDTO.getMobile());
+            }
             BigDecimal amount = detailsDTO.getAmount();
             BigDecimal amount = detailsDTO.getAmount();
             if(amount == null){
             if(amount == null){
                 detailsDTO.setAmount(BigDecimal.ZERO);
                 detailsDTO.setAmount(BigDecimal.ZERO);
             }
             }
         }
         }
-        dto = baseMapper.teamTotalStatistics(param.getType(), userId);
-        BigDecimal totalAmount = dto.getTotalAmount();
-        if(totalAmount == null){
-            dto.setTotalAmount(BigDecimal.ZERO);
-        }
         dto.setRecords(records);
         dto.setRecords(records);
         return dto;
         return dto;
     }
     }
@@ -192,6 +225,7 @@ public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInv
         List<Long> userList = records.stream().map(TeamDetailsDTO::getUserId).collect(Collectors.toList());
         List<Long> userList = records.stream().map(TeamDetailsDTO::getUserId).collect(Collectors.toList());
         List<UserDTO> usersLists = this.userService.listUsers(userList);
         List<UserDTO> usersLists = this.userService.listUsers(userList);
         Map<Long, String> userMap = usersLists.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
         Map<Long, String> userMap = usersLists.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
+        Map<Long, String> mobileMap = usersLists.stream().collect(Collectors.toMap(UserDTO::getId, UserDTO::getNickname));
         Map<Long, String> map = new HashMap<>();
         Map<Long, String> map = new HashMap<>();
         if(param.getType() == null){
         if(param.getType() == null){
             List<Long> userIds = records.stream().filter(e -> e.getSourceType() == 1).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
             List<Long> userIds = records.stream().filter(e -> e.getSourceType() == 1).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());

+ 23 - 9
vehicle-server/src/main/resources/mapper/UserInviteMapper.xml

@@ -7,7 +7,8 @@
             i.user_id,
             i.user_id,
             target_id AS inviteUserId,
             target_id AS inviteUserId,
             SUM( r.reality_amount ) amount,
             SUM( r.reality_amount ) amount,
-            i.type sourceType
+            i.type sourceType,
+            i.create_time AS inviteTime
         FROM
         FROM
             user_invite i
             user_invite i
                 LEFT JOIN currency_record r ON i.user_id = r.user_id
                 LEFT JOIN currency_record r ON i.user_id = r.user_id
@@ -22,14 +23,18 @@
         GROUP BY
         GROUP BY
             i.id
             i.id
         ORDER BY
         ORDER BY
-            amount DESC
+            inviteTime,amount DESC
         limit #{pageNum}, #{pageSize}
         limit #{pageNum}, #{pageSize}
     </select>
     </select>
 
 
     <select id="teamTotalStatistics" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDTO">
     <select id="teamTotalStatistics" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDTO">
         SELECT
         SELECT
         count(i.id) total,
         count(i.id) total,
-        sum(r.reality_amount) totalAmount
+        sum(r.reality_amount) totalAmount,
+        count(i.create_time >= #{midnight} or null) as today,
+        count((i.create_time >= #{yesterdayMidnight} and i.create_time <![CDATA[ < ]]> #{midnight}) or null) as lastDay,
+        count(i.create_time >= #{toMonth} or null) as toMonth,
+        count((i.create_time >= #{lastMonth} and i.create_time <![CDATA[ < ]]> #{toMonth}) or null) as lastMonth
         FROM
         FROM
         user_invite i
         user_invite i
         LEFT JOIN currency_record r ON i.user_id = r.user_id
         LEFT JOIN currency_record r ON i.user_id = r.user_id
@@ -43,15 +48,13 @@
         </if>
         </if>
     </select>
     </select>
 
 
-
-
-
     <select id="inviteList" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDetailsDTO">
     <select id="inviteList" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDetailsDTO">
         SELECT
         SELECT
         i.user_id,
         i.user_id,
         target_id AS inviteUserId,
         target_id AS inviteUserId,
         SUM( r.reality_amount ) amount,
         SUM( r.reality_amount ) amount,
-        i.type sourceType
+        i.type sourceType,
+        i.create_time AS inviteTime
         FROM
         FROM
         user_invite i
         user_invite i
         LEFT JOIN currency_record r ON i.user_id = r.user_id
         LEFT JOIN currency_record r ON i.user_id = r.user_id
@@ -69,8 +72,6 @@
         limit #{pageNum}, #{pageSize}
         limit #{pageNum}, #{pageSize}
     </select>
     </select>
 
 
-
-
     <select id="inviteTotalStatistics" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDTO">
     <select id="inviteTotalStatistics" resultType="com.chelvc.cloud.vehicle.client.dto.TeamDTO">
         SELECT
         SELECT
         count(i.id) total,
         count(i.id) total,
@@ -88,4 +89,17 @@
         </if>
         </if>
     </select>
     </select>
 
 
+    <select id="getMerchantAsset" resultType="com.chelvc.cloud.vehicle.client.dto.WalletDTO">
+        SELECT
+            SUM(operate_amount) as totalEarnings,
+            SUM(CASE WHEN create_time >= #{midnight} THEN operate_amount ELSE 0 END) as todayEarnings,
+            SUM(CASE WHEN create_time >= #{yesterdayMidnight} and create_time <![CDATA[ < ]]> #{midnight} THEN operate_amount ELSE 0 END) as yesterdayEarnings
+        FROM
+            balance_detail
+        WHERE
+            target_id = #{merchantId}
+          AND type = 2
+          AND flow_type = 0
+          AND operate_type = 1
+    </select>
 </mapper>
 </mapper>