MessageController.java 3.89 KB
package com.zhongzhi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.constant.Platform;
import com.zhongzhi.common.utils.DateFormatUtil;
import com.zhongzhi.common.utils.Localstorage;
import com.zhongzhi.common.utils.LoginRequired;
import com.zhongzhi.common.utils.ResponseData;
import com.zhongzhi.dto.message.MessagePageDTO;
import com.zhongzhi.model.AdministerDO;
import com.zhongzhi.model.MessageDO;
import com.zhongzhi.service.MessageService;
import com.zhongzhi.vo.ResponseVO;
import com.zhongzhi.vo.message.MessageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 通知消息表 前端控制器
 * </p>
 *
 * @author DengMin
 * @since 2021-05-17
 */
@RestController
@Api(tags = "通知消息")
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping(value = "/getMessage")
    @ApiOperation("查询通知")
    public ResponseVO getMessage() {
        List<MessageVO> messages = new ArrayList();

        List<MessageDO> list = messageService.list(new QueryWrapper<MessageDO>()
                .lambda()
                .orderByDesc(MessageDO::getCreateTime));
        for (MessageDO messageDO : list) {
            MessageVO messageVO = new MessageVO();
            BeanUtils.copyProperties(messageDO, messageVO);
            messageVO.setReleaseTime(DateFormatUtil.format(messageDO.getReleaseTime(), DateFormatUtil.FMT_sdf_yMd));
            messages.add(messageVO);
        }
        return ResponseData.generateCreatedResponse(0, messages);
    }

    @PostMapping(value = "/getMessageById")
    @LoginRequired({Platform.center})
    @ApiOperation("中心端 --- 根据ID查询详情:id/ID")
    public ResponseVO getMessageById(@RequestBody MessageDO messageDO) {
        return ResponseData.generateCreatedResponse(0, messageService.getById(messageDO.getId()));
    }

    @PostMapping(value = "/getMessagePage")
    @LoginRequired({Platform.center})
    @ApiOperation("中心端  ---分页查询通知: pageNo/当前页数, pageSize/每页显示条数")
    public ResponseVO getMessagePage(@RequestBody MessagePageDTO messagePageDTO) {
        return ResponseData.generateCreatedResponse(0, messageService.getMessagePage(messagePageDTO));
    }

    @PostMapping(value = "/createMessage")
    @LoginRequired({Platform.center})
    @ApiOperation("中心端  ---创建通知: title/标题, content/内容, attachmentUrl/附件地址, releaseTime/发布时间, attachmentName/附件名称, attachmentType/附件类型")
    public ResponseVO createMessage(@RequestBody MessageDO messageDO) {
        messageService.createMessage(messageDO);
        return ResponseData.generateCreatedResponse(0);
    }

    @PostMapping(value = "/updateMessage")
    @LoginRequired({Platform.center})
    @ApiOperation("中心端  ---编辑通知: id/ID, title/标题, content/内容, attachmentUrl/附件地址, attachmentName/附件名称, attachmentType/附件类型")
    public ResponseVO updateMessage(@RequestBody MessageDO messageDO) {
        messageService.updateById(messageDO);
        return ResponseData.generateCreatedResponse(0);
    }

    @PostMapping(value = "/delete")
    @LoginRequired({Platform.center})
    @ApiOperation("中心端  ---删除通知: id/ID, ")
    public ResponseVO delete(@RequestBody MessageDO messageDO) {
        messageService.removeById(messageDO.getId());
        return ResponseData.generateCreatedResponse(0);
    }
}