dongxin 1 год назад
Родитель
Сommit
f1c2500284

+ 73 - 0
linkwe-chinacoal/src/main/java/com/linkwechat/coal/datasource/BdshdbDataSourceConfig.java

@@ -0,0 +1,73 @@
+package com.linkwechat.coal.datasource;
+
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+import org.apache.ibatis.logging.stdout.StdOutImpl;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+
+import javax.sql.DataSource;
+
+/**
+ * 从数据源配置
+ */
+@Configuration
+@MapperScan(basePackages = {"com.linkwechat.coal.modules.bdshdb.*.mapper"}, sqlSessionFactoryRef = "ltycaasdbSqlSessionFactory")
+public class BdshdbDataSourceConfig {
+
+    @Bean(name = "bdshdbDataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.bdshdb")
+    public DataSource bdshdbDataSource() {
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "bdshdbSqlSessionFactory")
+    public SqlSessionFactory bdshdbSqlSessionFactory(@Qualifier("bdshdbDataSource") DataSource datasource)
+            throws Exception {
+        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
+        //configuration配置bean
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.setCacheEnabled(false);
+        // 配置打印sql语句s
+        configuration.setLogImpl(StdOutImpl.class);
+        // 添加自定义SQL注入
+        bean.setConfiguration(configuration);
+
+        //插件对象
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+
+        //分页插件
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+        bean.setDataSource(datasource);
+        // 设置mybatis的xml所在位置
+        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/modules/bdshdb/*/*.xml"));
+        bean.setPlugins(mybatisPlusInterceptor);
+        return bean.getObject();
+    }
+
+    @Bean("bdshdbSqlSessionTemplate")
+    public SqlSessionTemplate bdshdbSqlSessionTemplate(
+            @Qualifier("bdshdbSqlSessionFactory") SqlSessionFactory sessionFactory) {
+        return new SqlSessionTemplate(sessionFactory);
+    }
+
+    @Bean("bdshdbTransactionManager")
+    public PlatformTransactionManager bdshdbTransactionManager(@Qualifier("bdshdbDataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+
+}

+ 72 - 0
linkwe-chinacoal/src/main/java/com/linkwechat/coal/datasource/JzgdbDataSourceConfig.java

@@ -0,0 +1,72 @@
+package com.linkwechat.coal.datasource;
+
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+import org.apache.ibatis.logging.stdout.StdOutImpl;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+
+import javax.sql.DataSource;
+
+/**
+ * 从数据源配置
+ */
+@Configuration
+@MapperScan(basePackages = {"com.linkwechat.coal.modules.jzgdb.*.mapper"}, sqlSessionFactoryRef = "jzgdbSqlSessionFactory")
+public class JzgdbDataSourceConfig {
+
+    @Bean(name = "jzgdbDataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.jzgdb")
+    public DataSource jzgdbDataSource() {
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "jzgdbSqlSessionFactory")
+    public SqlSessionFactory jzgdbSqlSessionFactory(@Qualifier("jzgdbDataSource") DataSource datasource)
+            throws Exception {
+        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
+        //configuration配置bean
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.setCacheEnabled(false);
+        // 配置打印sql语句s
+        configuration.setLogImpl(StdOutImpl.class);
+        // 添加自定义SQL注入
+        bean.setConfiguration(configuration);
+
+        //插件对象
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+
+        //分页插件
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+        bean.setDataSource(datasource);
+        // 设置mybatis的xml所在位置
+        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/modules/jzgdb/*/*.xml"));
+        bean.setPlugins(mybatisPlusInterceptor);
+        return bean.getObject();
+    }
+
+    @Bean("jzgdbSqlSessionTemplate")
+    public SqlSessionTemplate jzgdbSqlSessionTemplate(
+            @Qualifier("jzgdbSqlSessionFactory") SqlSessionFactory sessionFactory) {
+        return new SqlSessionTemplate(sessionFactory);
+    }
+
+    @Bean("jzgdbTransactionManager")
+    public PlatformTransactionManager jzgdbTransactionManager(@Qualifier("jzgdbDataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+}

+ 141 - 0
linkwe-chinacoal/src/main/resources/mapper/modules/bdshdb/customer/test.xml

@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.linkwechat.coal.modules.qywx.system.mapper.SysDeptMapper">
+
+	<resultMap type="com.linkwechat.common.core.domain.entity.SysDept" id="SysDeptResult">
+		<id     property="deptId"     column="dept_id"     />
+		<result property="parentId"   column="parent_id"   />
+		<result property="ancestors"  column="ancestors"   />
+		<result property="deptName"   column="dept_name"   />
+		<result property="deptEnName"   column="dept_en_name"   />
+		<result property="orderNum"   column="order_num"   />
+		<result property="leader"     column="leader"      />
+		<result property="phone"      column="phone"       />
+		<result property="email"      column="email"       />
+		<result property="status"     column="status"      />
+		<result property="delFlag"    column="del_flag"    />
+		<result property="parentName" column="parent_name" />
+		<result property="createBy"   column="create_by"   />
+		<result property="createTime" column="create_time" />
+		<result property="updateBy"   column="update_by"   />
+		<result property="updateTime" column="update_time" />
+	</resultMap>
+
+	<sql id="Base_Column_List">
+		d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+	</sql>
+	<sql id="selectDeptVo">
+        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+        from sys_dept d
+    </sql>
+
+	<select id="selectDeptList" parameterType="com.linkwechat.common.core.domain.entity.SysDept" resultMap="SysDeptResult">
+        <include refid="selectDeptVo"/>
+        where d.del_flag = '0'
+        <if test="parentId != null and parentId != 0">
+			AND parent_id = #{parentId}
+		</if>
+		<if test="deptName != null and deptName != ''">
+			AND dept_name like concat('%', #{deptName}, '%')
+		</if>
+		<if test="status != null and status != ''">
+			AND status = #{status}
+		</if>
+		order by d.parent_id, d.order_num
+    </select>
+	<select id="select3DeptList" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0' /*and
+		(d.ancestors REGEXP  '^[0-9]+,[0-9]+,[0-9]+,[0-9]+$'
+			or d.ancestors REGEXP  '^[0-9]+,[0-9]+,[0-9]+$'
+			or d.parent_id='1' )*/
+		<if test="parentId != null and parentId != 0">
+			AND parent_id = #{parentId}
+		</if>
+		<if test="deptName != null and deptName != ''">
+			AND dept_name like concat('%', #{deptName}, '%')
+		</if>
+		<if test="status != null and status != ''">
+			AND status = #{status}
+		</if>
+		order by d.parent_id, d.order_num
+	</select>
+	<select id="selectByDeptIds" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0'
+		and d.dept_id in
+		<foreach collection="deptIds" open="(" item="item" index="index" separator="," close=")">
+			#{item}
+		</foreach>
+	</select>
+	<select id="selectDeptListAllChildren" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		select * from (SELECT
+		d.dept_id, d.parent_id, d.ancestors,
+		case
+		when d.ancestors like '0,1,4%' then concat(d.dept_name,'(公司总部)')
+		when d.ancestors like '0,1,3007%' then concat(d.dept_name,'(个人代理)')
+		when d.ancestors like '0,1,3026%' then concat(d.dept_name,'(业务员)')
+		else d.dept_name
+		end as dept_name,
+		d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+		FROM sys_dept d
+		where status = 0 and del_flag = '0'
+		and dept_id =#{deptId}
+		union
+		select
+		<include refid="Base_Column_List"/>
+		from sys_dept d
+		where status = 0 and del_flag = '0'
+		and (ancestors like concat('%,',#{deptId},',%') or ancestors like concat('%,', #{deptId}))
+		) aa
+	</select>
+	<select id="selectDeptListGetAllChildren" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		select * from (SELECT
+		d.dept_id, d.parent_id, d.ancestors,
+		case
+		when d.ancestors like '0,1,4%' then concat(d.dept_name,'(公司总部)')
+		when d.ancestors like '0,1,2973%' then concat(d.dept_name,'(离职人员)')
+		when d.ancestors like '0,1,3007%' then concat(d.dept_name,'(个人代理)')
+		when d.ancestors like '0,1,3026%' then concat(d.dept_name,'(业务员)')
+		when d.ancestors like '0,1,3088%' then concat(d.dept_name,'(IT)')
+		when d.ancestors like '0,1,3092%' then concat(d.dept_name,'(IT支持)')
+		when d.ancestors like '0,1,3104%' then concat(d.dept_name,'(专业代理)')
+		else d.dept_name
+		end as dept_name,
+		d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+		FROM sys_dept d
+		where status = 0 and del_flag = '0'
+		and dept_id  =#{dept}
+		union
+		select
+		<include refid="Base_Column_List"/>
+		from sys_dept d
+		where status = 0 and del_flag = '0'
+		and (ancestors like concat('%,',#{dept},',%') or ancestors like concat('%,', #{dept}))
+		) aa
+	</select>
+	<select id="selectByParentId" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		SELECT <include refid="Base_Column_List"/> from sys_dept a where a.parent_id=#{deptId}
+		and status = 0 and del_flag = '0'
+	</select>
+
+	<select id="selectParentDeptId" resultType="java.lang.String">
+		SELECT a.parent_id from sys_dept a
+		where a.dept_id in
+		<foreach collection="deptIds" open="(" item="item" index="index" separator="," close=")">
+			#{item}
+		</foreach>
+		and a.del_flag = '0'
+    </select>
+	<select id="selectByDeptId" resultType="java.lang.String">
+		select aaa.map_type from sys_dept_map aaa where aaa.dept_id = #{deptId}
+
+	</select>
+    <select id="selectByDeptIdGetDept" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		SELECT <include refid="Base_Column_List"/>
+		from sys_dept d
+		where d.dept_id =#{deptId}
+	</select>
+</mapper>

+ 141 - 0
linkwe-chinacoal/src/main/resources/mapper/modules/jzgdb/customer/test.xml

@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.linkwechat.coal.modules.qywx.system.mapper.SysDeptMapper">
+
+	<resultMap type="com.linkwechat.common.core.domain.entity.SysDept" id="SysDeptResult">
+		<id     property="deptId"     column="dept_id"     />
+		<result property="parentId"   column="parent_id"   />
+		<result property="ancestors"  column="ancestors"   />
+		<result property="deptName"   column="dept_name"   />
+		<result property="deptEnName"   column="dept_en_name"   />
+		<result property="orderNum"   column="order_num"   />
+		<result property="leader"     column="leader"      />
+		<result property="phone"      column="phone"       />
+		<result property="email"      column="email"       />
+		<result property="status"     column="status"      />
+		<result property="delFlag"    column="del_flag"    />
+		<result property="parentName" column="parent_name" />
+		<result property="createBy"   column="create_by"   />
+		<result property="createTime" column="create_time" />
+		<result property="updateBy"   column="update_by"   />
+		<result property="updateTime" column="update_time" />
+	</resultMap>
+
+	<sql id="Base_Column_List">
+		d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+	</sql>
+	<sql id="selectDeptVo">
+        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+        from sys_dept d
+    </sql>
+
+	<select id="selectDeptList" parameterType="com.linkwechat.common.core.domain.entity.SysDept" resultMap="SysDeptResult">
+        <include refid="selectDeptVo"/>
+        where d.del_flag = '0'
+        <if test="parentId != null and parentId != 0">
+			AND parent_id = #{parentId}
+		</if>
+		<if test="deptName != null and deptName != ''">
+			AND dept_name like concat('%', #{deptName}, '%')
+		</if>
+		<if test="status != null and status != ''">
+			AND status = #{status}
+		</if>
+		order by d.parent_id, d.order_num
+    </select>
+	<select id="select3DeptList" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0' /*and
+		(d.ancestors REGEXP  '^[0-9]+,[0-9]+,[0-9]+,[0-9]+$'
+			or d.ancestors REGEXP  '^[0-9]+,[0-9]+,[0-9]+$'
+			or d.parent_id='1' )*/
+		<if test="parentId != null and parentId != 0">
+			AND parent_id = #{parentId}
+		</if>
+		<if test="deptName != null and deptName != ''">
+			AND dept_name like concat('%', #{deptName}, '%')
+		</if>
+		<if test="status != null and status != ''">
+			AND status = #{status}
+		</if>
+		order by d.parent_id, d.order_num
+	</select>
+	<select id="selectByDeptIds" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0'
+		and d.dept_id in
+		<foreach collection="deptIds" open="(" item="item" index="index" separator="," close=")">
+			#{item}
+		</foreach>
+	</select>
+	<select id="selectDeptListAllChildren" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		select * from (SELECT
+		d.dept_id, d.parent_id, d.ancestors,
+		case
+		when d.ancestors like '0,1,4%' then concat(d.dept_name,'(公司总部)')
+		when d.ancestors like '0,1,3007%' then concat(d.dept_name,'(个人代理)')
+		when d.ancestors like '0,1,3026%' then concat(d.dept_name,'(业务员)')
+		else d.dept_name
+		end as dept_name,
+		d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+		FROM sys_dept d
+		where status = 0 and del_flag = '0'
+		and dept_id =#{deptId}
+		union
+		select
+		<include refid="Base_Column_List"/>
+		from sys_dept d
+		where status = 0 and del_flag = '0'
+		and (ancestors like concat('%,',#{deptId},',%') or ancestors like concat('%,', #{deptId}))
+		) aa
+	</select>
+	<select id="selectDeptListGetAllChildren" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		select * from (SELECT
+		d.dept_id, d.parent_id, d.ancestors,
+		case
+		when d.ancestors like '0,1,4%' then concat(d.dept_name,'(公司总部)')
+		when d.ancestors like '0,1,2973%' then concat(d.dept_name,'(离职人员)')
+		when d.ancestors like '0,1,3007%' then concat(d.dept_name,'(个人代理)')
+		when d.ancestors like '0,1,3026%' then concat(d.dept_name,'(业务员)')
+		when d.ancestors like '0,1,3088%' then concat(d.dept_name,'(IT)')
+		when d.ancestors like '0,1,3092%' then concat(d.dept_name,'(IT支持)')
+		when d.ancestors like '0,1,3104%' then concat(d.dept_name,'(专业代理)')
+		else d.dept_name
+		end as dept_name,
+		d.dept_en_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
+		FROM sys_dept d
+		where status = 0 and del_flag = '0'
+		and dept_id  =#{dept}
+		union
+		select
+		<include refid="Base_Column_List"/>
+		from sys_dept d
+		where status = 0 and del_flag = '0'
+		and (ancestors like concat('%,',#{dept},',%') or ancestors like concat('%,', #{dept}))
+		) aa
+	</select>
+	<select id="selectByParentId" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		SELECT <include refid="Base_Column_List"/> from sys_dept a where a.parent_id=#{deptId}
+		and status = 0 and del_flag = '0'
+	</select>
+
+	<select id="selectParentDeptId" resultType="java.lang.String">
+		SELECT a.parent_id from sys_dept a
+		where a.dept_id in
+		<foreach collection="deptIds" open="(" item="item" index="index" separator="," close=")">
+			#{item}
+		</foreach>
+		and a.del_flag = '0'
+    </select>
+	<select id="selectByDeptId" resultType="java.lang.String">
+		select aaa.map_type from sys_dept_map aaa where aaa.dept_id = #{deptId}
+
+	</select>
+    <select id="selectByDeptIdGetDept" resultType="com.linkwechat.common.core.domain.entity.SysDept">
+		SELECT <include refid="Base_Column_List"/>
+		from sys_dept d
+		where d.dept_id =#{deptId}
+	</select>
+</mapper>