From 21989973eb90e0fbf60c60ef9343a117fa67d354 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期日, 28 四月 2024 08:55:56 +0800 Subject: [PATCH] 靳总离职前,应元谋二期项目要求(慧图),做了通信协议修改,在他离职后,从韩月处得到最新协议,并做了部分协议软件实现修改,发现新协议中有一些协议定义有重复,也有错误的,所以这版本协议未全部实现,但实现的部分可以用来测试测控一体阀(与段志强一起测试过)。目前情况下,这版本协议实现不能应用于实际项目中,如果必须实现,还需要结合硬件协议具体实现内容再实现通信中间件的协议解析与构造部分,还需要实现上行数据处理任务树部分。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java | 46 ++++++++++++++++++++++++++++------------------ 1 files changed, 28 insertions(+), 18 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java index 1729ef2..6265e27 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java @@ -1,16 +1,14 @@ package com.dy.common.mybatis; +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.JSONWriter; import com.dy.common.po.BaseEntity; import com.dy.common.util.IDLongGenerator; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.SqlCommandType; -import org.apache.ibatis.plugin.Interceptor; -import org.apache.ibatis.plugin.Intercepts; -import org.apache.ibatis.plugin.Invocation; -import org.apache.ibatis.plugin.Plugin; -import org.apache.ibatis.plugin.Signature; +import org.apache.ibatis.plugin.*; import java.lang.reflect.Method; @@ -27,29 +25,41 @@ static int MAPPED_STATEMENT_INDEX = 0; static int PARAMETER_INDEX = 1; - static int ROWBOUNDS_INDEX = 2; - static int RESULT_HANDLER_INDEX = 3; static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME = "setId"; - static String BASE_FIELD_SET_CREATE_TIME_FUNTION_NAME = "setCreateDt"; - static String BASE_FIELD_SET_UPDATE_TIME_FUNTION_NAME = "setUpdateDt"; - static String BASE_FIELD_SET_DELETE_FUNTION_NAME = "setDelete"; + static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME2 = "setUserId"; - public AutoGenerateIdInterceptor() { - //System.out.println("auto generate primaryKey mybatis plugin start!!!"); - } - - @SuppressWarnings("static-access") + /** + * 鎷︽埅閫昏緫瀹炵幇 + * @param invocation 浠g悊 + * @return Object + * @throws Throwable 寮傚父 + */ public Object intercept(Invocation invocation) throws Throwable { MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX]; SqlCommandType commandType = mappedStatement.getSqlCommandType(); - if (commandType.INSERT.equals(SqlCommandType.INSERT)) { + if (commandType.equals(SqlCommandType.INSERT)) { Object entity = invocation.getArgs()[PARAMETER_INDEX]; if (entity instanceof BaseEntity) { - Class<? extends Object> entityClass = entity.getClass(); - Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; + //Class<? extends Object> entityClass = entity.getClass(); + Class<?> entityClass = entity.getClass(); + Method setMt = null ; + try{ + // 娣诲姞鐢ㄦ埛鏃秛serId涓鸿嚜鍔ㄧ敓鎴愪富閿�俽oleId瀛樺湪鏃舵槸涓虹敤鎴风粦瑙掕壊 + String jsonString = JSONObject.toJSONString(entity, JSONWriter.Feature.WriteMapNullValue); + JSONObject jsonObject = JSONObject.parseObject(jsonString); + if(jsonObject.containsKey("userId") && !jsonObject.containsKey("roleId")) { + setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME2, Long.class) ; + }else { + //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃 + setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; + } + }catch (Exception e){ + //褰揺ntityClass娌℃湁setId鏂规硶鏃讹紝浼氭姏鍑哄紓甯� + } if(setMt != null){ setMt.invoke(entity, new IDLongGenerator().generate()); } + invocation.getArgs()[PARAMETER_INDEX] = entity; } } -- Gitblit v1.8.0