데이터 초기화 API 추가 및 처리
This commit is contained in:
@@ -72,4 +72,9 @@ public class AdminController {
|
||||
return ResponseEntity.ok().body(adminService.deleteAdmin(adminRequest));
|
||||
}
|
||||
|
||||
//데이터 초기화
|
||||
@PostMapping("/init-data")
|
||||
public ResponseEntity<AdminResponse> initData(@RequestBody AuthenticateRequest authenticateRequest){
|
||||
return ResponseEntity.ok().body(adminService.initPassword(authenticateRequest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.caliverse.admin.domain.api;
|
||||
|
||||
import com.caliverse.admin.domain.request.AuthenticateRequest;
|
||||
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||
import com.caliverse.admin.domain.response.DataResponse;
|
||||
import com.caliverse.admin.domain.response.LogResponse;
|
||||
import com.caliverse.admin.domain.service.DataService;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "데이터 관련", description = "데이터 관련 api 입니다.")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/data")
|
||||
|
||||
public class DataController {
|
||||
|
||||
private final DataService dataService;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeProfile;
|
||||
|
||||
@PostMapping("/init-list")
|
||||
public ResponseEntity<DataResponse> initHistoryList(
|
||||
@RequestBody LogGenericRequest logGenericRequest){
|
||||
if(activeProfile.equals("live")){
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.NOT_FOUNT_API.toString())
|
||||
.build());
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().body( dataService.initHistoryList(logGenericRequest));
|
||||
}
|
||||
|
||||
//데이터 초기화
|
||||
@PostMapping("/init-data")
|
||||
public ResponseEntity<DataResponse> initData(@RequestBody AuthenticateRequest authenticateRequest){
|
||||
if(activeProfile.equals("live")){
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.NOT_FOUNT_API.toString())
|
||||
.build());
|
||||
}
|
||||
return ResponseEntity.ok().body(dataService.initData(authenticateRequest));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.caliverse.admin.domain.dao.admin;
|
||||
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.LandRequest;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface DataMapper {
|
||||
@Select("SELECT * FROM data_initialize_schedule WHERE status = 'WAIT'")
|
||||
@Results({
|
||||
@Result(property = "id", column = "id"),
|
||||
@Result(property = "dataType", column = "data_type"),
|
||||
@Result(property = "status", column = "status"),
|
||||
@Result(property = "deleted", column = "deleted"),
|
||||
@Result(property = "createBy", column = "create_by"),
|
||||
@Result(property = "createDt", column = "create_dt"),
|
||||
})
|
||||
List<DataInit> getDataInit();
|
||||
|
||||
@Update("UPDATE data_initialize_schedule SET status = #{status} WHERE id = #{id}")
|
||||
int updateStatus(@Param("id") long id, @Param("status") String status);
|
||||
|
||||
@Insert("INSERT INTO data_initialize_schedule (data_type, create_by) VALUES (#{dataType}, #{createBy})")
|
||||
int postDataInit(@Param("dataType") EInitDataType dataType, @Param("createBy") long createBy);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.caliverse.admin.domain.entity.LandAuction;
|
||||
import com.caliverse.admin.domain.entity.LandOwnerChange;
|
||||
import com.caliverse.admin.domain.entity.Message;
|
||||
import com.caliverse.admin.domain.request.LandRequest;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -12,7 +13,11 @@ import java.util.Map;
|
||||
|
||||
public interface LandMapper {
|
||||
|
||||
List<LandAuction> getAllLandAuction();
|
||||
List<LandOwnerChange> getAllLandOwnedChanges();
|
||||
|
||||
List<LandAuction> getLandAuctionList(Map map);
|
||||
|
||||
int getAllCnt(Map map);
|
||||
int getTotal();
|
||||
LandAuction getLandAuctionDetail(Long id);
|
||||
@@ -33,6 +38,8 @@ public interface LandMapper {
|
||||
int updateLandOwnerChange(LandRequest landRequest);
|
||||
|
||||
int deleteMessage(Map map);
|
||||
int initLandAuction(Long id);
|
||||
int initLandOwnedChanges(Long id);
|
||||
|
||||
int deleteLandAuction(Map map);
|
||||
int deleteLandOwnerChanges(Map map);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.caliverse.admin.domain.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DataInit {
|
||||
private Long id;
|
||||
private EInitDataType dataType;
|
||||
private DATA_INIT_STATUS status;
|
||||
|
||||
private boolean deleted;
|
||||
|
||||
@JsonProperty("create_by")
|
||||
private String createBy;
|
||||
@JsonProperty("create_dt")
|
||||
private LocalDateTime createDt;
|
||||
|
||||
public enum DATA_INIT_STATUS {
|
||||
WAIT,
|
||||
RUNNING,
|
||||
FINISH,
|
||||
FAIL
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.caliverse.admin.domain.entity;
|
||||
|
||||
public enum EInitDataType {
|
||||
None,
|
||||
LandAuction,
|
||||
LandOwned,
|
||||
LandDesc
|
||||
;
|
||||
|
||||
}
|
||||
@@ -48,7 +48,10 @@ public enum HISTORYTYPE {
|
||||
LAND_OWNER_CHANGE_ADD("랜드 소유권 변경 등록"),
|
||||
LAND_OWNER_CHANGE_UPDATE("랜드 소유권 변경 수정"),
|
||||
LAND_OWNER_CHANGE_DELETE("랜드 소유권 변경 예약 취소"),
|
||||
LAND_OWNER_CHANGE_MAIL("랜드 소유권 변경 우편")
|
||||
LAND_OWNER_CHANGE_MAIL("랜드 소유권 변경 우편"),
|
||||
LAND_OWNED_INITIALIZE("랜드 소유권 정보 초기화"),
|
||||
LAND_DESC_INITIALIZE("랜드 정보 초기화"),
|
||||
LAND_AUCTION_INITIALIZE("랜드 경매 초기화"),
|
||||
;
|
||||
private String historyType;
|
||||
HISTORYTYPE(String type) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.caliverse.admin.domain.request;
|
||||
|
||||
import com.caliverse.admin.domain.entity.EInitDataType;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.*;
|
||||
|
||||
@@ -12,7 +13,8 @@ public class AuthenticateRequest {
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
@JsonProperty("new_password")
|
||||
private String newPassword;
|
||||
@JsonProperty("init_data_type")
|
||||
private EInitDataType initDataType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.caliverse.admin.domain.response;
|
||||
|
||||
import com.caliverse.admin.history.domain.DynamodbDataInitializeHistory;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DataResponse {
|
||||
private int status;
|
||||
|
||||
private String result;
|
||||
|
||||
@JsonProperty("data")
|
||||
private ResultData resultData;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public static class ResultData {
|
||||
|
||||
@JsonProperty("init_list")
|
||||
List<DynamodbDataInitializeHistory> dataInitList;
|
||||
|
||||
private String message;
|
||||
|
||||
private int total;
|
||||
@JsonProperty("total_all")
|
||||
private int totalAll;
|
||||
@JsonProperty("page_no")
|
||||
private int pageNo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.DataMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.LandMapper;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.AuthenticateRequest;
|
||||
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||
import com.caliverse.admin.domain.response.DataResponse;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbDataService;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.component.transaction.TransactionIdManager;
|
||||
import com.caliverse.admin.history.domain.DynamodbDataInitializeHistory;
|
||||
import com.caliverse.admin.history.service.DataInitializeHistoryService;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DataService {
|
||||
|
||||
private final DynamodbDataService dynamodbDataService;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
private final LandMapper landMapper;
|
||||
private final DataMapper dataMapper;
|
||||
private final DataInitializeHistoryService dataInitializeHistoryService;
|
||||
private final TransactionIdManager transactionIdManager;
|
||||
|
||||
public DataResponse initHistoryList(LogGenericRequest logGenericRequest){
|
||||
|
||||
LocalDateTime startDt = logGenericRequest.getStartDt().plusHours(9);
|
||||
LocalDateTime endDt = logGenericRequest.getEndDt().plusHours(9).plusDays(1);
|
||||
|
||||
logGenericRequest.setStartDt(startDt);
|
||||
logGenericRequest.setEndDt(endDt);
|
||||
|
||||
List<DynamodbDataInitializeHistory> logList = new ArrayList<>();
|
||||
try{
|
||||
logList = dataInitializeHistoryService.loadHistoryData(logGenericRequest, DynamodbDataInitializeHistory.class);
|
||||
}catch(UncategorizedMongoDbException e){
|
||||
if (e.getMessage().contains("Sort exceeded memory limit")) {
|
||||
log.error("MongoDB Query memory limit error: {}", e.getMessage());
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_LOG_MEMORY_LIMIT.toString())
|
||||
.build();
|
||||
} else {
|
||||
log.error("MongoDB Query error", e);
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_MONGODB_QUERY.toString())
|
||||
.build();
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("dataInitialize error", e);
|
||||
}
|
||||
|
||||
return DataResponse.builder()
|
||||
.resultData(DataResponse.ResultData.builder()
|
||||
.dataInitList(logList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public DataResponse initData(AuthenticateRequest authenticateRequest){
|
||||
EInitDataType dataType = authenticateRequest.getInitDataType();
|
||||
log.info("initData email: {}, initDataType: {}", CommonUtils.getAdmin().getEmail(), dataType);
|
||||
|
||||
dataMapper.postDataInit(dataType, CommonUtils.getAdmin().getId());
|
||||
|
||||
// switch(dataType){
|
||||
// case LandAuction -> {
|
||||
// int result = initLandAuction();
|
||||
// if(result == 0){
|
||||
// return DataResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_DATA_INIT.toString())
|
||||
// .build();
|
||||
// }
|
||||
// }
|
||||
// case LandOwned -> {
|
||||
// int result = initLandOwned();
|
||||
// if(result == 0){
|
||||
// return DataResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_DATA_INIT.toString())
|
||||
// .build();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// dynamodbDataService.InitDataLandOwned();
|
||||
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(DataResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void initLandAuction(LandAuction landAuction){
|
||||
try {
|
||||
long auctionId = landAuction.getId();
|
||||
int result = landMapper.initLandAuction(auctionId);
|
||||
|
||||
List<Message> message = landMapper.getMessage(auctionId);
|
||||
Map map = new HashMap();
|
||||
map.put("id", landAuction.getId());
|
||||
landMapper.deleteMessage(map);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE.name(),
|
||||
landAuction,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
if (!message.isEmpty()) {
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_MESSAGE,
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE.name(),
|
||||
message,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
}
|
||||
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandAuction,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
true,
|
||||
"",
|
||||
landAuction
|
||||
);
|
||||
|
||||
}catch(Exception e){
|
||||
log.error("InitLandAuction Delete Error: {}", e.getMessage());
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandAuction,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
false,
|
||||
e.getMessage(),
|
||||
landAuction
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void initLandOwned(LandOwnerChange landOwnerChange){
|
||||
try {
|
||||
long id = landOwnerChange.getId();
|
||||
landMapper.initLandOwnedChanges(id);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_OWNED_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
HISTORYTYPE.LAND_OWNED_INITIALIZE.name(),
|
||||
landOwnerChange,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandOwned,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
true,
|
||||
"",
|
||||
landOwnerChange
|
||||
);
|
||||
}catch(Exception e){
|
||||
log.error("initLandOwned Delete Error: {}", e.getMessage());
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandOwned,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
false,
|
||||
e.getMessage(),
|
||||
landOwnerChange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public List<DataInit> getScheduleDataInitList(){
|
||||
return dataMapper.getDataInit();
|
||||
}
|
||||
|
||||
public void updateStatus(long id, DataInit.DATA_INIT_STATUS status){
|
||||
dataMapper.updateStatus(id, status.toString());
|
||||
}
|
||||
}
|
||||
@@ -2062,7 +2062,7 @@ public class DynamoDBService {
|
||||
|
||||
// LandAuctionRegistry 객체 생성
|
||||
LandAuctionRegistryDoc registry = new LandAuctionRegistryDoc();
|
||||
registry.setPK(DynamoDBConstants.PK_KEY_LAND_AUCTION);
|
||||
registry.setPK(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY);
|
||||
registry.setSK(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()));
|
||||
registry.setDocType(DynamoDBConstants.DOC_LANDAUCTION);
|
||||
registry.setAttribValue(attrib);
|
||||
@@ -2083,7 +2083,7 @@ public class DynamoDBService {
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
@@ -2132,7 +2132,7 @@ public class DynamoDBService {
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", auctionInfo.getLandId(), auctionInfo.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
@@ -2298,7 +2298,7 @@ public class DynamoDBService {
|
||||
TableSchema.fromBean(LandAuctionRegistryDoc.class));
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", land_id, auction_seq))
|
||||
.build();
|
||||
|
||||
|
||||
@@ -711,6 +711,14 @@ public class LandService {
|
||||
return landMapper.getScheduleLandOwnedChangeList();
|
||||
}
|
||||
|
||||
public List<LandAuction> getAllLandAuctionList(){
|
||||
return landMapper.getAllLandAuction();
|
||||
}
|
||||
|
||||
public List<LandOwnerChange> getAllLandOwnerChangesList(){
|
||||
return landMapper.getAllLandOwnedChanges();
|
||||
}
|
||||
|
||||
public LandAuctionRegistryAttrib getLandAuctionRegistryAttrib(Integer land_id, Integer auction_seq){
|
||||
return dynamodbLandAuctionService.getLandAuctionRegistry(land_id, auction_seq);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user