xiongzhu 6 ani în urmă
părinte
comite
120f8a9fd1

+ 2 - 0
log.txt

@@ -958,3 +958,5 @@ java.lang.NullPointerException
 [2019-10-21 16:13:43] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-10-21 18:42:01] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-10-21 18:42:41] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-10-22 14:41:38] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-10-22 15:29:17] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.

+ 5 - 1
src/main/java/com/izouma/awesomeadmin/dao/MatchDataMapper.java

@@ -40,7 +40,11 @@ public interface MatchDataMapper {
 
     List<MatchData> allUserMatchData(@Param("userId") Integer userId);
 
-    int deleteChildren(@Param("parentId")Integer parentId);
+    int deleteBySuperiorId(@Param("superiorId")Integer superiorId);
+
+    List<MatchData> findChildrenByParentId(@Param("parentId")Integer parentId);
+
+    List<MatchData> findByIdStr(@Param("ids") String ids);
 
 }
 

+ 32 - 6
src/main/java/com/izouma/awesomeadmin/dao/MatchDataMapper.xml

@@ -17,8 +17,9 @@
         <result column="loop_num" property="loopNum" jdbcType="INTEGER"/>
         <result column="pictures" property="pictures" jdbcType="VARCHAR"/>
         <result column="upload_user" property="uploadUser" jdbcType="INTEGER"/>
-        <result column="parent_id" property="parentId" javaType="INTEGER"/>
+        <result column="parent_id" property="parentId" jdbcType="VARCHAR"/>
         <result column="can_edit" property="canEdit" jdbcType="BIT"/>
+        <result column="superior_id" property="superiorId" jdbcType="VARCHAR"/>
         <association property="applyInfo1" column="{userId=user1,matchId=match_id}" javaType="ApplyInfo"
                      select="queryApplyInfo"/>
         <association property="applyInfo2" column="{userId=user2,matchId=match_id}" javaType="ApplyInfo"
@@ -33,7 +34,7 @@
           AND apply_info.user_id = #{userId}
     </select>
     <sql id="Base_Column_List">
-        id, del_flag, match_id, stage_id, user1, user2, score1, score2, bye1, bye2, abandon1, abandon2, state, winner, group_name, round, loop_num, pictures, upload_user, parent_id, can_edit    </sql>
+        id, del_flag, match_id, stage_id, user1, user2, score1, score2, bye1, bye2, abandon1, abandon2, state, winner, group_name, round, loop_num, pictures, upload_user, parent_id, can_edit, superior_id    </sql>
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
         select
         <include refid="Base_Column_List"/>
@@ -113,6 +114,9 @@
             <if test="canEdit!= null">
                 can_edit,
             </if>
+            <if test="superiorId!= null">
+                superior_id,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">
@@ -173,11 +177,14 @@
                 #{uploadUser,jdbcType=INTEGER},
             </if>
             <if test="parentId != null">
-                #{parentId,jdbcType=INTEGER},
+                #{parentId,jdbcType=VARCHAR},
             </if>
             <if test="canEdit != null">
                 #{canEdit,jdbcType=BIT},
             </if>
+            <if test="superiorId != null">
+                #{superiorId,jdbcType=VARCHAR},
+            </if>
         </trim>
     </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.MatchData">
@@ -241,11 +248,14 @@
                 upload_user= #{uploadUser,jdbcType=INTEGER},
             </if>
             <if test="parentId != null">
-                parent_id= #{parentId,jdbcType=INTEGER},
+                parent_id= #{parentId,jdbcType=VARCHAR},
             </if>
             <if test="canEdit != null">
                 can_edit= #{canEdit,jdbcType=INTEGER},
             </if>
+            <if test="superiorId != null">
+                superior_id= #{superiorId,jdbcType=VARCHAR},
+            </if>
         </set>
         where id = #{id,jdbcType=INTEGER}
     </update>
@@ -318,6 +328,9 @@
             <if test="record.canEdit != null and !&quot;&quot;.equals(record.canEdit)">
                 and can_edit = #{record.canEdit}
             </if>
