Java tutorial
/* * M2M ServiceFOTA ONM version 1.0 * * Copyright 2014 kt corp. All rights reserved. * * This is a proprietary software of kt corp, and you may not use this file except in * compliance with license agreement with kt corp. Any redistribution or use of this * software, with or without modification shall be strictly prohibited without prior written * approval of kt corp, and the copyright notice above does not evidence any actual or * intended publication of such software. */ package com.fota.fotastatMgt.controller; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.json.MappingJacksonJsonView; import com.fota.comm.util.Masking; import com.fota.comm.util.VoV; import com.fota.commMgt.vo.UserLoginVO; import com.fota.fotastatMgt.service.FotastatSVC; import com.fota.fotastatMgt.vo.FotastatHistoryVO; import com.fota.fotastatMgt.vo.FotastatSearchVO; import com.oreilly.servlet.MultipartRequest; @Controller @RequestMapping("/commonFota/fotastatMgt") public class FotastatCTR { private static final Logger logger = LoggerFactory.getLogger(FotastatCTR.class); /** * @uml.property name="mySVC" * @uml.associationEnd readOnly="true" */ @Autowired FotastatSVC mySVC; /** * @uml.property name="ajaxMainView" * @uml.associationEnd readOnly="true" */ @Autowired private MappingJacksonJsonView ajaxMainView; private static final String PATH = "/jb_log/excelUpload/fotaStat/"; private static final int SIZE = 10 * 1024 * 1024; /** * FOTA * @param request * @param model * @return * @throws Exception */ @RequestMapping(value = "/fotastat") public String getFotaStatView(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("fotastatSearchVO") FotastatSearchVO vo, Model model) throws Exception { if (!request.getServletPath().equals("/commonFota/fotastatMgt/fotastat")) { response.setStatus(403); return "redirect:/lresources/errorPage.jsp"; // return null; } // validation check vo.setBizTypeId(VoV.valid(vo.getBizTypeId(), 30, 4)); vo.setSvcId(VoV.valid(vo.getSvcId(), 30, 4)); vo.setDevMakerId(VoV.valid(vo.getDevMakerId(), 30, 4)); vo.setDevModelId(VoV.valid(vo.getDevModelId(), 30, 4)); vo.setCtn(VoV.valid(vo.getCtn(), 20, 4)); //------------------- FotastatSearchVO fvo; fvo = mySVC.searchDevInfo(vo); if (fvo != null) { fvo.setCtn(vo.getCtn()); model.addAttribute("data", fvo); } return "fotastatMgt/fotastatView"; } /** * FOTA * @param param * @param response * @return */ @RequestMapping(value = "/searchFotastat") @ResponseBody public ModelAndView search(@ModelAttribute("fotastatSearchVO") FotastatSearchVO vo, ModelMap model) throws Exception { // validation check vo.setBizTypeId(VoV.valid(vo.getBizTypeId(), 30, 4)); vo.setSvcId(VoV.valid(vo.getSvcId(), 30, 4)); vo.setDevMakerId(VoV.valid(vo.getDevMakerId(), 30, 4)); vo.setDevModelId(VoV.valid(vo.getDevModelId(), 30, 4)); vo.setFotaType(VoV.valid(vo.getFotaType(), 50)); if (!vo.getFotaType().equals("") && !vo.getFotaType().equals("PUSH") && !vo.getFotaType().equals("POLLING") && !vo.getFotaType().equals("PUSHPOLLING")) throw new Exception(); vo.setFotaYn(VoV.valid(vo.getFotaYn(), 1, 10)); vo.setProcessStatCd(VoV.valid(vo.getProcessStatCd(), 1, 12)); vo.setCtn(VoV.valid(vo.getCtn(), 20, 4)); vo.setClientNm(VoV.valid(vo.getClientNm(), 50, 2)); vo.setDealerNm(VoV.valid(vo.getDealerNm(), 50, 2)); vo.setModemMakerId(VoV.valid(vo.getModemMakerId(), 30, 4)); vo.setModemModelId(VoV.valid(vo.getModemModelId(), 30, 4)); //vo.setDevNonAccPeriod(VoV.valid(vo.getDevNonAccPeriod(), )); vo.setPushRsvYn(VoV.valid(vo.getPushRsvYn(), 1, 10)); vo.setCretDtFrom(VoV.valid(vo.getCretDtFrom())); vo.setCretDtTo(VoV.valid(vo.getCretDtTo())); //------------------- vo = mySVC.search(vo); // - ? java-Ctrl ? - DMS ? FotastatSearchVO tempVo; if (vo.getResults() != null && vo.getResults().size() > 0) { for (int i = 0; i < vo.getResults().size(); i++) { tempVo = vo.getResults().get(i); if (tempVo.getCtn() != null && !tempVo.getCtn().isEmpty()) { tempVo.setCtn(Masking.convertCtn(tempVo.getCtn())); } // DB ? ? // if(tempVo.getClientNm() != null && !tempVo.getClientNm().isEmpty()) { // tempVo.setClientNm(Masking.convertClientName(tempVo.getClientNm())); // } } } model.addAttribute("gridData", vo.getResults()); model.addAttribute("resultsSize", vo.getTotalRows()); model.addAttribute("page", vo.getPage()); model.addAttribute("totalPage", vo.getTotalPage()); return new ModelAndView(ajaxMainView, model); } /** * FOTA ? * @param param * @param response * @return */ @RequestMapping(value = "/searchFotaProcessHistory") @ResponseBody public ModelAndView searchFotaProcessHistory(@ModelAttribute("fotastatHistoryVO") FotastatHistoryVO vo, ModelMap model) throws Exception { // validation check vo.setDevId(VoV.valid(vo.getDevId(), 30, 4)); //------------------- vo = mySVC.searchFotaProcessHistory(vo); model.addAttribute("gridData", vo.getResults()); return new ModelAndView(ajaxMainView, model); } /** * FOTA ? * @param param * @param response * @return */ @RequestMapping(value = "/addFota") @ResponseBody public ModelAndView addFota(HttpServletRequest request, ModelMap model) throws Exception { int max = Integer.valueOf(request.getParameter("selectionCnt")); String t = ""; String p = ""; String k = ""; List<String> idList = new ArrayList<String>(); List<String> fmidList = new ArrayList<String>(); List<String> fmverList = new ArrayList<String>(); String devId = ""; String firmwareId = ""; String firmwareVer = ""; for (int i = 1; i <= max; i++) { t = "id" + i; p = "firmId" + i; k = "firmVer" + i; // validation check devId = VoV.valid(request.getParameter(t), 30, 4); firmwareId = VoV.valid(request.getParameter(p), 30, 4); firmwareVer = VoV.valid(request.getParameter(k), 100, 4); //------------------- idList.add(devId); fmidList.add(firmwareId); fmverList.add(firmwareVer); } mySVC.addFota(idList, fmidList, fmverList, ((UserLoginVO) request.getSession().getAttribute("userInfo")).getUserId()); return new ModelAndView(ajaxMainView, model); } /** * FOTA * @param param * @param response * @return */ @RequestMapping(value = "/cancelFota") @ResponseBody public ModelAndView cancelFota(HttpServletRequest request, ModelMap model) throws Exception { int max = Integer.valueOf(request.getParameter("selectionCnt")); String t = ""; String p = ""; String k = ""; List<String> idList = new ArrayList<String>(); // ? ? List<String> fmidList = new ArrayList<String>(); // ? List<String> fmverList = new ArrayList<String>(); // String devId = ""; String firmwareId = ""; String firmwareVer = ""; for (int i = 1; i <= max; i++) { t = "id" + i; p = "firmId" + i; k = "firmVer" + i; // validation check devId = VoV.valid(request.getParameter(t), 30, 4); firmwareId = VoV.valid(request.getParameter(p), 30, 4); firmwareVer = VoV.valid(request.getParameter(k), 100, 4); //------------------- idList.add(devId); fmidList.add(firmwareId); fmverList.add(firmwareVer); } mySVC.cancelFota(idList, fmidList, fmverList); return new ModelAndView(ajaxMainView, model); } /** * * @param param * @param response * @return */ @RequestMapping(value = "/fotastatExcelDownload") // @ResponseBody public FotastatExcelDown excelDown( // @ModelAttribute("fotastatSearchVO") FotastatSearchVO vo, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { logger.warn("FotastatCTR - excelDown() start"); // VO URL ? ? // ? Model HttpServletRequest FotastatSearchVO vo = new FotastatSearchVO(); String tempFotaType = request.getParameter("fotaType"); if (!tempFotaType.equals("") && !tempFotaType.equals("PUSH") && !tempFotaType.equals("POLLING") && !tempFotaType.equals("PUSHPOLLING")) throw new Exception(); if (request.getParameter("page") != null && !request.getParameter("page").isEmpty()) { vo.setPage(request.getParameter("page")); } if (request.getParameter("rowsPerPage") != null && !request.getParameter("rowsPerPage").isEmpty()) { vo.setRowsPerPage(request.getParameter("rowsPerPage")); } if (request.getParameter("fotaYn") != null && !request.getParameter("fotaYn").isEmpty()) { vo.setFotaYn(request.getParameter("fotaYn")); } if (request.getParameter("processStatCd") != null && !request.getParameter("processStatCd").isEmpty()) { vo.setProcessStatCd(request.getParameter("processStatCd")); } if (request.getParameter("ctn") != null && !request.getParameter("ctn").isEmpty()) { vo.setCtn(request.getParameter("ctn")); } if (request.getParameter("fotaType") != null && !request.getParameter("fotaType").isEmpty()) { vo.setFotaType(request.getParameter("fotaType")); } if (request.getParameter("bizTypeId") != null && !request.getParameter("bizTypeId").isEmpty()) { vo.setBizTypeId(request.getParameter("bizTypeId")); } if (request.getParameter("svcId") != null && !request.getParameter("svcId").isEmpty()) { vo.setSvcId(request.getParameter("svcId")); } if (request.getParameter("devMakerId") != null && !request.getParameter("devMakerId").isEmpty()) { vo.setDevMakerId(request.getParameter("devMakerId")); } if (request.getParameter("devModelId") != null && !request.getParameter("devModelId").isEmpty()) { vo.setDevModelId(request.getParameter("devModelId")); } if (request.getParameter("modemMakerId") != null && !request.getParameter("modemMakerId").isEmpty()) { vo.setModemMakerId(request.getParameter("modemMakerId")); } if (request.getParameter("modemModelId") != null && !request.getParameter("modemModelId").isEmpty()) { vo.setModemModelId(request.getParameter("modemModelId")); } if (request.getParameter("clientNm") != null && !request.getParameter("clientNm").isEmpty()) { vo.setClientNm(request.getParameter("clientNm")); } if (request.getParameter("dealerNm") != null && !request.getParameter("dealerNm").isEmpty()) { vo.setDealerNm(request.getParameter("dealerNm")); } if (request.getParameter("cretDtFrom") != null && !request.getParameter("cretDtFrom").isEmpty()) { vo.setCretDtFrom(request.getParameter("cretDtFrom")); } if (request.getParameter("cretDtTo") != null && !request.getParameter("cretDtTo").isEmpty()) { vo.setCretDtTo(request.getParameter("cretDtTo")); } if (request.getParameter("devNonAccPeriod") != null && !request.getParameter("devNonAccPeriod").isEmpty()) { vo.setDevNonAccPeriod(request.getParameter("devNonAccPeriod")); } if (request.getParameter("pushRsvYn") != null && !request.getParameter("pushRsvYn").isEmpty()) { vo.setPushRsvYn(request.getParameter("pushRsvYn")); } // validation check vo.setBizTypeId(VoV.valid(vo.getBizTypeId(), 30, 4)); vo.setSvcId(VoV.valid(vo.getSvcId(), 30, 4)); vo.setDevMakerId(VoV.valid(vo.getDevMakerId(), 30, 4)); vo.setDevModelId(VoV.valid(vo.getDevModelId(), 30, 4)); vo.setFotaType(VoV.valid(vo.getFotaType(), 50)); if (!vo.getFotaType().equals("") && !vo.getFotaType().equals("PUSH") && !vo.getFotaType().equals("POLLING") && !vo.getFotaType().equals("PUSHPOLLING")) throw new Exception(); vo.setFotaYn(VoV.valid(vo.getFotaYn(), 1, 10)); vo.setProcessStatCd(VoV.valid(vo.getProcessStatCd(), 1, 12)); vo.setCtn(VoV.valid(vo.getCtn(), 20, 4)); vo.setClientNm(VoV.valid(vo.getClientNm(), 50, 4)); vo.setDealerNm(VoV.valid(vo.getDealerNm(), 50, 4)); vo.setModemMakerId(VoV.valid(vo.getModemMakerId(), 30, 4)); vo.setModemModelId(VoV.valid(vo.getModemModelId(), 30, 4)); //vo.setDevNonAccPeriod(VoV.valid(vo.getDevNonAccPeriod(), )); vo.setPushRsvYn(VoV.valid(vo.getPushRsvYn(), 1, 10)); vo.setCretDtFrom(VoV.valid(vo.getCretDtFrom())); vo.setCretDtTo(VoV.valid(vo.getCretDtTo())); //------------------- vo = mySVC.search(vo); model.addAttribute("resultData", vo.getResults()); return new FotastatExcelDown(); } /* FOTA ?? * *//** * FOTA ? * @param param * @param response * @return */ @RequestMapping(value = "/addFotaAll") @ResponseBody public ModelAndView addFotaAll(HttpServletRequest request, @ModelAttribute("fotastatSearchVO") FotastatSearchVO vo, ModelMap model) throws Exception { // validation check vo.setDevModelId(VoV.valid(vo.getDevModelId(), 30, 4)); //------------------- mySVC.addFotaAll(vo.getDevModelId(), ((UserLoginVO) request.getSession().getAttribute("userInfo")).getUserId()); return new ModelAndView(ajaxMainView, model); } /** * ? * ? ?. * @param vo * @param model * @return */ @RequestMapping(value = "/checkUploadExcelFile") public ModelAndView checkUploadExcelFile(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { // logger.warn(" >>>>>>>>>> FotastatCTR - uploadExcelFil() start ... "); String retMsg = ""; // ? ? File pysicalFolder = new File(PATH); if (!pysicalFolder.exists() || !pysicalFolder.isDirectory()) { pysicalFolder.mkdirs(); } // ? MultipartRequest multi = new MultipartRequest(request, PATH, SIZE, "utf-8"); String upFileName = multi.getFilesystemName("file"); // logger.warn("upFile : " + upFile); FotastatSearchVO vo = new FotastatSearchVO(); vo.setBizTypeId(VoV.valid(multi.getParameter("bizTypeId"), 30, 4)); vo.setSvcId(VoV.valid(multi.getParameter("svcId"), 30, 4)); vo.setDevMakerId(VoV.valid(multi.getParameter("devMakerId"), 30, 4)); vo.setDevModelId(VoV.valid(multi.getParameter("devModelId"), 30, 4)); vo.setModemMakerId(VoV.valid(multi.getParameter("modemMakerId"), 30, 4)); vo.setModemModelId(VoV.valid(multi.getParameter("modemModelId"), 30, 4)); vo.setDealerNm(VoV.valid(multi.getParameter("dealerNm"), 50, 2)); // logger.warn("value check...\r\n" // + "bizTypeId : " + vo.getBizTypeId() + "\r\n" // + "svcId : " + vo.getSvcId() + "\r\n" // + "DevMakerId : " + vo.getDevMakerId() + "\r\n" // + "DevModelId : " + vo.getDevModelId() + "\r\n" // + "ModemMakerId : " + vo.getModemMakerId() + "\r\n" // + "ModemModelId : " + vo.getModemModelId() + "\r\n" // + "DealerNm : " + vo.getDealerNm() + "\r\n" // ); // vo.setPage("1"); vo.setRowsPerPage("1000"); if (upFileName == null || upFileName.equals("")) { model.addAttribute("msg", "?? ."); return new ModelAndView(ajaxMainView, model); } // poi ? ? ? File upfile = new File(PATH + upFileName); // poi try { FileInputStream file = new FileInputStream(upfile); //.xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); // XSSFSheet sheet = workbook.getSheetAt(0); // Iterator<Row> rowIterator = sheet.iterator(); // ? ? ctn list ? List<String> ctnList = new ArrayList<String>(); // ? rowIterator.next(); String tempCtn = ""; while (rowIterator.hasNext()) { Row row = rowIterator.next(); //For each row, iterate through all the columns Iterator<Cell> cellIterator = row.cellIterator(); tempCtn = ""; // ctn Cell cell = row.getCell(0); tempCtn = cell.toString().trim(); ctnList.add(tempCtn); } // ? ctn ? // db ? ctn vo = mySVC.search(vo); List<String> checkedCtnList = new ArrayList<String>(); int checkCount = 0; int fotaPossibilityCount = 0; for (int i = 0; i < ctnList.size(); i++) { for (int j = 0; j < vo.getResults().size(); j++) { if (ctnList.get(i).equals(vo.getResults().get(j).getCtn())) { checkedCtnList.add(ctnList.get(i)); checkCount++; // P(), S(), V(?) FOTA // W(), E(?), F() if (!((vo.getResults().get(j).getProcessStatCd().equals("") || vo.getResults().get(j).getProcessStatCd().equals("P")) || (vo.getResults().get(j).getProcessStatCd().equals("") || vo.getResults().get(j).getProcessStatCd().equals("S")) || (vo.getResults().get(j).getProcessStatCd().equals("?") || vo.getResults().get(j).getProcessStatCd().equals("V")))) { fotaPossibilityCount++; } } } } retMsg = " : " + ctnList.size() + "\r\n" + "? : " + checkCount + "\r\n" + " ? : " + (ctnList.size() - checkCount) + "\r\n" + " (? : " + fotaPossibilityCount + ")"; file.close(); upfile.delete(); model.addAttribute("retMsg", retMsg); model.addAttribute("checkedCtnList", checkedCtnList); model.addAttribute("fotaPossibilityCount", fotaPossibilityCount); } catch (Exception e) { logger.warn("?? ? ."); e.printStackTrace(); upfile.delete(); model.addAttribute("msg", "?? ? ."); } return new ModelAndView(ajaxMainView, model); } @RequestMapping(value = "/searchUploadExcelFileCtnInfo") @ResponseBody public ModelAndView searchUploadExcelFileCtnInfo(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { // ? ? File pysicalFolder = new File(PATH); if (!pysicalFolder.exists() || !pysicalFolder.isDirectory()) { pysicalFolder.mkdirs(); } // logger.warn("FotastatCTR - searchUploadExcelFileCtnInfo() start..."); // ? MultipartRequest multi = new MultipartRequest(request, PATH, SIZE, "utf-8"); FotastatSearchVO vo = new FotastatSearchVO(); vo.setBizTypeId(VoV.valid(multi.getParameter("bizTypeId"), 30, 4)); vo.setSvcId(VoV.valid(multi.getParameter("svcId"), 30, 4)); vo.setDevMakerId(VoV.valid(multi.getParameter("devMakerId"), 30, 4)); vo.setDevModelId(VoV.valid(multi.getParameter("devModelId"), 30, 4)); vo.setModemMakerId(VoV.valid(multi.getParameter("modemMakerId"), 30, 4)); vo.setModemModelId(VoV.valid(multi.getParameter("modemModelId"), 30, 4)); vo.setDealerNm(VoV.valid(multi.getParameter("dealerNm"), 50, 2)); vo.setPage(multi.getParameter("page")); vo.setRowsPerPage(multi.getParameter("rowsPerPage")); String tempCtnList = multi.getParameter("checkedCtnList"); // logger.warn("FotastatCTR - searchUploadExcelFileCtnInfo() vo info..." // + "bizTypeId : " + vo.getBizTypeId() + "\r\n" // + "svcId : " + vo.getSvcId() + "\r\n" // + "devMakerId : " + vo.getDevMakerId() + "\r\n" // + "devModelId : " + vo.getDevModelId() + "\r\n" // + "modemMakerId : " + vo.getModemMakerId() + "\r\n" // + "modemModelId : " + vo.getModemModelId() + "\r\n" // + "dealerNm : " + vo.getDealerNm() + "\r\n" // + "page : " + vo.getPage() + "\r\n" // + "rowsPerPage : " + vo.getRowsPerPage() + "\r\n" // + "checkedCtnList : " + tempCtnList + "\r\n" // ); String[] tempCtnListSplit = tempCtnList.split("\\^\\^"); vo.setCheckedCtnList(tempCtnListSplit); vo = mySVC.searchExcelFileUpload(vo); model.addAttribute("gridData", vo.getResults()); model.addAttribute("resultsSize", vo.getTotalRows()); model.addAttribute("page", vo.getPage()); model.addAttribute("totalPage", vo.getTotalPage()); model.addAttribute("uploadLength", vo.getResults().size()); return new ModelAndView(ajaxMainView, model); } }