init
This commit is contained in:
@@ -0,0 +1,377 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.adminlog.AdminPasswordInitLog;
|
||||
import com.caliverse.admin.domain.adminlog.IAdminLog;
|
||||
import com.caliverse.admin.domain.dao.admin.AdminMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.GroupMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.AdminRequest;
|
||||
import com.caliverse.admin.domain.request.AuthenticateRequest;
|
||||
import com.caliverse.admin.domain.response.AdminResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdminService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AdminService.class);
|
||||
|
||||
private final AdminMapper adminMapper;
|
||||
private final GroupMapper groupMapper;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final HistoryService historyService;
|
||||
@Value("${password.expiration-days}")
|
||||
private int passwordExpiration;
|
||||
|
||||
@Value("${spring.mail.host}")
|
||||
private String host;
|
||||
@Value("${spring.mail.port}")
|
||||
private int port;
|
||||
@Value("${spring.mail.username}")
|
||||
private String username;
|
||||
@Value("${spring.mail.password}")
|
||||
private String password;
|
||||
// 비번 초기화
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public AdminResponse initPassword(AuthenticateRequest authenticateRequest){
|
||||
|
||||
Optional<Admin> admin = adminMapper.findByEmail(authenticateRequest.getEmail());
|
||||
String initPwd = randomPwd();
|
||||
adminMapper.initPwd(passwordEncoder.encode(initPwd), admin.get().getId(), CommonUtils.getAdmin().getId());
|
||||
//유저 비번 기록 남기기
|
||||
adminMapper.saveHistoryPwd(passwordEncoder.encode(initPwd), admin.get().getId());
|
||||
//smtp
|
||||
sendMail(authenticateRequest.getEmail(),initPwd);
|
||||
|
||||
IAdminLog adminLog = new AdminPasswordInitLog(admin.get().getName(), admin.get().getEmail());
|
||||
adminLog.saveLogToDB();
|
||||
|
||||
log.info("initPassword id: {}, email: {}", admin.get().getId(), admin.get().getEmail());
|
||||
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(AdminResponse.ResultData.builder().message(SuccessCode.INIT.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 비번 재설정
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public AdminResponse updatePassword(AuthenticateRequest authenticateRequest){
|
||||
|
||||
String oldPwd = authenticateRequest.getPassword();
|
||||
String newPwd = authenticateRequest.getNewPassword();
|
||||
String pwdById = adminMapper.findPwdById(CommonUtils.getAdmin().getId());
|
||||
|
||||
/*
|
||||
https://nzin-publisher-bts.atlassian.net/browse/CAL-120
|
||||
임시 비밀번호 재설정 화면에서 현재 비밀번호 입력 필드가 노출되는 현상
|
||||
*/
|
||||
//입력한 비번이랑 현재 db 비번이랑 동일한지 체크
|
||||
/*if(!passwordEncoder.matches(oldPwd,pwdById)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.PASSWORD_ERROR.getMessage());
|
||||
}*/
|
||||
|
||||
//기존 사용이력있는 비밀번호 재사용 할수 없습니다.
|
||||
List<String> pwdList = adminMapper.findPwdHistoryById(CommonUtils.getAdmin().getId());
|
||||
long count = pwdList.stream().filter(pwd -> passwordEncoder.matches(newPwd,pwd)).count();
|
||||
|
||||
if(count == 0){
|
||||
adminMapper.updatePwd(passwordEncoder.encode(newPwd), CommonUtils.getAdmin().getId(), STATUS.PERMITTED );
|
||||
//유저 비번 기록 남기기
|
||||
adminMapper.saveHistoryPwd(passwordEncoder.encode(newPwd), CommonUtils.getAdmin().getId());
|
||||
}else{
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.PASSWORD_INCLUDE.getMessage());
|
||||
}
|
||||
|
||||
log.info("updatePassword Changed Password user: {}", CommonUtils.getAdmin().getId());
|
||||
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(AdminResponse.ResultData.builder().message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 사용자 정보 조회
|
||||
public AdminResponse getAdminInfo(){
|
||||
AdminResponse.ResultData resultData = null;
|
||||
|
||||
Optional<Admin> admin = adminMapper.findByEmail(CommonUtils.getAdmin().getEmail());
|
||||
if(admin.stream().count() > 0){
|
||||
// 권한 그룹 조회
|
||||
List<Authority> groupAuth = groupMapper.getGroupAuth(admin.get().getGroupId());
|
||||
|
||||
resultData = AdminResponse.ResultData.builder()
|
||||
.id(admin.get().getId())
|
||||
.name(admin.get().getName())
|
||||
.groupId(admin.get().getGroupId())
|
||||
.email(admin.get().getEmail())
|
||||
.status(admin.get().getStatus())
|
||||
.authorityList(groupAuth)
|
||||
.expiredDt(admin.get().getPwUpdateDt().plus(passwordExpiration, ChronoUnit.DAYS))
|
||||
.build();
|
||||
}
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(resultData)
|
||||
.build();
|
||||
}
|
||||
// 운영자 조회
|
||||
public AdminResponse getAdminList(Map<String, String> requestParams){
|
||||
|
||||
AdminResponse.ResultData adminData = null;
|
||||
|
||||
//페이징 처리
|
||||
requestParams = CommonUtils.pageSetting(requestParams);
|
||||
|
||||
List<Admin> adminList = adminMapper.getAdminList(requestParams);
|
||||
|
||||
int allCnt = adminMapper.getAllCnt(requestParams);
|
||||
|
||||
return AdminResponse.builder()
|
||||
.resultData(AdminResponse.ResultData.builder()
|
||||
.total(adminMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParams.get("page_no")!=null?
|
||||
Integer.valueOf(requestParams.get("page_no").toString()):1)
|
||||
.adminList(adminList).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 로그인 승인/불가
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public AdminResponse updateStatus(AdminRequest adminRequest){
|
||||
Map<String , Object> map = new HashMap<>();
|
||||
adminRequest.getList().forEach(
|
||||
item -> {
|
||||
|
||||
map.put("email", item.getEmail());
|
||||
map.put("id", CommonUtils.getAdmin().getId());
|
||||
|
||||
if(item.getIsApprove().equals(AdminRequest.Approve.APPROVE)){
|
||||
map.put("status", STATUS.PERMITTED);
|
||||
}else if (item.getIsApprove().equals(AdminRequest.Approve.REJECT)){
|
||||
map.put("status", STATUS.REJECT);
|
||||
}else{
|
||||
map.put("status", STATUS.ROLE_NOT_PERMITTED);
|
||||
}
|
||||
//로그인 승인
|
||||
adminMapper.updateStatus(map);
|
||||
|
||||
//로그 기록
|
||||
Optional<Admin> admin = adminMapper.findByEmail(item.getEmail());
|
||||
// map.put("adminId", admin.get().getId());
|
||||
// map.put("name", CommonUtils.getAdmin().getName());
|
||||
// map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
// map.put("type", HISTORYTYPE.LOGIN_PERMITTED);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name",admin.get().getName());
|
||||
jsonObject.put("email",item.getEmail());
|
||||
// map.put("content",jsonObject.toString());
|
||||
// historyMapper.saveLog(map);
|
||||
historyService.setLog(HISTORYTYPE.LOGIN_PERMITTED, jsonObject);
|
||||
}
|
||||
);
|
||||
|
||||
log.info("updateStatus User: {}", map);
|
||||
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(AdminResponse.ResultData.builder().message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
//운영자 그룹 저장
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public AdminResponse updateGroup(AdminRequest adminRequest){
|
||||
Map<String , Object> map = new HashMap<>();
|
||||
adminRequest.getList().forEach(
|
||||
item -> {
|
||||
map.put("email", item.getEmail());
|
||||
map.put("group_id", item.getGroupId());
|
||||
map.put("id", CommonUtils.getAdmin().getId());
|
||||
|
||||
//변경전 그룹 명세 조회
|
||||
Optional<Admin> admin = adminMapper.findByEmail(item.getEmail());
|
||||
|
||||
Map<String, String> beforeGroup = groupMapper.getGroupInfo(admin.get().getGroupId());
|
||||
//쿼리 실행
|
||||
adminMapper.updateGroup(map);
|
||||
//로그 기록
|
||||
//변경후 그룹 명세 조회
|
||||
Map<String, String> afterGroup = groupMapper.getGroupInfo(item.getGroupId());
|
||||
|
||||
// map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
// map.put("name", CommonUtils.getAdmin().getName());
|
||||
// map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
// map.put("type", HISTORYTYPE.ADMIN_INFO_UPDATE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name",admin.get().getName());
|
||||
jsonObject.put("email",item.getEmail());
|
||||
jsonObject.put("Authority(Before)", beforeGroup != null?beforeGroup.get("name"):"");
|
||||
jsonObject.put("Authority(after)", afterGroup != null? afterGroup.get("name"):"");
|
||||
// map.put("content",jsonObject.toString());
|
||||
// historyMapper.saveLog(map);
|
||||
historyService.setLog(HISTORYTYPE.ADMIN_INFO_UPDATE, jsonObject);
|
||||
}
|
||||
);
|
||||
|
||||
log.info("updateGroup Groups: {}", map);
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(AdminResponse.ResultData.builder().message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 운영자 선택 삭제
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public AdminResponse deleteAdmin(AdminRequest adminRequest){
|
||||
Map<String , Object> map = new HashMap<>();
|
||||
adminRequest.getList().forEach(
|
||||
item -> {
|
||||
map.put("email", item.getEmail());
|
||||
map.put("deleted", String.valueOf(1));
|
||||
//로그 기록
|
||||
Optional<Admin> admin = adminMapper.findByEmail(item.getEmail());
|
||||
|
||||
//쿼리 실행
|
||||
adminMapper.deleteAdmin(map);
|
||||
|
||||
// map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
// map.put("name", CommonUtils.getAdmin().getName());
|
||||
// map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
// map.put("type", HISTORYTYPE.ADMIN_INFO_DELETE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name",admin.get().getName());
|
||||
jsonObject.put("email",item.getEmail());
|
||||
// map.put("content",jsonObject.toString());
|
||||
// historyMapper.saveLog(map);
|
||||
historyService.setLog(HISTORYTYPE.ADMIN_INFO_DELETE, jsonObject);
|
||||
}
|
||||
);
|
||||
log.info("deleteAdmin Deleted Admin: {}", map);
|
||||
return AdminResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(AdminResponse.ResultData.builder().message(SuccessCode.DELETE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private String randomPwd(){
|
||||
final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
StringBuilder password = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int randomIndex = secureRandom.nextInt(CHARACTERS.length());
|
||||
char randomChar = CHARACTERS.charAt(randomIndex);
|
||||
password.append(randomChar);
|
||||
}
|
||||
|
||||
return password.toString();
|
||||
}
|
||||
|
||||
//초기화 메일 Send
|
||||
private void sendMail(String userEmail, String newPassword){
|
||||
JavaMailSender javaMailSender = getJavaMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true, "UTF-8");
|
||||
|
||||
helper.setSubject("【칼리버스】비밀번호 초기화");
|
||||
|
||||
helper.setFrom(username);
|
||||
|
||||
helper.setTo(userEmail);
|
||||
|
||||
//helper.setCc(ccAddr);
|
||||
|
||||
// helper.setBcc("14xxxxx098@qq.com");
|
||||
|
||||
helper.setSentDate(new Date());
|
||||
|
||||
|
||||
helper.setText(mailContent(newPassword),true);
|
||||
|
||||
//첨부파일
|
||||
//helper.addAttachment(userNm+"이력서",new File(filePath+fileName));
|
||||
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
log.info("sendMail mail : {}", userEmail);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.SENDMAIL_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//메일 설정
|
||||
private JavaMailSender getJavaMailSender() {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost(host);
|
||||
mailSender.setPort(port);
|
||||
mailSender.setUsername(username);
|
||||
mailSender.setPassword(password);
|
||||
|
||||
// 메일 설정, 프로퍼티 추가
|
||||
Properties properties = mailSender.getJavaMailProperties();
|
||||
properties.put("mail.transport.protocol", "smtp");
|
||||
properties.put("mail.smtp.auth", "true");
|
||||
properties.put("mail.smtp.ssl.enable", "true");
|
||||
properties.put("mail.smtp.socketFactory.port", 465);
|
||||
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
properties.put("mail.smtp.ssl.checkserveridentity", "true");
|
||||
properties.put("mail.smtp.socketFactory.fallback", "false");
|
||||
|
||||
return mailSender;
|
||||
}
|
||||
|
||||
//메일 내용 form
|
||||
private String mailContent(String newPassword){
|
||||
|
||||
String body =
|
||||
"<html>"+
|
||||
"<head>"+
|
||||
"<meta charset='UTF-8'>"+
|
||||
"</head>"+
|
||||
"<body style='font-family:Arial, sans-serif;'>"+
|
||||
"<p>안녕하세요! 비밀번호 초기화가 성공적으로 이루어졌습니다.</p>" +
|
||||
"<p>임시 비밀번호: <strong>"+newPassword+"</strong></p>"+
|
||||
"<p>로그인하여 계정에 액세스한 다음, [비밀번호 변경]을 통해 새 비밀번호를 설정해 주세요.</p>" +
|
||||
"<p>더 많은 질문이나 도움이 필요한 경우, 언제든지 연락해 주세요.</p>" +
|
||||
"</body>" +
|
||||
"</html>";
|
||||
|
||||
return body;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.AdminMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.TokenMapper;
|
||||
import com.caliverse.admin.domain.entity.Admin;
|
||||
import com.caliverse.admin.domain.entity.STATUS;
|
||||
import com.caliverse.admin.domain.entity.Token;
|
||||
import com.caliverse.admin.domain.request.AuthenticateRequest;
|
||||
import com.caliverse.admin.domain.response.AuthenticateResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.configuration.JwtService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticateService{
|
||||
|
||||
private final AdminMapper userMapper;
|
||||
private final TokenMapper tokenMapper;
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final JwtService jwtService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final HistoryService historyService;
|
||||
@Value("${password.expiration-days}")
|
||||
private int passwordExpiration;
|
||||
|
||||
// 로그인
|
||||
public AuthenticateResponse login(AuthenticateRequest authenticateRequest) {
|
||||
|
||||
String email = authenticateRequest.getEmail();
|
||||
String pw = authenticateRequest.getPassword();
|
||||
// 삭제 계정 여부
|
||||
if(!userMapper.existsByEmail(email)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_MATCH_USER.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken( email, pw ));
|
||||
}catch (AuthenticationException authException){
|
||||
// 인증에 실패하면 예외가 발생 AuthenticationException 떨어짐
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_FOUND_USER.getMessage());
|
||||
}
|
||||
|
||||
Admin admin = userMapper.findByEmail(authenticateRequest.getEmail())
|
||||
.orElseThrow(() -> new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_MATCH_USER.getMessage()));
|
||||
|
||||
//비번 기간 만료
|
||||
if (isPasswordExpired(admin.getPwUpdateDt())){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.PWD_EXPIRATION.getMessage()
|
||||
+"("+admin.getPwUpdateDt().plus(passwordExpiration,ChronoUnit.DAYS)
|
||||
.atZone(ZoneId.of("UTC"))
|
||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+" 종료)");
|
||||
}
|
||||
|
||||
if(admin.getStatus().name().equals("ROLE_NOT_PERMITTED") || admin.getStatus().name().equals("REJECT")){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_PERMITTED.getMessage());
|
||||
}
|
||||
int tokenCnt = tokenMapper.getCount(admin.getId());
|
||||
if(tokenCnt > 1){
|
||||
tokenMapper.updateResetToken(admin.getId());
|
||||
}
|
||||
|
||||
var jwtToken = jwtService.generateToken(admin);
|
||||
var refreshToken = jwtService.generateRefreshToken(admin);
|
||||
revokeAllUserTokens(admin);
|
||||
saveUserToken(admin.getId(), jwtToken);
|
||||
|
||||
log.info("login id: {}, token: {}", admin.getId(), jwtToken);
|
||||
|
||||
return AuthenticateResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.authValue(new AuthenticateResponse.AuthValue(jwtToken, refreshToken,String.valueOf(admin.getStatus())))
|
||||
.build();
|
||||
}
|
||||
|
||||
//회원가입
|
||||
public AuthenticateResponse register(AuthenticateRequest authenticateRequest){
|
||||
|
||||
if(userMapper.existsByEmail(authenticateRequest.getEmail())){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATED_EMAIL.getMessage());
|
||||
}
|
||||
|
||||
Admin admin = Admin.builder()
|
||||
// .status(STATUS.ROLE_NOT_PERMITTED) //2024.08.02 즉시 회원가입되게 변경
|
||||
.groupId((long)2)
|
||||
.status(STATUS.PERMITTED)
|
||||
.name(authenticateRequest.getName())
|
||||
.email(authenticateRequest.getEmail())
|
||||
.password(passwordEncoder.encode(authenticateRequest.getPassword()))
|
||||
.build();
|
||||
|
||||
userMapper.save(admin);
|
||||
log.info("register Sign Up : {}", admin);
|
||||
return AuthenticateResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.authValue(AuthenticateResponse.AuthValue.builder().message(SuccessCode.SAVE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 토큰 저장
|
||||
private void saveUserToken(Long memberId, String jwtToken) {
|
||||
var token = Token.builder()
|
||||
.adminId(memberId)
|
||||
.token(jwtToken)
|
||||
.tokenType(Token.TokenType.BEARER)
|
||||
.expired(false)
|
||||
.revoked(false)
|
||||
.build();
|
||||
tokenMapper.save(token);
|
||||
}
|
||||
|
||||
//토큰 삭제
|
||||
private void revokeAllUserTokens(Admin member) {
|
||||
var validUserTokens = tokenMapper.findAllValidTokenByUser(member.getId()).orElse(null);
|
||||
if(validUserTokens!=null){
|
||||
validUserTokens.setExpired(true);
|
||||
validUserTokens.setRevoked(true);
|
||||
tokenMapper.updateToken(validUserTokens);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPasswordExpired(LocalDateTime lastPasswordChangeDateTime) {
|
||||
LocalDateTime currentDateTime = LocalDateTime.now();
|
||||
LocalDateTime minusDate = currentDateTime.minusDays(passwordExpiration);
|
||||
|
||||
boolean isAfter = minusDate.isAfter(lastPasswordChangeDateTime);
|
||||
|
||||
return isAfter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.BattleMapper;
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.entity.BattleEvent;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.entity.LandAuction;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaBattleConfigData;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaBattleRewardData;
|
||||
import com.caliverse.admin.domain.request.BattleEventRequest;
|
||||
import com.caliverse.admin.domain.response.BattleEventResponse;
|
||||
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.utils.CommonUtils;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BattleEventService {
|
||||
|
||||
private final BattleMapper battleMapper;
|
||||
private final MetaDataHandler metaDataHandler;
|
||||
private final HistoryService historyService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
|
||||
//전투시스템 설정 데이터
|
||||
public BattleEventResponse getBattleConfigList(){
|
||||
|
||||
List<MetaBattleConfigData> list = metaDataHandler.getMetaBattleConfigsListData();
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleConfigList(list)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
//전투시스템 보상 데이터
|
||||
public BattleEventResponse getBattleRewardList(){
|
||||
|
||||
List<MetaBattleRewardData> list = metaDataHandler.getMetaBattleRewardsListData();
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleRewardList(list)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 전투시스템 이벤트 조회
|
||||
public BattleEventResponse getBattleEventList(@RequestParam Map<String, String> requestParam){
|
||||
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<BattleEvent> list = battleMapper.getBattleEventList(requestParam);
|
||||
|
||||
int allCnt = battleMapper.getAllCnt(requestParam);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleEventList(list)
|
||||
.total(battleMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.parseInt(requestParam.get("page_no")):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 전투시스템 이벤트 상세조회
|
||||
public BattleEventResponse getBattleEventDetail(Long id){
|
||||
|
||||
BattleEvent battleEvent = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleEvent(battleEvent)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse postBattleEvent(BattleEventRequest battleEventRequest){
|
||||
if(battleEventRequest.getRepeatType().equals(BattleEvent.BATTLE_REPEAT_TYPE.NONE)){
|
||||
LocalDateTime start_dt = battleEventRequest.getEventStartDt();
|
||||
LocalDateTime end_dt = start_dt.plusHours(12);
|
||||
battleEventRequest.setEventEndDt(end_dt);
|
||||
}
|
||||
|
||||
int operation_time = calcEndTime(battleEventRequest);
|
||||
battleEventRequest.setEventOperationTime(operation_time);
|
||||
|
||||
// int is_time = battleMapper.chkTimeOver(battleEventRequest);
|
||||
// if(is_time > 0){
|
||||
// return BattleEventResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_BATTLE_EVENT_TIME_OVER.toString())
|
||||
// .build();
|
||||
// }
|
||||
|
||||
int result = battleMapper.postBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Save: {}", battleEventRequest);
|
||||
|
||||
long battle_event_id = battleEventRequest.getId();
|
||||
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("id",String.valueOf(battle_event_id));
|
||||
|
||||
BattleEvent event_info = battleMapper.getBattleEventDetail(battle_event_id);
|
||||
|
||||
mysqlHistoryLogService.insertHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_ADD,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_ADD.name(),
|
||||
event_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.insertLandAuctionRegistryWithActivity(landRequest);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse updateBattleEvent(Long id, BattleEventRequest battleEventRequest) {
|
||||
battleEventRequest.setId(id);
|
||||
battleEventRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
battleEventRequest.setUpdateDt(LocalDateTime.now());
|
||||
|
||||
BattleEvent before_info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(!before_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !before_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
int result = battleMapper.updateBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Update Complete: {}", battleEventRequest);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", String.valueOf(id));
|
||||
|
||||
BattleEvent after_info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
mysqlHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE.name(),
|
||||
before_info,
|
||||
after_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.updateLandAuction(landRequest);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse deleteBattleEvent(BattleEventRequest battleEventRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
AtomicBoolean is_falil = new AtomicBoolean(false);
|
||||
|
||||
battleEventRequest.getList().forEach(
|
||||
item->{
|
||||
Long id = item.getId();
|
||||
BattleEvent info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(!info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
is_falil.set(true);
|
||||
return;
|
||||
}
|
||||
|
||||
map.put("id", id);
|
||||
map.put("updateBy", CommonUtils.getAdmin().getId());
|
||||
int result = battleMapper.deleteBattleEvent(map);
|
||||
log.info("BattleEvent Delete Complete: {}", item);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE.name(),
|
||||
info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.cancelLandAuction(auction_info);
|
||||
}
|
||||
);
|
||||
|
||||
if(is_falil.get()){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<BattleEvent> getScheduleBattleEventList(){
|
||||
return battleMapper.getScheduleBattleEventList();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void updateBattleEventStatus(Map<String,Object> map){
|
||||
try{
|
||||
battleMapper.updateStatusBattleEvent(map);
|
||||
log.info("BattleEvent status changed: {}", map.get("status"));
|
||||
}catch(Exception e){
|
||||
log.error("BattleEvent Status Update Fail map: {}", map);
|
||||
}
|
||||
}
|
||||
|
||||
// 이벤트 동작 시간 계산
|
||||
private int calcEndTime(BattleEventRequest battleEventRequest){
|
||||
MetaBattleConfigData config = metaDataHandler.getMetaBattleConfigsListData().stream()
|
||||
.filter(data -> data.getId().equals(battleEventRequest.getConfigId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if(config == null) return 0;
|
||||
|
||||
int round_time = battleEventRequest.getRoundTime();
|
||||
int round_count = battleEventRequest.getRoundCount();
|
||||
int round_wait_time = config.getNextRoundWaitTime();
|
||||
int result_wait_time = config.getResultUIWaitTime();
|
||||
int server_wait_time = CommonConstants.BATTLE_SERVER_WAIT_TIME;
|
||||
|
||||
int total_time = round_time + ((round_count - 1) * (round_time + round_wait_time)) + result_wait_time + server_wait_time;
|
||||
|
||||
return total_time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.BlackListMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.entity.BlackList;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.request.BlackListRequest;
|
||||
import com.caliverse.admin.domain.response.BlackListResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.common.utils.ExcelUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BlackListService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BlackListService.class);
|
||||
private final BlackListMapper blackListMapper;
|
||||
private final ExcelUtils excelUtils;
|
||||
private final HistoryMapper historyMapper;
|
||||
private final HistoryService historyService;
|
||||
private final DynamoDBService dynamoDBService;
|
||||
@Value("${caliverse.file}")
|
||||
private String excelPath;
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
public BlackListResponse getBlackList(Map requestParams){
|
||||
//페이징 처리
|
||||
requestParams = CommonUtils.pageSetting(requestParams);
|
||||
|
||||
List<BlackList> blackList = blackListMapper.getBlackList(requestParams);
|
||||
|
||||
int allCnt = blackListMapper.getAllCnt(requestParams);
|
||||
|
||||
return BlackListResponse.builder()
|
||||
.resultData(BlackListResponse.ResultData.builder()
|
||||
.list(blackList)
|
||||
.total(blackListMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParams.get("page_no")!=null?
|
||||
Integer.valueOf(requestParams.get("page_no").toString()):1)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public BlackListResponse getBlackListDetail(Long id ){
|
||||
BlackList blackList = blackListMapper.getBlackListDetail(id);
|
||||
List<BlackList> historyByGuid = blackListMapper.getHistoryByGuid(blackList.getGuid());
|
||||
blackList.setBlackListHistory(historyByGuid);
|
||||
return BlackListResponse.builder()
|
||||
.resultData(BlackListResponse.ResultData.builder()
|
||||
.blackList(blackList).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public BlackListResponse excelUpload(MultipartFile file){
|
||||
|
||||
List<BlackList> list = new ArrayList<>();
|
||||
// 파일 존재하지 않는 경우
|
||||
if (file.isEmpty()) {
|
||||
//Excel 파일을 선택해주세요.
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() );
|
||||
}
|
||||
|
||||
List<String> listData = excelUtils.getListData(file, 1, 0);
|
||||
|
||||
// 엑셀 파일내 중복된 데이터 있는지 체크
|
||||
if(excelUtils.hasDuplicates(listData)){
|
||||
//중복된 유저 정보가 있습니다.
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATE_EXCEL.getMessage() );
|
||||
}
|
||||
|
||||
listData.forEach(item->{
|
||||
|
||||
BlackList blackList = new BlackList();
|
||||
blackList.setGuid(item);
|
||||
//gameDB에서 닉네임, isWhiteUser, isBlackUser 조회
|
||||
String nickName = dynamoDBService.getGuidByName(item);
|
||||
if(nickName != ""){
|
||||
blackList.setNickname(nickName);
|
||||
}
|
||||
|
||||
//adminDB 에 데이터 있는지 체크
|
||||
int cnt = blackListMapper.getCountByGuid(item);
|
||||
//gameDB isWhiteUser 값 체크
|
||||
boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(item);
|
||||
boolean isGuid = dynamoDBService.isGuidChecked(item);
|
||||
|
||||
// //guid 검증
|
||||
// if(blackAttr.size() == 0){
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
// }
|
||||
//
|
||||
// boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(blackAttr.get("isBlackUser"));
|
||||
if(cnt == 0){
|
||||
if(isBlackUser || isGuid){
|
||||
blackList.setValidate(false);
|
||||
}else{
|
||||
blackList.setValidate(true);
|
||||
}
|
||||
}else if(cnt > 0){
|
||||
blackList.setValidate(false);
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ADMINDB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
list.add(blackList);
|
||||
}
|
||||
);
|
||||
|
||||
return BlackListResponse.builder()
|
||||
.resultData(BlackListResponse.ResultData.builder()
|
||||
.list(list)
|
||||
.build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
public Resource excelDown(String fileName) {
|
||||
return resourceLoader.getResource(excelPath + fileName);
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BlackListResponse postBlackList(BlackListRequest blackListRequest){
|
||||
|
||||
// 이용자 제재 상태를 판단하는 로직
|
||||
blackListRequest.setStatus(BlackList.STATUSTYPE.WAIT);
|
||||
blackListRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
|
||||
//복수 등록일 경우 validation 안함
|
||||
if (blackListRequest.getBlackList().size() > 1) {
|
||||
|
||||
blackListRequest.getBlackList().forEach(
|
||||
item->{
|
||||
if(item.getGuid() != null){
|
||||
String guid = item.getGuid();
|
||||
if(dynamoDBService.isGuidChecked(guid)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(guid);
|
||||
if(isBlackUser){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
blackListRequest.setGuid(guid);
|
||||
blackListRequest.setNickname(item.getNickname());
|
||||
blackListMapper.postBlackList(blackListRequest);
|
||||
logger.info("postBlackList insertBlackList: {}",blackListRequest);
|
||||
}
|
||||
}
|
||||
);
|
||||
}else{
|
||||
//단일일 경우 validation 함
|
||||
blackListRequest.getBlackList().forEach(
|
||||
item->{
|
||||
if(item.getGuid() != null){
|
||||
//adminDB 에 데이터 있는지 체크
|
||||
int cnt = blackListMapper.getCountByGuid(item.getGuid());
|
||||
if(cnt > 0){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ADMINDB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
if(dynamoDBService.isGuidChecked(item.getGuid())){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
boolean isBlackUser = dynamoDBService.isWhiteOrBlackUser(item.getGuid());
|
||||
if(isBlackUser){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
blackListRequest.setGuid(item.getGuid());
|
||||
blackListRequest.setNickname(dynamoDBService.getGuidByName(item.getGuid()));
|
||||
blackListMapper.postBlackList(blackListRequest);
|
||||
logger.info("postBlackList insertBlackList: {}",blackListRequest);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return BlackListResponse.builder()
|
||||
.resultData(BlackListResponse.ResultData.builder()
|
||||
.message(SuccessCode.REGISTRATION.getMessage()).build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BlackListResponse deleteBlackList(BlackListRequest blackListRequest){
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
blackListRequest.getBlackList().forEach(
|
||||
item->{
|
||||
map.put("id",item.getId());
|
||||
blackListMapper.deleteBlackList(map);
|
||||
|
||||
//로그 기록
|
||||
BlackList blackList = blackListMapper.getBlackListDetail(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.BLACKLIST_DELETE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("guid",blackList.getGuid());
|
||||
jsonObject.put("name","");
|
||||
//todo 닉네임을 dynamoDB에서 조회해와야 됨
|
||||
map.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(map);
|
||||
//dynamoDB char# 테이블에 isBlackUser : false 값을 insert
|
||||
// dynamoDBService.insertUpdateData(blackList.getGuid(),"isBlackUser", false);
|
||||
logger.info("deleteBlackList delete: {}",map);
|
||||
if(blackList.getStatus().equals(BlackList.STATUSTYPE.INPROGRESS))
|
||||
dynamoDBService.updateBlockUserEnd(blackList.getGuid());
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
return BlackListResponse.builder()
|
||||
.resultData(BlackListResponse.ResultData.builder()
|
||||
.message(SuccessCode.DELETE.getMessage()).build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void updateBlackListStatus(Long id, BlackList.STATUSTYPE status){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("status", status);
|
||||
|
||||
blackListMapper.updateStatus(map);
|
||||
logger.info("updateBlackListStatus BlackListSchedule status update: {}",map);
|
||||
}
|
||||
|
||||
public List<BlackList> getScheduleBlackList(){
|
||||
return blackListMapper.getScheduleBlackList();
|
||||
}
|
||||
|
||||
public void updateScheduleBlockUser(BlackList blockUser, String type){
|
||||
if(type.equals("start")){
|
||||
dynamoDBService.updateBlockUserStart(blockUser);
|
||||
}else{
|
||||
dynamoDBService.updateBlockUserEnd(blockUser.getGuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.CaliumMapper;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.entity.web3.ResponseConfirmData;
|
||||
import com.caliverse.admin.domain.entity.web3.ResponseErrorCode;
|
||||
import com.caliverse.admin.domain.entity.web3.ResponseRequestData;
|
||||
import com.caliverse.admin.domain.entity.web3.ResponseWithdrawableData;
|
||||
import com.caliverse.admin.domain.request.CaliumRequest;
|
||||
import com.caliverse.admin.domain.request.Web3Request;
|
||||
import com.caliverse.admin.domain.response.CaliumResponse;
|
||||
import com.caliverse.admin.domain.response.Web3Response;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbCaliumService;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.constants.Web3Constants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class CaliumService {
|
||||
|
||||
private final CaliumMapper caliumMapper;
|
||||
private final HistoryService historyService;
|
||||
private final Web3Service web3Service;
|
||||
// private final DynamoDBService dynamoDBService;
|
||||
private final DynamodbCaliumService dynamodbCaliumService;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
|
||||
public CaliumResponse getCaliumLimit(){
|
||||
Web3Response<ResponseWithdrawableData> web3Response = web3Service.get(
|
||||
Web3Constants.URL_SERVER_TYPE,
|
||||
null,
|
||||
ResponseWithdrawableData.class
|
||||
);
|
||||
log.info("getCaliumLimit calium WithdrawableInfo: {}", web3Response);
|
||||
|
||||
if(web3Response.isSuccess())
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.withdrawableInfo(web3Response.getData())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
else{
|
||||
String code = web3Response.getCode();
|
||||
Optional<ResponseErrorCode> error = ResponseErrorCode.fromCode(code);
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(code)
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.message(error.get().getMessage())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public CaliumResponse getList(Map requestParam){
|
||||
//페이징 처리
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<Calium> list = caliumMapper.getCaliumRequestList(requestParam);
|
||||
|
||||
double allCnt = caliumMapper.getCaliumTotal();
|
||||
double stock_qty = dynamodbCaliumService.getCaliumTotal();
|
||||
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.caliumList(list)
|
||||
.total(stock_qty)
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.parseInt(requestParam.get("page_no").toString()):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
public CaliumResponse getDetail(Long id){
|
||||
Calium calium = caliumMapper.getCaliumRequestDetail(id);
|
||||
|
||||
log.info("getDetail call Detail Info: {}", calium);
|
||||
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.calium(calium)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public CaliumResponse postCaliumRequest(CaliumRequest caliumRequest){
|
||||
caliumRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
|
||||
Web3Request apiRequest = Web3Request.builder()
|
||||
.serverType(Web3Constants.SERVER_NAME)
|
||||
.historyMessage(caliumRequest.getContent())
|
||||
.requestor(CommonUtils.getAdmin().getName())
|
||||
.amount(-Math.abs(caliumRequest.getCount())).build(); // 음수로 변환
|
||||
|
||||
Web3Response<ResponseRequestData> web3Response = web3Service.callWeb3Api(Web3Constants.URL_REQUEST, HttpMethod.POST, apiRequest, ResponseRequestData.class);
|
||||
|
||||
if(!web3Response.isSuccess()){
|
||||
log.error("postEvent Web3 api error: {}", web3Response);
|
||||
String code = web3Response.getCode();
|
||||
ResponseErrorCode error = ResponseErrorCode.fromCode(code).get();
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(code)
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.message(error.getMessage())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
log.info("postEvent Request Api Response: {}", web3Response);
|
||||
ResponseRequestData responseData = web3Response.getData();
|
||||
caliumRequest.setRequestId(responseData.get_id());
|
||||
caliumRequest.setCreateTime(responseData.getCreateTime());
|
||||
|
||||
int result = caliumMapper.postCaliumRequest(caliumRequest);
|
||||
log.info("postEvent AdminToolDB Event Save: {}", caliumRequest);
|
||||
|
||||
Calium calium = caliumMapper.getCaliumRequestDetail(caliumRequest.getId());
|
||||
|
||||
mysqlHistoryLogService.insertHistoryLog(
|
||||
HISTORYTYPE.CALIUM_ADD,
|
||||
MysqlConstants.TABLE_NAME_CALIUM_REQUEST,
|
||||
HISTORYTYPE.CALIUM_ADD.name(),
|
||||
calium,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("dept",caliumRequest.getDept());
|
||||
jsonObject.put("count",caliumRequest.getCount());
|
||||
jsonObject.put("content",caliumRequest.getContent());
|
||||
historyService.setLog(HISTORYTYPE.CALIUM_ADD, jsonObject);
|
||||
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public CaliumResponse updateCaliumCharged(CaliumRequest caliumRequest){
|
||||
log.info("updateCaliumCharged calium Request: {}", caliumRequest);
|
||||
Calium calium = caliumMapper.getCaliumRequestDetail(caliumRequest.getId());
|
||||
Long id = CommonUtils.getAdmin().getId();
|
||||
// 상태가 승인완료거나 요청한 본인이 아니면 에러처리
|
||||
if(!calium.getStatus().equals(Calium.CALIUMREQUESTSTATUS.COMPLETE) || !calium.getCreateBy().equals(id.toString())){
|
||||
log.error("updateCaliumCharged Calium Request Status or User Not Match status: {}, id: {}", calium.getStatus(), id);
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_CALIUM_FINISH.toString())
|
||||
.resultData(CaliumResponse.ResultData.builder()
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
dynamodbCaliumService.updateCaliumTotal(caliumRequest.getCount());
|
||||
|
||||
updateCaliumRequest(caliumRequest.getId(), Calium.CALIUMREQUESTSTATUS.FINISH);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("dynamoDB_update",dynamoResult);
|
||||
|
||||
historyService.setLog(HISTORYTYPE.CALIUM_TOTAL_UPDATE, jsonObject);
|
||||
|
||||
return CaliumResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void getScheduleCaliumRequestList(){
|
||||
List<Calium> scheduleList = caliumMapper.getScheduleCaliumRequest();
|
||||
for(Calium calium : scheduleList){
|
||||
String url = Web3Constants.URL_REQUEST_CONFIRM + calium.getRequestId();
|
||||
Web3Response<ResponseConfirmData> web3Response = web3Service.get(
|
||||
url,
|
||||
null,
|
||||
ResponseConfirmData.class
|
||||
);
|
||||
|
||||
if(web3Response.isSuccess()){
|
||||
ResponseConfirmData data = web3Response.getData();
|
||||
String state = data.getState();
|
||||
if(state.equals("confirm")){
|
||||
updateCaliumRequest(calium.getId(), Calium.CALIUMREQUESTSTATUS.COMPLETE, data);
|
||||
log.info("getScheduleCaliumRequestList Calium Request Confirm: {}", data);
|
||||
}else if(state.equals("cancel")){
|
||||
updateCaliumRequest(calium.getId(), Calium.CALIUMREQUESTSTATUS.REJECT, data);
|
||||
log.info("getScheduleCaliumRequestList Calium Request Cancel: {}", data);
|
||||
}
|
||||
}else{
|
||||
String code = web3Response.getCode();
|
||||
Optional<ResponseErrorCode> error = ResponseErrorCode.fromCode(code);
|
||||
log.error("getScheduleCaliumRequestList calium confirm request request_id: {}, Error: {}", calium.getRequestId(), error.get().getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCaliumRequest(Long id, Calium.CALIUMREQUESTSTATUS status){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("status", status.toString());
|
||||
map.put("updateBy", CommonUtils.getAdmin().getId());
|
||||
caliumMapper.updateStatusCaliumRequest(map);
|
||||
}
|
||||
|
||||
private void updateCaliumRequest(Long id, Calium.CALIUMREQUESTSTATUS status, ResponseConfirmData data){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("status", status.toString());
|
||||
map.put("stateTime", data.getStateTime());
|
||||
map.put("stateMessage", data.getState().equals("confirm") ? data.getStateMessage(): "");
|
||||
caliumMapper.updateStatusCaliumRequest(map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DynamoDBAttributeCreateService {
|
||||
|
||||
|
||||
public Map<String, AttributeValue> makeItemAttributeKey(String userGuid, String itemGuid){
|
||||
Map<String, AttributeValue> itemAttributes = new HashMap<>();
|
||||
itemAttributes.put("PK", AttributeValue.builder().s("item#" + userGuid).build());
|
||||
itemAttributes.put("SK", AttributeValue.builder().s(itemGuid).build());
|
||||
return itemAttributes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.DynamoDBConstants;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
|
||||
import software.amazon.awssdk.services.cloudwatch.model.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class DynamoDBMetricsService {
|
||||
|
||||
@Value("${amazon.dynamodb.metaTable}")
|
||||
private String metaTable;
|
||||
|
||||
private final CloudWatchClient cloudWatchClient;
|
||||
|
||||
public DynamoDBMetricsService(CloudWatchClient cloudWatchClient) {
|
||||
this.cloudWatchClient = cloudWatchClient;
|
||||
}
|
||||
|
||||
public GetMetricDataResponse getConsumedCapacityData(Instant startTime, Instant endTime) {
|
||||
var readCapacityQuery = MetricDataQuery.builder()
|
||||
.id("readCapacity")
|
||||
.metricStat(MetricStat.builder()
|
||||
.metric(Metric.builder()
|
||||
.namespace(DynamoDBConstants.NAMESPACE)
|
||||
.metricName(DynamoDBConstants.CONSUMED_READ_CAPACITY)
|
||||
.dimensions(List.of(
|
||||
Dimension.builder()
|
||||
.name("TableName")
|
||||
.value(metaTable)
|
||||
.build()
|
||||
))
|
||||
.build())
|
||||
.period(300) // 5분 간격
|
||||
.stat("Sum")
|
||||
.build())
|
||||
.returnData(true)
|
||||
.build();
|
||||
|
||||
var writeCapacityQuery = MetricDataQuery.builder()
|
||||
.id("writeCapacity")
|
||||
.metricStat(MetricStat.builder()
|
||||
.metric(Metric.builder()
|
||||
.namespace(DynamoDBConstants.NAMESPACE)
|
||||
.metricName(DynamoDBConstants.CONSUMED_WRITE_CAPACITY)
|
||||
.dimensions(List.of(
|
||||
Dimension.builder()
|
||||
.name("TableName")
|
||||
.value(metaTable)
|
||||
.build()
|
||||
))
|
||||
.build())
|
||||
.period(300)
|
||||
.stat("Sum")
|
||||
.build())
|
||||
.returnData(true)
|
||||
.build();
|
||||
|
||||
var request = GetMetricDataRequest.builder()
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.metricDataQueries(List.of(readCapacityQuery, writeCapacityQuery))
|
||||
.build();
|
||||
|
||||
return cloudWatchClient.getMetricData(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
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 org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
||||
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
|
||||
import software.amazon.awssdk.services.dynamodb.model.DeleteItemResponse;
|
||||
|
||||
|
||||
/*
|
||||
* 추후에 일반화 처리 필요
|
||||
* */
|
||||
@Service
|
||||
public class DynamoDBQueryServiceBase {
|
||||
|
||||
@Value("${amazon.dynamodb.metaTable}")
|
||||
private String metaTable;
|
||||
|
||||
private final DynamoDbClient dynamoDbClient;
|
||||
private final DynamoDBAttributeCreateService dynamoDBAttributeCreateService;
|
||||
|
||||
public DynamoDBQueryServiceBase(DynamoDbClient dynamoDbClient
|
||||
, DynamoDBAttributeCreateService dynamoDBAttributeCreateService
|
||||
) {
|
||||
this.dynamoDBAttributeCreateService = dynamoDBAttributeCreateService;
|
||||
this.dynamoDbClient = dynamoDbClient;
|
||||
}
|
||||
|
||||
|
||||
public void deleteUserItem(String userGuid, String itemGuid) {
|
||||
|
||||
|
||||
var itemAttributes = dynamoDBAttributeCreateService.makeItemAttributeKey(userGuid, itemGuid);
|
||||
|
||||
DeleteItemRequest request = DeleteItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.key(itemAttributes)
|
||||
.build();
|
||||
|
||||
DeleteItemResponse response = dynamoDbClient.deleteItem(request);
|
||||
|
||||
if (!response.sdkHttpResponse().isSuccessful()) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_ITEM_DELETE_FAIL.getMessage() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,396 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.EventMapper;
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.EventRequest;
|
||||
import com.caliverse.admin.domain.response.EventResponse;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbService;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class EventService {
|
||||
private final DynamoDBService dynamoDBService;
|
||||
private final DynamodbService dynamodbService;
|
||||
|
||||
private final EventMapper eventMapper;
|
||||
private final MetaDataHandler metaDataHandler;
|
||||
private final HistoryService historyService;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
|
||||
public EventResponse getList(Map requestParam){
|
||||
//페이징 처리
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<Event> list = eventMapper.getEventList(requestParam);
|
||||
|
||||
int allCnt = eventMapper.getAllCnt(requestParam);
|
||||
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.eventList(list)
|
||||
.total(eventMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.valueOf(requestParam.get("page_no").toString()):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
public EventResponse getDetail(Long id){
|
||||
Event event = eventMapper.getEventDetail(id);
|
||||
|
||||
event.setMailList(eventMapper.getMessage(id));
|
||||
List<Item> itemList = eventMapper.getItem(id);
|
||||
for(Item item : itemList){
|
||||
String itemName = metaDataHandler.getMetaItemNameData(Integer.parseInt(item.getItem()));
|
||||
item.setItemName(metaDataHandler.getTextStringData(itemName));
|
||||
}
|
||||
event.setItemList(itemList);
|
||||
|
||||
log.info("getDetail call User Email: {}, event_id: {}", CommonUtils.getAdmin().getEmail(), id);
|
||||
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.event(event)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public EventResponse postEvent(EventRequest eventRequest){
|
||||
eventRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
|
||||
int result = eventMapper.postEvent(eventRequest);
|
||||
log.info("postEvent AdminToolDB Event Save: {}", eventRequest);
|
||||
|
||||
long event_id = eventRequest.getId();
|
||||
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("mailId",String.valueOf(event_id));
|
||||
|
||||
//아이템 저장
|
||||
if(eventRequest.getItemList()!= null && !eventRequest.getItemList().isEmpty()){
|
||||
eventRequest.getItemList().forEach(
|
||||
item -> {
|
||||
map.put("goodsId",item.getItem());
|
||||
map.put("itemCnt",String.valueOf(item.getItemCnt()));
|
||||
eventMapper.insertItem(map);
|
||||
}
|
||||
);
|
||||
}
|
||||
log.info("postEvent AdminToolDB Item Save Complete");
|
||||
|
||||
//메시지 저장
|
||||
if(eventRequest.getMailList()!= null && !eventRequest.getMailList().isEmpty()){
|
||||
eventRequest.getMailList().forEach(
|
||||
item -> {
|
||||
map.put("title",item.getTitle());
|
||||
map.put("content",item.getContent());
|
||||
map.put("language",item.getLanguage());
|
||||
eventMapper.insertMessage(map);
|
||||
}
|
||||
);
|
||||
}
|
||||
log.info("postEvent AdminToolDB Message Save Complete");
|
||||
|
||||
Event event = eventMapper.getEventDetail(event_id);
|
||||
|
||||
mysqlHistoryLogService.insertHistoryLog(
|
||||
HISTORYTYPE.EVENT_ADD,
|
||||
MysqlConstants.TABLE_NAME_EVENT,
|
||||
HISTORYTYPE.EVENT_ADD.name(),
|
||||
event,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type",eventRequest.getEventType());
|
||||
jsonObject.put("start_dt",eventRequest.getStartDt());
|
||||
jsonObject.put("end_dt",eventRequest.getEndDt());
|
||||
jsonObject.put("mail_list",map);
|
||||
historyService.setLog(HISTORYTYPE.EVENT_ADD, jsonObject);
|
||||
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public EventResponse updateEvent(Long id, EventRequest eventRequest) {
|
||||
eventRequest.setId(id);
|
||||
eventRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
eventRequest.setUpdateDt(LocalDateTime.now());
|
||||
|
||||
Long event_id = eventRequest.getId();
|
||||
Event before_info = eventMapper.getEventDetail(event_id);
|
||||
before_info.setMailList(eventMapper.getMessage(event_id));
|
||||
before_info.setItemList(eventMapper.getItem(event_id));
|
||||
|
||||
int result = eventMapper.updateEvent(eventRequest);
|
||||
log.info("updateEvent AdminToolDB Event Update Complete: {}", eventRequest);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("mailId", String.valueOf(event_id));
|
||||
|
||||
// item 테이블 데이터 삭제 처리 by event_id
|
||||
eventMapper.deleteItem(map);
|
||||
|
||||
// 아이템 업데이트
|
||||
if (eventRequest.getItemList() != null && !eventRequest.getItemList().isEmpty()) {
|
||||
eventRequest.getItemList().forEach(item -> {
|
||||
map.put("goodsId", item.getItem());
|
||||
map.put("itemCnt", String.valueOf(item.getItemCnt()));
|
||||
|
||||
eventMapper.insertItem(map);
|
||||
});
|
||||
}
|
||||
log.info("updateEvent AdminToolDB Item Update Complete");
|
||||
|
||||
// message 테이블 데이터 삭제 처리 by mail_id
|
||||
eventMapper.deleteMessage(map);
|
||||
|
||||
// 메시지 업데이트
|
||||
if (eventRequest.getMailList() != null && !eventRequest.getMailList().isEmpty()) {
|
||||
eventRequest.getMailList().forEach(item -> {
|
||||
map.put("title", item.getTitle());
|
||||
map.put("content", item.getContent());
|
||||
map.put("language", item.getLanguage());
|
||||
|
||||
eventMapper.insertMessage(map);
|
||||
});
|
||||
}
|
||||
log.info("updateEvent AdminToolDB Message Update Complete");
|
||||
|
||||
Event after_event = eventMapper.getEventDetail(event_id);
|
||||
after_event.setMailList(eventMapper.getMessage(event_id));
|
||||
after_event.setItemList(eventMapper.getItem(event_id));
|
||||
|
||||
mysqlHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.EVENT_UPDATE,
|
||||
MysqlConstants.TABLE_NAME_EVENT,
|
||||
HISTORYTYPE.EVENT_UPDATE.name(),
|
||||
before_info,
|
||||
after_event,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
// if(result == 1){
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// ArrayNode mailTitleArray = objectMapper.createArrayNode();
|
||||
// ArrayNode mailTextArray = objectMapper.createArrayNode();
|
||||
// ArrayNode mailItemArray = objectMapper.createArrayNode();
|
||||
// for(Item item : eventRequest.getItemList()){
|
||||
// MailItem mailItem = MailItem.newBuilder().setItemId(CommonUtils.stringToInt(item.getItem())).setCount(item.getItemCnt()).build();
|
||||
// mailItemArray.add(JsonUtils.createMAilItem(mailItem));
|
||||
// }
|
||||
// for(Message msg: eventRequest.getMailList()){
|
||||
// String langText = msg.getLanguage();
|
||||
// int lang;
|
||||
//
|
||||
// if(langText.equals(LANGUAGETYPE.EN.toString())){
|
||||
// lang = LanguageType.LanguageType_en.getNumber();
|
||||
// }else if(langText.equals(LANGUAGETYPE.JA.toString())){
|
||||
// lang = LanguageType.LanguageType_ja.getNumber();
|
||||
// }else{
|
||||
// lang = LanguageType.LanguageType_ko.getNumber();
|
||||
// }
|
||||
// SystemMessage titleMessage = SystemMessage.builder().LanguageType(lang).Text(msg.getTitle()).build();
|
||||
// SystemMessage textMessage = SystemMessage.builder().LanguageType(lang).Text(msg.getContent()).build();
|
||||
//
|
||||
// mailTitleArray.add(JsonUtils.createSystemMessage(titleMessage));
|
||||
// mailTextArray.add(JsonUtils.createSystemMessage(textMessage));
|
||||
// }
|
||||
//
|
||||
// String dynamoResult = dynamoDBService.updateSystemMail(
|
||||
// event_id.toString(),
|
||||
// mailTitleArray,
|
||||
// mailTextArray,
|
||||
// eventRequest.getStartDt(),
|
||||
// eventRequest.getEndDt(),
|
||||
// mailItemArray);
|
||||
// jsonObject.put("dynamoDB_update",dynamoResult);
|
||||
// log.info("updateEvent DynamoDB Update Complete: {}", dynamoResult);
|
||||
// }
|
||||
|
||||
//로그 기록
|
||||
jsonObject.put("before_event",before_info.toString());
|
||||
jsonObject.put("type",eventRequest.getEventType());
|
||||
jsonObject.put("start_dt",eventRequest.getStartDt());
|
||||
jsonObject.put("end_dt",eventRequest.getEndDt());
|
||||
historyService.setLog(HISTORYTYPE.EVENT_UPDATE, jsonObject);
|
||||
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public EventResponse deleteEvent(EventRequest eventRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
|
||||
eventRequest.getList().forEach(
|
||||
item->{
|
||||
Long event_id = item.getId();
|
||||
Event event = eventMapper.getEventDetail(event_id);
|
||||
event.setMailList(eventMapper.getMessage(event_id));
|
||||
event.setItemList(eventMapper.getItem(event_id));
|
||||
|
||||
map.put("mailId",event_id);
|
||||
map.put("desc", item.getDeleteDesc());
|
||||
int result = eventMapper.deleteEvent(map);
|
||||
log.info("updateEvent AdminTool Delete Complete: {}", eventRequest);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.EVENT_DELETE,
|
||||
MysqlConstants.TABLE_NAME_EVENT,
|
||||
HISTORYTYPE.EVENT_DELETE.name(),
|
||||
event,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
// if(result == 1){
|
||||
// String dynamoResult = dynamoDBService.deleteSystemMail(item.getId().toString());
|
||||
// jsonObject.put("dynamoDB_data",dynamoResult);
|
||||
// log.info("updateEvent dynamoDB Delete Complete: {}", dynamoResult);
|
||||
// }
|
||||
|
||||
//로그 기록
|
||||
List<Message> message = eventMapper.getMessage(item.getId());
|
||||
if(!message.isEmpty()){
|
||||
jsonObject.put("message",message.get(0).getTitle());
|
||||
}
|
||||
historyService.setLog(HISTORYTYPE.EVENT_DELETE, jsonObject);
|
||||
}
|
||||
);
|
||||
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.message(SuccessCode.DELETE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<Event> getScheduleMailList(){
|
||||
return eventMapper.getScheduleEventList();
|
||||
}
|
||||
public List<Message> getMessageList(Long id){
|
||||
return eventMapper.getMessage(id);
|
||||
}
|
||||
|
||||
public List<Item> getItemList(Long id){
|
||||
return eventMapper.getItem(id);
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void updateEventStatus(Long id, Event.EVENTSTATUS status){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("status", status.toString());
|
||||
eventMapper.updateStatusEvent(map);
|
||||
log.info("updateEventStatus event status changed: {}", status);
|
||||
}
|
||||
|
||||
//메타 아이템
|
||||
public EventResponse getMetaItem(String metaId){
|
||||
long id = Long.parseLong(metaId);
|
||||
String item = metaDataHandler.getMetaItemNameData((int) id);
|
||||
boolean isItem = (item != null && !item.isEmpty());
|
||||
if(isItem) {
|
||||
Item item_info = new Item();
|
||||
item_info.setItem(metaId);
|
||||
item_info.setItemName(metaDataHandler.getTextStringData(item));
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.message(SuccessCode.ITEM_EXIST.getMessage())
|
||||
.itemInfo(item_info)
|
||||
.build())
|
||||
.build();
|
||||
}else
|
||||
return EventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(CommonCode.ERROR.getResult())
|
||||
.resultData(EventResponse.ResultData.builder()
|
||||
.message(ErrorCode.NOT_ITEM.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public void insertSystemMail(Event event, ArrayNode mailTitleArray, ArrayNode mailTextArray, ArrayNode mailSenderArray, ArrayNode mailItemArray){
|
||||
String dynamoResult = dynamoDBService.insertSystemMail(
|
||||
event.getId().intValue(),
|
||||
mailTitleArray,
|
||||
mailTextArray,
|
||||
mailSenderArray,
|
||||
event.getStartDt(),
|
||||
event.getEndDt(),
|
||||
mailItemArray
|
||||
);
|
||||
|
||||
eventMapper.updateAddFlag(event.getId());
|
||||
|
||||
historyService.setScheduleLog(HISTORYTYPE.EVENT_ADD, dynamoResult);
|
||||
log.info("insertSystemMail Save Complete: {}", dynamoResult);
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void insertSystemMail(Event event){
|
||||
try {
|
||||
long event_id = event.getId();
|
||||
event.setMailList(eventMapper.getMessage(event_id));
|
||||
event.setItemList(eventMapper.getItem(event_id));
|
||||
|
||||
dynamodbService.insertSystemMail(event);
|
||||
|
||||
eventMapper.updateAddFlag(event_id);
|
||||
updateEventStatus(event_id, Event.EVENTSTATUS.RUNNING);
|
||||
|
||||
log.info("insertSystemMail Save Complete: {}", event.getId());
|
||||
}catch (Exception e){
|
||||
log.error("insertSystemMail Exception: {}", e.getMessage());
|
||||
updateEventStatus(event.getId(), Event.EVENTSTATUS.FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.GroupMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.GroupRequest;
|
||||
import com.caliverse.admin.domain.response.GroupResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GroupService {
|
||||
|
||||
private final GroupMapper groupMapper;
|
||||
private final HistoryMapper historyMapper;
|
||||
|
||||
|
||||
// 관리자 권한 리스트 조회
|
||||
public GroupResponse getAllGroups(){
|
||||
|
||||
Map map = new HashMap();
|
||||
List<Groups> getGroupList = groupMapper.getGroupList(map);
|
||||
|
||||
return GroupResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(GroupResponse.ResultData.builder().groupList(getGroupList).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* param: orderby
|
||||
* param: page
|
||||
* return GroupResponse.list
|
||||
*/
|
||||
// 권한 설정 화면 리스트 조회
|
||||
public GroupResponse getGroupList(Map requestMap){
|
||||
|
||||
//페이징 처리
|
||||
requestMap = CommonUtils.pageSetting(requestMap);
|
||||
|
||||
List<Groups> groupList = groupMapper.getGroupList(requestMap);
|
||||
|
||||
int allCnt = groupMapper.getAllCnt();
|
||||
return GroupResponse.builder()
|
||||
.resultData(GroupResponse.ResultData.builder()
|
||||
.groupList(groupList)
|
||||
.total(allCnt)
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestMap.get("page_no")!=null?
|
||||
Integer.valueOf(requestMap.get("page_no").toString()):1)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 권한 설정 상세 조회
|
||||
public GroupResponse getGroupDetail(String groupId){
|
||||
|
||||
Long lid = Long.valueOf(groupId);
|
||||
List<Authority> authorityList = groupMapper.getGroupAuth(lid);
|
||||
return GroupResponse.builder()
|
||||
.resultData(GroupResponse.ResultData.builder()
|
||||
.authorityList(authorityList)
|
||||
.groupId(lid)
|
||||
.groupNm(groupMapper.getGroupInfo(lid).get("name"))
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
//권한 그룹 등록
|
||||
public GroupResponse postAdminGroup(GroupRequest groupRequest){
|
||||
List<Integer> authList = Arrays.asList(1, 5, 6, 9, 10, 11, 13, 14, 15, 16, 19, 22, 24, 26, 32); //그룹 초기 권한
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
groupRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
|
||||
int groupName = groupMapper.findGroupName(groupRequest.getGroupNm());
|
||||
|
||||
if(groupName == 0){
|
||||
groupMapper.postAdminGroup(groupRequest);
|
||||
|
||||
map.put("groupId", groupRequest.getId());
|
||||
authList.forEach(val->{
|
||||
map.put("authId",val);
|
||||
groupMapper.insertGroupAuth(map);
|
||||
});
|
||||
}else{
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATED_GROUPNAME.getMessage());
|
||||
}
|
||||
|
||||
log.info("postAdminGroup group: {}",map);
|
||||
|
||||
return GroupResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(GroupResponse.ResultData.builder().message(SuccessCode.SAVE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
//그룹 권한 수정
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public GroupResponse updateAdminGroup(String groupId,GroupRequest groupRequest){
|
||||
|
||||
Map<String , Object> map = new HashMap<>();
|
||||
//로그 남기 before 그룹 설정
|
||||
List<Authority> beforeAuth = groupMapper.getGroupAuth(Long.valueOf(groupId));
|
||||
log.info("updateAdminGroup before::{}",beforeAuth);
|
||||
|
||||
// group_auth 테이블 삭제 By groupId
|
||||
groupMapper.deleteGroupAuth(groupId);
|
||||
|
||||
groupRequest.getGroupList().forEach(
|
||||
item-> {
|
||||
map.put("authId", item.getAuthId());
|
||||
map.put("groupId", groupId);
|
||||
groupMapper.insertGroupAuth(map);
|
||||
}
|
||||
);
|
||||
//로그 남기 before 그룹 설정
|
||||
List<Authority> afterAuth = groupMapper.getGroupAuth(Long.valueOf(groupId));
|
||||
log.info("updateAdminGroup after::{}",afterAuth);
|
||||
//로그 기록
|
||||
map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
map.put("name", CommonUtils.getAdmin().getName());
|
||||
map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
map.put("type", HISTORYTYPE.GROUP_AUTH_UPDATE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("groupNm",groupMapper.getGroupInfo(Long.valueOf(groupId)).get("name"));
|
||||
jsonObject.put("auth(before)",beforeAuth);
|
||||
jsonObject.put("auth(after)",afterAuth);
|
||||
map.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(map);
|
||||
|
||||
return GroupResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(GroupResponse.ResultData.builder().message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
//그룹 삭제
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public GroupResponse deleteAdminGroup(GroupRequest groupRequest){
|
||||
Map<String, Object> map = new HashMap();
|
||||
groupRequest.getGroupList().forEach(
|
||||
item-> {
|
||||
//순서 바뀜 안됨, 삭제 하기전 그룹명 가져오기
|
||||
Map<String, String> groupInfo = groupMapper.getGroupInfo(item.getGroupId());
|
||||
|
||||
groupMapper.deleteGroup(item.getGroupId());
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("groupNm",groupInfo.get("name"));
|
||||
|
||||
map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
map.put("name", CommonUtils.getAdmin().getName());
|
||||
map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
map.put("type", HISTORYTYPE.GROUP_DELETE);
|
||||
map.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(map);
|
||||
}
|
||||
);
|
||||
log.info("deleteAdminGroup group: {}", map);
|
||||
|
||||
return GroupResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(GroupResponse.ResultData.builder().message(SuccessCode.DELETE.getMessage()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.entity.Log;
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.response.HistoryResponse;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
|
||||
import io.jsonwebtoken.io.IOException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class HistoryService {
|
||||
|
||||
private final HistoryMapper historyMapper;
|
||||
|
||||
public HistoryResponse getHistoryList(Map requestParams){
|
||||
|
||||
//페이징 처리
|
||||
requestParams = CommonUtils.pageSetting(requestParams);
|
||||
|
||||
List<Log> historyList = historyMapper.getHistoryList(requestParams);
|
||||
|
||||
int allCnt = historyMapper.getAllCnt(requestParams);
|
||||
|
||||
return HistoryResponse.builder()
|
||||
.resultData(HistoryResponse.ResultData.builder()
|
||||
.total(historyMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParams.get("page_no")!=null?
|
||||
Integer.valueOf(requestParams.get("page_no").toString()):1)
|
||||
.list(historyList).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
public HistoryResponse getHistoryDetail(String id){
|
||||
String logJson = historyMapper.getLogJson(id);
|
||||
return HistoryResponse.builder()
|
||||
.resultData(HistoryResponse.ResultData.builder().content(logJson).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void insertMetaData(File file) {
|
||||
try {
|
||||
// Read the JSON data from the file
|
||||
String jsonData = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
|
||||
// Parse the JSON data into a JSONArray
|
||||
JSONArray jsonArray = new JSONArray(jsonData);
|
||||
|
||||
|
||||
// Iterate over the elements in the JSONArray
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
// Get the current element as a JSONObject
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
|
||||
// Extract the values from the JSONObject
|
||||
Integer itemId = Integer.valueOf(jsonObject.getInt("item_id"));
|
||||
|
||||
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("fileName", file.getName());
|
||||
item.put("dataId", itemId);
|
||||
item.put("jsonData", jsonObject.toString());
|
||||
|
||||
|
||||
// Insert the values into MariaDB
|
||||
|
||||
historyMapper.insertMetaData(item);
|
||||
|
||||
|
||||
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
log.error("insertMetaData IOException: {}", e.getMessage());
|
||||
} catch (JSONException e) {
|
||||
log.error("insertMetaData JSONException: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setLog(HISTORYTYPE type, JSONObject content){
|
||||
//로그 기록
|
||||
Map<String, Object> logMap = new HashMap<>();
|
||||
logMap.put("adminId", CommonUtils.getAdmin().getId());
|
||||
logMap.put("name", CommonUtils.getAdmin().getName());
|
||||
logMap.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
logMap.put("type", type);
|
||||
logMap.put("content",content.toString());
|
||||
historyMapper.saveLog(logMap);
|
||||
}
|
||||
|
||||
public void setScheduleLog(HISTORYTYPE type, String message){
|
||||
//스케줄 로그 기록
|
||||
Map<String, Object> logMap = new HashMap<>();
|
||||
logMap.put("adminId", 1);
|
||||
logMap.put("name", "schedule");
|
||||
logMap.put("mail", "schedule");
|
||||
logMap.put("type", type);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message",message);
|
||||
logMap.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(logMap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,850 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.caliverse.admin.Indicators.Indicatorsservice.aggregationservice.*;
|
||||
import com.caliverse.admin.Indicators.entity.*;
|
||||
import com.caliverse.admin.logs.logservice.indicators.*;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.caliverse.admin.domain.entity.Currencys;
|
||||
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.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.common.utils.ExcelUtils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class IndicatorsService {
|
||||
private final ExcelUtils excelUtils;
|
||||
|
||||
|
||||
private IndicatorsAuLoadService indicatorsAuLoadService;
|
||||
private final IndicatorsDauLoadService indicatorsDauLoadService;
|
||||
private final IndicatorsMcuLoadService indicatorsMcuLoadService;
|
||||
private final IndicatorsDglcLoadService indicatorsDglcLoadService;
|
||||
private final IndicatorsPlayTimeLoadService indicatorsPlayTimeLoadService;
|
||||
private final IndicatorsNruLoadService indicatorsNruLoadService;
|
||||
private final IndicatorsCapacityLoadService indicatorsCapacityLoadService;
|
||||
private final IndicatorsMauLoadService indicatorsMauLoadService;
|
||||
private final IndicatorsWauLoadService indicatorsWauLoadService;
|
||||
private final IndicatorsUgqCreateLoadService indicatorsUgqCreateLoadService;
|
||||
private final IndicatorsMetaverServerLoadService indicatorsMetaverServerLoadService;
|
||||
|
||||
private final IndicatorsDauService dauService;
|
||||
private final IndicatorsNruService indicatorsNruService;
|
||||
private final IndicatorsMcuService mcuService;
|
||||
|
||||
private final DynamoDBMetricsService dynamoDBMetricsService;
|
||||
|
||||
//UserStatistics
|
||||
public IndicatorsResponse list(Map<String, String> requestParams){
|
||||
|
||||
String startDt = requestParams.get("start_dt");
|
||||
String endDt = requestParams.get("end_dt");
|
||||
log.info("list get UserStatistics startDt: {}, endDt: {}", startDt, endDt);
|
||||
|
||||
List<IndicatorsResponse.userStatistics> userStatistics = getMergeUserStatisticsData(startDt, endDt);
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.userStatisticsList(userStatistics)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
// dashboard
|
||||
public IndicatorsResponse total(){
|
||||
LocalDate search_date = LocalDate.now().minusDays(1);
|
||||
DauLogInfo dau_info = indicatorsDauLoadService.getDailyIndicatorLog(search_date.toString(), DauLogInfo.class);
|
||||
NruLogInfo nru_info = indicatorsNruLoadService.getDailyIndicatorLog(search_date.toString(), NruLogInfo.class);
|
||||
McuLogInfo mcu_info = indicatorsMcuLoadService.getDailyIndicatorLog(search_date.toString(), McuLogInfo.class);
|
||||
|
||||
LocalDate pre_search_date = LocalDate.now().minusDays(2);
|
||||
DauLogInfo pre_dau_info = indicatorsDauLoadService.getDailyIndicatorLog(pre_search_date.toString(), DauLogInfo.class);
|
||||
NruLogInfo pre_nru_info = indicatorsNruLoadService.getDailyIndicatorLog(pre_search_date.toString(), NruLogInfo.class);
|
||||
McuLogInfo pre_mcu_info = indicatorsMcuLoadService.getDailyIndicatorLog(pre_search_date.toString(), McuLogInfo.class);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
log.info("total pre_dau: {}, dau: {}, pre_nru: {}, nru: {}, pre_mcu: {}, mcu: {}",
|
||||
objectMapper.writeValueAsString(pre_dau_info), objectMapper.writeValueAsString(dau_info),
|
||||
objectMapper.writeValueAsString(pre_nru_info), objectMapper.writeValueAsString(nru_info),
|
||||
objectMapper.writeValueAsString(pre_mcu_info), objectMapper.writeValueAsString(mcu_info));
|
||||
}catch (JsonProcessingException e) {
|
||||
log.error("Error converting object to JSON", e);
|
||||
}
|
||||
|
||||
int dau_cnt = dau_info == null ? 0 : dau_info.getDau();
|
||||
int pre_dau_cnt = pre_dau_info == null ? 0 : pre_dau_info.getDau();
|
||||
IndicatorsResponse.Dau dau = IndicatorsResponse.Dau.builder()
|
||||
.count(dau_cnt)
|
||||
.updown(CommonUtils.getDiffStatus(dau_cnt, pre_dau_cnt))
|
||||
.dif(CommonUtils.getDiffRate(dau_cnt, pre_dau_cnt))
|
||||
.build();
|
||||
|
||||
int nru_cnt = nru_info == null ? 0 : nru_info.getNru();
|
||||
int pre_nru_cnt = pre_nru_info == null ? 0 : pre_nru_info.getNru();
|
||||
IndicatorsResponse.NRU nru = IndicatorsResponse.NRU.builder()
|
||||
.count(nru_cnt)
|
||||
.updown(CommonUtils.getDiffStatus(nru_cnt, pre_nru_cnt))
|
||||
.dif(CommonUtils.getDiffRate(nru_cnt, pre_nru_cnt))
|
||||
.build();
|
||||
|
||||
int mcu_cnt = mcu_info == null ? 0 : mcu_info.getMaxCountUser();
|
||||
int pre_mcu_cnt = pre_mcu_info == null ? 0 : pre_mcu_info.getMaxCountUser();
|
||||
IndicatorsResponse.MCU mcu = IndicatorsResponse.MCU.builder()
|
||||
.count(mcu_cnt)
|
||||
.updown(CommonUtils.getDiffStatus(mcu_cnt, pre_mcu_cnt))
|
||||
.dif(CommonUtils.getDiffRate(mcu_cnt, pre_mcu_cnt))
|
||||
.build();
|
||||
|
||||
IndicatorsResponse.Dashboard dashboard = IndicatorsResponse.Dashboard.builder()
|
||||
.dau(dau)
|
||||
.mcu(mcu)
|
||||
.pu(null)
|
||||
.nru(nru)
|
||||
.build();
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.dashboard(dashboard)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
//유저 지표 엑셀 다운로드(현재 frontend 기능으로 사용)
|
||||
public void userExcelDown(Map<String, String> requestParams, HttpServletResponse res){
|
||||
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
// List<Distinct> distinctCount = getDistinctCount(startDt, endDt);
|
||||
// String sheetName = "Caliverse_User";
|
||||
|
||||
// String headerNames[] = new String[]{"일자", "DAU", "WAU", "MAU","NRU","PU","MCU"};
|
||||
|
||||
// String[][] bodyDatass = new String[distinctCount.size()][7];
|
||||
|
||||
// for (int i = 0; i < distinctCount.size(); i++) {
|
||||
// bodyDatass[i][0] = String.valueOf(distinctCount.get(i).getDate());
|
||||
// bodyDatass[i][1] = String.valueOf(distinctCount.get(i).getDau());
|
||||
// bodyDatass[i][2] = String.valueOf(distinctCount.get(i).getWau());
|
||||
// bodyDatass[i][3] = String.valueOf(distinctCount.get(i).getMau());
|
||||
// bodyDatass[i][4] = String.valueOf(0);
|
||||
// bodyDatass[i][5] = String.valueOf(0);
|
||||
// bodyDatass[i][6] = String.valueOf(0);
|
||||
// }
|
||||
|
||||
// String outfileName = "Caliverse_User";
|
||||
// try {
|
||||
// excelUtils.excelDownload(sheetName, headerNames, bodyDatass ,outfileName, res);
|
||||
// }catch (IOException exception){
|
||||
// logger.error(exception.getMessage());
|
||||
// }
|
||||
|
||||
}
|
||||
// 유저 지표 Retention
|
||||
public IndicatorsResponse retentionList(Map<String, String> requestParams){
|
||||
List<IndicatorsResponse.Retention> retentionList = new ArrayList<>();
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
int cnt = dateRange.size();
|
||||
for (LocalDate date : dateRange) {
|
||||
List<IndicatorsResponse.Dday> dDayList = new ArrayList<>();
|
||||
for (int i = 0; i < cnt; i++){
|
||||
IndicatorsResponse.Dday dDay = IndicatorsResponse.Dday.builder()
|
||||
.date("D+" + i)
|
||||
.dif("0%")
|
||||
.build();
|
||||
dDayList.add(dDay);
|
||||
}
|
||||
cnt -- ;
|
||||
IndicatorsResponse.Retention retention = IndicatorsResponse.Retention.builder()
|
||||
.date(date)
|
||||
.dDay(dDayList)
|
||||
.build();
|
||||
retentionList.add(retention);
|
||||
}
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.retentionList(retentionList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public void retentionExcelDown(Map<String, String> requestParams,HttpServletResponse res){
|
||||
List<IndicatorsResponse.Retention> retentionList = new ArrayList<>();
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
int cnt = dateRange.size();
|
||||
for (LocalDate date : dateRange) {
|
||||
List<IndicatorsResponse.Dday> dDayList = new ArrayList<>();
|
||||
for (int i = 0; i < cnt; i++){
|
||||
IndicatorsResponse.Dday dDay = IndicatorsResponse.Dday.builder()
|
||||
.date("D+" + i)
|
||||
.dif("0%")
|
||||
.build();
|
||||
dDayList.add(dDay);
|
||||
}
|
||||
cnt -- ;
|
||||
IndicatorsResponse.Retention retention = IndicatorsResponse.Retention.builder()
|
||||
.date(date)
|
||||
.dDay(dDayList)
|
||||
.build();
|
||||
retentionList.add(retention);
|
||||
}
|
||||
// 엑셀 파일 생성 및 다운로드
|
||||
try {
|
||||
ExcelUtils.exportToExcelByRentention(retentionList,res);
|
||||
}catch (IOException exception){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
// 유저 지표 Retention
|
||||
public IndicatorsResponse segmentList(Map<String, String> requestParams){
|
||||
// LocalDate searchDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("search_dt")));
|
||||
|
||||
// List<IndicatorsResponse.Segment> segmentList = Arrays.asList(
|
||||
// IndicatorsResponse.Segment.builder().type("Excellent").au("0").dif("0%").build(),
|
||||
// IndicatorsResponse.Segment.builder().type("Influential").au("0").dif("0%").build(),
|
||||
// IndicatorsResponse.Segment.builder().type("Potential").au("0").dif("0%").build(),
|
||||
// IndicatorsResponse.Segment.builder().type("Before leave").au("0").dif("0%").build(),
|
||||
// IndicatorsResponse.Segment.builder().type("InActive").au("0").dif("0%").build(),
|
||||
// IndicatorsResponse.Segment.builder().type("New Join").au("0").dif("0%").build()
|
||||
// );
|
||||
// return IndicatorsResponse.builder()
|
||||
// .resultData(IndicatorsResponse.ResultData.builder()
|
||||
// .segmentList(segmentList)
|
||||
// .startDt(searchDt.minusDays(100))
|
||||
// .endDt(searchDt)
|
||||
// .build())
|
||||
// .status(CommonCode.SUCCESS.getHttpStatus())
|
||||
// .result(CommonCode.SUCCESS.getResult())
|
||||
// .build();
|
||||
return null;
|
||||
|
||||
}
|
||||
public void segmentExcelDown(Map<String, String> requestParams, HttpServletResponse res){
|
||||
LocalDate searchDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("search_dt")));
|
||||
|
||||
List<IndicatorsResponse.Segment> segmentList = Arrays.asList(
|
||||
IndicatorsResponse.Segment.builder().type("Excellent").au("0").dif("0%").build(),
|
||||
IndicatorsResponse.Segment.builder().type("Influential").au("0").dif("0%").build(),
|
||||
IndicatorsResponse.Segment.builder().type("Potential").au("0").dif("0%").build(),
|
||||
IndicatorsResponse.Segment.builder().type("Before leave").au("0").dif("0%").build(),
|
||||
IndicatorsResponse.Segment.builder().type("InActive").au("0").dif("0%").build(),
|
||||
IndicatorsResponse.Segment.builder().type("New Join").au("0").dif("0%").build()
|
||||
);
|
||||
|
||||
LocalDate startDt = searchDt.minusDays(100);
|
||||
LocalDate endDt = searchDt;
|
||||
// 엑셀 파일 생성 및 다운로드
|
||||
try {
|
||||
ExcelUtils.exportToExcelBySegment(segmentList,startDt,endDt,res);
|
||||
}catch (IOException exception){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
// 유저 지표 플레이타임
|
||||
public IndicatorsResponse playTimeList(Map<String, String> requestParams){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<IndicatorsResponse.Playtime> playtimeList = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
IndicatorsResponse.Playtime build = IndicatorsResponse.Playtime.builder()
|
||||
.date(date)
|
||||
.totalTime(0)
|
||||
.averageTime(0)
|
||||
.userCnt(Arrays.asList(0, 0, 0, 0))
|
||||
.build();
|
||||
playtimeList.add(build);
|
||||
}
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.playtimeList(playtimeList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public void playTimeExcelDown(Map<String, String> requestParams, HttpServletResponse res){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<IndicatorsResponse.Playtime> playtimeList = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
IndicatorsResponse.Playtime build = IndicatorsResponse.Playtime.builder()
|
||||
.date(date)
|
||||
.totalTime(0)
|
||||
.averageTime(0)
|
||||
.userCnt(Arrays.asList(0, 0, 0, 0))
|
||||
.build();
|
||||
playtimeList.add(build);
|
||||
}
|
||||
|
||||
String sheetName = "PlayTime";
|
||||
|
||||
String headerNames[] = new String[]{"일자","30분 이내","30분~1시간", "1시간~3시간", "3시간 이상"
|
||||
, "총 누적 플레이타임(분)","1인당 평균 플레이타임(분)"};
|
||||
|
||||
String[][] bodyDatass = new String[playtimeList.size()][7];
|
||||
for (int i = 0; i < playtimeList.size(); i++) {
|
||||
IndicatorsResponse.Playtime entry = playtimeList.get(i);
|
||||
bodyDatass[i][0] = String.valueOf(entry.getDate());
|
||||
bodyDatass[i][1] = String.valueOf(entry.getUserCnt().get(0));
|
||||
bodyDatass[i][2] = String.valueOf(entry.getUserCnt().get(1));
|
||||
bodyDatass[i][3] = String.valueOf(entry.getUserCnt().get(2));
|
||||
bodyDatass[i][4] = String.valueOf(entry.getUserCnt().get(3));
|
||||
bodyDatass[i][5] = String.valueOf(entry.getTotalTime());
|
||||
bodyDatass[i][6] = String.valueOf(entry.getAverageTime());
|
||||
}
|
||||
String outfileName = "PlayTime_"+ LocalDateTime.now().getNano();
|
||||
// 엑셀 파일 생성 및 다운로드
|
||||
try {
|
||||
excelUtils.excelDownload(sheetName,headerNames,bodyDatass,outfileName,res);
|
||||
}catch (IOException exception){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<IndicatorsResponse.DailyGoods> getDailyGoodsList(String currencyType, List<Currencys> dailyList
|
||||
, List<Currencys> totalList){
|
||||
List<IndicatorsResponse.DailyGoods> resList = dailyList.stream()
|
||||
.collect(Collectors.groupingBy(Currencys::getDate))
|
||||
.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(entry -> {
|
||||
LocalDate currentDate = entry.getKey();
|
||||
List<Currencys> currentDayList = entry.getValue();
|
||||
|
||||
List<IndicatorsResponse.Total> totals = totalList.stream()
|
||||
.filter(t -> currentDate.isEqual(t.getDate()))
|
||||
.map(t -> {
|
||||
IndicatorsResponse.Total total = new IndicatorsResponse.Total();
|
||||
total.setDate(currentDate);
|
||||
total.setDeltaType(t.getDeltaType());
|
||||
total.setQuantity(t.getQuantity());
|
||||
|
||||
// 이전 날짜의 Total 객체를 찾습니다.
|
||||
Currencys previousTotal = totalList.stream()
|
||||
.filter(previous -> currentDate.minusDays(1).isEqual(previous.getDate()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// 이전 날짜의 Total이 존재할 경우 dif를 계산합니다.
|
||||
if (previousTotal != null) {
|
||||
double previousQuantity = previousTotal.getQuantity();
|
||||
double currentQuantity = total.getQuantity();
|
||||
|
||||
// dif를 계산하여 설정합니다. (이전 날짜 대비 증가율 계산)
|
||||
if (previousQuantity != 0) {
|
||||
double dif = Math.round(((currentQuantity - previousQuantity) / previousQuantity) * 100);
|
||||
total.setDif(dif+"%");
|
||||
} else {
|
||||
// 이전 날짜의 Quantity가 0인 경우 예외 처리 (분모가 0일 때)
|
||||
total.setDif(String.valueOf(Double.POSITIVE_INFINITY));
|
||||
}
|
||||
} else {
|
||||
// 이전 날짜의 Total이 없는 경우 예외 처리
|
||||
total.setDif("");
|
||||
}
|
||||
return total;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ROUTE> acquireRoutes = Arrays.asList(
|
||||
ROUTE.QUEST_REWARD, ROUTE.SEASON_PASS, ROUTE.FROM_PROP,
|
||||
ROUTE.CLAIM_REWARD, ROUTE.USE_ITEM, ROUTE.TATTOO_ENHANCE,
|
||||
ROUTE.TATTOO_CONVERSION, ROUTE.SHOP_BUY, ROUTE.SHOP_SELL,
|
||||
ROUTE.PAID_PRODUCT, ROUTE.TRADE_ADD, ROUTE.NFT_LOCKIN
|
||||
);
|
||||
|
||||
List<ROUTE> consumeRoutes = Arrays.asList(
|
||||
ROUTE.SHOP_BUY, ROUTE.SHOP_SELL, ROUTE.USE_PROP,
|
||||
ROUTE.USE_TAXI, ROUTE.TATTOO_ENHANCE, ROUTE.TATTOO_CONVERSION,
|
||||
ROUTE.SHOUT, ROUTE.SUMMON, ROUTE.CREATE_PARTYROOM,
|
||||
ROUTE.INVENTORY_EXPAND, ROUTE.TRADE_REMOVE, ROUTE.NFT_UNLOCK
|
||||
);
|
||||
List<IndicatorsResponse.DailyData> dailyDataList = currentDayList.stream()
|
||||
.collect(Collectors.groupingBy(Currencys::getDeltaType))
|
||||
.entrySet().stream()
|
||||
.map(dataEntry -> {
|
||||
String deltaType = dataEntry.getKey();
|
||||
List<Currencys> data = dataEntry.getValue();
|
||||
|
||||
List<Currencys> modifiedData = new ArrayList<>();
|
||||
|
||||
if ("ACQUIRE".equals(deltaType)) {
|
||||
for (ROUTE route : acquireRoutes) {
|
||||
boolean containsRoute = data.stream().anyMatch(d -> route.name().equals(d.getRoute()));
|
||||
if (!containsRoute) {
|
||||
Currencys additionalData = new Currencys();
|
||||
additionalData.setRoute(route.getDescription());
|
||||
additionalData.setQuantity(0);
|
||||
additionalData.setDate(data.get(0).getDate());
|
||||
additionalData.setCurrencyType(currencyType);
|
||||
modifiedData.add(additionalData);
|
||||
}
|
||||
}
|
||||
} else if ("CONSUME".equals(deltaType)) {
|
||||
for (ROUTE route : consumeRoutes) {
|
||||
boolean containsRoute = data.stream().anyMatch(d -> route.name().equals(d.getRoute()));
|
||||
if (!containsRoute) {
|
||||
Currencys additionalData = new Currencys();
|
||||
additionalData.setRoute(route.getDescription());
|
||||
additionalData.setQuantity(0);
|
||||
additionalData.setDate(data.get(0).getDate());
|
||||
additionalData.setCurrencyType(currencyType);
|
||||
modifiedData.add(additionalData);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Currencys> lastData = data.stream()
|
||||
.map(d -> {
|
||||
ROUTE route = Arrays.stream(ROUTE.values())
|
||||
.filter(r -> r.name().equals(d.getRoute()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (route != null) {
|
||||
d.setRoute(route.getDescription());
|
||||
}
|
||||
return d;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
modifiedData.addAll(lastData);
|
||||
|
||||
IndicatorsResponse.DailyData dailyData = new IndicatorsResponse.DailyData();
|
||||
dailyData.setDeltaType(deltaType);
|
||||
dailyData.setDate(data.get(0).getDate());
|
||||
dailyData.setData(modifiedData);
|
||||
return dailyData;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
IndicatorsResponse.DailyGoods build = IndicatorsResponse.DailyGoods.builder()
|
||||
.date(currentDate)
|
||||
.total(totals)
|
||||
.dailyData(dailyDataList)
|
||||
.build();
|
||||
return build;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return resList;
|
||||
}
|
||||
//재화 지표
|
||||
public IndicatorsResponse getCurrencyUse(Map<String, String> requestParams) {
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
String currencyType = CommonUtils.objectToString(requestParams.get("currency_type"));
|
||||
|
||||
List<Currencys> dailyList = getCurrencyCount(startDt, endDt, currencyType);
|
||||
List<Currencys> totalList = getDailyGoodsTotal(startDt, endDt, currencyType);
|
||||
|
||||
List<IndicatorsResponse.DailyGoods> dailyGoodsList = getDailyGoodsList(currencyType, dailyList, totalList);
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.dailyGoods(dailyGoodsList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
//재화 지표 엑셀 다운로드
|
||||
public void currencyExcelDown(Map<String, String> requestParams, HttpServletResponse res){
|
||||
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
String currencyType = CommonUtils.objectToString(requestParams.get("currency_type"));
|
||||
|
||||
List<Currencys> dailyList = getCurrencyCount(startDt, endDt, currencyType);
|
||||
List<Currencys> totalList = getDailyGoodsTotal(startDt, endDt, currencyType);
|
||||
|
||||
List<IndicatorsResponse.DailyGoods> dailyGoodsList = getDailyGoodsList(currencyType, dailyList, totalList);
|
||||
|
||||
// 엑셀 파일 생성 및 다운로드
|
||||
try {
|
||||
ExcelUtils.exportToExcelByDailyGoods(dailyGoodsList, res);
|
||||
}catch (IOException exception){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//VBP 지표
|
||||
public IndicatorsResponse getVBPList(Map<String, String> requestParams){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<Currencys> dailyGoods = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
List<Currencys> currencysList = Arrays.asList(
|
||||
Currencys.builder().route("OFFLINE_VISIT").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("OFFLINE_PAYMENT").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("ONLINE_VISIT").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("ONLINE_PAYMENT").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("STORE").deltaType("USE").date(date).count(0).build(),
|
||||
Currencys.builder().route("VBP").deltaType("USE").date(date).count(0).build()
|
||||
);
|
||||
dailyGoods.addAll(currencysList);
|
||||
}
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.currencysList(dailyGoods)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
//이이템 지표
|
||||
public IndicatorsResponse getItemList(Map<String, String> requestParams){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<Currencys> dailyGoods = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
List<Currencys> currencysList = Arrays.asList(
|
||||
Currencys.builder().route("Dummy_GET_1").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_GET_2").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_GET_3").deltaType("GET").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_USE_1").deltaType("USE").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_USE_2").deltaType("USE").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_USE_3").deltaType("USE").date(date).count(0).build()
|
||||
);
|
||||
dailyGoods.addAll(currencysList);
|
||||
}
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.currencysList(dailyGoods)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
//인스턴스 지표
|
||||
public IndicatorsResponse getInstanceList(Map<String, String> requestParams){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<Currencys> dailyGoods = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
List<Currencys> currencysList = Arrays.asList(
|
||||
Currencys.builder().route("Dummy_Instance_1").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_Instance_1").date(date).count(0).build()
|
||||
);
|
||||
dailyGoods.addAll(currencysList);
|
||||
}
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.currencysList(dailyGoods)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
//의상/타투 지표
|
||||
public IndicatorsResponse getClothesList(Map<String, String> requestParams){
|
||||
String startDt = CommonUtils.objectToString(requestParams.get("start_dt"));
|
||||
String endDt = CommonUtils.objectToString(requestParams.get("end_dt"));
|
||||
List<LocalDate> dateRange = CommonUtils.dateRange(startDt, endDt);
|
||||
List<Currencys> dailyGoods = new ArrayList<>();
|
||||
for (LocalDate date : dateRange){
|
||||
List<Currencys> currencysList = Arrays.asList(
|
||||
Currencys.builder().route("Dummy_Item_Id_1").date(date).count(0).build(),
|
||||
Currencys.builder().route("Dummy_Item_Id_2").date(date).count(0).build()
|
||||
);
|
||||
dailyGoods.addAll(currencysList);
|
||||
}
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.currencysList(dailyGoods)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//DAU 지표
|
||||
public IndicatorsResponse getDauDataList(Map<String, String> requestParams){
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
|
||||
// List<DailyActiveUser> dailyActiveUserList = getDauList(startDt, endDt);
|
||||
|
||||
// return IndicatorsResponse.builder()
|
||||
// .resultData(IndicatorsResponse.ResultData.builder()
|
||||
// .dailyActiveUserList(dailyActiveUserList)
|
||||
// .build())
|
||||
// .status(CommonCode.SUCCESS.getHttpStatus())
|
||||
// .result(CommonCode.SUCCESS.getResult())
|
||||
// .build();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dauExcelDown(Map<String, String> requestParams, HttpServletResponse res){
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
|
||||
String fileName = CommonUtils.objectToString(requestParams.get("file"));
|
||||
//List<DailyActiveUser> dailyActiveUserList = getDauList(startDt, endDt);
|
||||
|
||||
String sheetName = "DAU";
|
||||
|
||||
String headerNames[] = new String[]{"일자","dau","dalc", "dglc", "max_au"
|
||||
, "00:00","01:00","02:00","03:00","04:00","05:00"
|
||||
, "06:00","07:00","08:00","09:00","10:00","11:00"
|
||||
, "12:00","13:00","14:00","15:00","16:00","17:00"
|
||||
, "18:00","19:00","20:00","21:00","22:00","23:00"};
|
||||
|
||||
int colLength = headerNames.length;
|
||||
|
||||
// String[][] bodyDatass = new String[dailyActiveUserList.size()][colLength];
|
||||
// for (int i = 0; i < dailyActiveUserList.size(); i++) {
|
||||
|
||||
// var entry = dailyActiveUserList.get(i);
|
||||
// bodyDatass[i][0] = String.valueOf(entry.getDate());
|
||||
// bodyDatass[i][1] = String.valueOf(entry.getDau());
|
||||
// bodyDatass[i][2] = String.valueOf(entry.getDalc());
|
||||
// bodyDatass[i][3] = String.valueOf(entry.getDglc());
|
||||
// bodyDatass[i][4] = String.valueOf(entry.getMaxAu());
|
||||
// bodyDatass[i][5] = String.valueOf(entry.getH0());
|
||||
// bodyDatass[i][6] = String.valueOf(entry.getH1());
|
||||
// bodyDatass[i][7] = String.valueOf(entry.getH2());
|
||||
// bodyDatass[i][8] = String.valueOf(entry.getH3());
|
||||
// bodyDatass[i][9] = String.valueOf(entry.getH4());
|
||||
// bodyDatass[i][10] = String.valueOf(entry.getH5());
|
||||
|
||||
// bodyDatass[i][11] = String.valueOf(entry.getH6());
|
||||
// bodyDatass[i][12] = String.valueOf(entry.getH7());
|
||||
// bodyDatass[i][13] = String.valueOf(entry.getH8());
|
||||
// bodyDatass[i][14] = String.valueOf(entry.getH9());
|
||||
// bodyDatass[i][15] = String.valueOf(entry.getH10());
|
||||
// bodyDatass[i][16] = String.valueOf(entry.getH11());
|
||||
|
||||
// bodyDatass[i][17] = String.valueOf(entry.getH12());
|
||||
// bodyDatass[i][18] = String.valueOf(entry.getH13());
|
||||
// bodyDatass[i][19] = String.valueOf(entry.getH14());
|
||||
// bodyDatass[i][20] = String.valueOf(entry.getH15());
|
||||
// bodyDatass[i][21] = String.valueOf(entry.getH16());
|
||||
// bodyDatass[i][22] = String.valueOf(entry.getH17());
|
||||
|
||||
// bodyDatass[i][23] = String.valueOf(entry.getH18());
|
||||
// bodyDatass[i][24] = String.valueOf(entry.getH19());
|
||||
// bodyDatass[i][25] = String.valueOf(entry.getH20());
|
||||
// bodyDatass[i][26] = String.valueOf(entry.getH21());
|
||||
// bodyDatass[i][27] = String.valueOf(entry.getH22());
|
||||
// bodyDatass[i][28] = String.valueOf(entry.getH23());
|
||||
|
||||
//위 28이란 숫자를 collength 값에 종속적으로 바꾸고 싶은데... 고민해보자
|
||||
//}
|
||||
|
||||
// 엑셀 파일 생성 및 다운로드
|
||||
// try {
|
||||
// excelUtils.excelDownload(sheetName,headerNames,bodyDatass,fileName,res);
|
||||
// }catch (IOException exception){
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.getMessage());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//Daily Medal 지표
|
||||
public IndicatorsResponse getDailyMedalDataList(Map<String, String> requestParams){
|
||||
LocalDate startDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("start_dt")));
|
||||
LocalDate endDt = LocalDate.parse(CommonUtils.objectToString(requestParams.get("end_dt")));
|
||||
|
||||
List<DailyMedal> dailyMedal = getDailyMedal(startDt, endDt);
|
||||
|
||||
return IndicatorsResponse.builder()
|
||||
.resultData(IndicatorsResponse.ResultData.builder()
|
||||
.dailyMedalList(dailyMedal)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<DailyMedal> getDailyMedal(LocalDate startTime, LocalDate endTime){
|
||||
|
||||
Map map = new HashMap();
|
||||
map.put("startDt" , CommonUtils.startOfDay(startTime));
|
||||
map.put("endDt" , CommonUtils.endOfDay(endTime));
|
||||
List<DailyMedal> dateActive = indicatorsMapper.getDailyMedal(map);
|
||||
|
||||
// 결과를 처리하여 결과값 반환
|
||||
return dateActive;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public List<Object> getDauList(LocalDate startTime, LocalDate endTime){
|
||||
|
||||
Map map = new HashMap();
|
||||
map.put("startDt" , CommonUtils.startOfDay(startTime));
|
||||
map.put("endDt" , CommonUtils.endOfDay(endTime));
|
||||
//List<DailyActiveUser> dateActive = indicatorsMapper.getDailyActiveUserList(map);
|
||||
|
||||
// 결과를 처리하여 결과값 반환
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<DauLogInfo> getActiveUserCount(LocalDate startTime, String endTime){
|
||||
|
||||
//Map map = new HashMap();
|
||||
//map.put("startDt" , CommonUtils.startOfDay(startTime));
|
||||
//map.put("endDt" , CommonUtils.endOfDay(endTime));
|
||||
//List<Distinct> dateActive = indicatorsMapper.getDailyActive(map);
|
||||
|
||||
// 결과를 처리하여 결과값 반환
|
||||
List<DauLogInfo> ativeUsers = indicatorsAuLoadService.getIndicatorsLogData(endTime, endTime, DauLogInfo.class);
|
||||
|
||||
return ativeUsers;
|
||||
}
|
||||
public List<Currencys> getCurrencyCount(LocalDate startTime, LocalDate endTime, String type){
|
||||
|
||||
Map inputMap = new HashMap();
|
||||
inputMap.put("startDt" , CommonUtils.startOfDay(startTime));
|
||||
inputMap.put("endDt" , CommonUtils.endOfDay(endTime));
|
||||
inputMap.put("currencyType" , type);
|
||||
//List<Currencys> currencysList = indicatorsMapper.getDailyGoods(inputMap);
|
||||
|
||||
// 결과를 처리하여 결과값 반환
|
||||
return new ArrayList<Currencys>();
|
||||
}
|
||||
public List<Currencys> getDailyGoodsTotal(LocalDate startTime, LocalDate endTime, String type){
|
||||
|
||||
Map inputMap = new HashMap();
|
||||
inputMap.put("startDt" , CommonUtils.startOfDay(startTime));
|
||||
inputMap.put("endDt" , CommonUtils.endOfDay(endTime));
|
||||
inputMap.put("currencyType" , type);
|
||||
//List<Currencys> total = indicatorsMapper.getDailyGoodsTotal(inputMap);
|
||||
|
||||
// 결과를 처리하여 결과값 반환
|
||||
return new ArrayList<Currencys>();
|
||||
}
|
||||
|
||||
// 데이터 병합
|
||||
private List<IndicatorsResponse.userStatistics> getMergeUserStatisticsData(String startDt, String endDt){
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
List<DauLogInfo> dauList = indicatorsDauLoadService.getIndicatorsLogData(startDt, endDt, DauLogInfo.class);
|
||||
List<DglcLogInfo> dglcList = indicatorsDglcLoadService.getIndicatorsLogData(startDt, endDt, DglcLogInfo.class);
|
||||
List<McuLogInfo> mcuList = indicatorsMcuLoadService.getIndicatorsLogData(startDt, endDt, McuLogInfo.class);
|
||||
List<PlayTimeLogInfo> playtimeList = indicatorsPlayTimeLoadService.getIndicatorsLogData(startDt, endDt, PlayTimeLogInfo.class);
|
||||
List<NruLogInfo> nruList = indicatorsNruLoadService.getIndicatorsLogData(startDt, endDt, NruLogInfo.class);
|
||||
List<DBCapacityInfo> capacityList = indicatorsCapacityLoadService.getIndicatorsLogData(startDt, endDt, DBCapacityInfo.class);
|
||||
List<MauLogInfo> mauList = indicatorsMauLoadService.getIndicatorsLogData(startDt, endDt, MauLogInfo.class);
|
||||
List<WauLogInfo> wauList = indicatorsWauLoadService.getIndicatorsLogData(startDt, endDt, WauLogInfo.class);
|
||||
List<UgqCreateLogInfo> ugqCreateList = indicatorsUgqCreateLoadService.getIndicatorsLogData(startDt, endDt, UgqCreateLogInfo.class);
|
||||
List<MetaverseServerInfo> metaverseServerList = indicatorsMetaverServerLoadService.getIndicatorsLogData(startDt, endDt, MetaverseServerInfo.class);
|
||||
log.info("getMergeUserStatisticsData Lists get Completed");
|
||||
|
||||
Map<String, Integer> dauMap = dauList.stream()
|
||||
.collect(Collectors.toMap(DauLogInfo::getLogDay, info -> info.getDau() != null ? info.getDau() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Integer> dglcMap = dglcList.stream()
|
||||
.collect(Collectors.toMap(DglcLogInfo::getLogDay, info -> info.getDglc() != null ? info.getDglc() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Integer> mcuMap = mcuList.stream()
|
||||
.collect(Collectors.toMap(McuLogInfo::getLogDay, info -> info.getMaxCountUser() != null ? info.getMaxCountUser() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Long> playtimeMap = playtimeList.stream()
|
||||
.collect(Collectors.toMap(PlayTimeLogInfo::getLogDay, info -> info.getTotalPlayTimeCount() != null ? info.getTotalPlayTimeCount() : 0L, (existing, replacement) -> existing));
|
||||
Map<String, Integer> nruMap = nruList.stream()
|
||||
.collect(Collectors.toMap(NruLogInfo::getLogDay, info -> info.getNru() != null ? info.getNru() : 0, (existing, replacement) -> existing));
|
||||
Map<String, DBCapacityInfo> capacityMap = capacityList.stream()
|
||||
.collect(Collectors.toMap(DBCapacityInfo::getLogDay, info -> info, (existing, replacement) -> existing));
|
||||
Map<String, Integer> mauMap = mauList.stream()
|
||||
.collect(Collectors.toMap(MauLogInfo::getLogDay, info -> info.getMau() != null ? info.getMau() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Integer> wauMap = wauList.stream()
|
||||
.collect(Collectors.toMap(WauLogInfo::getLogDay, info -> info.getWau() != null ? info.getWau() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Integer> ugqCreateMap = ugqCreateList.stream()
|
||||
.collect(Collectors.toMap(UgqCreateLogInfo::getLogDay, info -> info.getUgqCrateCount() != null ? info.getUgqCrateCount() : 0, (existing, replacement) -> existing));
|
||||
Map<String, Integer> metaverseServerMap = metaverseServerList.stream()
|
||||
.collect(Collectors.toMap(MetaverseServerInfo::getLogDay, info -> info.getServerCount() != null ? info.getServerCount() : 0, (existing, replacement) -> existing));
|
||||
log.info("getMergeUserStatisticsData Lists To Map Convert Completed");
|
||||
|
||||
Set<String> allDates = new TreeSet<>();
|
||||
allDates.addAll(dauMap.keySet());
|
||||
allDates.addAll(dglcMap.keySet());
|
||||
allDates.addAll(mcuMap.keySet());
|
||||
allDates.addAll(playtimeMap.keySet());
|
||||
allDates.addAll(nruMap.keySet());
|
||||
allDates.addAll(capacityMap.keySet());
|
||||
allDates.addAll(mauMap.keySet());
|
||||
allDates.addAll(wauMap.keySet());
|
||||
allDates.addAll(ugqCreateMap.keySet());
|
||||
allDates.addAll(metaverseServerMap.keySet());
|
||||
log.info("getMergeUserStatisticsData Lists Merge Completed");
|
||||
|
||||
return allDates.stream()
|
||||
.map(date -> {
|
||||
DBCapacityInfo capacity = capacityMap.getOrDefault(date, null);
|
||||
|
||||
return IndicatorsResponse.userStatistics.builder()
|
||||
.date(date)
|
||||
.dau(dauMap.getOrDefault(date, 0))
|
||||
.dglc(dglcMap.getOrDefault(date, 0))
|
||||
.mcu(mcuMap.getOrDefault(date, 0))
|
||||
.playtime(playtimeMap.getOrDefault(date, 0L))
|
||||
.nru(nruMap.getOrDefault(date, 0))
|
||||
.readCapacity(capacity != null ? capacity.getConsumeReadTotal() : 0L)
|
||||
.writeCapacity(capacity != null ? capacity.getConsumeWriteTotal() : 0L)
|
||||
.wau(wauMap.getOrDefault(date, 0))
|
||||
.mau(mauMap.getOrDefault(date, 0))
|
||||
.ugqCreate(ugqCreateMap.getOrDefault(date, 0))
|
||||
.serverCount(metaverseServerMap.getOrDefault(date, 0))
|
||||
.build();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}catch (Exception e){
|
||||
log.error("Error UserStatisticsData Merge Fail", e);
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.caliverse.admin.domain.adminlog.AdminItemDeleteLog;
|
||||
import com.caliverse.admin.domain.adminlog.IAdminLog;
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.entity.ItemList;
|
||||
import com.caliverse.admin.domain.entity.SEARCHTYPE;
|
||||
import com.caliverse.admin.domain.response.ItemDeleteResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.caliverse.admin.domain.request.ItemsRequest;
|
||||
import com.caliverse.admin.domain.response.ItemsResponse;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ItemsService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ItemsService.class);
|
||||
|
||||
private final DynamoDBService dynamoDBService;
|
||||
private final UserGameSessionService userGameSessionService;
|
||||
private final DynamoDBQueryServiceBase dynamoDBQueryServiceBase;
|
||||
private final HistoryMapper historyMapper;
|
||||
|
||||
|
||||
|
||||
// 아이템 정보 조회 GUID,item ID, item name
|
||||
public ItemsResponse findItems(Map<String,String> requestParam){
|
||||
String searchType = requestParam.get("search_type").toString();
|
||||
String search_key = requestParam.get("search_key").toString().trim();
|
||||
String guid = search_key;
|
||||
|
||||
if(searchType.equals(SEARCHTYPE.NAME.name())){
|
||||
guid = dynamoDBService.getNickNameByGuid(search_key);
|
||||
}
|
||||
|
||||
List<ItemList> itemList = dynamoDBService.getItems(guid);
|
||||
|
||||
return ItemsResponse.builder()
|
||||
.resultData(ItemsResponse.ResultData.builder()
|
||||
.list(itemList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public ItemDeleteResponse postItemDelete(ItemsRequest itemDeleteRequest){
|
||||
var userGuid = itemDeleteRequest.getUserGuid();
|
||||
var itemGuid = itemDeleteRequest.getItemGuid();
|
||||
var itemCount = itemDeleteRequest.getItemCount();
|
||||
|
||||
//UserKick
|
||||
userGameSessionService.kickUserSession(userGuid);
|
||||
//ItemDelete
|
||||
dynamoDBQueryServiceBase.deleteUserItem(userGuid, itemGuid);
|
||||
|
||||
//로그 기록
|
||||
IAdminLog adminLog = new AdminItemDeleteLog(userGuid, itemGuid, itemCount);
|
||||
adminLog.saveLogToDB();
|
||||
|
||||
|
||||
return ItemDeleteResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(ItemDeleteResponse.ResultData.builder()
|
||||
.message(SuccessCode.DYNAMODB_ITEM_DELETE_SUCCESS.getMessage())
|
||||
.deletedItemGuid(itemGuid)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.LandMapper;
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.dynamodb.domain.atrrib.LandAuctionHighestBidUserAttrib;
|
||||
import com.caliverse.admin.dynamodb.domain.atrrib.LandAuctionRegistryAttrib;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaBuildingData;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaLandData;
|
||||
import com.caliverse.admin.domain.request.LandRequest;
|
||||
import com.caliverse.admin.domain.response.LandResponse;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbLandAuctionService;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbLandService;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LandService {
|
||||
|
||||
// private final DynamoDBService dynamoDBService;
|
||||
private final DynamodbLandAuctionService dynamodbLandAuctionService;
|
||||
private final DynamodbLandService dynamodbLandService;
|
||||
|
||||
private final LandMapper landMapper;
|
||||
private final MetaDataHandler metaDataHandler;
|
||||
private final HistoryService historyService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
|
||||
// 랜드 정보 조회
|
||||
public LandResponse getLandList(){
|
||||
List<MetaLandData> landData = metaDataHandler.getMetaLandListData();
|
||||
List<LandResponse.Land> landList = landData.stream()
|
||||
.filter(land -> !land.isNonAuction() && land.getEditor().equals("USER"))
|
||||
.map(data -> LandResponse.Land.builder()
|
||||
.id(data.getLandId())
|
||||
.name(metaDataHandler.getTextStringData(data.getLandName()))
|
||||
.desc(metaDataHandler.getTextStringData(data.getLandDesc()))
|
||||
.owner(data.getOwner())
|
||||
.nonAuction(data.isNonAuction())
|
||||
.size(data.getLandSize())
|
||||
.socket(data.getBuildingSocket())
|
||||
.type(data.getLandType())
|
||||
.buildingId(data.getBuildingId())
|
||||
.build()
|
||||
).toList();
|
||||
|
||||
return LandResponse.builder()
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.landList(landList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 빌딩 정보 조회
|
||||
public LandResponse getBuildingList(){
|
||||
List<MetaBuildingData> buildingData = metaDataHandler.getMetaBuildingListData();
|
||||
List<LandResponse.Building> buildingList = buildingData.stream()
|
||||
.map(data -> LandResponse.Building.builder()
|
||||
.id(data.getBuildingId())
|
||||
.name(metaDataHandler.getTextStringData(data.getBuildingName()))
|
||||
.desc(metaDataHandler.getTextStringData(data.getBuildingDesc()))
|
||||
.owner(data.getOwner())
|
||||
.open(data.isBuildingOpen())
|
||||
.size(data.getBuildingSize())
|
||||
.socket(data.getInstanceSocket())
|
||||
.build()
|
||||
).toList();
|
||||
|
||||
return LandResponse.builder()
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.buildingList(buildingList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public LandResponse getLandDetail(Long id){
|
||||
|
||||
LandAuction event = landMapper.getLandAuctionDetail(id);
|
||||
|
||||
event.setMessageList(landMapper.getMessage(id));
|
||||
|
||||
log.info("call User Email: {}, event_id: {}", CommonUtils.getAdmin().getEmail(), id);
|
||||
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.auction(event)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 랜드 경매 조회
|
||||
public LandResponse getLandAuctionList(@RequestParam Map<String, String> requestParam){
|
||||
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<LandAuction> list = landMapper.getLandAuctionList(requestParam);
|
||||
|
||||
int allCnt = landMapper.getAllCnt(requestParam);
|
||||
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.auctionList(list)
|
||||
.total(landMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.parseInt(requestParam.get("page_no")):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 랜드 경매 상세조회
|
||||
public LandResponse getLandAuctionDetail(Long id){
|
||||
|
||||
LandAuction landAuction = landMapper.getLandAuctionDetail(id);
|
||||
|
||||
landAuction.setMessageList(landMapper.getMessage(id));
|
||||
|
||||
log.info("call User Email: {}, id: {}", CommonUtils.getAdmin().getEmail(), id);
|
||||
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.auction(landAuction)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public LandResponse postLandAuction(LandRequest landRequest){
|
||||
|
||||
Integer land_id = landRequest.getLandId();
|
||||
int isLand = landMapper.getPossibleLand(land_id);
|
||||
if(isLand > 0){
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_LAND_AUCTION_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
boolean isLandOwner = dynamodbLandService.isLandOwner(land_id);
|
||||
if(isLandOwner){
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_LAND_OWNER.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
// int nextSeq = landMapper.getMaxLandSeq(land_id) + 1;
|
||||
int next_auction_number = dynamodbLandAuctionService.getLandAuctionNumber(land_id) + 1;
|
||||
landRequest.setAuctionSeq(next_auction_number);
|
||||
landRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
|
||||
int result = landMapper.postLandAuction(landRequest);
|
||||
log.info("AdminToolDB LandAuction Save: {}", landRequest);
|
||||
|
||||
long auction_id = landRequest.getId();
|
||||
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("id",String.valueOf(auction_id));
|
||||
|
||||
//메시지 저장
|
||||
if(landRequest.getMassageList()!= null && !landRequest.getMassageList().isEmpty()){
|
||||
landRequest.getMassageList().forEach(
|
||||
item -> {
|
||||
map.put("title",item.getTitle());
|
||||
map.put("content",item.getContent());
|
||||
map.put("language",item.getLanguage());
|
||||
landMapper.insertMessage(map);
|
||||
}
|
||||
);
|
||||
}
|
||||
log.info("AdminToolDB Message Save Complete");
|
||||
|
||||
LandAuction auction_info = landMapper.getLandAuctionDetail(auction_id);
|
||||
auction_info.setMessageList(landMapper.getMessage(auction_id));
|
||||
|
||||
mysqlHistoryLogService.insertHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_ADD,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
HISTORYTYPE.LAND_AUCTION_ADD.name(),
|
||||
auction_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dynamodbLandAuctionService.insertLandAuctionRegistryWithActivity(landRequest);
|
||||
|
||||
//로그 기록
|
||||
try{
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("land_id", landRequest.getLandId());
|
||||
jsonObject.put("auction_seq", landRequest.getAuctionSeq());
|
||||
jsonObject.put("start_price", landRequest.getStartPrice());
|
||||
jsonObject.put("recv_start_dt", landRequest.getResvStartDt());
|
||||
jsonObject.put("recv_end_dt", landRequest.getResvEndDt());
|
||||
jsonObject.put("auction_start_dt", landRequest.getAuctionStartDt());
|
||||
jsonObject.put("auction_end_dt", landRequest.getAuctionEndDt());
|
||||
jsonObject.put("message_list", map);
|
||||
historyService.setLog(HISTORYTYPE.LAND_AUCTION_ADD, jsonObject);
|
||||
}catch(Exception e){
|
||||
log.error("history log Save Fail: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public LandResponse updateLandAuction(Long id, LandRequest landRequest) {
|
||||
landRequest.setId(id);
|
||||
landRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
landRequest.setUpdateDt(LocalDateTime.now());
|
||||
|
||||
LandAuction before_info = landMapper.getLandAuctionDetail(id);
|
||||
before_info.setMessageList(landMapper.getMessage(id));
|
||||
|
||||
if(!before_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !before_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
int result = landMapper.updateLandAuction(landRequest);
|
||||
log.info("AdminToolDB LandAuction Update Complete: {}", landRequest);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", String.valueOf(id));
|
||||
|
||||
// message 테이블 데이터 삭제 처리 by mail_id
|
||||
landMapper.deleteMessage(map);
|
||||
|
||||
// 메시지 업데이트
|
||||
if (landRequest.getMassageList() != null && !landRequest.getMassageList().isEmpty()) {
|
||||
landRequest.getMassageList().forEach(item -> {
|
||||
map.put("title", item.getTitle());
|
||||
map.put("content", item.getContent());
|
||||
map.put("language", item.getLanguage());
|
||||
|
||||
landMapper.insertMessage(map);
|
||||
});
|
||||
}
|
||||
log.info("AdminToolDB Message Update Complete");
|
||||
|
||||
LandAuction after_info = landMapper.getLandAuctionDetail(id);
|
||||
after_info.setMessageList(landMapper.getMessage(id));
|
||||
|
||||
mysqlHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_UPDATE,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
HISTORYTYPE.LAND_AUCTION_UPDATE.name(),
|
||||
before_info,
|
||||
after_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dynamodbLandAuctionService.updateLandAuction(landRequest);
|
||||
|
||||
//로그 기록
|
||||
try{
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("before_info",before_info.toString());
|
||||
jsonObject.put("after_info",after_info.toString());
|
||||
// jsonObject.put("dynamoDB_result",land_auction_registry_result);
|
||||
historyService.setLog(HISTORYTYPE.LAND_AUCTION_UPDATE, jsonObject);
|
||||
}catch(Exception e){
|
||||
log.error("history log Save Fail: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return LandResponse.builder()
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public LandResponse deleteLandAuction(LandRequest landRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
AtomicBoolean is_falil = new AtomicBoolean(false);
|
||||
|
||||
landRequest.getList().forEach(
|
||||
item->{
|
||||
Long auction_id = item.getId();
|
||||
LandAuction auction_info = landMapper.getLandAuctionDetail(auction_id);
|
||||
auction_info.setMessageList(landMapper.getMessage(auction_id));
|
||||
|
||||
if(!auction_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !auction_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
is_falil.set(true);
|
||||
return;
|
||||
}
|
||||
|
||||
map.put("id", auction_id);
|
||||
map.put("updateBy", CommonUtils.getAdmin().getId());
|
||||
int result = landMapper.deleteLandAuction(map);
|
||||
log.info("LandAuction Delete Complete: {}", item);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_DELETE,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
HISTORYTYPE.LAND_AUCTION_DELETE.name(),
|
||||
auction_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dynamodbLandAuctionService.cancelLandAuction(auction_info);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
//로그 기록
|
||||
List<Message> message = landMapper.getMessage(item.getId());
|
||||
if(!message.isEmpty()){
|
||||
jsonObject.put("message",message.get(0).getTitle());
|
||||
}
|
||||
jsonObject.put("auction_info", auction_info);
|
||||
// jsonObject.put("dynamoDB_result",land_auction_registry_result);
|
||||
historyService.setLog(HISTORYTYPE.LAND_AUCTION_DELETE, jsonObject);
|
||||
}
|
||||
);
|
||||
|
||||
if(is_falil.get()){
|
||||
return LandResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
return LandResponse.builder()
|
||||
.resultData(LandResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<LandAuction> getScheduleLandAuctionList(){
|
||||
return landMapper.getScheduleLandAuctionList();
|
||||
}
|
||||
|
||||
public LandAuctionRegistryAttrib getLandAuctionRegistryAttrib(Integer land_id, Integer auction_seq){
|
||||
return dynamodbLandAuctionService.getLandAuctionRegistry(land_id, auction_seq);
|
||||
}
|
||||
|
||||
public LandAuctionHighestBidUserAttrib getLandAuctionHighestUserAttrib(Integer land_id, Integer auction_seq){
|
||||
return dynamodbLandAuctionService.getLandAuctionHighestUser(land_id, auction_seq);
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void updateLandAuctionStatus(Map<String,Object> map){
|
||||
try{
|
||||
landMapper.updateStatusLandAuction(map);
|
||||
log.info("updateLandAuctionStatus landAuction status changed: {}", map.get("status"));
|
||||
}catch(Exception e){
|
||||
log.error("updateLandAuction LandAuction Update Fail map: {}", map);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.web.authentication.logout.LogoutHandler;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.TokenMapper;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogoutService implements LogoutHandler {
|
||||
private final TokenMapper tokenMapper;
|
||||
|
||||
@Override
|
||||
public void logout(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.Authentication authentication) {
|
||||
final String authHeader = request.getHeader("Authorization");
|
||||
final String jwt;
|
||||
if (authHeader == null ||!authHeader.startsWith("Bearer ")) {
|
||||
return;
|
||||
}
|
||||
jwt = authHeader.substring(7);
|
||||
var storedToken = tokenMapper.findByToken(jwt)
|
||||
.orElse(null);
|
||||
if (storedToken != null) {
|
||||
storedToken.setExpired(true);
|
||||
storedToken.setRevoked(true);
|
||||
tokenMapper.updateToken(storedToken);
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
log.info("logout User: {}", authentication.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.MailMapper;
|
||||
import com.caliverse.admin.domain.dao.total.WalletUserMapper;
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.MailRequest;
|
||||
import com.caliverse.admin.domain.response.MailResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.common.utils.ExcelUtils;
|
||||
import com.caliverse.admin.scheduler.ScheduleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MailService {
|
||||
private final DynamoDBService dynamoDBService;
|
||||
private final WalletUserMapper walletUserMapper;
|
||||
|
||||
@Value("${excel.file-path}")
|
||||
private String excelPath;
|
||||
@Value("${caliverse.file}")
|
||||
private String samplePath;
|
||||
private final ExcelUtils excelUtils;
|
||||
private final MailMapper mailMapper;
|
||||
private final HistoryMapper historyMapper;
|
||||
private final MetaDataHandler metaDataHandler;
|
||||
private final ResourceLoader resourceLoader;
|
||||
private final ScheduleService scheduleService;
|
||||
private final HistoryService historyService;
|
||||
|
||||
public MailResponse getList(Map requestParam){
|
||||
|
||||
// gameDB 조회 및 서비스 로직
|
||||
//페이징 처리
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<Mail> list = mailMapper.getMailList(requestParam);
|
||||
|
||||
int allCnt = mailMapper.getAllCnt(requestParam);
|
||||
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.mailList(list)
|
||||
.total(mailMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.valueOf(requestParam.get("page_no").toString()):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
public MailResponse getdetail(Long id){
|
||||
|
||||
// gameDB 조회 및 서비스 로직
|
||||
Mail mail = mailMapper.getMailDetail(id);
|
||||
|
||||
mail.setMailList(mailMapper.getMessage(id));
|
||||
// mail.setItemList(mailMapper.getItem(id));
|
||||
List<Item> itemList = mailMapper.getItem(id);
|
||||
for(Item item : itemList){
|
||||
String itemName = metaDataHandler.getMetaItemNameData(Integer.parseInt(item.getItem()));
|
||||
item.setItemName(metaDataHandler.getTextStringData(itemName));
|
||||
}
|
||||
mail.setItemList(itemList);
|
||||
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.mail(mail)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public MailResponse excelUpload(MultipartFile file){
|
||||
|
||||
List<Mail> list = new ArrayList<>();
|
||||
// 파일 존재하지 않는 경우
|
||||
if (file.isEmpty()) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
List listData = excelUtils.getListData(file, 1, 0);
|
||||
|
||||
// 엑셀 파일내 중복된 데이터 있는지 체크
|
||||
if(excelUtils.hasDuplicates(listData)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATE_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
listData.forEach(
|
||||
item->{
|
||||
Mail mail = new Mail();
|
||||
mail.setGuid(item.toString());
|
||||
list.add(mail);
|
||||
}
|
||||
);
|
||||
|
||||
// 파일을 서버에 저장
|
||||
String fileName = excelUtils.saveExcelFile(file);
|
||||
|
||||
return MailResponse.builder()
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.mailList(list).message(SuccessCode.EXCEL_UPLOAD.getMessage())
|
||||
.fileName(fileName)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public Resource excelDown(String fileName) {
|
||||
Path filePath = Path.of(excelPath+fileName);
|
||||
try {
|
||||
if(fileName.contains("sample")){
|
||||
return resourceLoader.getResource(samplePath + fileName);
|
||||
}
|
||||
Resource resource = new UrlResource(filePath.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 MailResponse postMail(MailRequest mailRequest){
|
||||
mailRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
if(mailRequest.isReserve()){
|
||||
mailRequest.setSendType(Mail.SENDTYPE.RESERVE_SEND);
|
||||
}else{
|
||||
mailRequest.setSendType(Mail.SENDTYPE.DIRECT_SEND);
|
||||
mailRequest.setSendDt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
|
||||
//단일일경우 guid 를 target 설정, 복수이면은 fileName을 target에 설정
|
||||
if(mailRequest.getGuid() != null){
|
||||
if(mailRequest.getUserType().equals(Mail.USERTYPE.GUID) && dynamoDBService.isGuidChecked(mailRequest.getGuid())){
|
||||
log.error("postMail RECEIVETYPE Single Guid Find Fail");
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
String guid = mailRequest.getGuid();
|
||||
// 닉네임이면 guid로 바꾼다
|
||||
if(mailRequest.getUserType().equals(Mail.USERTYPE.NICKNAME)) {
|
||||
// guid = dynamoDBService.getNickNameByGuid(guid);
|
||||
guid = getGuid(guid, Mail.USERTYPE.NICKNAME.name());
|
||||
if(guid == null || mailRequest.getGuid().equals(guid)){
|
||||
log.error("postMail RECEIVETYPE Single Nickname Find Fail");
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNOMODB_CHECK.getMessage() );
|
||||
}
|
||||
}else if(mailRequest.getUserType().equals(Mail.USERTYPE.EMAIL)){
|
||||
guid = getGuid(guid, Mail.USERTYPE.EMAIL.name());
|
||||
if(guid == null || guid.isEmpty()){
|
||||
log.error("postMail RECEIVETYPE Single EMAIL Find Fail");
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.EMAIL_CHECK.getMessage() );
|
||||
}
|
||||
}
|
||||
mailRequest.setReceiveType(Mail.RECEIVETYPE.SINGLE);
|
||||
mailRequest.setTarget(guid);
|
||||
}
|
||||
//엑셀 처리
|
||||
else{
|
||||
mailRequest.setReceiveType(Mail.RECEIVETYPE.MULTIPLE);
|
||||
if(mailRequest.getFileName() == null){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
List<Excel> excelList = excelUtils.getExcelListData(mailRequest.getFileName());
|
||||
for(Excel excel : excelList){
|
||||
switch (excel.getType()) {
|
||||
case "GUID" -> {
|
||||
if (dynamoDBService.isGuidChecked(excel.getUser())) {
|
||||
log.error("postMail Multi Guid({}) Find Fail", excel.getUser());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
}
|
||||
case "NICKNAME" -> {
|
||||
String user = getGuid(excel.getUser(), Mail.USERTYPE.NICKNAME.name());
|
||||
if (user == null || user.isEmpty()) {
|
||||
log.error("postMail Multi Nickname({}) Find Fail", excel.getUser());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNOMODB_CHECK.getMessage());
|
||||
}
|
||||
}
|
||||
case "EMAIL" -> {
|
||||
String user = getGuid(excel.getUser(), Mail.USERTYPE.EMAIL.name());
|
||||
if (user == null || user.isEmpty()) {
|
||||
log.error("postMail Multi Email({}) Find Fail", excel.getUser());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.EMAIL_CHECK.getMessage());
|
||||
}
|
||||
}
|
||||
default ->
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USERTYPE_CHECK_EXCEL.getMessage()); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
}
|
||||
mailRequest.setTarget(mailRequest.getFileName());
|
||||
}
|
||||
|
||||
mailMapper.postMail(mailRequest);
|
||||
|
||||
//log.info("mail_id::"+ mailRequest.getId());
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("mailId",String.valueOf(mailRequest.getId()));
|
||||
|
||||
//아이템 저장
|
||||
if(mailRequest.getItemList()!= null && !mailRequest.getItemList().isEmpty()){
|
||||
mailRequest.getItemList().forEach(
|
||||
item -> {
|
||||
map.put("goodsId",item.getItem());
|
||||
map.put("itemCnt",String.valueOf(item.getItemCnt()));
|
||||
mailMapper.insertItem(map);
|
||||
}
|
||||
);
|
||||
}
|
||||
//자원 저장
|
||||
// if(mailRequest.getResourceList()!= null && mailRequest.getResourceList().size() > 0){
|
||||
// mailRequest.getResourceList().forEach(
|
||||
// item -> {
|
||||
// map.put("goodsId",item.getItem());
|
||||
// map.put("itemCnt",String.valueOf(item.getItemCnt()));
|
||||
// mailMapper.insertItem(map);
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
//메시지 저장
|
||||
if(mailRequest.getMailList()!= null && mailRequest.getMailList().size() > 0){
|
||||
mailRequest.getMailList().forEach(
|
||||
item -> {
|
||||
map.put("title",item.getTitle());
|
||||
map.put("content",item.getContent());
|
||||
map.put("language",item.getLanguage());
|
||||
mailMapper.insertMessage(map);
|
||||
}
|
||||
);
|
||||
}
|
||||
log.info("postMail Insert Mail: {}", mailRequest);
|
||||
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("mail_type",mailRequest.getMailType());
|
||||
jsonObject.put("receiver",mailRequest.getTarget());
|
||||
Mail.SENDTYPE sendType = mailRequest.getSendType();
|
||||
jsonObject.put("send_type",sendType);
|
||||
if(sendType.equals(Mail.SENDTYPE.RESERVE_SEND))
|
||||
jsonObject.put("send_dt",mailRequest.getSendDt());
|
||||
jsonObject.put("mail_list",map);
|
||||
historyService.setLog(HISTORYTYPE.MAIL_ADD, jsonObject);
|
||||
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public MailResponse updateMail(Long id, MailRequest mailRequest) {
|
||||
mailRequest.setId(id);
|
||||
mailRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
mailRequest.setUpdateDt(LocalDateTime.now());
|
||||
|
||||
if (mailRequest.isReserve()) {
|
||||
mailRequest.setSendType(Mail.SENDTYPE.RESERVE_SEND);
|
||||
} else {
|
||||
mailRequest.setSendType(Mail.SENDTYPE.DIRECT_SEND);
|
||||
mailRequest.setSendDt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
//단일일경우 guid 를 target 설정, 복수이면은 fileName을 target에 설정
|
||||
if (mailRequest.getGuid() != null) {
|
||||
String guid = mailRequest.getGuid();
|
||||
// 닉네임이면 guid로 바꾼다
|
||||
if(mailRequest.getUserType().equals(Mail.USERTYPE.NICKNAME)) guid = dynamoDBService.getNickNameByGuid(guid);
|
||||
mailRequest.setReceiveType(Mail.RECEIVETYPE.SINGLE);
|
||||
mailRequest.setTarget(guid);
|
||||
} else {
|
||||
mailRequest.setReceiveType(Mail.RECEIVETYPE.MULTIPLE);
|
||||
|
||||
if (mailRequest.getFileName() == null) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage());
|
||||
}
|
||||
mailRequest.setTarget(mailRequest.getFileName());
|
||||
}
|
||||
|
||||
Long mail_id = mailRequest.getId();
|
||||
Mail before_info = mailMapper.getMailDetail(mail_id);
|
||||
List<Message> before_msg = mailMapper.getMessage(mail_id);
|
||||
List<Item> before_item = mailMapper.getItem(mail_id);
|
||||
|
||||
log.info("updateMail Update Before MailInfo: {}, Message: {}, Item: {}", before_info, before_msg, before_item);
|
||||
|
||||
mailMapper.updateMail(mailRequest);
|
||||
|
||||
// 스케줄에서 제거
|
||||
scheduleService.closeTask("mail-" + mail_id.toString());
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("mailId", String.valueOf(mailRequest.getId()));
|
||||
|
||||
// item 테이블 데이터 삭제 처리 by mail_id
|
||||
mailMapper.deleteItem(map);
|
||||
|
||||
// 아이템 업데이트
|
||||
if (mailRequest.getItemList() != null && !mailRequest.getItemList().isEmpty()) {
|
||||
mailRequest.getItemList().forEach(item -> {
|
||||
map.put("goodsId", item.getItem());
|
||||
map.put("itemCnt", String.valueOf(item.getItemCnt()));
|
||||
|
||||
mailMapper.insertItem(map);
|
||||
});
|
||||
}
|
||||
|
||||
// message 테이블 데이터 삭제 처리 by mail_id
|
||||
mailMapper.deleteMessage(map);
|
||||
|
||||
// 메일 업데이트
|
||||
if (mailRequest.getMailList() != null && !mailRequest.getMailList().isEmpty()) {
|
||||
mailRequest.getMailList().forEach(item -> {
|
||||
map.put("title", item.getTitle());
|
||||
map.put("content", item.getContent());
|
||||
map.put("language", item.getLanguage());
|
||||
|
||||
mailMapper.insertMessage(map);
|
||||
});
|
||||
}
|
||||
log.info("updateMail Update After Mail: {}", mailRequest);
|
||||
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("before_info",before_info.toString());
|
||||
jsonObject.put("before_msg",before_msg.toString());
|
||||
jsonObject.put("before_item",before_item.toString());
|
||||
jsonObject.put("mail_type",mailRequest.getMailType());
|
||||
jsonObject.put("receiver",mailRequest.getTarget());
|
||||
Mail.SENDTYPE sendType = mailRequest.getSendType();
|
||||
jsonObject.put("send_type",sendType);
|
||||
if(sendType.equals(Mail.SENDTYPE.RESERVE_SEND))
|
||||
jsonObject.put("send_dt",mailRequest.getSendDt());
|
||||
historyService.setLog(HISTORYTYPE.MAIL_UPDATE, jsonObject);
|
||||
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public MailResponse deleteMail(MailRequest mailRequest){
|
||||
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 MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.message(SuccessCode.DELETE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<Mail> getScheduleMailList(){
|
||||
return mailMapper.getSchesuleMailList();
|
||||
}
|
||||
|
||||
public List<Message> getMailMessageList(Long id){
|
||||
return mailMapper.getMessage(id);
|
||||
}
|
||||
|
||||
public List<Item> getMailItemList(Long id){
|
||||
return mailMapper.getItem(id);
|
||||
}
|
||||
|
||||
public void updateMailStatus(Long id, Mail.SENDSTATUS status){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("status", status.toString());
|
||||
mailMapper.updateCompleteMail(map);
|
||||
}
|
||||
|
||||
//메타 아이템
|
||||
public MailResponse getMetaItem(String metaId){
|
||||
long id = Long.parseLong(metaId);
|
||||
String item = metaDataHandler.getMetaItemNameData((int) id);
|
||||
boolean isItem = (item != null && !item.isEmpty());
|
||||
if(isItem) {
|
||||
Item item_info = new Item();
|
||||
item_info.setItem(metaId);
|
||||
item_info.setItemName(metaDataHandler.getTextStringData(item));
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.message(SuccessCode.ITEM_EXIST.getMessage())
|
||||
.itemInfo(item_info)
|
||||
.build())
|
||||
.build();
|
||||
}else
|
||||
return MailResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(CommonCode.ERROR.getResult())
|
||||
.resultData(MailResponse.ResultData.builder()
|
||||
.message(ErrorCode.NOT_ITEM.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public String getGuid(String target, String type){
|
||||
if(Mail.USERTYPE.EMAIL.name().equals(type)){
|
||||
WalletUser user = walletUserMapper.getUser(target);
|
||||
return dynamoDBService.getAccountIdByGuid(user.getAccount_id());
|
||||
}else if(Mail.USERTYPE.NICKNAME.name().equals(type)){
|
||||
return dynamoDBService.getNickNameByGuid(target);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setScheduleLog(HISTORYTYPE type, String message){
|
||||
//스케줄 로그 기록
|
||||
historyService.setScheduleLog(type, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.NoticeMapper;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.entity.InGame;
|
||||
import com.caliverse.admin.domain.entity.Message;
|
||||
import com.caliverse.admin.domain.request.NoticeRequest;
|
||||
import com.caliverse.admin.domain.response.NoticeResponse;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.scheduler.ScheduleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeService {
|
||||
|
||||
private final NoticeMapper noticeMapper;
|
||||
private final HistoryMapper historyMapper;
|
||||
private final ScheduleService scheduleService;
|
||||
private final HistoryService historyService;
|
||||
|
||||
public NoticeResponse getNoticeList(){
|
||||
|
||||
List<InGame> noticeList = noticeMapper.getNoticeList();
|
||||
|
||||
return NoticeResponse.builder()
|
||||
.resultData(NoticeResponse.ResultData.builder()
|
||||
.list(noticeList).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
public NoticeResponse getNoticeDetail(Long id){
|
||||
|
||||
NoticeResponse.ResultData resultData = null;
|
||||
log.info("getNoticeDetail id::"+id);
|
||||
|
||||
InGame inGame = noticeMapper.getNoticeDetail(id);
|
||||
|
||||
if(inGame != null){
|
||||
List<Message> noticeMessage = noticeMapper.getMessage(inGame.getId());
|
||||
|
||||
resultData = NoticeResponse.ResultData.builder()
|
||||
.gameMessages(noticeMessage)
|
||||
.inGame(inGame)
|
||||
.build();
|
||||
}else{
|
||||
// 조회된 데이터가 없습니다.
|
||||
return NoticeResponse.builder()
|
||||
.resultData(NoticeResponse.ResultData.builder().message(SuccessCode.NULL_DATA.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
return NoticeResponse.builder()
|
||||
.resultData(resultData)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
//인게임 메시지 등록
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public NoticeResponse postInGameMessage(NoticeRequest noticeRequest){
|
||||
// 등록자는 메일로 넣어주자
|
||||
noticeRequest.setCreateBy(CommonUtils.getAdmin().getId());
|
||||
// notice 테이블 insert
|
||||
int i = noticeMapper.postNotice(noticeRequest);
|
||||
if(i > 0){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
noticeRequest.getGameMessages().stream()
|
||||
.filter(item -> !item.getContent().isEmpty())
|
||||
.map(item -> {
|
||||
map.put("id", noticeRequest.getId());
|
||||
map.put("language", item.getLanguage());
|
||||
map.put("content", item.getContent());
|
||||
//메시지 테이블 insert
|
||||
noticeMapper.insertMessage(map);
|
||||
return item;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
log.info("postInGameMessage notice: {}", noticeRequest);
|
||||
|
||||
//로그 기록
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message_type",noticeRequest.getMessageType());
|
||||
jsonObject.put("repeat_type",noticeRequest.getRepeatType());
|
||||
jsonObject.put("repeat_cnt",noticeRequest.getRepeatCnt());
|
||||
jsonObject.put("repeat_dt",noticeRequest.getRepeatDt());
|
||||
jsonObject.put("send_dt",noticeRequest.getSendDt());
|
||||
jsonObject.put("end_dt",noticeRequest.getEndDt());
|
||||
jsonObject.put("message",noticeRequest.getGameMessages().toString());
|
||||
historyService.setLog(HISTORYTYPE.NOTICE_ADD, jsonObject);
|
||||
|
||||
return NoticeResponse.builder()
|
||||
.resultData(NoticeResponse.ResultData.builder().message(SuccessCode.REGISTRATION.getMessage()).build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public NoticeResponse updateInGameMessage(Long id, NoticeRequest noticeRequest){
|
||||
noticeRequest.setId(id);
|
||||
noticeRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
int i = noticeMapper.updateNotice(noticeRequest);
|
||||
// 스케줄에서 기존 등록 제거
|
||||
scheduleService.closeTask(noticeRequest.getId().toString());
|
||||
if(i > 0){
|
||||
InGame before_notice = noticeMapper.getNoticeDetail(noticeRequest.getId());
|
||||
log.info("updateInGameMessage Before notice: {}", before_notice);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
//선 삭제 후 insert
|
||||
noticeMapper.deleteMessage(noticeRequest.getId());
|
||||
|
||||
for (Message item : noticeRequest.getGameMessages()) {
|
||||
String content = item.getContent();
|
||||
|
||||
// content가 null이거나 빈 문자열인 경우 루프 건너뛰기
|
||||
if (content == null || content.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
map.put("id", noticeRequest.getId());
|
||||
map.put("language", item.getLanguage());
|
||||
map.put("content", content);
|
||||
// 메시지 테이블 insert
|
||||
noticeMapper.insertMessage(map);
|
||||
}
|
||||
}
|
||||
log.info("updateInGameMessage After notice: {}", noticeRequest);
|
||||
return NoticeResponse.builder()
|
||||
.resultData(NoticeResponse.ResultData.builder().message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public NoticeResponse deleteInGameMessage(NoticeRequest noticeRequest){
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
noticeRequest.getList().forEach(
|
||||
item->{
|
||||
|
||||
//사용자 로그 기록 (인게임 메시지 삭제)
|
||||
String message = noticeMapper.getMessageById(item.getMessageId());
|
||||
|
||||
noticeMapper.deleteNotice(item.getMessageId());
|
||||
|
||||
// 스케줄에서 제거
|
||||
scheduleService.closeTask("notice-" + item.getMessageId());
|
||||
|
||||
log.info("deleteInGameMessage notice: {}", item);
|
||||
|
||||
//로그 기록
|
||||
map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
map.put("name", CommonUtils.getAdmin().getName());
|
||||
map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
map.put("type", HISTORYTYPE.NOTICE_DELETE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message",message);
|
||||
map.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(map);
|
||||
}
|
||||
);
|
||||
log.info("deleteInGameMessage notice: {}", noticeRequest);
|
||||
return NoticeResponse.builder()
|
||||
.resultData(NoticeResponse.ResultData.builder().message(SuccessCode.DELETE.getMessage()).build())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<InGame> getScheduleNoticeList(){
|
||||
return noticeMapper.getSchesuleNoticeList();
|
||||
}
|
||||
|
||||
public List<Message> getNoticeMessageList(Long id){
|
||||
return noticeMapper.getMessage(id);
|
||||
}
|
||||
|
||||
public void updateNoticeStatus(Long id, InGame.SENDSTATUS status){
|
||||
HashMap map = new HashMap();
|
||||
map.put("id", id);
|
||||
map.put("status", status.toString());
|
||||
noticeMapper.updateStatusNotice(map);
|
||||
}
|
||||
|
||||
public void updateNoticeCount(Long id){
|
||||
noticeMapper.updateCountNotice(id);
|
||||
}
|
||||
|
||||
public void setScheduleLog(HISTORYTYPE type, String message){
|
||||
//스케줄 로그 기록
|
||||
Map<String, Object> logMap = new HashMap<>();
|
||||
logMap.put("adminId", 1);
|
||||
logMap.put("name", "schedule");
|
||||
logMap.put("mail", "schedule");
|
||||
logMap.put("type", type);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message",message);
|
||||
logMap.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(logMap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectAttributesRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectAttributesResponse;
|
||||
import software.amazon.awssdk.services.s3.model.S3Exception;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ConditionalOnProperty(name = "amazon.s3.enabled", havingValue = "true")
|
||||
@RequiredArgsConstructor
|
||||
public class S3Service {
|
||||
@Autowired(required = false)
|
||||
private final S3Client s3Client;
|
||||
|
||||
@Value("${amazon.s3.bucket-name}")
|
||||
private String bucketName;
|
||||
|
||||
public Optional<GetObjectAttributesResponse> getObjectMetadata(String key) {
|
||||
try {
|
||||
GetObjectAttributesRequest request = GetObjectAttributesRequest.builder()
|
||||
.bucket(bucketName)
|
||||
.key(key)
|
||||
.build();
|
||||
|
||||
GetObjectAttributesResponse response = s3Client.getObjectAttributes(request);
|
||||
return Optional.of(response);
|
||||
} catch (S3Exception e) {
|
||||
log.error("Error retrieving object metadata: {}", e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
|
||||
import com.caliverse.admin.domain.RabbitMq.MessageHandlerService;
|
||||
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.caliverse.admin.redis.service.RedisUserInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserGameSessionService {
|
||||
|
||||
private final RedisUserInfoService redisUserInfoService;
|
||||
//private final RabbitMqService rabbitMqService;
|
||||
|
||||
private final MessageHandlerService messageHandlerService;
|
||||
|
||||
|
||||
public UserGameSessionService(RedisUserInfoService redisUserInfoService
|
||||
, MessageHandlerService messageHandlerService
|
||||
) {
|
||||
this.redisUserInfoService = redisUserInfoService;
|
||||
this.messageHandlerService = messageHandlerService;
|
||||
}
|
||||
|
||||
|
||||
public void kickUserSession(String userGuid){
|
||||
|
||||
var loginSession = redisUserInfoService.getUserLoginSessionInfo(userGuid);
|
||||
|
||||
//게임이 접속중 이면 kick 하고 2초 대기
|
||||
if(null != loginSession ){
|
||||
var serverName = loginSession.getCurrentServer();
|
||||
messageHandlerService.sendUserKickMessage(userGuid, serverName);
|
||||
|
||||
//여기서 2초 정도 대기(게임 메모리 정리를 위해)
|
||||
try{
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
log.error("InterruptedException message: {}, serverName: {}, e.Message : {}", userGuid, serverName, e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.EXCEPTION_INVALID_PROTOCOL_BUFFER_EXCEPTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogUserItemHistoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class UserItemService {
|
||||
|
||||
private final BusinessLogUserItemHistoryService historyService;
|
||||
|
||||
public UserItemService(BusinessLogUserItemHistoryService hstoryService){
|
||||
this.historyService = hstoryService;
|
||||
}
|
||||
|
||||
|
||||
public String getUserItemHistory(Map<String, String> requestParams){
|
||||
|
||||
//페이징 처리
|
||||
//requestParams =
|
||||
CommonUtils.pageSetting(requestParams);
|
||||
|
||||
//몽고 DB 에서 호출 할수 있도록 처리
|
||||
String startDate = requestParams.get(AdminConstants.INDICATORS_KEY_START_DATE);
|
||||
String endDate = requestParams.get(AdminConstants.INDICATORS_KEY_END_DATE);
|
||||
String itemId = requestParams.get(AdminConstants.INDICATORS_KEY_ITEM_ID);
|
||||
|
||||
//UserItemService.class 바꿔야 한다.
|
||||
historyService.loadBusinessLogData(startDate, endDate, itemId, UserItemService.class);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.entity.REPORTTYPE;
|
||||
import com.caliverse.admin.domain.entity.SEARCHTYPE;
|
||||
import com.caliverse.admin.domain.entity.STATUS;
|
||||
import com.caliverse.admin.domain.request.UserReportRequest;
|
||||
import com.caliverse.admin.domain.response.UserReportResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserReportService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UserReportService.class);
|
||||
|
||||
private final DynamoDBService dynamoDBService;
|
||||
public UserReportResponse totalCnt(Map<String,String> requestParam){
|
||||
|
||||
int resolved = 0;
|
||||
int unResolved = 0;
|
||||
List<UserReportResponse.Report> userReportList = new ArrayList<>();
|
||||
|
||||
userReportList = dynamoDBService.getUserReportList(requestParam);
|
||||
Map<Boolean, Long> result = userReportList.stream()
|
||||
.collect(Collectors.partitioningBy(
|
||||
val -> val.getState() == STATUS.RESOLVED,
|
||||
Collectors.counting()
|
||||
));
|
||||
|
||||
resolved = result.get(true).intValue();
|
||||
unResolved = result.get(false).intValue();
|
||||
|
||||
int totalCnt = userReportList.size();
|
||||
return UserReportResponse.builder()
|
||||
.resultData(UserReportResponse.ResultData.builder()
|
||||
.totalCnt(totalCnt)
|
||||
.resolve(resolved)
|
||||
.unresolve(unResolved)
|
||||
.rate(totalCnt == 0 ? "0%" : Math.round(resolved * 100.0 / totalCnt) + "%")
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public UserReportResponse list(Map<String,String> requestParam){
|
||||
List<UserReportResponse.Report> userReportList = new ArrayList<>();
|
||||
userReportList = dynamoDBService.getUserReportList(requestParam);
|
||||
|
||||
String reportTypeFilter = CommonUtils.objectToString(requestParam.get("report_type"));
|
||||
String statusFilter = CommonUtils.objectToString(requestParam.get("status"));
|
||||
String searchType = CommonUtils.objectToString(requestParam.get("search_type"));
|
||||
String searchKey = CommonUtils.objectToString(requestParam.get("search_key"));
|
||||
String orderby = CommonUtils.objectToString(requestParam.get("orderby"));
|
||||
//페이징 처리
|
||||
int page = Integer.parseInt(requestParam.get("page_no"));
|
||||
int pageSize = Integer.parseInt(requestParam.get("page_size"));
|
||||
|
||||
if (!reportTypeFilter.isEmpty() && !reportTypeFilter.equals("ALL")) {
|
||||
userReportList = userReportList.stream()
|
||||
.filter(report -> report.getReportType() == REPORTTYPE.valueOf(reportTypeFilter))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (!statusFilter.isEmpty() &&!statusFilter.equals("ALL")) {
|
||||
userReportList = userReportList.stream()
|
||||
.filter(report -> report.getState() == STATUS.valueOf(statusFilter))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (!searchType.isEmpty() && !searchKey.isEmpty()) {
|
||||
userReportList = userReportList.stream()
|
||||
.filter(report -> {
|
||||
if (searchType.equals(SEARCHTYPE.GUID.name())) {
|
||||
return report.getReporterGuid().equals(searchKey);
|
||||
} else if (searchType.equals(SEARCHTYPE.EMAIL.name())) {
|
||||
return report.getManagerEmail().equals(searchKey);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.sorted(Comparator.comparing(UserReportResponse.Report::getCreateTime))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if(!orderby.isEmpty()){
|
||||
if(orderby.equalsIgnoreCase("desc")){
|
||||
userReportList = userReportList.stream()
|
||||
.sorted(Comparator.comparing(UserReportResponse.Report::getCreateTime).reversed())
|
||||
.collect(Collectors.toList());
|
||||
}else{
|
||||
userReportList = userReportList.stream()
|
||||
.sorted(Comparator.comparing(UserReportResponse.Report::getCreateTime))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
int start = (page - 1) * pageSize;
|
||||
int end = Math.min(start + pageSize, userReportList.size());
|
||||
|
||||
userReportList = userReportList.subList(start, end);
|
||||
|
||||
// row_num 추가
|
||||
|
||||
if (orderby.equalsIgnoreCase("desc")){
|
||||
for (int i = 0; i < userReportList.size(); i++) {
|
||||
userReportList.get(i).setRowNum(i + 1);
|
||||
}
|
||||
}else{
|
||||
int rowNum = userReportList.size();
|
||||
for (int i = 0; i < userReportList.size(); i++) {
|
||||
userReportList.get(i).setRowNum(rowNum--);
|
||||
}
|
||||
}
|
||||
return UserReportResponse.builder()
|
||||
.resultData(UserReportResponse.ResultData.builder()
|
||||
.list(userReportList)
|
||||
.pageNo(page)
|
||||
.total(userReportList.size())
|
||||
.totalAll(userReportList.size())
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public UserReportResponse reportDetail(Map<String,String> requestParam){
|
||||
|
||||
UserReportResponse.ResultData userReportDetail = dynamoDBService.getUserReportDetail(requestParam);
|
||||
|
||||
return UserReportResponse.builder()
|
||||
.resultData(userReportDetail)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public UserReportResponse replyDetail(Map<String,String> requestParam){
|
||||
|
||||
UserReportResponse.ResultData userReportDetail = dynamoDBService.getUserReplyDetail(requestParam);
|
||||
|
||||
return UserReportResponse.builder()
|
||||
.resultData(userReportDetail)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
//답변
|
||||
public UserReportResponse reportReply(UserReportRequest userReportRequest){
|
||||
|
||||
userReportRequest.setManagerEmail(CommonUtils.getAdmin().getEmail());
|
||||
dynamoDBService.reportReply(userReportRequest);
|
||||
|
||||
//신고 내역 상태 및 해결일자 변경
|
||||
dynamoDBService.changeReportStatus(userReportRequest);
|
||||
|
||||
|
||||
return UserReportResponse.builder()
|
||||
.resultData(UserReportResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public void dummy(Map<String, String> map){
|
||||
dynamoDBService.dummy(map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.caliverse.admin.domain.entity.FriendRequest;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.request.MailRequest;
|
||||
import com.caliverse.admin.redis.service.RedisUserInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.request.UsersRequest;
|
||||
import com.caliverse.admin.domain.response.UsersResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class UsersService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UsersService.class);
|
||||
|
||||
private final DynamoDBService dynamoDBService;
|
||||
private final HistoryService historyService;
|
||||
private final UserGameSessionService userGameSessionService;
|
||||
private final RedisUserInfoService redisUserInfoService;
|
||||
|
||||
//metadataHandler 어떻게 가져와야 되는가
|
||||
@Autowired
|
||||
private MetaDataHandler metaDataHandler;
|
||||
|
||||
// 닉네임 변경
|
||||
public UsersResponse changeNickname(UsersRequest usersRequest){
|
||||
String guid = usersRequest.getGuid();
|
||||
String nickname = usersRequest.getNickname();
|
||||
String newNickname = usersRequest.getNewNickname();
|
||||
|
||||
//신규 닉네임 유효성 체크
|
||||
ErrorCode check = CommonUtils.isValidNickname(newNickname);
|
||||
if(!check.equals(ErrorCode.SUCCESS)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), check.getMessage() );
|
||||
}
|
||||
|
||||
Map<String, String> serachNickname = dynamoDBService.getUsersByName(newNickname);
|
||||
if(serachNickname != null){
|
||||
//변경 닉네임이 존재합니다. 다시 시도해주세요.
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NICKNAME_EXIT_ERROR.getMessage() );
|
||||
}else{
|
||||
dynamoDBService.updateNickname(guid,nickname,newNickname);
|
||||
}
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
// GM 권한 변경
|
||||
public UsersResponse changeAdminLevel(UsersRequest usersRequest){
|
||||
String guid = usersRequest.getGuid();
|
||||
String type = usersRequest.getAdminLevel();
|
||||
|
||||
dynamoDBService.updateAdminLevel(guid, type);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
// 유정 정보 조회 닉네임,GUID,Account ID
|
||||
public UsersResponse findUsers(Map requestParam){
|
||||
|
||||
String searchType = requestParam.get("search_type").toString();
|
||||
String searchKey = requestParam.get("search_key").toString();
|
||||
|
||||
Map<String,String> res = dynamoDBService.findUsersBykey(searchType, searchKey);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.result(res)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
public UsersResponse getBasicInfo(String guid){
|
||||
|
||||
String account_id = dynamoDBService.getGuidByAccountId(guid);
|
||||
//userInfo
|
||||
Map<String, Object> userInfo = dynamoDBService.getAccountInfo(account_id);
|
||||
|
||||
// charInfo
|
||||
Map<String, Object> charInfo = dynamoDBService.getCharInfo(guid);
|
||||
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.charInfo((UsersResponse.CharInfo) charInfo.get("charInfo"))
|
||||
.userInfo((UsersResponse.UserInfo) userInfo.get("userInfo"))
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse getAvatarInfo(String guid){
|
||||
|
||||
//avatarInfo
|
||||
Map<String, Object> charInfo = dynamoDBService.getAvatarInfo(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.avatarInfo((UsersResponse.AvatarInfo) charInfo.get("avatarInfo"))
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse getClothInfo(String guid){
|
||||
|
||||
//clothInfo
|
||||
// Map<String, Object> charInfo = dynamoDBService.getClothInfo(guid);
|
||||
Map<String, Object> charInfo = dynamoDBService.getCloth(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.clothInfo((UsersResponse.ClothInfo) charInfo.get("clothInfo"))
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse getToolSlotInfo(String guid){
|
||||
|
||||
// toolslotInfo
|
||||
// List<UsersResponse.SlotInfo> toolSlot = dynamoDBService.getToolSlot(guid);
|
||||
Map<String, Object> toolSlot = dynamoDBService.getTools(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.slotInfoList((UsersResponse.SlotInfo) toolSlot.get("toolSlotInfo"))
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
public UsersResponse getInventoryInfo(String guid){
|
||||
|
||||
// List<List<UsersResponse.Inventory>> inventoryList = new ArrayList<>();
|
||||
// List<List<String>> item = dynamoDBService.getInvenItems(guid);
|
||||
// if(item != null){
|
||||
// for (List<String> list : item){
|
||||
// List<UsersResponse.Inventory> innerList = new ArrayList<>();
|
||||
// for (String key : list){
|
||||
// Map<String, Object> resItem = dynamoDBService.getItemTable(key);
|
||||
//
|
||||
// //객체를 생성하고 값을 설정
|
||||
// UsersResponse.Inventory inventory = new UsersResponse.Inventory();
|
||||
//
|
||||
// Object itemId = resItem.get("ItemId");
|
||||
// String itemIdString = CommonUtils.objectToString(itemId);
|
||||
// Integer itemIdInteger = CommonUtils.objectToInteger(itemId);
|
||||
//
|
||||
//
|
||||
// inventory.setCount(Integer.valueOf(CommonUtils.objectToString(resItem.get("Count"))));
|
||||
// inventory.setItemId(itemIdString);
|
||||
// inventory.setItemName(metaDataHandler.getMetaItemData(itemIdInteger).getName());
|
||||
// innerList.add(inventory);
|
||||
// }
|
||||
// inventoryList.add(innerList);
|
||||
// }
|
||||
// }
|
||||
UsersResponse.InventoryInfo inventoryInfo = dynamoDBService.getInvenItems(guid);
|
||||
logger.info("getInventoryInfo Inventory Items: {}", inventoryInfo);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.inventoryInfo(inventoryInfo)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse deleteInventoryItem(Map<String, String> requestParams){
|
||||
String guid = requestParams.get("guid");
|
||||
String item_guid = requestParams.get("item_guid");
|
||||
int current_cnt = Integer.parseInt(requestParams.get("current_cnt"));
|
||||
int update_cnt = Integer.parseInt(requestParams.get("cnt"));
|
||||
|
||||
userGameSessionService.kickUserSession(guid);
|
||||
if(update_cnt >= current_cnt){
|
||||
String attrib = dynamoDBService.deleteItem(guid, item_guid);
|
||||
if(!attrib.isEmpty()){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data",attrib);
|
||||
historyService.setLog(HISTORYTYPE.INVENTORY_ITEM_DELETE, jsonObject);
|
||||
}
|
||||
return UsersResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.DELETE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}else{
|
||||
int cnt = current_cnt - update_cnt;
|
||||
JSONObject json = dynamoDBService.updateItem(guid, item_guid, cnt);
|
||||
if(!json.isEmpty()){
|
||||
historyService.setLog(HISTORYTYPE.INVENTORY_ITEM_UPDATE, json);
|
||||
}
|
||||
return UsersResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public UsersResponse getMail(String guid, String type){
|
||||
|
||||
List<UsersResponse.Mail> mailList = dynamoDBService.getMail(guid, type);;
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.mailList(mailList)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse deleteMail(Map<String, String> requestParams){
|
||||
String guid = requestParams.get("guid");
|
||||
String mail_guid = requestParams.get("mail_guid");
|
||||
String type = requestParams.get("type");
|
||||
|
||||
userGameSessionService.kickUserSession(guid);
|
||||
String attrib = dynamoDBService.deleteMail(type, guid, mail_guid);
|
||||
if(!attrib.isEmpty()){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data",attrib);
|
||||
historyService.setLog(HISTORYTYPE.USER_MAIL_DELETE, jsonObject);
|
||||
}
|
||||
|
||||
return UsersResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.DELETE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public UsersResponse deleteMailItem(MailRequest.DeleteMailItem deleteMailItem){
|
||||
userGameSessionService.kickUserSession(deleteMailItem.getGuid());
|
||||
JSONObject json = dynamoDBService.updateMailItem(deleteMailItem.getType(), deleteMailItem.getGuid(),
|
||||
deleteMailItem.getMailGuid(), deleteMailItem.getItemId(), deleteMailItem.getParrentCount(), deleteMailItem.getCount());
|
||||
if(!json.isEmpty()){
|
||||
historyService.setLog(HISTORYTYPE.MAIL_ITEM_UPDATE, json);
|
||||
}
|
||||
return UsersResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(UsersResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public UsersResponse getMyhome(String guid){
|
||||
|
||||
UsersResponse.Myhome myhome = dynamoDBService.getMyhome(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.myhomeInfo(myhome)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse getFriendList(String guid){
|
||||
|
||||
List<UsersResponse.Friend> friendList = dynamoDBService.getFriendList(guid);
|
||||
List<UsersResponse.Friend> friendBlockList = dynamoDBService.getUserBlockList(guid);
|
||||
List<UsersResponse.Friend> friendSendList = new ArrayList<>();
|
||||
List<UsersResponse.Friend> friendReceiveList = new ArrayList<>();
|
||||
|
||||
List<FriendRequest> sendRequestList = redisUserInfoService.getFriendRequestInfo("send", guid);
|
||||
List<FriendRequest> receiveRequestList = redisUserInfoService.getFriendRequestInfo("receive", guid);
|
||||
AtomicInteger idx = new AtomicInteger(1);
|
||||
for(FriendRequest friendReq : sendRequestList){
|
||||
UsersResponse.Friend friend = new UsersResponse.Friend();
|
||||
friend.setRowNum(idx.getAndIncrement());
|
||||
String receive_guid = friendReq.getReceiverGuid();
|
||||
friend.setFriendGuid(receive_guid);
|
||||
friend.setFriendName(dynamoDBService.getGuidByName(receive_guid));
|
||||
friend.setReceiveDt(friendReq.getRequestTime());
|
||||
friend.setLanguage(dynamoDBService.getUserLanguage(receive_guid));
|
||||
|
||||
friendSendList.add(friend);
|
||||
}
|
||||
idx = new AtomicInteger(1);
|
||||
for(FriendRequest friendReq : receiveRequestList){
|
||||
UsersResponse.Friend friend = new UsersResponse.Friend();
|
||||
friend.setRowNum(idx.getAndIncrement());
|
||||
String send_guid = friendReq.getSenderGuid();
|
||||
friend.setFriendGuid(send_guid);
|
||||
friend.setFriendName(dynamoDBService.getGuidByName(send_guid));
|
||||
friend.setReceiveDt(friendReq.getRequestTime());
|
||||
friend.setLanguage(dynamoDBService.getUserLanguage(send_guid));
|
||||
|
||||
friendReceiveList.add(friend);
|
||||
}
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.friendList(friendList)
|
||||
.friendSendList(friendSendList)
|
||||
.friendReceiveList(friendReceiveList)
|
||||
.friendBlockList(friendBlockList)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public UsersResponse getTattoo(String guid){
|
||||
List<UsersResponse.Tattoo> resTatto = dynamoDBService.getTattoo(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.tattooList(resTatto)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public UsersResponse getQuest(String guid){
|
||||
// UsersResponse.Quest quest = new UsersResponse.Quest();
|
||||
//
|
||||
// List<UsersResponse.Quest> questListQuest = new ArrayList<>();
|
||||
//
|
||||
// Map<String, List<Map<String, Object>>> resMap= dynamoDBService.getQuest(guid);
|
||||
//
|
||||
// //List<Map<String, Object>> endList = resMap.get("EndList");
|
||||
// List<Map<String, Object>> questList = resMap.get("QuestList");
|
||||
//
|
||||
// int index = 1;
|
||||
// if(questList != null){
|
||||
// for (Map<String,Object> val : questList){
|
||||
// if(val != null){
|
||||
// quest = new UsersResponse.Quest();
|
||||
// quest.setQuestId(Integer.valueOf(CommonUtils.objectToString(val.get("QuestId"))));
|
||||
// quest.setStatus(CommonUtils.objectToString(val.get("IsComplete")));
|
||||
// quest.setRowNum((long)index);
|
||||
// questListQuest.add(quest);
|
||||
// index++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
List<UsersResponse.QuestInfo> questList = dynamoDBService.getQuest(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.questList(questList)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
/*public UsersResponse getClaim(String guid){
|
||||
|
||||
List<UsersResponse.Guid> tattoo = dynamoDBService.getTattoo(guid);
|
||||
|
||||
return UsersResponse.builder()
|
||||
.resultData(
|
||||
UsersResponse.ResultData.builder()
|
||||
.tattooList(tattoo)
|
||||
.build()
|
||||
)
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.entity.web3.ResponseErrorCode;
|
||||
import com.caliverse.admin.domain.response.Web3Response;
|
||||
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.caliverse.admin.global.configuration.RestConfig;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class Web3Service {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final RestConfig restConfig;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RetryTemplate retryTemplate;
|
||||
|
||||
public <T> Web3Response<T> get(String endpoint, Map<String, String> params, Class<T> responseType){
|
||||
String urlParams = addQueryParams(endpoint, params);
|
||||
return callWeb3Api(urlParams, HttpMethod.GET, null, responseType);
|
||||
}
|
||||
|
||||
public <T> Web3Response<T> post(String endpoint, Object request, Class<T> responseType){
|
||||
return callWeb3Api(endpoint, HttpMethod.POST, request, responseType);
|
||||
}
|
||||
|
||||
public <T> Web3Response<T> callWeb3Api(String endpoint, HttpMethod method, Object requestBody, Class<T> responseType){
|
||||
try{
|
||||
return retryTemplate.execute(context -> {
|
||||
try{
|
||||
String url = UriComponentsBuilder.fromHttpUrl(restConfig.getUrl() + endpoint).build().toUriString();
|
||||
log.info("callWeb3Api Call URL: {}, Param: {}, body: {}", restConfig.getUrl(), endpoint, requestBody);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
HttpEntity<?> entity = requestBody != null ?
|
||||
new HttpEntity<>(requestBody, headers) :
|
||||
new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<JsonNode> response = restTemplate.exchange(url, method, entity, JsonNode.class);
|
||||
|
||||
log.info("callWeb3Api Call response: {}", response);
|
||||
Web3Response<T> web3Response = parseResponse(response.getBody(), responseType);
|
||||
|
||||
if(!web3Response.isSuccess() && isRetryableError(web3Response.getCode())){
|
||||
throw new RestApiException(
|
||||
CommonCode.ERROR.getHttpStatus(),
|
||||
"Retriable error: " + web3Response.getCode()
|
||||
);
|
||||
}
|
||||
|
||||
return web3Response;
|
||||
}catch (Exception e) {
|
||||
log.warn("API call failed, retry {} of {}: {}",
|
||||
context.getRetryCount() + 1, restConfig.getMaxRetry(), e.getMessage());
|
||||
|
||||
// RestApiException이 아닌 경우 변환
|
||||
if (!(e instanceof RestApiException)) {
|
||||
throw new RestApiException(
|
||||
CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.ERROR_API_CALL.getMessage()
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}, context -> {
|
||||
log.error("All retry attempts failed for endpoint: {}", endpoint);
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.ERROR_API_CALL.getMessage());
|
||||
});
|
||||
|
||||
}catch(Exception e){
|
||||
log.error("Web3 API Call failed: endpoint={}, method={}", endpoint, method, e);
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_API_CALL.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private <T> Web3Response<T> parseResponse(JsonNode root, Class<T> responseType){
|
||||
try {
|
||||
Web3Response<T> web3Response = new Web3Response<>();
|
||||
boolean success = root.has("success") && root.get("success").asBoolean();
|
||||
web3Response.setSuccess(success);
|
||||
|
||||
if (root.has("code")) {
|
||||
web3Response.setCode(root.get("code").asText());
|
||||
}
|
||||
|
||||
if (success && root.has("data")) {
|
||||
JsonNode dataNode = root.get("data");
|
||||
if (!dataNode.isNull()) {
|
||||
T data = objectMapper.treeToValue(dataNode, responseType);
|
||||
web3Response.setData(data);
|
||||
}
|
||||
}
|
||||
log.info("parseResponse Set response Code: {}, Data: {}", web3Response.getCode(), web3Response.getData());
|
||||
|
||||
return web3Response;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("API Response Failed to parse response", e);
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_API_CALL.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String addQueryParams(String endpoint, Map<String, String> queryParams) {
|
||||
if (queryParams == null || queryParams.isEmpty()) {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath(endpoint);
|
||||
queryParams.forEach(builder::queryParam);
|
||||
return builder.build().toString();
|
||||
}
|
||||
|
||||
private boolean isRetryableError(String errorCode) {
|
||||
ResponseErrorCode responseErrorCode = ResponseErrorCode.fromCode(errorCode).get();
|
||||
// 재시도할 에러 코드 정의
|
||||
return Arrays.asList(
|
||||
ResponseErrorCode.RET_PWRH_001
|
||||
).contains(responseErrorCode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.HistoryMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.WhiteListMapper;
|
||||
import com.caliverse.admin.domain.entity.Admin;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.entity.WhiteList;
|
||||
import com.caliverse.admin.domain.request.WhiteListRequest;
|
||||
import com.caliverse.admin.domain.response.WhiteListResponse;
|
||||
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.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.common.utils.ExcelUtils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WhiteListService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WhiteListService.class);
|
||||
private final ExcelUtils excelUtils;
|
||||
private final WhiteListMapper whiteListMapper;
|
||||
private final HistoryMapper historyMapper;
|
||||
private final DynamoDBService dynamoDBService;
|
||||
public WhiteListResponse getWhiteList(Map<String, String> requestParams){
|
||||
|
||||
List<WhiteList> whiteList = whiteListMapper.getWhiteList();
|
||||
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.list(whiteList).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
public WhiteListResponse excelUpload(MultipartFile file){
|
||||
|
||||
List<WhiteList> list = new ArrayList<>();
|
||||
// 파일 존재하지 않는 경우
|
||||
if (file.isEmpty()) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
List<String> listData = excelUtils.getListData(file, 1, 0);
|
||||
|
||||
// 엑셀 파일내 중복된 데이터 있는지 체크
|
||||
if(excelUtils.hasDuplicates(listData)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATE_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
listData.forEach(
|
||||
item->{
|
||||
WhiteList whiteList = new WhiteList();
|
||||
//adminDB 조회
|
||||
int cnt = whiteListMapper.getCountByGuid(item.toString());
|
||||
if(cnt == 0 ){
|
||||
whiteList.setGuid(item.toString());
|
||||
}else{
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ADMINDB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
//gameDB #char isWhiteUser 값 체크
|
||||
Map<String, AttributeValue> whiteAttr = dynamoDBService.getItem("char#" + item, "char#" + item);
|
||||
//guid 검증
|
||||
if(whiteAttr.size() == 0){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
//화이트리스트 확정까지 보류
|
||||
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
||||
// if (isWhiteUser) {
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
||||
// }
|
||||
|
||||
list.add(whiteList);
|
||||
}
|
||||
);
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.list(list).message(SuccessCode.EXCEL_UPLOAD.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 단일 등록
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public WhiteListResponse postWhiteList(WhiteListRequest whiteListRequest){
|
||||
HashMap<String,Object> map = new HashMap<>();
|
||||
Admin admin = CommonUtils.getAdmin();
|
||||
map.put("status", WhiteList.STATUS.REJECT);
|
||||
map.put("createBy", admin.getId());
|
||||
|
||||
int cnt = whiteListMapper.getCountByGuid(whiteListRequest.getGuid());
|
||||
if(cnt > 0 ){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ADMINDB_EXIT_ERROR.getMessage());
|
||||
}
|
||||
//gameDB #char isWhiteUser 값 체크
|
||||
Map<String, AttributeValue> whiteAttr = dynamoDBService.getItem("user_base#" + whiteListRequest.getGuid()
|
||||
, "empty");
|
||||
|
||||
//guid 검증
|
||||
if(whiteAttr.size() == 0){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
|
||||
}
|
||||
//화이트리스트 확정까지 보류
|
||||
// boolean isWhiteUser = dynamoDBService.isWhiteOrBlackUser(whiteAttr.get("isWhiteUser"));
|
||||
// if (isWhiteUser) {
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_EXIT_ERROR.getMessage());
|
||||
// }
|
||||
map.put("guid",whiteListRequest.getGuid());
|
||||
map.put("nickname",dynamoDBService.getNickNameByGuid(whiteListRequest.getGuid()));
|
||||
whiteListMapper.postWhiteList(map);
|
||||
|
||||
//dynamoDB char# 테이블에 isWhiteUser : true 값을 insert
|
||||
dynamoDBService.insertUpdateData(whiteListRequest.getGuid(),"isWhiteUser",true);
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.message(SuccessCode.REGISTRATION.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
//복수 등록
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public WhiteListResponse multiPost(MultipartFile file){
|
||||
HashMap<String,Object> map = new HashMap<>();
|
||||
// 파일 존재하지 않는 경우
|
||||
if (file.isEmpty()) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
List<String> listData = excelUtils.getListData(file, 1, 0);
|
||||
|
||||
// 엑셀 파일내 중복된 데이터 있는지 체크
|
||||
if(excelUtils.hasDuplicates(listData)){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DUPLICATE_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
|
||||
}
|
||||
|
||||
Admin admin = CommonUtils.getAdmin();
|
||||
map.put("status", WhiteList.STATUS.REJECT);
|
||||
map.put("createBy", admin.getId());
|
||||
|
||||
listData.forEach(
|
||||
item->{
|
||||
map.put("guid",item.toString());
|
||||
map.put("nickname",dynamoDBService.getNickNameByGuid(item.toString()));
|
||||
whiteListMapper.postWhiteList(map);
|
||||
|
||||
//dynamoDB char# 테이블에 isWhiteUser : true 값을 insert
|
||||
dynamoDBService.insertUpdateData(item.toString(),"isWhiteUser", true);
|
||||
}
|
||||
);
|
||||
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.message(SuccessCode.REGISTRATION.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
public void excelDownLoad(HttpServletResponse response){
|
||||
|
||||
// 리스트 다시 가져옴
|
||||
List<WhiteList> whiteList = whiteListMapper.getWhiteList();
|
||||
|
||||
String sheetName = "Caliverse_whitelist";
|
||||
|
||||
String headerNames[] = new String[]{"Num","GUID","닉네임","반영상태","등록자(이메일주소)"};
|
||||
|
||||
String[][] bodyDatass = new String[whiteList.size()][5];
|
||||
for (int i = 0; i < whiteList.size(); i++) {
|
||||
WhiteList entry = whiteList.get(i);
|
||||
bodyDatass[i][0] = String.valueOf(entry.getRowNum());
|
||||
bodyDatass[i][1] = entry.getGuid();
|
||||
bodyDatass[i][2] = entry.getNickname();
|
||||
bodyDatass[i][3] = entry.getStatus().name();
|
||||
bodyDatass[i][4] = entry.getCreateBy();
|
||||
}
|
||||
String outfileName = "Caliverse_whitelist";
|
||||
try {
|
||||
excelUtils.excelDownload(sheetName, headerNames, bodyDatass ,outfileName, response);
|
||||
}catch (IOException exception){
|
||||
logger.error(exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
// 승인
|
||||
public WhiteListResponse updateWhiteList(WhiteListRequest whiteListRequest){
|
||||
|
||||
whiteListRequest.getList().forEach(
|
||||
item->{
|
||||
whiteListMapper.updateStatus(item.getId());
|
||||
}
|
||||
);
|
||||
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.message(SuccessCode.UPDATE.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public WhiteListResponse deleteWhiteList(WhiteListRequest whiteListRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
whiteListRequest.getList().forEach(
|
||||
item->{
|
||||
whiteListMapper.deleteWhiteList(item.getId());
|
||||
//로그 기록
|
||||
Map<String,String> resMap = whiteListMapper.getGuidById(item.getId());
|
||||
map.put("adminId", CommonUtils.getAdmin().getId());
|
||||
map.put("name", CommonUtils.getAdmin().getName());
|
||||
map.put("mail", CommonUtils.getAdmin().getEmail());
|
||||
map.put("type", HISTORYTYPE.WHITELIST_DELETE);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("guid",resMap.get("guid"));
|
||||
jsonObject.put("name",resMap.get("nickname"));
|
||||
map.put("content",jsonObject.toString());
|
||||
historyMapper.saveLog(map);
|
||||
dynamoDBService.insertUpdateData(CommonUtils.objectToString(resMap.get("guid")),"isWhiteUser",false);
|
||||
}
|
||||
);
|
||||
|
||||
// 리스트 다시 가져옴
|
||||
List<WhiteList> whiteList = whiteListMapper.getWhiteList();
|
||||
return WhiteListResponse.builder()
|
||||
.resultData(WhiteListResponse.ResultData.builder()
|
||||
.list(whiteList).message(SuccessCode.DELETE.getMessage()).build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user