AdminPolicyApiController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.goafanti.news.controller;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.annotation.Resource;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.validation.BindingResult;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.goafanti.common.bo.Result;
  15. import com.goafanti.common.constant.ErrorConstants;
  16. import com.goafanti.common.constant.PageConstants;
  17. import com.goafanti.common.controller.BaseApiController;
  18. import com.goafanti.common.model.News;
  19. import com.goafanti.common.model.Policy;
  20. import com.goafanti.common.utils.StringUtils;
  21. import com.goafanti.core.mybatis.JDBCIdGenerator;
  22. import com.goafanti.news.bo.InputNews;
  23. import com.goafanti.news.bo.newsInterestBo;
  24. import com.goafanti.news.service.PolicyService;
  25. @RestController
  26. @RequestMapping(value = "/api/admin/policy")
  27. public class AdminPolicyApiController extends BaseApiController {
  28. @Autowired
  29. private JDBCIdGenerator idGenerator;
  30. @Resource
  31. private PolicyService policyService;
  32. /*
  33. * 新增
  34. *
  35. * */
  36. @RequestMapping(value="/apply",method=RequestMethod.POST)
  37. public Result insertPolicy(Policy policy,String[]publishPages) {
  38. Result result=new Result();
  39. disposePolicyParams(policy,result);
  40. if(result.getError().size()>0)return result;
  41. if(publishPages==null || publishPages.length<1) {
  42. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
  43. return result;
  44. }
  45. List<String>webPages=new ArrayList<>();
  46. List<String>appPages=new ArrayList<>();
  47. PageConstants.putPolicy(publishPages,webPages,appPages);
  48. if(webPages.size()<1 && appPages.size()<1) {
  49. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
  50. return result;
  51. }
  52. policy.setCreateTime(new Date());
  53. policy.setEditTime(new Date());
  54. policy.setId(idGenerator.generateId());
  55. policy.setType(0);
  56. if(policy.getAuditStatus()!=null &&policy.getAuditStatus() == 2) {
  57. policy.setReleaseDate(new Date());
  58. }
  59. result.setData(policyService.saveNewPolicy(policy, webPages, appPages));
  60. return result;
  61. }
  62. private void disposePolicyParams(Policy policy,Result result) {
  63. if(StringUtils.isBlank(policy.getTitle())) {
  64. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","标题"));
  65. return ;
  66. }
  67. if(StringUtils.isBlank(policy.getContent()))
  68. {
  69. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","内容"));
  70. return ;
  71. }
  72. if(StringUtils.isBlank(policy.getSource()))
  73. {
  74. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","来源"));
  75. return ;
  76. }
  77. if(policy.getAuditStatus() == null )
  78. {
  79. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","审核状态"));
  80. return ;
  81. }
  82. }
  83. /*
  84. * 删除
  85. *
  86. * */
  87. @RequestMapping(value="/delete",method=RequestMethod.POST)
  88. public Result deleteById(Long id) {
  89. Result result=new Result();
  90. if(id ==null) {
  91. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空,"));return result;
  92. }
  93. int res=policyService.deletePolicyById(id);
  94. result.setData(res);
  95. if(res==-1) {
  96. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空"));
  97. }
  98. return result;
  99. }
  100. /*
  101. * 详情
  102. * */
  103. @RequestMapping(value="/detail",method=RequestMethod.GET)
  104. public Result getDetailById(Long id) {
  105. Result result=new Result();
  106. if(id==null) {
  107. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空,"));return result;
  108. }
  109. result.setData(policyService.getPolicyDetail(id));
  110. return result;
  111. }
  112. /*
  113. * 修改
  114. *
  115. * */
  116. @RequestMapping(value="/update",method=RequestMethod.POST)
  117. public Result updateNews(Policy policy,BindingResult bindingResult,String[] publishPages) {
  118. Result result=new Result();
  119. List<String>webPages=new ArrayList<>();
  120. List<String>appPages=new ArrayList<>();
  121. PageConstants.putPolicy(publishPages, webPages, appPages);
  122. if(webPages.size()<1 && appPages.size()<1) {
  123. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
  124. return result;
  125. }
  126. disposePolicyParams(policy, result);
  127. if(result.getError().size()>0) {
  128. return result;
  129. }
  130. if(policy.getAuditStatus()!=null &&policy.getAuditStatus() == 2) {
  131. policy.setReleaseDate(new Date());
  132. }
  133. policy.setEditTime(new Date());
  134. result.setData(policyService.updateSelectively( policy,webPages,appPages));
  135. return result;
  136. }
  137. /*
  138. * 变更发布状态、发布时间
  139. * */
  140. @RequestMapping(value="/updateStatus",method=RequestMethod.POST)
  141. public Result updateStatus(Long id,Integer auditStatus,Integer refresh) {
  142. Result result=new Result();
  143. if(id==null) {
  144. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","未找到该政策,"));
  145. return result;
  146. }
  147. Policy policy=policyService.getPolicyDetail(id);
  148. if(policy==null) {
  149. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","未找到该政策,"));
  150. return result;
  151. }
  152. if(refresh!=null &&refresh==1)
  153. {
  154. if( auditStatus!=2 && policy.getAuditStatus()!=2) {
  155. result.getError().add(buildError("","","当前未发布"));
  156. return result;
  157. }
  158. policy.setReleaseDate(new Date());}
  159. if(auditStatus!=null) {policy.setAuditStatus(auditStatus);
  160. if(auditStatus ==2)policy.setReleaseDate(new Date());}
  161. result.setData(policyService.updateSelectivelyWithoutPages(policy));
  162. return result;
  163. }
  164. /*
  165. * 政策搜索
  166. * */
  167. @RequestMapping(value="/list",method=RequestMethod.GET)
  168. public Result searchPolicy(String title,Integer auditStatus,String startReleaseDate,String endReleaseDate,String publishPage,Integer pageNo,Integer pageSize) {
  169. Result result=new Result();
  170. if(pageNo==null || pageNo<1)pageNo=1;
  171. if(pageSize==null || pageSize<1)pageSize=10;
  172. result.setData(policyService.searchPolicy(title,auditStatus,startReleaseDate,endReleaseDate,publishPage,pageNo,pageSize));
  173. return result;
  174. }
  175. }