| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package com.goafanti.news.controller;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.annotation.Resource;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.constant.PageConstants;
- import com.goafanti.common.controller.BaseApiController;
- import com.goafanti.common.model.News;
- import com.goafanti.common.model.Policy;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.core.mybatis.JDBCIdGenerator;
- import com.goafanti.news.bo.InputNews;
- import com.goafanti.news.service.PolicyService;
- @RestController
- @RequestMapping(value = "/open/api/admin/policy")
- public class AdminPolicyApiController extends BaseApiController {
-
- @Autowired
- private JDBCIdGenerator idGenerator;
- @Resource
- private PolicyService policyService;
- /*
- * 新增
- *
- * */
- @RequestMapping(value="/apply",method=RequestMethod.POST)
- public Result insertPolicy(Policy policy,String[]publishPages) {
- Result result=new Result();
- disposePolicyParams(policy,result);
- if(result.getError().size()>0)return result;
- if(publishPages==null || publishPages.length<1) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
- return result;
- }
- List<String>webPages=new ArrayList<>();
- List<String>appPages=new ArrayList<>();
- PageConstants.putPolicy(publishPages,webPages,appPages);
- if(webPages.size()<1 && appPages.size()<1) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
- return result;
- }
- policy.setCreateTime(new Date());
- policy.setId(idGenerator.generateId());
- policy.setType(0);
- if(policy.getAuditStatus()!=null &&policy.getAuditStatus() == 2) {
- policy.setReleaseDate(new Date());
-
- }
- result.setData(policyService.saveNewPolicy(policy, webPages, appPages));
- return result;
- }
-
- private void disposePolicyParams(Policy policy,Result result) {
- if(StringUtils.isBlank(policy.getTitle())) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","标题"));
- return ;
- }
- if(StringUtils.isBlank(policy.getContent()))
- {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","内容"));
- return ;
- }
- if(StringUtils.isBlank(policy.getSource()))
- {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","来源"));
- return ;
- }
- if(policy.getAuditStatus() == null )
- {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","审核状态"));
- return ;
- }
- }
- /*
- * 删除
- *
- * */
-
- @RequestMapping(value="/delete",method=RequestMethod.POST)
- public Result deleteById(Long id) {
- Result result=new Result();
- if(id ==null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空,"));return result;
- }
- int res=policyService.deletePolicyById(id);
- result.setData(res);
- if(res==-1) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空"));
- }
- return result;
- }
-
- /*
- * 详情
- * */
- @RequestMapping(value="/detail",method=RequestMethod.GET)
- public Result getDetailById(Long id) {
- Result result=new Result();
- if(id==null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id不可为空,"));return result;
- }
- result.setData(policyService.getPolicyDetail(id));
- return result;
- }
-
- /*
- * 修改
- *
- * */
- @RequestMapping(value="/update",method=RequestMethod.POST)
- public Result updateNews(Policy policy,BindingResult bindingResult,String[] publishPages) {
- Result result=new Result();
-
- List<String>webPages=new ArrayList<>();
- List<String>appPages=new ArrayList<>();
- PageConstants.putPolicy(publishPages, webPages, appPages);
- if(webPages.size()<1 && appPages.size()<1) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","发布位置"));
- return result;
- }
- disposePolicyParams(policy, result);
- if(result.getError().size()>0) {
- return result;
- }
- if(policy.getAuditStatus()!=null &&policy.getAuditStatus() == 2) {
- policy.setReleaseDate(new Date());
- }
-
- result.setData(policyService.updateSelectively( policy,webPages,appPages));
-
- return result;
- }
-
-
- /*
- * 变更发布状态、发布时间
- * */
- @RequestMapping(value="/updateStatus",method=RequestMethod.POST)
- public Result updateStatus(Long id,Integer auditStatus,Integer refresh) {
- Result result=new Result();
- if(id==null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","未找到该政策,"));
- return result;
- }
- Policy policy=policyService.getPolicyDetail(id);
- if(policy==null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","未找到该政策,"));
- return result;
- }
- if(refresh!=null &&refresh==1)
- {
- if( auditStatus!=2 && policy.getAuditStatus()!=2) {
- result.getError().add(buildError("","","当前未发布"));
- return result;
- }
- policy.setReleaseDate(new Date());}
- if(auditStatus!=null) {policy.setAuditStatus(auditStatus);
- if(auditStatus ==2)policy.setReleaseDate(new Date());}
-
- result.setData(policyService.updateSelectivelyWithoutPages(policy));
- return result;
-
- }
-
- /*
- * 政策搜索
- * */
- @RequestMapping(value="/list",method=RequestMethod.GET)
- public Result searchPolicy(String title,Integer auditStatus,String startReleaseDate,String endReleaseDate,String publishPage,Integer pageNo,Integer pageSize) {
- Result result=new Result();
- if(pageNo==null || pageNo<1)pageNo=1;
- if(pageSize==null || pageSize<1)pageSize=10;
- result.setData(policyService.searchPolicy(title,auditStatus,startReleaseDate,endReleaseDate,publishPage,pageNo,pageSize));
- return result;
- }
-
-
-
-
- }
|