Browse Source

更新excel下载相关

贾艺驰 4 years ago
parent
commit
c05734cf7e
25 changed files with 537 additions and 97 deletions
  1. 1 0
      common/src/main/java/com/api/common/UtilFun.java
  2. 3 1
      games/src/main/java/com/api/games/controller/GameAnswerController.java
  3. 68 24
      games/src/main/java/com/api/games/controller/GameLogController.java
  4. 20 10
      games/src/main/java/com/api/games/controller/PushLogController.java
  5. 63 20
      games/src/main/java/com/api/games/controller/ScaleLogController.java
  6. 58 18
      games/src/main/java/com/api/games/controller/UserConfigController.java
  7. 2 0
      games/src/main/java/com/api/games/dao/GameAnswerMapper.java
  8. 1 0
      games/src/main/java/com/api/games/dao/PushLogMapper.java
  9. 5 1
      games/src/main/java/com/api/games/dao/mapper/GameAnswerMapper.xml
  10. 1 0
      games/src/main/java/com/api/games/dao/mapper/GameLogMapper.xml
  11. 1 1
      games/src/main/java/com/api/games/dao/mapper/GamePlayTimeMapper.xml
  12. 5 0
      games/src/main/java/com/api/games/dao/mapper/PushLogMapper.xml
  13. 2 1
      games/src/main/java/com/api/games/dao/mapper/UserConfigMapper.xml
  14. 11 0
      games/src/main/java/com/api/games/model/GameLog.java
  15. 18 0
      games/src/main/java/com/api/games/model/GameLogDownload.java
  16. 23 0
      games/src/main/java/com/api/games/model/GameLogDownloadV2.java
  17. 11 0
      games/src/main/java/com/api/games/model/UserConfig.java
  18. 1 0
      games/src/main/java/com/api/games/result/GameInfoResult.java
  19. 5 0
      games/src/main/java/com/api/games/service/GameLogService.java
  20. 6 2
      games/src/main/java/com/api/games/service/PushLogService.java
  21. 2 0
      games/src/main/java/com/api/games/service/ScaleLogService.java
  22. 122 4
      games/src/main/java/com/api/games/service/impl/GameLogServiceImpl.java
  23. 77 10
      games/src/main/java/com/api/games/service/impl/PushLogServiceImpl.java
  24. 10 5
      games/src/main/java/com/api/games/service/impl/ScaleLogServiceImpl.java
  25. 21 0
      games/src/main/java/com/api/games/service/impl/UserConfigServiceImpl.java

+ 1 - 0
common/src/main/java/com/api/common/UtilFun.java

