修改道具日志展示

jieling
grimm 2024-05-17 18:56:06 +08:00
parent 7b180959c6
commit dd44e0cf19
9 changed files with 340 additions and 178 deletions

View File

@ -1,12 +1,14 @@
package com.jmfy.controller;
import com.alibaba.fastjson.JSONObject;
import com.jmfy.dao.ItemDao;
import com.jmfy.dao.ServerInfoDao;
import com.jmfy.model.CItemInfo;
import com.jmfy.model.CItemParam;
import com.jmfy.model.MoneyFlow;
import com.jmfy.model.ServerInfo;
import com.jmfy.model.vo.ItemFlowVo;
import com.jmfy.model.vo.ItemNameVo;
import com.jmfy.utils.DateUtil;
import com.jmfy.utils.FileCacheUtils;
import com.jmfy.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,12 +19,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by huangds on 2017/10/24.
@ -46,184 +46,49 @@ public class FindFlowController {
}
@RequestMapping(value = "/findFlow", method = {RequestMethod.POST,RequestMethod.GET})
public String findFlow(HttpSession session, ModelMap map , HttpServletRequest request) throws Exception {
public String findFlow(ModelMap map , HttpServletRequest request) throws Exception {
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
String startTime = parameterMap.get("startTime");
String endTime = parameterMap.get("endTime");
String serverId = parameterMap.get("serverId");
String userId = parameterMap.get("userId");
int page = Integer.parseInt(parameterMap.getOrDefault("page","1"));
CItemParam param = new CItemParam();
param.setEndTime(endTime);
param.setStartTime(startTime);
param.setServerId(Integer.parseInt(serverId));
param.setUserId(Integer.parseInt(userId));
param.setPage(page);
List<CItemInfo> moneyFlowList = itemDao.getItemFlowByUser(param);
List<ItemFlowVo> itemFlowVoList = new ArrayList<>();
SimpleDateFormat dateFormat = new SimpleDateFormat();
List<ItemFlowVo> itemFlowVoList = new ArrayList<>();
for (CItemInfo moneyFlow :moneyFlowList){
ItemFlowVo itemFlowVo = new ItemFlowVo();
itemFlowVo.setUserId(String.valueOf(moneyFlow.getUid()));
itemFlowVo.setServerId(serverId);
itemFlowVo.setUserLevel(moneyFlow.getLevel());
itemFlowVo.setTime(dateFormat.format(new Date(Long.parseLong(moneyFlow.getTime()))));
itemFlowVo.setItemName(moneyFlow.getItemId()+"."+FileCacheUtils.itemNameMap.get(moneyFlow.getItemId()));
itemFlowVo.setReason(FileCacheUtils.itemFlowResson.containsKey(moneyFlow.getReason()) ? FileCacheUtils.itemFlowResson.get(moneyFlow.getReason()) : Integer.toString(moneyFlow.getReason()));
itemFlowVo.setTime(DateUtil.stampToTime(Long.parseLong(moneyFlow.getTime())));
itemFlowVo.setItemId(moneyFlow.getItemId());
itemFlowVo.setItemName(moneyFlow.getItemName());
itemFlowVo.setReason(moneyFlow.getReasonStr());
itemFlowVo.setAfterMoney(String.valueOf(moneyFlow.getItemTotalNum()));
itemFlowVo.setAddOrReduce(String.valueOf(moneyFlow.getType()));
if(moneyFlow.getReason() == 41){
itemFlowVo.setAddOrReduce("0");
}
itemFlowVo.setAddOrReduce(moneyFlow.getTypeStr());
itemFlowVo.setCount(String.valueOf(moneyFlow.getItemNum()));
itemFlowVoList.add(itemFlowVo);
}
map.put("itemFlowVoList", itemFlowVoList);
map.put("itemNameMap",FileCacheUtils.itemNameMap);
return "itemFlow";
map.put("itemNameMap",buildItemNameVoList());
map.put("paramvalue", JSONObject.toJSONString(param));
return "itemFlow2";
}
public List<ItemNameVo> buildItemNameVoList(){
ArrayList<ItemNameVo> itemNameVos = new ArrayList<>();
for (Map.Entry<Integer, String> entry : FileCacheUtils.itemNameMap.entrySet()) {
ItemNameVo itemNameVo = new ItemNameVo();
itemNameVo.setId(entry.getKey());
itemNameVo.setName(entry.getValue());
itemNameVos.add(itemNameVo);
}
return itemNameVos;
}
//
// private String getReason(String reason) {
// return STableManager.getInstance().getsReason(Integer.parseInt(reason));
// }
//
// private String getItemName(int itemId, int iGoodsType) {
// String itemName = "";
// switch (iGoodsType) {
// case 999:
// itemName = getMoneyName(itemId);
// break;
// case 0:
// itemName = STableManager.getInstance().getsItemName(itemId);
// if (itemName ==null){
// itemName = STableManager.getInstance().getsExpCardName(itemId);
// if (itemName == null || itemName.isEmpty()) {
// itemName = String.valueOf(itemId);
// }
// }
// break;
// case 2:
// itemName = STableManager.getInstance().getsHeroName(itemId);
// break;
// case 3:
// itemName = STableManager.getInstance().getsYaofuName(itemId);
// break;
// case 4:
// //todo 皮肤 现在版本没有
// itemName = String.valueOf(itemId);
// break;
// case 5:
// //todo 头像框
// itemName = STableManager.getInstance().getsHeadName(itemId);
// break;
// case 6:
// itemName = STableManager.getInstance().getsItemName(itemId);
// break;
// case 7:
// itemName = STableManager.getInstance().getsItemName(itemId);
// break;
// case 8:
// itemName = STableManager.getInstance().getsItemName(itemId);
// break;
// case 10:
// itemName = STableManager.getInstance().getsMindName(itemId);
// break;
// case 11:
// //头像
// itemName = STableManager.getInstance().getsHeadName(itemId);
// break;
// case 14:
// //聊天红包
// itemName = "聊天红包";
// break;
// default:
// if (itemName.isEmpty()) {
// itemName = String.valueOf(itemId);
// }
// }
// return itemName;
// }
//
// private String getMoneyName(int moneyType) {
// String name = "";
// switch (moneyType) {
// case 0:
// name = "金币";
// break;
// case 1:
// name = "妖灵币";
// break;
// case 2:
// name = "友情点";
// break;
// case 3:
// name = "荣誉";
// break;
// case 4:
// name = "中级荣誉";
// break;
// case 5:
// name = "高级荣誉";
// break;
// case 8:
// name = "神券";
// break;
// case 9:
// name = "体力";
// break;
// case 10:
// name = "皮肤券";
// break;
// case 11:
// name = "灵石";
// break;
// case 12:
// name = "玄";
// break;
// case 13:
// name = "素";
// break;
// case 14:
// name = "鸣";
// break;
// case 15:
// name = "宗门资产";
// break;
// default:
// name = STableManager.getInstance().getsItemName(moneyType);
// if (name == null || name.isEmpty()) {
// name = String.valueOf(moneyType);
// }
//
// }
// return name;
// }
//
//
//
// @RequestMapping(value = "/findShopFlow", method = {RequestMethod.POST,RequestMethod.GET})
// public String findShopFlow(HttpSession session, ModelMap map , HttpServletRequest request) throws Exception {
// HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
// String startTime = parameterMap.get("startTime");
// String endTime = parameterMap.get("endTime");
// String serverId = parameterMap.get("serverId");
// String shopId = parameterMap.get("shopId");
// List<ShopBuyInfoFlow> itemFlowList = itemDao.findItemFlowInfoBuyShop(serverId,startTime,endTime,shopId);
// List<ShopItemInfoVo> shopItemInfoVos = new ArrayList<>();
// Map<String,Integer> itemBuyTimes = new HashMap<>();
// for (ShopBuyInfoFlow itemFlow:itemFlowList){
// String itemName = itemFlow.getBuyItemName();
// int itemNum = Integer.parseInt(itemFlow.getBuyItemNum());
// if (itemBuyTimes.containsKey(itemName)){
// itemNum = itemBuyTimes.get(itemName) + itemNum;
// }
// itemBuyTimes.put(itemName,itemNum);
// }
// for ( Map.Entry<String,Integer> entry :itemBuyTimes.entrySet()){
// ShopItemInfoVo shopItemInfoVo = new ShopItemInfoVo();
// shopItemInfoVo.setBuyNum(entry.getValue());
// shopItemInfoVo.setItemName(entry.getKey());
// shopItemInfoVos.add(shopItemInfoVo);
// }
// map.put("shopItemInfoVos",shopItemInfoVos);
// return "shopItemInfo";
// }
}

