guoyujia há 4 meses atrás
pai
commit
cfa3e07f06

+ 163 - 0
src/main/java/cn/ezhizao/project/business/notification/controller/SysNotificationController.java

@@ -0,0 +1,163 @@
+package cn.ezhizao.project.business.notification.controller;
+
+import cn.ezhizao.common.utils.poi.ExcelUtil;
+import cn.ezhizao.framework.aspectj.lang.annotation.Log;
+import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
+import cn.ezhizao.framework.web.controller.BaseController;
+import cn.ezhizao.framework.web.domain.AjaxResult;
+import cn.ezhizao.framework.web.page.TableDataInfo;
+import cn.ezhizao.project.business.notification.domain.SysNotification;
+import cn.ezhizao.project.business.notification.service.ISysNotificationService;
+import cn.ezhizao.project.system.domain.SysConfig;
+import cn.ezhizao.project.system.mapper.SysConfigMapper;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+
+
+
+/**
+ * 发版通知公告Controller
+ *
+ * @author ezhizao
+ * @date 2025-01-08
+ */
+@RestController
+@RequestMapping("/business/notification")
+public class SysNotificationController extends BaseController
+{
+    @Resource
+    private ISysNotificationService sysNotificationService;
+    @Resource
+    private SysConfigMapper sysConfigMapper;
+
+    /**
+     * 查询发版通知公告列表
+     */
+//    @PreAuthorize("@ss.hasPermi('business:notification:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        setTenantId(sysNotification);
+        startPage();
+        List<SysNotification> list = sysNotificationService.getList(sysNotification);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出发版通知公告列表
+     */
+    @PreAuthorize("@ss.hasPermi('business:notification:export')")
+    @Log(title = "发版通知公告", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        setTenantId(sysNotification);
+        List<SysNotification> list = sysNotificationService.getList(sysNotification);
+        ExcelUtil<SysNotification> util = new ExcelUtil<SysNotification>(SysNotification.class);
+        util.exportExcel(response, list, "发版通知公告数据");
+    }
+
+    /**
+     * 获取发版通知公告详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('business:notification:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return success(sysNotificationService.getById(id));
+    }
+    @Log(title = "搜索更新中,公告中的发版内容", businessType = BusinessType.SELECT)
+    @GetMapping(value = "/getFbNotification")
+    public AjaxResult getFbNotification(SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        return success(sysNotificationService.query().eq("type", 2).in("status", 1, 2).list());
+    }
+
+    @GetMapping(value = "/getHasNotification")
+    public AjaxResult getHasNotification(SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        SysConfig sysConfig = new SysConfig();
+        sysConfig.setConfigKey("business.sys.showAffiche");
+        SysConfig sysConfig1 = sysConfigMapper.selectConfig(sysConfig);
+        if(sysConfig1.getConfigValue().equals("true")){
+            return AjaxResult.success(sysNotificationService.query().eq("type", 2).in("status", 1, 2).list());
+        }
+        return new AjaxResult(202, "", null);
+    }
+
+    /**
+     * 新增发版通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('business:notification:add')")
+    @Log(title = "发版通知公告", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        setTenantId(sysNotification);
+        if(canSave(sysNotification)){
+            return toAjax(sysNotificationService.save(sysNotification));
+        }
+        return error("已经存在发版公告,不能新增");
+    }
+    //判断如果系统公告类型是发版,且存在其状态为公告中,更新中,不能保存
+    public boolean canSave(SysNotification sysNotification) {
+        //发版且状态为更新中、公告中
+        if(sysNotification.getType() == 2 && (sysNotification.getStatus() == 1 || sysNotification.getStatus() == 2)){
+            //新增
+            if(sysNotification.getId() == null){
+                List<SysNotification> list = sysNotificationService.query().eq("type", 2).in("status", 1, 2).list();
+                if (!list.isEmpty()) {
+                    return false;
+                }
+                return true;
+            }else{
+                List<SysNotification> list = sysNotificationService.query()
+                        .eq("type", 2).in("status", 1, 2).ne("id", sysNotification.getId()).list();
+                if (!list.isEmpty()) {
+                    return false;
+                }
+                return true;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 修改发版通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('business:notification:edit')")
+    @Log(title = "发版通知公告", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody SysNotification sysNotification) throws NoSuchFieldException, IllegalAccessException
+    {
+        setTenantId(sysNotification);
+        if(canSave(sysNotification)){
+            return toAjax(sysNotificationService.updateById(sysNotification));
+        }
+        return error("已经存在发版公告,不能修改");
+    }
+
+    /**
+     * 删除发版通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('business:notification:remove')")
+    @Log(title = "发版通知公告", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable List<Long> ids)
+    {
+        return toAjax(sysNotificationService.removeBatchByIds(ids));
+    }
+
+    @GetMapping("/getUnshowedNotification")
+    public AjaxResult getUnshowedNotification() {
+        // 获取未结束的公告
+        List<SysNotification> list = sysNotificationService.query().eq("status", 2).list();
+        // 假设有一个公告为更新中的公告,另一个公告为非更新中则可以接着查询。
+        return new AjaxResult(list.stream().anyMatch(t -> t.getStatus() == 2) ? 202 : 200, "", list);
+    }
+}

+ 54 - 0
src/main/java/cn/ezhizao/project/business/notification/domain/SysNotification.java

@@ -0,0 +1,54 @@
+package cn.ezhizao.project.business.notification.domain;
+
+import cn.ezhizao.framework.aspectj.lang.annotation.Excel;
+import cn.ezhizao.framework.web.domain.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 发版通知公告对象 sys_notification
+ *
+ * @author ezhizao
+ * @date 2025-01-08
+ */
+@Data
+@TableName(value = "sys_notification")
+public class SysNotification extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 公告标题 */
+    @Excel(name = "公告标题")
+    @ApiModelProperty(value = "公告标题")
+    private String title;
+
+    /** 公告类型(1公告 2发版) */
+    @Excel(name = "公告类型", readConverterExp = "1=公告,2=发版")
+    @ApiModelProperty(value = "公告类型")
+    private Integer type;
+
+    /** 公告内容 */
+    @Excel(name = "公告内容")
+    @ApiModelProperty(value = "公告内容")
+    private String content;
+
+    /** 更新中公告内容 */
+    @Excel(name = "更新中公告内容")
+    @ApiModelProperty(value = "更新中公告内容")
+    private String updateContent;
+
+    /** 公告状态(0 未开始 2 公告中 3更新中 4已完成) */
+    @Excel(name = "公告状态", readConverterExp = "0=,未=开始,2=,公=告中,3=更新中,4=已完成")
+    @ApiModelProperty(value = "公告状态")
+    private Integer status;
+
+    /** 更新者 */
+    @ApiModelProperty(value = "公告状态")
+    private String updateId;
+
+    @TableField(exist = false)
+    private Long tenantId;
+
+}

