2022-11-14 07:46:11 +00:00
|
|
|
package com.dbnt.faisp.config;
|
|
|
|
|
|
|
|
|
|
import com.dbnt.faisp.main.menuMgt.service.MenuMgtService;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import com.dbnt.faisp.main.organMgt.service.OrganConfigService;
|
|
|
|
|
import com.dbnt.faisp.main.userInfo.model.UserInfo;
|
|
|
|
|
import com.dbnt.faisp.main.codeMgt.service.CodeMgtService;
|
|
|
|
|
|
|
|
|
|
import com.dbnt.faisp.main.userInfo.service.UserInfoService;
|
|
|
|
|
import com.dbnt.faisp.util.ParamMap;
|
|
|
|
|
import com.dbnt.faisp.util.Utils;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class EditorController {
|
|
|
|
|
|
|
|
|
|
private final CodeMgtService codeMgtService;
|
|
|
|
|
private final OrganConfigService organConfigService;
|
|
|
|
|
private final MenuMgtService menuMgtService;
|
|
|
|
|
private final UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat sDate = new SimpleDateFormat("yyyyMM");
|
|
|
|
|
// 현재년월
|
|
|
|
|
String year = sDate.format(new Date()) + "/";
|
|
|
|
|
|
|
|
|
|
@Value("${file.dir}")
|
|
|
|
|
protected String fileDir;
|
2022-11-14 08:39:55 +00:00
|
|
|
@Value("${file.dir.editor}")
|
|
|
|
|
protected String editorPath;
|
2022-11-14 07:46:11 +00:00
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private Environment env;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/Crosseditor/uploadImg")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public ParamMap uploadImg(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
|
|
|
|
|
ParamMap result = new ParamMap();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
|
|
|
|
|
MultipartFile mFile = multipartRequest.getFile("imageFile");
|
|
|
|
|
if(!"".equals(mFile.getOriginalFilename())){
|
|
|
|
|
|
|
|
|
|
long attach_file_Size = mFile.getSize();
|
|
|
|
|
String attach_file_Name = mFile.getOriginalFilename();
|
|
|
|
|
String attach_save_Name = Utils.generationSaveName();
|
|
|
|
|
|
|
|
|
|
//파일 타입
|
|
|
|
|
String extNm = "." + attach_file_Name.substring( attach_file_Name.lastIndexOf( "." ) + 1, attach_file_Name.length());
|
|
|
|
|
if(".jpg,.png,.jpeg".indexOf(extNm.toLowerCase()) > -1) {
|
|
|
|
|
|
2022-11-14 08:39:55 +00:00
|
|
|
File dir = new File(fileDir+File.separator+editorPath);
|
2022-11-14 07:46:11 +00:00
|
|
|
if (!dir.exists()) {
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
// 생성
|
|
|
|
|
boolean result2 = dir.mkdir();
|
|
|
|
|
if (result2) {
|
|
|
|
|
System.out.println("Directory is created.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Failed to create directory.");
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e){
|
|
|
|
|
System.out.println("Exception occurred.");
|
|
|
|
|
e.getStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Directory already exists");
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 08:39:55 +00:00
|
|
|
File file = new File(fileDir+File.separator+editorPath, attach_save_Name + extNm);
|
2022-11-14 07:46:11 +00:00
|
|
|
|
|
|
|
|
FileCopyUtils.copy(mFile.getBytes(), file);
|
2022-11-14 08:39:55 +00:00
|
|
|
String webPath = "http://localhost:8080/file/editorFileDisplay?fileNm=" + attach_save_Name + extNm;
|
2022-11-14 07:46:11 +00:00
|
|
|
|
|
|
|
|
result.set("result", "success");
|
|
|
|
|
List<ParamMap> addmsg = new ArrayList<>();
|
|
|
|
|
ParamMap imgInfo = new ParamMap();
|
|
|
|
|
imgInfo.set("imageURL", webPath);
|
|
|
|
|
imgInfo.set("imageTitle", "");
|
|
|
|
|
imgInfo.set("imageAlt", "");
|
|
|
|
|
imgInfo.set("imageWidth", "");
|
|
|
|
|
imgInfo.set("imageWidthUnit", "px");
|
|
|
|
|
imgInfo.set("imageHeight", "");
|
|
|
|
|
imgInfo.set("imageHeightUnit", "");
|
|
|
|
|
imgInfo.set("imageSize", attach_file_Size);
|
|
|
|
|
imgInfo.set("imageMarginLeft", "");
|
|
|
|
|
imgInfo.set("imageMarginLeftUnit", "px");
|
|
|
|
|
imgInfo.set("imageMarginRight", "");
|
|
|
|
|
imgInfo.set("imageMarginRightUnit", "px");
|
|
|
|
|
imgInfo.set("imageMarginTop", "");
|
|
|
|
|
imgInfo.set("imageMarginTopUnit", "px");
|
|
|
|
|
imgInfo.set("imageMarginBottom", "");
|
|
|
|
|
imgInfo.set("imageMarginBottomUnit", "px");
|
|
|
|
|
imgInfo.set("imageAlign", "imageAlign");
|
|
|
|
|
imgInfo.set("imageId", "");
|
|
|
|
|
imgInfo.set("imageClass", "");
|
|
|
|
|
imgInfo.set("imageBorder", 0);
|
|
|
|
|
imgInfo.set("imageKind", "image");
|
|
|
|
|
imgInfo.set("imageOrgPath", attach_save_Name + extNm+"|"+webPath);
|
|
|
|
|
imgInfo.set("imageOrgWidth", 1893);
|
|
|
|
|
imgInfo.set("imageOrgHeight", 857);
|
|
|
|
|
imgInfo.set("editorFrame", "NamoSE_editorframe_crosseditor4");
|
|
|
|
|
addmsg.add(imgInfo);
|
|
|
|
|
result.set("addmsg", addmsg);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
result.set("uploaded", 0);
|
|
|
|
|
ParamMap error = new ParamMap();
|
|
|
|
|
error.set("message", "Check File Extentions.");
|
|
|
|
|
result.set("error", error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result.set("uploaded", 0);
|
|
|
|
|
ParamMap error = new ParamMap();
|
|
|
|
|
error.set("message", "Check File Extentions.");
|
|
|
|
|
result.set("error", error);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
result.set("uploaded", 0);
|
|
|
|
|
ParamMap error = new ParamMap();
|
|
|
|
|
error.set("message", "Check File Extentions.");
|
|
|
|
|
result.set("error", error);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getCurrentProfile() {
|
|
|
|
|
String[] profiles = env.getActiveProfiles();
|
|
|
|
|
|
|
|
|
|
if( profiles.length == 0 ) profiles = env.getDefaultProfiles();
|
|
|
|
|
|
|
|
|
|
return profiles[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|