View File

@ -28,19 +28,33 @@ public class ItemDaoImpl implements ItemDao {
@Override
public List<CItemInfo> getItemFlowByUser(CItemParam param) throws Exception {
if (param == null) {
throw new IllegalArgumentException("param cannot be null");
}
String dbName = MongoName.getMongoDBName(param.getServerId());
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(param.getStartTime());
long startTime = date.getTime();
Date endDate = simpleDateFormat.parse(param.getEndTime());
long endTime = endDate.getTime();
Query query = new Query();
query.addCriteria(Criteria.where("uid").is(param.getUserId()));
query.addCriteria(Criteria.where("time").lte(String.valueOf(endTime)).gte(String.valueOf(startTime)));
query.limit(10000);
return mongoTemplate.find(query, CItemInfo.class, collectionName);
try {
Date startTimeDate = simpleDateFormat.parse(param.getStartTime());
long startTime = startTimeDate.getTime();
Date endTimeDate = simpleDateFormat.parse(param.getEndTime());
long endTime = endTimeDate.getTime();
int page = param.getPage(); // 当前页
int pageSize = 1000; // 假设已添加到CItemParam中每页文档数量
int skipValue = (page - 1) * pageSize;
Query query = new Query();
query.addCriteria(Criteria.where("uid").is(param.getUserId()));
query.addCriteria(Criteria.where("time").lte(String.valueOf(endTime)).gte(String.valueOf(startTime)));
query.skip(skipValue).limit(pageSize); // 合并计算
return mongoTemplate.find(query, CItemInfo.class, collectionName);
} catch (Exception e) {
throw new Exception("Time format error", e); // 包装为更通用的异常,或自定义异常
}
}
@Override

View File

@ -1,9 +1,12 @@
package com.jmfy.model;
import com.jmfy.utils.FileCacheUtils;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import java.util.Map;
@CompoundIndexes({@CompoundIndex(name = "uid_time_index", def = "{'uid': 1, 'time': 1}")})
public class CItemInfo {
@ -59,6 +62,14 @@ public class CItemInfo {
return type;
}
public String getTypeStr() {
if (type == 0){
return "增加";
}else {
return "减少";
}
}
public void setType(int type) {
this.type = type;
}
@ -75,6 +86,16 @@ public class CItemInfo {
return reason;
}
public String getReasonStr() {
Map<Integer, String> itemFlowReason = FileCacheUtils.itemFlowResson;
if (itemFlowReason.containsKey(reason)) {
return itemFlowReason.get(reason);
}
else {
return Integer.toString(reason);
}
}
public void setReason(int reason) {
this.reason = reason;
}
@ -83,6 +104,10 @@ public class CItemInfo {
return itemId;
}
public String getItemName() {
return FileCacheUtils.itemNameMap.getOrDefault(itemId,"未知道具");
}
public void setItemId(int itemId) {
this.itemId = itemId;
}

View File

@ -9,6 +9,7 @@ public class CItemParam {
private int type;
private int reason;
private int itemId;
private int page;
public int getItemId() {
return itemId;
@ -65,4 +66,12 @@ public class CItemParam {
public void setReason(int reason) {
this.reason = reason;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}

View File

@ -10,10 +10,12 @@ public class ItemFlowVo implements java.io.Serializable {
public String userLevel;
public String itemName ;
public int itemId;
public String itemName;
public String afterMoney;
public String count ;
public String count;
public String reason;
@ -54,4 +56,48 @@ public class ItemFlowVo implements java.io.Serializable {
public void setCount(String count) {
this.count = count;
}
public String getUserId() {
return userId;
}
public String getServerId() {
return serverId;
}
public String getTime() {
return time;
}
public String getUserLevel() {
return userLevel;
}
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
public String getItemName() {
return itemName;
}
public String getAfterMoney() {
return afterMoney;
}
public String getCount() {
return count;
}
public String getReason() {
return reason;
}
public String getAddOrReduce() {
return addOrReduce;
}
}

View File

@ -0,0 +1,22 @@
package com.jmfy.model.vo;
public class ItemNameVo implements java.io.Serializable {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -84,7 +84,7 @@
<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
<button class="btn btn-primary radius" type="submit" ><i class="Hui-iconfont">&#xe632;</i> 查询</button>
<p class="row cl" style="font-size: 16px">
tips: 因性能原因,日志只显示前10000条请尽量缩小查询时间范围
tips: 因性能原因,减少了每次查询的条数,请尽量缩小时间范围已减少查询误差
</p>
</div>
</div>

View File

@ -33,10 +33,12 @@
<div style="height: 30px"></div>
<div class="text-c">
<!--<input type="text" placeholder="物品名称" name="itemName" value="" class="input-text" style="width:120px">-->
<select name="itemId" style="width: 150px" th:id="itemId"><!--下拉列表-->
<option value="0" selected="selected">0.所有</option>
<option th:each="item:${itemNameMap}" th:value="${item.key}" th:text="${item.key}+.+${item.value}"></option>
</select>
<span class="select-box" style="width:250px">
<select name="itemId" th:id="itemId"><!--下拉列表-->
<option value="0" selected="selected">0.所有</option>
<option th:each="item:${itemNameMap}" th:value="${item.key}" th:text="${item.key}+.+${item.value}"></option>
</select>
</span>
<span class="select-box" style="width:150px">
<select class="select" id="type" size="1">
<option value="0" selected>获得</option>

View File

@ -0,0 +1,179 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8"/>
<meta name="renderer" content="webkit|ie-comp|ie-stand"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<!-- <![endif]&ndash;&gt;-->
<link rel="stylesheet" type="text/css" href="h-ui/css/H-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="h-ui.admin/css/H-ui.admin.css"/>
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
<link rel="stylesheet" type="text/css" href="h-ui.admin/skin/default/skin.css" id="skin"/>
<link rel="stylesheet" type="text/css" href="h-ui.admin/css/style.css"/>
<!-- IE6支持 -->
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
<script>DD_belatedPNG.fix('*');</script>
<title>玩家道具日志查询</title>
</head>
<body>
<nav class="breadcrumb">
<i class="Hui-iconfont">&#xe67f;</i> 首页
<span class="c-gray en">&gt;</span> 流水日志管理
<span class="c-gray en">&gt;</span> 流水日志查询
<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
href="javascript:location.replace(location.href);" title="刷新">
<i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container" style="text-align: center">
<h2><span style="color:red;">玩家道具日志查询</span></h2>
<div class="text-c">
<div style="text-align: left;">
<div th:id="itemNameMap" style="float: left;width: 230px;"></div>
<button class="btn btn-success radius" style="margin-left: 10px;height: 40px;line-height: 40px;" type="button" onclick="tableToExcel()">导出</button>
<button class="btn btn-secondary radius" style="margin-left: 10px;height: 40px;line-height: 40px;" type="button" onclick="nextPage()">下一批</button>
</div>
<div class="mt-20">
<table id="aa" class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
<thead>
<tr class="text-c">
<th>用户id</th>
<th>服务器ID</th>
<th>时间</th>
<th>用户等级</th>
<th>道具ID</th>
<th>道具名称</th>
<th>道具数量</th>
<th>物品存量</th>
<th>操作原因</th>
<th>增减</th>
</tr>
</thead>
<tbody>
<tr th:each="obj:${itemFlowVoList}">
<td th:text="${obj.userId}" style="text-align: center;"></td>
<td th:text="${obj.serverId}" style="text-align: center;"></td>
<td th:text="${obj.time}" style="text-align: center;"></td>
<td th:text="${obj.userLevel}" style="text-align: center;"></td>
<td th:text="${obj.itemId}" style="text-align: center;"></td>
<td th:text="${obj.itemName}" style="text-align: center;"></td>
<td th:text="${obj.count}" style="text-align: center;"></td>
<td th:text="${obj.afterMoney}" style="text-align: center;"></td>
<td th:text="${obj.reason}" style="text-align: center;"></td>
<td th:text="${obj.addOrReduce}" style="text-align: center;"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="h-ui.admin/js/H-ui.admin.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<!--多选框-->
<script src="../static/xmSelect/js/xm-select.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script th:inline="javascript">
$('.table-sort').dataTable({
"aaSorting": [[2, "esc"]],//默认第几个排序
"bStateSave": true,//状态保存
"pading": false,
"aoColumnDefs": [
{"orderable": false, "aTargets": [0,1,3,4,5,6,7,8]}// 不参与排序的列
]
});
var itemNameMap = xmSelect.render({
el: '#itemNameMap', // div的id值
template({name, value}){
return name + '<span style="position: absolute; right: 10px; color: #8799a3">'+value+'</span>'
},
// toolbar: { // 工具条【‘全选’,‘清空’】
// show: true, // 开启工具条
// showIcon: false, // 隐藏工具条的图标
// },
tips: '仅查询道具id使用不参与搜索', // 让默认值不是“请选择”,而是“选择校区”
filterable: true, // 开启搜索模式默认按照name进行搜索
height:'260px',
model: {
label: {
type: 'block',
block: {
//最大显示数量, 0:不限制
showCount: 1,
//是否显示删除图标
showIcon: true,
}
}
},
prop: {
name: 'name',
value: 'id',
},
data: function () {
let infos = [[${itemNameMap}]];
return infos;
},
});
// 属性名和对应中文名的映射
const headerMapping = {
// let str = "用户id,服务器ID,时间,用户等级,道具ID,道具名称,道具数量,物品存量,操作原因,增减\n";
userId: '用户id',
serverId: '服务器ID',
time: '时间',
userLevel: '用户等级',
itemId: '道具ID',
itemName: '道具名称',
afterMoney: '道具数量',
count: '物品存量',
reason: '操作原因',
addOrReduce: '增减',
};
function tableToExcel() {
let data = [[${itemFlowVoList}]];
// 转换数据,将属性名换成对应的中文名
const transformedData = data.map(item => {
const transformedItem = {};
for (const key in item) {
if (headerMapping.hasOwnProperty(key)) {
transformedItem[headerMapping[key]] = item[key];
}
}
return transformedItem;
});
// 创建一个工作表
const worksheet = XLSX.utils.json_to_sheet(transformedData);
// 创建一个工作簿
const workbook = XLSX.utils.book_new();
// 将工作表添加到工作簿
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// 生成 Excel 文件并触发下载
XLSX.writeFile(workbook, 'data.xlsx');
}
// 重启服务器列表
function nextPage() {
let paramvalue = [[${paramvalue}]];
let parse = JSON.parse(paramvalue);
let page = parse.page + 1;
window.location = "/findFlow?" + "startTime=" + parse.startTime + "&endTime=" + parse.endTime + "&serverId=" + parse.serverId + "&userId=" + parse.userId + "&page=" + page;
}
</script>
</body>
</html>