Blame view

MessageController.java 3.89 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
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);
    }
}