Skip to content

Commit

Permalink
Merge pull request #5 from chhs2131/develop
Browse files Browse the repository at this point in the history
ipo list 일부 수정 및 comment 기록항목 추가
  • Loading branch information
chhs2131 authored May 31, 2022
2 parents 3d40b77 + aeaacc9 commit 2326469
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {
}

group = 'com.dbsgAPI'
version = '0.0.8-SNAPSHOT'
version = '0.0.9-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# 공모주토피아 백엔드 서버 개발

### 백엔드 개요

- 기준 서비스 인원 : 10만명
- 개발환경
- Window 10
- IntelliJ 2021.2.3 (Ultimate Edition) (SpringToolSuite4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.dbsgapi.dbsgapi.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
public class JsonCommentConverter {
private String commentType;
private String commentJson;
Expand Down Expand Up @@ -69,7 +71,7 @@ private boolean mapVerify(Map<String, Object> map, String key) {
return false;
} else if (map.get(key) == null) {
return false;
} else if (Objects.equals(String.valueOf(map.get(key)), "-1")) { // 예외처리 제대로 동작하게 수정 필요. [의무보유확약 비율이 정정되었습니다. (-1.0%), 수요 예측 결과가 발표되었습니다. (기업경쟁률: -1.0), 공모가가 확정되었습니다. (17200원)]
} else if (Objects.equals(String.valueOf(map.get(key)), "-1")) {
return false;
} else if (Objects.equals(String.valueOf(map.get(key)), "-1.0")) {
return false;
Expand Down Expand Up @@ -121,6 +123,17 @@ else if (mapVerify(map, "ipo_forecast_date")) { // 수요예측 종료일의
this.commentList.add("수요예측 종료일이 변경되었습니다. (" + String.valueOf( map.get("ipo_forecast_date")) + ")");
}

if (mapVerify(map, "ex_start_date") && mapVerify(map, "ex_end_date")) {
this.commentList.add("구주주 청약일이 변경되었습니다. (" +
String.valueOf( map.get("ex_start_date")) + " ~ " + String.valueOf( map.get("ex_end_date")) + ")");
}
else if (mapVerify(map, "ex_start_date")) {
this.commentList.add("구주주 청약 시작일이 변경되었습니다. (" + String.valueOf( map.get("ex_start_date")) + ")");
}
else if (mapVerify(map, "ex_end_date")) {
this.commentList.add("구주주 청약 종료일이 변경되었습니다. (" + String.valueOf( map.get("ex_end_date")) + ")");
}

// 2순위: 공모 관련 변동 정보
if (mapVerify(map, "lock_up_percent")) {
this.commentList.add( "의무보유확약 비율이 정정되었습니다. (" + String.valueOf( map.get("lock_up_percent"))+"%)");
Expand Down Expand Up @@ -171,6 +184,9 @@ else if (mapVerify(map, "ipo_price_high")) {
if (mapVerify(map, "par_value")) {
this.commentList.add( "액면가가 변경되었습니다. (" + String.valueOf( map.get("par_value")) + "원)");
}
if (mapVerify(map, "purpose_of_funds")) {
this.commentList.add( "자금의 사용목적이 변경되었습니다. (" + String.valueOf( map.get("purpose_of_funds")) + ")");
}

// 가장 높은 우선순위에 있는 comment를 반환한다. ex) 공모가가 확정되었습니다. (1,200원) - 외 3건
if(!commentList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class SwaggerConfiguration {
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("DBSG API")
.description("주식알리미 서비스에 사용되는 API 명세입니다.")
.version("v0.0.6")
.description("주식알리미 서비스에 사용되는 API 명세입니다.<br/>" +
"<a href='https://www.notion.so/8c74d32d5e9846d698757d8b23cb0108?v=065595755f7645028e0a191479d986fa'>서버 변동사항 정리</a>")
.version("v0.0.9")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class IpoApiController {
public ResponseEntity<List<IpoSummaryDto>> getIpoList(
@Parameter(description="페이지 번호") @RequestParam(required=false, defaultValue="1") int page,
@Parameter(description="페이지당 반환갯수") @RequestParam(required=false, defaultValue="100") int num,
@Parameter(description="종류") @RequestParam(required=false, defaultValue="all") String kind
@Parameter(description="검색 조건문 (임시) (ex: stock_name LIKE '%에스%')") @RequestParam(required=false, defaultValue="1=1") String queryString
) throws Exception {
List<IpoSummaryDto> listIpo = ipoService.selectIpos(kind, page, num);
// todo 검색조건문(queryString) 현재 임시 사용중으로 client가 query형태를 알지 못해도 사용할 수 있도록 수정 필요.
List<IpoSummaryDto> listIpo = ipoService.selectIpos(queryString, page, num);
log.debug(listIpo.toString());
return new ResponseEntity<>(listIpo, HttpStatus.OK);
}
Expand Down
43 changes: 41 additions & 2 deletions src/main/java/com/dbsgapi/dbsgapi/ipo/dto/IpoSummaryDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dbsgapi.dbsgapi.ipo.dto;

import com.dbsgapi.dbsgapi.common.JsonCommentConverter;
import com.dbsgapi.dbsgapi.ipo.service.IpoService;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -39,10 +41,47 @@ public class IpoSummaryDto {
private String underwriter;
@Schema(description ="태그", example = "")
private String tag;

// comment 관련 정보들
private int recentCommentIndex;
private String logType;
private String comment;
private String changeLogJson;
@Schema(description ="최근 발행된 코멘트", example = "수요예측이 끝났습니다! 결과를 확인해보세요.")
private String recentComment;

public String getRecentComment() {
return this.recentComment;
public String getRecentComment() { return this.recentComment; }
public void setComment(String comment) {
this.comment = comment;
this.recentComment = comment;
}
public void setChangeLogJson(String changeLogJson) {
// changeLogJson이 comment보다 후순위로 값을 가져옴. (아마 mybatis에서 가져오는 순서대로인것 같음)
this.changeLogJson = changeLogJson;

// changeLogJson을 체크하여 null이 아닌경우 comment를 갱신함.
if(changeLogJson != null && !changeLogJson.isEmpty()) {
JsonCommentConverter jcc = new JsonCommentConverter();
jcc.setCommentType(this.logType);
jcc.setCommentJson(this.changeLogJson);
this.recentComment = jcc.getRecentComment();
}
}

@JsonIgnore
public int getRecentCommentIndex() { // 외부에 값을 표출하진 않음 jsonIgnore
return recentCommentIndex;
}
@JsonIgnore
public String getLogType() { // 외부에 값을 표출하진 않음 jsonIgnore
return logType;
}
@JsonIgnore
public String getComment() { // 외부에 값을 표출하진 않음 jsonIgnore
return comment;
}
@JsonIgnore
public String getChangeLogJson() { // 외부에 값을 표출하진 않음 jsonIgnore
return changeLogJson;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Mapper
public interface IpoMapper {
List<IpoSummaryDto> selectIpos(Map<String, Integer> map) throws Exception;
List<IpoSummaryDto> selectIpos(Map<String, Object> map) throws Exception;
IpoDto selectIpo(long ipoIndex) throws Exception;
List<IpoSummaryDto> selectIpoScheduleList(Map<String, String> map) throws Exception;
List<IpoCommentDto> selectIpoComment(long ipoIndex) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;

public interface IpoService {
List<IpoSummaryDto> selectIpos(String kind, int page, int num) throws Exception;
List<IpoSummaryDto> selectIpos(String queryString, int page, int num) throws Exception;
IpoDto selectIpo(long ipoIndex) throws Exception;
List<IpoSummaryDto> selectIpoScheduleList(String startDate, String endDate) throws Exception;
List<IpoCommentDto> selectIpoComment(long ipoIndex) throws Exception;
Expand Down
33 changes: 5 additions & 28 deletions src/main/java/com/dbsgapi/dbsgapi/ipo/service/IpoServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,15 @@ public class IpoServiceImpl implements IpoService{
private IpoMapper ipoMapper;

@Override
public List<IpoSummaryDto> selectIpos(String kind, int page, int num) throws Exception {
// todo ipolist kind 구분하는 구문 추가
Map<String, Integer> map = new HashMap<String, Integer>();
public List<IpoSummaryDto> selectIpos(String queryString, int page, int num) throws Exception {
// todo ipolist keyword 구분하는 구문 추가
Map<String, Object> map = new HashMap<String, Object>();
map.put("limit", num);
map.put("offset", page * num - num);
map.put("queryString", queryString);

// ipo list 조회 로직
List<IpoSummaryDto> ipos = ipoMapper.selectIpos(map);

// recent_comment 조회 로직
Iterator<IpoSummaryDto> iterator = ipos.iterator();
while(iterator.hasNext()) {
IpoSummaryDto ipo = iterator.next();
String commentIndex = ipo.getRecentComment();

if(commentIndex != null) {
IpoCommentDto ipoComment = selectIpoCommentIndex(Long.parseLong(commentIndex));
if(ipoComment != null) {
if (ipoComment.getComment() != null) {
ipo.setRecentComment(ipoComment.getComment());
} else {
JsonCommentConverter jcc = new JsonCommentConverter(); // json인 경우 해석해서 대입
jcc.setCommentType(ipoComment.getLogType());
jcc.setCommentJson(ipoComment.getChangeLogJson());
ipo.setRecentComment(jcc.toString());
}
// 아무것도 없는 예외처리도 해야할까요
}
}
}

return ipos;
return ipoMapper.selectIpos(map);
}

@Override
Expand Down
41 changes: 31 additions & 10 deletions src/main/resources/mapper/sql-ipo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,46 @@
ipo_cancel_bool,
DATE_FORMAT(ipo_cancel_date, '%Y-%m-%d') ipo_cancel_date,

ct.recent_comment
ct.recent_comment_index,
ct.log_type,
ct.comment,
ct.change_log_json
FROM ipo LEFT OUTER JOIN
(
SELECT ipo_comment.ipo_index, ipo_comment.regist_date, ipo_comment.comment_index AS recent_comment
SELECT
ipo_comment.ipo_index,
ipo_comment.regist_date,
ipo_comment.comment_index as recent_comment_index,
ipo_comment.log_type,
ipo_comment.comment,
ipo_comment.change_log_json
FROM ipo_comment
WHERE (ipo_comment.ipo_index, ipo_comment.regist_date)
WHERE (ipo_comment.ipo_index, ipo_comment.regist_date, ipo_comment.enabled)
IN(
SELECT ipo_comment.ipo_index, MAX(ipo_comment.regist_date) FROM ipo_comment
SELECT ipo_comment.ipo_index, MAX(ipo_comment.regist_date), 'Y'
FROM ipo_comment
GROUP BY ipo_comment.ipo_index
)
) AS ct
ON ipo.ipo_index = ct.ipo_index LEFT OUTER JOIN
(SELECT iu.ipo_index, GROUP_CONCAT(iu.under_name ORDER BY iu.ind_total_max DESC) AS underwriter
FROM(
SELECT ipo_underwriter.ipo_index, ipo_underwriter.ind_total_max, IFNULL(uc2.underwriter_name, ipo_underwriter.under_name) AS under_name
FROM underwriter_code AS uc1 JOIN underwriter_code AS uc2 ON uc1.parents_code = uc2.underwriter_code
RIGHT OUTER JOIN ipo_underwriter ON uc1.underwriter_name LIKE ipo_underwriter.under_name) AS iu
GROUP BY iu.ipo_index) AS under
(
SELECT iu.ipo_index, GROUP_CONCAT(iu.under_name ORDER BY iu.ind_total_max DESC) AS underwriter
FROM(
SELECT
ipo_underwriter.ipo_index,
ipo_underwriter.ind_total_max,
IFNULL(uc2.underwriter_name, ipo_underwriter.under_name) AS under_name
FROM
underwriter_code AS uc1
JOIN underwriter_code AS uc2
ON uc1.parents_code = uc2.underwriter_code
RIGHT OUTER JOIN ipo_underwriter
ON uc1.underwriter_name LIKE ipo_underwriter.under_name
) AS iu
GROUP BY iu.ipo_index
) AS under
ON ipo.ipo_index = under.ipo_index
WHERE ${queryString}
ORDER BY ipo.ipo_start_date DESC
LIMIT #{limit} OFFSET #{offset};
</select>
Expand Down

0 comments on commit 2326469

Please sign in to comment.