浏览代码

配置mybatis多数据源,通过在controller层添加@TargetDataSource注解决定使用工信局的库还是发改委的库进行查询primary(工信局),secondary(发改委)

Wayne 4 月之前
父节点
当前提交
a0119850bb

+ 4 - 0
projects-service/src/main/java/com/rtrh/projects/modules/projects/service/impl/SubInfoServiceImpl.java

@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
 
 import com.rtrh.core.vo.Message;
 import com.rtrh.projects.modules.projects.dao.*;
+import com.rtrh.projects.modules.projects.mapper.SubInfoMapper;
 import com.rtrh.projects.modules.projects.po.*;
 import com.rtrh.projects.modules.projects.service.*;
 import com.rtrh.projects.modules.projects.vo.*;
@@ -145,6 +146,9 @@ public class SubInfoServiceImpl implements SubInfoService {
     @Autowired
     private TSystableDao tSystableDao;
 
+    @Autowired
+    private SubInfoMapper subInfoMapper;
+
     @Override
     public Page pageYqInfo(Page page, LoginUserVO vo, String projName, String startTime, String endTime, String overStatus, String year, String beginMonth, String endMonth, Boolean onlySub) {
         Page data = subInfoDao.pageYqInfo(page, vo, projName, startTime, endTime, overStatus, year, beginMonth, endMonth, onlySub, null, null, null, null, null);

+ 1 - 0
projects/src/main/java/com/rtrh/projects/web/controller/subject/api/SubInfoApiController.java

@@ -31,6 +31,7 @@ import com.rtrh.projects.modules.system.service.SubDataLogService;
 import com.rtrh.projects.modules.utils.DateUtils;
 import com.rtrh.projects.vo.subject.*;
 import com.rtrh.projects.web.log.Log;
+import com.rtrh.projects.web.util.TargetDataSource;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.DetachedCriteria;

+ 23 - 0
projects/src/main/java/com/rtrh/projects/web/util/DataSourceAspect.java

@@ -0,0 +1,23 @@
+package com.rtrh.projects.web.util;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+public class DataSourceAspect {
+
+    @Around("@annotation(targetDataSource)")
+    public Object switchDataSource(ProceedingJoinPoint point, TargetDataSource targetDataSource) throws Throwable {
+        String dataSource = targetDataSource.value();
+        DataSourceContextHolder.setDataSourceType(dataSource);
+
+        try {
+            return point.proceed();
+        } finally {
+            DataSourceContextHolder.clearDataSourceType();  // 执行完毕后清除数据源
+        }
+    }
+}

+ 18 - 0
projects/src/main/java/com/rtrh/projects/web/util/DataSourceContextHolder.java

@@ -0,0 +1,18 @@
+package com.rtrh.projects.web.util;
+
+public class DataSourceContextHolder {
+
+    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
+
+    public static void setDataSourceType(String dataSourceType) {
+        contextHolder.set(dataSourceType);
+    }
+
+    public static String getDataSourceType() {
+        return contextHolder.get();
+    }
+
+    public static void clearDataSourceType() {
+        contextHolder.remove();
+    }
+}

+ 12 - 0
projects/src/main/java/com/rtrh/projects/web/util/DynamicDataSource.java

@@ -0,0 +1,12 @@
+package com.rtrh.projects.web.util;
+
+import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
+
+public class DynamicDataSource extends AbstractRoutingDataSource {
+
+    @Override
+    protected Object determineCurrentLookupKey() {
+        // 获取当前线程绑定的数据源标识符
+        return DataSourceContextHolder.getDataSourceType();
+    }
+}

+ 12 - 0
projects/src/main/java/com/rtrh/projects/web/util/TargetDataSource.java

@@ -0,0 +1,12 @@
+package com.rtrh.projects.web.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TargetDataSource {
+    String value() default "primary";  // 默认是主数据源
+}

+ 6 - 0
projects/src/main/resources/dbconfig.properties

@@ -11,3 +11,9 @@ jdbc.password=Chaoliu@0917!@#
 #jdbc.username=root
 #jdbc.password=123456
 ##rtrhcrmdb
+
+#??????
+jdbc.secondary.driver=com.mysql.jdbc.Driver
+jdbc.secondary.url=jdbc:mysql://139.155.7.62:3306/subject_gxj?useUnicode=true&useSSL=false&characterEncoding=UTF-8&autoReconnect=true
+jdbc.secondary.username=root
+jdbc.secondary.password=Chaoliu@0917!@#

+ 32 - 1
projects/src/main/resources/rtrh-datasource.xml

@@ -46,5 +46,36 @@
         <property name="testOnReturn" value="false" />  
         <property name="maxOpenPreparedStatements" value="100" />
     </bean>
-    
+
+    <bean id="secondaryDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
+        <property name="url" value="${jdbc.secondary.url}" />
+        <property name="username" value="${jdbc.secondary.username}" />
+        <property name="password" value="${jdbc.secondary.password}" />
+        <property name="driverClassName" value="${jdbc.secondary.driver}" />
+        <property name="filters" value="stat" />
+
+        <property name="maxActive" value="100" />
+        <property name="initialSize" value="1" />
+        <property name="maxWait" value="60000" />
+        <property name="timeBetweenEvictionRunsMillis" value="60000" />
+        <property name="minEvictableIdleTimeMillis" value="300000" />
+
+        <property name="validationQuery" value="SELECT 'x' FROM DUAL" />
+        <property name="testWhileIdle" value="true" />
+        <property name="testOnBorrow" value="false" />
+        <property name="testOnReturn" value="false" />
+        <property name="maxOpenPreparedStatements" value="100" />
+    </bean>
+
+    <bean id="dataSource" class="com.rtrh.projects.web.util.DynamicDataSource">
+        <property name="targetDataSources">
+            <map>
+                <entry key="primary" value-ref="poolDataSource" />
+                <entry key="secondary" value-ref="secondaryDataSource" />
+            </map>
+        </property>
+        <property name="defaultTargetDataSource" ref="poolDataSource" />
+    </bean>
+
+
 </beans>

+ 40 - 4
projects/src/main/resources/rtrh-mybatis.xml

@@ -13,7 +13,7 @@
 		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd">
 	
 	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-		<property name="dataSource" ref="poolDataSource" />
+		<property name="dataSource" ref="dataSource" />
 		<property name="typeAliasesPackage" value="classpath*:/com.rtrh.core.plugins,com.rtrh.core.plugins,com.rtrh.demo.modules" />
 	<!-- 	<property name="configLocation" value="classpath:mybatisMsSqlConfig.xml" /> -->
 		<property name="mapperLocations" >
@@ -35,19 +35,55 @@
 		    </list>
 		  </property>
 	</bean>
+
+	<bean id="secondarySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+		<property name="dataSource" ref="dataSource" />
+		<property name="typeAliasesPackage" value="classpath*:/com/rtrh/core/plugins,com.rtrh.core.plugins,com.rtrh.demo.modules" />
+		<property name="mapperLocations">
+			<list>
+				<value>classpath*:/com/rtrh/core/plugins/**/mapper/*Mapper.xml</value>
+				<value>classpath*:/com/rtrh/projects/modules/**/*Mapper.xml</value>
+			</list>
+		</property>
+		<property name="plugins">
+			<list>
+				<bean class="com.github.pagehelper.PageHelper">
+					<property name="properties">
+						<value>
+							dialect=mysql
+							reasonable=true
+						</value>
+					</property>
+				</bean>
+			</list>
+		</property>
+	</bean>
 	
 	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
 		<property name="annotationClass" value="com.rtrh.core.repository.mybatis.MyBatisRepository" />
 		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
 		<property name="basePackage" value="com.rtrh.core.plugins.**.mapper,com.rtrh.**.modules.**.mapper" />
 	</bean>
-	
+
+	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+		<property name="annotationClass" value="com.rtrh.core.repository.mybatis.MyBatisRepository" />
+		<property name="sqlSessionFactoryBeanName" value="secondarySqlSessionFactory" />
+		<property name="basePackage" value="com.rtrh.core.plugins.**.mapper,com.rtrh.**.modules.**.mapper" />
+	</bean>
+
+
 	<!-- 配置事务 -->  
 	<bean id="txManager_mybatis"  
 	        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
 	    <property name="dataSource" ref="poolDataSource" />  
-	</bean>  
+	</bean>
+	<bean id="txManager_secondary"
+		  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+		<property name="dataSource" ref="secondaryDataSource" />
+	</bean>
+
 	<!-- 配置基于注解的事物aop -->  
-	<tx:annotation-driven transaction-manager="txManager_mybatis" proxy-target-class="true"/>  
+	<tx:annotation-driven transaction-manager="txManager_mybatis" proxy-target-class="true"/>
+	<tx:annotation-driven transaction-manager="txManager_secondary" proxy-target-class="true"/>
 
 </beans>

+ 11 - 15
projects/src/main/webapp/vmodules/subPreNew/sbForm.jsp

@@ -254,7 +254,7 @@
                     <div class="layui-form-label required" style='width:84px'> 办理人</div>
                     <div class="layui-input-block form-text">
                         <input type="text" class="layui-input" v-model="currObjData.transactors"
-                               placeholder="输入办理人">
+                               placeholder="输入办理人" disabled>
                     </div>
                 </div>
             </div>
@@ -264,7 +264,7 @@
                     <label class="layui-form-label required" style='width:94px'>办理人电话</label>
                     <div class="layui-input-block form-text">
                         <input type="text" class="layui-input" v-model="currObjData.transactorsPhone"
-                               placeholder="输入办理人">
+                               placeholder="输入办理人" disabled>
                     </div>
                 </div>
             </div>
@@ -275,7 +275,7 @@
                     <label class="layui-form-label required" style='width:84px'>开始办理时间</label>
                     <div class="layui-input-block form-text">
                         <input type="text" id="datePlan" readonly="readonly" class="layui-input"
-                               v-model="currObjData.datePlan" placeholder="请选择时间">
+                               v-model="currObjData.datePlan" placeholder="请选择时间" disabled>
                     </div>
                 </div>
             </div>
@@ -284,7 +284,7 @@
                     <label class="layui-form-label required" style='width:94px'>实际批复时间</label>
                     <div class="layui-input-block form-text">
                         <input type="text" id="dateConfirm" readonly="readonly" class="layui-input"
-                               v-model="currObjData.dateConfirm" placeholder="请选择时间">
+                               v-model="currObjData.dateConfirm" placeholder="请选择时间" disabled>
                     </div>
                 </div>
             </div>
@@ -294,7 +294,7 @@
                 <label class="layui-form-label required" style='width:84px'>批复文号</label>
                 <div class="layui-input-block form-text">
                     <input v-model="currObjData.apprNo" name="apprNo" style='width:305px' class="layui-input"
-                           placeholder="请输入批复文号">
+                           placeholder="请输入批复文号" disabled>
                 </div>
             </div>
         </div>
@@ -310,25 +310,21 @@
                                          @click="showImage1(item.fileAddre,item.fileType,item.createTime)"
                                          :alt="item.fileName"/>
                                     <div class="download_icon" @click="download(item.fileAddre,item.fileName)"></div>
-                                    <i class="layui-icon layui-icon-delete" @click="delPic(index)"></i>
                                 </div>
                                 {{item.fileName}}
                             </li>
-                            <li class="add" id="addPic">
-                                <div class="bg"><i class="layui-icon layui-icon-addition"></i></div>
-                            </li>
                         </ul>
                     </div>
                 </div>
             </div>
         </div>
         </div>
-        <div class="layui-row">
-            <div class="layui-form-item">
-                <label class="layui-form-label" style='width:84px'></label>
-                <input type="button" value="保存" class="layui-btn save-btn" lay-submit lay-filter="save"/>
-            </div>
-        </div>
+<%--        <div class="layui-row">--%>
+<%--            <div class="layui-form-item">--%>
+<%--                <label class="layui-form-label" style='width:84px'></label>--%>
+<%--                <input type="button" value="保存" class="layui-btn save-btn" lay-submit lay-filter="save"/>--%>
+<%--            </div>--%>
+<%--        </div>--%>
     </form>
 </template>
 <script type="text/html" id="imageDiv">

+ 23 - 8
projects/src/main/webapp/vmodules/subject/subInfo/report.jsp

@@ -66,8 +66,8 @@
 										<div class="layui-form-item">
 											<div class="layui-input-block time_box">
 												<button type="button" class="layui-btn layui-btn-normal" @click="search">查询</button>
-												<button type="button" class="layui-btn layui-btn-export" @click="downTemplate">下载模板</button>
-												<button type="button" class="layui-btn layui-btn-export" @click="impExcel">导入</button>
+<%--												<button type="button" class="layui-btn layui-btn-export" @click="downTemplate">下载模板</button>--%>
+<%--												<button type="button" class="layui-btn layui-btn-export" @click="impExcel">导入</button>--%>
 											</div>
 										</div>
 									</div>
@@ -76,9 +76,9 @@
 						</div>
 					</div>
 				</div>
-				<div>
-					<button class="layui-btn btn_add" @click="add">新增</button>
-				</div>
+<%--				<div>--%>
+<%--					<button class="layui-btn btn_add" @click="add">新增</button>--%>
+<%--				</div>--%>
 
 			</div>
 			<div class="table_box">
@@ -244,7 +244,8 @@
 </script>
 <script type="text/html" id="toolBar">
 	<div class="toolBar">
-		<span  style="width: 30px;" lay-event="detail">办理</span>
+		<span  style="width: 30px;" lay-event="toPre">办理情况</span>
+		<span  style="width: 30px;" lay-event="toDetail">项目详情</span>
 	</div>
 </script>
 <script>
@@ -284,7 +285,7 @@ new Vue({
 				  ,multiple: false //允许上传多个文件
     	    });
 			this.getData();
-			//window.toDetail = this.toDetail;
+			window.toDetail = this.toDetail;
 		},
 		del: function(obj) {
 			var self = this;
@@ -359,7 +360,7 @@ new Vue({
 					// {field: '', title: '周报', minWidth: 100, templet: '#week'},
 					// {field: '', title: '月报', minWidth: 100, templet: '#month'},
 					// {field: '', title: '是否停工', minWidth: 100, templet: '#stop'},
-					{title: '操作', width: 100, align:'center', toolbar: '#toolBar',},
+					{title: '操作', width: 180, align:'center', toolbar: '#toolBar',},
 				]],
 				fixed:true,
 				height:window.screen.availHeight-380,
@@ -424,6 +425,20 @@ new Vue({
 		detail: function(obj) {
 			window.location.href=App.getUrl("/subject/subInfo/detail?subId=" + obj.data.id);
 		},
+		// 前往项目手续办理页面
+		toPre: function (obj) {
+			window.location.href=App.getUrl("/subPreNew/sbTodo?subId=" + obj.data.id);
+		},
+		toDetail: function (obj) {
+			//详情
+			var index = layer.open({
+				type: 2,
+				title: '',
+				area: ['1000px', '800px'],
+				content: App.getUrl("/subject/subInfo/detailView?layer=true&subId=" + obj.data.id + "&lastUrl=" + window.location.href),
+			});
+			layui.layer.full(index);
+		},
 		preEdit: function(obj) {
 			window.location.href=App.getUrl("/subPreNew/todo?subId=" + obj.data.id);
 		},