package com.jmfy.controller; import com.google.gson.Gson; import com.jmfy.dao.BanFuctionDao; import com.jmfy.dao.ServerInfoDao; import com.jmfy.dao.UserInfoDao; import com.jmfy.model.*; import com.jmfy.model.vo.RechargeInfo; import com.jmfy.redisProperties.RedisUserKey; import com.jmfy.thrift.idl.Result; import com.jmfy.utils.RPCClient; import com.jmfy.utils.RedisUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.*; import java.util.*; @Controller public class GmController { private static final Logger LOGGER = LoggerFactory.getLogger(UserInfoController.class); @Resource private ServerInfoDao serverInfoDao; @Resource private UserInfoDao userInfoDao; @Resource private BanFuctionDao banFuctionDao; @RequestMapping(value = "/sendGm", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int publishNotice(HttpServletRequest request) throws Exception { List allServerInfo = serverInfoDao.getAllServerInfo(); List serverList = new ArrayList<>(); for (ServerInfo serverInfo : allServerInfo) { serverList.add(serverInfo.getServer_id()); } String cmd = request.getParameter("content"); if(cmd.equals("recharge")){ // recharge(); return 0; } String serverId = request.getParameter("serverId"); String[] split = serverId.split(","); for (String str : split) { if (!serverList.contains(str)) { continue; } try { //TODO 分服 String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(str), String.class, -1); System.out.println(rpcString); if(null==rpcString){ throw new Exception("serverAddress not exist"); } String thriftIp = rpcString.split(":")[0]; System.out.println(thriftIp); String thriftPort = rpcString.split(":")[1]; System.out.println(thriftPort); if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) { return -1; } else { Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort); //异常或者错误 if (result.getResultCode() != 0) { System.out.println("===================发送gm返回异常:"+result.getResultMsg()); } } } catch (Exception e) { e.printStackTrace(); return 1; } } return 0; } @RequestMapping(value = "/addhero", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int addHero(@RequestBody HeroTemp heroTemp , HttpServletResponse response) throws Exception { String stringUid = heroTemp.getUserId(); for (String userId:stringUid.split("#")) { CUserInfo userInfo =null; try { if(userId!=null&&!userId.isEmpty()){ userInfo = userInfoDao.findUserInfoByUserId(Integer.parseInt(userId)); } }catch (Exception e){ throw new Exception("uid null"); } if (userInfo == null){ throw new Exception("userInfo null"); } WhiteList whiteList = userInfoDao.findWhiteListInfo(userInfo.getOpenId()); if (whiteList == null){ throw new Exception("not access"); } //TODO 分服 String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(userInfo.getServerid()), String.class, -1); if(null==rpcString){ throw new Exception("serverAddress not exist"); } String thriftIp = rpcString.split(":")[0]; String thriftPort = rpcString.split(":")[1]; if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) { return -1; } else { for (int i = 0; i < heroTemp.getHeroId().size(); i++) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("addhero ").append(userId) .append(" ").append(heroTemp.getHeroId().get(i)) .append(" ").append(heroTemp.getHeroStar().get(i)); LOGGER.info("start addHero uid=>{},reward=>{}",userId,stringBuilder.toString()); Result result = RPCClient.gmSend(stringBuilder.toString(), thriftIp, thriftPort); // 异常或者错误 if (result.getResultCode() != 0) { continue; }else { LOGGER.info("addHero uid=>{},reward=>{}",userId,stringBuilder.toString()); } } } } return 0; } @RequestMapping(value = "/addHeroPage", method = {RequestMethod.POST, RequestMethod.GET}) public String noticeInfos (HttpSession session, ModelMap map , HttpServletRequest request) throws Exception { return "addHero"; } //修复订单 public void fixOrder() { String osName = System.getProperty("os.name"); String filePath = ""; if (osName.matches("^(?i)Windows.*$")) {// Window 系统 filePath = "conf/delivery-server.log"; } else {// Linux 系统 filePath = "../config/delivery-server.log"; } Gson gson = new Gson(); String s1 = "{\"orderId\":\"21032914511376426677449527296\",\"delivery_time\":\"2021-03-29 16:17:46\",\"serverId\":91001,\"userId\":\"10048062\"}"; String s2 = "{\"orderId\":\"21032914511376426677449527296\",\"delivery_time\":\"2021-04-05 00:26:36\",\"serverId\":10154,\"userId\":\"10048062\",\"goodsId\":\"1\",\"amount\":\"600\"}"; try { RedisUtil redisUtil = RedisUtil.getInstence(); BufferedReader in = new BufferedReader(new FileReader(filePath)); String str; Map allOrder = new HashMap<>(); while ((str = in.readLine()) != null) { if(str.contains("consumerid")&&str.contains("consumername")){ System.out.println(str); String[] split1 = str.split("&"); // String[] split = str.split("consumerid=")[1].split("&consumername"); // if(!split[0].contains("_")){ // continue; // } // System.out.println(split[0]+"---"+split[1]); // String[] s = split[0].split("_"); CPayOrder cPayOrder = new CPayOrder(); String orderNo = ""; for(String split:split1){ if(split.contains("consumerid")){ if(!split.contains("_")){ break; } String[] s = split.split("=")[1].split("_"); cPayOrder.setUserId(s[0]); cPayOrder.setGoodsId(s[1]); } if(split.contains("mhtOrderAmt")){ cPayOrder.setAmount(split.split("=")[1]); } if(split.contains("orderNo")){ orderNo = split.split("=")[1]; cPayOrder.setOrderId(orderNo); } } Object o1 = redisUtil.get("C_PAYORDER:" + orderNo); if(o1==null){ System.out.println(orderNo+"找不到"); continue; }else{ System.out.println(orderNo+"find"); } String o = (String)o1; CPayOrder errorOrder = gson.fromJson(o, CPayOrder.class); cPayOrder.setServerId(errorOrder.getServerId()); cPayOrder.setDelivery_time(errorOrder.getDelivery_time()); if(cPayOrder.getUserId()!=null){ allOrder.put(orderNo,cPayOrder); } String date = cPayOrder.getDelivery_time().substring(0, 10); redisUtil.putMapEntry("C_PAYORDER_MAP",date,orderNo,cPayOrder,-1); redisUtil.set("C_PAYORDER:" + orderNo,gson.toJson(cPayOrder)); } } // System.out.println(str);/ } catch (IOException e) { e.printStackTrace(); } } // public void recharge() throws IOException { // String osName = System.getProperty("os.name"); // String filePath = ""; // Gson gson = new Gson(); // if (osName.matches("^(?i)Windows.*$")) {// Window 系统 // filePath = "conf/"; // } else {// Linux 系统 // filePath = "../config/"; // } // BufferedReader in = new BufferedReader(new FileReader(filePath+"rechargeImport.txt")); // BufferedWriter out = new BufferedWriter(new FileWriter(filePath+"recharge.json")); // String str; // while ((str = in.readLine()) != null) { // String[] s = str.split("\t"); // RechargeInfo rechargeInfo = new RechargeInfo(s[0], Double.valueOf(s[1]), 0); // String json = gson.toJson(rechargeInfo); // System.out.println(s[0]+"||"+s[1]); // out.write(json+"\n"); // } // in.close(); // out.close(); // } @RequestMapping(value = "/banFunction", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int banFunction(HttpServletRequest request) throws Exception{ String function = request.getParameter("function");// protocal/good String action = request.getParameter("action");// ban/opend String id = request.getParameter("id");// id ServerBanPro banDao = banFuctionDao.findUserInfo(); if(banDao == null ){ ServerBanPro serverBanPro = new ServerBanPro(); //serverBanPro.setId(1); serverBanPro.setBanProtoId(new ArrayList(Arrays.asList(1,2))); serverBanPro.setBanGoodList(new ArrayList<>()); banFuctionDao.addServerBanPro(serverBanPro); banDao = serverBanPro; } switch (function){ case "protocal": if(action.equals("ban")){ if(!banDao.getBanProtoId().contains(Integer.valueOf(id))){ banDao.getBanProtoId().add(Integer.valueOf(id)); banFuctionDao.updateServerBanPro(banDao); } }else if(action.equals("open")){ if(banDao.getBanProtoId().contains(Integer.valueOf(id))){ banDao.getBanProtoId().remove(Integer.valueOf(id)); banFuctionDao.updateServerBanPro(banDao); } } break; case "good": if(action.equals("ban")){ if(!banDao.getBanGoodList().contains(Integer.valueOf(id))){ banDao.getBanGoodList().add(Integer.valueOf(id)); banFuctionDao.updateServerBanPro(banDao); } }else if(action.equals("open")){ if(banDao.getBanGoodList().contains(Integer.valueOf(id))){ banDao.getBanGoodList().remove(Integer.valueOf(id)); banFuctionDao.updateServerBanPro(banDao); } } break; } return 0; } public static void main(String[] args) throws IOException { String osName = System.getProperty("os.name"); String filePath = ""; Gson gson = new Gson(); if (osName.matches("^(?i)Windows.*$")) {// Window 系统 filePath = "conf/"; } else {// Linux 系统 filePath = "../config/"; } BufferedReader in = new BufferedReader(new FileReader(filePath+"rank.txt")); String str; int i = 568; while ((str = in.readLine()) != null) { int value = Integer.valueOf(str); int i1 = value % 50; if(i1==16||i1==2||i1==38){ System.out.println(value+" "+i); } i--; } in.close(); } static class CPayOrder { private String orderId;//充值回调中的pOrderId private String delivery_time;//发货时间 private int serverId;// private String userId;//充值回调中的userId private String roleId; private String goodsId; private String cpOrderId;//原厂订单号,通常为google或者ios充值才有,充值回调中的remark private String recharge_type ; // private String amount;// 充值回调中的amount,单位为分 public String getOrderId() { return orderId; } public String getDelivery_time() { return delivery_time; } public int getServerId() { return serverId; } public String getUserId() { return userId; } public String getCpOrderId() { return cpOrderId; } public void setOrderId(String orderId) { this.orderId = orderId; } public void setDelivery_time(String delivery_time) { this.delivery_time = delivery_time; } public void setServerId(int serverId) { this.serverId = serverId; } public void setUserId(String userId) { this.userId = userId; } public void setCpOrderId(String cpOrderId) { this.cpOrderId = cpOrderId; } public String getAmount() { return amount; } public void setAmount(String amount) { this.amount = amount; } public String getRoleId() { return roleId; } public void setRoleId(String roleId) { this.roleId = roleId; } public String getGoodsId() { return goodsId; } public void setGoodsId(String goodsId) { this.goodsId = goodsId; } public String getRecharge_type() { return recharge_type; } public void setRecharge_type(String recharge_type) { this.recharge_type = recharge_type; } @Override public String toString() { return "CPayOrder{" + "orderId='" + orderId + '\'' + ", delivery_time='" + delivery_time + '\'' + ", userId='" + userId + '\'' + ", cpOrderId='" + cpOrderId + '\'' + ", amount='" + amount + '\'' + '}'; } } }