초기소스
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
package com.wb.domainserver.domain.gcone.common.controller;
|
||||
|
||||
|
||||
import com.wb.domainserver.domain.admin.store.sopmal.service.BOMaSopmalService;
|
||||
import com.wb.domainserver.domain.admin.store.sopmal.vo.BOMaSopmalVO;
|
||||
import com.wb.domainserver.domain.admin.store.sopthema.service.BOSopthemaService;
|
||||
import com.wb.domainserver.domain.admin.store.sopthema.vo.BOSopThemaVO;
|
||||
import com.wb.domainserver.domain.admin.sys.menu.service.BOMaMenuService;
|
||||
import com.wb.domainserver.domain.admin.sys.menu.vo.BOMaMenuVO;
|
||||
import com.wb.domainserver.domain.gcone.common.service.BOCommonService;
|
||||
import com.wb.domainserver.domain.gcone.common.vo.BOCommonVO;
|
||||
import com.wb.domainserver.domain.gcone.setup.ordrmngr.mapper.BOOrdrMngrMapper;
|
||||
import com.wb.domainserver.domain.gcone.setup.ordrmngr.vo.BOSetupOrdrVO;
|
||||
import com.wb.domainserver.response.ApiResponse;
|
||||
import com.wb.domainserver.security.authentication.AnonymousUser;
|
||||
import com.wb.domainserver.security.authentication.MemberJwtContextHolder;
|
||||
import com.wb.domainserver.security.authorization.annotation.AuthPolicy;
|
||||
import com.wb.domainserver.security.authorization.annotation.Policy;
|
||||
import com.wb.domainserver.util.string.StringUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/gcone/common")
|
||||
public class BOCommonController {
|
||||
|
||||
@Autowired
|
||||
private BOCommonService service;
|
||||
|
||||
@Autowired
|
||||
private BOMaMenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private BOMaSopmalService sopmalService;
|
||||
|
||||
@Autowired
|
||||
private BOSopthemaService bOSopthemaService;
|
||||
|
||||
@Autowired
|
||||
private BOOrdrMngrMapper ordrMngrMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 파일 삭제에 따른 파일경로 조회, 파일관련정보 수정 및 물리적 파일삭제
|
||||
* @return
|
||||
*/
|
||||
@Policy(AuthPolicy.PUBLIC)
|
||||
@RequestMapping(value = "/deleteUploadedFile")
|
||||
public ResponseEntity<?> deleteUploadedFile(@RequestBody BOCommonVO commVO) {
|
||||
|
||||
// 각 구분자별 이미지관련정보 삭제 및 경로조회
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
message = service.deleteFileProcess(commVO);
|
||||
|
||||
log.debug("message 성공 확인 : {}", message);
|
||||
return ApiResponse.of(message).ifPresentOrElse(HttpStatus.OK, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DB에서 파일 경로 조회
|
||||
* @return
|
||||
*/
|
||||
@Policy(AuthPolicy.PUBLIC)
|
||||
@RequestMapping(value = "/selectImgPath")
|
||||
public ResponseEntity<?> selectImgPath(@RequestBody BOCommonVO commVO) {
|
||||
|
||||
// 각 구분자별 이미지관련정보 삭제 및 경로조회
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
message.put("fileInfo",service.selectImgPath(commVO));
|
||||
|
||||
log.debug("message 성공 확인 : {}", message);
|
||||
return ApiResponse.of(message).ifPresentOrElse(HttpStatus.OK, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 메뉴 조회
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@Policy(AuthPolicy.PUBLIC)
|
||||
@RequestMapping(value = "/selectBOSopmalTopMenuListInqire")
|
||||
public ResponseEntity<?> selectBOSopmalTopMenuListInqire(HttpServletRequest request, @RequestBody BOMaMenuVO vo) {
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
// 메뉴정보 조회
|
||||
resultMap.put("menuList", menuService.selectBOSopmalTopMenuListInqire(vo));
|
||||
|
||||
// Shop 정보 조회
|
||||
BOSetupOrdrVO boOrdrVO = new BOSetupOrdrVO();
|
||||
boOrdrVO.setSopmalCd(vo.getSopmalCd());
|
||||
resultMap.put("shopInfo", ordrMngrMapper.selectBOOrdrSetup(boOrdrVO));
|
||||
|
||||
//쇼핑몰 테마 조회
|
||||
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
|
||||
BOSopThemaVO boSopthemaVO = new BOSopThemaVO();
|
||||
if("01".equals(user.getSysDvCd())){
|
||||
boSopthemaVO.setSopmalCd(user.getSopmalCd());
|
||||
}
|
||||
|
||||
//접속환경이 비었으면
|
||||
log.debug("환경 ?{}",vo.getEnv());
|
||||
if("".equals(StringUtil.isNullToString(vo.getEnv()))){
|
||||
boSopthemaVO.setEnv("MO"); //기본 MO 세팅
|
||||
}else{
|
||||
boSopthemaVO.setEnv(vo.getEnv());//접속환경 PC, MO
|
||||
}
|
||||
|
||||
String themaPath = bOSopthemaService.selectBOSopThemaDtlInfo(boSopthemaVO);
|
||||
resultMap.put("themaPath", themaPath);
|
||||
|
||||
|
||||
return ApiResponse.of(resultMap).ifPresentOrElse(HttpStatus.OK, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 footer정보 조회
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@Policy(AuthPolicy.PUBLIC)
|
||||
@RequestMapping(value = "/selectBOSopmalFooterInfo")
|
||||
public ResponseEntity<?> selectBOSopmalFooterInfo(HttpServletRequest request) {
|
||||
|
||||
BOMaSopmalVO vo = new BOMaSopmalVO();
|
||||
vo.setSopmalCd(MemberJwtContextHolder.getMemberInfo().getSopmalCd());
|
||||
Map<String,Object> footerInfo = new HashMap<>();
|
||||
footerInfo.put("footerInfo", sopmalService.selectBOSopmalFooterInfo(vo));
|
||||
|
||||
return ApiResponse.of(footerInfo).ifPresentOrElse(HttpStatus.OK, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.wb.domainserver.domain.gcone.common.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.wb.domainserver.domain.gcone.common.vo.BOCommonVO;
|
||||
import com.wb.domainserver.util.dataaccess.DataMap;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface BOCommonMapper {
|
||||
|
||||
/**
|
||||
* 파일 정보 조회
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public DataMap selectBOFileInfo(BOCommonVO commVO);
|
||||
|
||||
/**
|
||||
* 파일 정보 수정
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public void updateBOFileInfo(BOCommonVO commVO);
|
||||
|
||||
|
||||
/**
|
||||
* 상품 파일 정보 조회
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public DataMap selectGoodsInfo(BOCommonVO commVO);
|
||||
|
||||
/**
|
||||
* 상품 파일 정보 수정
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public void updateBOGoodsFileInfo(BOCommonVO commVO);
|
||||
|
||||
|
||||
/**
|
||||
* 비밀번호 암호화 키 가져오기
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public String selectEncptKey(BOCommonVO commVO);
|
||||
|
||||
/**
|
||||
* 비밀번호 암호화 키 등록
|
||||
* @param BOCommonVO
|
||||
*/
|
||||
public int insertEncptKey(BOCommonVO commVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
package com.wb.domainserver.domain.gcone.common.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.wb.domainserver.security.authentication.AnonymousUser;
|
||||
import com.wb.domainserver.security.authentication.MemberJwtContextHolder;
|
||||
import com.wb.domainserver.security.authentication.MemberJwtToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 com.wb.domainserver.domain.gcone.common.mapper.BOCommonMapper;
|
||||
import com.wb.domainserver.domain.gcone.common.vo.BOCommonVO;
|
||||
import com.wb.domainserver.exception.WnbtRestException;
|
||||
import com.wb.domainserver.util.dataaccess.DataMap;
|
||||
import com.wb.domainserver.util.string.StringUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BOCommonService {
|
||||
|
||||
@Autowired
|
||||
private BOCommonMapper mapper;
|
||||
|
||||
@Value("${mngrfo.common.fileupload.uploaddirs.doc}")
|
||||
private String uploadDocFilePath;
|
||||
|
||||
@Value("${mngrfo.common.fileupload.uploaddirs.web}")
|
||||
private String uploadWebFilePath;
|
||||
|
||||
@Value("${mngrfo.common.fileupload.extensions.images}")
|
||||
private String whiteListFileUploadExtensions;
|
||||
|
||||
@Value("${secret.key}")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* <p>비밀번호를 암호화 한다</p>
|
||||
*
|
||||
* <pre>
|
||||
* BOCommonVO의 필수값
|
||||
* - pass(사용자입력 비밀번호)
|
||||
* - encptKeyDvCd(암호화키구분코드) => 01(회원),02(관리자), 03(매장)
|
||||
* - idntfcInnb(식별고유번호) => 회원/관리자/매장관리자 고유번호
|
||||
* String pass = "winbit1!@%"; // 비밀번호
|
||||
* String result = generateKeyAndHash(pass);
|
||||
* </pre>
|
||||
*
|
||||
* @param pass 사용자가 입력한 비밀번호
|
||||
* @return
|
||||
*/
|
||||
public String generateKey(BOCommonVO commVO) {
|
||||
|
||||
try {
|
||||
// 1. 기존 비밀번호 암호화 키 가져오기
|
||||
String encptKey = mapper.selectEncptKey(commVO);
|
||||
|
||||
if(StringUtil.isEmpty(encptKey)) {
|
||||
// 2. 암호화키 없으면 생성
|
||||
Random rand = new Random();
|
||||
StringBuilder key = new StringBuilder();
|
||||
key.append(rand.nextInt());
|
||||
int cnt = 5 + rand.nextInt(6); // 5에서 10 사이의 랜덤 숫자 생성
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
key.append(rand.nextInt()).append(System.nanoTime());
|
||||
}
|
||||
encptKey = hashSHA256(key.toString());
|
||||
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
|
||||
// commVO.setRegusr(user.getUserInn());
|
||||
commVO.setRegusr(0);
|
||||
commVO.setEncptKey(encptKey);
|
||||
mapper.insertEncptKey(commVO);
|
||||
}
|
||||
|
||||
// 3. 비밀번호 암호화
|
||||
String pwd = encptKey.substring(0, 10) + "-" + commVO.getPass() + "-" + encptKey.substring(encptKey.length() - 10);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
pwd = pwd.substring(0, 10) + "-" + pwd + "-" + pwd.substring(pwd.length() - 10);
|
||||
pwd = hashSHA256(pwd);
|
||||
}
|
||||
return pwd;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*기존 비밀번호 암호화 키 가져오기*/
|
||||
public String selectEncptKey(BOCommonVO commVO){
|
||||
return mapper.selectEncptKey(commVO);
|
||||
}
|
||||
|
||||
|
||||
private String hashSHA256(String input) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(input.getBytes());
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* 1) 게시판 첨부파일 (BDFL) - GC_BOARDDATA_FILE
|
||||
* 2) 게시판 대표이미지 (BDIG) - GC_BOARDDATA
|
||||
* 3) 상품 (GDIG) - GC_GOODS_IMAGE
|
||||
* 4) 이메일
|
||||
* 5-1) 메시지관리 (SMSF) - GC_SMS_FILE
|
||||
* 5-2) 대용량메시지관리 (SMSQ) - GC_LGQY_SMS
|
||||
* 5-3) 인트라넷 메시지 (SMSI) - GC_INTRANET_SMS_FILE
|
||||
* 6) 메인설정 (상단:MANT/하단:MANB) - GC_DESIGN
|
||||
* 7) 메인컨텐츠설정 (MANC) - GC_DESIGN_CONTENTS_ITEM
|
||||
* 7) 이벤트 (EVNT) - GC_EVENT
|
||||
* 8) 팝업 (POUP) - GC_DESIGN_POPUP
|
||||
* 9) 배너 (BANR) - GC_GOODS_BANNER
|
||||
* 10) 회원 (MBRG) - GC_MEMBER_GRAD
|
||||
*/
|
||||
/**
|
||||
* 파일경로 조회 후 파일정보 수정
|
||||
* @param BOCommonVO commVO
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public Map<String, Object> deleteFileProcess(BOCommonVO commVO) {
|
||||
log.debug("파일 삭제 => {}", commVO);
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
|
||||
//1. 파일경로조회
|
||||
String imgPath = "";
|
||||
String result = "success";
|
||||
DataMap dataMap = mapper.selectBOFileInfo(commVO);
|
||||
imgPath = dataMap.get("fileFullPath").toString();
|
||||
|
||||
log.debug("BoService imgPath :::{}",imgPath);
|
||||
|
||||
//2. 파일정보 변경
|
||||
if(commVO.getMenuGb().equals("GDIG")) {
|
||||
DataMap map = mapper.selectGoodsInfo(commVO);
|
||||
commVO.setGoodsInnb(map.get("goodsInnb").toString());
|
||||
commVO.setCutNb(map.get("cutNb").toString());
|
||||
mapper.updateBOGoodsFileInfo(commVO);
|
||||
}else {
|
||||
mapper.updateBOFileInfo(commVO);
|
||||
}
|
||||
|
||||
//3. 파일삭제
|
||||
if(imgPath != null && !imgPath.equals("")&& !imgPath.equals("/")) {
|
||||
result = deleteSystemFile(dataMap);
|
||||
}
|
||||
|
||||
message.put("result", result);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 파일경로 조회
|
||||
* @param BOCommonVO commVO : sopmalCd,fileSeq,menuGb
|
||||
* @return String
|
||||
*/
|
||||
public DataMap selectImgPath(BOCommonVO commVO) {
|
||||
//1. 파일경로조회
|
||||
DataMap map = mapper.selectBOFileInfo(commVO);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 파일경로 조회 후 물리적파일 삭제
|
||||
* @param BOCommonVO : sopmalCd,fileSeq,menuGb
|
||||
* @return String result
|
||||
*/
|
||||
public String deleteUploadedFiles(BOCommonVO commVO) {
|
||||
//1. DB파일경로 조회
|
||||
DataMap map = selectImgPath(commVO);
|
||||
String path = map.get("fileFullPath").toString();
|
||||
String result = "";
|
||||
|
||||
//2. 파일삭제
|
||||
if(path != null && !path.equals("") && !path.equals("/")) {
|
||||
result = deleteSystemFile(map);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 파일삭제
|
||||
* @param String path - 파일경로
|
||||
* @return String result
|
||||
*/
|
||||
public String deleteSystemFile(String filePath) {
|
||||
DataMap fileInfo = new DataMap();
|
||||
fileInfo.put("fileFullPath", filePath);
|
||||
fileInfo.put("filDvCd", "01");
|
||||
|
||||
return deleteSystemFile(fileInfo);
|
||||
}
|
||||
public String deleteSystemFile(DataMap dataMap) {
|
||||
|
||||
String result = "";
|
||||
String path = dataMap.get("fileFullPath").toString();
|
||||
if(path != null && !path.equals("") && !path.equals("/")) {
|
||||
|
||||
/* *************************************
|
||||
path는 DB경로. webroot , docroot 붙여줘야 함.
|
||||
************************************* */
|
||||
String fileDv = dataMap.get("filDvCd").toString();
|
||||
if(fileDv.equals("01")) {
|
||||
path = uploadWebFilePath + path;
|
||||
}else {
|
||||
path = uploadDocFilePath + path;
|
||||
}
|
||||
|
||||
//파일절대경로 셋팅
|
||||
Path filePath = Paths.get(path).toAbsolutePath().normalize();
|
||||
log.debug("[파일DB경로 path] ::: "+path);
|
||||
log.debug("[파일절대경로 filePath] ::: "+filePath);
|
||||
|
||||
Resource resource;
|
||||
try {
|
||||
resource = new UrlResource(filePath.toUri());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new WnbtRestException("Could not find file.", e);
|
||||
}
|
||||
log.debug("[파일소스 resource] ::: "+resource);
|
||||
log.debug("[파일소스 resource] ::: "+resource.getFilename());
|
||||
|
||||
//물리적 파일삭제
|
||||
try {
|
||||
File file = resource.getFile();
|
||||
if(file.exists()) {
|
||||
if(file.isDirectory()){
|
||||
//파일이 디렉토리인지 확인
|
||||
/*
|
||||
File[] files = file.listFiles();
|
||||
for( int i=0; i<files.length; i++){
|
||||
if( files[i].delete() ){
|
||||
log.debug(files[i].getName()+" 삭제성공");
|
||||
}else{
|
||||
log.debug(files[i].getName()+" 삭제실패");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if(file.delete()){ //여기에 상품2개파일 삭제구문 와야할듯....
|
||||
result = "success";
|
||||
log.debug("파일삭제 성공");
|
||||
}else{
|
||||
result = "fail";
|
||||
log.debug("파일삭제 실패");
|
||||
}
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
throw new WnbtRestException("Could not find file.", ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 암호화키 조회
|
||||
* @return String
|
||||
*/
|
||||
public String selectSecretkey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.wb.domainserver.domain.gcone.common.vo;
|
||||
|
||||
import com.wb.domainserver.domain.comm.vo.AbstractVO;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class BOCommonVO extends AbstractVO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 쇼핑몰코드 */
|
||||
private String shopCd;
|
||||
|
||||
/** 메뉴구분 */
|
||||
private String menuGb;
|
||||
|
||||
/** 파일키 */
|
||||
private String fileSeq;
|
||||
|
||||
/** 상품순번 */
|
||||
private String goodsInnb;
|
||||
|
||||
/** 상품cutnb */
|
||||
private String cutNb;
|
||||
|
||||
/** 암호화테이블 일련번호*/
|
||||
private String encptKeyInnb;
|
||||
|
||||
/** 암호화대상비밀번호 */
|
||||
private String pass;
|
||||
|
||||
/** 암호화키구분코드 */
|
||||
private String encptKeyDvCd;
|
||||
|
||||
/** 식별고유번호 */
|
||||
private String idntfcInnb;
|
||||
|
||||
/** 암호화키 */
|
||||
private String encptKey;
|
||||
}
|
||||
Reference in New Issue
Block a user