公告通知

This commit is contained in:
zjf committed 2025-07-01 18:51:36 +08:00
1 parent 32e04599da
commit 0a1cd59e77
6 files changed
+343

No files matched your search

@@ -0,0 +1,171 @@
package com.bsd.pjcloud.integrated.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.integrated.entity.NoticeEntity;
import com.bsd.pjcloud.integrated.service.NoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 通知公告
*
* @author zjf
* @date 2025-07-01 13:49:09
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/notice" )
@Tag(description = "notice" , name = "通知公告管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class NoticeController {
private final NoticeService noticeService;
/**
* 分页查询
* @param page 分页对象
* @param notice 通知公告
* @return
*/
@Operation(summary = "分页查询" , description = "分页查询" )
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('integrated_notice_view')" )
public R getNoticePage(@ParameterObject Page page, @ParameterObject NoticeEntity notice) {
LambdaQueryWrapper<NoticeEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(notice.getTitle()),NoticeEntity::getTitle,notice.getTitle());
return R.ok(noticeService.page(page, wrapper));
}
/**
* 通过id查询通知公告
* @param id id
* @return R
*/
@Operation(summary = "通过id查询" , description = "通过id查询" )
@GetMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('integrated_notice_view')" )
public R getById(@PathVariable("id" ) Long id) {
return R.ok(noticeService.getById(id));
}
/**
* 新增通知公告
* @param notice 通知公告
* @return R
*/
@Operation(summary = "新增通知公告" , description = "新增通知公告" )
@SysLog("新增通知公告" )
@PostMapping
@PreAuthorize("@pms.hasPermission('integrated_notice_add')" )
public R save(@RequestBody NoticeEntity notice) {
notice.setDeptId(SecurityUtils.getUser().getDeptId());
return R.ok(noticeService.save(notice));
}
/**
* 修改通知公告
* @param notice 通知公告
* @return R
*/
@Operation(summary = "修改通知公告" , description = "修改通知公告" )
@SysLog("修改通知公告" )
@PutMapping
@PreAuthorize("@pms.hasPermission('integrated_notice_edit')" )
public R updateById(@RequestBody NoticeEntity notice) {
return R.ok(noticeService.updateById(notice));
}
/**
* 通过id删除通知公告
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除通知公告" , description = "通过id删除通知公告" )
@SysLog("通过id删除通知公告" )
@DeleteMapping
@PreAuthorize("@pms.hasPermission('integrated_notice_del')" )
public R removeById(@RequestBody Long[] ids) {
return R.ok(noticeService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param notice 查询条件
* @param ids 导出指定ID
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('integrated_notice_export')" )
public List<NoticeEntity> export(NoticeEntity notice,Long[] ids) {
return noticeService.list(Wrappers.lambdaQuery(notice).in(ArrayUtil.isNotEmpty(ids), NoticeEntity::getId, ids));
}
/**
* App分页公告列表
* @param page 分页对象
* @param title 公告标题(可选)
* @return R
*/
@Operation(summary = "App分页公告列表", description = "App分页公告列表")
@GetMapping("/app/page")
public R getAppNoticePage(@ParameterObject Page page, @RequestParam(required = false) String title) {
LambdaQueryWrapper<NoticeEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(NoticeEntity::getStatus, "0"); // 只查已发布
wrapper.like(StrUtil.isNotBlank(title), NoticeEntity::getTitle, title);
wrapper.orderByDesc(NoticeEntity::getIsTop, NoticeEntity::getCreateTime); // 置顶优先,时间倒序
return R.ok(noticeService.page(page, wrapper));
}
/**
* App公告详情
* @param id 公告ID
* @return R
*/
@Operation(summary = "App公告详情", description = "App公告详情")
@GetMapping("/app/{id}")
public R getAppNoticeDetail(@PathVariable("id") Long id) {
NoticeEntity notice = noticeService.getById(id);
if (notice == null || !"0".equals(notice.getStatus())) {
return R.failed("公告不存在或已下架");
}
return R.ok(notice);
}
/**
* App公告浏览量+1
* @param id 公告ID
* @return R
*/
@Operation(summary = "App公告浏览量+1", description = "App公告浏览量+1")
@PostMapping("/app/view/{id}")
public R addViewCount(@PathVariable("id") Long id) {
NoticeEntity notice = noticeService.getById(id);
if (notice == null || !"0".equals(notice.getStatus())) {
return R.failed("公告不存在或已下架");
}
notice.setViewCount((notice.getViewCount() == null ? 0 : notice.getViewCount()) + 1);
noticeService.updateById(notice);
return R.ok();
}
}
@@ -0,0 +1,115 @@
package com.bsd.pjcloud.integrated.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
* 通知公告
*
* @author zjf
* @date 2025-07-01 13:49:09
*/
@Data
@TenantTable
@TableName("notice")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "通知公告")
public class NoticeEntity extends Model<NoticeEntity> {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="id")
private Long id;
/**
* 公告详情
*/
@Schema(description="公告详情")
private String description;
/**
* 状态 0已发布,1已下架
*/
@Schema(description="状态 0已发布,1已下架")
private String status;
/**
* 部门id
*/
@Schema(description="部门id")
private Long deptId;
/**
* 公告标题
*/
@Schema(description="公告标题")
private String title;
/**
* 公告图片
*/
@Schema(description="公告图片")
private String picUrl;
/**
* 是否置顶
*/
@Schema(description="是否置顶")
private String isTop;
/**
* 浏览次数
*/
@Schema(description="浏览次数")
private Integer viewCount;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建者")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
private LocalDateTime createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="更新者")
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="更新时间")
private LocalDateTime updateTime;
/**
* 是否删除
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description="是否删除")
private String delFlag;
/**
* 租户编号
*/
@Schema(description="租户编号")
private Long tenantId;
}
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.integrated.mapper;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.integrated.entity.NoticeEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface NoticeMapper extends PjcloudBaseMapper<NoticeEntity> {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.integrated.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.integrated.entity.NoticeEntity;
public interface NoticeService extends IService<NoticeEntity> {
}
@@ -0,0 +1,16 @@
package com.bsd.pjcloud.integrated.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.integrated.entity.NoticeEntity;
import com.bsd.pjcloud.integrated.mapper.NoticeMapper;
import com.bsd.pjcloud.integrated.service.NoticeService;
import org.springframework.stereotype.Service;
/**
* 通知公告
*
* @author zjf
* @date 2025-07-01 13:49:09
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, NoticeEntity> implements NoticeService {
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.integrated.mapper.NoticeMapper">
<resultMap id="noticeMap" type="com.bsd.pjcloud.integrated.entity.NoticeEntity">
<id property="id" column="id"/>
<result property="description" column="description"/>
<result property="status" column="status"/>
<result property="deptId" column="dept_id"/>
<result property="title" column="title"/>
<result property="picUrl" column="pic_url"/>
<result property="isTop" column="is_top"/>
<result property="viewCount" column="view_count"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>