瀏覽代碼

【制度查询】设置部分字段默认填充策略相关代码更新

fangtasyj 7 月之前
父節點
當前提交
6420c29171

+ 0 - 25
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/config/AutoPaginationInnerInterceptor.java

@@ -1,25 +0,0 @@
-package com.ruoyi.zzb.zdcx.config;
-
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
-import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
-import org.apache.ibatis.executor.Executor;
-
-/**
- * 配置动态数据库方言
- */
-public class AutoPaginationInnerInterceptor extends PaginationInnerInterceptor {
-
-    @Override
-    protected IDialect findIDialect(Executor executor) {
-        // 首先尝试获取已经设置的方言
-        IDialect dialect = super.findIDialect(executor);
-        // 如果方言未设置,则根据数据库连接类型动态获取
-        if (dialect == null) {
-            return DialectFactory.getDialect(JdbcUtils.getDbType(executor));
-        }
-        return dialect;
-    }
-
-}

+ 0 - 29
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/config/MyBatisPlusConfig.java

@@ -1,29 +0,0 @@
-package com.ruoyi.zzb.zdcx.config;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
-import com.ruoyi.common.utils.PageUtils;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
-
-/**
- * MyBatisPlus配置类
- */
-//@Configuration
-//@EnableTransactionManagement
-public class MyBatisPlusConfig {
-//    @Bean(value = "MybatisPlusInterceptor_oracle")
-    public MybatisPlusInterceptor mybatisPlusInterceptor() {
-        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
-        // 分页插件
-//        PaginationInnerInterceptor pi = new PaginationInnerInterceptor(DbType.ORACLE);
-        // 设置最大查询数量,防止一次查询太多数据,给数据库压力过大
-//        pi.setMaxLimit(1000L);
-        // 添加分页插件
-        interceptor.addInnerInterceptor(new AutoPaginationInnerInterceptor());
-        return interceptor;
-    }
-
-}

+ 26 - 0
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/config/MyMetaObjectHandler.java

@@ -0,0 +1,26 @@
+package com.ruoyi.zzb.zdcx.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+/**
+ * mybatisplus自动填充
+ */
+@Component
+public class MyMetaObjectHandler implements MetaObjectHandler {
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
+        this.strictInsertFill(metaObject, "isDelete", Integer.class, 0);
+        this.strictInsertFill(metaObject, "flag", Integer.class, 1);
+    }
+
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+    }
+
+}

+ 14 - 10
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/controller/ZdcxController.java

@@ -3,13 +3,14 @@ package com.ruoyi.zzb.zdcx.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.zzb.base.domain.BasePersonInfo;
 import com.ruoyi.zzb.common.RspResult;
-import com.ruoyi.zzb.zdcx.domain.Zdcx;
 import com.ruoyi.zzb.zdcx.service.ZdcxService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.sql.SQLIntegrityConstraintViolationException;
+
 @Slf4j
 @RestController
 @RequestMapping("/zhzg/api/zdcx")
