소스 정리

main
이범준 1 year ago
parent 97013ca05b
commit 0cd6c9f101

@ -1,5 +1,6 @@
package cokr.xit.fims.crdn.service;
import java.util.HashMap;
import java.util.List;
import cokr.xit.foundation.data.DataObject;
@ -18,5 +19,5 @@ public interface ImportService {
* @param dataObject
* @return
*/
boolean createCrdnByEquipmentLinkFile(String entType, List<DataObject> linkFileInfoList);
HashMap<String, Object> createCrdnByEquipmentLinkFile(String entType, List<DataObject> linkFileInfoList);
}

@ -1,5 +1,6 @@
package cokr.xit.fims.crdn.service.bean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -65,7 +66,10 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
}
@Override
public boolean createCrdnByEquipmentLinkFile(String entType, List<DataObject> linkFileInfoList) {
public HashMap<String, Object> createCrdnByEquipmentLinkFile(String entType, List<DataObject> linkFileInfoList) {
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("saved", false);
Crdn crdn = new Crdn();
@ -74,7 +78,7 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
}
return true;
return resultMap;
}
}

@ -239,16 +239,30 @@ public class Crdn05Controller extends ApplicationController {
*/
public ModelAndView createCrdnByLinkFile(String entType, String[] linkFileInfos) {
ModelAndView mav = new ModelAndView("jsonView");
boolean saved = false;
List<DataObject> linkFileInfoList = new ArrayList<DataObject>();
for(String linkFileInfo : linkFileInfos) {
linkFileInfoList.add(fromJson(linkFileInfo, DataObject.class));
}
saved = importService.createCrdnByEquipmentLinkFile(entType, linkFileInfoList);
HashMap<String, Object> resultMap = importService.createCrdnByEquipmentLinkFile(entType, linkFileInfoList);
boolean saved = (boolean) resultMap.get("saved");
mav.addObject("saved", saved);
if(!ifEmpty(resultMap.get("alertMessage"), () -> "").equals("")) {
mav.addObject("alertMessage", resultMap.get("alertMessage"));
}
if(!saved) {
if(!ifEmpty(resultMap.get("failReason"), () -> "").equals("")) {
mav.addObject("failReason", resultMap.get("failReason"));
} else {
mav.addObject("failReason", "알 수 없는 오류");
}
}
return mav;
}

@ -153,6 +153,8 @@
</div>
<form id="frmMultipart--${pageName}" method="post" enctype="multipart/form-data"></form>
<script>
pageObject["${pageName}"] = {};
@ -160,6 +162,8 @@ $(document).ready(function(){
var $P = pageObject["${pageName}"];
$P.tempGroup = {};
/**************************************************************************
* DatasetControl
**************************************************************************/
@ -201,37 +205,9 @@ $(document).ready(function(){
/**************************************************************************
* pageObject.function
**************************************************************************/
$P.renderCrdnList = (total) => {
var crdnList = $P.crdnControl.dataset;
var empty = crdnList.empty;
var notFound = [document.getElementById("crdnNotFound--${pageName}").innerHTML];
var found = document.getElementById("crdnRow--${pageName}").innerHTML;
var replacer = (str, dataItem) => str
.replace(/{onclick}/gi, "pageObject['${pageName}'].clickCrdnList('" + dataItem.getValue("FILE_NAME") + "');");
var trs = empty ? notFound : crdnList.inStrings(found,replacer);
$("#crdnTbody--${pageName}").html(trs.join());
if(!empty){
fnDownsizeCheck(document.getElementById("DataTables_Table_0--${pageName}"));
}
}
$P.clickCrdnList = (dataKey) => {
if(dataKey == ""){
return;
}
$P.crdnControl.setCurrent(dataKey);
};
/**************************************************************************
* element.on
**************************************************************************/
$("#btnSearch--${pageName}").on("click", function(){
if($("#entType--${pageName}").val() == ""){
$P.searchFileList = () => {
if($("#entType--${pageName}").val() == ""){
dialog.alert("장비업체를 선택하세요.");
return;
}
@ -254,11 +230,10 @@ $(document).ready(function(){
$P.crdnControl.setData(resp);
}
});
});
$("#btnFileUpload--${pageName}").on("click", function(){
if($("#entType--${pageName}").val() == ""){
}
$P.uploadLocalFile = () => {
if($("#entType--${pageName}").val() == ""){
dialog.alert("장비업체를 선택하세요.");
return;
}
@ -278,13 +253,75 @@ $(document).ready(function(){
dialog.alert("주정차,전용차로,미세먼지 과태료 파일 등록 기능은 서비스 준비 중입니다.");
return;
});
}
$P.renderCrdnList = (total) => {
var crdnList = $P.crdnControl.dataset;
var empty = crdnList.empty;
var notFound = [document.getElementById("crdnNotFound--${pageName}").innerHTML];
var found = document.getElementById("crdnRow--${pageName}").innerHTML;
var replacer = (str, dataItem) => str
.replace(/{onclick}/gi, "pageObject['${pageName}'].clickCrdnList('" + dataItem.getValue("FILE_NAME") + "');");
var trs = empty ? notFound : crdnList.inStrings(found,replacer);
$("#crdnTbody--${pageName}").html(trs.join());
if(!empty){
fnDownsizeCheck(document.getElementById("DataTables_Table_0--${pageName}"));
}
}
$("#btnInsertCrdn--${pageName}").on("click", function(){
$P.clickCrdnList = (dataKey) => {
if(dataKey == ""){
return;
}
});
$P.crdnControl.setCurrent(dataKey);
};
$("#btnDelete--${pageName}").on("click", function(){
$P.createCrdn = () => {
if($.isEmptyObject($P.tempGroup)){
dialog.alert("모든 자료가 처리 완료되었습니다.");
return;
}
var firstGroupKey = Object.keys($P.tempGroup)[0];
var formData = new FormData(document.getElementById("frmMultipart--${pageName}"));
formData.append("entType", $("#entType--${pageName}").val());
for(var i=0; i<$P.tempGroup[firstGroupKey].length; i++){
formData.append("linkFileInfos", JSON.stringify($P.tempGroup[firstGroupKey][i]));
}
ajax.post({
url : wctx.url("/${taskSeCd}/crdn/crdn05/020/create.do"),
contentType : false, processData : false,
data : formData,
success : (resp) => {
var removedFileName = $P.tempGroup[firstGroupKey].map(item => item.FILE_NAME);
delete $P.tempGroup[firstGroupKey];
if(resp.saved){
$P.removeCallback(removedFileName);
if(resp.alertMessage){
alert(alertMessage);
}
} else {
alert(resp.failReason);
}
//다음자료 진행
//$P.createCrdn();
}
});
};
$P.deleteFile = () => {
var current = $P.crdnControl.getCurrent();
if(current == null) return;
@ -298,17 +335,50 @@ $(document).ready(function(){
},
success : (resp) => {
if(resp.saved){
$P.crdnControl.dataset.remove(fileName);
var fileListTable = document.getElementById("DataTables_Table_0--${pageName}");
var tr = $(fileListTable).find("tbody").find("tr[data-key='"+fileName+"']");
var trIndex = $(fileListTable).find("tbody tr").index(tr);
fileListTable.deleteRow(trIndex+1);
$P.removeCallback(fileName);
}
}
});
}
$P.removeCallback = (removedFileName) => {
$P.crdnControl.dataset.remove(removedFileName);
$P.removeTableRow(removedFileName);
}
$P.removeTableRow = (removedFileName) => {
var fileListTable = document.getElementById("DataTables_Table_0--${pageName}");
var targetArr = [];
if(Array.isArray(removedFileName)){
targetArr = removedFileName;
} else {
targetArr = [removedFileName];
}
for(var i = 0; i < targetArr.length; i++){
var target = targetArr[i];
var tr = $(fileListTable).find("tbody").find("tr[data-key='"+target+"']");
var trIndex = $(fileListTable).find("tbody tr").index(tr);
fileListTable.deleteRow(trIndex+1);
}
}
/**************************************************************************
* element.on
**************************************************************************/
$("#btnSearch--${pageName}").on("click", function(){ $P.searchFileList(); });
$("#btnFileUpload--${pageName}").on("click", function(){ $P.uploadLocalFile(); });
$("#btnInsertCrdn--${pageName}").on("click", function(){
$P.tempGroup = Object.groupBy($P.crdnControl.dataset.getDataset(), ({ TEMP_GROUP_ID }) => "temp"+TEMP_GROUP_ID);
$P.createCrdn();
});
$("#btnDelete--${pageName}").on("click", function(){ $P.deleteFile(); });
$P.crdnControl.setData([]);
});

Loading…
Cancel
Save