AdminPolicyApiController.java 6.2 KB

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