From 112dfb738ad0a740f821822b00996363ba9bc44a Mon Sep 17 00:00:00 2001 From: duhui Date: Mon, 13 Feb 2023 10:29:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=81=93=E5=85=B7=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jmfy/controller/GmController.java | 105 +++++++++++------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/jmfy/controller/GmController.java b/src/main/java/com/jmfy/controller/GmController.java index 7337b80..ed4c708 100644 --- a/src/main/java/com/jmfy/controller/GmController.java +++ b/src/main/java/com/jmfy/controller/GmController.java @@ -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>> 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> serverMap = map.getOrDefault(serverId, new HashMap<>()); + HashMap 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>> entry1 : map.entrySet()) { + HashMap> value = entry1.getValue(); + for (Map.Entry> 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 map){ + StringBuilder buffer = new StringBuilder(); + for (Map.Entry 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); } /**