删除道具脚本

master
duhui 2023-02-13 10:29:57 +08:00
parent 0337d272ee
commit 112dfb738a
1 changed files with 66 additions and 39 deletions

View File

@ -14,6 +14,7 @@ import com.jmfy.thrift.idl.Result;
import com.jmfy.utils.*; import com.jmfy.utils.*;
import config.SItemConfig; import config.SItemConfig;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -63,6 +64,12 @@ public class GmController {
return 0; return 0;
} }
//根据excel删除道具
if (cmd.equals("deleteItem0210")){
deleteItem0210();
return 0;
}
// 修改服务器状态 serverstatus#10001#-2 // 修改服务器状态 serverstatus#10001#-2
if (cmd.contains("serverstatus")) { if (cmd.contains("serverstatus")) {
String[] split = cmd.split("#"); String[] split = cmd.split("#");
@ -286,52 +293,72 @@ public class GmController {
} }
} }
private void createExcelToDownload(String url, HttpServletResponse response){ private void deleteItem0210(){
LOGGER.info("删除道具0209前端下载============开始");
FileInputStream ips = null;
ServletOutputStream out = null;
try { try {
//获取文件存放的路径 String osName = System.getProperty("os.name");
File file = new File(url); String path;
String fileName = file.getName(); if (Pattern.matches("Linux.*", osName)) {
//获取到文字 数据库里对应的附件名字加上老的文件名字filename 截取到后面的文件类型 例txt 组成一个新的文件名字newFileName path = "/data/jieling/removeitem.xls";
if(!file.exists()) } else {
{ path = "D:/Program Files (x86)/Quick/Downloads/removeitem.xls";
//如果文件不存在就跳出
LOGGER.error("文件不存在,路径错误:{}", url);
return;
} }
ips = new FileInputStream(file);
response.setContentType("multipart/form-data"); // 解析路径的file文件
//为文件重新设置名字,采用数据库内存储的文件名称 HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(path));
response.addHeader("Content-Disposition", "attachment;filename=" + fileName); // sheet
out = response.getOutputStream(); for (int i = 0; i < wb.getNumberOfSheets(); i++) {
//读取文件流 HSSFSheet sheet = wb.getSheetAt(i);
int len = 0; int rowNum = sheet.getLastRowNum();
byte[] buffer = new byte[1024 * 10];
while((len = ips.read(buffer)) != -1) HashMap<String, HashMap<String, HashMap<String, Long>>> map = new HashMap<>();
{ // 行
out.write(buffer, 0, len); for (int j = 2; j < rowNum; j++) {
// 第几行
HSSFRow row = sheet.getRow(j);
// 重要的列 0 1 4 6
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String serverId = row.getCell(0).getStringCellValue();
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
String uid = row.getCell(1).getStringCellValue();
row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
String itemId = row.getCell(4).getStringCellValue();
row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
Long itemNum = Long.parseLong(row.getCell(6).getStringCellValue());
HashMap<String, HashMap<String, Long>> serverMap = map.getOrDefault(serverId, new HashMap<>());
HashMap<String, Long> userMap = serverMap.getOrDefault(uid, new HashMap<>());
userMap.put(itemId,userMap.getOrDefault(itemId,0L)+itemNum);
serverMap.put(uid,userMap);
map.put(serverId,serverMap);
}
LOGGER.info("删除道具,区服:{},信息:{}",sheet.getSheetName(),map);
for (Map.Entry<String, HashMap<String, HashMap<String, Long>>> entry1 : map.entrySet()) {
HashMap<String, HashMap<String, Long>> value = entry1.getValue();
for (Map.Entry<String, HashMap<String, Long>> entry2 : value.entrySet()) {
String item = getRemoveReward(entry2.getValue());
String cmd = "general removeitem "+entry2.getKey()+" "+item;
LOGGER.info("删除道具,命令:{}",cmd);
// RPCClient.sendCmd(Integer.parseInt(entry1.getKey()), cmd);
LOGGER.info("删除道具,完成");
}
}
} }
out.flush(); } catch (IOException e) {
}
catch(Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
finally }
{
try private String getRemoveReward(HashMap<String, Long> map){
{ StringBuilder buffer = new StringBuilder();
out.close(); for (Map.Entry<String, Long> entry : map.entrySet()) {
ips.close(); if (entry.getKey().equals("16")){
} continue;
catch(IOException e)
{
System.out.println("关闭流出现异常");
e.printStackTrace();
} }
buffer.append(entry.getKey()).append("#").append(entry.getValue()).append("|");
} }
return buffer.substring(0,buffer.length()-1);
} }
/** /**