Skip to content

Commit

Permalink
add: 오름 DB에 스티커 왼,오 스티커 번호 컬럼 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-EunJu committed Nov 17, 2022
1 parent 338a5d4 commit b70286e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/example/goorm/FileItemReaderJobConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,40 @@ public ItemProcessor<CsvReaderDto, Oreum> 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)
.yPos(y)
.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;
}
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;
}
dayCheck++;
return oreum;
};
}

}
1 change: 0 additions & 1 deletion src/main/java/com/example/goorm/oreum/OreumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/example/goorm/oreum/domain/Oreum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

13 changes: 9 additions & 4 deletions src/main/java/com/example/goorm/oreum/dto/OreumResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,33 +12,39 @@
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();
}

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();
}
}

0 comments on commit b70286e

Please sign in to comment.