Skip to content

Commit

Permalink
[FIX] progressBit 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jong-gil committed Dec 18, 2023
1 parent 3cd79c0 commit 653aa99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String setWorkerBit(@PathVariable("positionNum") int positionNum, @PathVa
}

@PostMapping("/progressBit/{workerId}")
public String setProgressBit(@PathVariable("workerId") Long id) {
public String setProgressBit(@PathVariable("workerId") Long id) throws Exception {
return redisService.setProgressBit(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.example.workerservice.entity.WorkerEntity;
import com.example.workerservice.repository.WorkerRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -45,10 +47,21 @@ public String setWorkerBit(int positionNum, String userType) {
}
return "WRONG workerId";
}
public String setProgressBit(Long workerId) {
if (-1 < workerId && workerId < 5) {
ValueOperations<String, String> redisBit = redisTemplate.opsForValue();
String progressBit = redisBit.get("progressBit");
public String setProgressBit(Long workerId) throws Exception {
ZSetOperations<String, String> redisSortedSet = redisTemplate.opsForZSet();
ValueOperations<String, String> redisBit = redisTemplate.opsForValue();
StringBuilder sb = new StringBuilder("worker");
String workerBitKey = String.valueOf(sb.append(workerId));

String redisTurn = redisBit.get("turn");
ObjectMapper objectMapper = new ObjectMapper();
long now = objectMapper.readValue(redisTurn, Long.class);
int setSize = redisSortedSet.rangeByScore(workerBitKey, 0L, now).size();
String progressBit = redisBit.get("progressBit");
char status = progressBit.charAt(workerId.intValue());

if (-1 < workerId && workerId < 5 && ((setSize > 3 && status == '0')||(setSize <= 3 && status == '1'))) {

String changedProgressBit = getChangedString(workerId, progressBit);
redisBit.set("progressBit", changedProgressBit);
return "Worker's Progress status has Changed";
Expand Down

0 comments on commit 653aa99

Please sign in to comment.