package com.pms.service; import java.io.File; import java.sql.Clob; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.ibatis.session.SqlSession; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestParam; import com.pms.common.Message; import com.pms.common.SqlMapConfig; import com.pms.common.bean.PersonBean; import com.pms.common.service.BaseService; import com.pms.common.utils.CommonUtils; import com.pms.common.utils.Constants; import com.pms.common.utils.EncryptUtil; @Service public class BatchService extends BaseService { /** * 첨부파일 연결 대상이 되는 파트의 목록을 가져온다. * @param request * @param paramMap * @return * @throws Exception */ static List targetFileList = new ArrayList(); @Scheduled(cron="0 59 23 * * ?") public void partConnectDrawingFile1(){ partConnectDrawingFile(); } @Scheduled(cron="0 0 04 * * ?") public void partConnectDrawingFile2(){ partConnectDrawingFile(); } public void partConnectDrawingFile(){ SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false); List> partList = new ArrayList(); getFileList(Constants.PART_DRAWING_STORAGE); try{ //도면파일이 연결되지 않은 파트의 목록을 가져온다. partList = sqlSession.selectList("partMng.getBatchTargetPartList"); for(Map partMap:partList){ System.out.println("partMap:"+partMap); String partObjId = CommonUtils.checkNull(partMap.get("objid")); String partNo = CommonUtils.checkNull(partMap.get("part_no")); String revision = CommonUtils.checkNull(partMap.get("revision")); int cu1Cnt = Integer.parseInt(CommonUtils.checkNull(partMap.get("cu01_cnt"),"0")); int cu2Cnt = Integer.parseInt(CommonUtils.checkNull(partMap.get("cu02_cnt"),"0")); int cu3Cnt = Integer.parseInt(CommonUtils.checkNull(partMap.get("cu03_cnt"),"0")); String targetFileName = partNo+revision; int revNum = 0; String revName = ""; if(!"".equals(revision)){ revNum = Integer.parseInt(revision.toUpperCase().replaceAll("R", "")); revName = "R"+revNum; } String targetFileName2 = partNo+revName; for(File targetFile:targetFileList){ String realFileName = CommonUtils.checkNull(targetFile.getName()); String ext = realFileName.substring(realFileName.lastIndexOf(".") + 1); String fileName = realFileName.replaceAll("."+ext, ""); ext = ext.toUpperCase(); String fileSize = CommonUtils.checkNull(targetFile.length()); System.out.println("targetFileName:"+targetFileName2); System.out.println("fileName:"+fileName); if(targetFileName2.equals(fileName)){ String docType = ""; String docTypeName = ""; if(ext.equals("DWG") && 0 == cu2Cnt){ docType = "2D_DRAWING_CAD"; docTypeName = "2D(Drawing) CAD 첨부파일"; } if(ext.equals("PDF") && 0 == cu3Cnt){ docType = "2D_PDF_CAD"; docTypeName = "2D(PDF) CAD 첨부파일"; } if(ext.equals("IPT") && 0 == cu1Cnt){ docType = "3D_CAD"; docTypeName = "3D CAD 첨부파일"; } if(!"".equals(docType) && !"".equals(docTypeName)){ Map connectFileMap = new HashMap(); connectFileMap.put("objId", CommonUtils.createObjId()); connectFileMap.put("targetObjId", partObjId); connectFileMap.put("savedFileName", realFileName); connectFileMap.put("realFileName", realFileName); connectFileMap.put("docType", docType); connectFileMap.put("docTypeName", docTypeName); connectFileMap.put("fileSize", fileSize); connectFileMap.put("fileExt", ext); connectFileMap.put("filePath", targetFile.getParent()); connectFileMap.put("writer", "batch_plm_admin"); System.out.println("connectFileMap:"+connectFileMap); sqlSession.insert("common.insertUploadFileInfo", connectFileMap); } } } } sqlSession.commit(); }catch(Exception e){ sqlSession.rollback(); throw e; }finally{ sqlSession.close(); } } public static List getFileList(String dirPath){ File dir = new File(dirPath); File files[] = dir.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { getFileList(file.getPath()); } else { targetFileList.add(file); } } return targetFileList; } }