Java tutorial
/* * Copyright 2011 MOPAS(Ministry of Public Administration and Security). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package egovframework.rte.tex.gds.service.impl; import java.io.File; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import egovframework.rte.fdl.cmmn.AbstractServiceImpl; import egovframework.rte.fdl.idgnr.EgovIdGnrService; import egovframework.rte.tex.com.service.SearchVO; import egovframework.rte.tex.gds.service.EgovGoodsService; import egovframework.rte.tex.gds.service.GoodsImageVO; import egovframework.rte.tex.gds.service.GoodsVO; /** * ? ? ?. * * @author ?? * @since 2011.06.07 * @version 1.0 * @see <pre> * == ?(Modification Information) == * * ? ? * ------- -------- --------------------------- * 2011.06.07 ?? ? * * </pre> */ @Service("goodsService") public class EgovGoodsServiceImpl extends AbstractServiceImpl implements EgovGoodsService { /** GoodsDAO */ @Resource(name = "goodsDAO") private GoodsDAO goodsDAO; /** goodsID Generation */ @Resource(name = "egovIdGnrServiceGds") private EgovIdGnrService egovIdGnrServiceGds; /** fileUploadProperties */ @Resource(name = "fileUploadProperties") Properties fileUploadProperties; /** * . * @param searchVO * @return List<GoodsVO> * @throws Exception */ public List<GoodsVO> selectGoodsList(SearchVO searchVO) throws Exception { return goodsDAO.selectGoodsList(searchVO); } /** * ?. * @param goodsVO ?? * @return String * @throws Exception */ public String insertGoods(GoodsVO goodsVO) throws Exception { log.debug(goodsVO.toString()); goodsDAO.insertGoodsImage(goodsVO.getGoodsImageVO()); goodsDAO.insertGoodsImage(goodsVO.getDetailImageVO()); /** ID Generation Service */ String id = egovIdGnrServiceGds.getNextStringId(); goodsVO.setGoodsId(id); log.debug(goodsVO.toString()); goodsDAO.insertGoods(goodsVO); return id; } /** * ? . * @param goodsVO * @return GoodsVO ? * @throws Exception */ public GoodsVO selectGoods(GoodsVO goodsVO) throws Exception { GoodsVO resultVO = goodsDAO.selectGoods(goodsVO); log.debug(resultVO); if (resultVO == null) throw processException("info.nodata.msg"); return resultVO; } /** * ? ? . * @param request * @param goodsVO * @throws Exception */ public void updateGoods(GoodsVO goodsVO, final HttpServletRequest request) throws Exception { final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; GoodsImageVO[] imageList = new GoodsImageVO[2]; // extract files final Map<String, MultipartFile> files = multiRequest.getFileMap(); // process files String uploadLastPath = fileUploadProperties.getProperty("file.upload.path"); String uploadPath = request.getSession().getServletContext().getRealPath("/") + uploadLastPath; File saveFolder = new File(uploadPath); // ? boolean isDir = false; if (!saveFolder.exists() || saveFolder.isFile()) { saveFolder.mkdirs(); } if (!isDir) { Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator(); MultipartFile file; String filePath; int i = 0; // goodsImage,detailImage index while (itr.hasNext()) { // ?? Entry<String, MultipartFile> entry = itr.next(); file = entry.getValue(); if (!"".equals(file.getOriginalFilename())) { String saveFileName; if (i == 0) { saveFileName = goodsVO.getGoodsImageVO().getGoodsImageId(); } else { saveFileName = goodsVO.getDetailImageVO().getGoodsImageId(); } imageList[i] = new GoodsImageVO(saveFileName, file.getOriginalFilename()); // ? filePath = uploadPath + "\\" + saveFileName; file.transferTo(new File(filePath)); } i++; } } if (imageList[0] != null) goodsVO.setGoodsImageVO(imageList[0]); if (imageList[1] != null) goodsVO.setDetailImageVO(imageList[1]); goodsDAO.updateGoods(goodsVO); } /** * ? . * @param goodsVO * @param request * @throws Exception */ public void deleteGoods(GoodsVO goodsVO, final HttpServletRequest request) throws Exception { goodsDAO.deleteGoods(goodsVO); //?( ) goodsDAO.deleteGoodsCart(goodsVO); //?? ? } /** * ? . * @param searchVO * @return int ? */ public int selectGoodsListTotCnt(SearchVO searchVO) { return goodsDAO.selectGoodsListTotCnt(searchVO); } /** * .(xml, excel) * @return List<GoodsVO> ? * @throws Exception */ public List<GoodsVO> selectGoodsXml() throws Exception { return goodsDAO.selectGoodsXml(); } }