| | |
| | | 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; |
New file |
| | |
| | | package com.dy.pipIrrGlobal.config; |
| | | |
| | | import jakarta.annotation.PostConstruct; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/4/27 9:31 |
| | | * @Description |
| | | */ |
| | | @Configuration |
| | | public class MyBatisGlConfig { |
| | | |
| | | @Autowired |
| | | private List<SqlSessionFactory> sqlSessionFactoryList; |
| | | |
| | | @Value("${common.virtual_card_disable_set_inuse:false}") |
| | | private Boolean disableSetInUse; |
| | | /** |
| | | * æ ¹æ®é
ç½®æä»¶é
ç½®ï¼é
ç½®æ¦æªå¨ |
| | | */ |
| | | @PostConstruct |
| | | public void addMyInterceptor() { |
| | | for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) { |
| | | if (disableSetInUse != null && disableSetInUse.booleanValue()) { |
| | | sqlSessionFactory.getConfiguration().addInterceptor(new VirtualCardInUseInterceptor()); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrGlobal.config; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/4/27 9:19 |
| | | * @Description |
| | | */ |
| | | import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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.Signature; |
| | | import java.lang.reflect.Method; |
| | | |
| | | /** |
| | | * æ¦æªèæå¡è¡¨çæ´æ°æä½ï¼ä½¿ä¸è½è®¾ç½®å ç¨ç¶ææä½ã |
| | | */ |
| | | @Intercepts({ |
| | | @Signature( |
| | | type = Executor.class, |
| | | method = "update", |
| | | args = { |
| | | MappedStatement.class, |
| | | Object.class |
| | | } |
| | | ) |
| | | }) |
| | | @Slf4j |
| | | public class VirtualCardInUseInterceptor implements Interceptor { |
| | | |
| | | static int MAPPED_STATEMENT_INDEX = 0; |
| | | static int PARAMETER_INDEX = 1; |
| | | static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETINUSE = "setInUse"; |
| | | |
| | | @Override |
| | | public Object intercept(Invocation invocation) throws Throwable { |
| | | Object entity = invocation.getArgs()[PARAMETER_INDEX]; |
| | | if (entity instanceof SeVirtualCard) { |
| | | MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX]; |
| | | SqlCommandType commandType = mappedStatement.getSqlCommandType(); |
| | | if (commandType.equals(SqlCommandType.INSERT)) { |
| | | Class<?> entityClass = entity.getClass(); |
| | | Method setInUse = null; |
| | | try { |
| | | setInUse = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETINUSE, Long.class); |
| | | } catch (Exception e) { |
| | | //å½entityClass没æsetInUseæ¹æ³æ¶ï¼ä¼æåºå¼å¸¸ |
| | | } |
| | | if (setInUse != null) { |
| | | setInUse.invoke(entity, 0); |
| | | } |
| | | invocation.getArgs()[PARAMETER_INDEX] = entity; |
| | | } |
| | | } |
| | | return invocation.proceed(); |
| | | } |
| | | } |
| | |
| | | # 233æå¡å¨ï¼ym,mj,sp,test |
| | | # 121æå¡å¨ï¼mq,yq,hlj,gz,lz,jc |
| | | spring_main_datasource_names: mq,yq,hlj,gz,lz,jc |
| | | |
| | | # èæå¡è¡¨å段in_useæä¸ºå ç¨ç¶æï¼å½ä¸ºtrueæ¶ç»ä¸è®¾ç½®å¼ä¸º0 |
| | | # 233æå¡å¨ï¼false |
| | | # 121æå¡å¨ï¼true |
| | | virtual_card_disable_set_inuse: true |
| | |
| | | # 233æå¡å¨ï¼ym,mj,sp,test |
| | | # 121æå¡å¨ï¼mq,yq,hlj,gz,lz,jc |
| | | spring_main_datasource_names: ym,mj,sp,test |
| | | |
| | | # èæå¡è¡¨å段in_useæä¸ºå ç¨ç¶æï¼å½ä¸ºtrueæ¶ç»ä¸è®¾ç½®å¼ä¸º0 |
| | | # 233æå¡å¨ï¼false |
| | | # 121æå¡å¨ï¼true |
| | | virtual_card_disable_set_inuse: false |
| | |
| | | # 233æå¡å¨ï¼ym,mj,sp,test |
| | | # 121æå¡å¨ï¼mq,yq,hlj,gz,lz,jc |
| | | spring_main_datasource_names: ym,mj,sp,test |
| | | |
| | | # èæå¡è¡¨å段in_useæä¸ºå ç¨ç¶æï¼å½ä¸ºtrueæ¶ç»ä¸è®¾ç½®å¼ä¸º0 |
| | | # 233æå¡å¨ï¼false |
| | | # 121æå¡å¨ï¼true |
| | | virtual_card_disable_set_inuse: false |
| | |
| | | COUNT(*) AS recordCount |
| | | FROM ba_user user |
| | | <where> |
| | | user.supperAdmin != 1 |
| | | AND user.deleted = 0 |
| | | user.deleted = 0 |
| | | <if test = "phone != null and phone !=''"> |
| | | AND user.phone= #{phone} |
| | | </if> |
| | |
| | | if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("æªéæ©ç»ç»åä½"); |
| | | } |
| | | if(vo.token == null || vo.token.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("æ token"); |
| | | } |
| | | if(vo.code == null || vo.code.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("请è¾å
¥éªè¯ç "); |
| | | } |
| | | //æç»ç»å使 ç¾ä½ä¸ºæ°æ®æºåç§° |
| | | DataSourceContext.set(vo.orgTag); |
| | | |
| | | // 仿°æ®åºè·åéªè¯ç |
| | | Map map = sv.getCodeByToken(vo.token); |
| | | Long expiration = Long.parseLong(map.get("expiration").toString()); |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > expiration) { |
| | | return BaseResponseUtils.buildErrorMsg("éªè¯ç å·²è¶
æ¶"); |
| | | } |
| | | String localCode = map.get("code").toString(); |
| | | if(!vo.code.equals(localCode)) { |
| | | return BaseResponseUtils.buildErrorMsg("éªè¯ç é误"); |
| | | if(vo.token != null && vo.token.trim().length() > 0) { |
| | | // ä»sessionä¸è·åéªè¯ç |
| | | //HttpSession session = (HttpSession) request.getSession(); |
| | | //String localCode = session.getAttribute(token).toString(); |
| | | // 仿°æ®åºè·åéªè¯ç |
| | | Map map = sv.getCodeByToken(vo.token); |
| | | Long expiration = Long.parseLong(map.get("expiration").toString()); |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > expiration) { |
| | | return BaseResponseUtils.buildErrorMsg("éªè¯ç å·²è¶
æ¶"); |
| | | } |
| | | String localCode = map.get("code").toString(); |
| | | if(!vo.code.equals(localCode)) { |
| | | return BaseResponseUtils.buildErrorMsg("éªè¯ç é误"); |
| | | } |
| | | } |
| | | |
| | | if(!sv.existPhone(vo.phone)){ |