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<>(); } }