Prechádzať zdrojové kódy

feat(system): 新增新闻资讯创建人和更新人字段

- 在 NewsInfo 模型中添加 createdBy 和 updatedBy 字段
- 更新 NewsInfoMapper.xml,增加创建人和更新人的映射
- 修改 NewsInfoServiceImpl,设置创建人和更新人信息
fugui001 3 mesiacov pred
rodič
commit
f862c590a0

+ 3 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/NewsInfo.java

@@ -84,5 +84,8 @@ public class NewsInfo {
      */
     private Date updatedAt;
 
+    private String createdBy;
+
+    private String updatedBy;
 
 }

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/NewsInfoServiceImpl.java

@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.satoken.utils.LoginHelper;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -142,6 +143,8 @@ public class NewsInfoServiceImpl implements INewsInfoService {
         if(newsInfoListByParam!=null){
            baseMapper.updateDefaultNews(bo.getPositionCode());
         }
+        String username = LoginHelper.getUsername();
+        add.setCreatedBy( username);
         boolean flag = baseMapper.insertNewsInfo(add) > 0;
         if (flag) {
             bo.setId(add.getId());
@@ -170,6 +173,8 @@ public class NewsInfoServiceImpl implements INewsInfoService {
         if(newsInfoListByParam!=null){
             baseMapper.updateDefaultNews(bo.getPositionCode());
         }
+        String username = LoginHelper.getUsername();
+        update.setUpdatedBy(username);
         return baseMapper.updateNewsInfoById(update) > 0;
     }
 

+ 3 - 1
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/NewsInfoMapper.xml

@@ -80,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="newsType != null and newsType != ''">news_type,</if>
             <if test="positionCode != null and positionCode != ''">position_code,</if>
             <if test="status != null and status != ''">status,</if>
+            <if test="createdBy != null and createdBy != ''">created_by,</if>
             created_at,
             updated_at
         </trim>
@@ -96,6 +97,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="newsType != null and newsType != ''">#{newsType},</if>
             <if test="positionCode != null and positionCode != ''">#{positionCode},</if>
             <if test="status != null and status != ''">#{status},</if>
+            <if test="createdBy != null and createdBy != ''">#{createdBy},</if>
             NOW(),
             NOW()
         </trim>
@@ -135,7 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
             <!-- status 非空才更新 -->
             <if test="status != null and status != ''">status = #{status},</if>
-
+            <if test="updatedBy != null and updatedBy != ''">updated_by = #{updatedBy},</if>
             updated_at = NOW()
         </set>
         WHERE id = #{id}