diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..563c143
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..63e9001
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..5a2f139
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..132404b
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..a6983df
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,75 @@
+
+
+ 4.0.0
+
+ org.example
+ InnGame
+ 1.0-SNAPSHOT
+ jar
+ InnGame
+
+ InnGame
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.0.RELEASE
+
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
+ com.alibaba
+ fastjson
+ 1.2.70
+
+
+ org.projectlombok
+ lombok
+
+
+ com.opencsv
+ opencsv
+ 4.6
+
+
+
+
+ 8
+ 8
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/qiwu/innGame/InnGameApplication.java b/src/main/java/com/qiwu/innGame/InnGameApplication.java
new file mode 100644
index 0000000..93e18fa
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/InnGameApplication.java
@@ -0,0 +1,17 @@
+package com.qiwu.innGame;
+
+import com.qiwu.innGame.common.cache.ExpireThread;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootConfiguration
+@SpringBootApplication
+public class InnGameApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(InnGameApplication.class, args);
+ ExpireThread expireThread = new ExpireThread();
+ Thread thread = new Thread(expireThread);
+ thread.start();
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/common/Constants.java b/src/main/java/com/qiwu/innGame/common/Constants.java
new file mode 100644
index 0000000..7187781
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/Constants.java
@@ -0,0 +1,76 @@
+package com.qiwu.innGame.common;
+
+public class Constants {
+
+ /**
+ * 玩家离线-0
+ */
+ public static final int OFFLINE = 0;
+ /**
+ * 玩家在线-1
+ */
+ public static final int ONLINE = 1;
+
+
+ /**
+ * 很少
+ */
+ public static final String FEW = "few";
+ /**
+ * 很多
+ */
+ public static final String LOT = "lot";
+
+
+ /**
+ * 请求的名称不存在
+ */
+ public static final int REQ_NON = -1;
+ /**
+ * 请求的名称随机
+ */
+ public static final int REQ_RANDOM = -2;
+ /**
+ * 请求的数量为"都", "统统", "全数", "所有", "全", "全部", "全都", "一起"之类
+ */
+ public static final int REQ_ALL = -3;
+ /**
+ * 请求的名称为首个、首位之类
+ */
+ public static final int REQ_FIRST = -4;
+ /**
+ * 请求的名称为中间
+ */
+ public static final int REQ_MIDDLE = -5;
+ /**
+ * 请求的名称为最后
+ */
+ public static final int REQ_LAST = -6;
+ /**
+ * 请求的名称为"其它/其他"
+ */
+ public static final Integer REQ_OTHER = -7;
+
+
+ /**
+ * 话术-旁白
+ */
+ public static final String SPEECH_ASIDE = "aside";
+ /**
+ * 话术-人物
+ */
+ public static final String SPEECH_PERSON = "person";
+
+
+
+
+ /**
+ * 不存在-0
+ */
+ public static final Integer NON = 0;
+ /**
+ * 不存在-0
+ */
+ public static final String NON_STR = "0";
+
+}
diff --git a/src/main/java/com/qiwu/innGame/common/InitSysServlet.java b/src/main/java/com/qiwu/innGame/common/InitSysServlet.java
new file mode 100644
index 0000000..d0773fb
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/InitSysServlet.java
@@ -0,0 +1,91 @@
+package com.qiwu.innGame.common;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.PlayerScoreDto;
+import com.qiwu.innGame.pojo.SpeechPojo;
+import com.qiwu.innGame.utils.FileUtil;
+import com.qiwu.innGame.utils.PersistenceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class InitSysServlet implements InitializingBean {
+ Logger log = LoggerFactory.getLogger(InitSysServlet.class);
+
+ @Value("${configFilePath}")
+ private String configFilePath;
+
+ @Value("${userFilePath}")
+ private String userFilePath;
+
+ @Value("${dataFilePath}")
+ private String dataFilePath;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ //--------------------加载配置目录下的所有话术----------------
+ log.info("开始加载话术");
+ Map speechMap = FileUtil.loadSpeech(configFilePath);
+ TimingAcquisition.speechMap.putAll(speechMap);
+ log.info("话术加载完成");
+
+ //-----------------缓存系列的配置信息------------------
+ log.info("开始加载配置信息");
+ List sensitiveWordList = FileUtil.loadSensitiveWord(configFilePath);
+ TimingAcquisition.sensitiveWordList.addAll(sensitiveWordList);
+ log.info("配置信息加载完成");
+
+ //-----------------缓存玩家数据------------------
+ log.info("开始加载玩家数据");
+ //从yml配置文件中取出存放玩家数据的地址
+ File file = new File(userFilePath);
+ //一级目录
+ File[] file1List = file.listFiles();
+ if (!StringUtils.isEmpty(file1List)) {
+ for (File file1 : file1List) {
+ //二级目录
+ File[] file2List = file1.listFiles();
+ if (!StringUtils.isEmpty(file2List)) {
+ for (File file2 : file2List) {
+ //三级目录
+ File[] file3List = file2.listFiles();
+ if (!StringUtils.isEmpty(file3List)) {
+ for (File file3 : file3List) {
+ //四级目录
+ File[] file4List = file3.listFiles();
+ if (!StringUtils.isEmpty(file4List)) {
+ for (File file4 : file4List) {
+ //用户uid目录
+ String uid = file4.getName().replace(".json", "");
+ //保存所有玩家的uid
+ TimingAcquisition.uidList.add(uid);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ log.info("玩家数据加载完成");
+
+ //-----------------缓存排行榜数据------------------
+ log.info("开始加载排行榜");
+ String rankingStr = PersistenceUtil.readJsonFile(dataFilePath, "playerRanking.json");
+ List rankingList = JSON.parseObject(rankingStr, new TypeReference>(){});
+ if (!StringUtils.isEmpty(rankingList)) {
+ TimingAcquisition.playerRanking.addAll(rankingList);
+ }
+ log.info("排行榜加载完成");
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/common/TimingAcquisition.java b/src/main/java/com/qiwu/innGame/common/TimingAcquisition.java
new file mode 100644
index 0000000..6eecc88
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/TimingAcquisition.java
@@ -0,0 +1,39 @@
+package com.qiwu.innGame.common;
+
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.PlayerScoreDto;
+import com.qiwu.innGame.pojo.SpeechPojo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Component
+public class TimingAcquisition {
+ static Logger log = LoggerFactory.getLogger(TimingAcquisition.class);
+
+ /**
+ * 玩家信息
+ */
+ public volatile static Map playerInfoMap = new ConcurrentHashMap<>();
+ /**
+ * 所有在线玩家的uid数组。用于是否加载玩家数据的判断
+ */
+ public volatile static List uidList = new ArrayList<>();
+ /**
+ * 排行榜前100名
+ */
+ public volatile static List playerRanking = new ArrayList<>();
+ /**
+ * 话术
+ */
+ public volatile static Map speechMap = new ConcurrentHashMap<>();
+ /**
+ * 敏感词汇
+ */
+ public volatile static List sensitiveWordList = new ArrayList<>();
+}
diff --git a/src/main/java/com/qiwu/innGame/common/cache/CacheGlobal.java b/src/main/java/com/qiwu/innGame/common/cache/CacheGlobal.java
new file mode 100644
index 0000000..c47d116
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/cache/CacheGlobal.java
@@ -0,0 +1,11 @@
+package com.qiwu.innGame.common.cache;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+public class CacheGlobal {
+ /**
+ * cache全局缓存对象
+ * */
+ public volatile static ConcurrentMap concurrentMap = new ConcurrentHashMap<>();
+}
diff --git a/src/main/java/com/qiwu/innGame/common/cache/ExpireThread.java b/src/main/java/com/qiwu/innGame/common/cache/ExpireThread.java
new file mode 100644
index 0000000..6afbc21
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/cache/ExpireThread.java
@@ -0,0 +1,65 @@
+package com.qiwu.innGame.common.cache;
+
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.utils.PlayerUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 过期缓存检测线程
+ * */
+@EnableAsync
+@Component
+public class ExpireThread implements Runnable{
+ Logger log = LoggerFactory.getLogger(ExpireThread.class);
+ //用户数据路径
+ public static String userFilePath;
+ @Value("${userFilePath}")
+ public void setUserFilePath(String userFilePath) {
+ ExpireThread.userFilePath = userFilePath;
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ //每60秒检测一次
+ TimeUnit.SECONDS.sleep(60);
+ expireCache();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ /**
+ * 清除全局缓存对象中过期缓存
+ */
+ public void expireCache() throws IOException {
+ for (String key : CacheGlobal.concurrentMap.keySet()) {
+ MyCache myCache = CacheGlobal.concurrentMap.get(key);
+ long timeoutTime = System.currentTimeMillis() - myCache.getWriteTime();
+ //未过期
+ if (timeoutTime < myCache.getExpireTime()) {
+ continue;
+ }
+ //规定时间内玩家无操作默认下线
+ if (key.contains("%#%online%#%")) {
+ String uid = key.replace("%#%online%#%", "");
+ PlayerInfoDto player = TimingAcquisition.playerInfoMap.get(uid);
+ if (!StringUtils.isEmpty(player)) {
+ PlayerUtil.offLine(uid);
+ }
+ }
+ //清除过期缓存
+ CacheGlobal.concurrentMap.remove(key);
+ }
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/common/cache/MyCache.java b/src/main/java/com/qiwu/innGame/common/cache/MyCache.java
new file mode 100644
index 0000000..5801205
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/common/cache/MyCache.java
@@ -0,0 +1,36 @@
+package com.qiwu.innGame.common.cache;
+
+import lombok.Data;
+
+@Data
+public class MyCache implements Comparable{
+ /**
+ * 缓存键
+ * */
+ private Object key;
+ /**
+ * 缓存值
+ * */
+ private Object value;
+ /**
+ * 最后访问时间
+ * */
+ private long lastTime;
+ /**
+ * 创建时间
+ * */
+ private long writeTime;
+ /**
+ * 存活时间
+ * */
+ private long expireTime;
+ /**
+ * 命中次数
+ * */
+ private Integer hitCount;
+
+ @Override
+ public int compareTo(MyCache mycache) {
+ return hitCount.compareTo(mycache.hitCount);
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/controller/CommonController.java b/src/main/java/com/qiwu/innGame/controller/CommonController.java
new file mode 100644
index 0000000..9c1d82b
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/controller/CommonController.java
@@ -0,0 +1,100 @@
+package com.qiwu.innGame.controller;
+
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultResponse;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+import com.qiwu.innGame.server.farm.impl.FarmServiceImpl;
+import com.qiwu.innGame.server.inn.impl.InnServiceImpl;
+import com.qiwu.innGame.server.login.impl.LoginServiceImpl;
+import com.qiwu.innGame.utils.DataTrimUtil;
+import com.qiwu.innGame.utils.RequestConversionUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.ParseException;
+
+@RestController
+@RequestMapping("/innGame")
+public class CommonController {
+ Logger log = LoggerFactory.getLogger(CommonController.class);
+
+ @Value("${offlineTime}")
+ private String offlineTime;
+
+ @Autowired
+ private LoginServiceImpl loginService;
+
+ @Autowired
+ private FarmServiceImpl farmService;
+
+ @Autowired
+ private InnServiceImpl innService;
+
+ @PostMapping(value = "/farm", produces = "application/json;charset=UTF-8")
+ public CommonResult ask(@RequestBody CommonRequest commonRequest) throws ParseException {
+ log.info(commonRequest.getUid() + "当前操作的原始请求参数:" + commonRequest.getVars() + ",原始话语:" + commonRequest.getOriginText());
+ CommonResult result = null;
+ String uid = commonRequest.getUid();
+ if (StringUtils.isEmpty(uid)) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+ resultResponse.set反馈ID(100001);
+ resultResponse.set反馈文本("【旁白@正常】未提供uid,无法操作。");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ boolean login = false;
+ //玩家已经存在
+ if (TimingAcquisition.uidList.contains(uid)) {
+ //玩家已经下线,重新加载
+ if (StringUtils.isEmpty(TimingAcquisition.playerInfoMap.get(uid))) {
+ loginService.loadPlayerData(commonRequest);
+ login = true;
+ }
+ } else {
+ //玩家第一次登录
+ if (StringUtils.isEmpty(TimingAcquisition.playerInfoMap.get(uid))) {
+ loginService.login(commonRequest);
+ login = true;
+ }
+ }
+ //请求参数转换
+ OperationRequest operationReq = RequestConversionUtil.request2Operation(commonRequest);
+ //玩家操作后,修改在线状态和延长下线时间
+ if (!login && !StringUtils.isEmpty(uid)) {
+ DataTrimUtil.AdjustStatus(commonRequest.getUid(), offlineTime);
+ }
+ String operateName = commonRequest.getVars().get操作名();
+ log.info(uid + "开始执行操作:【" + operateName + "】, 请求参数:" + operationReq);
+ switch (operateName) {
+ case "农场操作":
+ result = farmService.operate(operationReq);
+ break;
+ case "客栈操作":
+ result = innService.operate(operationReq);
+ break;
+ }
+ log.info(uid + "已完成操作:【" + operateName + "】");
+ return DataTrimUtil.AdjustParams(uid, result);
+ }
+
+ @GetMapping(value = "/addWord", produces = "application/json;charset=UTF-8")
+ public CommonResult addWord(@RequestParam("word") String word) throws ParseException {
+ return innService.addWord(word);
+ }
+ @GetMapping(value = "/deleteWord", produces = "application/json;charset=UTF-8")
+ public CommonResult deleteWord(@RequestParam("word") String word) throws ParseException {
+ return innService.deleteWord(word);
+ }
+ @GetMapping(value = "/checkRanking", produces = "application/json;charset=UTF-8")
+ public CommonResult checkRanking() throws ParseException {
+ return innService.checkRanking();
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/NurseryDtp.java b/src/main/java/com/qiwu/innGame/dto/NurseryDtp.java
new file mode 100644
index 0000000..34d6b9f
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/NurseryDtp.java
@@ -0,0 +1,19 @@
+package com.qiwu.innGame.dto;
+
+import lombok.Data;
+
+@Data
+public class NurseryDtp {
+ /**
+ * 花圃植物
+ */
+ private Integer plantId;
+ /**
+ * 植物种植时间
+ */
+ private String plantTime;
+ /**
+ * 植物成熟时间
+ */
+ private String matureTime;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/PlayerInfoDto.java b/src/main/java/com/qiwu/innGame/dto/PlayerInfoDto.java
new file mode 100644
index 0000000..fcb619b
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/PlayerInfoDto.java
@@ -0,0 +1,52 @@
+package com.qiwu.innGame.dto;
+
+import com.qiwu.innGame.common.Constants;
+import lombok.Data;
+
+@Data
+public class PlayerInfoDto {
+ /**
+ * 玩家uid
+ */
+ private String uid;
+ /**
+ * 玩家昵称
+ */
+ private String name;
+ /**
+ * 菜地
+ */
+ private int[] fields = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ /**
+ * 空闲菜地数量
+ */
+ private int fieldFree = 10;
+ /**
+ * 鱼塘
+ */
+ private int[] ponds = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ /**
+ * 空闲鱼塘数量
+ */
+ private int pondFree = 10;
+ /**
+ * 综合评分
+ */
+ private int score;
+ /**
+ * 排名
+ */
+ private int rank = 0;
+ /**
+ * 玩家在线状态
+ */
+ private Integer status = Constants.OFFLINE;
+ /**
+ * 玩家上线时间
+ */
+ private String onlineTime;
+ /**
+ * 玩家下线时间
+ */
+ private String offlineTime;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/PlayerScoreDto.java b/src/main/java/com/qiwu/innGame/dto/PlayerScoreDto.java
new file mode 100644
index 0000000..59f483f
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/PlayerScoreDto.java
@@ -0,0 +1,27 @@
+package com.qiwu.innGame.dto;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class PlayerScoreDto {
+ /**
+ * uid
+ */
+ private String uid;
+ /**
+ * 昵称
+ */
+ private String name;
+ /**
+ * 综合评分
+ */
+ private int score;
+
+ public PlayerScoreDto(String uid, String name, Integer score) {
+ this.uid = uid;
+ this.name = name;
+ this.score = score;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/ReplyDto.java b/src/main/java/com/qiwu/innGame/dto/ReplyDto.java
new file mode 100644
index 0000000..30fbf70
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/ReplyDto.java
@@ -0,0 +1,22 @@
+package com.qiwu.innGame.dto;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class ReplyDto {
+ /**
+ * 排行榜
+ */
+ private List playerRanking;
+ /**
+ * 当前页数
+ */
+ private int page = 1;
+ /**
+ * 姓名
+ */
+ private String name;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/request/CallRequest.java b/src/main/java/com/qiwu/innGame/dto/request/CallRequest.java
new file mode 100644
index 0000000..bac5756
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/request/CallRequest.java
@@ -0,0 +1,63 @@
+package com.qiwu.innGame.dto.request;
+
+import lombok.Data;
+
+@Data
+public class CallRequest {
+ /**
+ * 操作指令:查看,种植,收取,取消等
+ */
+ private String 操作名;
+ /**
+ * 方法编号
+ */
+ private Integer 方法编号;
+ /**
+ * 种子数量
+ */
+ private Integer 种子数量;
+ /**
+ * 鱼苗数量
+ */
+ private Integer 鱼苗数量;
+ /**
+ * 天数
+ */
+ private Integer 天数;
+ /**
+ * 客栈金币
+ */
+ private Integer 客栈金币;
+ /**
+ * 综合评分
+ */
+ private Integer 综合评分;
+ /**
+ * 上传昵称
+ */
+ private String 上传昵称;
+ /**
+ * 初始人缘
+ */
+ private Integer 初始人缘;
+ /**
+ * 初始魅力
+ */
+ private Integer 初始魅力;
+ /**
+ * 初始自信
+ */
+ private Integer 初始自信;
+ /**
+ * 掌柜生命值
+ */
+ private Integer 掌柜生命值;
+ /**
+ * 掌柜修为
+ */
+ private Integer 掌柜修为;
+ /**
+ * 初始掌柜技能点
+ */
+ private Integer 初始掌柜技能点;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/request/CommonRequest.java b/src/main/java/com/qiwu/innGame/dto/request/CommonRequest.java
new file mode 100644
index 0000000..4db5f17
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/request/CommonRequest.java
@@ -0,0 +1,35 @@
+package com.qiwu.innGame.dto.request;
+
+import lombok.Data;
+
+@Data
+public class CommonRequest {
+ /**
+ * 对话标识
+ */
+ private String chatKey;
+ /**
+ * 对话标识
+ */
+ private String channelId;
+ /**
+ * 用户唯一ID
+ */
+ private String uid;
+ /**
+ * 预处理之后的用户话语
+ */
+ private String queryText;
+ /**
+ * 用户原始话语
+ */
+ private String originText;
+ /**
+ * bot帐号
+ */
+ private String botAccount;
+ /**
+ * bot帐号
+ */
+ private CallRequest vars;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/request/OperationRequest.java b/src/main/java/com/qiwu/innGame/dto/request/OperationRequest.java
new file mode 100644
index 0000000..f01e0ff
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/request/OperationRequest.java
@@ -0,0 +1,71 @@
+package com.qiwu.innGame.dto.request;
+
+import lombok.Data;
+
+@Data
+public class OperationRequest {
+ /**
+ * 用户唯一ID
+ */
+ private String uid;
+ /**
+ * 操作名
+ */
+ private String operate;
+ /**
+ * 操作标签
+ */
+ private int operateLabel;
+ /**
+ * 方法编号
+ */
+ private Integer methodId;
+ /**
+ * 种子数量
+ */
+ private Integer seedNum = 1;
+ /**
+ * 鱼苗数量
+ */
+ private Integer fishNum = 1;
+ /**
+ * 天数
+ */
+ private Integer days;
+ /**
+ * 客栈金币
+ */
+ private Integer money;
+ /**
+ * 综合评分
+ */
+ private Integer score;
+ /**
+ * 昵称
+ */
+ private String nickName;
+ /**
+ * 初始人缘
+ */
+ private Integer popularity;
+ /**
+ * 初始魅力
+ */
+ private Integer charm;
+ /**
+ * 初始自信
+ */
+ private Integer confident;
+ /**
+ * 掌柜生命值
+ */
+ private Integer life;
+ /**
+ * 掌柜修为
+ */
+ private Integer cultivation;
+ /**
+ * 初始掌柜技能点
+ */
+ private Integer skill;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/CallResponse.java b/src/main/java/com/qiwu/innGame/dto/response/CallResponse.java
new file mode 100644
index 0000000..1d60a42
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/CallResponse.java
@@ -0,0 +1,23 @@
+package com.qiwu.innGame.dto.response;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class CallResponse implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 返回状态码
+ */
+ private Integer code;
+ /**
+ * 返回信息
+ */
+ private String message;
+ /**
+ * 返回内容
+ */
+ private String data;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/CommonResponse.java b/src/main/java/com/qiwu/innGame/dto/response/CommonResponse.java
new file mode 100644
index 0000000..d46cba9
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/CommonResponse.java
@@ -0,0 +1,22 @@
+package com.qiwu.innGame.dto.response;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class CommonResponse implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /**
+ * 返回码
+ */
+ private int code;
+ /**
+ * 返回说明
+ */
+ private String msg;
+ /**
+ * 返回数据
+ * */
+ private ResultVarsResponse data;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/CommonResult.java b/src/main/java/com/qiwu/innGame/dto/response/CommonResult.java
new file mode 100755
index 0000000..3dfb9dd
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/CommonResult.java
@@ -0,0 +1,123 @@
+package com.qiwu.innGame.dto.response;
+
+/**
+ * 通用返回对象
+ */
+public class CommonResult {
+ private long code;
+ private String message;
+ private T data;
+
+ protected CommonResult() {
+ }
+
+ protected CommonResult(long code, String message, T data) {
+ this.code = code;
+ this.message = message;
+ this.data = data;
+ }
+
+ /**
+ * 成功返回结果
+ *
+ * @param data 获取的数据
+ */
+ public static CommonResult success(T data) {
+ return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
+ }
+
+ /**
+ * 成功返回结果
+ *
+ * @param data 获取的数据
+ * @param message 提示信息
+ */
+ public static CommonResult success(T data, String message) {
+ return new CommonResult(ResultCode.SUCCESS.getCode(), message, data);
+ }
+
+ /**
+ * 失败返回结果
+ * @param errorCode 错误码
+ */
+ public static CommonResult failed(IErrorCode errorCode) {
+ return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null);
+ }
+
+ /**
+ * 失败返回结果
+ * @param errorCode 错误码
+ * @param message 错误信息
+ */
+ public static CommonResult failed(IErrorCode errorCode,String message) {
+ return new CommonResult(errorCode.getCode(), message, null);
+ }
+
+ /**
+ * 失败返回结果
+ * @param message 提示信息
+ */
+ public static CommonResult failed(String message) {
+ return new CommonResult(ResultCode.FAILED.getCode(), message, null);
+ }
+
+ /**
+ * 失败返回结果
+ */
+ public static CommonResult failed() {
+ return failed(ResultCode.FAILED);
+ }
+
+ /**
+ * 参数验证失败返回结果
+ */
+ public static CommonResult validateFailed() {
+ return failed(ResultCode.VALIDATE_FAILED);
+ }
+
+ /**
+ * 参数验证失败返回结果
+ * @param message 提示信息
+ */
+ public static CommonResult validateFailed(String message) {
+ return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null);
+ }
+
+ /**
+ * 未登录返回结果
+ */
+ public static CommonResult unauthorized(T data) {
+ return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
+ }
+
+ /**
+ * 未授权返回结果
+ */
+ public static CommonResult forbidden(T data) {
+ return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
+ }
+
+ public long getCode() {
+ return code;
+ }
+
+ public void setCode(long code) {
+ this.code = code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/IErrorCode.java b/src/main/java/com/qiwu/innGame/dto/response/IErrorCode.java
new file mode 100755
index 0000000..cf594f2
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/IErrorCode.java
@@ -0,0 +1,10 @@
+package com.qiwu.innGame.dto.response;
+
+/**
+ * 封装API的错误码
+ */
+public interface IErrorCode {
+ long getCode();
+
+ String getMessage();
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/ResultCode.java b/src/main/java/com/qiwu/innGame/dto/response/ResultCode.java
new file mode 100755
index 0000000..fa17aa5
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/ResultCode.java
@@ -0,0 +1,27 @@
+package com.qiwu.innGame.dto.response;
+
+/**
+ * 枚举了一些常用API操作码
+ */
+public enum ResultCode implements IErrorCode {
+ SUCCESS(1, "成功"),
+ FAILED(500, "操作失败"),
+ VALIDATE_FAILED(404, "参数检验失败"),
+ UNAUTHORIZED(401, "暂未登录或token已经过期"),
+ FORBIDDEN(403, "没有相关权限");
+ private long code;
+ private String message;
+
+ private ResultCode(long code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public long getCode() {
+ return code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/ResultResponse.java b/src/main/java/com/qiwu/innGame/dto/response/ResultResponse.java
new file mode 100644
index 0000000..fe8352e
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/ResultResponse.java
@@ -0,0 +1,47 @@
+package com.qiwu.innGame.dto.response;
+
+import lombok.Data;
+
+@Data
+public class ResultResponse {
+ /**
+ * 反馈ID即编号
+ */
+ private int 反馈ID;
+ /**
+ * 反馈文本
+ */
+ private String 反馈文本;
+ /**
+ * 后台附加返回,bot二次确认需要的参数
+ */
+ private String 后台附加返回;
+ /**
+ * 客栈金币
+ */
+ private Integer 客栈金币;
+ /**
+ * 初始人缘
+ */
+ private Integer 初始人缘;
+ /**
+ * 初始魅力
+ */
+ private Integer 初始魅力;
+ /**
+ * 初始自信
+ */
+ private Integer 初始自信;
+ /**
+ * 掌柜生命值
+ */
+ private Integer 掌柜生命值;
+ /**
+ * 掌柜修为
+ */
+ private Integer 掌柜修为;
+ /**
+ * 初始掌柜技能点
+ */
+ private Integer 初始掌柜技能点;
+}
diff --git a/src/main/java/com/qiwu/innGame/dto/response/ResultVarsResponse.java b/src/main/java/com/qiwu/innGame/dto/response/ResultVarsResponse.java
new file mode 100644
index 0000000..d26544b
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/dto/response/ResultVarsResponse.java
@@ -0,0 +1,19 @@
+package com.qiwu.innGame.dto.response;
+
+import lombok.Data;
+
+@Data
+public class ResultVarsResponse {
+ /**
+ * 返回变量集合
+ */
+ private ResultResponse vars;
+ /**
+ * 返回组属性集合
+ */
+ private ResultResponse groupVars;
+ /**
+ * 返回组属性集合
+ */
+ private ResultResponse botPostData;
+}
diff --git a/src/main/java/com/qiwu/innGame/pojo/RankingPojo.java b/src/main/java/com/qiwu/innGame/pojo/RankingPojo.java
new file mode 100644
index 0000000..8f36395
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/pojo/RankingPojo.java
@@ -0,0 +1,16 @@
+package com.qiwu.innGame.pojo;
+
+import com.opencsv.bean.CsvBindByName;
+import lombok.Data;
+
+@Data
+public class RankingPojo {
+ @CsvBindByName(column = "uid")
+ private String uid;
+
+ @CsvBindByName(column = "姓名")
+ private String name;
+
+ @CsvBindByName(column = "分数")
+ private Integer score;
+}
diff --git a/src/main/java/com/qiwu/innGame/pojo/SensitiveWordPojo.java b/src/main/java/com/qiwu/innGame/pojo/SensitiveWordPojo.java
new file mode 100644
index 0000000..5ea7bc6
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/pojo/SensitiveWordPojo.java
@@ -0,0 +1,10 @@
+package com.qiwu.innGame.pojo;
+
+import com.opencsv.bean.CsvBindByName;
+import lombok.Data;
+
+@Data
+public class SensitiveWordPojo {
+ @CsvBindByName(column = "敏感词汇")
+ private String word;
+}
diff --git a/src/main/java/com/qiwu/innGame/pojo/SpeechPojo.java b/src/main/java/com/qiwu/innGame/pojo/SpeechPojo.java
new file mode 100644
index 0000000..290232a
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/pojo/SpeechPojo.java
@@ -0,0 +1,18 @@
+package com.qiwu.innGame.pojo;
+
+import com.opencsv.bean.CsvBindByName;
+import lombok.Data;
+
+@Data
+public class SpeechPojo {
+ /**
+ * 植物id
+ */
+ @CsvBindByName(column = "反馈ID")
+ private Integer feedId;
+ /**
+ * 植物id
+ */
+ @CsvBindByName(column = "反馈文本")
+ private String text;
+}
diff --git a/src/main/java/com/qiwu/innGame/server/farm/FarmService.java b/src/main/java/com/qiwu/innGame/server/farm/FarmService.java
new file mode 100644
index 0000000..ea89c81
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/farm/FarmService.java
@@ -0,0 +1,15 @@
+package com.qiwu.innGame.server.farm;
+
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+
+public interface FarmService {
+ /**
+ * 农场操作
+ * @param operationReq
+ * @return
+ */
+ CommonResult operate(OperationRequest operationReq);
+}
diff --git a/src/main/java/com/qiwu/innGame/server/farm/impl/FarmServiceImpl.java b/src/main/java/com/qiwu/innGame/server/farm/impl/FarmServiceImpl.java
new file mode 100644
index 0000000..fc0ee6b
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/farm/impl/FarmServiceImpl.java
@@ -0,0 +1,310 @@
+package com.qiwu.innGame.server.farm.impl;
+
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultResponse;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+import com.qiwu.innGame.server.farm.FarmService;
+import com.qiwu.innGame.utils.PlayerUtil;
+import com.qiwu.innGame.utils.SpeechUtil;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@Service
+public class FarmServiceImpl implements FarmService {
+ @Override
+ public CommonResult operate(OperationRequest operationReq) {
+ int methodId = operationReq.getMethodId();
+ if (methodId == 1001) {
+ return plant(operationReq);
+ }
+ if (methodId == 1002) {
+ return putFish(operationReq);
+ }
+ if (methodId == 1003) {
+ return harvest(operationReq);
+ }
+ if (methodId == 1004) {
+ return fishing(operationReq);
+ }
+ return null;
+ }
+
+ /**
+ * 1001:种植
+ */
+ public CommonResult plant(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ Integer seedNum = operationReq.getSeedNum(); //种子数量
+ Integer days = operationReq.getDays(); //当前天数
+ Integer money = operationReq.getMoney();//客栈金币
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ //菜地
+ int[] fields = playerInfo.getFields();
+ //菜地空闲数量
+ Integer fieldFree = playerInfo.getFieldFree();
+ //没有空闲菜地
+ if (fieldFree == 0) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100103);
+ resultResponse.set反馈ID(100103);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ boolean flag = false;
+ //还有空闲菜地
+ if (seedNum > fieldFree) {
+ seedNum = fieldFree;
+ flag = true;
+ }
+ int num = money / 100;
+ if (seedNum > num) {
+ seedNum = num;
+ }
+ int k = 0; //过滤之前已种植的菜地
+ for (int i = 0; i < seedNum; i++) {
+ //记录空闲菜地种植时间
+ for (int j = k; j < fields.length; j++) {
+ k = j + 1;
+ if (fields[j] == 0) {
+ fields[j] = days;
+ break;
+ }
+ }
+ }
+ //更新空闲鱼塘数量
+ playerInfo.setFieldFree(fieldFree - seedNum);
+ String text = "";
+ //种子数量>空地数量
+ if (flag) {
+ //获取对应话术
+ text = SpeechUtil.getSpeech(100102);
+ resultResponse.set反馈ID(100102);
+ } else {
+ //获取对应话术
+ text = SpeechUtil.getSpeech(100101);
+ resultResponse.set反馈ID(100101);
+ }
+ resultResponse.set反馈文本(text);
+ resultResponse.set客栈金币(money - 100 * seedNum);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 1002:放鱼
+ */
+ public CommonResult putFish(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ Integer fishNum = operationReq.getFishNum(); //鱼苗数量
+ Integer days = operationReq.getDays(); //当前天数
+ Integer money = operationReq.getMoney(); // 客栈金币
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ //鱼塘
+ int[] ponds = playerInfo.getPonds();
+ //鱼塘空闲数量
+ Integer pondFree = playerInfo.getPondFree();
+ //没有空闲鱼塘
+ if (pondFree == 0) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100203);
+ resultResponse.set反馈ID(100203);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ boolean flag = false;
+ //还有空闲鱼塘
+ if (fishNum > pondFree) {
+ fishNum = pondFree;
+ flag = true;
+ }
+ int num = money / 100;
+ if (fishNum > num) {
+ fishNum = num;
+ }
+ int k = 0; //过滤之前已放鱼的鱼塘
+ for (int i = 0; i < fishNum; i++) {
+ //记录空闲鱼塘放鱼时间
+ for (int j = k; j < ponds.length; j++) {
+ k = j + 1;
+ if (ponds[j] == 0) {
+ ponds[j] = days;
+ break;
+ }
+ }
+ }
+ //更新空闲鱼塘数量
+ playerInfo.setPondFree(pondFree - fishNum);
+ String text = "";
+ //鱼苗数量>鱼塘空闲数量
+ if (flag) {
+ //获取对应话术
+ text = SpeechUtil.getSpeech(100202);
+ resultResponse.set反馈ID(100202);
+ } else {
+ //获取对应话术
+ text = SpeechUtil.getSpeech(100201);
+ resultResponse.set反馈ID(100201);
+ }
+ resultResponse.set反馈文本(text);
+ resultResponse.set客栈金币(money - 200 * fishNum);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 1003:收取果实
+ */
+ public CommonResult harvest(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ Integer days = operationReq.getDays(); //当前天数
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ //菜地
+ int[] fields = playerInfo.getFields();
+ int count = 0;
+ int free = 0;
+ for (int i = 0; i < fields.length; i++) {
+ if (fields[i] == 0) {
+ free++;
+ } else {
+ if (days - fields[i] >= 2) {
+ count++;
+ fields[i] = 0;
+ }
+ }
+ }
+ //没有种植菜
+ if (free == fields.length) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100303);
+ resultResponse.set反馈ID(100303);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //没有可以收取的果实
+ if (count == 0) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100302);
+ resultResponse.set反馈ID(100302);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //更新空闲菜地数量
+ playerInfo.setFieldFree(playerInfo.getFieldFree() + count);
+ StringBuilder addText = new StringBuilder();
+ List skillList = Arrays.asList("掌柜生命值", "掌柜修为", "初始掌柜技能点");
+ int[] totals = new int[]{0, 0 , 0};
+ for (int i = 0; i < count; i++) {
+ int random = PlayerUtil.getRandomNum(0, skillList.size());
+ totals[random] = totals[random] + 2;
+ }
+ for (int i = 0; i < totals.length; i++) {
+ if (totals[i] != 0) {
+ addText.append(skillList.get(i)).append("提升").append(totals[i]).append("点、");
+ }
+ }
+ if (addText.length() != 0) {
+ addText.deleteCharAt(addText.length() - 1);
+ }
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100301);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf(count), addText.toString(), String.valueOf(playerInfo.getFieldFree()));
+ resultResponse.set反馈ID(100301);
+ resultResponse.set反馈文本(text);
+ resultResponse.set掌柜生命值(operationReq.getLife() + totals[0]);
+ resultResponse.set掌柜修为(operationReq.getCultivation() + totals[1]);
+ resultResponse.set初始掌柜技能点(operationReq.getSkill() + totals[2]);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 1004:收网
+ */
+ public CommonResult fishing(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ Integer days = operationReq.getDays(); //当前天数
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ //鱼塘
+ int[] ponds = playerInfo.getPonds();
+ int count = 0;
+ int free = 0;
+ for (int i = 0; i < ponds.length; i++) {
+ if (ponds[i] == 0) {
+ free++;
+ } else {
+ if (days - ponds[i] >= 2) {
+ count++;
+ ponds[i] = 0;
+ }
+ }
+ }
+ //没有放鱼
+ if (free == ponds.length) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100403);
+ resultResponse.set反馈ID(100403);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //鱼没长大
+ if (count == 0) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100402);
+ resultResponse.set反馈ID(100402);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //更新空闲鱼塘数量
+ playerInfo.setPondFree(playerInfo.getPondFree() + count);
+ StringBuilder addText = new StringBuilder();
+ List skillList = Arrays.asList("初始人缘", "初始魅力", "初始自信");
+ int[] totals = new int[]{0, 0 , 0};
+ for (int i = 0; i < count; i++) {
+ int random = PlayerUtil.getRandomNum(0, skillList.size());
+ totals[random] = totals[random] + 2;
+ }
+ for (int i = 0; i < totals.length; i++) {
+ if (totals[i] != 0) {
+ addText.append(skillList.get(i)).append("提升").append(totals[i]).append("点、");
+ }
+ }
+ if (addText.length() != 0) {
+ addText.deleteCharAt(addText.length() - 1);
+ }
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100401);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf(count), addText.toString(), String.valueOf(playerInfo.getPondFree()));
+ resultResponse.set反馈ID(100401);
+ resultResponse.set反馈文本(text);
+ resultResponse.set初始人缘(operationReq.getPopularity() + totals[0]);
+ resultResponse.set初始魅力(operationReq.getCharm() + totals[1]);
+ resultResponse.set初始自信(operationReq.getConfident() + totals[2]);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/server/inn/InnService.java b/src/main/java/com/qiwu/innGame/server/inn/InnService.java
new file mode 100644
index 0000000..6e20d2f
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/inn/InnService.java
@@ -0,0 +1,33 @@
+package com.qiwu.innGame.server.inn;
+
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+
+public interface InnService {
+ /**
+ * 客栈操作
+ * @param operationReq
+ * @return
+ */
+ CommonResult operate(OperationRequest operationReq);
+ /**
+ * 新增敏感词
+ * @param word
+ * @return
+ */
+ CommonResult addWord(String word);
+ /**
+ * 删除敏感词
+ * @param word
+ * @return
+ */
+ CommonResult deleteWord(String word);
+ /**
+ * 删除敏感词
+ * @param word
+ * @return
+ */
+ CommonResult checkRanking();
+}
diff --git a/src/main/java/com/qiwu/innGame/server/inn/impl/InnServiceImpl.java b/src/main/java/com/qiwu/innGame/server/inn/impl/InnServiceImpl.java
new file mode 100644
index 0000000..86f32d5
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/inn/impl/InnServiceImpl.java
@@ -0,0 +1,463 @@
+package com.qiwu.innGame.server.inn.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.common.cache.CacheGlobal;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.PlayerScoreDto;
+import com.qiwu.innGame.dto.ReplyDto;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultResponse;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+import com.qiwu.innGame.server.inn.InnService;
+import com.qiwu.innGame.utils.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+@Service
+public class InnServiceImpl implements InnService {
+ Logger log = LoggerFactory.getLogger(InnServiceImpl.class);
+
+ //对话过期时间
+ @Value("${expireTime}")
+ private String expireTime;
+
+ //排行榜保存路径
+ @Value("${dataFilePath}")
+ private String dataFilePath;
+ //配置保存路径
+ @Value("${configFilePath}")
+ private String configFilePath;
+
+ @Override
+ public CommonResult operate(OperationRequest operationReq) {
+ int methodId = operationReq.getMethodId();
+ if (methodId == 1005) {
+ return checkRanking(operationReq);
+ }
+ if (methodId == 1006) {
+ return rankingView(operationReq);
+ }
+ if (methodId == 100701) {
+ return rankingNext(operationReq);
+ }
+ if (methodId == 100702) {
+ return rankingPre(operationReq);
+ }
+ if (methodId == 1008) {
+ return sensitiveCheck(operationReq);
+ }
+ if (methodId == 100801) {
+ return naming(operationReq);
+ }
+ if (methodId == 100802) {
+ return namingCancel(operationReq);
+ }
+ return null;
+ }
+
+ @Override
+ public CommonResult addWord(String word) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+ List sensitiveWordList = TimingAcquisition.sensitiveWordList;
+ if (StringUtils.isEmpty(word)) {
+ resultResponse.set反馈ID(100903);
+ resultResponse.set反馈文本("word不能为空");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ if (sensitiveWordList.contains(word)) {
+ resultResponse.set反馈ID(100901);
+ resultResponse.set反馈文本("已存在敏感词:【" + word + "】");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ sensitiveWordList.add(word);
+ PersistenceUtil.saveCsvToFile(configFilePath, "sensitiveWord.csv", word);
+ resultResponse.set反馈ID(100902);
+ resultResponse.set反馈文本("敏感词:【" + word + "】添加成功");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ @Override
+ public CommonResult deleteWord(String word) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+ List sensitiveWordList = TimingAcquisition.sensitiveWordList;
+ if (StringUtils.isEmpty(word)) {
+ resultResponse.set反馈ID(101003);
+ resultResponse.set反馈文本("word不能为空");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ if (!sensitiveWordList.contains(word)) {
+ resultResponse.set反馈ID(101001);
+ resultResponse.set反馈文本("不存在敏感词:【" + word + "】");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ sensitiveWordList.remove(word);
+ List sensitiveWordCopyList = new ArrayList<>(sensitiveWordList);
+ PersistenceUtil.saveCsvAllToFile(configFilePath, "sensitiveWord.csv", sensitiveWordCopyList);
+ resultResponse.set反馈ID(101002);
+ resultResponse.set反馈文本("敏感词:【" + word + "】删除成功");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ @Override
+ public CommonResult checkRanking() {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+ StringBuilder text = new StringBuilder();
+ List playerRanking = TimingAcquisition.playerRanking;
+ for (int i = 1; i <= playerRanking.size(); i++) {
+ PlayerScoreDto playerScore = playerRanking.get(i - 1);
+ text.append("第").append(i).append("名:").append(playerScore.getName()).
+ append(",得分:").append(playerScore.getScore()).append("------>");
+ }
+ resultResponse.set反馈ID(101101);
+ resultResponse.set反馈文本(text.toString());
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ public CommonResult sensitiveCheck(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ String name = operationReq.getNickName();
+ if (name.length() > 9) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100804);
+ resultResponse.set反馈ID(100804);
+ resultResponse.set反馈文本(text);
+ resultResponse.set后台附加返回("校验不通过3");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ List sensitiveWordList = TimingAcquisition.sensitiveWordList;
+ for (String word : sensitiveWordList) {
+ //包含敏感词汇
+ if (name.contains(word)) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100801);
+ resultResponse.set反馈ID(100801);
+ resultResponse.set反馈文本(text);
+ resultResponse.set后台附加返回("校验不通过1");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ }
+ for (PlayerScoreDto playerScore : TimingAcquisition.playerRanking) {
+ //重名
+ if (name.equals(playerScore.getName())) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100803);
+ resultResponse.set反馈ID(100803);
+ resultResponse.set反馈文本(text);
+ resultResponse.set后台附加返回("校验不通过2");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ }
+ ReplyDto reply = new ReplyDto();
+ reply.setName(name);
+ //缓存昵称
+ CacheUtil.put(uid, reply, Long.parseLong(expireTime));
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100802);
+ resultResponse.set反馈ID(100802);
+ resultResponse.set反馈文本(text);
+ resultResponse.set后台附加返回("校验通过");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 取名确认
+ * @param operationReq
+ * @return
+ */
+ public CommonResult naming(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ ReplyDto reply = (ReplyDto) CacheUtil.get(uid);
+ if (!StringUtils.isEmpty(reply)) {
+ String name = reply.getName();
+ //给玩家取名
+ TimingAcquisition.playerInfoMap.get(uid).setName(name);
+ }
+ resultResponse.set反馈ID(100805);
+ resultResponse.set反馈文本("命名成功");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 取消取名
+ * @param operationReq
+ * @return
+ */
+ public CommonResult namingCancel(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ //清除缓存
+ CacheGlobal.concurrentMap.remove(uid);
+ resultResponse.set反馈ID(100802);
+ resultResponse.set反馈文本("已取消命名");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 1005:判断排行榜
+ * @param operationReq
+ * @return
+ */
+ public CommonResult checkRanking(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ Integer score = operationReq.getScore();
+ PlayerScoreDto playerScore = new PlayerScoreDto(uid, PlayerUtil.getName(uid), score);
+ //排行榜
+ List playerRanking = TimingAcquisition.playerRanking;
+ //排行榜为空时
+ if (playerRanking.size() == 0) {
+ playerRanking.add(playerScore);
+ resultResponse.set反馈ID(100501);
+ resultResponse.set反馈文本("入选成功");
+ resultResponse.set后台附加返回("入选排行榜");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ int index = 100;
+ for (int i = playerRanking.size() - 1; i >= 0; i--) {
+ if (score > playerRanking.get(i).getScore()) {
+ if (i == 0) {
+ index = 0;
+ break;
+ }
+ continue;
+ }
+ if (score <= playerRanking.get(i).getScore()) {
+ index = i + 1;
+ break;
+ }
+ }
+ //玩家没有进入排行榜
+ if (index >= 100) {
+ resultResponse.set反馈ID(100501);
+ resultResponse.set反馈文本("入选失败");
+ resultResponse.set后台附加返回("没有入选排行榜");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //进入排行榜了
+ playerRanking.add(index, playerScore);
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ playerInfo.setScore(score);
+ playerInfo.setRank(index + 1);
+ //只保留前100排名
+ if (playerRanking.size() > 100) {
+ playerRanking.remove(playerRanking.size() - 1);
+ }
+ //持久化排行榜
+ String playerRankingStr = JSON.toJSONString(playerRanking);
+ PersistenceUtil.saveDataToFile(dataFilePath, "playerRanking", playerRankingStr);
+ //保存这一轮数据
+ ReplyDto reply = new ReplyDto();
+ List playerRankingCopy = new ArrayList<>(playerRanking);
+ reply.setPlayerRanking(playerRankingCopy);
+ //缓存排行榜,用于查看
+ CacheUtil.put(uid + "%ranking%", reply, Long.parseLong(expireTime));
+ resultResponse.set反馈ID(100502);
+ resultResponse.set反馈文本("入选成功");
+ resultResponse.set后台附加返回("入选排行榜");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 1006:查看排行榜
+ * @param operationReq
+ * @return
+ */
+ public CommonResult rankingView(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ PlayerInfoDto playerInfo = TimingAcquisition.playerInfoMap.get(uid);
+ ReplyDto reply = (ReplyDto) CacheUtil.get(uid + "%ranking%");
+ int page = 1;
+ List playerRanking;
+ if (!StringUtils.isEmpty(reply)) {
+ playerRanking = reply.getPlayerRanking();
+ } else {
+ playerRanking = TimingAcquisition.playerRanking;
+ reply = new ReplyDto();
+ reply.setPlayerRanking(playerRanking);
+ }
+ if (playerRanking.size() == 0) {
+ String text = SpeechUtil.getSpeech(100604);
+ resultResponse.set反馈ID(100604);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ //前十排名
+ StringBuilder addText = new StringBuilder();
+ int min = Math.min((page * 10), playerRanking.size());
+ for (int i = 1; i <= min; i++) {
+ PlayerScoreDto playerScore = playerRanking.get(i - 1);
+ addText.append("
" + "第").append(i).append("名:").append(playerScore.getName()).
+ append("
").append("--------------------得分:").append(playerScore.getScore()).append("。");
+ }
+ addText.append("
");
+ //获取对应话术
+ String text = "";
+ //玩家没有上排行榜
+ if (playerInfo.getRank() == 0) {
+ text = SpeechUtil.getSpeech(100601);
+ text = SpeechUtil.speechReplaceNum(text, addText.toString());
+ } else {
+ int rank = playerInfo.getRank();
+ if (rank == 1) {
+ text = SpeechUtil.getSpeech(100603);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf(rank),
+ String.valueOf(playerRanking.get(0).getScore()), addText.toString());
+ resultResponse.set反馈ID(100603);
+ } else {
+ text = SpeechUtil.getSpeech(100602);
+ PlayerScoreDto playerScore = playerRanking.get(rank - 2);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf(rank), playerScore.getName(),
+ String.valueOf(playerScore.getScore()), addText.toString());
+ resultResponse.set反馈ID(100602);
+ }
+ }
+ reply.setPage(page);
+ //缓存排行榜,用于查看
+ CacheUtil.put(uid + "%ranking%", reply, Long.parseLong(expireTime));
+ resultResponse.set反馈文本(text);
+ resultResponse.set后台附加返回("排行榜查询");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 100701:排行榜下一页
+ * @param operationReq
+ * @return
+ */
+ public CommonResult rankingNext(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ ReplyDto reply = (ReplyDto) CacheUtil.get(uid + "%ranking%");
+ int page = 1;
+ List playerRanking;
+ if (!StringUtils.isEmpty(reply)) {
+ playerRanking = reply.getPlayerRanking();
+ page = reply.getPage();
+ page++;
+ } else {
+ playerRanking = TimingAcquisition.playerRanking;
+ reply = new ReplyDto();
+ reply.setPlayerRanking(playerRanking);
+ }
+ //没有下一页
+ if (((page - 1) * 10) >= playerRanking.size()) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100701);
+ resultResponse.set反馈ID(100701);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ StringBuilder addText = new StringBuilder();
+ int min = Math.min((page * 10), playerRanking.size());
+ for (int i = (page - 1) * 10; i < min; i++) {
+ PlayerScoreDto playerScore = playerRanking.get(i);
+ addText.append("
" + "第").append(i + 1).append("名:").append(playerScore.getName()).
+ append("
").append("--------------------得分:").append(playerScore.getScore()).append("。");
+ }
+ addText.append("
");
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100702);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf((page - 1) * 10 + 1), String.valueOf(min), addText.toString());
+ reply.setPage(page);
+ //缓存排行榜,用于查看
+ CacheUtil.put(uid + "%ranking%", reply, Long.parseLong(expireTime));
+ resultResponse.set反馈ID(100702);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ /**
+ * 100702:排行榜上一页
+ * @param operationReq
+ * @return
+ */
+ public CommonResult rankingPre(OperationRequest operationReq) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = operationReq.getUid();
+ ReplyDto reply = (ReplyDto) CacheUtil.get(uid + "%ranking%");
+ int page = 1;
+ List playerRanking;
+ if (!StringUtils.isEmpty(reply)) {
+ playerRanking = reply.getPlayerRanking();
+ page = reply.getPage();
+ } else {
+ playerRanking = TimingAcquisition.playerRanking;
+ reply = new ReplyDto();
+ reply.setPlayerRanking(playerRanking);
+ }
+ //没有上一页
+ if (page == 1) {
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100703);
+ resultResponse.set反馈ID(100703);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+ page = page - 1;
+ StringBuilder addText = new StringBuilder();
+ for (int i = (page - 1) * 10; i < page * 10; i++) {
+ PlayerScoreDto playerScore = playerRanking.get(i);
+ addText.append("
" + "第").append(i + 1).append("名:").append(playerScore.getName()).
+ append("
").append("--------------------得分:").append(playerScore.getScore()).append("。");
+ }
+ addText.append("
");
+ //获取对应话术
+ String text = SpeechUtil.getSpeech(100704);
+ text = SpeechUtil.speechReplaceNum(text, String.valueOf((page - 1) * 10 + 1), String.valueOf(page * 10), addText.toString());
+ reply.setPage(page);
+ //缓存排行榜,用于查看
+ CacheUtil.put(uid + "%ranking%", reply, Long.parseLong(expireTime));
+ resultResponse.set反馈ID(100704);
+ resultResponse.set反馈文本(text);
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/server/login/LoginService.java b/src/main/java/com/qiwu/innGame/server/login/LoginService.java
new file mode 100644
index 0000000..2d1f8a5
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/login/LoginService.java
@@ -0,0 +1,15 @@
+package com.qiwu.innGame.server.login;
+
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+
+public interface LoginService {
+ CommonResult login(CommonRequest commonRequest);
+
+ CommonResult startGame(CommonRequest commonRequest);
+
+ CommonResult loadPlayerData(CommonRequest commonRequest);
+
+ CommonResult reloadPlayerData(CommonRequest commonRequest);
+}
diff --git a/src/main/java/com/qiwu/innGame/server/login/impl/LoginServiceImpl.java b/src/main/java/com/qiwu/innGame/server/login/impl/LoginServiceImpl.java
new file mode 100644
index 0000000..3ab2414
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/server/login/impl/LoginServiceImpl.java
@@ -0,0 +1,129 @@
+package com.qiwu.innGame.server.login.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.qiwu.innGame.common.Constants;
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultResponse;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+import com.qiwu.innGame.server.login.LoginService;
+import com.qiwu.innGame.utils.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Service
+public class LoginServiceImpl implements LoginService {
+ Logger log = LoggerFactory.getLogger(LoginServiceImpl.class);
+
+ @Value("${offlineTime}")
+ private String offlineTime;
+ @Override
+ public CommonResult login(CommonRequest commonRequest) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+ //存放玩家数据
+ Map uidGateNoMap = new ConcurrentHashMap<>();
+ String nowTime = DateUtil.getCurrentTime();
+ PlayerInfoDto player = new PlayerInfoDto();
+ String uid = commonRequest.getUid();
+ player.setUid(uid);
+ player.setStatus(Constants.ONLINE);
+ player.setOnlineTime(nowTime);
+ TimingAcquisition.playerInfoMap.put(uid, player);
+ String playerStr = JSON.toJSONString(player);
+ //创建玩家数据路径
+ String path = MD5Util.changeToPath(uid);
+ //持久化玩家数据
+ PersistenceUtil.saveDataToFile(path, uid, playerStr);
+ //保存所有玩家的uid
+ TimingAcquisition.uidList.add(uid);
+
+ //该玩家以唯一标识加入全局缓存,用于玩家离线判断
+ String uniqueUid = uid + "%#%online%#%";
+ CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
+
+ resultResponse.set反馈ID(100000);
+ resultResponse.set反馈文本("登录成功");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ @Override
+ public CommonResult startGame(CommonRequest commonRequest) {
+ return null;
+ }
+
+ @Override
+ public CommonResult loadPlayerData(CommonRequest commonRequest) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = commonRequest.getUid();
+ //创建玩家数据路径
+ String path = MD5Util.changeToPath(uid);
+ String playStr = PersistenceUtil.loadPlayerData(path, uid);
+ //第一次进入该关卡
+ if (StringUtils.isEmpty(playStr)) {
+ return login(commonRequest);
+ }
+ PlayerInfoDto player = JSON.parseObject(playStr, new TypeReference(){});
+ player.setOnlineTime(DateUtil.getCurrentTime());
+ player.setStatus(Constants.ONLINE);
+ //玩家数据加入缓存
+ TimingAcquisition.playerInfoMap.put(uid, player);
+ //该玩家以唯一标识加入全局缓存,用于玩家离线判断
+ String uniqueUid = uid + "%#%online%#%";
+ CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
+
+ resultResponse.set反馈ID(100010);
+ resultResponse.set反馈文本(uid + "的数据加载完成");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+
+ @Override
+ public CommonResult reloadPlayerData(CommonRequest commonRequest) {
+ ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
+ ResultResponse resultResponse = new ResultResponse();
+
+ String uid = commonRequest.getUid();
+
+ PlayerInfoDto player = TimingAcquisition.playerInfoMap.get(uid);
+ //更新玩家为离线状态
+ player.setStatus(Constants.OFFLINE);
+ //修改下线时间
+ player.setOfflineTime(DateUtil.getCurrentTime());
+ //创建玩家数据路径
+ String path = MD5Util.changeToPath(uid);
+ //--------------持久化该园丁信息---------------
+ PersistenceUtil.saveDataToFile(path, uid, JSON.toJSONString(player));
+ //-----------------重新加载该玩家的关卡数据到缓存-----------------
+ String playStr = PersistenceUtil.loadPlayerData(path, uid);
+ //第一次进入该关卡
+ if (StringUtils.isEmpty(playStr)) {
+ return login(commonRequest);
+ }
+ PlayerInfoDto playerNew = JSON.parseObject(playStr, new TypeReference(){});
+ player.setOnlineTime(DateUtil.getCurrentTime());
+ player.setStatus(Constants.ONLINE);
+ //玩家数据加入缓存
+ TimingAcquisition.playerInfoMap.put(uid, playerNew);
+ //该玩家以唯一标识加入全局缓存,用于玩家离线判断
+ String uniqueUid = uid + "%#%online%#%";
+ CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
+
+ resultResponse.set反馈ID(100010);
+ resultResponse.set反馈文本(uid + "的关卡数据重新加载完成");
+ resultVarsResponse.setVars(resultResponse);
+ return CommonResult.success(resultVarsResponse);
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/CacheUtil.java b/src/main/java/com/qiwu/innGame/utils/CacheUtil.java
new file mode 100644
index 0000000..08e1283
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/CacheUtil.java
@@ -0,0 +1,67 @@
+package com.qiwu.innGame.utils;
+
+import com.qiwu.innGame.common.cache.CacheGlobal;
+import com.qiwu.innGame.common.cache.MyCache;
+import org.springframework.util.StringUtils;
+
+/**
+ * 缓存操作工具
+ * */
+public class CacheUtil {
+ /**
+ * 添加缓存
+ * @param key
+ * @param value
+ * @param expire
+ */
+ public static void put(String key, Object value, long expire) {
+ if (StringUtils.isEmpty(key)) {
+ return;
+ }
+ if (CacheGlobal.concurrentMap.containsKey(key)) {
+ MyCache myCache = CacheGlobal.concurrentMap.get(key);
+ myCache.setHitCount(myCache.getHitCount() + 1);
+ myCache.setLastTime(System.currentTimeMillis());
+ myCache.setExpireTime(expire);
+ myCache.setValue(value);
+ } else {
+ MyCache myCache = new MyCache();
+ myCache.setKey(key);
+ myCache.setValue(value);
+ myCache.setWriteTime(System.currentTimeMillis());
+ myCache.setLastTime(System.currentTimeMillis());
+ myCache.setExpireTime(expire);
+ myCache.setHitCount(1);
+ CacheGlobal.concurrentMap.put(key, myCache);
+ }
+ }
+
+ /**
+ * 获取缓存
+ * @param key
+ */
+ public static Object get(String key) {
+ if (StringUtils.isEmpty(key)) {
+ return null;
+ }
+ if (CacheGlobal.concurrentMap.isEmpty()) {
+ return null;
+ }
+ if (!CacheGlobal.concurrentMap.containsKey(key)) {
+ return null;
+ }
+ MyCache myCache = CacheGlobal.concurrentMap.get(key);
+ if (myCache == null) {
+ return null;
+ }
+ //惰性删除
+ long timeOutTime = System.currentTimeMillis() - myCache.getWriteTime();
+ if (timeOutTime >= myCache.getExpireTime()) {
+ CacheGlobal.concurrentMap.remove(key);
+ return null;
+ }
+ myCache.setHitCount(myCache.getHitCount() + 1);
+ myCache.setWriteTime(System.currentTimeMillis());
+ return myCache.getValue();
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/CsvUtil.java b/src/main/java/com/qiwu/innGame/utils/CsvUtil.java
new file mode 100644
index 0000000..58c43b2
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/CsvUtil.java
@@ -0,0 +1,40 @@
+package com.qiwu.innGame.utils;
+
+import com.opencsv.CSVReader;
+import com.opencsv.bean.CsvToBeanBuilder;
+import com.opencsv.bean.CsvToBeanFilter;
+import com.opencsv.bean.HeaderColumnNameMappingStrategy;
+import org.springframework.util.StringUtils;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class CsvUtil {
+ public List read(String filePath, Class clazz) {
+ try {
+ CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8));
+ HeaderColumnNameMappingStrategy mapper = new HeaderColumnNameMappingStrategy<>();
+ mapper.setType(clazz);
+ return new CsvToBeanBuilder(reader)
+ .withMappingStrategy(mapper)
+ .withIgnoreLeadingWhiteSpace(true)
+ .withFilter(new MyFilter())
+ .build()
+ .parse();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ System.out.printf("csv文件: {%s} 读取异常%n", filePath);
+ }
+ return null;
+ }
+
+ private static class MyFilter implements CsvToBeanFilter {
+ public boolean allowLine(String[] line) {
+ String id = line[0];
+ return !StringUtils.isEmpty(id) && !id.equals("");
+ }
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/DataTrimUtil.java b/src/main/java/com/qiwu/innGame/utils/DataTrimUtil.java
new file mode 100644
index 0000000..1adcdcc
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/DataTrimUtil.java
@@ -0,0 +1,86 @@
+package com.qiwu.innGame.utils;
+
+import com.qiwu.innGame.common.Constants;
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+import com.qiwu.innGame.dto.response.CommonResult;
+import com.qiwu.innGame.dto.response.ResultVarsResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
+
+import java.text.ParseException;
+
+public class DataTrimUtil {
+ static Logger log = LoggerFactory.getLogger(DataTrimUtil.class);
+
+ /**
+ * 判断整数尾数是否为1
+ */
+ public static boolean checkIntWithOne(Integer num) {
+ int remain = num % 10;
+ if (remain == 1) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 玩家状态更改
+ */
+ public static void AdjustStatus(String uid, String offlineTime) throws ParseException {
+ //玩家当前为离线状态
+ PlayerInfoDto player = TimingAcquisition.playerInfoMap.get(uid);
+ //上次操作时间过期,需更改为在线状态
+ String nowTime = DateUtil.getCurrentTime();
+ if (!StringUtils.isEmpty(player.getOnlineTime())) {
+ if (DateUtil.subTime(nowTime, player.getOnlineTime()) > (Long.parseLong(offlineTime) / 1000)) {
+ //更新玩家在线状态
+ statusUpdate(uid);
+ }
+ }
+ if (player.getStatus() == Constants.OFFLINE) {
+ //更新玩家在线状态
+ statusUpdate(uid);
+ }
+ //该玩家以唯一标识加入全局缓存,用于玩家离线判断
+ String uniqueUid = uid + "%#%online%#%";
+ CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
+ }
+
+ /**
+ * 玩家状态更新为在线
+ */
+ public static void statusUpdate(String uid) {
+ if (!StringUtils.isEmpty(TimingAcquisition.playerInfoMap.get(uid))) {
+ TimingAcquisition.playerInfoMap.get(uid).setStatus(Constants.ONLINE);
+ //修改上线时间
+ TimingAcquisition.playerInfoMap.get(uid).setOnlineTime(DateUtil.getCurrentTime());
+ }
+ }
+
+ /**
+ * 判断整数尾数是否为1
+ */
+ public static CommonResult AdjustParams(String uid, CommonResult result) {
+ if (StringUtils.isEmpty(result)) {
+ return CommonResult.failed("操作失败");
+ }
+ ResultVarsResponse data = result.getData();
+ if (!StringUtils.isEmpty(data)) {
+ //所有“后台附加返回”为null值的都给转成“无效返回”
+ if (StringUtils.isEmpty(data.getVars().get后台附加返回())) {
+ data.getVars().set后台附加返回("无效返回");
+ }
+ String feedContent = "后台返回参数 = [" +
+ "code:" + result.getCode() +
+ ", msg:" + result.getMessage() +
+ ", 反馈ID:" + data.getVars().get反馈ID() +
+ ", 反馈文本:" + data.getVars().get反馈文本() +
+ ", 后台附加返回:" + data.getVars().get后台附加返回() +
+ "]";
+ log.info(feedContent);
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/DateUtil.java b/src/main/java/com/qiwu/innGame/utils/DateUtil.java
new file mode 100644
index 0000000..13392f5
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/DateUtil.java
@@ -0,0 +1,489 @@
+package com.qiwu.innGame.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 时间工具类
+ * @author hjd
+ */
+public class DateUtil {
+ /**
+ * 获取当前时间
+ * @return String
+ */
+ public static String currentTimes(){
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
+ String format = df.format(new Date());// new Date()为获取当前系统时间
+ return format;
+ }
+
+ /**
+ * 以"yyyyMMddHHmmss"格式获取当前时间
+ * @return
+ */
+ public static String getCurrentTime(){
+ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ String format = df.format(new Date());// new Date()为获取当前系统时间
+ return format;
+ }
+ /**
+ * 时间加上毫秒
+ * @param time
+ * @param sub
+ * @return String
+ */
+ public static String addTime(String time, int sub) throws ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ Date dt = sdf.parse(time);
+ Calendar newTime = Calendar.getInstance();
+ newTime.setTime(dt);
+ newTime.add(Calendar.SECOND, sub);
+ Date newDt = newTime.getTime();
+
+ return sdf.format(newDt);
+ }
+
+ /**
+ * 时间减去毫秒
+ * @param time
+ * @param sub
+ * @return String
+ */
+ public static String subTime(String time, int sub) throws ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ Date dt = sdf.parse(time);
+ Calendar newTime = Calendar.getInstance();
+ newTime.setTime(dt);
+ newTime.add(Calendar.SECOND, -sub);
+ Date newDt = newTime.getTime();
+
+ return sdf.format(newDt);
+ }
+
+ /**
+ * 计算时间差(time1 - time2),返回单位为秒
+ * @param time1
+ * @param time2
+ * @return long
+ */
+ public static long subTime(String time1, String time2) throws ParseException {
+ String t1 = (time1.compareTo(time2) > 0) ? time1 : time2;
+ String t2 = (time1.compareTo(time2) > 0) ? time2 : time1;
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ Date dt1 = sdf.parse(t1);
+ Date dt2 = sdf.parse(t2);
+ return (dt1.getTime() - dt2.getTime())/1000;
+ }
+
+ /**
+ * 计算时间差(time1 - time2),返回单位为天/时/分/秒
+ * @param time1
+ * @param time2
+ * @return String
+ */
+ public static String subTimeToDate(String time1, String time2) throws ParseException {
+ String t1 = (time1.compareTo(time2) > 0) ? time1 : time2;
+ String t2 = (time1.compareTo(time2) > 0) ? time2 : time1;
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ Date dt1 = sdf.parse(t1);
+ Date dt2 = sdf.parse(t2);
+ long time = (dt1.getTime() - dt2.getTime())/1000;
+ String result = null;
+ long days = time / (60 * 60 * 24);
+ long hours = (time % (60 * 60 * 24)) / (60 * 60);
+ long minutes = (time % (60 * 60)) / 60;
+ long seconds = time % 60;
+ if (days > 0) {
+ result = days + "天" + hours + "小时" + minutes + "分钟";
+ } else if (hours > 0) {
+ result = hours + "小时" + minutes + "分钟";
+ } else if (minutes > 0) {
+ result = minutes + "分钟" + seconds + "秒";
+ } else {
+ result = seconds + "秒";
+ }
+ return result;
+ }
+
+ /**
+ * 将秒换算成单位为天/时/分/秒
+ * @param time
+ * @return String
+ */
+ public static String timeToDate(Long time) throws ParseException {
+ String result = null;
+ long days = time / (60 * 60 * 24);
+ long hours = (time % (60 * 60 * 24)) / (60 * 60);
+ long minutes = (time % (60 * 60)) / 60;
+ long seconds = time % 60;
+ if (days > 0) {
+ result = days + "天" + hours + "小时" + minutes + "分钟";
+ } else if (hours > 0) {
+ result = hours + "小时" + minutes + "分钟";
+ } else if (minutes > 0) {
+ result = minutes + "分钟" + seconds + "秒";
+ } else {
+ result = seconds + "秒";
+ }
+ return result;
+ }
+
+ /**
+ * 计算时间差(time1 - time2),返回单位为天
+ * @param time1
+ * @param time2
+ * @return String
+ */
+ public static long subTimeToDay(String time1, String time2) throws ParseException {
+ String t1 = (time1.compareTo(time2) > 0) ? time1 : time2;
+ String t2 = (time1.compareTo(time2) > 0) ? time2 : time1;
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
+ Date dt1 = sdf.parse(t1);
+ Date dt2 = sdf.parse(t2);
+ long time = (dt1.getTime() - dt2.getTime())/1000;
+ long result = 0;
+ return time / (60 * 60 * 24);
+ }
+
+ /**
+ * 日期比较:(time1 > time2)返回1,=返回0,<返回-1
+ * @param time1
+ * @param time2
+ * @return int
+ */
+ public static int compare(String time1, String time2) throws ParseException {
+ time1 = time1.substring(0, 8);
+ time2 = time2.substring(0, 8);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");//设置日期格式
+ Date dt1 = sdf.parse(time1);
+ Date dt2 = sdf.parse(time2);
+ return dt1.compareTo(dt2);
+ }
+
+ /**
+ * "yyyyMMddHHmmss"转成“yyyy-MM-dd HH:mm:ss“
+ * @param time
+ * @return String
+ */
+ public static String changeForm(String time) throws ParseException {
+ Date date = new Date();
+ try {
+ date = new SimpleDateFormat("yyyyMMddHHmmss").parse(time);//先按照原格式转换为时间
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ String str = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);//再将时间转换为对应格式字符串
+ return str;
+ }
+
+ /**
+ * 获取今天的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-11-03 00:00:00, 2017-11-03 24:00:00]
+ */
+ public static List getToday() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.add(Calendar.DATE, 0);
+ String today = dateFormat.format(calendar.getTime());
+ dataList.add(today + " 00:00:00");
+ dataList.add(today + " 24:00:00");
+ return dataList;
+ }
+
+ /**
+ * 获取昨天的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-11-02 00:00:00, 2017-11-02 24:00:00]
+ */
+ public static List getYesterday() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ //获取指定时间
+ Calendar calendar = Calendar.getInstance();
+ //获取当天时间的起点时间
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ //获取当前日期前一天
+ calendar.add(Calendar.DATE, -1);
+ //转换成指定格式
+ String yesterday = dateFormat.format(calendar.getTime());
+ dataList.add(yesterday + " 00:00:00");
+ dataList.add(yesterday + " 24:00:00");
+ return dataList;
+ }
+
+ /**
+ * 获取前天的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-11-02 00:00:00, 2017-11-02 24:00:00]
+ */
+ public static List getDayBeforeYesterday() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ //获取指定时间
+ Calendar calendar = Calendar.getInstance();
+ //获取当天时间的起点时间
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ //获取当前日期前一天
+ calendar.add(Calendar.DATE, -2);
+ //转换成指定格式
+ String yesterday = dateFormat.format(calendar.getTime());
+ dataList.add(yesterday + " 00:00:00");
+ dataList.add(yesterday + " 24:00:00");
+ return dataList;
+ }
+
+ /**
+ * 获取本周的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-10-30 00:00:00, 2017-11-05 24:00:00]
+ */
+ public static List getCurrentWeek() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar calendar = Calendar.getInstance();
+ calendar.setFirstDayOfWeek(Calendar.MONDAY);//设置周一为一周之内的第一天
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
+ String monday = dateFormat.format(calendar.getTime()) + " 00:00:00";
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
+ String sunday = dateFormat.format(calendar.getTime()) + " 24:00:00";
+ dataList.add(monday);
+ dataList.add(sunday);
+ return dataList;
+ }
+
+ /**
+ * 获取上周的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-10-30 00:00:00, 2017-11-05 24:00:00]
+ */
+ public static List getLastWeek() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
+ Calendar calendar1 = Calendar.getInstance();
+ Calendar calendar2 = Calendar.getInstance();
+ int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;
+ int offset1 = 1 - dayOfWeek;
+ int offset2 = 7 - dayOfWeek;
+ calendar1.add(Calendar.DATE, offset1 - 7);
+ calendar2.add(Calendar.DATE, offset2 - 7);
+// 上周星期一
+ String lastBeginDate = sdf.format(calendar1.getTime())+ " 00:00:00";
+ dataList.add(lastBeginDate);
+// 上周星期日
+ String lastEndDate = sdf.format(calendar2.getTime())+ " 00:00:00";
+ dataList.add(lastEndDate);
+ return dataList;
+ }
+
+ /**
+ * 获取本月的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-11-01 00:00:00, 2017-11-30 24:00:00]
+ */
+ public static List getCurrentMonth() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.add(Calendar.MONTH, 0);//0表示本月
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ String firstDayOfMonth = dateFormat.format(calendar.getTime()) + " 00:00:00";
+ calendar.add(Calendar.MONTH, 1);
+ calendar.set(Calendar.DAY_OF_MONTH, 0);
+ String lastDayOfMonth = dateFormat.format(calendar.getTime()) + " 24:00:00";
+ dataList.add(firstDayOfMonth);
+ dataList.add(lastDayOfMonth);
+ return dataList;
+ }
+
+ /**
+ * 获取上个月的时间范围
+ * @return 返回长度为2的字符串集合,如:[2017-11-01 00:00:00, 2017-11-30 24:00:00]
+ */
+ public static List getLastMonth() {
+ List dataList = new ArrayList<>(2);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.add(Calendar.MONTH, -1);//0表示
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ String firstDayOfMonth = dateFormat.format(calendar.getTime()) + " 00:00:00";
+ calendar.add(Calendar.MONTH, 1);
+ calendar.set(Calendar.DAY_OF_MONTH, 0);
+ String lastDayOfMonth = dateFormat.format(calendar.getTime()) + " 24:00:00";
+ dataList.add(firstDayOfMonth);
+ dataList.add(lastDayOfMonth);
+ return dataList;
+ }
+
+ /**
+ * 获取今年某月份的开始结束日期
+ *
+ * @param offset 0本月,1下个月,-1上个月,依次类推
+ * @return
+ */
+ public static List someMonth(int offset) {
+ List dataList = new ArrayList<>(2);
+ Calendar calendar = Calendar.getInstance();
+ //获取当前年份
+ int i = calendar.get(Calendar.YEAR);
+ calendar.set(Calendar.YEAR, i);
+ calendar.set(Calendar.MONTH, offset - 1);
+ calendar.set(Calendar.DATE, 1);
+ String str = getCalendarToTimestapStr(setStarthhmmss(calendar));
+ dataList.add(str);
+ calendar.set(Calendar.YEAR, i);
+ calendar.set(Calendar.MONTH, offset);
+ calendar.set(Calendar.DATE, 1);
+ String strs = getCalendarToTimestapStr(setStarthhmmss(calendar));
+ dataList.add(strs);
+ return dataList;
+ }
+
+ /**
+ * 获取某天的开始日期
+ *
+ * @param offset 0今天,1明天,-1昨天,依次类推
+ * @return
+ */
+ public static List dayStart(int offset) {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ LocalDateTime localDateTime = LocalDate.now().plusDays(offset).atStartOfDay();
+ dataList.add(localDateTime.format(dtf));
+ return dataList;
+
+ }
+
+ /**
+ * 获取某周的开始日期
+ *
+ * @param offset 0本周,1下周,-1上周,依次类推
+ * @return
+ */
+ public static List weekStart(int offset) {
+ List dataList = new ArrayList<>(2);
+ LocalDate localDate = LocalDate.now().plusWeeks(offset);
+ LocalDate date = localDate.with(DayOfWeek.MONDAY);
+ DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String dateStr = date.format(fmt)+" 00:00:00";
+ dataList.add(dateStr);
+ return dataList;
+ }
+
+ /**
+ * 获取某月份的开始日期
+ *
+ * @param offset 0本月,1下个月,-1上个月,依次类推
+ * @return
+ */
+ public static List monthStart(int offset) {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ LocalDate date = LocalDate.now().plusMonths(offset).with(TemporalAdjusters.firstDayOfMonth());
+ String firstDayOfMonth = date.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth);
+ return dataList;
+ }
+
+ /**
+ * 获取某年的开始日期
+ *
+ * @param offset 0今年,1明年,-1去年,依次类推
+ * @return
+ */
+ public static List yearStart(int offset) {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ LocalDate localDate = LocalDate.now().plusYears(offset).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth = localDate.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth);
+ return dataList;
+ }
+
+ /**
+ * 获取 日历 的 时间戳字符串 (月 需要 +1)
+ */
+ private static String getCalendarToTimestapStr(Calendar cal){
+
+ String yyyymmdd = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
+ String hhmmss = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
+ return yyyymmdd + " "+ hhmmss;
+ }
+
+ /**
+ * 设置 开始时间的 时分秒
+ */
+ private static Calendar setStarthhmmss(Calendar cal){
+ cal.set(Calendar.HOUR_OF_DAY, 00);
+ cal.set(Calendar.MINUTE, 00);
+ cal.set(Calendar.SECOND, 00);
+ return cal;
+ }
+
+ /**
+ * 获取去年的时间段
+ * @return
+ */
+ public static List getLastYear() {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ LocalDate localDate = LocalDate.now().plusYears(-1).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth = localDate.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth);
+ LocalDate localDate1 = LocalDate.now().plusYears(0).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth1 = localDate1.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth1);
+ return dataList;
+ }
+
+ /**
+ * 获取今年的时间段
+ * @return
+ */
+ public static List getThisYear() {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ LocalDate localDate = LocalDate.now().plusYears(0).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth = localDate.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth);
+ LocalDate localDate1 = LocalDate.now().plusYears(1).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth1 = localDate1.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth1);
+ return dataList;
+ }
+
+ /**
+ * 前年
+ * @return
+ */
+ public static List getTheYearBeforeLast() {
+ List dataList = new ArrayList<>(2);
+ DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ LocalDate localDate = LocalDate.now().plusYears(-2).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth = localDate.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth);
+ LocalDate localDate1 = LocalDate.now().plusYears(-1).with(TemporalAdjusters.firstDayOfYear());
+ String firstDayOfMonth1 = localDate1.format(dateFormat) + " 00:00:00";
+ dataList.add(firstDayOfMonth1);
+ return dataList;
+ }
+
+ public static void main(String[] args) throws ParseException {
+ String time = addTime("20220525165212", 76);
+ System.out.println(time);
+ String t1 = "20220706170722";
+ String t2 = getCurrentTime();
+ System.out.println("时间比较结果:" + changeForm(t1));
+ System.out.println("时间差:" + subTimeToDate(t2, t1));
+ }
+
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/FileUtil.java b/src/main/java/com/qiwu/innGame/utils/FileUtil.java
new file mode 100644
index 0000000..40222e5
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/FileUtil.java
@@ -0,0 +1,50 @@
+package com.qiwu.innGame.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.qiwu.innGame.dto.PlayerScoreDto;
+import com.qiwu.innGame.pojo.RankingPojo;
+import com.qiwu.innGame.pojo.SensitiveWordPojo;
+import com.qiwu.innGame.pojo.SpeechPojo;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class FileUtil {
+ /**
+ * 加载话术表
+ */
+ public static Map loadSpeech(String filePath) {
+ String speechPath = filePath + "speech.csv";
+ CsvUtil csvUtil = new CsvUtil<>();
+ List speechList = csvUtil.read(speechPath, SpeechPojo.class);
+ Map speechMap = new ConcurrentHashMap<>();
+ for (SpeechPojo speech : speechList) {
+ speechMap.put(speech.getFeedId(), speech);
+ }
+ return speechMap;
+ }
+ /**
+ * 加载敏感词汇表
+ */
+ public static List loadSensitiveWord(String filePath) {
+ String sensitiveWordPath = filePath + "sensitiveWord.csv";
+ CsvUtil csvUtil = new CsvUtil<>();
+ List wordList = csvUtil.read(sensitiveWordPath, SensitiveWordPojo.class);
+ List sensitiveWordList = new ArrayList<>();
+ for (SensitiveWordPojo sensitive : wordList) {
+ sensitiveWordList.add(sensitive.getWord());
+ }
+ return sensitiveWordList;
+ }
+
+// public static void main(String[] args) {
+// String path = "/home/jiaoyou/projects/innGame/data/初始排行榜.csv";
+// CsvUtil csvUtil = new CsvUtil<>();
+// List rankingList = csvUtil.read(path, RankingPojo.class);
+// String playerRankingStr = JSON.toJSONString(rankingList);
+// PersistenceUtil.saveDataToFile("/home/jiaoyou/projects/innGame/data/", "playerRanking", playerRankingStr);
+// }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/MD5Util.java b/src/main/java/com/qiwu/innGame/utils/MD5Util.java
new file mode 100644
index 0000000..ec747d2
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/MD5Util.java
@@ -0,0 +1,50 @@
+package com.qiwu.innGame.utils;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+@Component
+public class MD5Util {
+ //玩家数据路径
+ public static String userFilePath;
+ @Value("${userFilePath}")
+ public void setUserFilePath(String userFilePath) {
+ MD5Util.userFilePath = userFilePath;
+ }
+
+ /**
+ * 使用md5进行加密
+ */
+ public static String md5(String text) {
+ byte[] secretBytes = null;
+ try {
+ secretBytes = MessageDigest.getInstance("md5").digest(text.getBytes());
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("没有md5的算法");
+ }
+ StringBuilder sb = new StringBuilder(40);
+ for(byte x:secretBytes) {
+ if((x & 0xff)>>4 == 0) {
+ sb.append("0").append(Integer.toHexString(x & 0xff));
+ } else {
+ sb.append(Integer.toHexString(x & 0xff));
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 将uid转成对应的路径
+ */
+ public static String changeToPath(String uid) {
+ //创建玩家数据路径
+ String md5 = md5(uid);
+ String front = md5.substring(0,2);
+ String second = md5.substring(2, 4);
+ String three = md5.substring(4, 6);
+ return userFilePath + "/" + front + "/" + second+ "/" + three+ "/";
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/PersistenceUtil.java b/src/main/java/com/qiwu/innGame/utils/PersistenceUtil.java
new file mode 100644
index 0000000..a7ee2d0
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/PersistenceUtil.java
@@ -0,0 +1,269 @@
+package com.qiwu.innGame.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.opencsv.CSVWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.PriorityBlockingQueue;
+
+public class PersistenceUtil {
+ static Logger log = LoggerFactory.getLogger(PersistenceUtil.class);
+ /**
+ * 保存玩家数据到json文件
+ * @param fileName
+ * @param data
+ * @return void
+ */
+ public static void saveDataToFile(String path, String fileName, String data) {
+ FileWriter fw = null;
+ File file = new File(path);
+ if (!file.exists()) {
+ try {
+ file.mkdirs();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ fw = new FileWriter(path + "/" + fileName + ".json", false);
+ fw.write(data);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fw != null) {
+ fw.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 持久化文件
+ * @param fileName
+ * @param data
+ * @return void
+ */
+ public static void saveCsvToFile(String path, String fileName, String data) {
+ FileWriter fw = null;
+ File file = new File(path);
+ if (!file.exists()) {
+ try {
+ file.mkdirs();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ fw = new FileWriter(path + fileName, true);
+ CSVWriter mCsvWriter = new CSVWriter(fw);
+ mCsvWriter.writeNext(new String[]{data});
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fw != null) {
+ fw.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 持久化文件
+ * @param fileName
+ * @param data
+ * @return void
+ */
+ public static void saveCsvAllToFile(String path, String fileName, List data) {
+ FileWriter fw = null;
+ File file = new File(path);
+ if (!file.exists()) {
+ try {
+ file.mkdirs();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ fw = new FileWriter(path + fileName, false);
+ CSVWriter mCsvWriter = new CSVWriter(fw);
+ mCsvWriter.writeNext(new String[]{"敏感词汇"});
+ for (String d : data) {
+ mCsvWriter.writeNext(new String[]{d});
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fw != null) {
+ fw.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ /**
+ * 从json文件中读取各配置文件的信息
+ * @param path
+ * @param fileName
+ * @return String
+ */
+ public static String getConfigFromFile(String path, String fileName) {
+ BufferedReader reader = null;
+ String lastStr = "";
+ try {
+ FileInputStream fileInputStream = new FileInputStream(path + fileName);
+ InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
+ reader = new BufferedReader(inputStreamReader);
+ String stringTmp = null;
+ while ((stringTmp = reader.readLine()) != null) {
+ lastStr += stringTmp;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return lastStr;
+ }
+
+ /**
+ * 读取json文件数据
+ * @param path json文件路径
+ * @param fileName
+ * @return 字符串
+ */
+ public static String readJson(String path, String fileName) {
+ String jsonPath = path + fileName;
+ File jsonFile = new File(jsonPath);
+ try {
+ FileReader fileReader = new FileReader(jsonFile);
+ BufferedReader reader = new BufferedReader(fileReader);
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ int ch = reader.read();
+ if (ch != -1) {
+ sb.append((char) ch);
+ } else {
+ break;
+ }
+ }
+ fileReader.close();
+ reader.close();
+ return sb.toString();
+ } catch (IOException e) {
+ return "";
+ }
+ }
+
+ /**
+ * 将话术转成map格式
+ * @param
+ * @return Map>>
+ */
+ public static Map>> loadSpeechToMap(String speechFilePath, String fileName) {
+ Map>> speechMap = new HashMap<>();
+ try {
+ InputStream in = new FileInputStream(speechFilePath + fileName);
+ Yaml yaml = new Yaml();
+ speechMap = yaml.load(in);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return speechMap;
+ }
+
+ /**
+ * 读取玩家json文件的数据
+ * @param path json文件路径
+ * @param uid
+ * @return 字符串
+ */
+ public static String loadPlayerData(String path, String uid) {
+ BufferedReader reader = null;
+ String fileName = uid + ".json";
+ String lastStr = "";
+ File file = new File(path + fileName);
+ if (!file.exists()) {
+ return lastStr;
+ }
+ try {
+ FileInputStream fileInputStream = new FileInputStream(path + fileName);
+ InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
+ reader = new BufferedReader(inputStreamReader);
+ String stringTmp = null;
+ while ((stringTmp = reader.readLine()) != null) {
+ lastStr += stringTmp;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return lastStr;
+ }
+
+ /**
+ * 读取json文件的数据
+ * @param path json文件路径
+ * @param fileName
+ * @return 字符串
+ */
+ public static String readJsonFile(String path, String fileName) {
+ BufferedReader reader = null;
+ String lastStr = "";
+ File file = new File(path + fileName);
+ if (!file.exists()) {
+ return lastStr;
+ }
+ try {
+ FileInputStream fileInputStream = new FileInputStream(path + fileName);
+ InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
+ reader = new BufferedReader(inputStreamReader);
+ String stringTmp = null;
+ while ((stringTmp = reader.readLine()) != null) {
+ lastStr += stringTmp;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return lastStr;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/PlayerUtil.java b/src/main/java/com/qiwu/innGame/utils/PlayerUtil.java
new file mode 100644
index 0000000..4eeaf2f
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/PlayerUtil.java
@@ -0,0 +1,49 @@
+package com.qiwu.innGame.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.qiwu.innGame.common.Constants;
+import com.qiwu.innGame.common.TimingAcquisition;
+import com.qiwu.innGame.dto.PlayerInfoDto;
+
+import java.util.Random;
+
+public class PlayerUtil {
+ /**
+ * 玩家下线
+ */
+ public static void offLine(String uid) {
+ PlayerInfoDto player = TimingAcquisition.playerInfoMap.get(uid);
+ //更新玩家为离线状态
+ player.setStatus(Constants.OFFLINE);
+ //修改下线时间
+ player.setOfflineTime(DateUtil.getCurrentTime());
+ //创建玩家数据路径
+ String path = MD5Util.changeToPath(uid);
+ //--------------持久化该玩家信息---------------
+ PersistenceUtil.saveDataToFile(path, player.getUid(), JSON.toJSONString(player));
+ //-----------------清除该玩家的数据缓存-----------------
+ TimingAcquisition.playerInfoMap.remove(uid);
+ }
+
+ /**
+ * 通过uid获取昵称
+ */
+ public static String getName(String uid) {
+ return TimingAcquisition.playerInfoMap.get(uid).getName();
+ }
+
+ /**
+ * 取指定范围内的随机数
+ * @param num1
+ * @param num2
+ * @return Integer
+ */
+ public static Integer getRandomNum(Integer num1, Integer num2) {
+ Integer min = num1 > num2 ? num2 : num1;
+ int sub = num1 > num2 ? num1-num2 : num2-num1;
+ sub = sub == 0 ? 1 : sub;
+ Random random = new Random();
+ //random.nextInt(1)结果为0,random.nextInt(0)会报错
+ return random.nextInt(sub) + min;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/RequestConversionUtil.java b/src/main/java/com/qiwu/innGame/utils/RequestConversionUtil.java
new file mode 100644
index 0000000..38bedac
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/RequestConversionUtil.java
@@ -0,0 +1,90 @@
+package com.qiwu.innGame.utils;
+
+import com.qiwu.innGame.dto.request.CallRequest;
+import com.qiwu.innGame.dto.request.CommonRequest;
+import com.qiwu.innGame.dto.request.OperationRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
+
+public class RequestConversionUtil {
+ Logger log = LoggerFactory.getLogger(RequestConversionUtil.class);
+ /**
+ * 将请求的中文转成系统数据
+ * @param commonRequest
+ * @return OperationRequest
+ */
+ public static OperationRequest request2Operation(CommonRequest commonRequest) {
+ OperationRequest operationRequest = new OperationRequest();
+ CallRequest callRequest = commonRequest.getVars();
+ String uid = commonRequest.getUid();
+ operationRequest.setUid(uid);
+
+ //---------------------存在"方法编号"-----------------------
+ Integer methodId = callRequest.get方法编号();
+ if (!StringUtils.isEmpty(methodId)) {
+ operationRequest.setMethodId(methodId);
+ }
+ //---------------------存在"种子数量"-----------------------
+ Integer seedNum = callRequest.get种子数量();
+ if (!StringUtils.isEmpty(seedNum)) {
+ operationRequest.setSeedNum(seedNum);
+ }
+ //---------------------存在"鱼苗数量"-----------------------
+ Integer fishNum = callRequest.get鱼苗数量();
+ if (!StringUtils.isEmpty(fishNum)) {
+ operationRequest.setFishNum(fishNum);
+ }
+ //---------------------存在"天数"-----------------------
+ Integer days = callRequest.get天数();
+ if (!StringUtils.isEmpty(days)) {
+ operationRequest.setDays(days);
+ }
+ //---------------------存在"客栈金币"-----------------------
+ Integer money = callRequest.get客栈金币();
+ if (!StringUtils.isEmpty(money)) {
+ operationRequest.setMoney(money);
+ }
+ //---------------------存在"综合评分"-----------------------
+ Integer score = callRequest.get综合评分();
+ if (!StringUtils.isEmpty(score)) {
+ operationRequest.setScore(score);
+ }
+ //---------------------存在"上传昵称"-----------------------
+ String nickName = callRequest.get上传昵称();
+ if (!StringUtils.isEmpty(nickName)) {
+ operationRequest.setNickName(nickName);
+ }
+ //---------------------存在"初始人缘"-----------------------
+ Integer popularity = callRequest.get初始人缘();
+ if (!StringUtils.isEmpty(popularity)) {
+ operationRequest.setPopularity(popularity);
+ }
+ //---------------------存在"初始魅力"-----------------------
+ Integer charm = callRequest.get初始魅力();
+ if (!StringUtils.isEmpty(charm)) {
+ operationRequest.setCharm(charm);
+ }
+ //---------------------存在"初始自信"-----------------------
+ Integer confident = callRequest.get初始自信();
+ if (!StringUtils.isEmpty(confident)) {
+ operationRequest.setConfident(confident);
+ }
+ //---------------------存在"掌柜生命值"-----------------------
+ Integer life = callRequest.get掌柜生命值();
+ if (!StringUtils.isEmpty(life)) {
+ operationRequest.setLife(life);
+ }
+ //---------------------存在"掌柜修为"-----------------------
+ Integer cultivation = callRequest.get掌柜修为();
+ if (!StringUtils.isEmpty(cultivation)) {
+ operationRequest.setCultivation(cultivation);
+ }
+ //---------------------存在"初始掌柜技能点"-----------------------
+ Integer skill = callRequest.get初始掌柜技能点();
+ if (!StringUtils.isEmpty(skill)) {
+ operationRequest.setSkill(skill);
+ }
+ return operationRequest;
+ }
+}
diff --git a/src/main/java/com/qiwu/innGame/utils/SpeechUtil.java b/src/main/java/com/qiwu/innGame/utils/SpeechUtil.java
new file mode 100644
index 0000000..7d09910
--- /dev/null
+++ b/src/main/java/com/qiwu/innGame/utils/SpeechUtil.java
@@ -0,0 +1,74 @@
+package com.qiwu.innGame.utils;
+
+import com.qiwu.innGame.common.TimingAcquisition;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+
+public class SpeechUtil {
+ /**
+ * 从查看模块话术获取话术
+ * @param uid
+ * @param feedId
+ * @return String
+ */
+ public static String getSpeech(Integer feedId) {
+ return TimingAcquisition.speechMap.get(feedId).getText();
+ }
+ /**
+ * 替换话术中的一个数字
+ * @param one
+ * @return String
+ */
+ public static String speechReplaceNum(String text, String one) {
+ return text.replace("【1】", one);
+ }
+
+ /**
+ * 替换话术中的两个数字
+ * @param one
+ * @param two
+ * @return String
+ */
+ public static String speechReplaceNum(String text, String one, String two) {
+ return text.replace("【1】", one).replace("【2】", two);
+ }
+
+ /**
+ * 替换话术中的三个数字
+ * @param one
+ * @param two
+ * @param three
+ * @return String
+ */
+ public static String speechReplaceNum(String text, String one, String two, String three) {
+ return text.replace("【1】", one).replace("【2】", two).replace("【3】", three);
+ }
+
+ /**
+ * 替换话术中的四个数字
+ * @param one
+ * @param two
+ * @param three
+ * @param four
+ * @return String
+ */
+ public static String speechReplaceNum(String text, String one, String two, String three, String four) {
+ return text.replace("【1】", one).replace("【2】", two).replace("【3】", three).replace("【4】", four);
+ }
+
+ /**
+ * 替换话术中的五个数字
+ * @param one
+ * @param two
+ * @param three
+ * @param four
+ * @param five
+ * @return String
+ */
+ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five) {
+ return text.replace("【1】", one).replace("【2】", two).replace("【3】", three)
+ .replace("【4】", four).replace("【5】", five);
+ }
+}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
new file mode 100644
index 0000000..b8d747d
--- /dev/null
+++ b/src/main/resources/application-dev.yml
@@ -0,0 +1,17 @@
+server:
+ port: 8080
+ serlvet:
+ context-type: /innGame
+
+
+#玩家无操作时长,默认下线
+offlineTime: 180000
+
+#对话过期时间
+expireTime: 180000
+
+configFilePath: /home/jiaoyou/projects/innGame/config/
+
+dataFilePath: /home/jiaoyou/projects/innGame/data/
+
+userFilePath: /home/jiaoyou/projects/innGame/user/
\ No newline at end of file
diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml
new file mode 100644
index 0000000..2f90940
--- /dev/null
+++ b/src/main/resources/application-pro.yml
@@ -0,0 +1,17 @@
+server:
+ port: 60023
+ serlvet:
+ context-type: /innGame
+
+
+#玩家无操作时长,默认下线
+offlineTime: 180000
+
+#对话过期时间
+expireTime: 180000
+
+configFilePath: /home/jiaoyou/projects/innGame/config/
+
+dataFilePath: /home/jiaoyou/projects/innGame/data/
+
+userFilePath: /home/jiaoyou/projects/innGame/user/
\ No newline at end of file
diff --git a/src/main/resources/application-uat.yml b/src/main/resources/application-uat.yml
new file mode 100644
index 0000000..36d5071
--- /dev/null
+++ b/src/main/resources/application-uat.yml
@@ -0,0 +1,17 @@
+server:
+ port: 60019
+ serlvet:
+ context-type: /innGame
+
+
+#玩家无操作时长,默认下线
+offlineTime: 180000
+
+#对话过期时间
+expireTime: 180000
+
+configFilePath: /home/jiaoyou/projects/innGame/config/
+
+dataFilePath: /home/jiaoyou/projects/innGame/data/
+
+userFilePath: /home/jiaoyou/projects/innGame/user/
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..3d7808a
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,3 @@
+spring:
+ profiles:
+ active: dev