删除道具脚本

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