Browse Source

feat:表中新增基础默认字段,创建修改人、时间、逻辑删除筛选数据,生产数据携带默认值等

韩帛霖 1 year ago
parent
commit
dcf99a1c04

+ 11 - 6
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.TableSql;
 import com.ruoyi.system.mapper.CommonMapper;
@@ -21,8 +22,7 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.util.*;
 
-import static com.ruoyi.common.utils.StringUtils.convertToCamelCase;
-import static com.ruoyi.common.utils.StringUtils.toUnderScoreCase;
+import static com.ruoyi.common.utils.StringUtils.*;
 
 
 @Service
@@ -59,9 +59,14 @@ public class CommonServiceImpl implements ICommonService {
                 fieldNames.add(toUnderScoreCase(key));
             });
         });
+        fieldNames.add("create_by");
+        fieldNames.add("create_time");
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("create_by", SecurityUtils.getUsername());
+        objectMap.put("create_time", DateUtils.getTime());
+        mapList.add(objectMap);
         return commonMapper.batchInsert(fieldNames, tableName, mapList);
 
-
 //        String tableName = (String) commonEntity.getBasicMap().get("tableName");
 //        List<Map<String, String>> list = commonEntity.getAddListMap();
 //        List<Map<String, Object>> mapList = new ArrayList<>();
@@ -87,10 +92,10 @@ public class CommonServiceImpl implements ICommonService {
         Map<String, Object> fields = JSONObject.parseObject(JSON.toJSONString(commonEntity.getCommMap()));
         Map<String, Object> endfields = new HashMap<>();
         fields.keySet().forEach(item -> {
-//            Map<String, Object> asd = JSONObject.parseObject("{ \"" + toUnderScoreCase(item) + "\":\"" + fields.get(item) + "\"}", new TypeReference<Map<String, Object>>() {
-//            });
             endfields.put(toUnderScoreCase(item), fields.get(item));
         });
+        endfields.put("update_by", SecurityUtils.getUsername());
+        endfields.put("update_time", DateUtils.getTime());
         return commonMapper.edit(endfields, tableName, conditions);
     }
 
@@ -188,7 +193,7 @@ public class CommonServiceImpl implements ICommonService {
         for (int w = 0; w < mapList.size(); w++) {
             XSSFRow row = sheet.createRow(rowIndex++);
             for (int e = 0; e < fieldList.size(); e++) {
-                Object val = mapList.get(w).get(toUnderScoreCase(fieldList.get(e)));
+                Object val = mapList.get(w).get(toCamelCase(fieldList.get(e)));
                 row.createCell(e).setCellValue((val == null ? "" : val).toString());
             }
         }

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -203,7 +203,8 @@ public class DragTableServiceImpl implements IDragTableService {
                 }
                 break;
         }
-        tableSql.setTableCondition(SQL + SQL_END);
+        String where = dragTableVo.getDtTableName() + ".del_flag = '2'";
+        tableSql.setTableCondition(where + SQL + SQL_END);
         tableSql.setTableAlias(dragTableVo.getDtTableName());
         tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
         tableSql.setSqlKey(dragTableVo.getSqlKey());

+ 1 - 1
ruoyi-system/src/main/resources/mapper/common/CommonMapper.xml

@@ -39,7 +39,7 @@
     </insert>
 
     <delete id="batchDelete">
-        delete from ${tableName}
+        update ${tableName} set del_flag = '2'
         <where>
             <if test="conditions != null">
                 <foreach collection="conditions" item="value" index="key" separator="and">