|
|
@@ -0,0 +1,335 @@
|
|
|
+package com.ad.bf.controller;
|
|
|
+
|
|
|
+import java.util.Enumeration;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
+
|
|
|
+import com.ad.bf.service.ADBF01Service;
|
|
|
+import com.top.file.FileDownloader;
|
|
|
+import com.top.file.FileUploader;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping("/ad/bf/ADBF01")
|
|
|
+public class ADBF01Controller {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ADBF01Service service;
|
|
|
+
|
|
|
+ @Value("#{conf['FILE.ATTACH.BUSINESSFORM']}")
|
|
|
+ private String attachFileUploadDir;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileUploader fileUploader;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileDownloader fileDownloader;
|
|
|
+
|
|
|
+ //리스트 페이지
|
|
|
+ @RequestMapping(value="/page")
|
|
|
+ public String page(@RequestParam HashMap<String,String> params, Model model) {
|
|
|
+ return "ad/bf/ADBF01";
|
|
|
+ }
|
|
|
+
|
|
|
+ //팝업(등록) 페이지
|
|
|
+ @RequestMapping(value="/popup")
|
|
|
+ public String popup(@RequestParam HashMap<String,String> params, Model model) {
|
|
|
+
|
|
|
+ return "ad/bf/ADBF01P";
|
|
|
+ }
|
|
|
+
|
|
|
+ //팝업(조회) 페이지
|
|
|
+ @RequestMapping(value="/popup1")
|
|
|
+ public String popup1(@RequestParam HashMap<String,String> params, Model model, HttpSession session) {
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ HashMap<String, String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ String login_id = staffInfo.get("login_id");
|
|
|
+
|
|
|
+ HashMap<String, String> info = null;
|
|
|
+ List<HashMap<String, String>> attachList = null;
|
|
|
+
|
|
|
+ info = service.selectBusinessFormDetail(params);
|
|
|
+ attachList = service.selectBusinessFormAttachList(params);
|
|
|
+
|
|
|
+ model.addAttribute("login_id", login_id);
|
|
|
+ model.addAttribute("info", info);
|
|
|
+ model.addAttribute("attachList", attachList);
|
|
|
+ model.addAttribute("fileDownloadPath", attachFileUploadDir);
|
|
|
+
|
|
|
+ return "ad/bf/ADBF01P1";
|
|
|
+ }
|
|
|
+
|
|
|
+ //팝업(수정) 페이지
|
|
|
+ @RequestMapping(value="/popup2")
|
|
|
+ public String popup2(@RequestParam HashMap<String,String> params, Model model, HttpSession session) {
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ HashMap<String, String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ String login_id = staffInfo.get("login_id");
|
|
|
+
|
|
|
+ HashMap<String, String> info = null;
|
|
|
+ List<HashMap<String, String>> attachList = null;
|
|
|
+
|
|
|
+ info = service.selectBusinessFormDetail(params);
|
|
|
+ attachList = service.selectBusinessFormAttachList(params);
|
|
|
+
|
|
|
+ model.addAttribute("login_id", login_id);
|
|
|
+ model.addAttribute("info", info);
|
|
|
+ model.addAttribute("attachList", attachList);
|
|
|
+ model.addAttribute("fileDownloadPath", attachFileUploadDir);
|
|
|
+
|
|
|
+ return "ad/bf/ADBF01P2";
|
|
|
+ }
|
|
|
+
|
|
|
+ //리스트 조회
|
|
|
+ @RequestMapping(value = "/selectBusinessFormList", produces = "application/json")
|
|
|
+ @ResponseBody
|
|
|
+ public HashMap<String, Object> getSearch(@RequestParam HashMap<String, String> params, Model model, HttpSession session) {
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ HashMap<String, String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ String staffId = staffInfo.get("login_id");
|
|
|
+ String vendor_no = staffInfo.get("vendor_no");
|
|
|
+ params.put("vendor_no", vendor_no);
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
+ List<HashMap<String, String>> list = service.selectBusinessFormList(params);
|
|
|
+ map.put("rows", list);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ //상세 조회
|
|
|
+ @RequestMapping(value = "/selectBusinessFormDetail", produces = "application/json")
|
|
|
+ @ResponseBody
|
|
|
+ public HashMap<String, Object> searchDtl(@RequestParam HashMap<String, String> params, Model model, HttpSession session) {
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
+ HashMap<String, String> info = service.selectBusinessFormDetail(params);
|
|
|
+ map.put("info", info);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ //등록
|
|
|
+ @RequestMapping(value = "/saveBusinessForm", produces = "text/html;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public String saveBusinessForm(@RequestParam HashMap<String, String> params, MultipartHttpServletRequest mpreq, HttpSession session) throws Exception {
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ HashMap<String, String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ String staffId = staffInfo.get("login_id");
|
|
|
+ String vendor_no = staffInfo.get("vendor_no");
|
|
|
+
|
|
|
+ Enumeration<String> paramNames = mpreq.getParameterNames();
|
|
|
+
|
|
|
+ while(paramNames.hasMoreElements()) {
|
|
|
+ String key = paramNames.nextElement();
|
|
|
+ String originalValue = mpreq.getParameter(key);
|
|
|
+ String encodedValue = new String(originalValue.getBytes("ISO-8859-1"), "UTF-8");
|
|
|
+ //mpreq.setAttribute(key, encodedValue);
|
|
|
+ params.put(key, encodedValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 1.문서번호 불러오기 */
|
|
|
+ service.getBusinessFormSeq(params);
|
|
|
+
|
|
|
+ /* 2.문서기본정보 저장 */
|
|
|
+ params.put("vendor_no", vendor_no);
|
|
|
+ params.put("reg_id", staffId);
|
|
|
+ params.put("view_cnt", "0");
|
|
|
+ params.put("del_yn", "N");
|
|
|
+ params.put("businessform_typ", "1");
|
|
|
+ service.insertBusinessFormMst(params);
|
|
|
+
|
|
|
+ /* 3.첨부파일 저장 */
|
|
|
+ int fileCnt = 3; //첨부파일 갯수
|
|
|
+ MultipartFile[] multipartFile = new MultipartFile[fileCnt];
|
|
|
+ boolean[] hasNewAttach = new boolean[fileCnt];
|
|
|
+
|
|
|
+ multipartFile[0] = mpreq.getFile("attachFile0");
|
|
|
+ multipartFile[1] = mpreq.getFile("attachFile1");
|
|
|
+ multipartFile[2] = mpreq.getFile("attachFile2");
|
|
|
+
|
|
|
+
|
|
|
+ for(int i=0; i < fileCnt; i++) {
|
|
|
+
|
|
|
+ // 첨부파일 유무
|
|
|
+ hasNewAttach[i] = multipartFile[i] != null && multipartFile[i].getSize() != 0 ? true : false;
|
|
|
+
|
|
|
+ //첨부파일 확장자 체크
|
|
|
+ if (hasNewAttach[i]) {
|
|
|
+ String fileExt = multipartFile[i].getOriginalFilename().toLowerCase();
|
|
|
+
|
|
|
+ if(!fileExt.endsWith(".ppt") && !fileExt.endsWith(".pptx") && !fileExt.endsWith(".xls") && !fileExt.endsWith(".xlsx") && !fileExt.endsWith(".doc") &&
|
|
|
+ !fileExt.endsWith(".docx") && !fileExt.endsWith(".hwp") && !fileExt.endsWith(".jpg") && !fileExt.endsWith(".jpeg") && !fileExt.endsWith(".gif") &&
|
|
|
+ !fileExt.endsWith(".png") && !fileExt.endsWith(".bmp") && !fileExt.endsWith(".tif")){
|
|
|
+ return "-1";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 첨부파일이 있으면
|
|
|
+ if (hasNewAttach[i]) {
|
|
|
+ fileUploader.uploadFile(multipartFile[i], "/api3/fdata", attachFileUploadDir, String.valueOf(System.currentTimeMillis()), false);
|
|
|
+ String encodedFilename = new String(fileUploader.getOraginFileName().getBytes("ISO-8859-1"), "UTF-8"); //파일명
|
|
|
+
|
|
|
+ params.put("filename_txt", encodedFilename);
|
|
|
+ params.put("attachfile_txt", fileUploader.getTargetFileName());
|
|
|
+ params.put("download_cnt", "0");
|
|
|
+ service.insertBusinessFormAttach(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ //등록
|
|
|
+ @RequestMapping(value="/insertBusinessFormMst", produces="application/json")
|
|
|
+ @ResponseBody
|
|
|
+ public HashMap<String,String> insertBusinessFormMst(HttpSession session, @RequestParam HashMap<String,String> params) throws Exception {
|
|
|
+
|
|
|
+ HashMap<String,String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ params.put("reg_id", staffInfo.get("staff_id") );
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+ ret += service.insertBusinessFormMst(params);
|
|
|
+
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("code", String.valueOf(ret));
|
|
|
+ if(ret > 0) map.put("msg", "저장에 성공하였습니다.");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ //등록
|
|
|
+ @RequestMapping(value = "/updateBusinessForm", produces = "text/html;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public String updateBusinessForm(@RequestParam HashMap<String, String> params, MultipartHttpServletRequest mpreq, HttpSession session) throws Exception {
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ HashMap<String, String> staffInfo = (HashMap<String, String>) session.getAttribute("STAFFINFORMATION");
|
|
|
+ String login_id = staffInfo.get("login_id");
|
|
|
+
|
|
|
+ params.put("mod_id",login_id);
|
|
|
+
|
|
|
+ Enumeration<String> paramNames = mpreq.getParameterNames();
|
|
|
+
|
|
|
+ while(paramNames.hasMoreElements()) {
|
|
|
+ String key = paramNames.nextElement();
|
|
|
+ String originalValue = mpreq.getParameter(key);
|
|
|
+ String encodedValue = new String(originalValue.getBytes("ISO-8859-1"), "UTF-8");
|
|
|
+ params.put(key, encodedValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+ ret += service.updateBusinessFormMst(params);
|
|
|
+
|
|
|
+
|
|
|
+ /* 3.첨부파일 저장 */
|
|
|
+ int fileCnt = 3; //첨부파일 갯수
|
|
|
+ MultipartFile[] multipartFile = new MultipartFile[fileCnt];
|
|
|
+ boolean[] hasNewAttach = new boolean[fileCnt];
|
|
|
+
|
|
|
+ multipartFile[0] = mpreq.getFile("attachFile0");
|
|
|
+ multipartFile[1] = mpreq.getFile("attachFile1");
|
|
|
+ multipartFile[2] = mpreq.getFile("attachFile2");
|
|
|
+
|
|
|
+
|
|
|
+ for(int i=0; i < fileCnt; i++) {
|
|
|
+
|
|
|
+ // 첨부파일 유무
|
|
|
+ hasNewAttach[i] = multipartFile[i] != null && multipartFile[i].getSize() != 0 ? true : false;
|
|
|
+
|
|
|
+ //첨부파일 확장자 체크
|
|
|
+ if (hasNewAttach[i]) {
|
|
|
+ String fileExt = multipartFile[i].getOriginalFilename().toLowerCase();
|
|
|
+
|
|
|
+ if(!fileExt.endsWith(".ppt") && !fileExt.endsWith(".pptx") && !fileExt.endsWith(".xls") && !fileExt.endsWith(".xlsx") && !fileExt.endsWith(".doc") &&
|
|
|
+ !fileExt.endsWith(".docx") && !fileExt.endsWith(".hwp") && !fileExt.endsWith(".jpg") && !fileExt.endsWith(".jpeg") && !fileExt.endsWith(".gif") &&
|
|
|
+ !fileExt.endsWith(".png") && !fileExt.endsWith(".bmp") && !fileExt.endsWith(".tif")){
|
|
|
+ return "-1";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 첨부파일이 있으면
|
|
|
+ if (hasNewAttach[i]) {
|
|
|
+ fileUploader.uploadFile(multipartFile[i], "/api3/fdata", attachFileUploadDir, String.valueOf(System.currentTimeMillis()), false);
|
|
|
+ String encodedFilename = new String(fileUploader.getOraginFileName().getBytes("ISO-8859-1"), "UTF-8"); //파일명
|
|
|
+
|
|
|
+ params.put("filename_txt", encodedFilename);
|
|
|
+ params.put("attachfile_txt", fileUploader.getTargetFileName());
|
|
|
+ params.put("download_cnt", "0");
|
|
|
+ service.insertBusinessFormAttach(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ //삭제
|
|
|
+ @RequestMapping(value="/deleteBusinessFormMst", produces="application/json")
|
|
|
+ @ResponseBody
|
|
|
+ public HashMap<String,String> deleteBusinessFormMst(HttpSession session, @RequestParam HashMap<String,String> params) throws Exception {
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+ ret += service.deleteBusinessFormMst(params);
|
|
|
+ ret += service.deleteBusinessFormAttach(params);
|
|
|
+
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("code", String.valueOf(ret));
|
|
|
+ if(ret > 0) map.put("msg", "삭제에 성공하였습니다.");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ //파일삭제
|
|
|
+ @RequestMapping(value="/deleteBusinessFormAttach", produces="application/json")
|
|
|
+ @ResponseBody
|
|
|
+ public HashMap<String,String> deleteBusinessFormAttach(HttpSession session, @RequestParam HashMap<String,String> params) throws Exception {
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ HashMap<String, String> attachInfo = service.getBusinessFormAttach(params);
|
|
|
+
|
|
|
+ if(attachInfo != null) {
|
|
|
+
|
|
|
+// String attachfile_txt = String.valueOf(attachInfo.get("attachfile_txt"));
|
|
|
+//
|
|
|
+// File file = new File("/api3/fdata" + attachFileUploadDir + attachfile_txt);
|
|
|
+//
|
|
|
+// if( file.exists() ){
|
|
|
+// if(file.delete()){
|
|
|
+// System.out.println("파일삭제 성공");
|
|
|
+// }else{
|
|
|
+// System.out.println("파일삭제 실패");
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// System.out.println("파일이 존재하지 않습니다.");
|
|
|
+// }
|
|
|
+
|
|
|
+ ret += service.deleteBusinessFormAttach(params);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("code", String.valueOf(ret));
|
|
|
+ if(ret > 0) map.put("msg", "삭제에 성공하였습니다.");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|