PolicyService.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package com.goafanti.news.service;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.UUID;
  7. import org.aspectj.weaver.ast.And;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.app.bo.AppDiscoveryBo;
  12. import com.goafanti.common.dao.JtCollectSearchMapper;
  13. import com.goafanti.common.dao.PolicyMapper;
  14. import com.goafanti.common.dao.PolicyPublishMapper;
  15. import com.goafanti.common.enums.collectType;
  16. import com.goafanti.common.model.JtCollectSearch;
  17. import com.goafanti.common.model.Policy;
  18. import com.goafanti.common.model.PolicyPublish;
  19. import com.goafanti.core.mybatis.BaseMybatisDao;
  20. import com.goafanti.core.mybatis.page.Pagination;
  21. import com.goafanti.news.bo.PolicyResult;
  22. @Service
  23. public class PolicyService extends BaseMybatisDao<PolicyMapper> {
  24. @Autowired
  25. PolicyMapper policyMapper;
  26. @Autowired
  27. PolicyPublishMapper policyPublishMapper;
  28. @Autowired
  29. JtCollectSearchMapper jtCollectSearchMapper;
  30. @Value(value="${collect_flag}")
  31. private Boolean collectFlag ;
  32. public Policy saveNewPolicy(Policy policy,List<String>webPages,List<String>appPages) {
  33. if (null!=policy&&policy.getAuditStatus()!=null&&policy.getAuditStatus()==2) {
  34. addJtCollectSearch(policy);
  35. }
  36. policyMapper.insertSelective(policy);
  37. PolicyPublish pp=null;
  38. if(webPages!=null)
  39. for(String s:webPages)
  40. {
  41. pp=new PolicyPublish();
  42. pp.setId(UUID.randomUUID().toString());
  43. pp.setIfTop(0);
  44. pp.setPolicyId(policy.getId()+"");
  45. pp.setPublishClient(0);
  46. pp.setPublisher("管理员");
  47. pp.setPublishPage(s);
  48. pp.setPublishPlatform("");
  49. pp.setPublishTime(new Date());
  50. pp.setShowNumber(1);
  51. pp.setTopNumber(1);
  52. policyPublishMapper.insert(pp);
  53. }
  54. if(appPages!=null)
  55. for(String s:appPages)
  56. {pp=new PolicyPublish();
  57. pp.setId(UUID.randomUUID().toString());
  58. pp.setIfTop(0);
  59. pp.setPolicyId(policy.getId()+"");
  60. pp.setPublishClient(1);
  61. pp.setPublisher("管理员");
  62. pp.setPublishPage(s);
  63. pp.setPublishPlatform("");
  64. pp.setPublishTime(new Date());
  65. pp.setShowNumber(1);
  66. pp.setTopNumber(1);
  67. policyPublishMapper.insert(pp);
  68. }
  69. return policy;
  70. }
  71. public int deletePolicyById(Long id) {
  72. if(id!=null) {
  73. if(collectFlag)jtCollectSearchMapper.deleteByrowId(String.valueOf(id));
  74. policyPublishMapper.deleteByPolicyId(id);
  75. return policyMapper.deleteByPrimaryKey(id);
  76. }
  77. else return -1;
  78. }
  79. public PolicyResult getPolicyDetail(Long id) {
  80. PolicyResult policyResult=policyMapper.selectByPrimaryKey(id);
  81. List<String> publishPages=policyPublishMapper.getPagesByPolicyId(id);
  82. if(policyResult!=null)
  83. policyResult.setPublishPages(publishPages);
  84. return policyResult;
  85. }
  86. public int updateSelectively(Policy policy, List<String> webPages, List<String> appPages) {
  87. // TODO Auto-generated method stub
  88. policyPublishMapper.deleteByPolicyId(policy.getId());
  89. PolicyPublish pp=null;
  90. if(webPages!=null)
  91. for(String s:webPages)
  92. {
  93. pp=new PolicyPublish();
  94. pp.setId(UUID.randomUUID().toString());
  95. pp.setIfTop(0);
  96. pp.setPolicyId(policy.getId()+"");
  97. pp.setPublishClient(0);
  98. pp.setPublisher("管理员");
  99. pp.setPublishPage(s);
  100. pp.setPublishPlatform("");
  101. pp.setPublishTime(new Date());
  102. pp.setShowNumber(1);
  103. pp.setTopNumber(1);
  104. policyPublishMapper.insert(pp);
  105. }
  106. if(appPages!=null)
  107. for(String s:appPages)
  108. {pp=new PolicyPublish();
  109. pp.setId(UUID.randomUUID().toString());
  110. pp.setIfTop(0);
  111. pp.setPolicyId(policy.getId()+"");
  112. pp.setPublishClient(1);
  113. pp.setPublisher("管理员");
  114. pp.setPublishPage(s);
  115. pp.setPublishPlatform("");
  116. pp.setPublishTime(new Date());
  117. pp.setShowNumber(1);
  118. pp.setTopNumber(1);
  119. policyPublishMapper.insert(pp);
  120. }
  121. return policyMapper.updateByPrimaryKeySelective(policy);
  122. }
  123. public int updateSelectivelyWithoutPages(Policy policy)
  124. {
  125. if(policy==null || policy.getId() ==null )
  126. return -1;
  127. else return policyMapper.updateByPrimaryKeySelective(policy);
  128. }
  129. @SuppressWarnings("unchecked")
  130. public Pagination<PolicyResult>searchPolicy(String title,Integer auditStatus,String startReleaseDate,String endReleaseDate,String publishPage,Integer pageNo,Integer pageSize,Integer provinceId){
  131. Map<String, Object> params = new HashMap<>();
  132. if(title!=null)params.put("title", title);
  133. if(auditStatus!=null &&auditStatus>=0 && auditStatus<=4)params.put("auditStatus", auditStatus);
  134. if(startReleaseDate!=null) {
  135. params.put("startDate", startReleaseDate);
  136. }
  137. if(endReleaseDate!=null)params.put("endDate", endReleaseDate);
  138. if(publishPage!=null)params.put("publishPage", publishPage);
  139. if(provinceId!=null)params.put("provinceId", provinceId);
  140. return (Pagination<PolicyResult>) findPage("findPolicyByPageAndPublishPages","findPolicyCountByPageAndPublishPages",params, pageNo, pageSize);
  141. }
  142. @SuppressWarnings("unchecked")
  143. public Pagination<AppDiscoveryBo> appListPolicy(Integer pageNo, Integer pageSize) {
  144. Map<String, Object> params = new HashMap<>();
  145. return (Pagination<AppDiscoveryBo>) findPage("findPolicyAppList","findPolicyAppCount",params, pageNo, pageSize);
  146. }
  147. public PolicyResult policyDetail(String id) {
  148. PolicyResult policyResult =policyMapper.selectPolicyDetail(id);
  149. return policyResult;
  150. }
  151. @SuppressWarnings("unchecked")
  152. public Pagination<PolicyResult> searchPolicyAndNewsList(Policy policy, Integer pageNo, Integer pageSize){
  153. Map<String, Object> params = new HashMap<>();
  154. params.put("policy", policy);
  155. return (Pagination<PolicyResult>) findPage("searchPolicyAndNewsList","searchPolicyAndNewsCount",params, pageNo, pageSize);
  156. }
  157. public void addJtCollectSearch(Policy policy) {
  158. if(collectFlag){
  159. JtCollectSearch r=new JtCollectSearch();
  160. r.setFromTable(collectType.POLICY.getDesc());
  161. r.setKeyword(policy.getKeyword());
  162. r.setTitle(policy.getTitle());
  163. r.setRowId(policy.getId().toString());
  164. String sum = policy.getSummary();
  165. if(null != sum && sum.length() > 40){
  166. sum = sum.substring(0,40) + "...";
  167. }
  168. r.setSummary(sum);
  169. jtCollectSearchMapper.insertSelective(r);
  170. }
  171. }
  172. public void updateJtCollectSearch(Policy policy) {
  173. if(collectFlag)jtCollectSearchMapper.deleteByrowId(policy.getId().toString());
  174. }
  175. }