@@ -25,7 +26,7 @@ public class ZdcxController {
      */
     @PostMapping("/query")
     public JSONObject query(@RequestBody JSONObject reqBody){
-        if(StringUtils.isBlank(reqBody.getString("queryFlag"))){
+        if(null == reqBody.getInteger("queryFlag")){
             log.error("【查询标志】参数为空");
             return RspResult.error("【查询标志】参数为空");
         }
@@ -37,7 +38,7 @@ public class ZdcxController {
             return RspResult.success(zdcxService.getDataByPage(reqBody));
         }catch (Exception e){
             log.error("根据条件分页查询制度信息发生异常", e);
-            return RspResult.error(e.getMessage());
+            return RspResult.error("根据条件分页查询制度信息发生异常 - " + e.getMessage());
         }
     }
 
@@ -54,15 +55,18 @@ public class ZdcxController {
             return RspResult.error("【用户警号】参数为空");
         }
         // 根据警号查询当前登录用户信息,警号为前端传入
-        BasePersonInfo basePersonInfo = zdcxService.getDataByParams(policeNo);
-        if(basePersonInfo != null){
-            boolean flag = zdcxService.insertStandardInfo(reqBody, basePersonInfo);
-            if(flag){
-                return RspResult.success();
+        try {
+            BasePersonInfo basePersonInfo = zdcxService.getDataByParams(policeNo);
+            if(basePersonInfo != null){
+                if(zdcxService.insertStandardInfo(reqBody, basePersonInfo)){
+                    return RspResult.success();
+                }
             }
-            return RspResult.error("制度规范信息保存失败");
+            return RspResult.error("不存在用户信息,制度规范信息保存失败");
+        } catch (Exception e){
+            log.error("制度规范信息保存失败", e);
+            return RspResult.error("制度规范信息保存失败 - " + e.getMessage());
         }
-        return RspResult.error("不存在用户信息,制度规范信息保存失败");
     }
 
 

+ 7 - 8
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/domain/Zdcx.java

@@ -1,9 +1,6 @@
 package com.ruoyi.zzb.zdcx.domain;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -17,10 +14,11 @@ import java.util.Date;
  */
 @Data
 @NoArgsConstructor
+@AllArgsConstructor
 @TableName("STANDARD_DOC_INFO")
 public class Zdcx {
 
-    @TableId(type = IdType.INPUT, value = "ID")
+    @TableId(type = IdType.ASSIGN_ID, value = "ID")
     @TableField("ID")
     private String id;
     // 文号
@@ -37,7 +35,7 @@ public class Zdcx {
     private String content;
 
     // 发布时间
-    @TableField("CREATE_TIME")
+    @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date createTime;
@@ -56,11 +54,12 @@ public class Zdcx {
     private String createDeptName;
     @TableField("CREATE_DEPT_CODE")
     private String createDeptCode;
+
     // 是否删除
-    @TableField("IS_DELETE")
+    @TableField(value = "IS_DELETE", fill = FieldFill.INSERT)
     private Integer isDelete;
     // 常量标志
-    @TableField("FLAG")
+    @TableField(value = "FLAG", fill = FieldFill.INSERT)
     private Integer flag;
 
 

+ 4 - 11
ruoyi-zzb/src/main/java/com/ruoyi/zzb/zdcx/service/ZdcxService.java

@@ -99,13 +99,10 @@ public class ZdcxService {
     public boolean insertStandardInfo(JSONObject reqBody, BasePersonInfo basePersonInfo){
         Zdcx zdcx = new Zdcx();
         // 制度信息
-        zdcx.setId(UUID.randomUUID().toString().replace("-", ""));
         zdcx.setDocId(reqBody.getString("docId"));
         zdcx.setTitle(reqBody.getString("title"));
         zdcx.setPublishDept(reqBody.getString("publishDept"));
         zdcx.setContent(reqBody.getString("content"));
-        zdcx.setIsDelete(0);
-        zdcx.setFlag(1);
         // 录入人信息
         zdcx.setCreateUserId(basePersonInfo.getUserId());
         zdcx.setCreateUserName(basePersonInfo.getName());
@@ -114,15 +111,11 @@ public class ZdcxService {
         zdcx.setCreateDeptCode(basePersonInfo.getDeptCode());
         zdcx.setCreateParentDeptName(basePersonInfo.getParentDeptName());
         zdcx.setCreateParentDeptCode(basePersonInfo.getParentDeptCode());
-        try {
-            if (zdcxMapper.insert(zdcx) > 0) {
-                log.info("制度规范信息保存成功");
-                return true;
-            }
-        }catch (Exception e){
-            log.error("制度规范信息保存时发生异常", e);
-            return false;
+        if (zdcxMapper.insert(zdcx) > 0) {
+            log.info("制度规范信息保存成功");
+            return true;
         }
+        log.error("制度规范信息保存失败");
         return false;
     }