package com.pms.service; import java.sql.Clob; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.ibatis.session.SqlSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.pms.common.Message; import com.pms.common.SqlMapConfig; import com.pms.common.bean.PersonBean; import com.pms.common.utils.CommonUtils; import com.pms.common.utils.Constants; import com.pms.common.utils.MailUtil; @Service public class StructureReviewReportService { CommonService commonService = null; @Autowired public void setCommonService(CommonService commonService){ this.commonService = commonService; } /** * 등록Form 차종목록 조회 * @param paramMap * @return */ public List getCarList(Map paramMap){ List resultList = new ArrayList(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); resultList = sqlSession.selectList("structureReviewReport.getCarMngList", paramMap); }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultList; } /** * 등록Form 제품목록 조회 * @param paramMap * @return */ public List getProductList(Map paramMap){ List resultList = new ArrayList(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); resultList = sqlSession.selectList("structureReviewReport.getProductMngList", paramMap); }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultList; } /** * 구조검토제안서 저장 * @param request * @param paramMap */ public Map saveReport(HttpServletRequest request, Map paramMap){ Map resultMap = new HashMap(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); PersonBean person = (PersonBean)request.getSession().getAttribute(Constants.PERSON_BEAN); paramMap.put("writer", CommonUtils.checkNull(person.getUserId())); String objId = CommonUtils.checkNull(paramMap.get("objId")); if("".equals(objId)){ objId = CommonUtils.createObjId(); paramMap.put("objId", objId); } int cnt = sqlSession.update("structureReviewReport.saveReport", paramMap); if(cnt > 0){ resultMap.put("success", true); resultMap.put("msg", Message.SAVE_SUCCESS); }else{ resultMap.put("success", false); resultMap.put("msg", Message.SAVE_FAILED); } }catch(Exception e){ resultMap.put("success", false); resultMap.put("msg", Message.SAVE_FAILED); e.printStackTrace(); }finally{ sqlSession.close(); } return resultMap; } /** * 구조검토제안서 조회 * @param request * @param paramMap * @return */ public List getStructureReviewReportList(HttpServletRequest request, Map paramMap){ List resultList = new ArrayList(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); resultList = sqlSession.selectList("structureReviewReport.getStructureReviewReportList", paramMap); for(Map map : resultList){ map.put("PROBLEM_CONTENTS", CommonUtils.getClobToString((Clob)map.get("PROBLEM_CONTENTS"))); map.put("SUGGEST_CONTENTS", CommonUtils.getClobToString((Clob)map.get("SUGGEST_CONTENTS"))); Map fileMap = new HashMap(); fileMap.put("targetObjId", map.get("OBJID")); ArrayList fileList = commonService.getFileList(fileMap); for(int i = 0 ; i < fileList.size() ; i++){ Map fileResultMap = (HashMap)fileList.get(i); String docType = CommonUtils.checkNull(fileResultMap.get("DOC_TYPE")); if("STR_PROBLEM_ATTACH".equals(docType)){ map.put("STR_PROBLEM_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_PROBLEM_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_PROBLEM_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_PROBLEM_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); }else if("STR_SUGGEST_ATTACH".equals(docType)) { map.put("STR_SUGGEST_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_SUGGEST_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_SUGGEST_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_SUGGEST_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); } } } }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultList; } /** * 구조검토제안서 작성중 목록 * @param request * @param paramMap * @return */ public List getStructureReviewReportTempList(HttpServletRequest request, Map paramMap){ List resultList = new ArrayList(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); PersonBean person = (PersonBean)request.getSession().getAttribute(Constants.PERSON_BEAN); paramMap.put("writer", CommonUtils.checkNull(person.getUserId())); resultList = sqlSession.selectList("structureReviewReport.getStructureReviewReportTempList", paramMap); for(Map map : resultList){ map.put("PROBLEM_CONTENTS", CommonUtils.getClobToString((Clob)map.get("PROBLEM_CONTENTS"))); map.put("SUGGEST_CONTENTS", CommonUtils.getClobToString((Clob)map.get("SUGGEST_CONTENTS"))); Map fileMap = new HashMap(); fileMap.put("targetObjId", map.get("OBJID")); ArrayList fileList = commonService.getFileList(fileMap); for(int i = 0 ; i < fileList.size() ; i++){ Map fileResultMap = (HashMap)fileList.get(i); String docType = CommonUtils.checkNull(fileResultMap.get("DOC_TYPE")); if("STR_PROBLEM_ATTACH".equals(docType)){ map.put("STR_PROBLEM_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_PROBLEM_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_PROBLEM_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_PROBLEM_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); }else if("STR_SUGGEST_ATTACH".equals(docType)) { map.put("STR_SUGGEST_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_SUGGEST_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_SUGGEST_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_SUGGEST_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); } } } }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultList; } /** * 구조검토제안서 제안완료 목록 * @param request * @param paramMap * @return */ public List getStructureReviewReportSuggestCompleteList(HttpServletRequest request, Map paramMap){ List resultList = new ArrayList(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); PersonBean person = (PersonBean)request.getSession().getAttribute(Constants.PERSON_BEAN); paramMap.put("writer", CommonUtils.checkNull(person.getUserId())); resultList = sqlSession.selectList("structureReviewReport.getStructureReviewReportSuggestCompleteList", paramMap); for(Map map : resultList){ map.put("PROBLEM_CONTENTS", CommonUtils.getClobToString((Clob)map.get("PROBLEM_CONTENTS"))); map.put("SUGGEST_CONTENTS", CommonUtils.getClobToString((Clob)map.get("SUGGEST_CONTENTS"))); Map fileMap = new HashMap(); fileMap.put("targetObjId", map.get("OBJID")); ArrayList fileList = commonService.getFileList(fileMap); for(int i = 0 ; i < fileList.size() ; i++){ Map fileResultMap = (HashMap)fileList.get(i); String docType = CommonUtils.checkNull(fileResultMap.get("DOC_TYPE")); if("STR_PROBLEM_ATTACH".equals(docType)){ map.put("STR_PROBLEM_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_PROBLEM_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_PROBLEM_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_PROBLEM_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); }else if("STR_SUGGEST_ATTACH".equals(docType)) { map.put("STR_SUGGEST_ATTACH_FILE_PATH", CommonUtils.checkNull(fileResultMap.get("FILE_PATH"))); map.put("STR_SUGGEST_ATTACH_SAVED_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("SAVED_FILE_NAME"))); map.put("STR_SUGGEST_ATTACH_UPPER_FILE_EXT", CommonUtils.checkNull(fileResultMap.get("UPPER_FILE_EXT"))); map.put("STR_SUGGEST_ATTACH_REAL_FILE_NAME", CommonUtils.checkNull(fileResultMap.get("REAL_FILE_NAME"))); } } } }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultList; } /** * 구조검토제안서 상세 * @param paramMap * @return */ public Map getStructureReviewReportInfo(Map paramMap){ Map resultMap = new HashMap(); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); resultMap = sqlSession.selectOne("structureReviewReport.getStructureReviewReportInfo", paramMap); if(resultMap != null && !resultMap.isEmpty()){ resultMap.put("PROBLEM_CONTENTS", CommonUtils.getClobToString((Clob)resultMap.get("PROBLEM_CONTENTS"))); resultMap.put("SUGGEST_CONTENTS", CommonUtils.getClobToString((Clob)resultMap.get("SUGGEST_CONTENTS"))); } }catch(Exception e){ e.printStackTrace(); }finally{ sqlSession.close(); } return resultMap; } /** * 구조검토제안서 확정(완료) * @param paramMap * @return */ public Map completeStructureReviewReportInfo(Map paramMap){ Map resultMap = new HashMap(); SqlSession sqlSession = null; System.out.println("paramMap : "+paramMap); try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(); int cnt = sqlSession.update("structureReviewReport.completeStructureReviewReportInfo", paramMap); if(cnt > 0){ resultMap.put("result", true); resultMap.put("msg", Message.COMPLETE_SUCCESS); }else{ resultMap.put("result", false); resultMap.put("msg", Message.FAILED); } }catch(Exception e){ resultMap.put("result", false); resultMap.put("msg", Message.FAILED); e.printStackTrace(); }finally{ sqlSession.close(); } return resultMap; } /** * 구조검토제안서 제안완료 메일발송 * @param request * @param paramMap */ public Map sendSuggestCompleteMail(HttpServletRequest request, Map paramMap){ Map resultMap = new HashMap(); PersonBean person = (PersonBean)request.getSession().getAttribute(Constants.PERSON_BEAN); String sendUserId = CommonUtils.checkNull(person.getUserId()); SqlSession sqlSession = null; try{ sqlSession = SqlMapConfig.getInstance().getSqlSession(false); //1. 수신처 확인 String[] receivers = request.getParameterValues("chk"); for(String receiverStr : receivers){ String[] receiverArr = receiverStr.split(":"); String receptionUserId = receiverArr[0]; String receiverTo = receiverArr[1]; System.out.println("1. send mail receiver check.."); System.out.println("receptionUserId : "+receptionUserId+", receiverTo : "+receiverTo); //2. 구조검토제안서 상태변경 (create => suggestComplete) String targetObjIdStr = CommonUtils.checkNull(paramMap.get("targetObjId")); System.out.println("2. target object id check.."); System.out.println("total targetObjId : "+targetObjIdStr); if(targetObjIdStr.indexOf(",") > -1){ //여러건일때 String[] targetObjIds = targetObjIdStr.split(","); int cnt = targetObjIds.length; System.out.println("target object count : "+cnt); for(String targetObjId : targetObjIds){ System.out.println("targetObjId : "+targetObjId); int updateCnt = sqlSession.update("structureReviewReport.updateStructureReviewReportSuggestComplete", targetObjId); } //3. 메일발송 MailUtil.sendMail(sendUserId, Constants.FROM_ADDR, receptionUserId, receiverTo, null, null, null, "test title", "test contents", Constants.MAIL_TYPE_STRUCTURE_REVIEW_REPORT_SUGGEST_COMPLETE); }else{ //단건일때 sqlSession.update("structureReviewReport.updateStructureReviewReportSuggestComplete", targetObjIdStr); //3. 메일발송 MailUtil.sendMail(sendUserId, Constants.FROM_ADDR, receptionUserId, receiverTo, null, null, null, "test title", "test contents", Constants.MAIL_TYPE_STRUCTURE_REVIEW_REPORT_SUGGEST_COMPLETE); } } resultMap.put("result", true); resultMap.put("msg", Message.SEND_MAIL_SUCCESS); sqlSession.commit(); }catch(Exception e){ resultMap.put("result", false); resultMap.put("msg", Message.STRUCTURE_REVIEW_REPORT_SUGGEST_COMPLETE_SEND_MAIL_FAILED); sqlSession.rollback(); e.printStackTrace(); }finally{ sqlSession.close(); } return resultMap; } }