| | |
| | | package kr.wisestone.owl.service.impl; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | import kr.wisestone.owl.common.ExcelConditionCheck; |
| | | import kr.wisestone.owl.constant.Constants; |
| | | import kr.wisestone.owl.constant.MngPermission; |
| | | import kr.wisestone.owl.constant.MsgConstants; |
| | | import kr.wisestone.owl.domain.Guide; |
| | | import kr.wisestone.owl.domain.User; |
| | | import kr.wisestone.owl.domain.UserLevel; |
| | | import kr.wisestone.owl.exception.OwlRuntimeException; |
| | | import kr.wisestone.owl.mapper.GuideMapper; |
| | | import kr.wisestone.owl.repository.GuideRepository; |
| | | import kr.wisestone.owl.service.GuideService; |
| | | import kr.wisestone.owl.service.UserLevelService; |
| | | import kr.wisestone.owl.service.UserWorkspaceService; |
| | | import kr.wisestone.owl.service.WorkspaceService; |
| | | import kr.wisestone.owl.util.CommonUtil; |
| | | import kr.wisestone.owl.util.ConvertUtil; |
| | | import kr.wisestone.owl.vo.GuideVo; |
| | | import kr.wisestone.owl.vo.ManageUserVo; |
| | | import kr.wisestone.owl.vo.ResPage; |
| | | import kr.wisestone.owl.vo.*; |
| | | import kr.wisestone.owl.web.condition.GuideCondition; |
| | | import kr.wisestone.owl.web.condition.NoticeCondition; |
| | | import kr.wisestone.owl.web.form.GuideForm; |
| | | import kr.wisestone.owl.web.form.NoticeForm; |
| | | import kr.wisestone.owl.web.view.ExcelView; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.jpa.repository.JpaRepository; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Autowired |
| | | private GuideMapper guideMapper; |
| | | |
| | | @Autowired |
| | | private WorkspaceService workspaceService; |
| | | |
| | | @Autowired |
| | | private ExcelView excelView; |
| | | |
| | | @Autowired |
| | | private ExcelConditionCheck excelConditionCheck; |
| | | |
| | | @Autowired |
| | | private UserLevelService userLevelService; |
| | | |
| | | @Autowired |
| | | private UserWorkspaceService userWorkspaceService; |
| | | |
| | | @Override |
| | | protected JpaRepository<Guide, Long> getRepository() { |
| | |
| | | guideCondition.setPageSize(pageable.getPageSize()); |
| | | guideCondition.setTitle(guideCondition.getTitle()); |
| | | |
| | | List<Map<String, Object>> results = this.guideMapper.find(guideCondition); |
| | | Long totalCount = this.guideMapper.count(guideCondition); |
| | | User user = this.webAppUtil.getLoginUserObject(); |
| | | UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId()); |
| | | |
| | | List<Map<String, Object>> results = Lists.newArrayList(); |
| | | Long totalCount = 0L; |
| | | if (this.userWorkspaceService.checkWorkspaceManager(user) |
| | | || MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_GUIDE)) { |
| | | results = this.guideMapper.find(guideCondition); |
| | | totalCount = this.guideMapper.count(guideCondition); |
| | | } else { |
| | | results = this.guideMapper.findNotActivation(guideCondition); |
| | | totalCount = this.guideMapper.countNotActivation(guideCondition); |
| | | } |
| | | int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1; |
| | | List<GuideVo> guideVos = ConvertUtil.convertListToListClass(results, GuideVo.class); |
| | | |
| | |
| | | |
| | | resJsonData.put(Constants.RES_KEY_CONTENTS, guideVo); |
| | | } |
| | | |
| | | @Override |
| | | public void remove(GuideForm guideForm) { |
| | | if (guideForm.getRemoveIds().size() < 1) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANY_REMOVE_NOT_SELECT)); |
| | | } |
| | | for (Long id : guideForm.getRemoveIds()) { |
| | | this.guideRepository.deleteById(id); |
| | | this.guideRepository.flush(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ModelAndView downloadExcel(HttpServletRequest request, Model model) { |
| | | ModelAndView modelAndView = this.workspaceService.checkUseExcelDownload(model); |
| | | if (modelAndView != null) { |
| | | return modelAndView; |
| | | } |
| | | |
| | | Map<String, Object> conditions = new HashMap<>(); |
| | | // 엑셀 다운로드에 필요한 검색 조건 정보를 추출하고 검색 조건 추출에 오류가 발생하면 경고를 표시해준다. |
| | | modelAndView = this.excelConditionCheck.checkCondition(conditions, request, model); |
| | | if (modelAndView != null) { |
| | | return modelAndView; |
| | | } |
| | | |
| | | GuideCondition guideCondition = GuideCondition.make(conditions); |
| | | List<Map<String, Object>> results = this.guideMapper.find(guideCondition); |
| | | List<GuideVo> guideVos = ConvertUtil.convertListToListClass(results, GuideVo.class); |
| | | |
| | | // code_ko_KR 에 code명 설정 |
| | | ExportExcelVo excelInfo = new ExportExcelVo(); |
| | | excelInfo.setFileName(this.messageAccessor.message("가이드 목록")); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("title", this.messageAccessor.message("guide.title"), 6, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("registerDate", this.messageAccessor.message("guide.registerDate"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("writer", this.messageAccessor.message("guide.registerId"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | |
| | | excelInfo.setDatas(guideVos); |
| | | |
| | | model.addAttribute(Constants.EXCEL, excelInfo); |
| | | return new ModelAndView(this.excelView); |
| | | } |
| | | } |