+ 30 - 0
src/main/java/cn/ezhizao/project/business/notification/mapper/SysNotificationMapper.java

@@ -0,0 +1,30 @@
+package cn.ezhizao.project.business.notification.mapper;
+
+import cn.ezhizao.project.business.notification.domain.SysNotification;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import java.util.List;
+
+/**
+ * 发版通知公告Mapper接口
+ *
+ * @author ezhizao
+ * @date 2025-01-08
+ */
+public interface SysNotificationMapper extends BaseMapper<SysNotification>
+{
+    /**
+     * 查询发版通知公告列表
+     *
+     * @param sysNotification 发版通知公告
+     * @return 发版通知公告集合
+     */
+    public List<SysNotification> getList(SysNotification sysNotification);
+
+    /**
+     * 物理删除
+     * @param sysNotification
+     * @return 删除结果
+    */
+    public int physicalDelete(SysNotification sysNotification);
+}

+ 31 - 0
src/main/java/cn/ezhizao/project/business/notification/service/ISysNotificationService.java

@@ -0,0 +1,31 @@
+package cn.ezhizao.project.business.notification.service;
+
+import cn.ezhizao.project.business.notification.domain.SysNotification;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+/**
+ * 发版通知公告Service接口
+ *
+ * @author ezhizao
+ * @date 2025-01-08
+ */
+public interface ISysNotificationService extends IService<SysNotification>
+{
+    /**
+     * 查询发版通知公告列表
+     *
+     * @param sysNotification 发版通知公告
+     * @return 发版通知公告集合
+     */
+    public List<SysNotification> getList(SysNotification sysNotification);
+
+    /**
+     * 物理删除
+     * @param sysNotification
+     * @return 删除结果
+     */
+    public int physicalDelete(SysNotification sysNotification);
+
+}

+ 45 - 0
src/main/java/cn/ezhizao/project/business/notification/service/impl/SysNotificationServiceImpl.java

@@ -0,0 +1,45 @@
+package cn.ezhizao.project.business.notification.service.impl;
+
+import cn.ezhizao.project.business.notification.domain.SysNotification;
+import cn.ezhizao.project.business.notification.mapper.SysNotificationMapper;
+import cn.ezhizao.project.business.notification.service.ISysNotificationService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+
+/**
+ * 发版通知公告Service业务层处理
+ *
+ * @author ezhizao
+ * @date 2025-01-08
+ */
+@Service
+public class SysNotificationServiceImpl  extends ServiceImpl<SysNotificationMapper, SysNotification> implements ISysNotificationService
+{
+    @Resource
+    private SysNotificationMapper sysNotificationMapper;
+
+    /**
+     * 查询发版通知公告列表
+     *
+     * @param sysNotification 发版通知公告
+     * @return 发版通知公告
+     */
+    @Override
+    public List<SysNotification> getList(SysNotification sysNotification)
+    {
+        return sysNotificationMapper.getList(sysNotification);
+    }
+
+    /**
+     * 物理删除
+     * @param sysNotification
+     * @return 删除结果
+     */
+    @Override
+    public int physicalDelete(SysNotification sysNotification){ return sysNotificationMapper.physicalDelete(sysNotification); };
+
+}

+ 33 - 0
src/main/resources/mybatis/business/notification/SysNotificationMapper.xml

@@ -0,0 +1,33 @@
+<?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="cn.ezhizao.project.business.notification.mapper.SysNotificationMapper">
+
+    <resultMap type="cn.ezhizao.project.business.notification.domain.SysNotification" id="SysNotificationResult">
+        <id column="id" property="id"/>
+    </resultMap>
+
+
+    <select id="getList" parameterType="SysNotification" resultMap="SysNotificationResult">
+        SELECT * FROM sys_notification
+        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
+            deleted = 0
+            <if test="title != null  and title != ''"> AND title = #{title}</if>
+            <if test="type != null "> AND type = #{type}</if>
+            <if test="content != null  and content != ''"> AND content = #{content}</if>
+            <if test="updateContent != null  and updateContent != ''"> AND update_content = #{updateContent}</if>
+            <if test="status != null "> AND status = #{status}</if>
+        </trim>
+    </select>
+
+    <delete id="physicalDelete">
+        DELETE FROM sys_notification
+        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
+            <if test="id != null">
+                id = #{id} AND
+            </if>
+       <!-- 删除条件为其他外键可以在这里加 -->
+        </trim>
+    </delete>
+</mapper>