@@ -21,6 +21,7 @@ public class UtilFun {
     public  static  final  String YYYYMMDDHHMMSS3="yyyyMMddHHmmss";
     public  static  final  String YYYYMMDD2="yyyy/MM/dd";
     public  static  final  String YMD="yyyy-MM-dd";
+    public static final String HHMMSS = "HH:mm:ss";
     /**
      * 判断list不为
      *

+ 3 - 1
games/src/main/java/com/api/games/controller/GameAnswerController.java

@@ -52,7 +52,8 @@ public class GameAnswerController extends Ctrl{
         String endTime,
         String version,
         String selected,
-        String gameAnswer
+        String gameAnswer,
+        String deviceId
     ){
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
@@ -70,6 +71,7 @@ public class GameAnswerController extends Ctrl{
         }
         gameLog.setVersion(version);
         gameLog.setSelected(selected);
+        gameLog.setDeviceId(deviceId);
 
         return gameAnswerService.add(gamePlayId, gameLog, gameAnswer);
     }

+ 68 - 24
games/src/main/java/com/api/games/controller/GameLogController.java

@@ -6,7 +6,10 @@ import com.api.core.annotation.PowerEnable;
 import com.api.core.controller.Ctrl;
 import com.api.core.response.Result;
 import com.api.core.response.ResultGenerator;
+import com.api.games.model.GameAnswer;
 import com.api.games.model.GameLog;
+import com.api.games.model.GameLogDownload;
+import com.api.games.model.GameLogDownloadV2;
 import com.api.games.service.GameLogService;
 import io.swagger.annotations.*;
 import org.apache.poi.ss.usermodel.CellType;
@@ -19,9 +22,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
@@ -100,15 +101,29 @@ public class GameLogController extends Ctrl {
     public void downloadFile(@RequestParam(defaultValue = "{}") String search,
                                @RequestParam(defaultValue = "{}") String order,
                                HttpServletResponse response) {
-        List<Map<String, Object>> res = gameLogService.download(search, order);
-        if (res == null || res.size() < 1) return ;
-        Map<String, Object> stat = gameLogService.download(search);
+//        List<Map<String, Object>> res = gameLogService.download(search, order);
+//        if (res == null || res.size() < 1) return ;
+//        Map<String, Object> stat = gameLogService.download(search);
+
+        List<GameLogDownloadV2> res = gameLogService.newDownload(search, order);
+
+        int column = 15;
+
+        int columnPlus = 0;
+        for (GameLogDownloadV2 item : res){
+            if (item.gameAnswers.size() > columnPlus)
+                columnPlus = item.gameAnswers.size();
+        }
+
+        column += columnPlus * 4;
 
-        int column = 14;
         int rowCount = res.size();
         String fileTitle = UtilFun.DateToString(new Date(), UtilFun.YMD) + ".xlsx";
-        String[] title = {"序號","用戶名", "日期", "版本", "序號", "開始時間", "完成時間", "完成度", "抽取數字", "出現數字", "用戶回答", "正誤",
-                "每個答案的反應時間", "總的正確率", "平均反應時間"};
+        String[] title = getTitles(new String[]{"ID","用戶名", "日期", "序號", "版本", "正確率", "錯誤率", "錯失率", "反應時間"
+                , "主觀正確率", "主觀信度", "開始時間", "完成時間", "完成度", "設備碼", "抽取的數字"}, columnPlus);
+
+
+
         File file = new File(fileTitle);
         BufferedInputStream bis = null;
         OutputStream os = null;
@@ -156,63 +171,81 @@ public class GameLogController extends Ctrl {
                         String text = "";
                         switch (j) {
                             case 1: {
-                                text = res.get(i).get("nickname").toString();
+                                text = res.get(i).nickName;
                                 break;
                             }
                             case 2:{
-                                text = res.get(i).get("startTime").toString().substring(0, 10);
+                                text = res.get(i).date;
                                 break;
                             }
                             case 3:{
-                                text = res.get(i).get("version").toString();
+                                text = res.get(i).sign;
                                 break;
                             }
                             case 4:{
-                                text = res.get(i).get("sign").toString();
+                                text = res.get(i).version;
                                 break;
                             }
                             case 5:{
-                                text = res.get(i).get("startTime").toString();
+                                text = res.get(i).rightRate;
                                 break;
                             }
                             case 6:{
-                                text = res.get(i).get("endTime").toString();
+                                text = res.get(i).wrongRate;
                                 break;
                             }
                             case 7:{
-                                text = res.get(i).get("schedule").toString();
+                                text = res.get(i).missRate;
                                 break;
                             }
                             case 8:{
-                                text = String.valueOf(res.get(i).get("selected"));
+                                text = res.get(i).reaction;
                                 break;
                             }
                             case 9:{
-                                text = res.get(i).get("showNum").toString();
+                                text = res.get(i).right;
                                 break;
                             }
                             case 10:{
-                                text = res.get(i).get("answer").toString();
+                                text = res.get(i).trust;
                                 break;
                             }
                             case 11:{
-                                text = String.valueOf(res.get(i).get("answer").toString().equals(res.get(i).get("showNum").toString()) && res.get(i).get("showNum").toString().equals(res.get(i).get("correct").toString()));
+                                text = res.get(i).startTime;
                                 break;
                             }
                             case 12:{
-                                text = res.get(i).get("reaction").toString();
+                                text = res.get(i).finishTime;
                                 break;
                             }
                             case 13:{
-                                text = stat.get("correctRate").toString();
+                                text = res.get(i).finish;
                                 break;
                             }
                             case 14:{
-                                text = stat.get("avgReaction").toString();
+                                text = res.get(i).deviceId;
+                                break;
+                            }
+                            case 15:{
+                                text = res.get(i).number;
                                 break;
                             }
                             default:{
-                                text = "";
+                                int size = (j - 16) / 4;
+
+                                if (res.get(i).gameAnswers.size() > size){
+                                    GameAnswer gameAnswer = res.get(i).gameAnswers.get(size);
+                                    int itemSize = (j - 16) % 4;
+                                    if (itemSize == 0){
+                                        text = gameAnswer.getShowNum().toString();
+                                    }else if(itemSize == 1){
+                                        text = gameAnswer.getAnswer() == 1 ? "按下" : "沒按下";
+                                    }else if(itemSize == 2){
+                                        text = gameAnswer.getCorrect() == 1 ? "正確" : gameAnswer.getCorrect() == 2 ? "錯誤" : "錯失";
+                                    }else if(itemSize == 3){
+                                        text = gameAnswer.getReaction().floatValue() + "ms";
+                                    }
+                                }
                                 break;
                             }
                         }
@@ -278,6 +311,17 @@ public class GameLogController extends Ctrl {
                 logger.error("close exception", e);
             }
         }
+    }
 
+    private String[] getTitles(String[] titles, int count){
+        List<String> temp = Arrays.asList(titles);
+        List<String> result = new ArrayList<>(temp);
+        for (int i = 0; i < count; i ++){
+            result.add("出現的數字" + (i + 1));
+            result.add("用戶回答" + (i + 1));
+            result.add("正誤" + (i + 1));
+            result.add("反應時間" + (i + 1));
+        }
+        return result.toArray(new String[0]);
     }
 }

+ 20 - 10
games/src/main/java/com/api/games/controller/PushLogController.java

@@ -107,13 +107,19 @@ public class PushLogController extends Ctrl {
     }
 
     @PostMapping(value = "/delay/game", name = "推迟游戏")
-    public Result delay(@RequestParam Long gamePlayTimeId, @RequestParam Long gameConfigId, @RequestParam int delayMin){
-        return pushLogService.delayGame(gamePlayTimeId, gameConfigId, delayMin);
+    public Result delay(@RequestParam Long gamePlayTimeId, @RequestParam Long gameConfigId, @RequestParam int delayMin, @RequestParam String deviceId){
+        return pushLogService.delayGame(gamePlayTimeId, gameConfigId, delayMin, deviceId);
     }
 
     @PostMapping(value = "/delay/scale", name = "推迟量表")
-    public Result delayScale(@RequestParam Long gamePlayTimeId, @RequestParam int delayMin){
-        return pushLogService.delayScale(gamePlayTimeId, delayMin);
+    public Result delayScale(@RequestParam Long gamePlayTimeId
+            , @RequestParam int delayMin, @RequestParam String deviceId){
+        return pushLogService.delayScale(gamePlayTimeId, delayMin, deviceId);
+    }
+
+    @PostMapping(value = "/enter", name = "进入推送")
+    public Result enter(@RequestParam Long gamePlayTimeId, @RequestParam String deviceId, @RequestParam Integer type){
+        return pushLogService.enter(gamePlayTimeId, deviceId, type);
     }
 
 //    @PostMapping(value = "/delay/scale", name = "推迟量表")
@@ -147,10 +153,10 @@ public class PushLogController extends Ctrl {
                              HttpServletResponse response) {
         List<Map<String, Object>> res = pushLogService.download(search, order);
 
-        int column = 4;
+        int column = 5;
         int rowCount = res.size();
         String fileTitle = UtilFun.DateToString(new Date(), UtilFun.YMD) + ".xlsx";
-        String[] title = {"序號", "用戶名", "推送時間", "推送狀態", "推送類型"};
+        String[] title = {"序號", "用戶名", "推送日期", "推送時間", "推送狀態", "推送類型"};
         File file = new File(fileTitle);
         BufferedInputStream bis = null;
         OutputStream os = null;
@@ -203,16 +209,20 @@ public class PushLogController extends Ctrl {
                                 text = res.get(i).get("nickname").toString();
                                 break;
                             }
-                            case 2: {
-                                text = res.get(i).get("pushTime").toString().substring(0, 10);
+                            case 2:{
+                                text = res.get(i).get("pushTime").toString().split(" ")[0];
                                 break;
                             }
                             case 3: {
-                                text = res.get(i).get("status").toString();
+                                text = res.get(i).get("pushTime").toString().split(" ")[1];
                                 break;
                             }
                             case 4: {
-                                text = res.get(i).get("type").toString();
+                                text = res.get(i).get("status").toString().equals("1") ? "delay" : res.get(i).get("status").toString().equals("2") ? "expired" : "enter";
+                                break;
+                            }
+                            case 5: {
+                                text = res.get(i).get("type").toString().equals("1") ? "game" : "scale";
                                 break;
                             }
                             default: {

+ 63 - 20
games/src/main/java/com/api/games/controller/ScaleLogController.java

@@ -66,7 +66,8 @@ public class ScaleLogController extends Ctrl {
                       @RequestParam String dinner,
                       @RequestParam String getUp,
                       @RequestParam String sleep,
-                      @RequestParam String work
+                      @RequestParam String work,
+                      @RequestParam String deviceId
         ){
         AuthUser authUser = (AuthUser) authentication.getPrincipal();
         ScaleLog scaleLog = new ScaleLog();
@@ -102,6 +103,7 @@ public class ScaleLogController extends Ctrl {
         scaleLog.setCreateDate(UtilFun.StringToDate(endDate, UtilFun.YYYYMMDDHHMMSS));
         scaleLog.setEventDate(UtilFun.StringToDate(eventDate, UtilFun.YMD));
         scaleLog.setSign(scaleLogService.sign(authUser.getId()));
+        scaleLog.setDeviceId(deviceId);
 
         scaleLogService.save(scaleLog);
         scaleLogService.deletePlayGameId(gamePlayId);
@@ -118,21 +120,42 @@ public class ScaleLogController extends Ctrl {
         int days = (int) ((new Date().getTime() - UtilFun.StringToDate(config.getScaleStart(), UtilFun.YMD).getTime()) / (1000 * 3600 * 24));
         scaleLog.setSign(String.valueOf(days));
         //记录用户填写的属性
-        int success = 0;
-        if(scaleLog.getContact()!=null){
+        float success = 0;
+        if(scaleLog.getContact()!=null && !scaleLog.getContact().equals("沒做")){
             success += 1;
+            if (scaleLog.getContact().split(":").length > 1){
+                scaleLog.setContact(addZero(scaleLog.getContact()));
+            }
         }
-        if(scaleLog.getDinner() !=null){
+
+        if(scaleLog.getDinner() !=null && !scaleLog.getDinner().equals("沒做")){
             success += 1;
+            if (scaleLog.getDinner().split(":").length > 1){
+                scaleLog.setDinner(addZero(scaleLog.getDinner()));
+            }
         }
-        if(scaleLog.getGetUp() != null){
+
+
+        if(scaleLog.getGetUp() != null && !scaleLog.getGetUp().equals("沒做")){
             success += 1;
+            if (scaleLog.getGetUp().split(":").length > 1){
+                scaleLog.setGetUp(addZero(scaleLog.getGetUp()));
+            }
         }
-        if(scaleLog.getSleep()!=null){
+
+
+        if(scaleLog.getSleep()!=null && !scaleLog.getSleep().equals("沒做")){
             success += 1;
+            if (scaleLog.getSleep().split(":").length > 1){
+                scaleLog.setSleep(addZero(scaleLog.getSleep()));
+            }
         }
-        if(scaleLog.getWork() !=null){
+
+        if(scaleLog.getWork() !=null && !scaleLog.getWork().equals("沒做")){
             success += 1;
+            if (scaleLog.getWork().split(":").length > 1){
+                scaleLog.setWork(addZero(scaleLog.getWork()));
+            }
         }
         //计算完成度
         scaleLog.setSchedule(BigDecimal.valueOf( success / 5));
@@ -140,6 +163,19 @@ public class ScaleLogController extends Ctrl {
         return ResultGenerator.genSuccessResult();
     }
 
+    private String addZero(String value){
+        String result = "";
+        String temp = value.split(":")[0];
+        if (temp.length() < 2)
+            temp = "0" + temp;
+        result += temp + ":";
+        temp = value.split(":")[1];
+        if (temp.length() < 2)
+            temp = "0" + temp;
+        result += temp;
+        return result;
+    }
+
     @ApiOperation(value = "量表删除", tags = {"量表"}, notes = "量表删除")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "id", required = true, value = "量表id", dataType = "Long", paramType = "query")
@@ -202,10 +238,10 @@ public class ScaleLogController extends Ctrl {
                              HttpServletResponse response) {
         List<Map<String, Object>> res = scaleLogService.download(search, order);
 
-        int column = 11;
+        int column = 13;
         int rowCount = res.size();
         String fileTitle = UtilFun.DateToString(new Date(), UtilFun.YMD) + ".xlsx";
-        String[] title = {"序號", "用戶名", "日期", "序號", "開始時間", "完成時間", "完成度", "下床", "接觸", "工作", "晚飯", "睡覺"};
+        String[] title = {"ID", "用戶名", "序號", "量表日期", "填寫日期", "開始時間", "完成時間", "完成度", "起床", "和人接觸", "工作", "晚飯", "睡覺", "設備碼"};
         File file = new File(fileTitle);
         BufferedInputStream bis = null;
         OutputStream os = null;
@@ -259,46 +295,53 @@ public class ScaleLogController extends Ctrl {
                                 break;
                             }
                             case 2: {
-                                text = res.get(i).get("eventDate").toString().substring(0, 10);
+                                text = res.get(i).get("sign").toString();
                                 break;
                             }
                             case 3: {
-                                text = res.get(i).get("sign").toString();
+                                text = res.get(i).get("eventDate").toString().substring(0, 10);
                                 break;
                             }
-                            case 4: {
-                                text = res.get(i).get("startDate").toString();
+                            case 4:{
+                                text = res.get(i).get("startDate").toString().split(" ")[0];
                                 break;
                             }
-
                             case 5: {
-                                text = res.get(i).get("createDate").toString();
+                                text = res.get(i).get("startDate").toString().split(" ")[1];
                                 break;
                             }
                             case 6: {
-                                text = res.get(i).get("schedule").toString();
+                                text = res.get(i).get("createDate").toString().split(" ")[1];
                                 break;
                             }
                             case 7: {
-                                text = res.get(i).get("getUp").toString();
+                                text = res.get(i).get("schedule").toString();
                                 break;
                             }
                             case 8: {
-                                text = res.get(i).get("contact").toString();
+                                text = res.get(i).get("getUp").toString();
                                 break;
                             }
                             case 9: {
-                                text = res.get(i).get("work").toString();
+                                text = res.get(i).get("contact").toString();
                                 break;
                             }
                             case 10: {
-                                text = res.get(i).get("dinner").toString();
+                                text = res.get(i).get("work").toString();
                                 break;
                             }
                             case 11: {
+                                text = res.get(i).get("dinner").toString();
+                                break;
+                            }
+                            case 12: {
                                 text = res.get(i).get("sleep").toString();
                                 break;
                             }
+                            case 13:{
+                                text = res.get(i).get("deviceId").toString();
+                                break;
+                            }
                             default: {
                                 text = "";
                                 break;

+ 58 - 18
games/src/main/java/com/api/games/controller/UserConfigController.java

@@ -10,7 +10,9 @@ import com.api.core.config.AuthUser;
 import com.api.core.controller.Ctrl;
 import com.api.core.response.Result;
 import com.api.core.response.ResultGenerator;
+import com.api.games.model.GameConfig;
 import com.api.games.model.UserConfig;
+import com.api.games.service.GameConfigService;
 import com.api.games.service.ScaleLogService;
 import com.api.games.service.UserConfigService;
 import io.swagger.annotations.*;
@@ -28,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +51,8 @@ public class UserConfigController extends Ctrl {
     private UserConfigService userConfigService;
     @Resource
     private UserService userService;
+    @Resource
+    private GameConfigService gameConfigService;
 
     @ApiOperation(value = "用户配置删除", tags = {"用户配置"}, notes = "用户配置删除")
     @ApiImplicitParams({
@@ -55,7 +60,6 @@ public class UserConfigController extends Ctrl {
     })
     @PostMapping(value = "/delete", name = "用户配置删除")
     public Result delete(@RequestParam Long id) {
-
         return userConfigService.delete(id);
     }
 
@@ -161,11 +165,31 @@ public class UserConfigController extends Ctrl {
                              HttpServletResponse response) {
         List<Map<String, Object>> res = userConfigService.download(search, order);
 
-        int column = 13;
+
+        for(Map<String, Object> item : res){
+            String scaleStart = item.get("scaleStart") == null ? null : (String) item.get("scaleStart");
+            String scaleEnd =  item.get("scaleEnd") == null ? null : (String) item.get("scaleEnd");
+            if (scaleStart != null && scaleEnd != null){
+                Calendar current = Calendar.getInstance();
+                Calendar calendarStart = Calendar.getInstance();
+                calendarStart.setTime(UtilFun.StringToDate(scaleStart, UtilFun.YYYYMMDDHHMMSS));
+                Calendar calendarEnd = Calendar.getInstance();
+                calendarEnd.setTime(UtilFun.StringToDate(scaleEnd, UtilFun.YYYYMMDDHHMMSS));
+                if (current.before(calendarStart)){
+                    item.put("status", 0);
+                } else if (current.after(calendarEnd)){
+                    item.put("status", 2);
+                } else if(current.after(calendarStart) && current.before(calendarEnd)){
+                    item.put("status", 1);
+                }
+            }
+        }
+
+        int column = 15;
         int rowCount = res.size();
         String fileTitle = UtilFun.DateToString(new Date(), UtilFun.YMD) + ".xlsx";
-        String[] title = {"序號", "用戶名", "狀態", "密碼", "性別", "創建日期", "開始日期", "結束日期", "量表提示時間", "數字顯示的時長", "數據交換間隔",
-                "正確數字出現次數", "隨機數字出現次數", "小遊戲練習結束進入測試的時長"};
+        String[] title = {"ID", "用戶名", "狀態", "創建日期", "開始日期", "結束日期", "量表提示時間", "數字顯示的時長", "數交換間隔",
+                "正確數字出現次數", "隨機數字出現次數", "練習結束進入測試的時長", "每天遊戲次數", "遊戲版本", "遊戲時間段", "登出"};
         File file = new File(fileTitle);
         BufferedInputStream bis = null;
         OutputStream os = null;
@@ -218,52 +242,68 @@ public class UserConfigController extends Ctrl {
                                 break;
                             }
                             case 2: {
-                                text = res.get(i).get("status").toString();
+                                String status = res.get(i).get("status").toString();
+                                if (status.equals("0"))
+                                    text = "waiting";
+                                else if(status.equals("1"))
+                                    text = "processing";
+                                else
+                                    text = "end";
                                 break;
                             }
                             case 3: {
-                                text = res.get(i).get("password").toString();
+                                text = res.get(i).get("createTime").toString();
                                 break;
                             }
                             case 4: {
-                                text = res.get(i).get("gender").toString();
+                                text = res.get(i).get("scaleStart").toString();
                                 break;
                             }
-
                             case 5: {
-                                text = res.get(i).get("createTime").toString();
+                                text = res.get(i).get("scaleEnd").toString();
                                 break;
                             }
                             case 6: {
-                                text = res.get(i).get("scaleStart").toString();
+                                text = res.get(i).get("scaleTime").toString();
                                 break;
                             }
                             case 7: {
-                                text = res.get(i).get("scaleEnd").toString();
+                                text = res.get(i).get("showTime").toString();
                                 break;
                             }
                             case 8: {
-                                text = res.get(i).get("scaleTime").toString();
+                                text = res.get(i).get("hideTime").toString();
                                 break;
                             }
                             case 9: {
-                                text = res.get(i).get("showTime").toString();
+                                text = res.get(i).get("correct").toString();
                                 break;
                             }
                             case 10: {
-                                text = res.get(i).get("hideTime").toString();
+                                text = res.get(i).get("supporting").toString();
                                 break;
                             }
                             case 11: {
-                                text = res.get(i).get("correct").toString();
+                                text = res.get(i).get("practice").toString();
                                 break;
                             }
                             case 12: {
-                                text = res.get(i).get("supporting").toString();
+                                text = res.get(i).get("gameCount").toString();
                                 break;
                             }
-                            case 13: {
-                                text = res.get(i).get("practice").toString();
+                            case 13:{
+                                text = res.get(i).get("version").toString();
+                                break;
+                            }
+                            case 14:{
+                                List<GameConfig> gameConfigList = (List<GameConfig>)gameConfigService.listUid((Long) res.get(i).get("userId")).getData();
+                                text = "";
+                                for (GameConfig item: gameConfigList)
+                                    text += item.getStartTime() + "-" + item.getEndTime() + " ";
+                                break;
+                            }
+                            case 15: {
+                                text = res.get(i).get("loginOut").toString().equals("0") ? "yes" : "no";
                                 break;
                             }
                             default: {

+ 2 - 0
games/src/main/java/com/api/games/dao/GameAnswerMapper.java

@@ -13,5 +13,7 @@ public interface GameAnswerMapper extends Mapper<GameAnswer> {
 
     Map<String, Object> statistics(Map<String, Object> params);
 
+    Float getAvgReaction(Long id);
+
     List<Map<String, Object>> list(Map<String, Object> params, Map<String, Object> order);
 }

+ 1 - 0
games/src/main/java/com/api/games/dao/PushLogMapper.java

@@ -9,4 +9,5 @@ import java.util.Map;
 public interface PushLogMapper extends Mapper<PushLog> {
     List<Map<String, Object>> list(Map<String, Object> params, Map<String, Object> order);
     List<PushLog> listByGamePlayId(Long id);
+    void deleteByUid(Long uid);
 }

+ 5 - 1
games/src/main/java/com/api/games/dao/mapper/GameAnswerMapper.xml

@@ -13,6 +13,10 @@
     <result column="show_num" jdbcType="INTEGER" property="showNum" />
   </resultMap>
 
+    <select id="getAvgReaction" resultType="float">
+        SELECT avg(reaction) FROM game_answer where game_log_id = #{id} and reaction > 0;
+    </select>
+
     <select id="listByGameIdNew" resultMap="BaseResultMap">
         select * from game_answer where game_log_id =#{id}
     </select>
@@ -52,7 +56,7 @@
 
     </select>
     <select id="list" resultType="com.api.common.mybatis.ResultMap">
-       SELECT *  fROM (select * from game_answer) a
+       SELECT *,gl.id as gid  fROM (select * from game_answer) a
          left join game_log gl on (gl.id = a.game_log_id)
          left join sys_user sy on (sy.id = gl.user_id)
          left join user_config uc on (uc.user_id = gl.user_id)

+ 1 - 0
games/src/main/java/com/api/games/dao/mapper/GameLogMapper.xml

@@ -18,6 +18,7 @@
     <result column="selected" jdbcType="VARCHAR" property="selected" />
     <result column="exercise" jdbcType="INTEGER" property="exercise" />
   </resultMap>
+
     <select id="list" resultType="com.api.common.mybatis.ResultMap">
         select u.nickname,g.* from game_log g
             left join sys_user u on (g.user_id = u.id)

+ 1 - 1
games/src/main/java/com/api/games/dao/mapper/GamePlayTimeMapper.xml

@@ -17,7 +17,7 @@
       select * from game_play_time where uid = #{uid} order by game_time
     </select>
     <select id="listUidAndInPeriod" resultMap="BaseResultMap">
-        SELECT * FROM game_play_time where uid=#{uid} and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &gt;= str_to_date(#{startDate}, '%Y-%m-%d %H:%i:%s') and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &lt;= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s');
+        SELECT * FROM game_play_time where uid=#{uid} and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &gt;= str_to_date(#{startDate}, '%Y-%m-%d %H:%i:%s') and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &lt;= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s') and type = 0;
     </select>
     <select id="getScalePlayTime" resultMap="BaseResultMap">
         SELECT * FROM game_play_time where uid = #{uid} and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &gt;= str_to_date(#{startDate}, '%Y-%m-%d %H:%i:%s') and str_to_date(game_time, '%Y-%m-%d %H:%i:%s') &lt;= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s') and type = 1

+ 5 - 0
games/src/main/java/com/api/games/dao/mapper/PushLogMapper.xml

@@ -14,6 +14,11 @@
     <result column="status" jdbcType="INTEGER" property="status" />
     <result column="device_id" jdbcType="VARCHAR" property="deviceId" />
   </resultMap>
+
+  <delete id="deleteByUid">
+    delete from push_log where uid = #{uid}
+  </delete>
+
     <select id="listByGamePlayId" resultMap="BaseResultMap">
       select * from push_log where msg_id = #{id}
     </select>

+ 2 - 1
games/src/main/java/com/api/games/dao/mapper/UserConfigMapper.xml

@@ -17,13 +17,14 @@
     <result column="practice" jdbcType="INTEGER" property="practice" />
     <result column="game_count" jdbcType="INTEGER" property="gameCount" />
     <result column="version" jdbcType="VARCHAR" property="version" />
+    <result column="exercise_right" jdbcType="INTEGER" property="exerciseRight" />
     <result column="exercise" jdbcType="INTEGER" property="exercise" />
     <result column="login_out" jdbcType="INTEGER" property="loginOut" />
   </resultMap>
     <select id="list" resultType="com.api.common.mybatis.ResultMap">
         select u.nickname,u.password,u.create_time,u.enable,u.type,u.id,u.status,u.gender,u.openId , c.id as
         configId,c.user_id,c.scale_end ,c.scale_start,
-        c.scale_time,c.show_time,c.hide_time,c.correct,c.supporting,c.practice,c.game_count,c.version,c.exercise,c.login_out
+        c.scale_time,c.show_time,c.hide_time,c.correct,c.supporting,c.practice,c.game_count,c.version,c.exercise_right,c.exercise,c.login_out
         from (select * from sys_user where type = 1) u
         left join user_config c on (u.id = c.user_id ) where 1=1
         <if test="params.nickname !=null and params.nickname !=''">

+ 11 - 0
games/src/main/java/com/api/games/model/GameLog.java

@@ -38,8 +38,19 @@ public class GameLog implements Serializable {
 
     private Integer exercise;
 
+    @Column(name = "device_id")
+    private String deviceId;
+
     private static final long serialVersionUID = 1L;
 
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
     /**
      * @return id
      */

+ 18 - 0
games/src/main/java/com/api/games/model/GameLogDownload.java

@@ -0,0 +1,18 @@
+package com.api.games.model;
+
+public class GameLogDownload {
+    public String sign;
+    public String userName;
+    public String date;
+    public String version;
+    public String startDate;
+    public String endDate;
+    public String schedule;
+    public String number;
+    public String showNumber;
+    public String answer;
+    public String right;
+    public String sumRight;
+    public String reaction;
+    public String avgReaction;
+}

+ 23 - 0
games/src/main/java/com/api/games/model/GameLogDownloadV2.java

@@ -0,0 +1,23 @@
+package com.api.games.model;
+
+import java.util.List;
+
+public class GameLogDownloadV2 {
+    public String nickName;
+    public String date;
+    public String sign;
+    public String version;
+    public String rightRate;
+    public String wrongRate;
+    public String missRate;
+    public String reaction;
+    public String right;
+    public String trust;
+    public String startTime;
+    public String finishTime;
+    public String finish;
+    public String deviceId;
+    public String number;
+
+    public List<GameAnswer> gameAnswers;
+}

+ 11 - 0
games/src/main/java/com/api/games/model/UserConfig.java

@@ -38,6 +38,9 @@ public class UserConfig implements Serializable {
 
     private String version;
 
+    @Column(name = "exercise_right")
+    private Integer exerciseRight;
+
     private Integer exercise;
 
     @Column(name = "login_out")
@@ -240,4 +243,12 @@ public class UserConfig implements Serializable {
     public void setLoginOut(Integer loginOut) {
         this.loginOut = loginOut;
     }
+
+    public Integer getExerciseRight() {
+        return exerciseRight;
+    }
+
+    public void setExerciseRight(Integer exerciseRight) {
+        this.exerciseRight = exerciseRight;
+    }
 }

+ 1 - 0
games/src/main/java/com/api/games/result/GameInfoResult.java

@@ -18,6 +18,7 @@ public class GameInfoResult {
     public int correctNumberOccurrenceNumber;//正確數字出現次數
     public int errorNumberOccurrenceNumber;//錯誤數字出現次數
     public long practiseDuration; //用戶熱身時長
+    public int practiseRightNumber;
     public int practiseOccurrenceNumber;//用戶熱身數字出現次數
 
     public static int convertVersion(String version){

+ 5 - 0
games/src/main/java/com/api/games/service/GameLogService.java

@@ -2,6 +2,8 @@ package com.api.games.service;
 import com.api.core.response.Result;
 import com.api.games.model.GameLog;
 import com.api.core.service.Service;
+import com.api.games.model.GameLogDownload;
+import com.api.games.model.GameLogDownloadV2;
 
 import java.util.List;
 import java.util.Map;
@@ -25,5 +27,8 @@ public interface GameLogService extends Service<GameLog> {
     Result notPerformed();
 
     List<Map<String, Object>> download(String search, String order);
+
+    List<GameLogDownloadV2> newDownload(String search, String orderMap);
+
     Map<String,Object> download(String search);
 }

+ 6 - 2
games/src/main/java/com/api/games/service/PushLogService.java

@@ -16,9 +16,13 @@ public interface PushLogService extends Service<PushLog> {
 
     Result needPlayGame(long userId);
 
+    void deleteByUid(long userId);
+
     List<Map<String, Object>> download(String search, String order);
 
-    Result delayGame(Long gamePlayTimeId, Long gameConfigId, int delayMin);
+    Result delayGame(Long gamePlayTimeId, Long gameConfigId, int delayMin, String deviceId);
+
+    Result delayScale(Long gamePlayTimeId, int delayMin, String deviceId);
 
-    Result delayScale(Long gamePlayTimeId, int delayMin);
+    Result enter(Long gamePlayTimeId, String deviceId, Integer type);
 }

+ 2 - 0
games/src/main/java/com/api/games/service/ScaleLogService.java

@@ -12,6 +12,8 @@ import java.util.Map;
  */
 public interface ScaleLogService extends Service<ScaleLog> {
 
+    void deleteByUid(Long id);
+
     Result list(String search, String order, Integer page, Integer size);
     /**
      * 监测当天应该完成但是未完成的用户,添加一条未测记录

+ 122 - 4
games/src/main/java/com/api/games/service/impl/GameLogServiceImpl.java

@@ -1,13 +1,17 @@
 package com.api.games.service.impl;
 
 import com.api.common.JSONUtils;
+import com.api.common.UtilFun;
 import com.api.core.response.Result;
 import com.api.core.response.ResultGenerator;
 import com.api.core.service.AbstractService;
 import com.api.games.dao.GameAnswerMapper;
 import com.api.games.dao.GameLogMapper;
 import com.api.games.dao.GamePlayTimeMapper;
+import com.api.games.model.GameAnswer;
 import com.api.games.model.GameLog;
+import com.api.games.model.GameLogDownload;
+import com.api.games.model.GameLogDownloadV2;
 import com.api.games.service.GameLogService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -15,10 +19,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.*;
 
 
 /**
@@ -51,10 +54,49 @@ public class GameLogServiceImpl extends AbstractService<GameLog> implements Game
 
         PageHelper.startPage(page, size);
         List<Map<String, Object>> res = gameLogMapper.list(params, order);
+
+        for (Map<String, Object> item : res){
+            long id = (Long) item.get("id");
+            List<GameAnswer> list = gameAnswerMapper.listByGameIdNew((int)id);
+            item.put("wrongRate", getRate(list, 2));
+            item.put("missRate", getRate(list, 3));
+            item.put("avgReaction", getAvgReaction(list));
+        }
+
         PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(res);
         return ResultGenerator.genSuccessResult(pageInfo);
     }
 
+    private float getAvgReaction(List<GameAnswer> list){
+        if (list != null) {
+            float size = 0;
+            float reaction = 0;
+            for (GameAnswer item : list){
+                if (item.getReaction().intValue() != -1) {
+                    reaction += item.getReaction().floatValue();
+                    size += 1;
+                }
+            }
+            return reaction == 0 ? 0 : reaction / size;
+        } else {
+            return 0;
+        }
+    }
+
+    private float getRate(List<GameAnswer> list, int answer){
+        if (list != null) {
+            float size = 0;
+            for (GameAnswer item : list){
+                if (item.getCorrect() == answer) {
+                    size += 1;
+                }
+            }
+            return size == 0 ? 0 : size / list.size();
+        } else {
+            return 0;
+        }
+    }
+
     @Override
     public Result detail(Integer id) {
 //        List<Map<String, Object>> res = gameAnswerMapper.listByGameId(id);
@@ -96,6 +138,82 @@ public class GameLogServiceImpl extends AbstractService<GameLog> implements Game
     }
 
     @Override
+    public List<GameLogDownloadV2> newDownload(String search, String orderMap) {
+        Map<String, Object> params = JSONUtils.json2map(search);
+        Map<String, Object> order = JSONUtils.json2map(orderMap);
+
+        for (String key : order.keySet()) {
+            if (order.get(key) != null && order.get(key).equals("ascending")) order.put(key, "asc");
+            if (order.get(key) != null && order.get(key).equals("descending")) order.put(key, "desc");
+        }
+
+        List<Map<String, Object>> gameLogs = gameLogMapper.list(params, order);
+
+
+        List<GameLogDownloadV2> result = new ArrayList<>();
+
+        for (int i = 0; i < gameLogs.size(); i ++){
+            GameLogDownloadV2 item = new GameLogDownloadV2();
+            Map<String, Object> gameLog = gameLogs.get(i);
+            item.nickName = gameLog.get("nickname").toString();
+
+            Date date = new Date(((Timestamp) gameLog.get("startTime")).getTime());
+            Date endDate = new Date(((Timestamp) gameLog.get("endTime")).getTime());
+            item.date = UtilFun.DateToString(date, UtilFun.YMD);
+            item.sign = gameLog.get("sign").toString();
+            item.version = gameLog.get("version").toString();
+            item.rightRate = (((BigDecimal)gameLog.get("realCorrectRate")).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() * 100) + "%";
+            item.right = (((BigDecimal)gameLog.get("correctRate")).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() * 100) + "%";
+            item.trust = (((BigDecimal)gameLog.get("confidence")).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() * 100) + "%";
+            item.startTime = UtilFun.DateToString(date, UtilFun.HHMMSS);
+            item.finishTime = UtilFun.DateToString(endDate, UtilFun.HHMMSS);
+            item.finish =  (((BigDecimal)gameLog.get("schedule")).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() * 100) + "%";
+            item.deviceId = gameLog.get("deviceId").toString();
+            item.number = gameLog.get("selected").toString();
+
+            item.gameAnswers = gameAnswerMapper.listByGameIdNew(((Long)gameLog.get("id")).intValue());
+
+            item.wrongRate = (getRate(item.gameAnswers, 2) * 100) + "%";
+            item.missRate = (getRate(item.gameAnswers, 3) * 100) + "%";
+
+            item.reaction = getAvgReaction(item.gameAnswers) + " ms";
+
+            result.add(item);
+        }
+
+//        List<Map<String, Object>> logs = gameAnswerMapper.list(params, order);
+//
+//        List<GameLogDownload> result = new ArrayList<>();
+//
+//        for (int i = 0; i < logs.size(); i ++){
+//            GameLogDownload item = new GameLogDownload();
+//            item.sign = (String) logs.get(i).get("sign");
+//            item.userName = (String) logs.get(i).get("nickname");
+//            item.version = (String) logs.get(i).get("version");
+//
+//            Date date = new Date(((Timestamp) logs.get(i).get("startTime")).getTime());
+//            Date end = new Date(((Timestamp) logs.get(i).get("endTime")).getTime());
+//            item.date = UtilFun.DateToString(date, UtilFun.YMD);
+//            item.startDate = UtilFun.DateToString(date, UtilFun.HHMMSS);
+//            item.endDate = UtilFun.DateToString(end, UtilFun.HHMMSS);
+//
+//            item.schedule = String.valueOf((((BigDecimal)logs.get(i).get("schedule")).floatValue() * 100));
+//            item.number = (String) logs.get(i).get("selected");
+//            item.showNumber = String.valueOf((Integer) logs.get(i).get("showNum"));
+//            item.answer = ((Integer) logs.get(i).get("answer")) == 1 ? "按下" : "没按下";
+//
+//            int right = (Integer) logs.get(i).get("correct");
+//            item.right = right == 1 ? "正确" : right == 2 ? "错误" : "错失";
+//            item.sumRight = String.valueOf((((BigDecimal)logs.get(i).get("correctRate")).floatValue() * 100));
+//            item.reaction = String.valueOf((((BigDecimal)logs.get(i).get("reaction")).intValue()));
+//            item.avgReaction = String.valueOf(gameAnswerMapper.getAvgReaction((Long)logs.get(i).get("gid")));
+//            result.add(item);
+//        }
+
+        return result;
+    }
+
+    @Override
     public List<Map<String, Object>> download(String search,String ordermap) {
         Map<String, Object> params = JSONUtils.json2map(search);
         Map<String, Object> order = JSONUtils.json2map(ordermap);

+ 77 - 10
games/src/main/java/com/api/games/service/impl/PushLogServiceImpl.java

@@ -45,6 +45,11 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
     private SimpleDateFormat simpleDateFormatGameConfig = new SimpleDateFormat("HH:mm");
 
     @Override
+    public void deleteByUid(long userId) {
+        pushLogMapper.deleteByUid(userId);
+    }
+
+    @Override
     public Result list(String search, String ordermap, Integer page, Integer size) {
         Map<String, Object> params = JSONUtils.json2map(search);
         Map<String, Object> order = JSONUtils.json2map(ordermap);
@@ -69,13 +74,17 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
         UserConfig config = userConfigMapper.findByUid(userId);
 
         if (config != null && config.getScaleStart() != null && config.getScaleEnd() != null){
-
             try {
                 Date scaleStart = simpleDateFormatScale.parse(config.getScaleStart());
                 Date scaleEnd = simpleDateFormatScale.parse(config.getScaleEnd());
+                Calendar scaleEndCalendarTop = Calendar.getInstance();
+                scaleEndCalendarTop.setTime(scaleEnd);
+                scaleEndCalendarTop.add(Calendar.DATE, 1);
+                scaleEnd = scaleEndCalendarTop.getTime();
                 if (currentDate.getTime() >= scaleStart.getTime() && currentDate.getTime() <= scaleEnd.getTime()){
                     //当前处于量表测试期间
                     //游戏逻辑处理
+                    System.out.println(userId + "此用户目前在测量时间内");
                     GameConfig gameConfig = inThePeriod(gameConfigMapper.listUid(userId), currentDate);
                     if (gameConfig != null){
                         Calendar scaleStartCalendar = Calendar.getInstance();
@@ -104,6 +113,7 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
                                 result.correctNumberOccurrenceNumber = config.getCorrect();
                                 result.errorNumberOccurrenceNumber = config.getSupporting();
                                 result.practiseDuration = config.getPractice();
+                                result.practiseRightNumber = config.getExerciseRight();
                                 result.practiseOccurrenceNumber = config.getExercise();
 
                                 String[] versionInfo = config.getVersion().split(",");
@@ -128,7 +138,7 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
                                         }
                                     }
                                 }
-
+                                System.out.println(userId + "此用户需要做游戏");
                                 return ResultGenerator.genSuccessResult(result);
                             }
                         }
@@ -144,6 +154,11 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
                     List<GamePlayTime> gamePlayTime = gamePlayTimeMapper.getScalePlayTime(userId, simpleDateFormatScale.format(startDate.getTime()), simpleDateFormatScale.format(endDate.getTime()));
                     if (gamePlayTime != null && gamePlayTime.size() > 0){
                         GamePlayTime playTime = gamePlayTime.get(0);
+                        if (pushedThreeTimes(playTime.getId()))
+                            return ResultGenerator.genSuccessResult(result);
+
+                        System.out.println(userId + "此用户需要做量表");
+
                         result.needDoGame = true;
                         result.playGameType = 1;
                         result.playGameId = playTime.getId();
@@ -160,10 +175,9 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
     }
 
     @Override
-    public Result delayScale(Long gamePlayTimeId, int delayMin) {
+    public Result delayScale(Long gamePlayTimeId, int delayMin, String deviceId) {
         if (gamePlayTimeId != null){
-            List<PushLog> pushLogs = pushLogMapper.listByGamePlayId(gamePlayTimeId);
-            if (pushLogs != null && pushLogs.size() >=3){
+            if (pushedThreeTimes(gamePlayTimeId)){
                 return new Result("已經推遲過三次,請盡快完成量表");
             }else{
                 GamePlayTime gamePlayTime = gamePlayTimeMapper.selectByPrimaryKey(gamePlayTimeId);
@@ -181,12 +195,24 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
                         pushLog.setPushTime(new Date());
                         pushLog.setUid(gamePlayTime.getUid());
                         pushLog.setType(2);
-                        pushLog.setDeviceId("");
+                        pushLog.setDeviceId(deviceId);
                         pushLog.setMsgId(gamePlayTimeId + "");
                         pushLog.setStatus(ConstUser.PUSH_DELAY);
                         pushLogMapper.insert(pushLog);
                         gamePlayTime.setGameTime(UtilFun.DateToString(newTime.getTime(), UtilFun.YYYYMMDDHHMMSS));
                         gamePlayTimeMapper.updateByPrimaryKey(gamePlayTime);
+
+                        if (pushedThreeTimes(gamePlayTimeId)){
+                            pushLog = new PushLog();
+                            pushLog.setPushTime(new Date());
+                            pushLog.setUid(gamePlayTime.getUid());
+                            pushLog.setType(2);
+                            pushLog.setDeviceId(deviceId);
+                            pushLog.setMsgId(gamePlayTimeId + "");
+                            pushLog.setStatus(ConstUser.PUSH_NO);
+                            pushLogMapper.insert(pushLog);
+                        }
+
                         return ResultGenerator.genSuccessResult();
                     }
                 }
@@ -197,7 +223,21 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
     }
 
     @Override
-    public Result delayGame(Long gamePlayTimeId, Long gameConfigId, int delayMin) {
+    public Result enter(Long gamePlayTimeId, String deviceId, Integer type) {
+        GamePlayTime gamePlayTime = gamePlayTimeMapper.selectByPrimaryKey(gamePlayTimeId);
+        PushLog pushLog = new PushLog();
+        pushLog.setPushTime(new Date());
+        pushLog.setUid(gamePlayTime.getUid());
+        pushLog.setType(type);
+        pushLog.setDeviceId(deviceId);
+        pushLog.setMsgId(gamePlayTimeId + "");
+        pushLog.setStatus(ConstUser.PUSH_ING);
+        pushLogMapper.insert(pushLog);
+        return ResultGenerator.genSuccessResult();
+    }
+
+    @Override
+    public Result delayGame(Long gamePlayTimeId, Long gameConfigId, int delayMin, String deviceId) {
         if (gamePlayTimeId != null && gameConfigId != null){
             GamePlayTime gamePlayTime = gamePlayTimeMapper.selectByPrimaryKey(gamePlayTimeId);
             GameConfig gameConfig = gameConfigMapper.selectByPrimaryKey(gameConfigId);
@@ -220,14 +260,24 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
                         pushLog.setPushTime(new Date());
                         pushLog.setUid(gameConfig.getUid());
                         pushLog.setType(1);
-                        pushLog.setDeviceId(gameConfigId + "");
+                        pushLog.setDeviceId(deviceId);
                         pushLog.setMsgId(gamePlayTimeId + "");
                         pushLog.setStatus(ConstUser.PUSH_DELAY);
                         pushLogMapper.insert(pushLog);
                         gamePlayTimeMapper.updateByPrimaryKey(gamePlayTime);
                         return ResultGenerator.genSuccessResult();
-                    }else
-                        return new Result("無法推遲相應時間,請盡快完成遊戲");
+                    }else {
+                        PushLog pushLog = new PushLog();
+                        pushLog.setPushTime(new Date());
+                        pushLog.setUid(gameConfig.getUid());
+                        pushLog.setType(1);
+                        pushLog.setDeviceId(deviceId);
+                        pushLog.setMsgId(gamePlayTimeId + "");
+                        pushLog.setStatus(ConstUser.PUSH_NO);
+                        pushLogMapper.insert(pushLog);
+                        gamePlayTimeMapper.deleteByPrimaryKey(gamePlayTime.getId());
+                        return new Result("你選擇的延遲的時間點已超過該時間段結束前10分鐘,該時間段結束前10分鐘,將停止推送,無法進入該時間段的測試");
+                    }
 
 
                 } catch (Exception e){
@@ -254,6 +304,23 @@ public class PushLogServiceImpl extends AbstractService<PushLog> implements Push
         return pushLogMapper.list(params,order);
     }
 
+
+    private boolean pushedThreeTimes(long gamePlayTimeId){
+        List<PushLog> pushLogs = pushLogMapper.listByGamePlayId(gamePlayTimeId);
+        List<PushLog> pushLogsDelay = new ArrayList<>();
+        if(pushLogs != null && pushLogs.size() < 3){
+            return false;
+        }else if (pushLogs != null){
+            for (PushLog pushLog : pushLogs)
+                if (pushLog.getStatus() == ConstUser.PUSH_DELAY)
+                    pushLogsDelay.add(pushLog);
+            if (pushLogsDelay.size() >= 3)
+                return true;
+        }
+
+        return false;
+    }
+
     private String getRandomVersion(String[] versions){
         return versions[(int)(Math.random() * versions.length)];
     }

+ 10 - 5
games/src/main/java/com/api/games/service/impl/ScaleLogServiceImpl.java

@@ -13,6 +13,7 @@ import com.api.games.dao.UserConfigMapper;
 import com.api.games.model.GamePlayTime;
 import com.api.games.model.PushLog;
 import com.api.games.model.ScaleLog;
+import com.api.games.model.UserConfig;
 import com.api.games.service.ScaleLogService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -50,15 +51,19 @@ public class ScaleLogServiceImpl extends AbstractService<ScaleLog> implements Sc
     @Override
     public Result listOverDate(Long uid){
         Calendar calendar = Calendar.getInstance();
-        calendar.add(Calendar.DATE, -1);
-        calendar.set(Calendar.HOUR_OF_DAY, 23);
-        calendar.set(Calendar.MINUTE, 59);
-        calendar.set(Calendar.SECOND, 59);
-        calendar.set(Calendar.MILLISECOND, 999);
+        calendar.add(Calendar.HOUR_OF_DAY, -2);
         return ResultGenerator.genSuccessResult(gamePlayTimeMapper.getScalePlayTime(uid, "2000-01-01 00:00:00", UtilFun.DateToString(calendar.getTime(), UtilFun.YYYYMMDDHHMMSS)));
     }
 
     @Override
+    public void deleteByUid(Long id) {
+        List<ScaleLog> scaleLogs = scaleLogMapper.listByUid(id);
+        for (ScaleLog item : scaleLogs){
+            deleteById(item.getId());
+        }
+    }
+
+    @Override
     public Result list(String search, String ordermap, Integer page, Integer size) {
         Map<String, Object> params = JSONUtils.json2map(search);
         Map<String, Object> order = JSONUtils.json2map(ordermap);

+ 21 - 0
games/src/main/java/com/api/games/service/impl/UserConfigServiceImpl.java

@@ -53,6 +53,10 @@ public class UserConfigServiceImpl extends AbstractService<UserConfig> implement
     private GameLogMapper gameLogMapper;
     @Resource
     private GamePlayTimeMapper gamePlayTimeMapper;
+    @Resource
+    private ScaleLogMapper scaleLogMapper;
+    @Resource
+    private GameAnswerMapper gameAnswerMapper;
 
     @Resource
     private PushLogMapper pushLogMapper;
@@ -148,10 +152,25 @@ public class UserConfigServiceImpl extends AbstractService<UserConfig> implement
 
     @Override
     public Result delete(Long id) {
+        List<GameLog> gameLogs = gameLogMapper.listUid(id);
+        for (GameLog log : gameLogs){
+            List<GameAnswer> gameAnswers = gameAnswerMapper.listByGameIdNew(log.getId().intValue());
+            for (GameAnswer gameAnswer : gameAnswers)
+                gameAnswerMapper.deleteByPrimaryKey(gameAnswer.getId());
+            gameLogMapper.deleteByPrimaryKey(log.getId());
+        }
+
+        List<ScaleLog> scaleLogList = scaleLogMapper.listByUid(id);
+        for (ScaleLog log : scaleLogList)
+            scaleLogMapper.deleteByPrimaryKey(log.getId());
+
+        pushLogMapper.deleteByUid(id);
+
         gameConfigMapper.deleteUid(id);
         userConfigMapper.deleteByUid(id);
         userMapper.deleteByPrimaryKey(id);
         userRoleMapper.deleteByUid(id);
+
         return ResultGenerator.genSuccessResult();
     }
 
@@ -372,8 +391,10 @@ public class UserConfigServiceImpl extends AbstractService<UserConfig> implement
         try {
             Calendar scaleStartCalendar = Calendar.getInstance();
             scaleStartCalendar.setTime(sdfScaleDate.parse(scaleStart));
+            scaleStartCalendar.add(Calendar.DATE, 1);
             Calendar scaleEndCalendar = Calendar.getInstance();
             scaleEndCalendar.setTime(sdfScaleDate.parse(scaleEnd));
+            scaleEndCalendar.add(Calendar.DATE, 1);
 
             if (scaleStartCalendar.equals(scaleEndCalendar))
                 result.add(new GamePlayTime(uid, sdfScaleDate.format(mergeDate(scaleStartCalendar, sdfScaleTime.parse(scaleTime)).getTime()), GamePlayTime.TYPE_SCALE));