182 lines
5.9 KiB
Java
182 lines
5.9 KiB
Java
package com.rzyc.controller;
|
|
|
|
import com.common.utils.DateUtils;
|
|
import com.common.utils.TypeConversion;
|
|
import com.common.utils.model.*;
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.rzyc.advice.LoginAuth;
|
|
import com.rzyc.bean.dynamic.DynamicPageDto;
|
|
import com.rzyc.bean.dynamic.dto.ChangeDynamicDto;
|
|
import com.rzyc.enums.DelState;
|
|
import com.rzyc.model.Dynamic;
|
|
import com.rzyc.model.NewsClass;
|
|
import com.rzyc.model.NewsCnt;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
@Api(tags = "动态")
|
|
@CrossOrigin("*")
|
|
@RequestMapping("dynamic")
|
|
@Controller
|
|
@Validated
|
|
public class DynamicController extends com.rzyc.controller.BaseController {
|
|
|
|
|
|
/**
|
|
* 动态分页
|
|
* @return<
|
|
* @throws Exception
|
|
*/
|
|
@ApiOperation(value = "动态分页", notes = "动态分页")
|
|
@PostMapping("/dynamicPage")
|
|
@ResponseBody
|
|
@LoginAuth
|
|
public SingleResult<Pager<Dynamic>> dynamicPage(@Valid DynamicPageDto dynamicPageDto)throws Exception{
|
|
SingleResult<Pager<Dynamic>> result = new SingleResult<>();
|
|
String condition = TypeConversion.getCondition(dynamicPageDto.getCondition());
|
|
PageHelper.startPage(dynamicPageDto.getPage(), dynamicPageDto.getPageSize());
|
|
Page<Dynamic> page = (Page<Dynamic>)newsCntMapper.newsCntList(dynamicPageDto.getNewsClassId(),condition);
|
|
Pager<Dynamic> pager = new Pager<>();
|
|
getDatePage(pager,page);
|
|
if(pager.getRows().size() > 0){
|
|
for (Dynamic dynamic : pager.getRows()){
|
|
handleDynamic(dynamic);
|
|
}
|
|
}
|
|
result.setData(pager);
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 动态分类列表
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@ApiOperation(value = "动态分类列表", notes = "动态分类列表")
|
|
@PostMapping("/newsClassList")
|
|
@ResponseBody
|
|
@LoginAuth
|
|
public MultiResult<NewsClass> newsClassList()throws Exception{
|
|
MultiResult<NewsClass> result = new MultiResult<>();
|
|
List<NewsClass> newsClasses = newsClassMapper.findAll();
|
|
if(newsClasses.size() > 0){
|
|
result.setData(newsClasses);
|
|
}else{
|
|
result.setCode(Code.NO_DATA.getCode());
|
|
result.setMessage(Message.NO_DATA);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 动态详情
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@ApiOperation(value = "动态详情", notes = "动态详情")
|
|
@ApiImplicitParam(name = "dynamicId",value = "动态id")
|
|
@PostMapping("/dynamicDetail/{dynamicId}")
|
|
@ResponseBody
|
|
@LoginAuth
|
|
public SingleResult<NewsCnt> dynamicDetail(@PathVariable String dynamicId)throws Exception{
|
|
SingleResult<NewsCnt> result = new SingleResult<>();
|
|
|
|
NewsCnt newsCnt = newsCntMapper.findById(dynamicId);
|
|
if(null != newsCnt){
|
|
// newsCnt.setCoverImage(setServiceFile(newsCnt.getCoverImage()));
|
|
result.setData(newsCnt);
|
|
}else{
|
|
result.setCode(Code.NO_DATA.getCode());
|
|
result.setMessage(Message.NO_DATA);
|
|
}
|
|
|
|
/*Dynamic dynamic = newsCntMapper.newCntDetail(dynamicId);
|
|
if(null != dynamic){
|
|
handleDynamic(dynamic);
|
|
result.setData(dynamic);
|
|
}else{
|
|
result.setCode(Code.NO_DATA.getCode());
|
|
result.setMessage(Message.NO_DATA);
|
|
}*/
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 修改新增动态
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@ApiOperation(value = "修改新增动态", notes = "修改新增动态")
|
|
@PostMapping("changeDynamic")
|
|
@ResponseBody
|
|
@LoginAuth
|
|
public SingleResult<String> changeDynamic(@Valid @RequestBody ChangeDynamicDto changeDynamicDto)throws Exception{
|
|
SingleResult<String> result = new SingleResult<>();
|
|
NewsCnt newsCnt = new NewsCnt();
|
|
BeanUtils.copyProperties(newsCnt,changeDynamicDto);
|
|
|
|
//操作人
|
|
String chinaName = getChinaName();
|
|
newsCnt.setModifiedby(chinaName);
|
|
newsCnt.setCreatedby(chinaName);
|
|
newsCnt.setModifiedon(new Date());
|
|
newsCnt.setCreatedon(new Date());
|
|
newsCnt.setDelState(DelState.NOT_DEL.getState());
|
|
|
|
//封面图
|
|
// newsCnt.setCoverImage(delServiceFile(changeDynamicDto.getShowImageUrl()));
|
|
newsCnt.setCoverImage(changeDynamicDto.getShowImageUrl());
|
|
|
|
newsCnt.setPublictime(DateUtils.parseString2Date(changeDynamicDto.getPublicTime(),"yyyy-MM-dd HH:mm"));
|
|
|
|
Dynamic dynamic = newsCntMapper.newCntDetail(newsCnt.getNewscntid());
|
|
if(null != dynamic){
|
|
//修改
|
|
newsCntMapper.changeNews(newsCnt);
|
|
}else{
|
|
//新增
|
|
newsCntMapper.insert(newsCnt);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 删除动态
|
|
* @param dynamicId
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@ApiOperation(value = "删除动态", notes = "删除动态")
|
|
@ApiImplicitParam(name = "dynamicId",value = "动态id 多个逗号隔开",required = true)
|
|
@PostMapping("delNewsCnt")
|
|
@ResponseBody
|
|
@LoginAuth
|
|
public SingleResult<String> delNewsCnt(String dynamicId)throws Exception{
|
|
SingleResult<String> result = new SingleResult<>();
|
|
String[] strs = dynamicId.split(",");
|
|
//操作人
|
|
String chinaName = getChinaName();
|
|
if(strs.length > 0){
|
|
for (String str : strs){
|
|
NewsCnt newsCnt = newsCntMapper.findById(str);
|
|
if(null != newsCnt){
|
|
newsCntMapper.delNewsCnt(newsCnt.getNewscntid(),chinaName);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|