parent
e1602d076c
commit
96838b34d6
@ -0,0 +1,135 @@ |
||||
package com.hfkj.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMessage; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.message.BsMessageService; |
||||
import com.hfkj.sysenum.message.MessageStatusEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/msg") |
||||
@Api(value = "消息") |
||||
public class BsMessageController { |
||||
private static Logger log = LoggerFactory.getLogger(BsMessageController.class); |
||||
@Resource |
||||
private BsMessageService messageService; |
||||
|
||||
@RequestMapping(value="/edit",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑消息") |
||||
public ResponseData edit(@RequestBody BsMessage body) { |
||||
try { |
||||
if (body == null |
||||
|| body.getType() == null |
||||
|| StringUtils.isBlank(body.getTitle()) |
||||
|| StringUtils.isBlank(body.getContent()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
BsMessage message; |
||||
if (null != body.getId()) { |
||||
// 查询消息
|
||||
message = messageService.getDetail(body.getId()); |
||||
if (message == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} else { |
||||
message = new BsMessage(); |
||||
message.setStatus(MessageStatusEnum.status1.getStatus()); |
||||
} |
||||
message.setType(body.getType()); |
||||
message.setTitle(body.getTitle()); |
||||
message.setContent(body.getContent()); |
||||
messageService.editData(message); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/release",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "发布消息") |
||||
public ResponseData release(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("id") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询消息
|
||||
BsMessage message = messageService.getDetail(body.getLong("id")); |
||||
if (message == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
message.setStatus(MessageStatusEnum.status2.getStatus()); |
||||
messageService.editData(message); |
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/del",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除消息") |
||||
public ResponseData del(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("id") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询消息
|
||||
BsMessage message = messageService.getDetail(body.getLong("id")); |
||||
if (message == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
message.setStatus(MessageStatusEnum.status0.getStatus()); |
||||
messageService.editData(message); |
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询消息列表") |
||||
public ResponseData queryList(@RequestParam(name = "type", required = true) Integer type, |
||||
@RequestParam(name = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("type", type); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(messageService.getList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue