| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- package platform.modules.home.service;
- import com.github.pagehelper.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import io.swagger.models.auth.In;
- import org.apache.commons.io.IOUtils;
- 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.dto.SearchGlobalDto;
- 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.io.IOException;
- import java.io.InputStream;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.ArrayList;
- import java.util.Base64;
- import java.util.List;
- import java.util.Objects;
- /**
- * @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 ActivityRegistrationService activityRegistrationService;
- @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<Content> 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<FileDown> fileDowns = new ArrayList<>();
- List<Attachment> 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<Attachment> 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);
- }
- //报名人数
- activity.setSgin_number(activityRegistrationService.getActivityRegistrationNumber(activity.getId()));
- //活动回顾
- 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);
- }
- //InputStream is_detail = activityService.getQRcode("1", "350", "activity_id=" + id);
- InputStream is_detail = activityService.getQRcode("1", "350", id+"");
- try {
- byte[] bytes_detail = IOUtils.toByteArray(is_detail);
- String encoded_detail = Base64.getEncoder().encodeToString(bytes_detail);
- activity.setQr_code("data:image/jpg;base64," + encoded_detail);
- } catch (IOException e) {
- e.printStackTrace();
- }
- 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;
- }
- public PageInfo<SearchGlobalDto> searchGlobal(Integer pageNum, Integer pageSize, String keyword) {
- PageHelper.startPage(pageNum, pageSize);
- List<SearchGlobalDto> res = contentService.searchGlobal(keyword);
- for (SearchGlobalDto re : res) {
- String title = re.getTitle();
- if (title != null) {
- title = htmlFilter(title);
- if (keyword != null && !Objects.equals(keyword, "")) {
- title = title.replace(keyword, "<m>" + keyword + "</m>");
- }
- }
- String content = re.getContent();
- if (content != null) {
- content = htmlFilter(content);
- if (keyword != null && !Objects.equals(keyword, "")) {
- content = content.replace(keyword, "<m>" + keyword + "</m>");
- }
- }
- re.setTitle(title);
- re.setContent(content);
- }
- return new PageInfo<>(res);
- }
- public List<String> searchLatest(Integer size) {
- PageInfo<SearchGlobalDto> searchGlobalPage = searchGlobal(1, size, "");
- List<SearchGlobalDto> searchGlobalList = searchGlobalPage.getList();
- List<String> titles = new ArrayList<>();
- for (SearchGlobalDto searchGlobalDto : searchGlobalList) {
- titles.add(searchGlobalDto.getTitle());
- }
- return titles;
- }
- private String htmlFilter(String html) {
- // 过滤文章内容中的html
- html = html.replaceAll("</?[^<]+>", "");
- // 去除字符串中的空格 回车 换行符 制表符 等
- html = html.replaceAll("\\s*|\t|\r|\n", "");
- // 去除空格
- html = html.replaceAll(" ", "");
- // 去掉其他一些字符
- //html = html.replaceAll("\", "");
- return html;
- }
- }
|