SystemNoticeController.java 5.5 KB
Newer Older
苗卫卫 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
package com.boco.nbd.wios.manage.controller;

import cn.hutool.core.lang.Assert;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.SystemNotice;
import com.boco.nbd.wios.manage.entity.bo.SystemNoticeBo;
import com.boco.nbd.wios.manage.entity.bo.SystemNoticeVo;
import com.boco.nbd.wios.manage.service.impl.SystemNoticeService;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * 公告管理接口
 *
 * @author wty
 * @version [版本号, 2020年10月21日]
 */
@RestController
@RequestMapping("api")
@Api(tags = "公告管理接口")
@ApiIgnore
public class SystemNoticeController {

    @Autowired
    private SystemNoticeService systemNoticeService;

    /**
     * 添加公告/文件
     *
     * @param systemNotice
     * @return
     */
    @PostMapping(value = "systemNotice/add")
    @ApiOperation(value = "添加公告/文件")

    public BaseResponse<Object> add( SystemNotice systemNotice) {
        if (!StringUtils.isEmpty(systemNotice.getTitle()) && systemNotice.getTitle().length() > WiosConstant.MAX_NOTICE_TITLE_LENGTH) {
            throw new ServiceException("标题过长");
        }
        if (!StringUtils.isEmpty(systemNotice.getContent()) && systemNotice.getContent().length() > WiosConstant.MAX_NOTICE_CONTENT_LENGTH) {
            throw new ServiceException("内容过长");
        }
        Assert.notNull(systemNotice.getType(), "公告类型为空");
        systemNoticeService.add(systemNotice);
        return new BaseResponse<>();

    }

    /**
     * 查询公告/文件列表
     *
     * @param condition
     * @return
     */
    @GetMapping(value = "systemNotice/getList")
    @ApiOperation(value = "查询公告/文件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "一页显示数量", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pagecount", value = "页码", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "type", value = "公告/文件类型", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "allList", value = "所有列表标记", dataType = "int", paramType = "query", required = true),
    })
    public BaseResponse<List<SystemNoticeVo>> getAll(SystemNoticeBo condition) {
        Assert.notNull(condition.getType(), "公告类型为空");
        Assert.notNull(condition.getAllList(), "是否获取所有公告");
        return new BaseResponse<List<SystemNoticeVo>>(systemNoticeService.getList(condition));

    }


    /**
     * 查询公告/文件明细
     *
     * @param id
     * @return
     */
    @GetMapping(value = "systemNotice/detail")
    @ApiOperation(value = "查询公告/文件明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataType = "Long", paramType = "query", required = true),
    })
    public BaseResponse<SystemNoticeVo> getDetail(Long id) {

        Assert.notNull(id, "获取公告Id为空");
        return new BaseResponse<SystemNoticeVo>(systemNoticeService.getDetail(id));

    }

    /**
     * 修改公告/文件明细
     *
     * @param id
     * @return
     */
    @PostMapping(value = "systemNotice/updateNotice")
    @ApiOperation(value = "修改公告/文件明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataType = "Long", paramType = "query", required = true),
    })
    public BaseResponse<SystemNoticeVo> updateNotice(Long id,SystemNoticeBo systemNotice) {
        if (!StringUtils.isEmpty(systemNotice.getTitle()) && systemNotice.getTitle().length() > WiosConstant.MAX_NOTICE_TITLE_LENGTH) {
            throw new ServiceException("标题过长");
        }
        if (!StringUtils.isEmpty(systemNotice.getContent()) && systemNotice.getContent().length() > WiosConstant.MAX_NOTICE_CONTENT_LENGTH) {
            throw new ServiceException("内容过长");
        }
        Assert.notNull(id, "获取公告Id为空");
        Assert.notNull(systemNotice.getType(), "公告类型为空");
        systemNoticeService.updateNotice(systemNotice,id);
        return new BaseResponse<>();

    }

    /**
     * 删除公告/文件
     *
     * @param id
     * @return
     */
    @PostMapping(value = "systemNotice/deltetNotice")
    @ApiOperation(value = "删除公告/文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataType = "Long", paramType = "query", required = true),
    })
    public BaseResponse<SystemNoticeVo> deltetNotice(Long id, SystemNoticeBo systemNotice) {

        Assert.notNull(id, "获取公告Id为空");
        Assert.notNull(systemNotice.getType(), "删除公告类型为空");
        Assert.notNull(systemNotice.getType(), "删除公告状态不确定");
        systemNoticeService.deleteNotice(systemNotice,id);
        return new BaseResponse<>();

    }

}