|
@@ -1,5 +1,9 @@
|
|
|
package com.yonge.cooleshow.cms.controller;
|
|
|
|
|
|
+import com.yonge.cooleshow.cms.dal.entity.NewsStatusEnum;
|
|
|
+import com.yonge.cooleshow.cms.dto.SysNewsInformationDto;
|
|
|
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
+import com.yonge.cooleshow.common.page.PageInfo;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -11,11 +15,7 @@ import java.util.Map;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
@@ -29,99 +29,101 @@ import com.yonge.cooleshow.common.controller.BaseController;
|
|
|
import com.yonge.toolset.log.model.AuditLogAnnotation;
|
|
|
import com.yonge.toolset.utils.collection.MapUtil;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
@RestController
|
|
|
@RequestMapping("news")
|
|
|
-@Api(tags = "资讯服务")
|
|
|
+@Api(tags = "资讯/广告/闪页/轮播图服务")
|
|
|
public class NewsController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private SysNewsInformationService sysNewsInformationService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysNewsTypeService sysNewsTypeService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysNewsInformationDao sysNewsInformationDao;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private StudentRegistrationDao studentRegistrationDao;
|
|
|
-
|
|
|
- @ApiOperation("资讯列表分页查询")
|
|
|
- @GetMapping(value = "/list")
|
|
|
- public Object getList(NewsInformationQueryInfo queryInfo) {
|
|
|
-
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
- MapUtil.populateMap(params, queryInfo);
|
|
|
- int count = sysNewsInformationDao.queryCount(params);
|
|
|
- if(count == 0){
|
|
|
- queryInfo.setMemo(null);
|
|
|
- }
|
|
|
- return succeed(sysNewsInformationService.queryPage(queryInfo));
|
|
|
- }
|
|
|
|
|
|
- @ApiOperation("资讯列表分页查询")
|
|
|
- @GetMapping(value = "/queryPage")
|
|
|
- public Object queryPage(NewsInformationQueryInfo queryInfo) {
|
|
|
+ @ApiOperation(value = "资讯/广告/闪页/轮播图 列表分页查询", httpMethod="POST", consumes="application/json", produces="application/json")
|
|
|
+ @PostMapping(value = "/page", consumes="application/json", produces="application/json")
|
|
|
+ public HttpResponseResult<PageInfo<SysNewsInformationDto>> getList(@Valid @RequestBody NewsInformationQueryInfo queryInfo) {
|
|
|
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
MapUtil.populateMap(params, queryInfo);
|
|
|
- int count = sysNewsInformationDao.queryCount(params);
|
|
|
- if(count == 0){
|
|
|
- queryInfo.setMemo(null);
|
|
|
- }
|
|
|
- return succeed(sysNewsInformationService.queryPage(queryInfo));
|
|
|
+ return succeed(sysNewsInformationService.selectPage(queryInfo));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("资讯类型列表查询")
|
|
|
- @GetMapping(value = "/typeList")
|
|
|
- public Object getTypeList(Long parentId) {
|
|
|
- return succeed(sysNewsTypeService.queryByParentId(parentId));
|
|
|
- }
|
|
|
|
|
|
- @ApiOperation("资讯列表分页查询")
|
|
|
- @GetMapping(value = "/homeList")
|
|
|
- public Object getHomeList(NewsInformationQueryInfo queryInfo) {
|
|
|
- queryInfo.setRows(10);
|
|
|
- SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
- return succeed(sysNewsInformationService.getHomeList(user, queryInfo));
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("查询资讯详情")
|
|
|
+ @ApiOperation("查询资讯/广告/闪页/轮播图 详情")
|
|
|
@ApiImplicitParam(name = "id", value = "资讯ID编号", required = true, dataType = "Long", paramType = "path")
|
|
|
- @GetMapping(value = "/query")
|
|
|
- public Object query(Long id) {
|
|
|
+ @GetMapping(value = "/query/{id}")
|
|
|
+ public HttpResponseResult<SysNewsInformationDto> query(@PathVariable Long id) {
|
|
|
|
|
|
return succeed(sysNewsInformationService.queryById(id));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("新增资讯")
|
|
|
- @PostMapping(value = "/add", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
+ @ApiOperation(value = "新增资讯/广告/闪页/轮播图 ", httpMethod="POST", consumes="application/json", produces="application/json")
|
|
|
+ @PostMapping(value = "/add", consumes="application/json", produces="application/json")
|
|
|
@AuditLogAnnotation(operateName = "资讯新增",interfaceURL = "news/add")
|
|
|
- @PreAuthorize("@pcs.hasPermissions('news/add')")
|
|
|
- public Object add(SysNewsInformation newsInfo) {
|
|
|
+ // @PreAuthorize("@pcs.hasPermissions('news/add')")
|
|
|
+ public Object add(@Valid @RequestBody SysNewsInformation newsInfo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null || sysUser.getId() == null) {
|
|
|
+ return failed("用户信息获取失败");
|
|
|
+ }
|
|
|
+ newsInfo.setStatus(NewsStatusEnum.HIDDEN);
|
|
|
+ newsInfo.setCreateTime(new Date());
|
|
|
+ newsInfo.setCreateBy(sysUser.getId());
|
|
|
+ newsInfo.setUpdateTime(new Date());
|
|
|
+ newsInfo.setUpdateBy(sysUser.getId());
|
|
|
return succeed(sysNewsInformationService.insert(newsInfo));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("更新资讯")
|
|
|
- @PostMapping(value = "/update", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
+ @ApiOperation(value = "更新资讯/广告/闪页/轮播图 ", httpMethod="POST", consumes="application/json", produces="application/json")
|
|
|
+ @PostMapping(value = "/update", consumes="application/json", produces="application/json")
|
|
|
@AuditLogAnnotation(operateName = "资讯更新",interfaceURL = "news/update")
|
|
|
- @PreAuthorize("@pcs.hasPermissions('news/update')")
|
|
|
- public Object update(SysNewsInformation newsInfo) {
|
|
|
- Date date = new Date();
|
|
|
- newsInfo.setUpdateTime(date);
|
|
|
+ // @PreAuthorize("@pcs.hasPermissions('news/update')")
|
|
|
+ public Object update(@Valid @RequestBody SysNewsInformation newsInfo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null || sysUser.getId() == null) {
|
|
|
+ return failed("用户信息获取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysNewsInformationDto sysNewsInformationDto = sysNewsInformationService.queryById(newsInfo.getId());
|
|
|
+ if (sysNewsInformationDto == null) {
|
|
|
+ return failed("未找到相关信息");
|
|
|
+ }
|
|
|
+ if(NewsStatusEnum.SHOW.getCode().equals(sysNewsInformationDto.getStatus().getCode())) {
|
|
|
+ return failed("启用状态下,不可修改");
|
|
|
+ }
|
|
|
+ newsInfo.setUpdateTime(new Date());
|
|
|
+ newsInfo.setUpdateBy(sysUser.getId());
|
|
|
|
|
|
return succeed(sysNewsInformationService.update(newsInfo));
|
|
|
}
|
|
|
|
|
|
@ApiOperation("删除")
|
|
|
- @PostMapping(value = "/del/{id}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
+ @PostMapping(value = "/del/{id}")
|
|
|
@AuditLogAnnotation(operateName = "资讯删除",interfaceURL = "news/del")
|
|
|
- @PreAuthorize("@pcs.hasPermissions('news/del')")
|
|
|
+ // @PreAuthorize("@pcs.hasPermissions('news/del')")
|
|
|
public Object add(@PathVariable("id") Long id) {
|
|
|
+ SysNewsInformationDto sysNewsInformationDto = sysNewsInformationService.queryById(id);
|
|
|
+ if (sysNewsInformationDto == null) {
|
|
|
+ return failed("未找到相关信息");
|
|
|
+ }
|
|
|
+ if(NewsStatusEnum.SHOW.getCode().equals(sysNewsInformationDto.getStatus().getCode())) {
|
|
|
+ return failed("启用状态下,不可删除");
|
|
|
+ }
|
|
|
return succeed(sysNewsInformationService.deleteWithLogical(id));
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("启用/停用")
|
|
|
+ @PostMapping(value = "/status/{id}")
|
|
|
+ @AuditLogAnnotation(operateName = "资讯启用/停用",interfaceURL = "news/update")
|
|
|
+ // @PreAuthorize("@pcs.hasPermissions('news/del')")
|
|
|
+ public Object status(@PathVariable("id") Long id) {
|
|
|
+ SysNewsInformationDto sysNewsInformationDto = sysNewsInformationService.queryById(id);
|
|
|
+ if (sysNewsInformationDto == null) {
|
|
|
+ return failed("未找到相关信息");
|
|
|
+ }
|
|
|
+ return succeed(sysNewsInformationService.updateStatus(id));
|
|
|
+ }
|
|
|
}
|