Переглянути джерело

自动填充处理类FieldMetaObjectHandler

ChenYang 1 рік тому
батько
коміт
00727c462f

+ 3 - 1
README.md

@@ -1,4 +1,6 @@
 # AMS产品
-#Master v2.0 
+#佰穗莱项目(基于master_v2.0)
+
+#master_v2.0的优化内容如下:
  1. Mybatis plus引入,提供工具类CrudService,BaseService的封装
  2. 枚举类工具类EnumUtils,JackSonUtil工具类,RestTemplate提供支持

+ 12 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/bean/dto/WarewmsDTO.java

@@ -0,0 +1,12 @@
+package com.ruoyi.common.core.bean.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class WarewmsDTO implements Serializable {
+
+    private static final long serialVersionUID = -3689701440388944457L;
+
+}

+ 24 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/bean/dto/WarewmsExtDTO.java

@@ -0,0 +1,24 @@
+package com.ruoyi.common.core.bean.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class WarewmsExtDTO extends WarewmsDTO {
+
+
+    private static final long serialVersionUID = 972168161325170489L;
+
+    private Long id;
+
+    private Long creator;
+
+    private Date createDate;
+
+    private Long updater;
+
+    private Date updateDate;
+
+
+}

+ 14 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/bean/entity/WarewmsEntity.java

@@ -0,0 +1,14 @@
+package com.ruoyi.common.core.bean.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@TableName
+public class WarewmsEntity implements Serializable {
+
+    private static final long serialVersionUID = -4517083772312506873L;
+
+}

+ 32 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/bean/entity/WarewmsExtEntity.java

@@ -0,0 +1,32 @@
+package com.ruoyi.common.core.bean.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.util.Date;
+
+@Data
+@Accessors(chain = true)
+public class WarewmsExtEntity extends WarewmsEntity {
+
+    private static final long serialVersionUID = 5454051931854654410L;
+
+    @TableId
+    private String id;
+
+    @TableField(fill = FieldFill.INSERT)
+    private String creator;
+
+    @TableField(fill = FieldFill.INSERT)
+    private Date createDate;
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String updater;
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateDate;
+
+}

+ 0 - 1
ruoyi-common/src/main/java/com/ruoyi/common/exception/GlobalException.java

@@ -18,7 +18,6 @@ public class GlobalException extends RuntimeException
     /**
      * 错误明细,内部调试错误
      *
-     * 和 {@link CommonResult#getDetailMessage()} 一致的设计
      */
     private String detailMessage;
 

+ 0 - 1
ruoyi-common/src/main/java/com/ruoyi/common/exception/ServiceException.java

@@ -24,7 +24,6 @@ public final class ServiceException extends RuntimeException
     /**
      * 错误明细,内部调试错误
      *
-     * 和 {@link CommonResult#getDetailMessage()} 一致的设计
      */
     private String detailMessage;
 

+ 52 - 0
ruoyi-common/src/main/java/com/ruoyi/common/handler/FieldMetaObjectHandler.java

@@ -0,0 +1,52 @@
+
+
+package com.ruoyi.common.handler;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.ruoyi.common.utils.SecurityUtils;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+/**
+ * 公共字段,自动填充值
+ *
+ * @author ChenYang
+ */
+@Component
+public class FieldMetaObjectHandler implements MetaObjectHandler {
+
+    private final static String CREATE_DATE = "createDate";
+    private final static String CREATOR = "creator";
+    private final static String UPDATE_DATE = "updateDate";
+    private final static String UPDATER = "updater";
+
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        /*try {
+            if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
+                BaseExtEntity baseExtEntity = (BaseExtEntity) metaObject.getOriginalObject();
+                Date currentDate = ObjectUtil.isNotNull(baseExtEntity.getCreateDate())
+                        ? baseExtEntity.getCreateDate() : new Date();
+                baseExtEntity.setCreateDate(currentDate).setUpdateDate(currentDate);
+                String operateUser = StringUtils.isNotBlank(baseExtEntity.getCreator())
+                        ? baseExtEntity.getCreator() : SecurityUtils.getUsername();
+                baseExtEntity.setCreator(operateUser).setUpdater(operateUser);
+            }
+        } catch (Exception e) {
+            throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
+        }*/
+        strictInsertFill(metaObject, CREATOR, String.class, SecurityUtils.getUsername());
+        strictInsertFill(metaObject, CREATE_DATE, Date.class, DateUtil.date());
+        strictInsertFill(metaObject, UPDATER, String.class, SecurityUtils.getUsername());
+        strictInsertFill(metaObject, UPDATE_DATE, Date.class, DateUtil.date());
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        strictInsertFill(metaObject, UPDATER, String.class, SecurityUtils.getUsername());
+        strictInsertFill(metaObject, UPDATE_DATE, Date.class, DateUtil.date());
+    }
+}

+ 0 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/JacksonUtil.java

@@ -18,7 +18,6 @@ public class JacksonUtil {
         return StringUtils.isNotBlank(jsonString) ? mapper.readValue(jsonString, clazz) : null ;
     }
 
-
     @SneakyThrows
     public static <T> T toObject(String jsonString, TypeReference<T> typeReference) {
         return (T)(StringUtils.isNotBlank(jsonString) ? mapper.readValue(jsonString, typeReference) : null) ;

+ 0 - 61
warewms-ams/src/main/java/com/ruoyi/ams/project/service/BaseLocationInfoSubService.java

@@ -1,61 +0,0 @@
-package com.ruoyi.ams.project.service;
-
-import com.alibaba.fastjson.JSON;
-import com.ruoyi.ams.config.domain.dto.LotattDTO;
-import com.ruoyi.base.domain.vo.BaseLocationLotattVO;
-import com.ruoyi.base.service.IBaseLocationInfoService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author JWK
- * @version 1.0
- * @date 2023/4/3 18:44
- */
-@Service
-public class BaseLocationInfoSubService {
-
-    @Autowired
-    private IBaseLocationInfoService baseLocationInfoService;
-
-
-    /**
-     * 根据条件查询可分配库位
-     *
-     * @param zoneId
-     * @param bindSku
-     * @param orderBy
-     * @return
-     */
-    public List<BaseLocationLotattVO> selectAllocatingInventoryAccordingConditionsOrderBy(List<String> zoneId
-            , String bindSku
-            , String orderBy) {
-        return baseLocationInfoService.selectAllocatingLocationAccordingConditionsOrderBy(zoneId
-                , bindSku
-                , orderBy);
-    }
-
-    /**
-     * 根据条件查询可分配库存
-     *
-     * @param zoneId
-     * @param lotattDTO
-     * @param sku
-     * @param orderBy
-     * @return
-     */
-    public List<BaseLocationLotattVO> selectAllocatingInventoryAccordingConditionsOrderBy(List<String> zoneId
-            , LotattDTO lotattDTO
-            , String sku
-            , String orderBy) {
-        Map<String, String> map = JSON.parseObject(JSON.toJSONString(lotattDTO), HashMap.class);
-        return baseLocationInfoService.selectAllocatingInventoryAccordingConditionsOrderBy(zoneId
-                , map
-                , sku
-                , orderBy);
-    }
-}