Compare commits
4 Commits
eed02de94e
...
45e6b05cab
| Author | SHA1 | Date | |
|---|---|---|---|
| 45e6b05cab | |||
| d7c6ce3277 | |||
| 031e97d305 | |||
| ed6d950463 |
@@ -0,0 +1,27 @@
|
|||||||
|
package com.caliverse.admin.domain.api;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.request.AIRequest;
|
||||||
|
import com.caliverse.admin.domain.response.AIResponse;
|
||||||
|
import com.caliverse.admin.domain.service.AIService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Tag(name = "AI 관련", description = "AI api 입니다.")
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/v1/ai")
|
||||||
|
|
||||||
|
public class AIController {
|
||||||
|
|
||||||
|
private final AIService aiService;
|
||||||
|
|
||||||
|
@PostMapping("/analyze")
|
||||||
|
public ResponseEntity<AIResponse> aiAnalyze(@RequestBody AIRequest dataRequest){
|
||||||
|
return ResponseEntity.ok().body(aiService.aiMessageAnalyze(dataRequest));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.caliverse.admin.domain.api;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.request.MenuRequest;
|
||||||
|
import com.caliverse.admin.domain.response.MenuResponse;
|
||||||
|
import com.caliverse.admin.domain.service.MenuService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Tag(name = "메뉴", description = "메뉴 배너 조회 및 관리 api")
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/v1/menu")
|
||||||
|
public class MenuController {
|
||||||
|
|
||||||
|
private final MenuService menuService;
|
||||||
|
|
||||||
|
// 조회
|
||||||
|
@GetMapping("/banner/list")
|
||||||
|
public ResponseEntity<MenuResponse> getList(
|
||||||
|
@RequestParam Map<String, String> requestParam){
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(menuService.getList(requestParam));
|
||||||
|
}
|
||||||
|
// 상세 조회
|
||||||
|
@GetMapping("/banner/detail/{id}")
|
||||||
|
public ResponseEntity<MenuResponse> getList(
|
||||||
|
@PathVariable("id") Long id){
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(menuService.getdetail(id));
|
||||||
|
}
|
||||||
|
@PostMapping("/image-upload")
|
||||||
|
public ResponseEntity<MenuResponse> imageUpload(
|
||||||
|
@RequestParam("file") MultipartFile file){
|
||||||
|
return ResponseEntity.ok().body( menuService.imageUpload(file));
|
||||||
|
}
|
||||||
|
@GetMapping("/image-down")
|
||||||
|
public ResponseEntity<Resource> imageDown(
|
||||||
|
@RequestParam("file") String fileName){
|
||||||
|
Resource resource = menuService.fileDown(fileName);
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
@GetMapping("/image-delete")
|
||||||
|
public ResponseEntity<MenuResponse> imageDelete(
|
||||||
|
@RequestParam("file") String fileName){
|
||||||
|
return ResponseEntity.ok().body( menuService.imageDelete(fileName));
|
||||||
|
}
|
||||||
|
@PostMapping("/banner")
|
||||||
|
public ResponseEntity<MenuResponse> postMenuBanner(
|
||||||
|
@RequestBody MenuRequest menuRequest){
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(menuService.postBanner(menuRequest));
|
||||||
|
}
|
||||||
|
@PutMapping("/banner/{id}")
|
||||||
|
public ResponseEntity<MenuResponse> updateMenuBanner(
|
||||||
|
@PathVariable("id")Long id, @RequestBody MenuRequest menuRequest){
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(menuService.updateBanner(id, menuRequest));
|
||||||
|
}
|
||||||
|
@DeleteMapping("/banner/delete")
|
||||||
|
public ResponseEntity<MenuResponse> deleteMenuBanner(
|
||||||
|
@RequestBody MenuRequest menuRequest){
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(menuService.deleteMail(menuRequest));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.caliverse.admin.domain.dao.admin;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.MenuBanner;
|
||||||
|
import com.caliverse.admin.domain.entity.Message;
|
||||||
|
import com.caliverse.admin.domain.request.MenuRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface MenuMapper {
|
||||||
|
|
||||||
|
List<MenuBanner> getBannerList(Map map);
|
||||||
|
int getTotal();
|
||||||
|
MenuBanner getBannerDetail(Long id);
|
||||||
|
List<Message> getMessage(Long id);
|
||||||
|
List<MenuBanner> getScheduleBannerList();
|
||||||
|
|
||||||
|
void insertBanner(MenuRequest mailRequest);
|
||||||
|
void insertMessage(Map map);
|
||||||
|
|
||||||
|
int updateBanner(MenuRequest mailRequest);
|
||||||
|
int updateBannerStatus(Map map);
|
||||||
|
|
||||||
|
int deleteMessage(Map map);
|
||||||
|
void deleteBanner(Map map);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.caliverse.admin.domain.entity.AI;
|
||||||
|
|
||||||
|
public enum AIRequestType {
|
||||||
|
BUSINESS_LOG,
|
||||||
|
MAIL
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.caliverse.admin.domain.entity.AI;
|
||||||
|
|
||||||
|
public enum AIRole {
|
||||||
|
user,
|
||||||
|
system,
|
||||||
|
assistant
|
||||||
|
}
|
||||||
@@ -52,6 +52,9 @@ public enum HISTORYTYPE {
|
|||||||
LAND_OWNED_INITIALIZE("랜드 소유권 정보 초기화"),
|
LAND_OWNED_INITIALIZE("랜드 소유권 정보 초기화"),
|
||||||
LAND_DESC_INITIALIZE("랜드 정보 초기화"),
|
LAND_DESC_INITIALIZE("랜드 정보 초기화"),
|
||||||
LAND_AUCTION_INITIALIZE("랜드 경매 초기화"),
|
LAND_AUCTION_INITIALIZE("랜드 경매 초기화"),
|
||||||
|
MENU_BANNER_ADD("메뉴 배너 등록"),
|
||||||
|
MENU_BANNER_UPDATE("메뉴 배너 수정"),
|
||||||
|
MENU_BANNER_DELETE("메뉴 배너 삭제"),
|
||||||
;
|
;
|
||||||
private String historyType;
|
private String historyType;
|
||||||
HISTORYTYPE(String type) {
|
HISTORYTYPE(String type) {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class MenuBanner {
|
||||||
|
private Long id;
|
||||||
|
@JsonProperty("row_num")
|
||||||
|
private Long rowNum;
|
||||||
|
private String title;
|
||||||
|
private BANNER_STATUS status;
|
||||||
|
@JsonProperty("image_list")
|
||||||
|
private List<Message> imageList;
|
||||||
|
@JsonProperty("start_dt")
|
||||||
|
private LocalDateTime startDt;
|
||||||
|
@JsonProperty("end_dt")
|
||||||
|
private LocalDateTime endDt;
|
||||||
|
@JsonProperty("is_link")
|
||||||
|
private boolean isLink;
|
||||||
|
|
||||||
|
@JsonProperty("create_by")
|
||||||
|
private String createBy;
|
||||||
|
@JsonProperty("create_dt")
|
||||||
|
private LocalDateTime createDt;
|
||||||
|
@JsonProperty("update_by")
|
||||||
|
private String updateBy;
|
||||||
|
@JsonProperty("update_dt")
|
||||||
|
private LocalDateTime updateDt;
|
||||||
|
|
||||||
|
public static class Guid{
|
||||||
|
String guid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BANNER_STATUS {
|
||||||
|
WAIT,
|
||||||
|
FINISH,
|
||||||
|
FAIL,
|
||||||
|
RUNNING,
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.caliverse.admin.domain.request;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.AI.AIRequestType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AIRequest {
|
||||||
|
private String message;
|
||||||
|
private AIRequestType type;
|
||||||
|
private Map<String, Object> conditions;
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.caliverse.admin.domain.request;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.Message;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MenuRequest {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
@JsonProperty("image_list")
|
||||||
|
private List<Message> imageList;
|
||||||
|
@JsonProperty("start_dt")
|
||||||
|
private LocalDateTime startDt;
|
||||||
|
@JsonProperty("end_dt")
|
||||||
|
private LocalDateTime endDt;
|
||||||
|
@JsonProperty("is_link")
|
||||||
|
private boolean isLink;
|
||||||
|
@JsonProperty("link_list")
|
||||||
|
private List<Message> linkList;
|
||||||
|
|
||||||
|
@JsonProperty("create_by")
|
||||||
|
private Long createBy;
|
||||||
|
@JsonProperty("create_dt")
|
||||||
|
private LocalDateTime createDt;
|
||||||
|
@JsonProperty("update_by")
|
||||||
|
private Long updateBy;
|
||||||
|
@JsonProperty("update_dt")
|
||||||
|
private LocalDateTime updateDt;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class DeleteMailItem {
|
||||||
|
private String type;
|
||||||
|
private String guid;
|
||||||
|
@JsonProperty("mail_guid")
|
||||||
|
private String MailGuid;
|
||||||
|
@JsonProperty("item_id")
|
||||||
|
private Long itemId;
|
||||||
|
@JsonProperty("parrent_count")
|
||||||
|
private Double parrentCount;
|
||||||
|
private Double count;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.caliverse.admin.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class OpenAIRequest {
|
||||||
|
private String model;
|
||||||
|
private List<Map<String, String>> messages;
|
||||||
|
@Builder.Default
|
||||||
|
private double temperature = 0.7;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
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 AIResponse {
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
@JsonProperty("data")
|
||||||
|
private ResultData resultData;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public static class ResultData {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
private int total;
|
||||||
|
@JsonProperty("total_all")
|
||||||
|
private int totalAll;
|
||||||
|
@JsonProperty("page_no")
|
||||||
|
private int pageNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.caliverse.admin.domain.response;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.MenuBanner;
|
||||||
|
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 MenuResponse {
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
@JsonProperty("data")
|
||||||
|
private ResultData resultData;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public static class ResultData{
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@JsonProperty("detail")
|
||||||
|
private MenuBanner banner;
|
||||||
|
|
||||||
|
@JsonProperty("list")
|
||||||
|
private List<MenuBanner> bannerList;
|
||||||
|
@JsonProperty("file_name")
|
||||||
|
private String fileName;
|
||||||
|
private int total;
|
||||||
|
@JsonProperty("total_all")
|
||||||
|
private int totalAll;
|
||||||
|
@JsonProperty("page_no")
|
||||||
|
private int pageNo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.caliverse.admin.domain.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class OpenAIResponse {
|
||||||
|
private List<Choice> choices;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public static class Choice {
|
||||||
|
private Message message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public static class Message {
|
||||||
|
private String role;
|
||||||
|
private String content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.caliverse.admin.domain.response;
|
|||||||
|
|
||||||
import com.caliverse.admin.domain.entity.FriendRequest;
|
import com.caliverse.admin.domain.entity.FriendRequest;
|
||||||
import com.caliverse.admin.domain.entity.LANGUAGETYPE;
|
import com.caliverse.admin.domain.entity.LANGUAGETYPE;
|
||||||
|
import com.caliverse.admin.dynamodb.entity.ELanguageType;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -74,7 +75,7 @@ public class UsersResponse {
|
|||||||
private String aid;
|
private String aid;
|
||||||
@JsonProperty("user_id")
|
@JsonProperty("user_id")
|
||||||
private String userId;
|
private String userId;
|
||||||
private LANGUAGETYPE nation;
|
private ELanguageType nation;
|
||||||
private String membership;
|
private String membership;
|
||||||
//친구 추천코드
|
//친구 추천코드
|
||||||
@JsonProperty("friend_code")
|
@JsonProperty("friend_code")
|
||||||
@@ -108,16 +109,16 @@ public class UsersResponse {
|
|||||||
private String level;
|
private String level;
|
||||||
//골드
|
//골드
|
||||||
@JsonProperty("gold_cali")
|
@JsonProperty("gold_cali")
|
||||||
private String goldCali;
|
private Double goldCali;
|
||||||
//사파이어
|
//사파이어
|
||||||
@JsonProperty("blue_cali")
|
@JsonProperty("blue_cali")
|
||||||
private String blueCali;
|
private Double blueCali;
|
||||||
//칼리움
|
//칼리움
|
||||||
@JsonProperty("red_cali")
|
@JsonProperty("red_cali")
|
||||||
private String redCali;
|
private Double redCali;
|
||||||
//루비
|
//루비
|
||||||
@JsonProperty("black_cali")
|
@JsonProperty("black_cali")
|
||||||
private String blackCali;
|
private Double blackCali;
|
||||||
|
|
||||||
}
|
}
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
110
src/main/java/com/caliverse/admin/domain/service/AIService.java
Normal file
110
src/main/java/com/caliverse/admin/domain/service/AIService.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package com.caliverse.admin.domain.service;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.dao.admin.MailMapper;
|
||||||
|
import com.caliverse.admin.domain.entity.AI.AIRequestType;
|
||||||
|
import com.caliverse.admin.domain.entity.AI.AIRole;
|
||||||
|
import com.caliverse.admin.domain.entity.Mail;
|
||||||
|
import com.caliverse.admin.domain.request.AIRequest;
|
||||||
|
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||||
|
import com.caliverse.admin.domain.request.OpenAIRequest;
|
||||||
|
import com.caliverse.admin.domain.response.AIResponse;
|
||||||
|
import com.caliverse.admin.domain.response.OpenAIResponse;
|
||||||
|
import com.caliverse.admin.global.common.code.CommonCode;
|
||||||
|
import com.caliverse.admin.global.common.constants.CommonConstants;
|
||||||
|
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||||
|
import com.caliverse.admin.logs.Indicatordomain.GenericMongoLog;
|
||||||
|
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogGenericService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AIService {
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper mapper;
|
||||||
|
|
||||||
|
private final OpenAIService openAIService;
|
||||||
|
private final BusinessLogGenericService businessLogGenericService;
|
||||||
|
private final MailMapper mailMapper;
|
||||||
|
|
||||||
|
public AIResponse aiMessageAnalyze(AIRequest dataRequest){
|
||||||
|
List<Map<String,String>> messages = initMessage();
|
||||||
|
|
||||||
|
List<?> data = getDataList(dataRequest.getType(), dataRequest.getConditions());
|
||||||
|
|
||||||
|
messages = splitDataToMessages(messages, data, dataRequest.getMessage());
|
||||||
|
|
||||||
|
OpenAIRequest openAIRequest = new OpenAIRequest();
|
||||||
|
openAIRequest.setMessages(messages);
|
||||||
|
|
||||||
|
OpenAIResponse result = openAIService.askOpenAI(openAIRequest);
|
||||||
|
log.info(result.getChoices().get(0).getMessage().getContent());
|
||||||
|
return AIResponse.builder()
|
||||||
|
.resultData(AIResponse.ResultData.builder()
|
||||||
|
.result(result.getChoices().get(0).getMessage().getContent())
|
||||||
|
.build())
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, String>> splitDataToMessages(List<Map<String,String>> messages, List<?> dataList, String userMessage) {
|
||||||
|
String dataJson;
|
||||||
|
try {
|
||||||
|
dataJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(dataList);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException("JSON 변환 실패", e);
|
||||||
|
}
|
||||||
|
messages.add(CommonUtils.getAIMessage(AIRole.user, messageMerge(userMessage, dataJson)));
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String messageMerge(String message, String data){
|
||||||
|
return String.format("사용자 질문: %s\n\n아래는 시스템이 제공하는 데이터입니다.\n%s", message, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String,String>> initMessage(){
|
||||||
|
List<Map<String,String>> messages = new ArrayList<>();
|
||||||
|
messages.add(CommonUtils.getAIMessage(AIRole.system,
|
||||||
|
"""
|
||||||
|
너는 프론트엔드 게시용 데이터를 생성하는 게임 데이터 분석 AI야. \
|
||||||
|
사용자는 게임 로그 데이터와 함께 다양한 질문을 보낼 수 있어. \
|
||||||
|
너는 항상 HTML 또는 React 코드 형식으로 응답해야 해. \
|
||||||
|
응답에는 반드시 다음 항목을 포함해줘: \
|
||||||
|
1) 분석된 내용 설명 \
|
||||||
|
2) 분석된 요약 결과 (표 또는 문단) \
|
||||||
|
3) 시각화 차트 (예: bar chart, pie chart 등) \
|
||||||
|
응답은 반드시 한국어로 작성해. \
|
||||||
|
절대로 파이썬, Java, Node.js 코드 같은 것은 포함하지 마. \
|
||||||
|
사용자의 웹에 그대로 게시될 수 있는 코드만 생성해. \
|
||||||
|
React를 쓸 경우, React 18 기준 코드로 TailwindCSS 기반의 스타일을 사용해줘.
|
||||||
|
"""));
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<?> getDataList(AIRequestType type, Map<String, Object> conditions){
|
||||||
|
switch (type){
|
||||||
|
case BUSINESS_LOG -> {
|
||||||
|
LogGenericRequest logReq = mapper.convertValue(conditions, LogGenericRequest.class);
|
||||||
|
List<GenericMongoLog> logs = businessLogGenericService.loadBusinessLogData(logReq, GenericMongoLog.class, true);
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
case MAIL -> {
|
||||||
|
List<Mail> mailList = mailMapper.getMailList(conditions);
|
||||||
|
return mailList;
|
||||||
|
}
|
||||||
|
default -> throw new RuntimeException("Not Type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -158,12 +158,12 @@ public class BlackListService {
|
|||||||
if(item.getGuid() != null){
|
if(item.getGuid() != null){
|
||||||
String guid = item.getGuid();
|
String guid = item.getGuid();
|
||||||
if(dynamoDBService.isGuidChecked(guid)){
|
if(dynamoDBService.isGuidChecked(guid)){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.toString());
|
||||||
}
|
}
|
||||||
// boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(guid);
|
// boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(guid);
|
||||||
boolean isBlackUser = dynamodbUserService.isBlockUser(guid);
|
boolean isBlackUser = dynamodbUserService.isBlockUser(guid);
|
||||||
if(isBlackUser){
|
if(isBlackUser){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USER_BLOCK_REGIST_DUPLE_WARNING.toString());
|
||||||
}
|
}
|
||||||
blackListRequest.setGuid(guid);
|
blackListRequest.setGuid(guid);
|
||||||
blackListRequest.setNickname(item.getNickname());
|
blackListRequest.setNickname(item.getNickname());
|
||||||
@@ -180,15 +180,15 @@ public class BlackListService {
|
|||||||
//adminDB 에 데이터 있는지 체크
|
//adminDB 에 데이터 있는지 체크
|
||||||
int cnt = blackListMapper.getCountByGuid(item.getGuid());
|
int cnt = blackListMapper.getCountByGuid(item.getGuid());
|
||||||
if(cnt > 0){
|
if(cnt > 0){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ADMINDB_EXIT_ERROR.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USER_BLOCK_REGIST_DUPLE_WARNING.toString());
|
||||||
}
|
}
|
||||||
if(dynamoDBService.isGuidChecked(item.getGuid())){
|
if(dynamoDBService.isGuidChecked(item.getGuid())){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.toString());
|
||||||
}
|
}
|
||||||
// boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(item.getGuid());
|
// boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(item.getGuid());
|
||||||
boolean isBlackUser = dynamodbUserService.isBlockUser(item.getGuid());
|
boolean isBlackUser = dynamodbUserService.isBlockUser(item.getGuid());
|
||||||
if(isBlackUser){
|
if(isBlackUser){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USER_BLOCK_REGIST_DUPLE_WARNING.toString());
|
||||||
}
|
}
|
||||||
blackListRequest.setGuid(item.getGuid());
|
blackListRequest.setGuid(item.getGuid());
|
||||||
blackListRequest.setNickname(dynamodbUserService.getGuidByName(item.getGuid()));
|
blackListRequest.setNickname(dynamodbUserService.getGuidByName(item.getGuid()));
|
||||||
|
|||||||
@@ -325,92 +325,92 @@ public class DynamoDBService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> getAccountInfo(String guid){
|
// public Map<String, Object> getAccountInfo(String guid){
|
||||||
Map<String, Object> resMap = new HashMap<>();
|
// Map<String, Object> resMap = new HashMap<>();
|
||||||
|
//
|
||||||
String key = "PK = :pkValue AND SK = :skValue";
|
// String key = "PK = :pkValue AND SK = :skValue";
|
||||||
Map<String, AttributeValue> values = Map.of(":pkValue", AttributeValue.builder().s("account_base#"+guid).build()
|
// Map<String, AttributeValue> values = Map.of(":pkValue", AttributeValue.builder().s("account_base#"+guid).build()
|
||||||
,":skValue", AttributeValue.builder().s("empty").build());
|
// ,":skValue", AttributeValue.builder().s("empty").build());
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
// 쿼리 실행
|
// // 쿼리 실행
|
||||||
QueryResponse response = executeQuery(key, values);
|
// QueryResponse response = executeQuery(key, values);
|
||||||
|
//
|
||||||
// 응답에서 원하는 속성을 가져옵니다.
|
// // 응답에서 원하는 속성을 가져옵니다.
|
||||||
for (Map<String, AttributeValue> item : response.items()) {
|
// for (Map<String, AttributeValue> item : response.items()) {
|
||||||
AttributeValue attrValue = item.get("AccountBaseAttrib");
|
// AttributeValue attrValue = item.get("AccountBaseAttrib");
|
||||||
if (attrValue != null) {
|
// if (attrValue != null) {
|
||||||
// "Attr" 속성의 값을 읽어옵니다.
|
// // "Attr" 속성의 값을 읽어옵니다.
|
||||||
String attrJson = attrValue.s();
|
// String attrJson = attrValue.s();
|
||||||
|
//
|
||||||
// JSON 문자열을 파싱하여 Map 또는 다른 객체로 변환합니다.
|
// // JSON 문자열을 파싱하여 Map 또는 다른 객체로 변환합니다.
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Map<String, Object> attrMap = objectMapper.readValue(attrJson, new TypeReference<Map<String, Object>>() {});
|
// Map<String, Object> attrMap = objectMapper.readValue(attrJson, new TypeReference<Map<String, Object>>() {});
|
||||||
|
//
|
||||||
resMap.put("userInfo", UsersResponse.UserInfo.builder()
|
// resMap.put("userInfo", UsersResponse.UserInfo.builder()
|
||||||
.aid(CommonUtils.objectToString(attrMap.get("user_guid")))
|
// .aid(CommonUtils.objectToString(attrMap.get("user_guid")))
|
||||||
.userId(CommonUtils.objectToString(attrMap.get("account_id")))
|
// .userId(CommonUtils.objectToString(attrMap.get("account_id")))
|
||||||
.nation(LANGUAGETYPE.values()[CommonUtils.objectToInteger(attrMap.get("language_type"))])
|
// .nation(LANGUAGETYPE.values()[CommonUtils.objectToInteger(attrMap.get("language_type"))])
|
||||||
//
|
// //
|
||||||
.membership(CommonUtils.objectToString(null))
|
// .membership(CommonUtils.objectToString(null))
|
||||||
//todo 친구 추천 코드 임시 null 값으로 셋팅 23.09.20
|
// //todo 친구 추천 코드 임시 null 값으로 셋팅 23.09.20
|
||||||
.friendCode(CommonUtils.objectToString(null))
|
// .friendCode(CommonUtils.objectToString(null))
|
||||||
.createDt(CommonUtils.objectToString(attrMap.get("created_datetime")))
|
// .createDt(CommonUtils.objectToString(attrMap.get("created_datetime")))
|
||||||
.accessDt(CommonUtils.objectToString(attrMap.get("login_datetime")))
|
// .accessDt(CommonUtils.objectToString(attrMap.get("login_datetime")))
|
||||||
.endDt(CommonUtils.objectToString(attrMap.get("logout_datetime")))
|
// .endDt(CommonUtils.objectToString(attrMap.get("logout_datetime")))
|
||||||
.walletUrl(CommonUtils.objectToString(attrMap.get("connect_facewallet")))
|
// .walletUrl(CommonUtils.objectToString(attrMap.get("connect_facewallet")))
|
||||||
.adminLevel(CommonUtils.objectToString(attrMap.get("auth_amdin_level_type")))
|
// .adminLevel(CommonUtils.objectToString(attrMap.get("auth_amdin_level_type")))
|
||||||
//todo 예비슬롯 임시 null 값으로 셋팅 23.09.20
|
// //todo 예비슬롯 임시 null 값으로 셋팅 23.09.20
|
||||||
.spareSlot(CommonUtils.objectToString(null))
|
// .spareSlot(CommonUtils.objectToString(null))
|
||||||
.build());
|
// .build());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
log.info("getAccountInfo UserInfo: {}", resMap);
|
// log.info("getAccountInfo UserInfo: {}", resMap);
|
||||||
|
//
|
||||||
return resMap;
|
// return resMap;
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 유저조회 - 기본정보
|
// // 유저조회 - 기본정보
|
||||||
public Map<String, Object> getCharInfo(String guid){
|
// public Map<String, Object> getCharInfo(String guid){
|
||||||
Map<String, Object> resMap = new HashMap<>();
|
// Map<String, Object> resMap = new HashMap<>();
|
||||||
|
//
|
||||||
String key = "PK = :pkValue AND SK = :skValue";
|
// String key = "PK = :pkValue AND SK = :skValue";
|
||||||
Map<String, AttributeValue> values = Map.of(":pkValue", AttributeValue.builder().s("money#"+guid).build()
|
// Map<String, AttributeValue> values = Map.of(":pkValue", AttributeValue.builder().s("money#"+guid).build()
|
||||||
,":skValue", AttributeValue.builder().s("empty").build());
|
// ,":skValue", AttributeValue.builder().s("empty").build());
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
// 쿼리 실행
|
// // 쿼리 실행
|
||||||
QueryResponse response = executeQuery(key, values);
|
// QueryResponse response = executeQuery(key, values);
|
||||||
|
//
|
||||||
// 응답에서 원하는 속성을 가져옵니다.
|
// // 응답에서 원하는 속성을 가져옵니다.
|
||||||
for (Map<String, AttributeValue> item : response.items()) {
|
// for (Map<String, AttributeValue> item : response.items()) {
|
||||||
|
//
|
||||||
//캐릭터 CharInfo 조회
|
// //캐릭터 CharInfo 조회
|
||||||
AttributeValue charValue = item.get("MoneyAttrib");
|
// AttributeValue charValue = item.get("MoneyAttrib");
|
||||||
if (charValue != null) {
|
// if (charValue != null) {
|
||||||
// "Attr" 속성의 값을 읽어옵니다.
|
// // "Attr" 속성의 값을 읽어옵니다.
|
||||||
Map<String, AttributeValue> attrMap = charValue.m();
|
// Map<String, AttributeValue> attrMap = charValue.m();
|
||||||
|
//
|
||||||
resMap.put("charInfo", UsersResponse.CharInfo.builder()
|
// resMap.put("charInfo", UsersResponse.CharInfo.builder()
|
||||||
.characterName(getGuidByName(guid))
|
// .characterName(getGuidByName(guid))
|
||||||
.level(CommonUtils.objectToString(null))
|
// .level(CommonUtils.objectToString(null))
|
||||||
.goldCali(CommonUtils.objectToString(attrMap.get("gold").n()))
|
// .goldCali(CommonUtils.objectToString(attrMap.get("gold").n()))
|
||||||
.redCali(CommonUtils.objectToString(attrMap.get("calium").n()))
|
// .redCali(CommonUtils.objectToString(attrMap.get("calium").n()))
|
||||||
.blackCali(CommonUtils.objectToString(attrMap.get("ruby").n()))
|
// .blackCali(CommonUtils.objectToString(attrMap.get("ruby").n()))
|
||||||
.blueCali(CommonUtils.objectToString(attrMap.get("sapphire").n()))
|
// .blueCali(CommonUtils.objectToString(attrMap.get("sapphire").n()))
|
||||||
.build());
|
// .build());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
log.info("getCharInfo CharInfo: {}", resMap);
|
// log.info("getCharInfo CharInfo: {}", resMap);
|
||||||
|
//
|
||||||
return resMap;
|
// return resMap;
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 유저조회 - 아바타
|
// 유저조회 - 아바타
|
||||||
public Map<String, Object> getAvatarInfo(String guid){
|
public Map<String, Object> getAvatarInfo(String guid){
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static com.caliverse.admin.global.common.utils.CommonUtils.convertIsoByDatetime;
|
import static com.caliverse.admin.global.common.utils.CommonUtils.convertIsoByDatetime;
|
||||||
import static com.caliverse.admin.global.common.utils.DateUtils.stringToDateTime;
|
|
||||||
import static com.caliverse.admin.global.common.utils.DateUtils.stringISOToLocalDateTime;
|
import static com.caliverse.admin.global.common.utils.DateUtils.stringISOToLocalDateTime;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -445,7 +444,7 @@ public class LandService {
|
|||||||
if(nickname.isEmpty() || !nickname.equals(landRequest.getUserName())){
|
if(nickname.isEmpty() || !nickname.equals(landRequest.getUserName())){
|
||||||
return LandResponse.builder()
|
return LandResponse.builder()
|
||||||
.status(CommonCode.ERROR.getHttpStatus())
|
.status(CommonCode.ERROR.getHttpStatus())
|
||||||
.result(ErrorCode.GUID_CHECK.toString())
|
.result(ErrorCode.WARNING_GUID_CHECK.toString())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,10 @@ public class LogService {
|
|||||||
int page = logGenericRequest.getPageNo();
|
int page = logGenericRequest.getPageNo();
|
||||||
int size = logGenericRequest.getPageSize();
|
int size = logGenericRequest.getPageSize();
|
||||||
|
|
||||||
LocalDateTime startDt = logGenericRequest.getStartDt().plusHours(9);
|
// LocalDateTime startDt = logGenericRequest.getStartDt().plusHours(9);
|
||||||
LocalDateTime endDt = logGenericRequest.getEndDt().plusHours(9).plusDays(1);
|
// LocalDateTime endDt = logGenericRequest.getEndDt().plusHours(9).plusDays(1);
|
||||||
|
// logGenericRequest.setStartDt(startDt);
|
||||||
logGenericRequest.setStartDt(startDt);
|
// logGenericRequest.setEndDt(endDt);
|
||||||
logGenericRequest.setEndDt(endDt);
|
|
||||||
|
|
||||||
// List<Map<String, Object>> logList = businessLogGenericService.loadBusinessLogData(logGenericRequest);
|
// List<Map<String, Object>> logList = businessLogGenericService.loadBusinessLogData(logGenericRequest);
|
||||||
List<GenericMongoLog> logList = new ArrayList<>();
|
List<GenericMongoLog> logList = new ArrayList<>();
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class MailService {
|
|||||||
if(mailRequest.getGuid() != null){
|
if(mailRequest.getGuid() != null){
|
||||||
if(mailRequest.getUserType().equals(Mail.USERTYPE.GUID) && dynamoDBService.isGuidChecked(mailRequest.getGuid())){
|
if(mailRequest.getUserType().equals(Mail.USERTYPE.GUID) && dynamoDBService.isGuidChecked(mailRequest.getGuid())){
|
||||||
log.error("postMail RECEIVETYPE Single Guid Find Fail");
|
log.error("postMail RECEIVETYPE Single Guid Find Fail");
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.getMessage());
|
||||||
}
|
}
|
||||||
String guid = mailRequest.getGuid();
|
String guid = mailRequest.getGuid();
|
||||||
// 닉네임이면 guid로 바꾼다
|
// 닉네임이면 guid로 바꾼다
|
||||||
@@ -213,7 +213,7 @@ public class MailService {
|
|||||||
case "GUID" -> {
|
case "GUID" -> {
|
||||||
if (dynamoDBService.isGuidChecked(excel.getUser())) {
|
if (dynamoDBService.isGuidChecked(excel.getUser())) {
|
||||||
log.error("postMail Multi Guid({}) Find Fail", excel.getUser());
|
log.error("postMail Multi Guid({}) Find Fail", excel.getUser());
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.toString());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "NICKNAME" -> {
|
case "NICKNAME" -> {
|
||||||
|
|||||||
@@ -0,0 +1,325 @@
|
|||||||
|
package com.caliverse.admin.domain.service;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.dao.admin.MenuMapper;
|
||||||
|
import com.caliverse.admin.domain.entity.*;
|
||||||
|
import com.caliverse.admin.domain.request.MenuRequest;
|
||||||
|
import com.caliverse.admin.domain.response.MenuResponse;
|
||||||
|
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.CommonConstants;
|
||||||
|
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||||
|
import com.caliverse.admin.global.common.exception.RestApiException;
|
||||||
|
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||||
|
import com.caliverse.admin.global.common.utils.FileUtils;
|
||||||
|
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import software.amazon.awssdk.services.s3.model.S3Exception;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MenuService {
|
||||||
|
|
||||||
|
@Value("${excel.file-path}")
|
||||||
|
private String filePath;
|
||||||
|
@Value("${caliverse.file}")
|
||||||
|
private String samplePath;
|
||||||
|
private final FileUtils fileUtils;
|
||||||
|
private final MenuMapper menuMapper;
|
||||||
|
private final ResourceLoader resourceLoader;
|
||||||
|
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||||
|
private final S3Service s3Service;
|
||||||
|
|
||||||
|
public MenuResponse getList(Map requestParam){
|
||||||
|
|
||||||
|
//페이징 처리
|
||||||
|
requestParam = CommonUtils.pageSetting(requestParam);
|
||||||
|
|
||||||
|
List<MenuBanner> list = menuMapper.getBannerList(requestParam);
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.bannerList(list)
|
||||||
|
.total(menuMapper.getTotal())
|
||||||
|
.totalAll(list.size())
|
||||||
|
.pageNo(requestParam.get("page_no")!=null?
|
||||||
|
Integer.valueOf(requestParam.get("page_no").toString()):1)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuResponse getdetail(Long id){
|
||||||
|
MenuBanner banner = menuMapper.getBannerDetail(id);
|
||||||
|
|
||||||
|
banner.setImageList(menuMapper.getMessage(id));
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.banner(banner)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuResponse imageUpload(MultipartFile file){
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_FILE.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일을 서버에 저장
|
||||||
|
String fileName = fileUtils.saveFile(file);
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(SuccessCode.EXCEL_UPLOAD.getMessage())
|
||||||
|
.fileName(fileName)
|
||||||
|
.build())
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuResponse imageDelete(String fileName){
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_FILE.getMessage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 서버 파일 삭제
|
||||||
|
boolean is_delete = fileUtils.deleteFile(fileName);
|
||||||
|
|
||||||
|
if(is_delete){
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(SuccessCode.FILE_DELETE.getMessage())
|
||||||
|
.build())
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.build();
|
||||||
|
}else{
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(ErrorCode.ERROR_FILE_DELETE.getMessage())
|
||||||
|
.build())
|
||||||
|
.status(CommonCode.ERROR.getHttpStatus())
|
||||||
|
.result(CommonCode.ERROR.getResult())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource fileDown(String fileName) {
|
||||||
|
Path fileFullPath = Path.of(filePath+fileName);
|
||||||
|
try {
|
||||||
|
if(fileName.contains("sample")){
|
||||||
|
return resourceLoader.getResource(samplePath + fileName);
|
||||||
|
}
|
||||||
|
Resource resource = new UrlResource(fileFullPath.toUri());
|
||||||
|
if (resource.exists() && resource.isReadable()) {
|
||||||
|
return resource;
|
||||||
|
} else {
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage());
|
||||||
|
}
|
||||||
|
}catch (MalformedURLException e){
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(transactionManager = "transactionManager")
|
||||||
|
public MenuResponse postBanner(MenuRequest menuRequest){
|
||||||
|
menuRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||||
|
|
||||||
|
menuMapper.insertBanner(menuRequest);
|
||||||
|
|
||||||
|
long banner_id = menuRequest.getId();
|
||||||
|
HashMap<String,String> map = new HashMap<>();
|
||||||
|
map.put("id",String.valueOf(banner_id));
|
||||||
|
|
||||||
|
//메시지 저장(title=이미지명, content=이미지 링크)
|
||||||
|
if(menuRequest.getImageList()!= null && !menuRequest.getImageList().isEmpty()){
|
||||||
|
menuRequest.getImageList().forEach(image -> {
|
||||||
|
String temp_file = image.getContent();
|
||||||
|
String contentType = fileUtils.getContentType(temp_file);
|
||||||
|
File file = fileUtils.loadFileObject(temp_file);
|
||||||
|
String fileUri = "";
|
||||||
|
try{
|
||||||
|
fileUri = s3Service.uploadFile(file, CommonConstants.S3_MENU_BANNER_DIRECTORY + banner_id, contentType);
|
||||||
|
}catch (S3Exception e) {
|
||||||
|
log.error("S3 오류: {}", e.getMessage());
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_S3_UPLOAD.getMessage());
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("파일 읽기 오류: {}", e.getMessage());
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_S3_UPLOAD.getMessage());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("파일 업로드 중 예상치 못한 오류: {}", e.getMessage(), e);
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_S3_UPLOAD.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fileUri.isEmpty()){
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_S3_UPLOAD.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
map.put("title", fileUri);
|
||||||
|
map.put("language", image.getLanguage());
|
||||||
|
if(menuRequest.isLink() && (menuRequest.getLinkList() != null && !menuRequest.getLinkList().isEmpty())){
|
||||||
|
String link = menuRequest.getLinkList().stream().filter(data -> data.getLanguage().equals(image.getLanguage())).findFirst().get().getContent();
|
||||||
|
map.put("content", link);
|
||||||
|
}else{
|
||||||
|
map.put("content", "");
|
||||||
|
}
|
||||||
|
menuMapper.insertMessage(map);
|
||||||
|
|
||||||
|
fileUtils.deleteFile(temp_file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuBanner banner = menuMapper.getBannerDetail(menuRequest.getId());
|
||||||
|
|
||||||
|
mysqlHistoryLogService.insertHistoryLog(
|
||||||
|
HISTORYTYPE.MENU_BANNER_ADD,
|
||||||
|
MysqlConstants.TABLE_NAME_MENU_BANNER,
|
||||||
|
HISTORYTYPE.MENU_BANNER_ADD.name(),
|
||||||
|
banner,
|
||||||
|
CommonUtils.getAdmin().getEmail(),
|
||||||
|
CommonUtils.getClientIp()
|
||||||
|
);
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(SuccessCode.SAVE.getMessage())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(transactionManager = "transactionManager")
|
||||||
|
public MenuResponse updateBanner(Long id, MenuRequest menuRequest) {
|
||||||
|
menuRequest.setId(id);
|
||||||
|
menuRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||||
|
menuRequest.setUpdateDt(LocalDateTime.now());
|
||||||
|
|
||||||
|
Long banner_id = menuRequest.getId();
|
||||||
|
MenuBanner before_info = menuMapper.getBannerDetail(banner_id);
|
||||||
|
List<Message> before_msg = menuMapper.getMessage(banner_id);
|
||||||
|
before_info.setImageList(before_msg);
|
||||||
|
|
||||||
|
log.info("updateBanner Update Before MenuBanner: {}, Images: {}", before_info, before_msg);
|
||||||
|
|
||||||
|
menuMapper.updateBanner(menuRequest);
|
||||||
|
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("id", String.valueOf(menuRequest.getId()));
|
||||||
|
|
||||||
|
menuMapper.deleteMessage(map);
|
||||||
|
|
||||||
|
if(menuRequest.getImageList()!= null && !menuRequest.getImageList().isEmpty()){
|
||||||
|
menuRequest.getImageList().forEach(image -> {
|
||||||
|
map.put("title", image.getContent());
|
||||||
|
map.put("language", image.getLanguage());
|
||||||
|
if(menuRequest.isLink() && menuRequest.getLinkList() != null && !menuRequest.getLinkList().isEmpty()){
|
||||||
|
String link = menuRequest.getLinkList().stream().filter(data -> data.getLanguage().equals(image.getLanguage())).findFirst().get().getContent();
|
||||||
|
map.put("content", link);
|
||||||
|
}
|
||||||
|
menuMapper.insertMessage(map);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
log.info("updateBanner Update After Banner: {}", menuRequest);
|
||||||
|
|
||||||
|
MenuBanner after_info = menuMapper.getBannerDetail(banner_id);
|
||||||
|
after_info.setImageList(menuMapper.getMessage(banner_id));
|
||||||
|
|
||||||
|
mysqlHistoryLogService.updateHistoryLog(
|
||||||
|
HISTORYTYPE.MENU_BANNER_UPDATE,
|
||||||
|
MysqlConstants.TABLE_NAME_MENU_BANNER,
|
||||||
|
HISTORYTYPE.MENU_BANNER_UPDATE.name(),
|
||||||
|
before_info,
|
||||||
|
after_info,
|
||||||
|
CommonUtils.getAdmin().getEmail(),
|
||||||
|
CommonUtils.getClientIp()
|
||||||
|
);
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(SuccessCode.UPDATE.getMessage())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(transactionManager = "transactionManager")
|
||||||
|
public MenuResponse deleteMail(MenuRequest menuRequest){
|
||||||
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
// mailRequest.getList().forEach(
|
||||||
|
// item->{
|
||||||
|
// map.put("id",item.getId());
|
||||||
|
// mailMapper.deleteMail(map);
|
||||||
|
//
|
||||||
|
// // 스케줄에서 제거
|
||||||
|
// scheduleService.closeTask("mail-" + item.getId());
|
||||||
|
// log.info("deleteMail Mail: {}", item);
|
||||||
|
//
|
||||||
|
// //로그 기록
|
||||||
|
// List<Message> message = mailMapper.getMessage(Long.valueOf(item.getId()));
|
||||||
|
// map.put("adminId", CommonUtils.getAdmin().getId());
|
||||||
|
// map.put("name", CommonUtils.getAdmin().getName());
|
||||||
|
// map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||||
|
// map.put("type", HISTORYTYPE.MAIL_DELETE);
|
||||||
|
// JSONObject jsonObject = new JSONObject();
|
||||||
|
// if(!message.isEmpty()){
|
||||||
|
// jsonObject.put("message",message.get(0).getTitle());
|
||||||
|
// }
|
||||||
|
// map.put("content",jsonObject.toString());
|
||||||
|
// historyMapper.saveLog(map);
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
return MenuResponse.builder()
|
||||||
|
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||||
|
.result(CommonCode.SUCCESS.getResult())
|
||||||
|
.resultData(MenuResponse.ResultData.builder()
|
||||||
|
.message(SuccessCode.DELETE.getMessage())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MenuBanner> getScheduleMailList(){
|
||||||
|
return menuMapper.getScheduleBannerList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Message> getMessageList(Long id){
|
||||||
|
return menuMapper.getMessage(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStatus(Long id, MenuBanner.BANNER_STATUS status){
|
||||||
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
map.put("id", id);
|
||||||
|
map.put("status", status.toString());
|
||||||
|
menuMapper.updateBannerStatus(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,358 @@
|
|||||||
|
package com.caliverse.admin.domain.service;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.request.OpenAIRequest;
|
||||||
|
import com.caliverse.admin.domain.response.OpenAIResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class OpenAIService {
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Value("${open-ai.url}")
|
||||||
|
private String api_url;
|
||||||
|
|
||||||
|
@Value("${open-ai.key}")
|
||||||
|
private String api_key;
|
||||||
|
|
||||||
|
@Value("${open-ai.chatModel}")
|
||||||
|
private String api_chat_model;
|
||||||
|
|
||||||
|
@Value("${open-ai.assistantsModel}")
|
||||||
|
private String api_assistants_model;
|
||||||
|
|
||||||
|
public OpenAIResponse askOpenAI(OpenAIRequest request) {
|
||||||
|
request.setModel(api_chat_model);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
|
||||||
|
HttpEntity<OpenAIRequest> entity = new HttpEntity<>(request, headers);
|
||||||
|
|
||||||
|
ResponseEntity<OpenAIResponse> response = restTemplate.exchange(
|
||||||
|
api_url + "chat/completions",
|
||||||
|
HttpMethod.POST,
|
||||||
|
entity,
|
||||||
|
OpenAIResponse.class
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일 업로드 메서드
|
||||||
|
public String uploadFile(String filePath) {
|
||||||
|
String url = "https://api.openai.com/v1/files";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
body.add("file", new FileSystemResource(new File(filePath)));
|
||||||
|
body.add("purpose", "assistants");
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("File uploaded successfully: {}", response.getBody());
|
||||||
|
return (String) response.getBody().get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assistant 생성 메서드
|
||||||
|
public String createAssistant(String name, String instructions) {
|
||||||
|
String url = "https://api.openai.com/v1/assistants";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("model", api_assistants_model);
|
||||||
|
body.put("name", name);
|
||||||
|
body.put("instructions", instructions);
|
||||||
|
body.put("tools", List.of(Map.of("type", "retrieval")));
|
||||||
|
|
||||||
|
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("Assistant created successfully: {}", response.getBody());
|
||||||
|
return (String) response.getBody().get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread 생성 메서드
|
||||||
|
public String createThread() {
|
||||||
|
String url = "https://api.openai.com/v1/threads";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
|
||||||
|
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("Thread created successfully: {}", response.getBody());
|
||||||
|
return (String) response.getBody().get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread에 메시지 추가 메서드
|
||||||
|
public String addMessageToThread(String threadId, String content, String fileId) {
|
||||||
|
String url = "https://api.openai.com/v1/threads/" + threadId + "/messages";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("role", "user");
|
||||||
|
body.put("content", content);
|
||||||
|
|
||||||
|
if (fileId != null && !fileId.isEmpty()) {
|
||||||
|
body.put("file_ids", Collections.singletonList(fileId));
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("Message added to thread successfully: {}", response.getBody());
|
||||||
|
return (String) response.getBody().get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run 실행 메서드
|
||||||
|
public String startRun(String threadId, String assistantId) {
|
||||||
|
String url = "https://api.openai.com/v1/threads/" + threadId + "/runs";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("assistant_id", assistantId);
|
||||||
|
|
||||||
|
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("Run started successfully: {}", response.getBody());
|
||||||
|
return (String) response.getBody().get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run 상태 확인 메서드
|
||||||
|
public Map<String, Object> checkRunStatus(String threadId, String runId) {
|
||||||
|
String url = "https://api.openai.com/v1/threads/" + threadId + "/runs/" + runId;
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
|
||||||
|
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.GET,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.debug("Run status: {}", response.getBody());
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread의 메시지 목록 조회 메서드
|
||||||
|
public List<Map<String, Object>> listMessages(String threadId) {
|
||||||
|
String url = "https://api.openai.com/v1/threads/" + threadId + "/messages";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
|
||||||
|
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.GET,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.debug("Thread messages: {}", response.getBody());
|
||||||
|
return (List<Map<String, Object>>) response.getBody().get("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 마지막 Assistant 메시지 추출 메서드
|
||||||
|
public String extractLastAssistantMessage(String threadId) {
|
||||||
|
List<Map<String, Object>> messages = listMessages(threadId);
|
||||||
|
|
||||||
|
for (Map<String, Object> message : messages) {
|
||||||
|
if ("assistant".equals(message.get("role"))) {
|
||||||
|
List<Map<String, Object>> content = (List<Map<String, Object>>) message.get("content");
|
||||||
|
if (content != null && !content.isEmpty()) {
|
||||||
|
for (Map<String, Object> contentItem : content) {
|
||||||
|
if ("text".equals(contentItem.get("type"))) {
|
||||||
|
Map<String, Object> text = (Map<String, Object>) contentItem.get("text");
|
||||||
|
return (String) text.get("value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break; // 가장 최신 assistant 메시지만 처리
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "No assistant response found";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일 삭제 메서드
|
||||||
|
public boolean deleteFile(String fileId) {
|
||||||
|
String url = "https://api.openai.com/v1/files/" + fileId;
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
|
||||||
|
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.DELETE,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("File deleted successfully: {}", response.getBody());
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error deleting file: {}", e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assistant 가져오기 또는 생성 메서드
|
||||||
|
public String getOrCreateAssistant() {
|
||||||
|
String url = "https://api.openai.com/v1/assistants";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(api_key);
|
||||||
|
|
||||||
|
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.GET,
|
||||||
|
requestEntity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Map<String, Object>> assistants = (List<Map<String, Object>>) response.getBody().get("data");
|
||||||
|
|
||||||
|
// 데이터 분석 어시스턴트 찾기
|
||||||
|
for (Map<String, Object> assistant : assistants) {
|
||||||
|
if ("Data Analyzer".equals(assistant.get("name"))) {
|
||||||
|
return (String) assistant.get("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 없으면 새로 생성
|
||||||
|
return createAssistant("Data Analyzer",
|
||||||
|
"You are a data analysis assistant. Analyze the provided JSON data and generate visualizations. " +
|
||||||
|
"Your responses should be in HTML format with appropriate visualizations using charts. " +
|
||||||
|
"Focus on identifying patterns, trends, and insights from the data. " +
|
||||||
|
"Use Korean language for all responses.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 전체 비동기 프로세스 실행 및 결과 대기 메서드
|
||||||
|
public String processDataAnalysisAndWait(String filePath, String question) {
|
||||||
|
try {
|
||||||
|
// 1. 파일 업로드
|
||||||
|
String fileId = uploadFile(filePath);
|
||||||
|
|
||||||
|
// 2. Assistant 얻기 또는 생성
|
||||||
|
String assistantId = getOrCreateAssistant();
|
||||||
|
|
||||||
|
// 3. Thread 생성
|
||||||
|
String threadId = createThread();
|
||||||
|
|
||||||
|
// 4. 메시지 추가
|
||||||
|
addMessageToThread(threadId, question, fileId);
|
||||||
|
|
||||||
|
// 5. Run 실행
|
||||||
|
String runId = startRun(threadId, assistantId);
|
||||||
|
|
||||||
|
// 6. 완료 대기 (최대 60초, 3초마다 체크)
|
||||||
|
String status = "queued";
|
||||||
|
int maxAttempts = 20;
|
||||||
|
int attempts = 0;
|
||||||
|
|
||||||
|
while (!status.equals("completed") && attempts < maxAttempts) {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
Map<String, Object> runStatus = checkRunStatus(threadId, runId);
|
||||||
|
status = (String) runStatus.get("status");
|
||||||
|
|
||||||
|
if (status.equals("failed") || status.equals("cancelled")) {
|
||||||
|
throw new RuntimeException("Run failed with status: " + status);
|
||||||
|
}
|
||||||
|
|
||||||
|
attempts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!status.equals("completed")) {
|
||||||
|
throw new RuntimeException("Run timed out after 60 seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. 응답 메시지 추출
|
||||||
|
String result = extractLastAssistantMessage(threadId);
|
||||||
|
|
||||||
|
// 8. 파일 정리 (선택적)
|
||||||
|
deleteFile(fileId);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in data analysis process: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Data analysis failed: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,12 +6,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import software.amazon.awssdk.core.sync.RequestBody;
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
import software.amazon.awssdk.services.s3.model.GetObjectAttributesRequest;
|
import software.amazon.awssdk.services.s3.model.*;
|
||||||
import software.amazon.awssdk.services.s3.model.GetObjectAttributesResponse;
|
|
||||||
import software.amazon.awssdk.services.s3.model.S3Exception;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -24,6 +28,9 @@ public class S3Service {
|
|||||||
@Value("${amazon.s3.bucket-name}")
|
@Value("${amazon.s3.bucket-name}")
|
||||||
private String bucketName;
|
private String bucketName;
|
||||||
|
|
||||||
|
@Value("${amazon.aws.region}")
|
||||||
|
private String region;
|
||||||
|
|
||||||
public Optional<GetObjectAttributesResponse> getObjectMetadata(String key) {
|
public Optional<GetObjectAttributesResponse> getObjectMetadata(String key) {
|
||||||
try {
|
try {
|
||||||
GetObjectAttributesRequest request = GetObjectAttributesRequest.builder()
|
GetObjectAttributesRequest request = GetObjectAttributesRequest.builder()
|
||||||
@@ -38,4 +45,42 @@ public class S3Service {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String uploadFile(File file, String directoryName, String contentType) throws IOException, S3Exception {
|
||||||
|
String fileName = UUID.randomUUID().toString() + "-" + file.getName();
|
||||||
|
|
||||||
|
// S3 객체 키 (경로 + 파일명)
|
||||||
|
String objectKey = directoryName + "/" + fileName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
PutObjectRequest putObjectRequest = PutObjectRequest.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.key(objectKey)
|
||||||
|
.contentType(contentType)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 파일 업로드
|
||||||
|
PutObjectResponse response = s3Client.putObject(
|
||||||
|
putObjectRequest,
|
||||||
|
RequestBody.fromBytes(Files.readAllBytes(file.toPath()))
|
||||||
|
);
|
||||||
|
//https://metaverse-myhomeugc-test.s3.us-west-2.amazonaws.com/0002896883264fc9af5be62134939ce4/552ec8a4302348edb3fbf1496811d75f.ugcinfo
|
||||||
|
return "https://" + bucketName + ".s3." +
|
||||||
|
s3Client.serviceClientConfiguration().region().toString() +
|
||||||
|
".amazonaws.com/" + objectKey;
|
||||||
|
// return "s3://" + bucketName + objectKey;
|
||||||
|
}catch (S3Exception | IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFile(String fileUrl) {
|
||||||
|
String objectKey = fileUrl.substring(fileUrl.indexOf(".com/") + 5);
|
||||||
|
|
||||||
|
s3Client.deleteObject(builder -> builder
|
||||||
|
.bucket(bucketName)
|
||||||
|
.key(objectKey)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ import java.util.stream.Collectors;
|
|||||||
import com.caliverse.admin.domain.entity.FriendRequest;
|
import com.caliverse.admin.domain.entity.FriendRequest;
|
||||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||||
import com.caliverse.admin.domain.request.MailRequest;
|
import com.caliverse.admin.domain.request.MailRequest;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.atrrib.AccountBaseAttrib;
|
||||||
import com.caliverse.admin.dynamodb.domain.atrrib.MailAttrib;
|
import com.caliverse.admin.dynamodb.domain.atrrib.MailAttrib;
|
||||||
import com.caliverse.admin.dynamodb.domain.atrrib.MailJsonAttrib;
|
import com.caliverse.admin.dynamodb.domain.atrrib.MailJsonAttrib;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.atrrib.MoneyAttrib;
|
||||||
import com.caliverse.admin.dynamodb.domain.doc.MailDoc;
|
import com.caliverse.admin.dynamodb.domain.doc.MailDoc;
|
||||||
import com.caliverse.admin.dynamodb.dto.PageResult;
|
import com.caliverse.admin.dynamodb.dto.PageResult;
|
||||||
import com.caliverse.admin.dynamodb.service.DynamodbService;
|
import com.caliverse.admin.dynamodb.service.DynamodbService;
|
||||||
|
import com.caliverse.admin.dynamodb.service.DynamodbUserService;
|
||||||
import com.caliverse.admin.global.common.utils.DynamodbUtil;
|
import com.caliverse.admin.global.common.utils.DynamodbUtil;
|
||||||
import com.caliverse.admin.redis.service.RedisUserInfoService;
|
import com.caliverse.admin.redis.service.RedisUserInfoService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -54,6 +57,8 @@ public class UsersService {
|
|||||||
@Qualifier("objectMapper")
|
@Qualifier("objectMapper")
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
@Autowired
|
||||||
|
private DynamodbUserService dynamodbUserService;
|
||||||
|
|
||||||
// 닉네임 변경
|
// 닉네임 변경
|
||||||
public UsersResponse changeNickname(UsersRequest usersRequest){
|
public UsersResponse changeNickname(UsersRequest usersRequest){
|
||||||
@@ -138,20 +143,41 @@ public class UsersService {
|
|||||||
|
|
||||||
public UsersResponse getBasicInfo(String guid){
|
public UsersResponse getBasicInfo(String guid){
|
||||||
|
|
||||||
String account_id = dynamoDBService.getGuidByAccountId(guid);
|
String account_id = dynamodbUserService.getGuidByAccountId(guid);
|
||||||
//userInfo
|
|
||||||
Map<String, Object> userInfo = dynamoDBService.getAccountInfo(account_id);
|
AccountBaseAttrib accountBaseAttrib = dynamodbUserService.getAccountInfo(account_id);
|
||||||
|
UsersResponse.UserInfo userInfo = UsersResponse.UserInfo.builder()
|
||||||
|
.aid(accountBaseAttrib.getUserGuid())
|
||||||
|
.userId(accountBaseAttrib.getAccountId())
|
||||||
|
.nation(accountBaseAttrib.getLanguageType())
|
||||||
|
.membership("")
|
||||||
|
.friendCode("")
|
||||||
|
.createDt(accountBaseAttrib.getCreatedDateTime())
|
||||||
|
.accessDt(accountBaseAttrib.getLoginDateTime())
|
||||||
|
.endDt(accountBaseAttrib.getLogoutDateTime())
|
||||||
|
.walletUrl("")
|
||||||
|
.adminLevel(accountBaseAttrib.getAuthAdminLevelType().name())
|
||||||
|
.spareSlot("")
|
||||||
|
.build();
|
||||||
|
|
||||||
// charInfo
|
// charInfo
|
||||||
Map<String, Object> charInfo = dynamoDBService.getCharInfo(guid);
|
MoneyAttrib moneyAttrib = dynamodbUserService.getMoneyInfo(guid);
|
||||||
|
UsersResponse.CharInfo charInfo = UsersResponse.CharInfo.builder()
|
||||||
|
.characterName(dynamodbUserService.getGuidByName(guid))
|
||||||
|
.level("")
|
||||||
|
.goldCali(moneyAttrib.getGold())
|
||||||
|
.redCali(moneyAttrib.getCalium())
|
||||||
|
.blackCali(moneyAttrib.getRuby())
|
||||||
|
.blueCali(moneyAttrib.getSapphire())
|
||||||
|
.build();
|
||||||
|
|
||||||
boolean userSession = userGameSessionService.userSession(guid);
|
boolean userSession = userGameSessionService.userSession(guid);
|
||||||
|
|
||||||
return UsersResponse.builder()
|
return UsersResponse.builder()
|
||||||
.resultData(
|
.resultData(
|
||||||
UsersResponse.ResultData.builder()
|
UsersResponse.ResultData.builder()
|
||||||
.charInfo((UsersResponse.CharInfo) charInfo.get("charInfo"))
|
.charInfo(charInfo)
|
||||||
.userInfo((UsersResponse.UserInfo) userInfo.get("userInfo"))
|
.userInfo(userInfo)
|
||||||
.userSession(userSession)
|
.userSession(userSession)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class WhiteListService {
|
|||||||
Map<String, AttributeValue> whiteAttr = dynamoDBService.getItem("char#" + item, "char#" + item);
|
Map<String, AttributeValue> whiteAttr = dynamoDBService.getItem("char#" + item, "char#" + item);
|
||||||
//guid 검증
|
//guid 검증
|
||||||
if(whiteAttr.size() == 0){
|
if(whiteAttr.size() == 0){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.getMessage());
|
||||||
}
|
}
|
||||||
//화이트리스트 확정까지 보류
|
//화이트리스트 확정까지 보류
|
||||||
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
||||||
@@ -116,7 +116,7 @@ public class WhiteListService {
|
|||||||
|
|
||||||
//guid 검증
|
//guid 검증
|
||||||
if(whiteAttr.size() == 0){
|
if(whiteAttr.size() == 0){
|
||||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.WARNING_GUID_CHECK.getMessage());
|
||||||
}
|
}
|
||||||
//화이트리스트 확정까지 보류
|
//화이트리스트 확정까지 보류
|
||||||
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ public interface AccountBaseRepository extends DynamoDBRepository<AccountBaseDoc
|
|||||||
boolean isBlockUser(String account_id);
|
boolean isBlockUser(String account_id);
|
||||||
void updateBlockUserStart(String account_id, BlackList blackList);
|
void updateBlockUserStart(String account_id, BlackList blackList);
|
||||||
void updateBlockUserEnd(String account_id);
|
void updateBlockUserEnd(String account_id);
|
||||||
AccountBaseAttrib findUser(Long account_id);
|
AccountBaseAttrib findUser(String account_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public class AccountBaseRepositoryImpl extends BaseDynamoDBRepository<AccountBas
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountBaseAttrib findUser(Long account_id) {
|
public AccountBaseAttrib findUser(String account_id) {
|
||||||
Key key = Key.builder()
|
Key key = Key.builder()
|
||||||
.partitionValue(DynamoDBConstants.PK_KEY_ACCOUNT_BASE + account_id)
|
.partitionValue(DynamoDBConstants.PK_KEY_ACCOUNT_BASE + account_id)
|
||||||
.sortValue(DynamoDBConstants.EMPTY)
|
.sortValue(DynamoDBConstants.EMPTY)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.caliverse.admin.dynamodb.service;
|
package com.caliverse.admin.dynamodb.service;
|
||||||
|
|
||||||
import com.caliverse.admin.domain.entity.BlackList;
|
import com.caliverse.admin.domain.entity.BlackList;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.atrrib.AccountBaseAttrib;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.atrrib.MoneyAttrib;
|
||||||
import com.caliverse.admin.dynamodb.domain.atrrib.NicknameAttrib;
|
import com.caliverse.admin.dynamodb.domain.atrrib.NicknameAttrib;
|
||||||
import com.caliverse.admin.dynamodb.domain.atrrib.UserBaseAttrib;
|
import com.caliverse.admin.dynamodb.domain.atrrib.UserBaseAttrib;
|
||||||
import com.caliverse.admin.dynamodb.repository.*;
|
import com.caliverse.admin.dynamodb.repository.*;
|
||||||
@@ -23,6 +25,7 @@ public class DynamodbUserService {
|
|||||||
private final UserBaseRepository userBaseRepository;
|
private final UserBaseRepository userBaseRepository;
|
||||||
private final UserNicknameRegistryRepository registryRepository;
|
private final UserNicknameRegistryRepository registryRepository;
|
||||||
private final NicknameRepository nicknameRepository;
|
private final NicknameRepository nicknameRepository;
|
||||||
|
private final MoneyRepository moneyRepository;
|
||||||
|
|
||||||
private final ObjectMapper mapper = new ObjectMapper();
|
private final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@@ -64,4 +67,12 @@ public class DynamodbUserService {
|
|||||||
return userBaseAttrib.getAccountId();
|
return userBaseAttrib.getAccountId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AccountBaseAttrib getAccountInfo(String accountId){
|
||||||
|
return accountBaseRepository.findUser(accountId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoneyAttrib getMoneyInfo(String guid){
|
||||||
|
return moneyRepository.findAttrib(guid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ public enum ErrorCode {
|
|||||||
DUPLICATE_EXCEL("중복된 유저 정보가 있습니다."),
|
DUPLICATE_EXCEL("중복된 유저 정보가 있습니다."),
|
||||||
USERTYPE_CHECK_EXCEL("타입을 확인해주세요."),
|
USERTYPE_CHECK_EXCEL("타입을 확인해주세요."),
|
||||||
|
|
||||||
|
NOT_EXIT_FILE("파일을 선택해주세요."),
|
||||||
|
ERROR_FILE_UPLOAD("파일 업로드중 오류 발생하였습니다."),
|
||||||
|
ERROR_FILE_S3_UPLOAD("파일을 S3로 업로드중 오류 발생하였습니다."),
|
||||||
|
ERROR_FILE_DELETE("파일 삭제중 오류 발생하였습니다."),
|
||||||
|
|
||||||
ERROR_API_CALL("API 호출에 실패하였습니다."),
|
ERROR_API_CALL("API 호출에 실패하였습니다."),
|
||||||
|
|
||||||
ERROR_HISTORY_SAVE("히스토리로그 저장 실패"),
|
ERROR_HISTORY_SAVE("히스토리로그 저장 실패"),
|
||||||
@@ -83,7 +88,7 @@ public enum ErrorCode {
|
|||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
// DyanamoDB
|
// DyanamoDB
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
GUID_CHECK("Guid를 확인해주세요."),
|
WARNING_GUID_CHECK("Guid를 확인해주세요."),
|
||||||
EMAIL_CHECK("Email을 확인해주세요"),
|
EMAIL_CHECK("Email을 확인해주세요"),
|
||||||
GUID_LENGTH_CHECK("guid(32자)를 확인해주세요."),
|
GUID_LENGTH_CHECK("guid(32자)를 확인해주세요."),
|
||||||
NICKNAME_CHECK("gameDB에 닉네임이 없습니다."),
|
NICKNAME_CHECK("gameDB에 닉네임이 없습니다."),
|
||||||
@@ -98,6 +103,7 @@ public enum ErrorCode {
|
|||||||
DYNAMODB_CONVERT_ERROR("형변환 도중 에러가 발생하였습니다."),
|
DYNAMODB_CONVERT_ERROR("형변환 도중 에러가 발생하였습니다."),
|
||||||
DYNAMODB_JSON_PARSE_ERROR("dynamoDB Json 변환 중 에러 발생"),
|
DYNAMODB_JSON_PARSE_ERROR("dynamoDB Json 변환 중 에러 발생"),
|
||||||
|
|
||||||
|
USER_BLOCK_REGIST_DUPLE_WARNING("이미 제재가 등록된 유저입니다."),
|
||||||
|
|
||||||
ADMINDB_EXIT_ERROR("admindb_exit_error"),
|
ADMINDB_EXIT_ERROR("admindb_exit_error"),
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public enum SuccessCode {
|
|||||||
INIT("비밀번호 초기화 하였습니다."),
|
INIT("비밀번호 초기화 하였습니다."),
|
||||||
NULL_DATA("조회된 데이터가 없습니다."),
|
NULL_DATA("조회된 데이터가 없습니다."),
|
||||||
EXCEL_UPLOAD("파일 업로드 하였습니다."),
|
EXCEL_UPLOAD("파일 업로드 하였습니다."),
|
||||||
|
FILE_DELETE("파일을 삭제 하였습니다."),
|
||||||
REGISTRATION("등록 하였습니다."),
|
REGISTRATION("등록 하였습니다."),
|
||||||
ITEM_EXIST("아이템이 존재합니다"),
|
ITEM_EXIST("아이템이 존재합니다"),
|
||||||
SUCCESS("성공 하였습니다."),
|
SUCCESS("성공 하였습니다."),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class CommonConstants {
|
|||||||
public static final String LAND_EVENT = "event";
|
public static final String LAND_EVENT = "event";
|
||||||
public static final String SYSTEM_MAIL_LAND_TRANS_KEY = "LandTrans";
|
public static final String SYSTEM_MAIL_LAND_TRANS_KEY = "LandTrans";
|
||||||
public static final int DYNAMODB_PAGING_SIZE = 30;
|
public static final int DYNAMODB_PAGING_SIZE = 30;
|
||||||
|
public static final String S3_MENU_BANNER_DIRECTORY = "banner-";
|
||||||
|
|
||||||
public static final String FORMAT_DATE_ISO_DATETIME_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
public static final String FORMAT_DATE_ISO_DATETIME_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
public static final String FORMAT_DATE_ISO_DATETIME_MILLIS_NANO = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'";
|
public static final String FORMAT_DATE_ISO_DATETIME_MILLIS_NANO = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'";
|
||||||
@@ -24,4 +25,6 @@ public class CommonConstants {
|
|||||||
public static final String FORMAT_DATE_MAIL_DATETIME = "yyyy/MM/dd/HH:mm:ss:SS";
|
public static final String FORMAT_DATE_MAIL_DATETIME = "yyyy/MM/dd/HH:mm:ss:SS";
|
||||||
|
|
||||||
public static final String TRANSACTION_ID_KEY = "TRANSACTION_ID";
|
public static final String TRANSACTION_ID_KEY = "TRANSACTION_ID";
|
||||||
|
|
||||||
|
public static final int AI_MESSAGE_LIMIT_SIZE = 50;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ public class MysqlConstants {
|
|||||||
public static String TABLE_NAME_LAND_OWNER_CHANGE = "land_ownership_changes";
|
public static String TABLE_NAME_LAND_OWNER_CHANGE = "land_ownership_changes";
|
||||||
public static String TABLE_NAME_CALIUM_REQUEST = "calium_request";
|
public static String TABLE_NAME_CALIUM_REQUEST = "calium_request";
|
||||||
public static String TABLE_NAME_EVENT = "event";
|
public static String TABLE_NAME_EVENT = "event";
|
||||||
|
public static String TABLE_NAME_MENU_BANNER = "menu_banner";
|
||||||
public static String TABLE_NAME_MAIL = "mail";
|
public static String TABLE_NAME_MAIL = "mail";
|
||||||
public static String TABLE_NAME_NOTICE = "notice";
|
public static String TABLE_NAME_NOTICE = "notice";
|
||||||
public static String TABLE_NAME_BATTLE_EVENT = "battle_event";
|
public static String TABLE_NAME_BATTLE_EVENT = "battle_event";
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.AI.AIRole;
|
||||||
import com.caliverse.admin.domain.entity.DiffStatus;
|
import com.caliverse.admin.domain.entity.DiffStatus;
|
||||||
import com.caliverse.admin.global.common.code.CommonCode;
|
import com.caliverse.admin.global.common.code.CommonCode;
|
||||||
import com.caliverse.admin.global.common.constants.CommonConstants;
|
import com.caliverse.admin.global.common.constants.CommonConstants;
|
||||||
@@ -383,4 +384,8 @@ public class CommonUtils {
|
|||||||
return "\"" + value.toString().replace("\"", "\\\"") + "\"";
|
return "\"" + value.toString().replace("\"", "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> getAIMessage(AIRole role, String message){
|
||||||
|
return Map.of("role", role.toString(), "content", message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package com.caliverse.admin.global.common.utils;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.Currencys;
|
||||||
|
import com.caliverse.admin.domain.entity.Excel;
|
||||||
|
import com.caliverse.admin.domain.entity.ROUTE;
|
||||||
|
import com.caliverse.admin.domain.response.IndicatorsResponse;
|
||||||
|
import com.caliverse.admin.global.common.code.CommonCode;
|
||||||
|
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||||
|
import com.caliverse.admin.global.common.exception.RestApiException;
|
||||||
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||||
|
import jakarta.servlet.ServletOutputStream;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFColor;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFFont;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class FileUtils {
|
||||||
|
|
||||||
|
@Value("${excel.file-path}")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
public byte[] loadFileByte(String fileName) {
|
||||||
|
try {
|
||||||
|
String localFilePath = filePath + File.separator + fileName;
|
||||||
|
Path sourcePath = Path.of(localFilePath);
|
||||||
|
|
||||||
|
if (!Files.exists(sourcePath)) {
|
||||||
|
throw new RuntimeException("파일을 찾을 수 없습니다: " + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Files.readAllBytes(sourcePath);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("파일 로드 중 오류 발생: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileInputStream loadFileStream(String fileName){
|
||||||
|
String fullPath = filePath + fileName;
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(new File(fullPath))) {
|
||||||
|
return fis;
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File loadFileObject(String fileName){
|
||||||
|
String fullPath = filePath + fileName;
|
||||||
|
|
||||||
|
File file = new File(fullPath);
|
||||||
|
|
||||||
|
if (!file.exists() || !file.isFile()) {
|
||||||
|
throw new RuntimeException("파일을 찾을 수 없습니다: " + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String saveFile(MultipartFile file){
|
||||||
|
try{
|
||||||
|
String fileName = CommonUtils.setFileName(file.getOriginalFilename());
|
||||||
|
String path = filePath + File.separator + fileName;
|
||||||
|
Path destinationPath = Path.of(path);
|
||||||
|
|
||||||
|
Files.copy(file.getInputStream(), destinationPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}catch (IOException e){
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_UPLOAD.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteFile(String fileName) {
|
||||||
|
try {
|
||||||
|
String path = filePath + File.separator + fileName;
|
||||||
|
Path fileToDelete = Path.of(path);
|
||||||
|
|
||||||
|
if (!Files.exists(fileToDelete)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Files.deleteIfExists(fileToDelete);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_FILE_DELETE.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean hasDuplicates(List<String> dataList) {
|
||||||
|
Set<String> uniqueValues = new HashSet<>();
|
||||||
|
|
||||||
|
for (String value : dataList) {
|
||||||
|
if (uniqueValues.contains(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
uniqueValues.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isString32Characters(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return input.length() == 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContentType(String fileName) {
|
||||||
|
String extension = "";
|
||||||
|
int i = fileName.lastIndexOf('.');
|
||||||
|
if (i > 0) {
|
||||||
|
extension = fileName.substring(i + 1).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (extension) {
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
return "image/jpeg";
|
||||||
|
case "png":
|
||||||
|
return "image/png";
|
||||||
|
case "gif":
|
||||||
|
return "image/gif";
|
||||||
|
case "pdf":
|
||||||
|
return "application/pdf";
|
||||||
|
case "txt":
|
||||||
|
return "text/plain";
|
||||||
|
case "html":
|
||||||
|
return "text/html";
|
||||||
|
case "doc":
|
||||||
|
return "application/msword";
|
||||||
|
case "docx":
|
||||||
|
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||||
|
case "xls":
|
||||||
|
return "application/vnd.ms-excel";
|
||||||
|
case "xlsx":
|
||||||
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream"; // 기본 바이너리 타입
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.caliverse.admin.global.configuration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JacksonConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ObjectMapper objectMapper() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.registerModule(new JavaTimeModule());
|
||||||
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); // 필요시
|
||||||
|
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -36,11 +37,17 @@ public class BusinessLogGenericService extends BusinessLogServiceBase {
|
|||||||
super(mongoTemplate);
|
super(mongoTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> loadBusinessLogData(LogGenericRequest logGenericRequest, Class<T> class1){
|
||||||
|
return loadBusinessLogData(logGenericRequest, class1, false);
|
||||||
|
}
|
||||||
|
|
||||||
// public List<Map<String, Object>> loadBusinessLogData(LogGenericRequest logGenericRequest) {
|
// public List<Map<String, Object>> loadBusinessLogData(LogGenericRequest logGenericRequest) {
|
||||||
public <T> List<T> loadBusinessLogData(LogGenericRequest logGenericRequest, Class<T> class1) {
|
public <T> List<T> loadBusinessLogData(LogGenericRequest logGenericRequest, Class<T> class1, boolean isSimple) {
|
||||||
String startTime = logGenericRequest.getStartDt().toString().substring(0, 10);
|
LocalDateTime startDt = logGenericRequest.getStartDt().plusHours(9);
|
||||||
String endTime = logGenericRequest.getEndDt().toString().substring(0, 10);
|
LocalDateTime endDt = logGenericRequest.getEndDt().plusHours(9).plusDays(1);
|
||||||
|
|
||||||
|
String startTime = startDt.toString().substring(0, 10);
|
||||||
|
String endTime = endDt.toString().substring(0, 10);
|
||||||
LogAction logAction = logGenericRequest.getLogAction();
|
LogAction logAction = logGenericRequest.getLogAction();
|
||||||
LogDomain logDomain = logGenericRequest.getLogDomain();
|
LogDomain logDomain = logGenericRequest.getLogDomain();
|
||||||
SearchUserType searchUserType = logGenericRequest.getSearchType();
|
SearchUserType searchUserType = logGenericRequest.getSearchType();
|
||||||
@@ -223,25 +230,17 @@ public class BusinessLogGenericService extends BusinessLogServiceBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(filters != null && !filters.isEmpty()) {
|
if(isSimple){
|
||||||
// List<Document> filterDocuments = new ArrayList<>();
|
operations.add(context ->
|
||||||
//
|
new Document("$project",
|
||||||
// for (LogGenericRequest.LogFilter filter : filters) {
|
new Document(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, 1)
|
||||||
// if (filter.getFieldName() != null && !filter.getFieldName().isEmpty() &&
|
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, 1)
|
||||||
// filter.getValue() != null) {
|
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, 1)
|
||||||
// Document filterDoc = new Document(filter.getFieldName(), filter.getValue());
|
.append(AdminConstants.MONGO_DB_KEY_LOGTIME, 1)
|
||||||
// filterDocuments.add(filterDoc);
|
.append("body", 1)
|
||||||
// }
|
)
|
||||||
// }
|
);
|
||||||
//
|
}
|
||||||
// if (!filterDocuments.isEmpty()) {
|
|
||||||
// operations.add(context ->
|
|
||||||
// new Document("$match",
|
|
||||||
// new Document("$and", filterDocuments)
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 최종 출력 형식
|
// 최종 출력 형식
|
||||||
operations.add(context ->
|
operations.add(context ->
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
spring:
|
spring:
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 5MB
|
||||||
|
max-request-size: 10MB
|
||||||
## deploy
|
## deploy
|
||||||
# profiles:
|
# profiles:
|
||||||
# active: stage
|
# active: stage
|
||||||
@@ -25,4 +29,15 @@ spring:
|
|||||||
password:
|
password:
|
||||||
expiration-days: 180
|
expiration-days: 180
|
||||||
|
|
||||||
|
open-ai:
|
||||||
|
key: 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
|
||||||
|
url: https://api.openai.com/v1/
|
||||||
|
chatModel: gpt-4o
|
||||||
|
assistantsModel: gpt-4-1106-preview
|
||||||
|
|
||||||
|
claude:
|
||||||
|
key: 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
|
||||||
|
model: claude-3-7-sonnet-20250219
|
||||||
|
url: https://api.anthropic.com/v1/messages
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
146
src/main/resources/mappers/MenuMapper.xml
Normal file
146
src/main/resources/mappers/MenuMapper.xml
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.caliverse.admin.domain.dao.admin.MenuMapper">
|
||||||
|
<resultMap id="MenuResultMap" type="com.caliverse.admin.domain.entity.MenuBanner">
|
||||||
|
<id property="id" column="id"/>
|
||||||
|
<result property="rowNum" column="row_num"/>
|
||||||
|
<result property="title" column="title"/>
|
||||||
|
<result property="isLink" column="is_link"/>
|
||||||
|
<result property="status" column="status"/>
|
||||||
|
<result property="startDt" column="start_dt"/>
|
||||||
|
<result property="endDt" column="end_dt"/>
|
||||||
|
<result property="createBy" column="create_by"/>
|
||||||
|
<result property="createDt" column="create_dt"/>
|
||||||
|
<result property="updateBy" column="update_by"/>
|
||||||
|
<result property="updateDt" column="update_dt"/>
|
||||||
|
</resultMap>
|
||||||
|
<resultMap id="MessageResultMap" type="com.caliverse.admin.domain.entity.Message">
|
||||||
|
<result property="title" column="title"/>
|
||||||
|
<result property="language" column="language"/>
|
||||||
|
<result property="content" column="content"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!--리스트 조회-->
|
||||||
|
<select id="getBannerList" resultMap="MenuResultMap" parameterType="map">
|
||||||
|
SELECT (@row_number:=@row_number + 1) AS row_num , c.*
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
a.id
|
||||||
|
, a.title
|
||||||
|
, a.is_link
|
||||||
|
, a.status
|
||||||
|
, a.start_dt
|
||||||
|
, a.end_dt
|
||||||
|
, (SELECT email FROM admin WHERE id = a.create_by ) AS create_by
|
||||||
|
, a.create_dt
|
||||||
|
, (SELECT email FROM admin WHERE id = a.update_by ) AS update_by
|
||||||
|
, a.update_dt
|
||||||
|
FROM menu_banner a
|
||||||
|
WHERE 1 = 1
|
||||||
|
AND a.deleted = 0
|
||||||
|
|
||||||
|
<if test="search_data != null and search_data != ''">
|
||||||
|
AND a.title LIKE CONCAT('%',#{search_data},'%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="status != null and status != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="status != 'ALL' ">
|
||||||
|
AND a.status = #{status}
|
||||||
|
</when>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="start_dt != null and start_dt != '' and end_dt !=null and end_dt!= ''">
|
||||||
|
AND a.start_dt >= #{start_dt, jdbcType=TIMESTAMP}
|
||||||
|
AND a.end_dt <= #{end_dt, jdbcType=TIMESTAMP}
|
||||||
|
</if>
|
||||||
|
|
||||||
|
ORDER BY a.create_dt
|
||||||
|
)c
|
||||||
|
, (SELECT @row_number:=0) AS t
|
||||||
|
<if test="orderby != null and orderby != ''">
|
||||||
|
ORDER BY row_num ${orderby}
|
||||||
|
</if>
|
||||||
|
<if test="pageSize != null and pageSize != ''">
|
||||||
|
LIMIT ${pageSize} OFFSET ${offset}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getTotal" resultType="java.lang.Integer" parameterType="map">
|
||||||
|
SELECT count(*) FROM menu_banner WHERE deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getBannerDetail" parameterType="java.lang.Long" resultMap="MenuResultMap" >
|
||||||
|
SELECT
|
||||||
|
a.id
|
||||||
|
, a.title
|
||||||
|
, a.is_link
|
||||||
|
, a.start_dt
|
||||||
|
, a.end_dt
|
||||||
|
, a.status
|
||||||
|
, (SELECT email FROM admin WHERE id = a.create_by ) AS create_by
|
||||||
|
, a.create_dt
|
||||||
|
, (SELECT email FROM admin WHERE id = a.update_by ) AS update_by
|
||||||
|
, a.update_dt
|
||||||
|
FROM menu_banner a
|
||||||
|
WHERE a.id = #{id}
|
||||||
|
AND deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getMessage" parameterType="java.lang.Long" resultMap="MessageResultMap" >
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM message
|
||||||
|
WHERE target_id = #{id}
|
||||||
|
AND type = 'BANNER'
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertBanner" parameterType="com.caliverse.admin.domain.request.MenuRequest" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
INSERT INTO menu_banner (title, is_link, start_dt, end_dt)
|
||||||
|
VALUES (#{title}, #{isLink}, #{startDt}, #{endDt})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="insertMessage" parameterType="map">
|
||||||
|
INSERT INTO message (target_id, type, title, content, language)
|
||||||
|
VALUES (#{id}, 'BANNER', #{title}, #{content}, #{language})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateBanner" parameterType="com.caliverse.admin.domain.request.MenuRequest">
|
||||||
|
UPDATE menu_banner SET target = #{target}
|
||||||
|
, is_reserve = #{isReserve}
|
||||||
|
, receive_type = #{receiveType}
|
||||||
|
, send_type =#{sendType}
|
||||||
|
, mail_type = #{mailType}
|
||||||
|
, send_dt = #{sendDt}
|
||||||
|
, update_by = #{updateBy}
|
||||||
|
, update_dt = NOW()
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="deleteMessage" parameterType="map">
|
||||||
|
DELETE FROM message
|
||||||
|
WHERE target_id = #{mailId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="deleteBanner" parameterType="map">
|
||||||
|
UPDATE menu_banner SET deleted = 1
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="getScheduleBannerList" resultMap="MenuResultMap">
|
||||||
|
SELECT id,
|
||||||
|
, a.title
|
||||||
|
, a.is_link
|
||||||
|
, a.start_dt
|
||||||
|
, a.end_dt
|
||||||
|
FROM menu_banner
|
||||||
|
WHERE send_status = 'WAIT'
|
||||||
|
AND deleted = false
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updateBannerStatus" parameterType="map">
|
||||||
|
UPDATE menu_banner SET status = #{status}
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user