package kr.wisestone.owl.service.impl;
|
|
import com.google.common.collect.Lists;
|
import kr.wisestone.owl.common.ExcelConditionCheck;
|
import kr.wisestone.owl.config.kafka.KafkaSender;
|
import kr.wisestone.owl.constant.Constants;
|
import kr.wisestone.owl.constant.MngPermission;
|
import kr.wisestone.owl.constant.MsgConstants;
|
import kr.wisestone.owl.domain.Faq;
|
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.FaqMapper;
|
import kr.wisestone.owl.mapper.NoticeMapper;
|
import kr.wisestone.owl.repository.FaqRepository;
|
import kr.wisestone.owl.service.*;
|
import kr.wisestone.owl.util.ConvertUtil;
|
import kr.wisestone.owl.vo.*;
|
import kr.wisestone.owl.web.condition.FaqCondition;
|
import kr.wisestone.owl.web.condition.NoticeCondition;
|
import kr.wisestone.owl.web.form.FaqForm;
|
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;
|
|
@Service
|
public class FaqServiceImpl extends AbstractServiceImpl<Faq, Long, JpaRepository<Faq, Long>> implements FaqService {
|
|
@Autowired
|
private FaqRepository faqRepository;
|
|
@Autowired
|
private UserService userService;
|
|
@Autowired
|
private KafkaSender kafkaSender;
|
|
@Autowired
|
private FaqMapper faqMapper;
|
|
@Autowired
|
private WorkspaceService workspaceService;
|
|
@Autowired
|
private UserLevelService userLevelService;
|
|
@Autowired
|
private UserWorkspaceService userWorkspaceService;
|
|
@Autowired
|
private ExcelView excelView;
|
|
@Autowired
|
private ExcelConditionCheck excelConditionCheck;
|
|
@Override
|
protected JpaRepository<Faq, Long> getRepository() {
|
return this.faqRepository;
|
}
|
|
// 공지 사항 등록
|
@Override
|
@Transactional
|
public Faq addFaq(FaqForm faqForm) {
|
// faq 제목 및 내용 공백 체크
|
this.verifyTitleAndDescription(faqForm.getTitle(), faqForm.getDescription());
|
|
faqForm.setStatus(Faq.INACTIVATION);
|
Faq faq = ConvertUtil.copyProperties(faqForm, Faq.class);
|
|
return this.faqRepository.saveAndFlush(faq);
|
}
|
|
// faq 제목 및 내용 공백 체크
|
private void verifyTitleAndDescription(String title, String description) {
|
if (StringUtils.isEmpty(title) || StringUtils.isEmpty(description)) {
|
throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.FAQ_EMPTY_CONTENT));
|
}
|
}
|
|
// faq 조회
|
@Override
|
@Transactional(readOnly = true)
|
public List<FaqVo> findFaq(Map<String, Object> resJsonData,
|
FaqCondition faqCondition, Pageable pageable) {
|
|
faqCondition.setPage(pageable.getPageNumber() * pageable.getPageSize());
|
faqCondition.setPageSize(pageable.getPageSize());
|
faqCondition.setTitle(faqCondition.getTitle());
|
|
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_FAQ)) {
|
results = this.faqMapper.find(faqCondition);
|
totalCount = this.faqMapper.count(faqCondition);
|
} else {
|
results = this.faqMapper.findNotActivation(faqCondition);
|
totalCount = this.faqMapper.countNotActivation(faqCondition);
|
}
|
int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
|
List<FaqVo> faqVos = ConvertUtil.convertListToListClass(results, FaqVo.class);
|
|
// faq 아이디 1 은 관리자 - 관리자만 수정 가능
|
for (FaqVo faqVo : faqVos) {
|
Boolean bActivation = false;
|
|
if(faqVo.getStatus().equals(Faq.ACTIVATION)) {
|
bActivation = true;
|
}
|
faqVo.activation = bActivation;
|
}
|
|
resJsonData.put(Constants.RES_KEY_CONTENTS, faqVos);
|
resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
|
totalPage, totalCount));
|
|
return faqVos;
|
}
|
|
// faq 수정
|
@Override
|
@Transactional
|
public Faq modifyFaq(FaqForm faqForm) {
|
// 공지사항 제목 및 내용 공백 체크
|
this.verifyTitleAndDescription(faqForm.getTitle(), faqForm.getDescription());
|
|
Faq faq = this.getFaq(faqForm.getId());
|
ConvertUtil.copyProperties(faqForm, faq, "id");
|
|
return this.faqRepository.saveAndFlush(faq);
|
}
|
|
// faq 수정
|
@Override
|
@Transactional
|
public Faq activeFaq(FaqForm faqForm) {
|
|
boolean bActivation = faqForm.getActivation();
|
|
if(bActivation) {
|
faqForm.setStatus(Faq.ACTIVATION);
|
} else {
|
faqForm.setStatus(Faq.INACTIVATION);
|
}
|
|
Faq faq = this.getFaq(faqForm.getId());
|
ConvertUtil.copyProperties(faqForm, faq, "id");
|
|
return this.faqRepository.saveAndFlush(faq);
|
}
|
|
// faq id 로 조회한다.
|
@Override
|
@Transactional(readOnly = true)
|
public Faq getFaq(Long id) {
|
if (id == null) {
|
throw new OwlRuntimeException(
|
this.messageAccessor.getMessage(MsgConstants.FAQ_NOT_EXIST));
|
}
|
|
Faq faq = this.findOne(id);
|
|
if (faq == null) {
|
throw new OwlRuntimeException(
|
this.messageAccessor.getMessage(MsgConstants.FAQ_NOT_EXIST));
|
}
|
|
return faq;
|
}
|
|
// faq 상세 정보를 조회한다.
|
@Override
|
@Transactional(readOnly = true)
|
public void detailFaq(Map<String, Object> resJsonData, FaqCondition faqCondition) {
|
FaqVo faqVo = new FaqVo();
|
|
if (faqCondition.getId() != null) {
|
Faq faq = this.getFaq(faqCondition.getId());
|
faqVo = ConvertUtil.copyProperties(faq, FaqVo.class);
|
}
|
|
resJsonData.put(Constants.RES_KEY_CONTENTS, faqVo);
|
}
|
|
@Override
|
public void remove(FaqForm faqForm) {
|
if (faqForm.getRemoveIds().size() < 1) {
|
throw new OwlRuntimeException(
|
this.messageAccessor.getMessage(MsgConstants.COMPANY_REMOVE_NOT_SELECT));
|
}
|
for (Long id : faqForm.getRemoveIds()) {
|
this.faqRepository.deleteById(id);
|
this.faqRepository.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;
|
}
|
|
FaqCondition faqCondition = FaqCondition.make(conditions);
|
List<Map<String, Object>> results = this.faqMapper.find(faqCondition);
|
List<FaqVo> faqVos = ConvertUtil.convertListToListClass(results, FaqVo.class);
|
|
// code_ko_KR 에 code명 설정
|
ExportExcelVo excelInfo = new ExportExcelVo();
|
excelInfo.setFileName(this.messageAccessor.message("FAQ 목록"));
|
excelInfo.addAttrInfos(new ExportExcelAttrVo("title", this.messageAccessor.message("faq.title"), 6, ExportExcelAttrVo.ALIGN_CENTER));
|
excelInfo.addAttrInfos(new ExportExcelAttrVo("registerDate", this.messageAccessor.message("faq.registerDate"), 10, ExportExcelAttrVo.ALIGN_CENTER));
|
excelInfo.addAttrInfos(new ExportExcelAttrVo("writer", this.messageAccessor.message("faq.registerId"), 10, ExportExcelAttrVo.ALIGN_CENTER));
|
|
excelInfo.setDatas(faqVos);
|
|
model.addAttribute(Constants.EXCEL, excelInfo);
|
return new ModelAndView(this.excelView);
|
}
|
}
|