|
@@ -30,6 +30,7 @@ import org.nutz.dao.sql.Criteria;
|
|
|
import org.nutz.dao.sql.Sql;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -61,11 +62,99 @@ public class RoleManageServiceImpl implements IRoleManageService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<Map> getRoleRechargeRanking(RoleRechargeRankingDTO dto) {
|
|
|
+ //创建查询条件 给主表使用
|
|
|
+ Criteria criA = getSqlByQuery(dto);
|
|
|
+ //给充值时间查询条件
|
|
|
+ Criteria criTodayAmount = getDateSqlByQuery(dto);
|
|
|
+ //分页对象
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
+ //查询总记录数
|
|
|
+ Sql countSql = Sqls.create(getCountNumSql(criA, criTodayAmount));
|
|
|
+ countSql.setCallback(Sqls.callback.integer());
|
|
|
+ dao.execute(countSql);
|
|
|
+ pager.setRecordCount(countSql.getInt());
|
|
|
+ //主表添加排序条件
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())) {
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())) {
|
|
|
+ criA.getOrderBy().orderBy("amount", dto.getSortType());
|
|
|
+ } else {
|
|
|
+ criA.getOrderBy().orderBy(dto.getSortFiled(), dto.getSortType());
|
|
|
+ }
|
|
|
+ //创建sql
|
|
|
+ Sql sql = Sqls.create(getRoleRechargeRankingSql(criA, criTodayAmount));
|
|
|
+ sql.setCallback(Sqls.callback.maps());
|
|
|
+ sql.setPager(pager);
|
|
|
+ dao.execute(sql);
|
|
|
+ //查询结果
|
|
|
+ List<Map> list = sql.getList(Map.class);
|
|
|
+ //用户id列表
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ for (Map map : list) {
|
|
|
+ //把投手id和运营id和GSID和客服人员ID 转成List
|
|
|
+ List<String> keys = Arrays.asList("put_user_id", "oper_user_id", "gs_id", "customer_service_id");
|
|
|
+ for (String key : keys) {
|
|
|
+ if (map.get(key) != null) {
|
|
|
+ userIds.add(Long.valueOf(map.get(key).toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //去掉字符串中的‘[]’
|
|
|
+ String str = (String) map.get("role_amount");
|
|
|
+ if(str!=null&&str.contains("[") && str.contains("]")){
|
|
|
+ map.put("role_amount", str.replaceAll("\\[|\\]", ""));
|
|
|
+ }
|
|
|
+ //去除‘null’字符串
|
|
|
+ List<String> nullStringKeys = Arrays.asList("add_corp_user_id", "user_wechat", "remark", "user_phone", "country");
|
|
|
+ nullStringKeys.stream()
|
|
|
+ .filter(key -> "null".equals(map.get(key)))
|
|
|
+ .forEach(key -> map.put(key, null));
|
|
|
+ }
|
|
|
+ //去重userIds
|
|
|
+ userIds = userIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ //发送RPC接口查询所有用户
|
|
|
+ ResultVO<Map<Long, String>> userMap = sysUserRpc.getUserNameByIds(userIds);
|
|
|
+
|
|
|
+ for (Map map : list) {
|
|
|
+ //投手名
|
|
|
+ updateUserName(map, "put_user_id", "put_user_name", userMap);
|
|
|
+ //运营人员名
|
|
|
+ updateUserName(map, "oper_user_id", "oper_user_name", userMap);
|
|
|
+ //GS人员名
|
|
|
+ updateUserName(map, "gs_id", "gs_name", userMap);
|
|
|
+ //客服人员名
|
|
|
+ updateUserName(map, "customer_service_id", "customer_service_name", userMap);
|
|
|
+ }
|
|
|
+ //返回结果
|
|
|
+ return new Page<>(list, pager);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新用户名称
|
|
|
+ private void updateUserName(Map<String, Object> map, String userIdKey, String userNameKey, ResultVO<Map<Long, String>> userMap) {
|
|
|
+ Object userIdObj = map.get(userIdKey);
|
|
|
+ if (userIdObj != null) {
|
|
|
+ try {
|
|
|
+ long userId = Long.parseLong(userIdObj.toString());
|
|
|
+ String userName = userMap.getData().get(userId);
|
|
|
+ if (userName != null) {
|
|
|
+ map.put(userNameKey, userName);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 处理长整型转换异常
|
|
|
+ log.error("Error parsing user ID for key " + userIdKey + ": " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件生成查询sql条件
|
|
|
+ */
|
|
|
+ private Criteria getSqlByQuery(RoleRechargeRankingDTO dto){
|
|
|
//默认查询不合服的数据
|
|
|
if (dto.getIsMergeServer() == null) {
|
|
|
dto.setIsMergeServer(Boolean.FALSE);
|
|
|
}
|
|
|
- //创建查询条件 给主表使用
|
|
|
Criteria criA = Cnd.cri();
|
|
|
if (CollectionUtils.isNotEmpty(dto.getGameId())) {
|
|
|
//角色注册子游戏
|
|
@@ -208,7 +297,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
|
|
|
criA.where().andEquals("is_add_corp_wechat", dto.getIsAddCorpWechat());
|
|
|
}
|
|
|
}
|
|
|
- //给充值时间查询条件
|
|
|
+ return criA;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据时间条件生成查询sql
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Criteria getDateSqlByQuery(RoleRechargeRankingDTO dto){
|
|
|
Criteria criTodayAmount = Cnd.cri();
|
|
|
//查询充值成功的
|
|
|
criTodayAmount.where().andEquals("status", 2);
|
|
@@ -216,103 +312,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
|
|
|
//充值时间限制
|
|
|
criTodayAmount.where().andBetween("DATE(pay_time)", dto.getRechargeBeginDate(), dto.getRechargeEndDate());
|
|
|
}
|
|
|
- //分页对象
|
|
|
- Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
- //查询总记录数
|
|
|
- Sql countSql = Sqls.create(getCountNumSql(criA, criTodayAmount));
|
|
|
- countSql.setCallback(Sqls.callback.integer());
|
|
|
- dao.execute(countSql);
|
|
|
- pager.setRecordCount(countSql.getInt());
|
|
|
- //主表添加排序条件
|
|
|
- if (StringUtils.isBlank(dto.getSortType())) {
|
|
|
- dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(dto.getSortFiled())) {
|
|
|
- criA.getOrderBy().orderBy("amount", dto.getSortType());
|
|
|
- } else {
|
|
|
- criA.getOrderBy().orderBy(dto.getSortFiled(), dto.getSortType());
|
|
|
- }
|
|
|
- //创建sql
|
|
|
- Sql sql = Sqls.create(getRoleRechargeRankingSql(criA, criTodayAmount));
|
|
|
- sql.setCallback(Sqls.callback.maps());
|
|
|
- sql.setPager(pager);
|
|
|
- dao.execute(sql);
|
|
|
- //查询结果
|
|
|
- List<Map> list = sql.getList(Map.class);
|
|
|
- //用户id列表
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
- for (Map map : list) {
|
|
|
-// getNameById(map);
|
|
|
- //把投手id和运营id和GSID和客服人员ID 转成List
|
|
|
- if(map.get("put_user_id") != null){
|
|
|
- userIds.add(Long.valueOf(map.get("put_user_id").toString()));
|
|
|
- }
|
|
|
- if(map.get("oper_user_id") != null){
|
|
|
- userIds.add(Long.valueOf(map.get("oper_user_id").toString()));
|
|
|
- }
|
|
|
- if(map.get("gs_id") != null){
|
|
|
- userIds.add(Long.valueOf(map.get("gs_id").toString()));
|
|
|
- }
|
|
|
- if(map.get("customer_service_id") != null){
|
|
|
- userIds.add(Long.valueOf(map.get("customer_service_id").toString()));
|
|
|
- }
|
|
|
- String str = (String) map.get("role_amount");
|
|
|
- if(str!=null&&str.contains("[") && str.contains("]")){
|
|
|
- //去掉字符串中的‘[]’
|
|
|
- map.put("role_amount", str.replaceAll("\\[|\\]", ""));
|
|
|
- }
|
|
|
-
|
|
|
- //去除‘null’字符串
|
|
|
- if ("null".equals(map.get("add_corp_user_id"))) {
|
|
|
- map.put("add_corp_user_id", null);
|
|
|
- }
|
|
|
- if ("null".equals(map.get("user_wechat"))) {
|
|
|
- map.put("user_wechat", null);
|
|
|
- }
|
|
|
- if ("null".equals(map.get("remark"))) {
|
|
|
- map.put("remark", null);
|
|
|
- }
|
|
|
- if ("null".equals(map.get("user_phone"))) {
|
|
|
- map.put("user_phone", null);
|
|
|
- }
|
|
|
- if ("null".equals(map.get("country"))) {
|
|
|
- map.put("country", null);
|
|
|
- }
|
|
|
- }
|
|
|
- //去重userIds
|
|
|
- userIds = userIds.stream().distinct().collect(Collectors.toList());
|
|
|
- //发送RPC接口查询所有用户
|
|
|
- ResultVO<Map<Long, String>> userMap = sysUserRpc.getUserNameByIds(userIds);
|
|
|
-
|
|
|
- for (Map map : list) {
|
|
|
- //投手名
|
|
|
- updateUserName(map, "put_user_id", "put_user_name", userMap);
|
|
|
- //运营人员名
|
|
|
- updateUserName(map, "oper_user_id", "oper_user_name", userMap);
|
|
|
- //GS人员名
|
|
|
- updateUserName(map, "gs_id", "gs_name", userMap);
|
|
|
- //客服人员名
|
|
|
- updateUserName(map, "customer_service_id", "customer_service_name", userMap);
|
|
|
- }
|
|
|
- //返回结果
|
|
|
- return new Page<>(list, pager);
|
|
|
- }
|
|
|
-
|
|
|
- // 更新用户名称
|
|
|
- private void updateUserName(Map<String, Object> map, String userIdKey, String userNameKey, ResultVO<Map<Long, String>> userMap) {
|
|
|
- Object userIdObj = map.get(userIdKey);
|
|
|
- if (userIdObj != null) {
|
|
|
- try {
|
|
|
- long userId = Long.parseLong(userIdObj.toString());
|
|
|
- String userName = userMap.getData().get(userId);
|
|
|
- if (userName != null) {
|
|
|
- map.put(userNameKey, userName);
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- // 处理长整型转换异常
|
|
|
- log.error("Error parsing user ID for key " + userIdKey + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
+ return criTodayAmount;
|
|
|
}
|
|
|
|
|
|
|