package platform.modules.home.service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.models.auth.In; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import platform.common.Constant; import platform.common.base.model.DictionaryItem; import platform.common.base.service.DictionaryItemService; import platform.common.util.ShiroUtils; import platform.modules.government.dto.FeedbackQuery; import platform.modules.government.entity.*; import platform.modules.government.service.*; import platform.modules.home.dto.HomeRefactorDto; import platform.modules.home.request.FindRequest; import platform.modules.sys.entity.ActivityDetail; import platform.modules.sys.entity.ActivityFavourite; import platform.modules.sys.entity.ActivityFeedback; import platform.modules.sys.entity.ActivityReview; import platform.modules.sys.service.*; import platform.modules.sys.web.ResponseMessage; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; /** * @author kevin * @since 2019/5/21 3:45 PM */ @Service public class HomeRefactorService { @Autowired private ContentService contentService; @Autowired private ActivityService activityService; @Autowired private ProjectDeclarationService projectDeclarationService; @Autowired private ProjectFillingDeclarationService projectFillingDeclarationService; @Autowired private DictionaryItemService dictionaryItemService; @Autowired private ProjectProvincesDeclarationService projectProvincesDeclarationService; @Autowired private AttachmentService attachmentService; @Autowired private ActivityReviewService activityReviewService; @Autowired private ActivityFeedbackService activityFeedbackService; @Autowired private DepartmentService departmentService; @Autowired private ActivityFavouriteService activityFavouriteService; /** * 门户首页信息 * * @return */ public HomeRefactorDto findHomeIndex() { HomeRefactorDto refactor = new HomeRefactorDto(); FindRequest request = new FindRequest(); request.setPage_size(1); request.setId(64); refactor.setMessage(contentService.findContentList(request).get(0)); request.setId(1); refactor.setActivity(activityService.findContentList(request).getList().get(0)); request.setId(69); request.setType(""); refactor.setProject(projectDeclarationService.findProjectList(request).getList().get(0)); return refactor; } /** * content列表 * * @param request * @return */ public PageInfo findContentList(FindRequest request) { PageHelper.startPage(request.getPage_no(), request.getPage_size()); return new PageInfo<>(contentService.findContentList(request)); } /** * 详情 * * @param id * @return */ public Content contentDeatil(Integer id) { Content content = contentService.findById(id); if (null == content.getBrowse_count()) { content.setBrowse_count(0); } List fileDowns = new ArrayList<>(); List files = attachmentService.selectByIdAndBusinessId(Constant.Attachment.CONTENT_FILE, content.getId(), null); if (null != files && files.size() > 0) { FileDown addFileDown = new FileDown(files.get(0).getId(), files.get(0).getFile_name(), files.get(0).getFile_url(), files.get(0).getDownload_uri()); content.setAddFileDown(addFileDown); for (Attachment file : files) { FileDown fileDown = new FileDown(file.getId(), file.getFile_name(), file.getFile_url(), file.getDownload_uri()); fileDowns.add(fileDown); } } content.setFileDowns(fileDowns); content.setContent(StringEscapeUtils.unescapeHtml4(content.getContent())); //更新数量 content.setBrowse_count(content.getBrowse_count() + 1); contentService.updateSelective(content); return content; } /** * 项目申报详情 * * @param id * @return */ public ResponseMessage findProjectDetail(Integer id, Integer isFilling) { if (isFilling == 0){ //项目申报 ProjectDeclaration project = projectDeclarationService.selectById(String.valueOf(id)); if (project != null){ String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source()); project.setProject_source_name(sourceName); project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content())); //项目来源 String source = project.getProject_source(); if (StringUtils.isNotBlank(source)) { DictionaryItem sourceItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, source); if (null != sourceItem) { project.setProject_source_name(sourceItem.getName()); } } if (null == project.getBrowse_count()) { project.setBrowse_count(0); } //更新数量 project.setBrowse_count(project.getBrowse_count() + 1); projectDeclarationService.updateSelective(project); } return ResponseMessage.success("success", project); } else if (isFilling == 1){ ProjectProvincesDeclaration provinces = projectProvincesDeclarationService.selectById(String.valueOf(id)); if (null != provinces) { String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, provinces.getProject_source()); provinces.setProject_source_name(sourceName); provinces.setContent(StringEscapeUtils.unescapeHtml4(provinces.getContent())); if (null == provinces.getBrowse_count()) { provinces.setBrowse_count(0); } //项目来源 String source = provinces.getProject_source(); if (StringUtils.isNotBlank(source)) { DictionaryItem sourceItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, source); if (null != sourceItem) { provinces.setProject_source_name(sourceItem.getName()); } } //更新数量 provinces.setBrowse_count(provinces.getBrowse_count() + 1); projectProvincesDeclarationService.updateSelective(provinces); } return ResponseMessage.success("success", provinces); } return ResponseMessage.success("success", null); } /** * 专题活动详情 * * @param id * @return */ public ActivityDetail findByActivityId(Integer id, Integer user_id) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); //符合条件的载体集合 ActivityDetail activity = activityService.findOne(id.toString()); if (activity != null) { LocalDateTime localDate = LocalDateTime.parse(activity.getActivity_endtime(), formatter); if (LocalDateTime.now().isBefore(localDate)) { activity.setCan_sign_up(true); } //活动图片 List attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.ACTIVITY, activity.getId(), null); if (null != attachments && attachments.size() > 0) { FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri()); activity.setFileDown(fileDown); } //活动回顾 ActivityReview review = activityReviewService.findByActivityId(id); if (review != null) { Attachment attachment = attachmentService.findByBizIdAndBizType(review.getId(), Constant.Attachment.REVIEW_ACTIVITY); if (attachment != null) { FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()); review.setFileDown(fileDown); } activity.setActivityReview(review); } // 综合星级 activity.setAvg_star(activityFeedbackService.findAvgStar(id)); //是否收藏 if (isFavourited(id, user_id)){ activity.setIs_favourited("1"); } else { activity.setIs_favourited("0"); } //浏览数+1 activity.setReading_number(activity.getReading_number() + 1); activityService.updateSelective(activity); } return activity; } /** * 活动是否收藏 * @param id * @return */ public boolean isFavourited(Integer id, Integer user_id){ ActivityFavourite activityFavourite = activityFavouriteService.selectByActivityIdAndUserId(id + "", user_id + ""); if (activityFavourite != null){ return true; } return false; } }