HomeRefactorService.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package platform.modules.home.service;
  2. import com.github.pagehelper.PageHelper;
  3. import com.github.pagehelper.PageInfo;
  4. import io.swagger.models.auth.In;
  5. import org.apache.commons.lang3.StringEscapeUtils;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import platform.common.Constant;
  10. import platform.common.base.model.DictionaryItem;
  11. import platform.common.base.service.DictionaryItemService;
  12. import platform.common.util.ShiroUtils;
  13. import platform.modules.government.dto.FeedbackQuery;
  14. import platform.modules.government.entity.*;
  15. import platform.modules.government.service.*;
  16. import platform.modules.home.dto.HomeRefactorDto;
  17. import platform.modules.home.request.FindRequest;
  18. import platform.modules.sys.entity.ActivityDetail;
  19. import platform.modules.sys.entity.ActivityFavourite;
  20. import platform.modules.sys.entity.ActivityFeedback;
  21. import platform.modules.sys.entity.ActivityReview;
  22. import platform.modules.sys.service.*;
  23. import platform.modules.sys.web.ResponseMessage;
  24. import java.time.LocalDateTime;
  25. import java.time.format.DateTimeFormatter;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. /**
  29. * @author kevin
  30. * @since 2019/5/21 3:45 PM
  31. */
  32. @Service
  33. public class HomeRefactorService {
  34. @Autowired
  35. private ContentService contentService;
  36. @Autowired
  37. private ActivityService activityService;
  38. @Autowired
  39. private ProjectDeclarationService projectDeclarationService;
  40. @Autowired
  41. private ProjectFillingDeclarationService projectFillingDeclarationService;
  42. @Autowired
  43. private DictionaryItemService dictionaryItemService;
  44. @Autowired
  45. private ProjectProvincesDeclarationService projectProvincesDeclarationService;
  46. @Autowired
  47. private AttachmentService attachmentService;
  48. @Autowired
  49. private ActivityReviewService activityReviewService;
  50. @Autowired
  51. private ActivityFeedbackService activityFeedbackService;
  52. @Autowired
  53. private DepartmentService departmentService;
  54. @Autowired
  55. private ActivityFavouriteService activityFavouriteService;
  56. /**
  57. * 门户首页信息
  58. *
  59. * @return
  60. */
  61. public HomeRefactorDto findHomeIndex() {
  62. HomeRefactorDto refactor = new HomeRefactorDto();
  63. FindRequest request = new FindRequest();
  64. request.setPage_size(1);
  65. request.setId(64);
  66. refactor.setMessage(contentService.findContentList(request).get(0));
  67. request.setId(1);
  68. refactor.setActivity(activityService.findContentList(request).getList().get(0));
  69. request.setId(69);
  70. request.setType("");
  71. refactor.setProject(projectDeclarationService.findProjectList(request).getList().get(0));
  72. return refactor;
  73. }
  74. /**
  75. * content列表
  76. *
  77. * @param request
  78. * @return
  79. */
  80. public PageInfo<Content> findContentList(FindRequest request) {
  81. PageHelper.startPage(request.getPage_no(), request.getPage_size());
  82. return new PageInfo<>(contentService.findContentList(request));
  83. }
  84. /**
  85. * 详情
  86. *
  87. * @param id
  88. * @return
  89. */
  90. public Content contentDeatil(Integer id) {
  91. Content content = contentService.findById(id);
  92. if (null == content.getBrowse_count()) {
  93. content.setBrowse_count(0);
  94. }
  95. List<FileDown> fileDowns = new ArrayList<>();
  96. List<Attachment> files = attachmentService.selectByIdAndBusinessId(Constant.Attachment.CONTENT_FILE, content.getId(), null);
  97. if (null != files && files.size() > 0) {
  98. FileDown addFileDown = new FileDown(files.get(0).getId(), files.get(0).getFile_name(), files.get(0).getFile_url(), files.get(0).getDownload_uri());
  99. content.setAddFileDown(addFileDown);
  100. for (Attachment file : files) {
  101. FileDown fileDown = new FileDown(file.getId(), file.getFile_name(), file.getFile_url(), file.getDownload_uri());
  102. fileDowns.add(fileDown);
  103. }
  104. }
  105. content.setFileDowns(fileDowns);
  106. content.setContent(StringEscapeUtils.unescapeHtml4(content.getContent()));
  107. //更新数量
  108. content.setBrowse_count(content.getBrowse_count() + 1);
  109. contentService.updateSelective(content);
  110. return content;
  111. }
  112. /**
  113. * 项目申报详情
  114. *
  115. * @param id
  116. * @return
  117. */
  118. public ResponseMessage findProjectDetail(Integer id, Integer isFilling) {
  119. if (isFilling == 0){
  120. //项目申报
  121. ProjectDeclaration project = projectDeclarationService.selectById(String.valueOf(id));
  122. if (project != null){
  123. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source());
  124. project.setProject_source_name(sourceName);
  125. project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content()));
  126. //项目来源
  127. String source = project.getProject_source();
  128. if (StringUtils.isNotBlank(source)) {
  129. DictionaryItem sourceItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, source);
  130. if (null != sourceItem) {
  131. project.setProject_source_name(sourceItem.getName());
  132. }
  133. }
  134. if (null == project.getBrowse_count()) {
  135. project.setBrowse_count(0);
  136. }
  137. //更新数量
  138. project.setBrowse_count(project.getBrowse_count() + 1);
  139. projectDeclarationService.updateSelective(project);
  140. }
  141. return ResponseMessage.success("success", project);
  142. } else if (isFilling == 1){
  143. ProjectProvincesDeclaration provinces = projectProvincesDeclarationService.selectById(String.valueOf(id));
  144. if (null != provinces) {
  145. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, provinces.getProject_source());
  146. provinces.setProject_source_name(sourceName);
  147. provinces.setContent(StringEscapeUtils.unescapeHtml4(provinces.getContent()));
  148. if (null == provinces.getBrowse_count()) {
  149. provinces.setBrowse_count(0);
  150. }
  151. //项目来源
  152. String source = provinces.getProject_source();
  153. if (StringUtils.isNotBlank(source)) {
  154. DictionaryItem sourceItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, source);
  155. if (null != sourceItem) {
  156. provinces.setProject_source_name(sourceItem.getName());
  157. }
  158. }
  159. //更新数量
  160. provinces.setBrowse_count(provinces.getBrowse_count() + 1);
  161. projectProvincesDeclarationService.updateSelective(provinces);
  162. }
  163. return ResponseMessage.success("success", provinces);
  164. }
  165. return ResponseMessage.success("success", null);
  166. }
  167. /**
  168. * 专题活动详情
  169. *
  170. * @param id
  171. * @return
  172. */
  173. public ActivityDetail findByActivityId(Integer id, Integer user_id) {
  174. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  175. //符合条件的载体集合
  176. ActivityDetail activity = activityService.findOne(id.toString());
  177. if (activity != null) {
  178. LocalDateTime localDate = LocalDateTime.parse(activity.getActivity_endtime(), formatter);
  179. if (LocalDateTime.now().isBefore(localDate)) {
  180. activity.setCan_sign_up(true);
  181. }
  182. //活动图片
  183. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.ACTIVITY, activity.getId(), null);
  184. if (null != attachments && attachments.size() > 0) {
  185. FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri());
  186. activity.setFileDown(fileDown);
  187. }
  188. //活动回顾
  189. ActivityReview review = activityReviewService.findByActivityId(id);
  190. if (review != null) {
  191. Attachment attachment = attachmentService.findByBizIdAndBizType(review.getId(), Constant.Attachment.REVIEW_ACTIVITY);
  192. if (attachment != null) {
  193. FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(),
  194. attachment.getDownload_uri());
  195. review.setFileDown(fileDown);
  196. }
  197. activity.setActivityReview(review);
  198. }
  199. // 综合星级
  200. activity.setAvg_star(activityFeedbackService.findAvgStar(id));
  201. //是否收藏
  202. if (isFavourited(id, user_id)){
  203. activity.setIs_favourited("1");
  204. }
  205. else {
  206. activity.setIs_favourited("0");
  207. }
  208. //浏览数+1
  209. activity.setReading_number(activity.getReading_number() + 1);
  210. activityService.updateSelective(activity);
  211. }
  212. return activity;
  213. }
  214. /**
  215. * 活动是否收藏
  216. * @param id
  217. * @return
  218. */
  219. public boolean isFavourited(Integer id, Integer user_id){
  220. ActivityFavourite activityFavourite = activityFavouriteService.selectByActivityIdAndUserId(id + "", user_id + "");
  221. if (activityFavourite != null){
  222. return true;
  223. }
  224. return false;
  225. }
  226. }