FAISP/src/main/java/com/dbnt/faisp/fipTarget/FipTargetController.java

260 lines
11 KiB
Java
Raw Normal View History

2022-09-28 07:56:31 +00:00
package com.dbnt.faisp.fipTarget;
import com.dbnt.faisp.authMgt.service.AuthMgtService;
import com.dbnt.faisp.fipTarget.model.PartInfo;
2022-10-05 05:25:34 +00:00
import com.dbnt.faisp.fipTarget.model.PartInfoFile;
2022-09-28 07:56:31 +00:00
import com.dbnt.faisp.fipTarget.service.FipTargetService;
import com.dbnt.faisp.organMgt.service.OrganConfigService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import com.dbnt.faisp.util.ParamMap;
import com.dbnt.faisp.util.Utils;
import lombok.RequiredArgsConstructor;
2022-10-05 05:25:34 +00:00
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
2022-09-28 07:56:31 +00:00
import java.io.IOException;
2022-10-05 05:25:34 +00:00
import java.net.URLEncoder;
2022-09-28 07:56:31 +00:00
import java.time.LocalDateTime;
import java.util.List;
2022-10-05 05:25:34 +00:00
import javax.servlet.http.HttpServletRequest;
2022-09-28 07:56:31 +00:00
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
2022-10-05 05:25:34 +00:00
import org.springframework.util.FileCopyUtils;
2022-09-28 07:56:31 +00:00
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
@RestController
@RequiredArgsConstructor
@RequestMapping("/target")
public class FipTargetController {
private final OrganConfigService organConfigService;
private final AuthMgtService authMgtService;
private final FipTargetService fipTargetService;
2022-09-28 07:56:31 +00:00
// 외사분실운영현황 시작
2022-09-28 07:56:31 +00:00
@GetMapping("/partInfoList")
2022-09-29 08:55:12 +00:00
public ModelAndView partInfoList(@AuthenticationPrincipal UserInfo loginUser,PartInfo partInfo, HttpServletResponse response) {
2022-09-28 07:56:31 +00:00
ModelAndView mav = new ModelAndView("fipTarget/partInfoList");
2022-09-29 08:55:12 +00:00
partInfo.setDownOrganCdList(loginUser.getDownOrganCdList());
//엑셀다운
if(partInfo.getExcel() != null && partInfo.getExcel().equals("Y")){
ParamMap header = fipTargetService.selectWorkTypeTotal(partInfo);
2022-10-05 05:25:34 +00:00
String[] headers = { "mgt_organ", "land_police", "terminal_nm", "mp_work_type", "mp_people_cnt", "mp_description", "pl_work_type", "pl_people_cnt", "pl_description", "pi_manager_name", "rent_price", "utility_price", "wrt_dt"};
String[] headerNames = { "해경서", "육경서","터미넡명", "해경", "", "", "육경", "", "", "", "", "",""};
String[] headerNames2 = null;
if(header != null) {
2022-10-05 05:25:34 +00:00
headerNames2 = new String[] { "", "", "", "상주 "+header.getString("mp_sangju")+"개소 "+header.getString("mp_sangju_total")+"명"
,"비상주 "+header.getString("mp_bsangju")+"개소 "+header.getString("mp_bsangju_total")+"명"
,"폐쇄 "+header.getString("mp_closure")+"개소 "+header.getString("mp_closure_total")+"명"
,"상주 "+header.getString("pl_sangju")+"개소 "+header.getString("pl_sangju_total")+"명"
,"비상주 "+header.getString("pl_bsangju")+"개소 "+header.getString("pl_bsangju_total")+"명"
,"폐쇄 "+header.getString("pl_closure")+"개소 "+header.getString("pl_closure_total")+"명"
2022-10-05 05:25:34 +00:00
, "", "", "", "" };
}else {
2022-10-05 05:25:34 +00:00
headerNames2 = new String[] { "", "","", "상주 0개소 0명","비상주 0개소 0명","폐쇄 0개소 0명","상주 0개소 0명","비상주 0개소 0명","폐쇄 0개소 0명", "", "", "", "" };
}
2022-10-05 05:25:34 +00:00
String[] headerNames3 = { "", "","", "근무방법", "명", "비고", "근무방법", "명", "비고", "담당자", "임차료", "공공요금", "최종수정일" };
String[] columnType = { "String", "String","String", "String", "int", "String", "String", "int", "String", "String", "String","String", "String"};
2022-09-29 08:55:12 +00:00
String sheetName = "외사 분실 현황";
String excelFileName = "외사 분실 현황";
List<PartInfo> partInfoList= fipTargetService.selectPartInfoList(partInfo);
2022-09-29 08:55:12 +00:00
try {
Utils.partInfolistToExcel(partInfoList, response, headers, headerNames,headerNames2,headerNames3, columnType, sheetName, excelFileName);
} catch (IOException e) {
}
return null;
}
2022-09-28 07:56:31 +00:00
//메뉴권한 확인
2022-10-05 05:25:34 +00:00
String accessAuth = authMgtService.selectAccessConfigList(loginUser.getUserSeq(), "/target/partInfoList").get(0).getAccessAuth();
2022-09-28 07:56:31 +00:00
mav.addObject("accessAuth", accessAuth);
partInfo.setDownOrganCdList(loginUser.getDownOrganCdList());
partInfo.setQueryInfo();
mav.addObject("total", fipTargetService.selectWorkTypeTotal(partInfo));
mav.addObject("partInfoList", fipTargetService.selectPartInfoList(partInfo));
partInfo.setContentCnt(fipTargetService.selectPartInfoListCnt(partInfo));
2022-09-28 07:56:31 +00:00
partInfo.setPaginationInfo();
2022-09-29 08:55:12 +00:00
mav.addObject("mgtOrganList", loginUser.getDownOrganCdList());
2022-09-28 07:56:31 +00:00
mav.addObject("searchParams", partInfo);
return mav;
}
@GetMapping("/partInfoEditModal")
public ModelAndView partInfoEditModal(@AuthenticationPrincipal UserInfo loginUser,PartInfo partInfo) {
ModelAndView mav = new ModelAndView("fipTarget/partInfoEditModal");
mav.addObject("mgtOrganList", loginUser.getDownOrganCdList());
return mav;
}
@GetMapping("/partInfoSelecBox")
public ModelAndView equipTypeSelecBox(String ogCd) {
2022-09-29 08:55:12 +00:00
ModelAndView mav = new ModelAndView("fipTarget/partInfoSelecBox");
2022-09-28 07:56:31 +00:00
ParamMap param = new ParamMap();
param.put("downOrganCdList", organConfigService.selectDownOrganListWhereUserOgCd(ogCd));
mav.addObject("managerList", fipTargetService.selectPartInfoManagerList(param));
2022-09-28 07:56:31 +00:00
return mav;
}
@PostMapping("/savePartInfo")
public void savePartInfo (@AuthenticationPrincipal UserInfo loginUser, PartInfo partInfo,MultipartHttpServletRequest request){
partInfo.setMultipartFileList(request.getMultiFileMap().get("uploadFiles"));
partInfo.setWrtNm(loginUser.getUserId());
partInfo.setWrtPart(loginUser.getOfcCd());
partInfo.setWrtUserSeq(loginUser.getUserSeq());
partInfo.setWrtOrgan(loginUser.getOgCd());
partInfo.setWrtDt(LocalDateTime.now());
fipTargetService.savePartInfo(partInfo);
2022-09-28 07:56:31 +00:00
}
2022-09-29 08:55:12 +00:00
@GetMapping("/updatePartInfoPage")
public ModelAndView updatePartInfoPage(@AuthenticationPrincipal UserInfo loginUser,PartInfo partInfo) {
ModelAndView mav = new ModelAndView("fipTarget/partInfoModifyModal");
mav.addObject("mgtOrganList", loginUser.getDownOrganCdList());
PartInfo partInfoView = fipTargetService.selectPartInfo(partInfo);
2022-09-29 08:55:12 +00:00
ParamMap param = new ParamMap();
param.put("downOrganCdList", organConfigService.selectDownOrganListWhereUserOgCd(partInfoView.getMgtOrgan()));
mav.addObject("managerList", fipTargetService.selectPartInfoManagerList(param));
partInfoView.setFileList(fipTargetService.selectPartInfoFile(partInfo));
2022-09-29 08:55:12 +00:00
mav.addObject("partInfo", partInfoView);
2022-10-05 05:25:34 +00:00
//메뉴권한 확인
String accessAuth = authMgtService.selectAccessConfigList(loginUser.getUserSeq(), "/target/partInfoList").get(0).getAccessAuth();
mav.addObject("accessAuth", accessAuth);
mav.addObject("userId", loginUser.getUserId());
mav.addObject("wrtId", fipTargetService.selectPartInfoFirstId(partInfo));
2022-09-29 08:55:12 +00:00
return mav;
}
@PostMapping("/updatePartInfo")
public int updatePartInfo (@AuthenticationPrincipal UserInfo loginUser,PartInfo partInfo,
MultipartHttpServletRequest request,
@RequestParam(value = "fileSeq", required = false) List < Integer > deleteFileSeq){
partInfo.setMultipartFileList(request.getMultiFileMap().get("uploadFiles"));
partInfo.setWrtUserSeq(loginUser.getUserSeq());
partInfo.setWrtNm(loginUser.getUserId());
2022-10-05 05:25:34 +00:00
partInfo.setWrtOrgan(loginUser.getOgCd());
partInfo.setWrtPart(loginUser.getOfcCd());
partInfo.setWrtDt(LocalDateTime.now());
fipTargetService.updatePartInfo(partInfo,deleteFileSeq);
return partInfo.getPiSeq();
}
@GetMapping("/PartInfoHistoryPage")
public ModelAndView PartInfoHistoryPage(PartInfo partInfo) {
ModelAndView mav = new ModelAndView("fipTarget/partInfoHistory");
mav.addObject("partInfoList", fipTargetService.selectPartInfoSeq(partInfo));
return mav;
}
@GetMapping("/partInfoHistoryView")
@ResponseBody
public PartInfo partInfoHistoryView(PartInfo partInfo){
PartInfo partInfoHistory = fipTargetService.selectPartInfoHistoryView(partInfo);
partInfoHistory.setFileList(fipTargetService.selectPartInfoFileHistoryView(partInfo));
return partInfoHistory;
}
@PostMapping("/deletePartInfo")
@ResponseBody
public void deletePartInfo(@RequestBody PartInfo partInfo) {
fipTargetService.deletePartInfo(partInfo);
}
2022-10-05 05:25:34 +00:00
@GetMapping("/partInfoFileDownload")
public void fileDownload(HttpServletRequest request,
HttpServletResponse response,
Integer fileSeq,
Integer piSeq,
Integer versionNo) {
PartInfoFile downloadFile = null;
downloadFile = fipTargetService.selectPartInfoFileDown(fileSeq, piSeq,versionNo);
BufferedInputStream in;
BufferedOutputStream out;
try {
File file = new File(downloadFile.getFilePath(), downloadFile.getConvNm());
setDisposition(downloadFile.getOrigNm()+'.'+downloadFile.getFileExtn(), request, response);
in = new BufferedInputStream(new FileInputStream(file));
out = new BufferedOutputStream(response.getOutputStream());
FileCopyUtils.copy(in, out);
out.flush();
if(out!=null) out.close();
if(in!=null )in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void setDisposition(String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
String browser = getBrowser(request);
String dispositionPrefix = "attachment; filename=";
String encodedFilename = null;
if (browser.equals("MSIE")) {
encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");
} else if (browser.equals("Trident")) { // IE11 문자열 깨짐 방지
encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");
} else if (browser.equals("Firefox")) {
encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\"";
} else if (browser.equals("Opera")) {
encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\"";
} else if (browser.equals("Chrome")) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < filename.length(); i++) {
char c = filename.charAt(i);
if (c > '~') {
sb.append(URLEncoder.encode("" + c, "UTF-8"));
} else {
sb.append(c);
}
}
encodedFilename = sb.toString();
} else {
throw new IOException("Not supported browser");
}
response.setHeader("Content-Disposition", dispositionPrefix + encodedFilename);
if ("Opera".equals(browser)) {
response.setContentType("application/octet-stream;charset=UTF-8");
}
}
private String getBrowser(HttpServletRequest request) {
String header = request.getHeader("User-Agent");
if (header.indexOf("MSIE") > -1) {
return "MSIE";
} else if (header.indexOf("Trident") > -1) { // IE11 문자열 깨짐 방지
return "Trident";
} else if (header.indexOf("Chrome") > -1) {
return "Chrome";
} else if (header.indexOf("Opera") > -1) {
return "Opera";
}
return "Firefox";
}
//외사분실 운영현황 끝
2022-09-28 07:56:31 +00:00
}