Pārlūkot izejas kodu

中英文切换Demo

qxp 5 gadi atpakaļ
vecāks
revīzija
efd5c991a6

+ 86 - 0
bin/start_dgtly-admin.sh

@@ -0,0 +1,86 @@
+#!/bin/bash
+
+AppName=dgtly-admin.jar
+
+#JVM参数
+JVM_OPTS="-Dname=$AppName  -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
+APP_HOME=`pwd`
+LOG_PATH=$APP_HOME/logs/$AppName.log
+
+if [ "$1" = "" ];
+then
+    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
+    exit 1
+fi
+
+if [ "$AppName" = "" ];
+then
+    echo -e "\033[0;31m 未输入应用名 \033[0m"
+    exit 1
+fi
+
+function start()
+{
+    PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
+
+	if [ x"$PID" != x"" ]; then
+	    echo "$AppName is running..."
+	else
+		nohup java -jar  $JVM_OPTS $AppName --spring.profiles.active=test > $LOG_PATH 2>&1 &
+		echo "Start $AppName success..."
+	fi
+}
+
+function stop()
+{
+    echo "Stop $AppName"
+	
+	PID=""
+	query(){
+		PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
+	}
+
+	query
+	if [ x"$PID" != x"" ]; then
+		kill -TERM $PID
+		echo "$AppName (pid:$PID) exiting..."
+		while [ x"$PID" != x"" ]
+		do
+			sleep 1
+			query
+		done
+		echo "$AppName exited."
+	else
+		echo "$AppName already stopped."
+	fi
+}
+
+function restart()
+{
+    stop
+    sleep 2
+    start
+}
+
+function status()
+{
+    PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
+    if [ $PID != 0 ];then
+        echo "$AppName is running..."
+    else
+        echo "$AppName is not running..."
+    fi
+}
+
+case $1 in
+    start)
+    start;;
+    stop)
+    stop;;
+    restart)
+    restart;;
+    status)
+    status;;
+    *)
+
+esac

+ 86 - 0
bin/start_dgtly-api.sh

@@ -0,0 +1,86 @@
+#!/bin/bash
+
+AppName=dgtly-api.jar
+
+#JVM参数
+JVM_OPTS="-Dname=$AppName  -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
+APP_HOME=`pwd`
+LOG_PATH=$APP_HOME/logs/$AppName.log
+
+if [ "$1" = "" ];
+then
+    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
+    exit 1
+fi
+
+if [ "$AppName" = "" ];
+then
+    echo -e "\033[0;31m 未输入应用名 \033[0m"
+    exit 1
+fi
+
+function start()
+{
+    PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
+
+	if [ x"$PID" != x"" ]; then
+	    echo "$AppName is running..."
+	else
+		nohup java -jar  $JVM_OPTS $AppName --spring.profiles.active=test > $LOG_PATH 2>&1 &
+		echo "Start $AppName success..."
+	fi
+}
+
+function stop()
+{
+    echo "Stop $AppName"
+	
+	PID=""
+	query(){
+		PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
+	}
+
+	query
+	if [ x"$PID" != x"" ]; then
+		kill -TERM $PID
+		echo "$AppName (pid:$PID) exiting..."
+		while [ x"$PID" != x"" ]
+		do
+			sleep 1
+			query
+		done
+		echo "$AppName exited."
+	else
+		echo "$AppName already stopped."
+	fi
+}
+
+function restart()
+{
+    stop
+    sleep 2
+    start
+}
+
+function status()
+{
+    PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
+    if [ $PID != 0 ];then
+        echo "$AppName is running..."
+    else
+        echo "$AppName is not running..."
+    fi
+}
+
+case $1 in
+    start)
+    start;;
+    stop)
+    stop;;
+    restart)
+    restart;;
+    status)
+    status;;
+    *)
+
+esac

+ 42 - 0
dgtly-apiframework/src/main/java/com/dgtly/apiframework/config/SwitchEnSqlInterceptorConfig.java

@@ -0,0 +1,42 @@
+package com.dgtly.apiframework.config;
+
+import com.dgtly.apiframework.interceptor.SwitchEnSqlInterceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.PostConstruct;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+
+@Configuration
+@ConditionalOnBean({SqlSessionFactory.class})
+@AutoConfigureAfter({MybatisAutoConfiguration.class})
+public class SwitchEnSqlInterceptorConfig {
+
+        @Autowired
+        private List<SqlSessionFactory> sqlSessionFactoryList;
+
+        public SwitchEnSqlInterceptorConfig() {
+        }
+
+
+
+        @PostConstruct
+        public void addPageInterceptor() {
+            SwitchEnSqlInterceptor interceptor = new SwitchEnSqlInterceptor();
+            Iterator var3 = this.sqlSessionFactoryList.iterator();
+            Properties properties = new Properties();
+            interceptor.setProperties( properties);
+            while(var3.hasNext()) {
+                SqlSessionFactory sqlSessionFactory = (SqlSessionFactory)var3.next();
+                sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
+            }
+
+        }
+}

+ 58 - 0
dgtly-apiframework/src/main/java/com/dgtly/apiframework/interceptor/SwitchEnSqlInterceptor.java

@@ -0,0 +1,58 @@
+package com.dgtly.apiframework.interceptor;
+
+import org.apache.ibatis.cache.CacheKey;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.plugin.*;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.Properties;
+
+@Component
+@Intercepts({@Signature(
+        type = Executor.class,
+        method = "query",
+        args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
+), @Signature(
+        type = Executor.class,
+        method = "query",
+        args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}
+)})
+public class SwitchEnSqlInterceptor  implements Interceptor {
+    private Logger log= LoggerFactory.getLogger(SwitchEnSqlInterceptor.class);
+    public SwitchEnSqlInterceptor() {
+    }
+
+    public Object intercept(Invocation invocation) throws Throwable {
+        // 获取原始sql语句
+        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
+        Object parameter = invocation.getArgs()[1];
+        BoundSql boundSql = mappedStatement.getBoundSql(parameter);
+        String oldsql = boundSql.getSql();
+       // log.info("old:"+oldsql);
+        oldsql = oldsql.replaceAll("gi.name","gi.id name");
+        // 改变sql语句
+        BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), oldsql ,
+                boundSql.getParameterMappings(), boundSql.getParameterObject());
+        invocation.getArgs()[5] = newBoundSql;
+        // 注解invocation.method.annotations()
+        // 继续执行
+        Object result = invocation.proceed();
+        return result;
+    }
+
+
+    public Object plugin(Object target) {
+        // TODO Auto-generated method stub
+        return Plugin.wrap(target, this);
+    }
+
+    public void setProperties(Properties properties) {
+
+    }
+}

+ 15 - 0
dgtly-common/src/main/java/com/dgtly/common/annotation/SwitchEn.java

@@ -0,0 +1,15 @@
+package com.dgtly.common.annotation;
+
+import java.lang.annotation.*;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface SwitchEn {
+
+
+    /**
+     * 
+     */
+    public String files() default "";
+}

+ 2 - 1
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/mapper/GoodsInfoMapper.java

@@ -1,8 +1,8 @@
 package com.dgtly.goods.mapper;
 
+import com.dgtly.common.annotation.SwitchEn;
 import com.dgtly.goods.domain.GoodsInfo;
 import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Property;
 
 import java.util.List;
 
@@ -20,6 +20,7 @@ public interface GoodsInfoMapper
      * @param id 商品基础详情ID
      * @return 商品基础详情
      */
+    @SwitchEn
     public GoodsInfo selectGoodsInfoById(Long id);
 
     /**