Explorar o código

校验房间过时

wuweihao %!s(int64=3) %!d(string=hai) anos
pai
achega
ec50c4b3ff

+ 0 - 72
gis_application/src/main/resources/sh/run.sh

@@ -1,72 +0,0 @@
-#!/bin/sh
-APP_NAME=museum_capital_tts.jar
-APP_PORT=8008
-APP_EVN=sit   #执行环境
-APP_ORDER=$1   #执行方法  start|stop|restart
-APP_OS=win  # 系统类型 linux|win
-# 获取线程号
-APP_PID=`netstat -ano | grep $APP_PORT | grep LISTENING | awk '{print $5}'`
-
-
-# 启动命令
-startApp(){
-    if [ ${APP_PID} ];
-    then
-    	echo "程序已经在运行了"
-    else
-    	echo "执行 start 方法"
-    	nohup java -Djava.net.preferIPv4Stack=true -jar -Xmx3072M -Xms512M ./$APP_NAME --spring.profiles.active=$APP_EVN --server.port=$APP_PORT & echo $! > tpid
-	echo Start Success!
-fi
-}
-
-# 停止命令
-stopApp(){
-    echo "执行 stop 方法"
-    if [ ${APP_PID} ]; 
-	then
-		echo $APP_NAME "存在,执行 stop 方法"
-		if [ ${APP_OS} == "linux" ];
-		then
-			kill -9 ${APP_PID} && echo 'Linux Kill Process!'
-		else
-			cmd "/C TASKKILL /F /PID $APP_PID"
-			echo 'Win Kill Process!'
-		fi
-	else
-		echo $APP_NAME 没有运行
-    fi
-}
-
-# 重启命令
-restartApp(){
-    echo " 1 执行 restart 方法"
-	stopApp
-	APP_PID=''  #将进程号置空
-	sleep 2
-	echo "进程号:" ${APP_PID} 
-	echo " 2 执行 restart 方法"
-	startApp
-}
-
-# 判断执行命令 取第一个参数
-case $APP_ORDER in
-    "start")
-        startApp
-		exit 0
-        ;;
-    "stop")
-        stopApp
-		exit 1
-        ;;
-	"restart")
-		restartApp
-		exit 2
-	;;
-    *)
-     echo "Unknown inupt!"
-     exit 3
-     ;;
-esac
-
-

+ 0 - 11
gis_application/src/main/resources/sh/shutdown.sh

@@ -1,11 +0,0 @@
-#!/bin/bash
-RESOURCE_NAME=army_chongqing_college.jar
-   Pid=`awk '{print $1}' tpid`
-
-if [ ${Pid} ]; then
-kill -9 $Pid
-echo 'Kill Process!'
-else
-echo 'Stop failed!'
-fi
-

+ 0 - 123
gis_application/src/main/resources/sh/startJar.sh

@@ -1,123 +0,0 @@
-APP_NAME=
-APP_DEBUG=
-
-usage() {
-    echo "case: sh run.sh [start|stop|restart|status]"
-    echo "请类似这样执行 ./*.sh start   or  ./*sh restart"
-    exit 1
-}
-
-checkEnv(){
-      if [ -z "${APP_NAME}" ] || [ -z "${APP_DEBUG}" ]; then #判断pid是否为空
-           if [[ $1 = 'prod' ]];   then
-                        echo "prod start"
-                        APP_NAME=changeing-prod.jar
-                        APP_DEBUG=5526
-                      elif  [[ $1 = 'uat' ]] ; then
-                        echo "uat start"
-                        APP_NAME=changeing-uat.jar
-                        APP_DEBUG=5520
-                      elif  [[ $1 = 'devuat' ]] ; then
-                        echo "devuat start"
-                        APP_NAME=changeing-devuat.jar
-                        APP_DEBUG=5526
-                      else
-                        echo "没有设置环境"
-            fi
-     # else
-         #    echo "已经设置-${APP_NAME}-${APP_DEBUG}"
-     fi
-}
-
-# 判断当前服务是否已经启动的函数
-is_exist(){
-    checkEnv $1
-    pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' ` #根据ps 命令查询当前服务的进程号 赋值给pid"
-    if [ -z "${pid}" ]; then #判断pid是否为空
-        echo "pid 不存在"
-        return 1
-    else
-        echo "pid 存在"
-        return 0
-    fi
-}
-
-
-start(){
-    checkEnv $1
-    is_exist
-    if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号打印出来
-        echo "${APP_NAME} running. pid=${pid}"
-    else
-        nohup java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${APP_DEBUG} $APP_NAME > logs.log 2>error.log &  # 说明pid为空
-        # 执行java -jar 命令启动服务
-        echo "${APP_NAME} started启动"
-    fi
-}
-
-
-stop(){
-    echo "执行 stop 方法"
-    checkEnv $1
-    is_exist
-    if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号杀死
-        kill -9 $pid
-        echo "${pid} stopped-停止"
-    else
-        echo "${APP_NAME} 没有运行"
-    fi
-}
-
-
-status(){
-    echo "执行 status 方法"
-    checkEnv $1
-    is_exist
-    if [ $? -eq "0" ]; then
-        echo "${APP_NAME} running-启动. Pid is ${pid}"
-    else
-        echo "${APP_NAME} 没有运行"
-    fi
-}
-
-
-# 重启命令其实就是先执行关闭命令 再执行重启命令
-restart(){
-        echo "执行 restart 方法"
-        checkEnv $1
-        is_exist
-        if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号杀死
-            kill -9 $pid
-            echo "${pid} stopped-停止"
-        else
-            echo "${APP_NAME} 没有运行"
-        fi
-        sleep 5
-        is_exist
-        if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号打印出来
-            echo "${APP_NAME} running. pid=${pid}"
-        else
-            nohup java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${APP_DEBUG} $APP_NAME > logs.log 2>error.log &  # 说明pid为空 执行java -jar 命令启动服务
-            echo "${APP_NAME} started启动"
-        fi
-}
-
-
-# 这里的$1 取的是当前输入命令 的第二个参数 ./start.sh start
-case "$1" in
-    "start")
-        start $2
-        ;;
-    "stop")
-        stop $2
-        ;;
-    "status")
-        status $2
-        ;;
-    "restart")
-        restart $2
-        ;;
-    *)
-    usage
-    ;;
-esac

