From b70286e204132ed5566fd4a6ad44aae4b6da6460 Mon Sep 17 00:00:00 2001 From: Song-EunJu Date: Fri, 18 Nov 2022 02:53:49 +0900 Subject: [PATCH] =?UTF-8?q?add:=20=EC=98=A4=EB=A6=84=20DB=EC=97=90=20?= =?UTF-8?q?=EC=8A=A4=ED=8B=B0=EC=BB=A4=20=EC=99=BC,=EC=98=A4=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EB=B2=88=ED=98=B8=20=EC=BB=AC=EB=9F=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/goorm/FileItemReaderJobConfig.java | 15 +++++++++++---- .../com/example/goorm/oreum/OreumController.java | 1 - .../com/example/goorm/oreum/domain/Oreum.java | 9 +++++---- .../example/goorm/oreum/dto/OreumResponse.java | 13 +++++++++---- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/example/goorm/FileItemReaderJobConfig.java b/src/main/java/com/example/goorm/FileItemReaderJobConfig.java index 3ec4405..a2132da 100644 --- a/src/main/java/com/example/goorm/FileItemReaderJobConfig.java +++ b/src/main/java/com/example/goorm/FileItemReaderJobConfig.java @@ -63,6 +63,10 @@ public ItemProcessor csvProcessor() { double y = Double.parseDouble(pos.split(" ")[1]); double z = Double.parseDouble(pos.split(" ")[2]); + int left = (int)(Math.random()*5); // 0~4 (스티커 안붙이는 경우 고려) + // 왼쪽이 빈 스티커인 경우, 무조건 오른쪽 스티커는 있도록 + int right = (left == 0) ? (int)(Math.random()*4)+1 : (int)(Math.random()*5); + Oreum oreum = Oreum.builder() .name(name) .xPos(x) @@ -70,12 +74,15 @@ public ItemProcessor csvProcessor() { .zPos(z) .month(monthCheck) .day(dayCheck) + .leftPos(left) + .rightPos(right) .build(); oreum.toTypeEnum(type); oreumRepository.save(oreum); - if((monthCheck == 1 || monthCheck == 3 || monthCheck == 5 || monthCheck == 7 - || monthCheck == 8 || monthCheck == 10 || monthCheck ==12) && dayCheck == 31) { + + if(((monthCheck<=7 && monthCheck%2==1) || (monthCheck>=8 && monthCheck%2==0)) + && dayCheck == 31) { monthCheck++; dayCheck = 0; } @@ -83,7 +90,8 @@ else if(monthCheck == 2 && dayCheck == 29){ monthCheck++; dayCheck = 0; } - else if((monthCheck == 4 || monthCheck == 6 || monthCheck ==9 || monthCheck == 11) && dayCheck == 30){ + else if((monthCheck == 4 || monthCheck == 6 || monthCheck == 9 || monthCheck == 11) + && dayCheck == 30){ monthCheck++; dayCheck = 0; } @@ -91,5 +99,4 @@ else if((monthCheck == 4 || monthCheck == 6 || monthCheck ==9 || monthCheck == 1 return oreum; }; } - } diff --git a/src/main/java/com/example/goorm/oreum/OreumController.java b/src/main/java/com/example/goorm/oreum/OreumController.java index 6a23c29..110348c 100644 --- a/src/main/java/com/example/goorm/oreum/OreumController.java +++ b/src/main/java/com/example/goorm/oreum/OreumController.java @@ -7,7 +7,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; - @Controller @CrossOrigin(origins = "*") @RequiredArgsConstructor diff --git a/src/main/java/com/example/goorm/oreum/domain/Oreum.java b/src/main/java/com/example/goorm/oreum/domain/Oreum.java index 3e15657..789d14c 100644 --- a/src/main/java/com/example/goorm/oreum/domain/Oreum.java +++ b/src/main/java/com/example/goorm/oreum/domain/Oreum.java @@ -20,20 +20,21 @@ public class Oreum { private String name; @Enumerated(EnumType.STRING) - private OreumType type; + private OreumType oreumType; + private double xPos; private double yPos; private double zPos; private int month; private int day; + private int leftPos; + private int rightPos; - // 랜덤 색상값 추가해줘야 함 public void toTypeEnum(String type) { - this.type = Arrays.stream(OreumType.values()) + this.oreumType = Arrays.stream(OreumType.values()) .filter(o1 -> o1.getTitle().equals(type)) .findFirst() .get(); } - } diff --git a/src/main/java/com/example/goorm/oreum/dto/OreumResponse.java b/src/main/java/com/example/goorm/oreum/dto/OreumResponse.java index f7a6b8e..5428681 100644 --- a/src/main/java/com/example/goorm/oreum/dto/OreumResponse.java +++ b/src/main/java/com/example/goorm/oreum/dto/OreumResponse.java @@ -2,7 +2,6 @@ import com.example.goorm.oreum.domain.MyOreum; import com.example.goorm.oreum.domain.Oreum; -import com.example.goorm.oreum.domain.OreumType; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -13,21 +12,25 @@ public class OreumResponse { private String nickname; private String name; - private OreumType type; + private String type; private double xPos; private double yPos; private double zPos; private Long myOreumId; + private int left; + private int right; public static OreumResponse of(Oreum oreum, MyOreum myOreum, BirthdayRequest request){ return OreumResponse.builder() .nickname(request.getNickname()) .name(oreum.getName()) - .type(oreum.getType()) + .type(oreum.getOreumType().getTitle()) .xPos(oreum.getXPos()) .yPos(oreum.getYPos()) .zPos(oreum.getZPos()) .myOreumId(myOreum.getId()) + .left(oreum.getLeftPos()) + .right(oreum.getRightPos()) .build(); } @@ -35,11 +38,13 @@ public static OreumResponse ofOthers(Oreum oreum, MyOreum myOreum){ return OreumResponse.builder() .nickname(myOreum.getNickname()) .name(oreum.getName()) - .type(oreum.getType()) + .type(oreum.getOreumType().getTitle()) .xPos(oreum.getXPos()) .yPos(oreum.getYPos()) .zPos(oreum.getZPos()) .myOreumId(myOreum.getId()) + .left(oreum.getLeftPos()) + .right(oreum.getRightPos()) .build(); } } \ No newline at end of file