Prechádzať zdrojové kódy

add 增加mybatis-plus依赖及配置

fengxiaolei 2 rokov pred
rodič
commit
ac0d44f648

+ 9 - 0
pom.xml

@@ -199,6 +199,14 @@
                 <version>${ruoyi.version}</version>
             </dependency>
 
+
+            <!-- 业务模块-->
+            <dependency>
+                <groupId>com.product.center.manage</groupId>
+                <artifactId>product-center-manage-business</artifactId>
+                <version>${ruoyi.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 
@@ -209,6 +217,7 @@
         <module>product-center-manage-quartz</module>
         <module>product-center-manage-generator</module>
         <module>product-center-manage-common</module>
+        <module>product-center-manage-business</module>
     </modules>
     <packaging>pom</packaging>
 

+ 6 - 0
product-center-manage-admin/pom.xml

@@ -67,6 +67,12 @@
             <artifactId>product-center-manage-generator</artifactId>
         </dependency>
 
+        <!-- 业务模块-->
+        <dependency>
+            <groupId>com.product.center.manage</groupId>
+            <artifactId>product-center-manage-business</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 10 - 0
product-center-manage-admin/src/main/resources/application.yml

@@ -82,6 +82,16 @@ mybatis:
     # 加载全局的配置文件
     configLocation: classpath:mybatis/mybatis-config.xml
 
+# MyBatis Plus配置
+mybatis-plus:
+  # 搜索指定包别名
+  typeAliasesPackage: com.product.center.manage.**.domain
+  # 配置mapper的扫描,找到所有的mapper.xml映射文件
+  mapperLocations: classpath*:mapper/**/*Mapper.xml
+  # 加载全局的配置文件
+  configLocation: classpath:mybatis/mybatis-config.xml
+
+
 # PageHelper分页插件
 pagehelper:
   helperDialect: mysql

+ 15 - 0
product-center-manage-common/pom.xml

@@ -101,6 +101,21 @@
             <artifactId>javax.servlet-api</artifactId>
         </dependency>
 
+
+        <!-- mybatis-plus 增强CRUD -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.4.2</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+
+
     </dependencies>
 
 </project>

+ 132 - 132
product-center-manage-framework/src/main/java/com/product/center/manage/framework/config/MyBatisConfig.java

@@ -1,132 +1,132 @@
-package com.product.center.manage.framework.config;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import javax.sql.DataSource;
-import org.apache.ibatis.io.VFS;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.env.Environment;
-import org.springframework.core.io.DefaultResourceLoader;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.util.ClassUtils;
-import com.product.center.manage.common.utils.StringUtils;
-
-/**
- * Mybatis支持*匹配扫描包
- *
- * @author ruoyi
- */
-@Configuration
-public class MyBatisConfig
-{
-    @Autowired
-    private Environment env;
-
-    static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
-
-    public static String setTypeAliasesPackage(String typeAliasesPackage)
-    {
-        ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
-        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
-        List<String> allResult = new ArrayList<String>();
-        try
-        {
-            for (String aliasesPackage : typeAliasesPackage.split(","))
-            {
-                List<String> result = new ArrayList<String>();
-                aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
-                        + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
-                Resource[] resources = resolver.getResources(aliasesPackage);
-                if (resources != null && resources.length > 0)
-                {
-                    MetadataReader metadataReader = null;
-                    for (Resource resource : resources)
-                    {
-                        if (resource.isReadable())
-                        {
-                            metadataReader = metadataReaderFactory.getMetadataReader(resource);
-                            try
-                            {
-                                result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
-                            }
-                            catch (ClassNotFoundException e)
-                            {
-                                e.printStackTrace();
-                            }
-                        }
-                    }
-                }
-                if (result.size() > 0)
-                {
-                    HashSet<String> hashResult = new HashSet<String>(result);
-                    allResult.addAll(hashResult);
-                }
-            }
-            if (allResult.size() > 0)
-            {
-                typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
-            }
-            else
-            {
-                throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
-            }
-        }
-        catch (IOException e)
-        {
-            e.printStackTrace();
-        }
-        return typeAliasesPackage;
-    }
-
-    public Resource[] resolveMapperLocations(String[] mapperLocations)
-    {
-        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
-        List<Resource> resources = new ArrayList<Resource>();
-        if (mapperLocations != null)
-        {
-            for (String mapperLocation : mapperLocations)
-            {
-                try
-                {
-                    Resource[] mappers = resourceResolver.getResources(mapperLocation);
-                    resources.addAll(Arrays.asList(mappers));
-                }
-                catch (IOException e)
-                {
-                    // ignore
-                }
-            }
-        }
-        return resources.toArray(new Resource[resources.size()]);
-    }
-
-    @Bean
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
-    {
-        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
-        String mapperLocations = env.getProperty("mybatis.mapperLocations");
-        String configLocation = env.getProperty("mybatis.configLocation");
-        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
-        VFS.addImplClass(SpringBootVFS.class);
-
-        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
-        sessionFactory.setDataSource(dataSource);
-        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
-        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
-        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
-        return sessionFactory.getObject();
-    }
-}
+//package com.product.center.manage.framework.config;
+//
+//import java.io.IOException;
+//import java.util.ArrayList;
+//import java.util.Arrays;
+//import java.util.HashSet;
+//import java.util.List;
+//import javax.sql.DataSource;
+//import org.apache.ibatis.io.VFS;
+//import org.apache.ibatis.session.SqlSessionFactory;
+//import org.mybatis.spring.SqlSessionFactoryBean;
+//import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.core.env.Environment;
+//import org.springframework.core.io.DefaultResourceLoader;
+//import org.springframework.core.io.Resource;
+//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+//import org.springframework.core.io.support.ResourcePatternResolver;
+//import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
+//import org.springframework.core.type.classreading.MetadataReader;
+//import org.springframework.core.type.classreading.MetadataReaderFactory;
+//import org.springframework.util.ClassUtils;
+//import com.product.center.manage.common.utils.StringUtils;
+//
+///**
+// * Mybatis支持*匹配扫描包
+// *
+// * @author ruoyi
+// */
+//@Configuration
+//public class MyBatisConfig
+//{
+//    @Autowired
+//    private Environment env;
+//
+//    static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
+//
+//    public static String setTypeAliasesPackage(String typeAliasesPackage)
+//    {
+//        ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
+//        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
+//        List<String> allResult = new ArrayList<String>();
+//        try
+//        {
+//            for (String aliasesPackage : typeAliasesPackage.split(","))
+//            {
+//                List<String> result = new ArrayList<String>();
+//                aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+//                        + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
+//                Resource[] resources = resolver.getResources(aliasesPackage);
+//                if (resources != null && resources.length > 0)
+//                {
+//                    MetadataReader metadataReader = null;
+//                    for (Resource resource : resources)
+//                    {
+//                        if (resource.isReadable())
+//                        {
+//                            metadataReader = metadataReaderFactory.getMetadataReader(resource);
+//                            try
+//                            {
+//                                result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
+//                            }
+//                            catch (ClassNotFoundException e)
+//                            {
+//                                e.printStackTrace();
+//                            }
+//                        }
+//                    }
+//                }
+//                if (result.size() > 0)
+//                {
+//                    HashSet<String> hashResult = new HashSet<String>(result);
+//                    allResult.addAll(hashResult);
+//                }
+//            }
+//            if (allResult.size() > 0)
+//            {
+//                typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
+//            }
+//            else
+//            {
+//                throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
+//            }
+//        }
+//        catch (IOException e)
+//        {
+//            e.printStackTrace();
+//        }
+//        return typeAliasesPackage;
+//    }
+//
+//    public Resource[] resolveMapperLocations(String[] mapperLocations)
+//    {
+//        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
+//        List<Resource> resources = new ArrayList<Resource>();
+//        if (mapperLocations != null)
+//        {
+//            for (String mapperLocation : mapperLocations)
+//            {
+//                try
+//                {
+//                    Resource[] mappers = resourceResolver.getResources(mapperLocation);
+//                    resources.addAll(Arrays.asList(mappers));
+//                }
+//                catch (IOException e)
+//                {
+//                    // ignore
+//                }
+//            }
+//        }
+//        return resources.toArray(new Resource[resources.size()]);
+//    }
+//
+//    @Bean
+//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
+//    {
+//        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
+//        String mapperLocations = env.getProperty("mybatis.mapperLocations");
+//        String configLocation = env.getProperty("mybatis.configLocation");
+//        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
+//        VFS.addImplClass(SpringBootVFS.class);
+//
+//        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
+//        sessionFactory.setDataSource(dataSource);
+//        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
+//        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
+//        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
+//        return sessionFactory.getObject();
+//    }
+//}

+ 62 - 0
product-center-manage-framework/src/main/java/com/product/center/manage/framework/config/MybatisPlusConfig.java

@@ -0,0 +1,62 @@
+package com.product.center.manage.framework.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * Mybatis Plus 配置
+ *
+ * @author ruoyi
+ */
+@EnableTransactionManagement(proxyTargetClass = true)
+@Configuration
+public class MybatisPlusConfig
+{
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor()
+    {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        // 分页插件
+        interceptor.addInnerInterceptor(paginationInnerInterceptor());
+        // 乐观锁插件
+        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
+        // 阻断插件
+        interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
+        return interceptor;
+    }
+
+    /**
+     * 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
+     */
+    public PaginationInnerInterceptor paginationInnerInterceptor()
+    {
+        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
+        // 设置数据库类型为mysql
+        paginationInnerInterceptor.setDbType(DbType.MYSQL);
+        // 设置最大单页限制数量,默认 500 条,-1 不受限制
+        paginationInnerInterceptor.setMaxLimit(-1L);
+        return paginationInnerInterceptor;
+    }
+
+    /**
+     * 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
+     */
+    public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
+    {
+        return new OptimisticLockerInnerInterceptor();
+    }
+
+    /**
+     * 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
+     */
+    public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
+    {
+        return new BlockAttackInnerInterceptor();
+    }
+}

+ 6 - 0
product-center-manage-quartz/pom.xml

@@ -35,6 +35,12 @@
             <artifactId>product-center-manage-common</artifactId>
         </dependency>
 
+        <!-- 系统模块-->
+        <dependency>
+            <groupId>com.product.center.manage</groupId>
+            <artifactId>product-center-manage-business</artifactId>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 22 - 0
product-center-manage-quartz/src/main/java/com/product/center/manage/quartz/task/policysyn/PolicySynJob.java

@@ -0,0 +1,22 @@
+package com.product.center.manage.quartz.task.policysyn;
+
+import com.product.center.manage.service.impl.PolicySynServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author :fxl
+ * @date :Created in 2022/9/22 10:31
+ * @description:
+ */
+public class PolicySynJob {
+
+    @Autowired
+    private PolicySynServiceImpl policySynService;
+
+
+    public void startPolicySyn(){
+        policySynService.startPolicySyn();
+    }
+
+
+}