+ 0 - 11
gis_application/src/main/resources/sh/startup.sh

@@ -1,11 +0,0 @@
-#!/bin/sh
-RESOURCE_NAME=army_chongqing_college.jar
-APP_DEBUG=5005
-rm -f tpid
-nohup java -jar -Xmx3072M -Xms512M ./$RESOURCE_NAME --spring.profiles.active=sit --server.port=8005 & echo $! > tpid
-echo Start Success!
-
-
-
-
-

+ 1 - 1
gis_cms/src/main/java/com/gis/cms/controller/MyController.java

@@ -40,7 +40,7 @@ public class MyController {
 
     @WebControllerLog(description = "我的-保存得分", addDb = true)
     @ApiOperation(value = "保存得分")
-    @GetMapping("/saveScore")
+    @PostMapping("/saveScore")
     public Result saveScore(@Valid @RequestBody ScoreDto param) {
         return entityService.saveScore(param);
     }

+ 1 - 6
gis_cms/src/main/java/com/gis/cms/controller/RoomController.java

@@ -44,12 +44,7 @@ public class RoomController {
         return entityService.saveEntity(param);
     }
 
-//    @WebControllerLog(description = "房间管理-新增/编辑", addDb = true)
-//    @ApiOperation(value = "新增/编辑")
-//    @PostMapping("/save1")
-//    public Result save1(@Valid @RequestBody RoomDto param) {
-//        return entityService.saveEntity1(param);
-//    }
+
 
 
     @ApiOperation("详情")

+ 2 - 2
gis_cms/src/main/java/com/gis/cms/entity/dto/ScoreDto.java

@@ -21,9 +21,9 @@ public class ScoreDto {
     @ApiModelProperty(value = "房间id(为空代表普通模式)")
     private Long roomId;
 
-    @NotBlank(message = "得分不能为空")
+    @NotNull(message = "得分不能为空")
     @ApiModelProperty(value = "得分", required = true)
-    private String score;
+    private Integer score;
 
     @NotNull(message = "耗时不能为空")
     @ApiModelProperty(value = "耗时,单位秒", required = true)

+ 2 - 0
gis_cms/src/main/java/com/gis/cms/service/GameLogService.java

@@ -25,4 +25,6 @@ public interface GameLogService extends IService<GameLogEntity> {
 
     // 团队|个人总分
     Integer totalScore(Long userId, Long roomId);
+
+    GameLogEntity findByRoomIdAndUserId(Long roomId, Long userId, String type);
 }

+ 39 - 14
gis_cms/src/main/java/com/gis/cms/service/impl/GameLogServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Optional;
@@ -58,19 +59,33 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
         Long roomId = param.getRoomId();
         GameLogEntity entity;
         Long userId = iBaseService.getUserId();
-        // 模式, 活动:activity , 普通:general
-        if (roomId == null) {
+        if (roomId == null) { // 普通模式
             String type = "general";
             entity = new GameLogEntity();
             BeanUtils.copyProperties(param, entity);
             entity.setType(type);
-
             entity.setCreatorId(userId);
-        } else {
+            this.save(entity);
+        } else { // 活动模式
+            // 检查房间活动是否结束
+            RoomEntity roomEntity = roomService.getById(roomId);
+            BaseRuntimeException.isNull(roomEntity, ErrorEnum.FAILURE_SYS_2001);
+            LocalDateTime endTime = roomEntity.getEndTime();
+            BaseRuntimeException.isTrue(endTime.isBefore(LocalDateTime.now())  , null, "活动已结束");
+
             entity = this.getById(param.getGameLogId());
+            BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
+
+            Integer score = entity.getScore();
+            Integer pScore = param.getScore();
+            // 比较之前得分, 取最大值, DB大-> 不需要更新
+            if (score!=null && score > pScore){
+                log.info("数据库得分高, 不需要更新");
+                return Result.success();
+            }
             BeanUtils.copyProperties(param, entity);
+            this.updateById(entity);
         }
-        this.saveOrUpdate(entity);
 
         // 更新积分等级
         updateUserLevel(userId, roomId);
@@ -82,21 +97,20 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
     private void updateUserLevel(Long userId, Long roomId){
         Integer totalScore = this.totalScore(userId, roomId);
         int level = 0;
-        if (totalScore < 500){
+        if (500 <= totalScore && totalScore < 1000){
             level = 1;
-        } else if (totalScore < 1000) {
+        } else if (1000 <= totalScore && totalScore < 2000) {
             level = 2;
-        } else if (totalScore < 2000) {
+        } else if (2000 <= totalScore && totalScore < 5000) {
             level = 3;
-        } else if (totalScore < 5000) {
+        } else if (totalScore >= 5000) {
             level = 4;
         }
         WxUserEntity entity = wxUserService.getById(userId);
         // 更新等级
         if (!entity.getLevel().equals(level)){
-            LambdaUpdateWrapper<WxUserEntity> updateWrapper = new LambdaUpdateWrapper<>();
-            updateWrapper.set(WxUserEntity::getLevel, level);
-            wxUserService.update(updateWrapper);
+            entity.setLevel(level);
+            wxUserService.updateById(entity);
             log.info("更新等级完成:{}", level);
         }
 
@@ -158,10 +172,10 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
         StringBuilder sql = new StringBuilder();
         sql.append("select sum(score) from tb_game_log where is_delete=0 ");
         if (userId != null){
-            sql.append("and creator_id=").append(userId);
+            sql.append(" and creator_id=").append(userId);
         }
         if (roomId != null){
-            sql.append("and room_id=").append(roomId);
+            sql.append(" and room_id=").append(roomId);
         }
         return getBaseMapper().sumSql(sql.toString());
     }
@@ -182,4 +196,15 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
     }
 
 
+    @Override
+    public GameLogEntity findByRoomIdAndUserId(Long roomId, Long userId, String type){
+        LambdaQueryWrapper<GameLogEntity> wapper = new LambdaQueryWrapper<>();
+        wapper.eq(GameLogEntity::getRoomId, roomId);
+        wapper.eq(GameLogEntity::getCreatorId, userId);
+        wapper.eq(GameLogEntity::getType, type);
+        return this.getOne(wapper);
+
+    }
+
+
 }

+ 23 - 8
gis_cms/src/main/java/com/gis/cms/service/impl/RoomServiceImpl.java

@@ -2,6 +2,7 @@ package com.gis.cms.service.impl;
 
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gis.cms.entity.dto.RoomDto;
@@ -87,17 +88,31 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
             return Result.failure("该房间不存在: " + code );
         }
 
+        LocalDateTime endTime = roomEntity.getEndTime();
+        BaseRuntimeException.isTrue(endTime.isBefore(LocalDateTime.now())  , null, "活动已结束");
+
+        Long roomId = roomEntity.getId();
+        Long userId = iBaseService.getUserId();
+        String type = "activity";
         // 加入房间记录
-        GameLogEntity entity = new GameLogEntity();
-        entity.setRoomId(roomEntity.getId());
-        entity.setType("activity");
-        // 用户加入房间
-        entity.setCreatorId(iBaseService.getUserId());
-        entity.setScore(0);
-        gameLogService.save(entity);
-        return Result.success(roomEntity);
+        GameLogEntity entity = gameLogService.findByRoomIdAndUserId(roomId, userId, type);
+        if (entity == null){
+            log.info("需要创建该房间的游戏记录");
+            // 用户加入房间
+            entity = new GameLogEntity();
+            entity.setCreatorId(userId);
+            entity.setType(type);
+            entity.setScore(0);
+            entity.setRoomId(roomId);
+            gameLogService.save(entity);
+        }
+
+        return Result.success(entity);
     }
 