+            <if test="record.superiorId != null and !&quot;&quot;.equals(record.superiorId)">
+                and superior_id = #{record.superiorId}
+            </if>
             <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR user1 LIKE concat('%',#{record.searchKey},'%')
@@ -434,6 +447,9 @@
             <if test="canEdit != null and !&quot;&quot;.equals(canEdit)">
                 and can_edit = #{canEdit}
             </if>
+            <if test="superiorId != null and !&quot;&quot;.equals(superiorId)">
+                and superior_id = #{superiorId}
+            </if>
             <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR user1 LIKE concat('%',#{searchKey},'%')
@@ -561,6 +577,9 @@
             <if test="canEdit != null and !&quot;&quot;.equals(canEdit)">
                 and can_edit = #{canEdit}
             </if>
+            <if test="superiorId != null and !&quot;&quot;.equals(superiorId)">
+                and superior_id = #{superiorId}
+            </if>
 
         </where>
         LIMIT 1
@@ -642,8 +661,15 @@
         LIMIT 20
     </select>
 
-    <delete id="deleteChildren">
-        update match_data set del_flag = 'Y' where parent_id = #{parentId}
+    <delete id="deleteBySuperiorId">
+        update match_data set del_flag = 'Y' where FIND_IN_SET(#{superiorId}, superior_id)
     </delete>
+
+    <select id="findChildrenByParentId" resultType="com.izouma.awesomeadmin.model.MatchData">
+        select * from match_data where FIND_IN_SET(#{parentId}, parent_id)
+    </select>
+    <select id="findByIdStr" resultType="com.izouma.awesomeadmin.model.MatchData">
+        select * from match_data where find_in_set(id, #{ids});
+    </select>
 </mapper>
 

+ 12 - 3
src/main/java/com/izouma/awesomeadmin/model/MatchData.java

@@ -34,7 +34,8 @@ public class MatchData {
     private Integer   userId;
     private Boolean   teamMode;
     private Boolean   canEdit;
-    private Integer   parentId;
+    private String    parentId;
+    private String    superiorId;
 
     private String searchKey;
 
@@ -264,11 +265,11 @@ public class MatchData {
         this.teamMode = teamMode;
     }
 
-    public Integer getParentId() {
+    public String getParentId() {
         return parentId;
     }
 
-    public void setParentId(Integer parentId) {
+    public void setParentId(String parentId) {
         this.parentId = parentId;
     }
 
@@ -279,5 +280,13 @@ public class MatchData {
     public void setCanEdit(Boolean canEdit) {
         this.canEdit = canEdit;
     }
+
+    public String getSuperiorId() {
+        return superiorId;
+    }
+
+    public void setSuperiorId(String superiorId) {
+        this.superiorId = superiorId;
+    }
 }
 

+ 51 - 16
src/main/java/com/izouma/awesomeadmin/service/impl/MatchDataServiceImpl.java

@@ -1,6 +1,8 @@
 package com.izouma.awesomeadmin.service.impl;
 
 import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -137,8 +139,19 @@ public class MatchDataServiceImpl implements MatchDataService {
         logger.info("updateMatchData");
         try {
             MatchData m = getMatchDataById(record.getId().toString());
-            if (m.getState() == 2) {
+            boolean reset = m.getState() == 2;
+            if (reset) {
                 delChildren(record.getId());
+                matchDataMapper.findChildrenByParentId(record.getId()).forEach(child -> {
+                    if (StringUtils.isNotEmpty(child.getParentId())) {
+                        matchDataMapper.findByIdStr(child.getParentId()).forEach(parent -> {
+                            if (parent.getState() == 2) {
+                                parent.setState(1);
+                                matchDataMapper.updateByPrimaryKeySelective(parent);
+                            }
+                        });
+                    }
+                });
             }
 
             int updates = matchDataMapper.updateByPrimaryKeySelective(record);
@@ -198,12 +211,12 @@ public class MatchDataServiceImpl implements MatchDataService {
         boolean insert = nextMatchData == null;
         if (insert) {
             nextMatchData = new MatchData();
-            nextMatchData.setParentId(matchData.getId());
             nextMatchData.setMatchId(matchData.getMatchId());
             nextMatchData.setRound(nextNum);
             nextMatchData.setLoopNum(nextRound);
             nextMatchData.setGroupName("第" + nextRound + "轮");
         }
+        addParentId(nextMatchData, matchData);
         if (currentNum % 2 == 0) {
             if (winnerId == -1) {
                 nextMatchData.setBye2(true);
@@ -304,7 +317,7 @@ public class MatchDataServiceImpl implements MatchDataService {
             nextData = getMatchData(nextData);
             if (nextData == null) {
                 nextData = new MatchData();
-                nextData.setParentId(matchData.getId());
+                addParentId(nextData, matchData);
                 nextData.setMatchId(matchInfo.getId());
                 nextData.setRound(nextNum);
                 nextData.setLoopNum(totalRound + 1);
@@ -319,7 +332,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                     nextLoseData = getMatchData(nextLoseData);
                     if (nextLoseData == null) {
                         nextLoseData = new MatchData();
-                        nextLoseData.setParentId(matchData.getId());
+                        addParentId(nextLoseData, matchData);
                         nextLoseData.setMatchId(matchInfo.getId());
                         nextLoseData.setRound(currentNum * 2 - 1);
                         nextLoseData.setLoopNum(totalRound);
@@ -328,6 +341,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                         nextLoseData.setBye2(loseBye);
                         createMatchData(nextLoseData);
                     } else {
+                        addParentId(nextLoseData, matchData);
                         nextLoseData.setUser2(loserId);
                         nextLoseData.setBye2(loseBye);
                         if (nextLoseData.getBye1() || nextLoseData.getBye2()) {
@@ -341,6 +355,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                 }
                 createMatchData(nextData);
             } else {
+                nextData.setMatchId(matchInfo.getId());
                 if (loseRound) {
                     nextData.setUser2(winnerId);
                 } else {
@@ -359,7 +374,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                 Integer lastWinner = lastWinData.getScore1() > lastWinData.getScore2() ? lastWinData.getUser1() : lastWinData.getUser2();
                 if (!lastWinner.equals(winnerId)) {
                     MatchData nextData = new MatchData();
-                    nextData.setParentId(matchData.getId());
+                    addParentId(nextData, matchData);
                     nextData.setMatchId(matchInfo.getId());
                     nextData.setUser1(matchData.getUser1());
                     nextData.setUser2(matchData.getUser2());
@@ -394,12 +409,12 @@ public class MatchDataServiceImpl implements MatchDataService {
             boolean insert = nextData == null;
             if (nextData == null) {
                 nextData = new MatchData();
-                nextData.setParentId(matchData.getId());
                 nextData.setMatchId(matchInfo.getId());
                 nextData.setRound(nextNum);
                 nextData.setLoopNum(nextRound);
                 nextData.setGroupName("败者组第" + nextRound + "轮");
             }
+            addParentId(nextData, matchData);
             if (nextRound % 2 == 0) {
                 nextData.setUser1(winnerId);
                 nextData.setBye1(winnerBye);
@@ -442,7 +457,7 @@ public class MatchDataServiceImpl implements MatchDataService {
             nextWinData = getMatchData(nextWinData);
             if (nextWinData == null) {
                 nextWinData = new MatchData();
-                nextWinData.setParentId(matchData.getId());
+                addParentId(nextWinData, matchData);
                 nextWinData.setMatchId(matchData.getMatchId());
                 nextWinData.setRound(nextNumWin);
                 nextWinData.setLoopNum(nextRoundWin);
@@ -454,6 +469,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                 }
                 createMatchData(nextWinData);
             } else {
+                addParentId(nextWinData, matchData);
                 if (currentNum % 2 == 0) {
                     nextWinData.setUser2(winnerId);
                 } else {
@@ -469,7 +485,7 @@ public class MatchDataServiceImpl implements MatchDataService {
             nextLoseData = getMatchData(nextLoseData);
             if (nextLoseData == null) {
                 nextLoseData = new MatchData();
-                nextLoseData.setParentId(matchData.getId());
+                addParentId(nextLoseData, matchData);
                 nextLoseData.setMatchId(matchData.getMatchId());
                 nextLoseData.setRound(nextNumLose);
                 nextLoseData.setLoopNum(nextRoundLose);
@@ -483,6 +499,7 @@ public class MatchDataServiceImpl implements MatchDataService {
                 }
                 createMatchData(nextLoseData);
             } else {
+                addParentId(nextLoseData, matchData);
                 nextLoseData.setUser2(loserId);
                 nextLoseData.setBye2(loseBye);
                 if (nextLoseData.getBye1() || nextLoseData.getBye2()) {
@@ -793,17 +810,35 @@ public class MatchDataServiceImpl implements MatchDataService {
         return sum;
     }
 
-    private void delChildren(Integer parentId) {
-        MatchData matchData = new MatchData();
-        matchData.setParentId(parentId);
-        List<MatchData> list = matchDataMapper.queryAllMatchData(matchData);
-        for (MatchData data : list) {
-            delChildren(data.getId());
+    private void addParentId(MatchData matchData, MatchData parent) {
+        if (StringUtils.isEmpty(matchData.getParentId())) {
+            matchData.setParentId(parent.getId().toString());
+        } else {
+            if (Arrays.stream(matchData.getParentId().split(",")).map(Integer::parseInt).noneMatch(integer -> integer.equals(parent.getId()))) {
+                matchData.setParentId(matchData.getParentId() + "," + parent.getId());
+            }
         }
-        for (MatchData data : list) {
-            deleteMatchData(data.getId().toString());
+        addSuperiorId(matchData, parent);
+    }
+
+    private void addSuperiorId(MatchData matchData, MatchData superior) {
+        Set<String> ids = new HashSet<>();
+        if (StringUtils.isNotEmpty(matchData.getSuperiorId())) {
+            ids.addAll(Arrays.asList(matchData.getSuperiorId().split(",")));
         }
+        if (StringUtils.isNotEmpty(superior.getSuperiorId())) {
+            ids.addAll(Arrays.asList(superior.getSuperiorId().split(",")));
+        }
+        ids.add(superior.getId().toString());
+        matchData.setSuperiorId(StringUtils.join(ids, ","));
     }
 
+    private void delChildren(Integer parentId) {
+        matchDataMapper.findChildrenByParentId(parentId).forEach(child -> {
+            delChildren(child.getId());
+            matchDataMapper.delete(child.getId().toString());
+        });
+        matchDataMapper.deleteBySuperiorId(parentId);
+    }
 }
 

+ 4 - 2
src/main/vue/src/components/DoubleElimination.vue

@@ -34,7 +34,8 @@
                         :mode="mode"
                         :allMatchData="matchData"
                         @switchAgainst="switchAgainst"
-                        :switchData="switchData">
+                        :switchData="switchData"
+                        :admin="admin">
                     </vs-pair>
                 </template>
                 <template v-for="(i,r) in round">
@@ -70,7 +71,8 @@
                         :participantNum="participantNum"
                         :allMatchData="matchData"
                         @switchAgainst="switchAgainst"
-                        :switchData="switchData">
+                        :switchData="switchData"
+                        :admin="admin">
                     </vs-pair>
                 </template>
                 <template v-for="(i,r) in loserRound">

+ 1 - 1
src/test/java/MatchTest.java

@@ -33,7 +33,7 @@ public class MatchTest {
     @Test
     public void createMatch() {
 
-        int matchId = 446;
+        int matchId = 448;
         MatchInfo matchInfo = matchInfoService.getMatchInfoById(String.valueOf(matchId));
 
         List<UserInfo> userInfoList = RandomDataUtil.generateRandomDataNoRepeat(userInfoService.getUserInfoList(new UserInfo()), matchInfo.getStageInfo().get(0).getTotalNum());

+ 0 - 0
velocity.log