+
+
+
     @Override
     public Result search(RoomListDto param) {
         // 每次请求接口前更新房间状态,使用redis, 缓存30分钟更新一次房间状态

+ 2 - 2
run.sh

@@ -1,7 +1,7 @@
 #!/bin/sh
 APP_NAME=wx_lvdao.jar
 APP_PORT=8015
-APP_EVN=$2   #执行环境
+APP_EVN=$2   #执行环境 sit|pro
 APP_ORDER=$1   #执行方法  start|stop|restart
 # 获取进程号
 APP_PID=`netstat -ntpl | grep $APP_PORT | grep LISTEN | awk '{print $7}' | awk -F "/" '{print $1}'`
@@ -14,7 +14,7 @@ startApp(){
     	echo "程序已经在运行了"
     else
     	echo "执行 start 方法"
-    	nohup java -Djava.net.preferIPv4Stack=true -jar -Xmx3072M -Xms512M ./$APP_NAME --spring.profiles.active=$APP_EVN --server.port=$APP_PORT > logs.log 2>error.log &  # 说明pid为空
+    	nohup java -jar -Xmx3072M -Xms512M ./$APP_NAME --spring.profiles.active=$APP_EVN --server.port=$APP_PORT > logs.log 2>error.log &  # 说明pid为空
 	echo Start Success!
 fi
 }