update 2021-01-20

pull/64/head
陈云志 5 years ago
commit a72dc929be

@ -0,0 +1,7 @@
#! /bin/bash
for bootJar in $(find . -name "project-*.jar")
do
./$bootJar &
done

@ -0,0 +1,15 @@
#!/bin/bash
# 远程机器上程序发布目录 user@ip:/dir
remote_dist=$1
if [[ $remote_dist ]];then
scp -r ./auth-boot/build/libs/project-auth-boot-*.jar $remote_dist/auth &
scp -r ./file-boot/build/libs/project-file-boot-*.jar $remote_dist/file &
scp -r ./gateway-boot/build/libs/project-gateway-boot-*.jar $remote_dist/gateway &
scp -r ./gen-boot/build/libs/project-gen-boot-*.jar $remote_dist/gen &
scp -r ./job-boot/build/libs/project-job-boot-*.jar $remote_dist/job &
scp -r ./monitor-boot/build/libs/project-monitor-boot-*.jar $remote_dist/monitor &
scp -r ./system-boot/build/libs/project-system-boot-*.jar $remote_dist/system &
fi

@ -0,0 +1,18 @@
#!/bin/bash
docker network rm fastdfs-net
docker network create fastdfs-net
docker run -dit --network=fastdfs-net --restart=always --name=fdfs-tracker \
-v /var/fdfs/tracker:/var/fdfs \
ygqygq2/fastdfs-nginx:latest tracker
docker run -dit --network=fastdfs-net --restart=always --name=fdfs-storage0 \
-e TRACKER_SERVER=tracker:22122 -v /var/fdfs/storage0:/var/fdfs \
ygqygq2/fastdfs-nginx:latest storage
docker run -dit --network=fastdfs-net --restart=always --name=fdfs-storage1 \
-e TRACKER_SERVER=tracker:22122 -v /var/fdfs/storage1:/var/fdfs \
ygqygq2/fastdfs-nginx:latest storage

@ -0,0 +1,4 @@
#!/bin/bash
docker rm -f nginx-latest
docker run --name=nginx-latest --restart=always -p 80:80 -v /opt/pscada-online/nginx-conf/:/etc/nginx/ -v /var/logs/nginx:/var/logs/nginx -v /opt/pscada-online/www:/opt/pscada-online/www -e TZ="Asia/Shanghai" -d nginx

@ -0,0 +1,9 @@
#!/bin/bash
docker rm -f prtainer-latest
docker run -itd -p 9000:9000 -e TZ="Asia/Shanghai" \
--name prtainer-latest --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
portainer/portainer-ce

@ -0,0 +1,3 @@
#! /bin/bash
docker rm -f redis-6.0
docker run --name=redis-6.0 --restart=always -itd -v /opt/pscada-online/redis-conf/redis.conf:/etc/redis/redis.conf -p 6379:6379 redis

@ -0,0 +1,6 @@
#!/bin/bash
docker rm -f sentinel-dashboard
docker run --name=sentinel-dashboard --restart=always -e TZ="Asia/Shanghai" -p 9002:8858 -d bladex/sentinel-dashboard:latest

@ -1,8 +0,0 @@
#! /bin/bash
for dir in $(ls .)
do
if [[ -f $dir/project-*.jar ]];then
./$dir/project-*.jar &
fi
done

@ -1,6 +0,0 @@
#! /bin/bash
docker rm -f redis-6.0
#项目程序部署目录
project=$1
docker run --name=redis-6.0 --restart=always -itd -v ${project}/redis-conf/redis.conf:/etc/redis/redis.conf -p 6379:6379 redis

@ -3,25 +3,25 @@
# 使用方法: ./publish.sh 版本号. # 使用方法: ./publish.sh 版本号.
# git pull; git add . ;git commit -m " 发布版本 $*" ; git push # git pull; git add . ;git commit -m " 发布版本 $*" ; git push
gradleArgs="clean publish -DbuildProduct=true -DreleaseVersion=$1" gradleArgs=" -s clean publish -DbuildProduct=true -DreleaseVersion=$1 -DdevVersion=$1"
# 发布公共模块,必须按照下列顺序 编译发布。 # 发布公共模块,必须按照下列顺序 编译发布。
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-core/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-core/build.gradle
gradle $gradleArgs -b ./ruoyi-api/ruoyi-api-system/build.gradle -s gradle $gradleArgs -b ./ruoyi-api/ruoyi-api-system/build.gradle
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-redis/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-redis/build.gradle
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-security/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-security/build.gradle
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-log/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-log/build.gradle
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-datascope/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-datascope/build.gradle
gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-swagger/build.gradle -s gradle $gradleArgs -b ./ruoyi-common/ruoyi-common-swagger/build.gradle
### 六个 微服务依赖, monitor 不需要发布。 ### 六个 微服务依赖, monitor 不需要发布。
gradle $gradleArgs -b ./ruoyi-auth/build.gradle -s gradle $gradleArgs -b ./ruoyi-auth/build.gradle
gradle $gradleArgs -b ./ruoyi-gateway/build.gradle -s gradle $gradleArgs -b ./ruoyi-gateway/build.gradle
gradle $gradleArgs -b ./ruoyi-modules/ruoyi-system/build.gradle -s gradle $gradleArgs -b ./ruoyi-modules/ruoyi-system/build.gradle
gradle $gradleArgs -b ./ruoyi-modules/ruoyi-file/build.gradle -s gradle $gradleArgs -b ./ruoyi-modules/ruoyi-file/build.gradle
gradle $gradleArgs -b ./ruoyi-modules/ruoyi-gen/build.gradle -s gradle $gradleArgs -b ./ruoyi-modules/ruoyi-gen/build.gradle
gradle $gradleArgs -b ./ruoyi-modules/ruoyi-job/build.gradle -s gradle $gradleArgs -b ./ruoyi-modules/ruoyi-job/build.gradle
gradle $gradleArgs -b ./ruoyi-visual/ruoyi-monitor/build.gradle

@ -1,23 +1,22 @@
package com.ruoyi.system.api; package com.ruoyi.system.api;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class) @FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService public interface RemoteFileService {
{
/** /**
* *
* *
@ -25,5 +24,5 @@ public interface RemoteFileService
* @return * @return
*/ */
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file); R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
} }

@ -1,35 +1,24 @@
package com.ruoyi.system.api.factory; package com.ruoyi.system.api.factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteFileService; import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
{
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class); private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
@Override @Override
public RemoteFileService create(Throwable throwable) public RemoteFileService create(Throwable throwable) {
{
log.error("文件服务调用失败:{}", throwable.getMessage()); log.error("文件服务调用失败:{}", throwable.getMessage());
return new RemoteFileService() return file -> R.fail("上传文件失败:" + throwable.getMessage());
{
@Override
public R<SysFile> upload(MultipartFile file)
{
return R.fail("上传文件失败:" + throwable.getMessage());
}
};
} }
} }

@ -1,24 +1,18 @@
package com.ruoyi.common.redis.service; package com.ruoyi.common.redis.service;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* spring redis * spring redis
* *
* @author ruoyi * @author ruoyi
**/ **/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Component @Component
public class RedisService public class RedisService
{ {
@ -31,7 +25,7 @@ public class RedisService
* @param key * @param key
* @param value * @param value
*/ */
public <T> void setCacheObject(final String key, final T value) public <T> void setCacheObject(String key, T value)
{ {
redisTemplate.opsForValue().set(key, value); redisTemplate.opsForValue().set(key, value);
} }
@ -44,7 +38,7 @@ public class RedisService
* @param timeout * @param timeout
* @param timeUnit * @param timeUnit
*/ */
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) public <T> void setCacheObject(String key, T value, Long timeout, TimeUnit timeUnit)
{ {
redisTemplate.opsForValue().set(key, value, timeout, timeUnit); redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
} }
@ -56,7 +50,7 @@ public class RedisService
* @param timeout * @param timeout
* @return true=false= * @return true=false=
*/ */
public boolean expire(final String key, final long timeout) public boolean expire(String key, long timeout)
{ {
return expire(key, timeout, TimeUnit.SECONDS); return expire(key, timeout, TimeUnit.SECONDS);
} }
@ -69,7 +63,7 @@ public class RedisService
* @param unit * @param unit
* @return true=false= * @return true=false=
*/ */
public boolean expire(final String key, final long timeout, final TimeUnit unit) public boolean expire(String key, long timeout, TimeUnit unit)
{ {
return redisTemplate.expire(key, timeout, unit); return redisTemplate.expire(key, timeout, unit);
} }
@ -80,7 +74,7 @@ public class RedisService
* @param key * @param key
* @return * @return
*/ */
public <T> T getCacheObject(final String key) public <T> T getCacheObject(String key)
{ {
ValueOperations<String, T> operation = redisTemplate.opsForValue(); ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key); return operation.get(key);
@ -91,7 +85,7 @@ public class RedisService
* *
* @param key * @param key
*/ */
public boolean deleteObject(final String key) public boolean deleteObject(String key)
{ {
return redisTemplate.delete(key); return redisTemplate.delete(key);
} }
@ -102,7 +96,7 @@ public class RedisService
* @param collection * @param collection
* @return * @return
*/ */
public long deleteObject(final Collection collection) public long deleteObject(Collection collection)
{ {
return redisTemplate.delete(collection); return redisTemplate.delete(collection);
} }
@ -114,7 +108,7 @@ public class RedisService
* @param dataList List * @param dataList List
* @return * @return
*/ */
public <T> long setCacheList(final String key, final List<T> dataList) public <T> long setCacheList(String key, List<T> dataList)
{ {
Long count = redisTemplate.opsForList().rightPushAll(key, dataList); Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count; return count == null ? 0 : count;
@ -126,7 +120,7 @@ public class RedisService
* @param key * @param key
* @return * @return
*/ */
public <T> List<T> getCacheList(final String key) public <T> List<T> getCacheList(String key)
{ {
return redisTemplate.opsForList().range(key, 0, -1); return redisTemplate.opsForList().range(key, 0, -1);
} }
@ -138,7 +132,7 @@ public class RedisService
* @param dataSet * @param dataSet
* @return * @return
*/ */
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) public <T> BoundSetOperations<String, T> setCacheSet(String key, Set<T> dataSet)
{ {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key); BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
Iterator<T> it = dataSet.iterator(); Iterator<T> it = dataSet.iterator();
@ -155,7 +149,7 @@ public class RedisService
* @param key * @param key
* @return * @return
*/ */
public <T> Set<T> getCacheSet(final String key) public <T> Set<T> getCacheSet(String key)
{ {
return redisTemplate.opsForSet().members(key); return redisTemplate.opsForSet().members(key);
} }
@ -166,7 +160,7 @@ public class RedisService
* @param key * @param key
* @param dataMap * @param dataMap
*/ */
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) public <T> void setCacheMap(String key, Map<String, T> dataMap)
{ {
if (dataMap != null) { if (dataMap != null) {
redisTemplate.opsForHash().putAll(key, dataMap); redisTemplate.opsForHash().putAll(key, dataMap);
@ -179,7 +173,7 @@ public class RedisService
* @param key * @param key
* @return * @return
*/ */
public <T> Map<String, T> getCacheMap(final String key) public <T> Map<String, T> getCacheMap(String key)
{ {
return redisTemplate.opsForHash().entries(key); return redisTemplate.opsForHash().entries(key);
} }
@ -191,7 +185,7 @@ public class RedisService
* @param hKey Hash * @param hKey Hash
* @param value * @param value
*/ */
public <T> void setCacheMapValue(final String key, final String hKey, final T value) public <T> void setCacheMapValue(String key, String hKey, T value)
{ {
redisTemplate.opsForHash().put(key, hKey, value); redisTemplate.opsForHash().put(key, hKey, value);
} }
@ -203,7 +197,7 @@ public class RedisService
* @param hKey Hash * @param hKey Hash
* @return Hash * @return Hash
*/ */
public <T> T getCacheMapValue(final String key, final String hKey) public <T> T getCacheMapValue(String key, String hKey)
{ {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash(); HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(key, hKey); return opsForHash.get(key, hKey);
@ -216,19 +210,42 @@ public class RedisService
* @param hKeys Hash * @param hKeys Hash
* @return Hash * @return Hash
*/ */
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) public <T> List<T> getMultiCacheMapValue(String key, Collection<Object> hKeys)
{ {
return redisTemplate.opsForHash().multiGet(key, hKeys); return redisTemplate.opsForHash().multiGet(key, hKeys);
} }
/** /**
* *
* *
* @param pattern * @param pattern
* @return * @return
*/ */
public Collection<String> keys(final String pattern) @Deprecated
public Collection<String> keys(String pattern)
{ {
return redisTemplate.keys(pattern); return redisTemplate.keys(pattern);
} }
/**
* keys
*
* @param matchKey
* @return
*/
public Set<String> scan(String matchKey) {
Set<String> keys = (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
Set<String> keysTmp = new HashSet<>();
Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(matchKey).count(1000).build());
while (cursor.hasNext()) {
keysTmp.add(new String(cursor.next()));
}
try {
cursor.close();
} catch (IOException e) {
}
return keysTmp;
});
return keys;
}
} }

@ -0,0 +1 @@
../../build-config/publish.sh

@ -1,21 +1,22 @@
package com.ruoyi.file.service; package com.ruoyi.file.service;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
/** /**
* FastDFS * FastDFS
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class FastDfsSysFileServiceImpl implements ISysFileService @ConfigurationProperties(prefix = "fdfs")
{ public class FastDfsSysFileServiceImpl implements ISysFileService {
/** /**
* 访 * 访
*/ */
@ -27,14 +28,13 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
/** /**
* FastDfs * FastDfs
* *
* @param file * @param file
* @return 访 * @return 访
* @throws Exception * @throws Exception
*/ */
@Override @Override
public String uploadFile(MultipartFile file) throws Exception public String uploadFile(MultipartFile file) throws Exception {
{
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
FilenameUtils.getExtension(file.getOriginalFilename()), null); FilenameUtils.getExtension(file.getOriginalFilename()), null);
return domain + "/" + storePath.getFullPath(); return domain + "/" + storePath.getFullPath();

@ -1,20 +1,18 @@
package com.ruoyi.file.service; package com.ruoyi.file.service;
import com.ruoyi.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.file.utils.FileUploadUtils;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Primary
@Service //@Service
public class LocalSysFileServiceImpl implements ISysFileService //@ConfigurationProperties(prefix = "fdfs")
{ public class LocalSysFileServiceImpl implements ISysFileService {
/** /**
* *
*/ */
@ -26,7 +24,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
*/ */
@Value("${file.domain}") @Value("${file.domain}")
public String domain; public String domain;
/** /**
* *
*/ */
@ -35,13 +33,13 @@ public class LocalSysFileServiceImpl implements ISysFileService
/** /**
* *
* *
* @param file * @param file
* @return 访 * @return 访
* @throws Exception * @throws Exception
*/ */
public String uploadFile(MultipartFile file) throws Exception @Override
{ public String uploadFile(MultipartFile file) throws Exception {
String name = FileUploadUtils.upload(localFilePath, file); String name = FileUploadUtils.upload(localFilePath, file);
String url = domain + localFilePrefix + name; String url = domain + localFilePrefix + name;
return url; return url;

@ -1,21 +1,22 @@
package com.ruoyi.file.service; package com.ruoyi.file.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.file.config.MinioConfig; import com.ruoyi.file.config.MinioConfig;
import com.ruoyi.file.utils.FileUploadUtils; import com.ruoyi.file.utils.FileUploadUtils;
import io.minio.MinioClient; import io.minio.MinioClient;
import io.minio.PutObjectArgs; import io.minio.PutObjectArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/** /**
* Minio * Minio
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class MinioSysFileServiceImpl implements ISysFileService @Primary
{ public class MinioSysFileServiceImpl implements ISysFileService {
@Autowired @Autowired
private MinioConfig minioConfig; private MinioConfig minioConfig;
@ -24,13 +25,13 @@ public class MinioSysFileServiceImpl implements ISysFileService
/** /**
* *
* *
* @param file * @param file
* @return 访 * @return 访
* @throws Exception * @throws Exception
*/ */
public String uploadFile(MultipartFile file) throws Exception @Override
{ public String uploadFile(MultipartFile file) throws Exception {
String fileName = FileUploadUtils.extractFilename(file); String fileName = FileUploadUtils.extractFilename(file);
PutObjectArgs args = PutObjectArgs.builder() PutObjectArgs args = PutObjectArgs.builder()
.bucket(minioConfig.getBucketName()) .bucket(minioConfig.getBucketName())

@ -38,8 +38,8 @@ dependencies {
implementation "org.apache.commons:commons-lang3:3.11" implementation "org.apache.commons:commons-lang3:3.11"
implementation "io.springfox:springfox-swagger-ui:2.9.2" implementation "io.springfox:springfox-swagger-ui:2.9.2"
implementation "org.mariadb.jdbc:mariadb-java-client:2.7.1" implementation "org.mariadb.jdbc:mariadb-java-client:2.7.1"
implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4" // implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4"
implementation 'com.baomidou:mybatis-plus-boot-starter:3.4.1'
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${alibabaCloud}"
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${alibabaCloud}"
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:${alibabaCloud}"

@ -1,24 +1,22 @@
package com.ruoyi.gen; package com.ruoyi.gen;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import com.ruoyi.common.security.annotation.EnableCustomConfig; import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients; import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@EnableCustomConfig @EnableCustomConfig
@EnableCustomSwagger2 @EnableCustomSwagger2
@EnableRyFeignClients @EnableRyFeignClients
@SpringCloudApplication @SpringCloudApplication
public class RuoYiGenApplication public class RuoYiGenApplication {
{ public static void main(String[] args) {
public static void main(String[] args)
{
SpringApplication.run(RuoYiGenApplication.class, args); SpringApplication.run(RuoYiGenApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 代码生成模块启动成功 ლ(´ڡ`ლ)゙ \n" + System.out.println("(♥◠‿◠)ノ゙ 代码生成模块启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" + " .-------. ____ __ \n" +

@ -5,62 +5,61 @@ import org.springframework.stereotype.Component;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
@ConfigurationProperties(prefix = "gen") @ConfigurationProperties(prefix = "gen")
public class GenConfig public class GenConfig {
{ /**
/** 作者 */ *
*/
public static String author; public static String author;
/** 生成包路径 */ /**
*
*/
public static String packageName; public static String packageName;
/** 自动去除表前缀默认是false */ /**
* false
*/
public static boolean autoRemovePre; public static boolean autoRemovePre;
/** 表前缀(类名不会包含表前缀) */ /**
* ()
*/
public static String tablePrefix; public static String tablePrefix;
public static String getAuthor() public static String getAuthor() {
{
return author; return author;
} }
public void setAuthor(String author) public void setAuthor(String author) {
{
GenConfig.author = author; GenConfig.author = author;
} }
public static String getPackageName() public static String getPackageName() {
{
return packageName; return packageName;
} }
public void setPackageName(String packageName) public void setPackageName(String packageName) {
{
GenConfig.packageName = packageName; GenConfig.packageName = packageName;
} }
public static boolean getAutoRemovePre() public static boolean getAutoRemovePre() {
{
return autoRemovePre; return autoRemovePre;
} }
public void setAutoRemovePre(boolean autoRemovePre) public void setAutoRemovePre(boolean autoRemovePre) {
{
GenConfig.autoRemovePre = autoRemovePre; GenConfig.autoRemovePre = autoRemovePre;
} }
public static String getTablePrefix() public static String getTablePrefix() {
{
return tablePrefix; return tablePrefix;
} }
public void setTablePrefix(String tablePrefix) public void setTablePrefix(String tablePrefix) {
{
GenConfig.tablePrefix = tablePrefix; GenConfig.tablePrefix = tablePrefix;
} }
} }

@ -1,21 +1,5 @@
package com.ruoyi.gen.controller; package com.ruoyi.gen.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
@ -27,16 +11,25 @@ import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.gen.service.IGenTableColumnService; import com.ruoyi.gen.service.IGenTableColumnService;
import com.ruoyi.gen.service.IGenTableService; import com.ruoyi.gen.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@RequestMapping("/gen") @RequestMapping("/gen")
@RestController @RestController
public class GenController extends BaseController public class GenController extends BaseController {
{
@Autowired @Autowired
private IGenTableService genTableService; private IGenTableService genTableService;
@ -48,8 +41,7 @@ public class GenController extends BaseController
*/ */
@PreAuthorize(hasPermi = "tool:gen:list") @PreAuthorize(hasPermi = "tool:gen:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo genList(GenTable genTable) public TableDataInfo genList(GenTable genTable) {
{
startPage(); startPage();
List<GenTable> list = genTableService.selectGenTableList(genTable); List<GenTable> list = genTableService.selectGenTableList(genTable);
return getDataTable(list); return getDataTable(list);
@ -60,8 +52,7 @@ public class GenController extends BaseController
*/ */
@PreAuthorize(hasPermi = "tool:gen:query") @PreAuthorize(hasPermi = "tool:gen:query")
@GetMapping(value = "/{talbleId}") @GetMapping(value = "/{talbleId}")
public AjaxResult getInfo(@PathVariable Long talbleId) public AjaxResult getInfo(@PathVariable Long talbleId) {
{
GenTable table = genTableService.selectGenTableById(talbleId); GenTable table = genTableService.selectGenTableById(talbleId);
List<GenTable> tables = genTableService.selectGenTableAll(); List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
@ -77,8 +68,7 @@ public class GenController extends BaseController
*/ */
@PreAuthorize(hasPermi = "tool:gen:list") @PreAuthorize(hasPermi = "tool:gen:list")
@GetMapping("/db/list") @GetMapping("/db/list")
public TableDataInfo dataList(GenTable genTable) public TableDataInfo dataList(GenTable genTable) {
{
startPage(); startPage();
List<GenTable> list = genTableService.selectDbTableList(genTable); List<GenTable> list = genTableService.selectDbTableList(genTable);
return getDataTable(list); return getDataTable(list);
@ -88,8 +78,7 @@ public class GenController extends BaseController
* *
*/ */
@GetMapping(value = "/column/{talbleId}") @GetMapping(value = "/column/{talbleId}")
public TableDataInfo columnList(Long tableId) public TableDataInfo columnList(Long tableId) {
{
TableDataInfo dataInfo = new TableDataInfo(); TableDataInfo dataInfo = new TableDataInfo();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
dataInfo.setRows(list); dataInfo.setRows(list);
@ -103,8 +92,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:list") @PreAuthorize(hasPermi = "tool:gen:list")
@Log(title = "代码生成", businessType = BusinessType.IMPORT) @Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable") @PostMapping("/importTable")
public AjaxResult importTableSave(String tables) public AjaxResult importTableSave(String tables) {
{
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
// 查询表信息 // 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
@ -118,8 +106,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:edit") @PreAuthorize(hasPermi = "tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE) @Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult editSave(@Validated @RequestBody GenTable genTable) public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
{
genTableService.validateEdit(genTable); genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable); genTableService.updateGenTable(genTable);
return AjaxResult.success(); return AjaxResult.success();
@ -131,8 +118,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:remove") @PreAuthorize(hasPermi = "tool:gen:remove")
@Log(title = "代码生成", businessType = BusinessType.DELETE) @Log(title = "代码生成", businessType = BusinessType.DELETE)
@DeleteMapping("/{tableIds}") @DeleteMapping("/{tableIds}")
public AjaxResult remove(@PathVariable Long[] tableIds) public AjaxResult remove(@PathVariable Long[] tableIds) {
{
genTableService.deleteGenTableByIds(tableIds); genTableService.deleteGenTableByIds(tableIds);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -142,8 +128,7 @@ public class GenController extends BaseController
*/ */
@PreAuthorize(hasPermi = "tool:gen:preview") @PreAuthorize(hasPermi = "tool:gen:preview")
@GetMapping("/preview/{tableId}") @GetMapping("/preview/{tableId}")
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
{
Map<String, String> dataMap = genTableService.previewCode(tableId); Map<String, String> dataMap = genTableService.previewCode(tableId);
return AjaxResult.success(dataMap); return AjaxResult.success(dataMap);
} }
@ -154,8 +139,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:code") @PreAuthorize(hasPermi = "tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}") @GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
{
byte[] data = genTableService.downloadCode(tableName); byte[] data = genTableService.downloadCode(tableName);
genCode(response, data); genCode(response, data);
} }
@ -166,8 +150,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:code") @PreAuthorize(hasPermi = "tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}") @GetMapping("/genCode/{tableName}")
public AjaxResult genCode(@PathVariable("tableName") String tableName) public AjaxResult genCode(@PathVariable("tableName") String tableName) {
{
genTableService.generatorCode(tableName); genTableService.generatorCode(tableName);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -178,8 +161,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:edit") @PreAuthorize(hasPermi = "tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE) @Log(title = "代码生成", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}") @GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName) public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
{
genTableService.synchDb(tableName); genTableService.synchDb(tableName);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -190,8 +172,7 @@ public class GenController extends BaseController
@PreAuthorize(hasPermi = "tool:gen:code") @PreAuthorize(hasPermi = "tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode") @GetMapping("/batchGenCode")
public void batchGenCode(HttpServletResponse response, String tables) throws IOException public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
{
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames); byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data); genCode(response, data);
@ -200,10 +181,9 @@ public class GenController extends BaseController
/** /**
* zip * zip
*/ */
private void genCode(HttpServletResponse response, byte[] data) throws IOException private void genCode(HttpServletResponse response, byte[] data) throws IOException {
{
response.reset(); response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.setHeader("Content-Disposition", "attachment; filename=\"code.zip\"");
response.addHeader("Content-Length", "" + data.length); response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8"); response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream()); IOUtils.write(data, response.getOutputStream());

@ -1,370 +1,316 @@
package com.ruoyi.gen.domain; package com.ruoyi.gen.domain;
import java.util.List; import com.ruoyi.common.core.constant.GenConstants;
import javax.validation.Valid; import com.ruoyi.common.core.utils.StringUtils;
import javax.validation.constraints.NotBlank; import com.ruoyi.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.StringUtils; import javax.validation.Valid;
import com.ruoyi.common.core.web.domain.BaseEntity; import javax.validation.constraints.NotBlank;
import java.util.List;
/**
* gen_table /**
* * gen_table
* @author ruoyi *
*/ * @author ruoyi
public class GenTable extends BaseEntity */
{ public class GenTable extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /**
private Long tableId; *
*/
/** 表名称 */ private Long tableId;
@NotBlank(message = "表名称不能为空")
private String tableName; /**
*
/** 表描述 */ */
@NotBlank(message = "表描述不能为空") @NotBlank(message = "表名称不能为空")
private String tableComment; private String tableName;
/** 关联父表的表名 */ /**
private String subTableName; *
*/
/** 本表关联父表的外键名 */ @NotBlank(message = "表描述不能为空")
private String subTableFkName; private String tableComment;
/** 实体类名称(首字母大写) */ /**
@NotBlank(message = "实体类名称不能为空") * ()
private String className; */
@NotBlank(message = "实体类名称不能为空")
/** 使用的模板crud单表操作 tree树表操作 sub主子表操作 */ private String className;
private String tplCategory;
/**
/** 生成包路径 */ * 使crud tree
@NotBlank(message = "生成包路径不能为空") */
private String packageName; private String tplCategory;
/** 生成模块名 */ /**
@NotBlank(message = "生成模块名不能为空") *
private String moduleName; */
@NotBlank(message = "生成包路径不能为空")
/** 生成业务名 */ private String packageName;
@NotBlank(message = "生成业务名不能为空")
private String businessName; /**
*
/** 生成功能名 */ */
@NotBlank(message = "生成功能名不能为空") @NotBlank(message = "生成模块名不能为空")
private String functionName; private String moduleName;
/** 生成作者 */ /**
@NotBlank(message = "作者不能为空") *
private String functionAuthor; */
@NotBlank(message = "生成业务名不能为空")
/** 生成代码方式0zip压缩包 1自定义路径 */ private String businessName;
private String genType;
/**
/** 生成路径(不填默认项目路径) */ *
private String genPath; */
@NotBlank(message = "生成功能名不能为空")
/** 主键信息 */ private String functionName;
private GenTableColumn pkColumn;
/**
/** 子表信息 */ *
private GenTable subTable; */
@NotBlank(message = "作者不能为空")
/** 表列信息 */ private String functionAuthor;
@Valid
private List<GenTableColumn> columns; /**
* 0zip 1
/** 其它生成选项 */ */
private String options; private String genType;
/** 树编码字段 */ /**
private String treeCode; *
*/
/** 树父编码字段 */ private String genPath;
private String treeParentCode;
/**
/** 树名称字段 */ *
private String treeName; */
private GenTableColumn pkColumn;
/** 上级菜单ID字段 */
private String parentMenuId; /**
*
/** 上级菜单名称字段 */ */
private String parentMenuName; @Valid
private List<GenTableColumn> columns;
public Long getTableId()
{ /**
return tableId; *
} */
private String options;
public void setTableId(Long tableId)
{ /**
this.tableId = tableId; *
} */
private String treeCode;
public String getTableName()
{ /**
return tableName; *
} */
private String treeParentCode;
public void setTableName(String tableName)
{ /**
this.tableName = tableName; *
} */
private String treeName;
public String getTableComment()
{ /**
return tableComment; * ID
} */
private String parentMenuId;
public void setTableComment(String tableComment)
{ /**
this.tableComment = tableComment; *
} */
private String parentMenuName;
public String getSubTableName()
{ public Long getTableId() {
return subTableName; return tableId;
} }
public void setSubTableName(String subTableName) public void setTableId(Long tableId) {
{ this.tableId = tableId;
this.subTableName = subTableName; }
}
public String getTableName() {
public String getSubTableFkName() return tableName;
{ }
return subTableFkName;
} public void setTableName(String tableName) {
this.tableName = tableName;
public void setSubTableFkName(String subTableFkName) }
{
this.subTableFkName = subTableFkName; public String getTableComment() {
} return tableComment;
}
public String getClassName()
{ public void setTableComment(String tableComment) {
return className; this.tableComment = tableComment;
} }
public void setClassName(String className) public String getClassName() {
{ return className;
this.className = className; }
}
public void setClassName(String className) {
public String getTplCategory() this.className = className;
{ }
return tplCategory;
} public String getTplCategory() {
return tplCategory;
public void setTplCategory(String tplCategory) }
{
this.tplCategory = tplCategory; public void setTplCategory(String tplCategory) {
} this.tplCategory = tplCategory;
}
public String getPackageName()
{ public String getPackageName() {
return packageName; return packageName;
} }
public void setPackageName(String packageName) public void setPackageName(String packageName) {
{ this.packageName = packageName;
this.packageName = packageName; }
}
public String getModuleName() {
public String getModuleName() return moduleName;
{ }
return moduleName;
} public void setModuleName(String moduleName) {
this.moduleName = moduleName;
public void setModuleName(String moduleName) }
{
this.moduleName = moduleName; public String getBusinessName() {
} return businessName;
}
public String getBusinessName()
{ public void setBusinessName(String businessName) {
return businessName; this.businessName = businessName;
} }
public void setBusinessName(String businessName) public String getFunctionName() {
{ return functionName;
this.businessName = businessName; }
}
public void setFunctionName(String functionName) {
public String getFunctionName() this.functionName = functionName;
{ }
return functionName;
} public String getFunctionAuthor() {
return functionAuthor;
public void setFunctionName(String functionName) }
{
this.functionName = functionName; public void setFunctionAuthor(String functionAuthor) {
} this.functionAuthor = functionAuthor;
}
public String getFunctionAuthor()
{ public String getGenType() {
return functionAuthor; return genType;
} }
public void setFunctionAuthor(String functionAuthor) public void setGenType(String genType) {
{ this.genType = genType;
this.functionAuthor = functionAuthor; }
}
public String getGenPath() {
public String getGenType() return genPath;
{ }
return genType;
} public void setGenPath(String genPath) {
this.genPath = genPath;
public void setGenType(String genType) }
{
this.genType = genType; public GenTableColumn getPkColumn() {
} return pkColumn;
}
public String getGenPath()
{ public void setPkColumn(GenTableColumn pkColumn) {
return genPath; this.pkColumn = pkColumn;
} }
public void setGenPath(String genPath) public List<GenTableColumn> getColumns() {
{ return columns;
this.genPath = genPath; }
}
public void setColumns(List<GenTableColumn> columns) {
public GenTableColumn getPkColumn() this.columns = columns;
{ }
return pkColumn;
} public String getOptions() {
return options;
public void setPkColumn(GenTableColumn pkColumn) }
{
this.pkColumn = pkColumn; public void setOptions(String options) {
} this.options = options;
}
public GenTable getSubTable()
{ public String getTreeCode() {
return subTable; return treeCode;
} }
public void setSubTable(GenTable subTable) public void setTreeCode(String treeCode) {
{ this.treeCode = treeCode;
this.subTable = subTable; }
}
public List<GenTableColumn> getColumns() public String getTreeParentCode() {
{ return treeParentCode;
return columns; }
}
public void setTreeParentCode(String treeParentCode) {
public void setColumns(List<GenTableColumn> columns) this.treeParentCode = treeParentCode;
{ }
this.columns = columns;
} public String getTreeName() {
return treeName;
public String getOptions() }
{
return options; public void setTreeName(String treeName) {
} this.treeName = treeName;
}
public void setOptions(String options)
{ public String getParentMenuId() {
this.options = options; return parentMenuId;
} }
public String getTreeCode() public void setParentMenuId(String parentMenuId) {
{ this.parentMenuId = parentMenuId;
return treeCode; }
}
public String getParentMenuName() {
public void setTreeCode(String treeCode) return parentMenuName;
{ }
this.treeCode = treeCode;
} public void setParentMenuName(String parentMenuName) {
this.parentMenuName = parentMenuName;
public String getTreeParentCode() }
{
return treeParentCode; public boolean isTree() {
} return isTree(tplCategory);
}
public void setTreeParentCode(String treeParentCode)
{ public static boolean isTree(String tplCategory) {
this.treeParentCode = treeParentCode; return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
} }
public String getTreeName() public boolean isCrud() {
{ return isCrud(tplCategory);
return treeName; }
}
public static boolean isCrud(String tplCategory) {
public void setTreeName(String treeName) return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
{ }
this.treeName = treeName;
} public boolean isSuperColumn(String javaField) {
return isSuperColumn(tplCategory, javaField);
public String getParentMenuId() }
{
return parentMenuId; public static boolean isSuperColumn(String tplCategory, String javaField) {
} if (isTree(tplCategory)) {
return StringUtils.equalsAnyIgnoreCase(javaField,
public void setParentMenuId(String parentMenuId) ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
{ }
this.parentMenuId = parentMenuId; return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
} }
}
public String getParentMenuName()
{
return parentMenuName;
}
public void setParentMenuName(String parentMenuName)
{
this.parentMenuName = parentMenuName;
}
public boolean isSub()
{
return isSub(this.tplCategory);
}
public static boolean isSub(String tplCategory)
{
return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory);
}
public boolean isTree()
{
return isTree(this.tplCategory);
}
public static boolean isTree(String tplCategory)
{
return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
}
public boolean isCrud()
{
return isCrud(this.tplCategory);
}
public static boolean isCrud(String tplCategory)
{
return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
}
public boolean isSuperColumn(String javaField)
{
return isSuperColumn(this.tplCategory, javaField);
}
public static boolean isSuperColumn(String tplCategory, String javaField)
{
if (isTree(tplCategory))
{
return StringUtils.equalsAnyIgnoreCase(javaField,
ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
}
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}
}

@ -1,374 +1,344 @@
package com.ruoyi.gen.domain; package com.ruoyi.gen.domain;
import javax.validation.constraints.NotBlank; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.BaseEntity;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.BaseEntity; import javax.validation.constraints.NotBlank;
/** /**
* gen_table_column * gen_table_column
* *
* @author ruoyi * @author ruoyi
*/ */
public class GenTableColumn extends BaseEntity public class GenTableColumn extends BaseEntity {
{ private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
/** 编号 */ *
private Long columnId; */
private Long columnId;
/** 归属表编号 */
private Long tableId; /**
*
/** 列名称 */ */
private String columnName; private Long tableId;
/** 列描述 */ /**
private String columnComment; *
*/
/** 列类型 */ private String columnName;
private String columnType;
/**
/** JAVA类型 */ *
private String javaType; */
private String columnComment;
/** JAVA字段名 */
@NotBlank(message = "Java属性不能为空") /**
private String javaField; *
*/
/** 是否主键1是 */ private String columnType;
private String isPk;
/**
/** 是否自增1是 */ * JAVA
private String isIncrement; */
private String javaType;
/** 是否必填1是 */
private String isRequired; /**
* JAVA
/** 是否为插入字段1是 */ */
private String isInsert; @NotBlank(message = "Java属性不能为空")
private String javaField;
/** 是否编辑字段1是 */
private String isEdit; /**
* 1
/** 是否列表字段1是 */ */
private String isList; private String isPk;
/** 是否查询字段1是 */ /**
private String isQuery; * 1
*/
/** 查询方式EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围 */ private String isIncrement;
private String queryType;
/**
/** 显示类型input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件 */ * 1
private String htmlType; */
private String isRequired;
/** 字典类型 */
private String dictType; /**
* 1
/** 排序 */ */
private Integer sort; private String isInsert;
public void setColumnId(Long columnId) /**
{ * 1
this.columnId = columnId; */
} private String isEdit;
public Long getColumnId() /**
{ * 1
return columnId; */
} private String isList;
public void setTableId(Long tableId) /**
{ * 1
this.tableId = tableId; */
} private String isQuery;
public Long getTableId() /**
{ * EQNEGTLTLIKEBETWEEN
return tableId; */
} private String queryType;
public void setColumnName(String columnName) /**
{ * inputtextareaselectcheckboxradiodatetimeuploadeditor
this.columnName = columnName; */
} private String htmlType;
public String getColumnName() /**
{ *
return columnName; */
} private String dictType;
public void setColumnComment(String columnComment) /**
{ *
this.columnComment = columnComment; */
} private Integer sort;
public String getColumnComment() public void setColumnId(Long columnId) {
{ this.columnId = columnId;
return columnComment; }
}
public Long getColumnId() {
public void setColumnType(String columnType) return columnId;
{ }
this.columnType = columnType;
} public void setTableId(Long tableId) {
this.tableId = tableId;
public String getColumnType() }
{
return columnType; public Long getTableId() {
} return tableId;
}
public void setJavaType(String javaType)
{ public void setColumnName(String columnName) {
this.javaType = javaType; this.columnName = columnName;
} }
public String getJavaType() public String getColumnName() {
{ return columnName;
return javaType; }
}
public void setColumnComment(String columnComment) {
public void setJavaField(String javaField) this.columnComment = columnComment;
{ }
this.javaField = javaField;
} public String getColumnComment() {
return columnComment;
public String getJavaField() }
{
return javaField; public void setColumnType(String columnType) {
} this.columnType = columnType;
}
public String getCapJavaField()
{ public String getColumnType() {
return StringUtils.capitalize(javaField); return columnType;
} }
public void setIsPk(String isPk) public void setJavaType(String javaType) {
{ this.javaType = javaType;
this.isPk = isPk; }
}
public String getJavaType() {
public String getIsPk() return javaType;
{ }
return isPk;
} public void setJavaField(String javaField) {
this.javaField = javaField;
public boolean isPk() }
{
return isPk(this.isPk); public String getJavaField() {
} return javaField;
}
public boolean isPk(String isPk)
{ public void setIsPk(String isPk) {
return isPk != null && StringUtils.equals("1", isPk); this.isPk = isPk;
} }
public String getIsIncrement() public String getIsPk() {
{ return isPk;
return isIncrement; }
}
public boolean isPk() {
public void setIsIncrement(String isIncrement) return isPk(isPk);
{ }
this.isIncrement = isIncrement;
} public boolean isPk(String isPk) {
return isPk != null && StringUtils.equals("1", isPk);
public boolean isIncrement() }
{
return isIncrement(this.isIncrement); public String getIsIncrement() {
} return isIncrement;
}
public boolean isIncrement(String isIncrement)
{ public void setIsIncrement(String isIncrement) {
return isIncrement != null && StringUtils.equals("1", isIncrement); this.isIncrement = isIncrement;
} }
public void setIsRequired(String isRequired) public boolean isIncrement() {
{ return isIncrement(isIncrement);
this.isRequired = isRequired; }
}
public boolean isIncrement(String isIncrement) {
public String getIsRequired() return isIncrement != null && StringUtils.equals("1", isIncrement);
{ }
return isRequired;
} public void setIsRequired(String isRequired) {
this.isRequired = isRequired;
public boolean isRequired() }
{
return isRequired(this.isRequired); public String getIsRequired() {
} return isRequired;
}
public boolean isRequired(String isRequired)
{ public boolean isRequired() {
return isRequired != null && StringUtils.equals("1", isRequired); return isRequired(isRequired);
} }
public void setIsInsert(String isInsert) public boolean isRequired(String isRequired) {
{ return isRequired != null && StringUtils.equals("1", isRequired);
this.isInsert = isInsert; }
}
public void setIsInsert(String isInsert) {
public String getIsInsert() this.isInsert = isInsert;
{ }
return isInsert;
} public String getIsInsert() {
return isInsert;
public boolean isInsert() }
{
return isInsert(this.isInsert); public boolean isInsert() {
} return isInsert(isInsert);
}
public boolean isInsert(String isInsert)
{ public boolean isInsert(String isInsert) {
return isInsert != null && StringUtils.equals("1", isInsert); return isInsert != null && StringUtils.equals("1", isInsert);
} }
public void setIsEdit(String isEdit) public void setIsEdit(String isEdit) {
{ this.isEdit = isEdit;
this.isEdit = isEdit; }
}
public String getIsEdit() {
public String getIsEdit() return isEdit;
{ }
return isEdit;
} public boolean isEdit() {
return isInsert(isEdit);
public boolean isEdit() }
{
return isInsert(this.isEdit); public boolean isEdit(String isEdit) {
} return isEdit != null && StringUtils.equals("1", isEdit);
}
public boolean isEdit(String isEdit)
{ public void setIsList(String isList) {
return isEdit != null && StringUtils.equals("1", isEdit); this.isList = isList;
} }
public void setIsList(String isList) public String getIsList() {
{ return isList;
this.isList = isList; }
}
public boolean isList() {
public String getIsList() return isList(isList);
{ }
return isList;
} public boolean isList(String isList) {
return isList != null && StringUtils.equals("1", isList);
public boolean isList() }
{
return isList(this.isList); public void setIsQuery(String isQuery) {
} this.isQuery = isQuery;
}
public boolean isList(String isList)
{ public String getIsQuery() {
return isList != null && StringUtils.equals("1", isList); return isQuery;
} }
public void setIsQuery(String isQuery) public boolean isQuery() {
{ return isQuery(isQuery);
this.isQuery = isQuery; }
}
public boolean isQuery(String isQuery) {
public String getIsQuery() return isQuery != null && StringUtils.equals("1", isQuery);
{ }
return isQuery;
} public void setQueryType(String queryType) {
this.queryType = queryType;
public boolean isQuery() }
{
return isQuery(this.isQuery); public String getQueryType() {
} return queryType;
}
public boolean isQuery(String isQuery)
{ public String getHtmlType() {
return isQuery != null && StringUtils.equals("1", isQuery); return htmlType;
} }
public void setQueryType(String queryType) public void setHtmlType(String htmlType) {
{ this.htmlType = htmlType;
this.queryType = queryType; }
}
public void setDictType(String dictType) {
public String getQueryType() this.dictType = dictType;
{ }
return queryType;
} public String getDictType() {
return dictType;
public String getHtmlType() }
{
return htmlType; public void setSort(Integer sort) {
} this.sort = sort;
}
public void setHtmlType(String htmlType)
{ public Integer getSort() {
this.htmlType = htmlType; return sort;
} }
public void setDictType(String dictType) public boolean isSuperColumn() {
{ return isSuperColumn(javaField);
this.dictType = dictType; }
}
public static boolean isSuperColumn(String javaField) {
public String getDictType() return StringUtils.equalsAnyIgnoreCase(javaField,
{ // BaseEntity
return dictType; "createBy", "createTime", "updateBy", "updateTime", "remark",
} // TreeEntity
"parentName", "parentId", "orderNum", "ancestors");
public void setSort(Integer sort) }
{
this.sort = sort; public boolean isUsableColumn() {
} return isUsableColumn(javaField);
}
public Integer getSort()
{ public static boolean isUsableColumn(String javaField) {
return sort; // isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
} return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
}
public boolean isSuperColumn()
{ public String readConverterExp() {
return isSuperColumn(this.javaField); String remarks = StringUtils.substringBetween(columnComment, "", "");
} StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks)) {
public static boolean isSuperColumn(String javaField) for (String value : remarks.split(" ")) {
{ if (StringUtils.isNotEmpty(value)) {
return StringUtils.equalsAnyIgnoreCase(javaField, Object startStr = value.subSequence(0, 1);
// BaseEntity String endStr = value.substring(1);
"createBy", "createTime", "updateBy", "updateTime", "remark", sb.append("").append(startStr).append("=").append(endStr).append(",");
// TreeEntity }
"parentName", "parentId", "orderNum", "ancestors"); }
} return sb.deleteCharAt(sb.length() - 1).toString();
} else {
public boolean isUsableColumn() return columnComment;
{ }
return isUsableColumn(javaField); }
}
public static boolean isUsableColumn(String javaField)
{
// isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
}
public String readConverterExp()
{
String remarks = StringUtils.substringBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks))
{
for (String value : remarks.split(" "))
{
if (StringUtils.isNotEmpty(value))
{
Object startStr = value.subSequence(0, 1);
String endStr = value.substring(1);
sb.append("").append(startStr).append("=").append(endStr).append(",");
}
}
return sb.deleteCharAt(sb.length() - 1).toString();
}
else
{
return this.columnComment;
}
}
} }

@ -1,18 +1,18 @@
package com.ruoyi.gen.mapper; package com.ruoyi.gen.mapper;
import java.util.List;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import java.util.List;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public interface GenTableColumnMapper public interface GenTableColumnMapper {
{
/** /**
* *
* *
* @param tableName * @param tableName
* @return * @return
*/ */
@ -20,7 +20,7 @@ public interface GenTableColumnMapper
/** /**
* *
* *
* @param tableId * @param tableId
* @return * @return
*/ */
@ -28,7 +28,7 @@ public interface GenTableColumnMapper
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@ -36,7 +36,7 @@ public interface GenTableColumnMapper
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@ -44,7 +44,7 @@ public interface GenTableColumnMapper
/** /**
* *
* *
* @param genTableColumns * @param genTableColumns
* @return * @return
*/ */
@ -52,7 +52,7 @@ public interface GenTableColumnMapper
/** /**
* *
* *
* @param ids ID * @param ids ID
* @return * @return
*/ */

@ -1,18 +1,18 @@
package com.ruoyi.gen.mapper; package com.ruoyi.gen.mapper;
import java.util.List;
import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTable;
import java.util.List;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public interface GenTableMapper public interface GenTableMapper {
{
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -20,7 +20,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -28,7 +28,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param tableNames * @param tableNames
* @return * @return
*/ */
@ -43,7 +43,7 @@ public interface GenTableMapper
/** /**
* ID * ID
* *
* @param id ID * @param id ID
* @return * @return
*/ */
@ -51,7 +51,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param tableName * @param tableName
* @return * @return
*/ */
@ -59,7 +59,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -67,7 +67,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -75,7 +75,7 @@ public interface GenTableMapper
/** /**
* *
* *
* @param ids ID * @param ids ID
* @return * @return
*/ */

@ -1,68 +1,64 @@
package com.ruoyi.gen.service; package com.ruoyi.gen.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.gen.mapper.GenTableColumnMapper; import com.ruoyi.gen.mapper.GenTableColumnMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service("genTableColumnService")
public class GenTableColumnServiceImpl implements IGenTableColumnService public class GenTableColumnServiceImpl implements IGenTableColumnService {
{ @Autowired
@Autowired private GenTableColumnMapper genTableColumnMapper;
private GenTableColumnMapper genTableColumnMapper;
/** /**
* *
* *
* @param tableId * @param tableId
* @return * @return
*/ */
@Override @Override
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
{ return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); }
}
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@Override @Override
public int insertGenTableColumn(GenTableColumn genTableColumn) public int insertGenTableColumn(GenTableColumn genTableColumn) {
{ return genTableColumnMapper.insertGenTableColumn(genTableColumn);
return genTableColumnMapper.insertGenTableColumn(genTableColumn); }
}
/**
/**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@Override @Override
public int updateGenTableColumn(GenTableColumn genTableColumn) public int updateGenTableColumn(GenTableColumn genTableColumn) {
{ return genTableColumnMapper.updateGenTableColumn(genTableColumn);
return genTableColumnMapper.updateGenTableColumn(genTableColumn); }
}
/** /**
* *
* *
* @param ids ID * @param ids ID
* @return * @return
*/ */
@Override @Override
public int deleteGenTableColumnByIds(String ids) public int deleteGenTableColumnByIds(String ids) {
{ return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); }
}
} }

@ -1,499 +1,394 @@
package com.ruoyi.gen.service; package com.ruoyi.gen.service;
import java.io.ByteArrayOutputStream; import com.alibaba.fastjson.JSON;
import java.io.File; import com.alibaba.fastjson.JSONObject;
import java.io.IOException; import com.ruoyi.common.core.constant.Constants;
import java.io.StringWriter; import com.ruoyi.common.core.constant.GenConstants;
import java.util.LinkedHashMap; import com.ruoyi.common.core.exception.CustomException;
import java.util.List; import com.ruoyi.common.core.text.CharsetKit;
import java.util.Map; import com.ruoyi.common.core.utils.SecurityUtils;
import java.util.stream.Collectors; import com.ruoyi.common.core.utils.StringUtils;
import java.util.zip.ZipEntry; import com.ruoyi.common.core.utils.file.FileUtils;
import java.util.zip.ZipOutputStream; import com.ruoyi.gen.domain.GenTable;
import org.apache.commons.io.IOUtils; import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.velocity.Template; import com.ruoyi.gen.mapper.GenTableColumnMapper;
import org.apache.velocity.VelocityContext; import com.ruoyi.gen.mapper.GenTableMapper;
import org.apache.velocity.app.Velocity; import com.ruoyi.gen.util.GenUtils;
import org.slf4j.Logger; import com.ruoyi.gen.util.VelocityInitializer;
import org.slf4j.LoggerFactory; import com.ruoyi.gen.util.VelocityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service; import org.apache.velocity.Template;
import org.springframework.transaction.annotation.Transactional; import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson.JSON; import org.apache.velocity.app.Velocity;
import com.alibaba.fastjson.JSONObject; import org.slf4j.Logger;
import com.ruoyi.common.core.constant.Constants; import org.slf4j.LoggerFactory;
import com.ruoyi.common.core.constant.GenConstants; import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.core.exception.CustomException; import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.CharsetKit; import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.common.core.utils.StringUtils; import java.io.ByteArrayOutputStream;
import com.ruoyi.common.core.utils.file.FileUtils; import java.io.File;
import com.ruoyi.gen.domain.GenTable; import java.io.IOException;
import com.ruoyi.gen.domain.GenTableColumn; import java.io.StringWriter;
import com.ruoyi.gen.mapper.GenTableColumnMapper; import java.util.LinkedHashMap;
import com.ruoyi.gen.mapper.GenTableMapper; import java.util.List;
import com.ruoyi.gen.util.GenUtils; import java.util.Map;
import com.ruoyi.gen.util.VelocityInitializer; import java.util.stream.Collectors;
import com.ruoyi.gen.util.VelocityUtils; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* /**
* *
* @author ruoyi *
*/ * @author ruoyi
@Service */
public class GenTableServiceImpl implements IGenTableService @Service
{ public class GenTableServiceImpl implements IGenTableService {
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@Autowired @Autowired
private GenTableMapper genTableMapper; private GenTableMapper genTableMapper;
@Autowired @Autowired
private GenTableColumnMapper genTableColumnMapper; private GenTableColumnMapper genTableColumnMapper;
/** /**
* *
* *
* @param id ID * @param id ID
* @return * @return
*/ */
@Override @Override
public GenTable selectGenTableById(Long id) public GenTable selectGenTableById(Long id) {
{ GenTable genTable = genTableMapper.selectGenTableById(id);
GenTable genTable = genTableMapper.selectGenTableById(id); setTableFromOptions(genTable);
setTableFromOptions(genTable); return genTable;
return genTable; }
}
/**
/** *
* *
* * @param genTable
* @param genTable * @return
* @return */
*/ @Override
@Override public List<GenTable> selectGenTableList(GenTable genTable) {
public List<GenTable> selectGenTableList(GenTable genTable) return genTableMapper.selectGenTableList(genTable);
{ }
return genTableMapper.selectGenTableList(genTable);
} /**
*
/** *
* * @param genTable
* * @return
* @param genTable */
* @return @Override
*/ public List<GenTable> selectDbTableList(GenTable genTable) {
@Override return genTableMapper.selectDbTableList(genTable);
public List<GenTable> selectDbTableList(GenTable genTable) }
{
return genTableMapper.selectDbTableList(genTable); /**
} *
*
/** * @param tableNames
* * @return
* */
* @param tableNames @Override
* @return public List<GenTable> selectDbTableListByNames(String[] tableNames) {
*/ return genTableMapper.selectDbTableListByNames(tableNames);
@Override }
public List<GenTable> selectDbTableListByNames(String[] tableNames)
{ /**
return genTableMapper.selectDbTableListByNames(tableNames); *
} *
* @param genTable
/** * @return
* */
* @Override
* @return @Transactional
*/ public void updateGenTable(GenTable genTable) {
@Override String options = JSON.toJSONString(genTable.getParams());
public List<GenTable> selectGenTableAll() genTable.setOptions(options);
{ int row = genTableMapper.updateGenTable(genTable);
return genTableMapper.selectGenTableAll(); if (row > 0) {
} for (GenTableColumn cenTableColumn : genTable.getColumns()) {
genTableColumnMapper.updateGenTableColumn(cenTableColumn);
/** }
* }
* }
* @param genTable
* @return /**
*/ *
@Override *
@Transactional * @param tableIds ID
public void updateGenTable(GenTable genTable) * @return
{ */
String options = JSON.toJSONString(genTable.getParams()); @Override
genTable.setOptions(options); @Transactional
int row = genTableMapper.updateGenTable(genTable); public void deleteGenTableByIds(Long[] tableIds) {
if (row > 0) genTableMapper.deleteGenTableByIds(tableIds);
{ genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
for (GenTableColumn cenTableColumn : genTable.getColumns()) }
{
genTableColumnMapper.updateGenTableColumn(cenTableColumn); /**
} *
} *
} * @param tableList
*/
/** @Override
* @Transactional
* public void importGenTable(List<GenTable> tableList) {
* @param tableIds ID String operName = SecurityUtils.getUsername();
* @return try {
*/ for (GenTable table : tableList) {
@Override String tableName = table.getTableName();
@Transactional GenUtils.initTable(table, operName);
public void deleteGenTableByIds(Long[] tableIds) int row = genTableMapper.insertGenTable(table);
{ if (row > 0) {
genTableMapper.deleteGenTableByIds(tableIds); // 保存列信息
genTableColumnMapper.deleteGenTableColumnByIds(tableIds); List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
} for (GenTableColumn column : genTableColumns) {
GenUtils.initColumnField(column, table);
/** genTableColumnMapper.insertGenTableColumn(column);
* }
* }
* @param tableList }
*/ } catch (Exception e) {
@Override throw new CustomException("导入失败:" + e.getMessage());
@Transactional }
public void importGenTable(List<GenTable> tableList) }
{
String operName = SecurityUtils.getUsername(); /**
try *
{ *
for (GenTable table : tableList) * @param tableId
{ * @return
String tableName = table.getTableName(); */
GenUtils.initTable(table, operName); @Override
int row = genTableMapper.insertGenTable(table); public Map<String, String> previewCode(Long tableId) {
if (row > 0) Map<String, String> dataMap = new LinkedHashMap<>();
{ // 查询表信息
// 保存列信息 GenTable table = genTableMapper.selectGenTableById(tableId);
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); // 查询列信息
for (GenTableColumn column : genTableColumns) List<GenTableColumn> columns = table.getColumns();
{ setPkColumn(table, columns);
GenUtils.initColumnField(column, table); VelocityInitializer.initVelocity();
genTableColumnMapper.insertGenTableColumn(column);
} VelocityContext context = VelocityUtils.prepareContext(table);
}
} // 获取模板列表
} List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
catch (Exception e) for (String template : templates) {
{ // 渲染模板
throw new CustomException("导入失败:" + e.getMessage()); StringWriter sw = new StringWriter();
} Template tpl = Velocity.getTemplate(template, Constants.UTF8);
} tpl.merge(context, sw);
dataMap.put(template, sw.toString());
/** }
* return dataMap;
* }
* @param tableId
* @return /**
*/ *
@Override *
public Map<String, String> previewCode(Long tableId) * @param tableName
{ * @return
Map<String, String> dataMap = new LinkedHashMap<>(); */
// 查询表信息 @Override
GenTable table = genTableMapper.selectGenTableById(tableId); public byte[] downloadCode(String tableName) {
// 设置主子表信息 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
setSubTable(table); ZipOutputStream zip = new ZipOutputStream(outputStream);
// 设置主键列信息 generatorCode(tableName, zip);
setPkColumn(table); IOUtils.closeQuietly(zip);
VelocityInitializer.initVelocity(); return outputStream.toByteArray();
}
VelocityContext context = VelocityUtils.prepareContext(table);
/**
// 获取模板列表 *
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); *
for (String template : templates) * @param tableName
{ */
// 渲染模板 @Override
StringWriter sw = new StringWriter(); public void generatorCode(String tableName) {
Template tpl = Velocity.getTemplate(template, Constants.UTF8); // 查询表信息
tpl.merge(context, sw); GenTable table = genTableMapper.selectGenTableByName(tableName);
dataMap.put(template, sw.toString()); // 查询列信息
} List<GenTableColumn> columns = table.getColumns();
return dataMap; setPkColumn(table, columns);
}
VelocityInitializer.initVelocity();
/**
* VelocityContext context = VelocityUtils.prepareContext(table);
*
* @param tableName // 获取模板列表
* @return List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
*/ for (String template : templates) {
@Override if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
public byte[] downloadCode(String tableName) // 渲染模板
{ StringWriter sw = new StringWriter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
ZipOutputStream zip = new ZipOutputStream(outputStream); tpl.merge(context, sw);
generatorCode(tableName, zip); try {
IOUtils.closeQuietly(zip); String path = getGenPath(table, template);
return outputStream.toByteArray(); FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
} } catch (IOException e) {
throw new CustomException("渲染模板失败,表名:" + table.getTableName());
/** }
* }
* }
* @param tableName }
*/
@Override /**
public void generatorCode(String tableName) *
{ *
// 查询表信息 * @param tableName
GenTable table = genTableMapper.selectGenTableByName(tableName); */
// 设置主子表信息 @Override
setSubTable(table); @Transactional
// 设置主键列信息 public void synchDb(String tableName) {
setPkColumn(table); GenTable table = genTableMapper.selectGenTableByName(tableName);
List<GenTableColumn> tableColumns = table.getColumns();
VelocityInitializer.initVelocity(); List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
VelocityContext context = VelocityUtils.prepareContext(table); List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); dbTableColumns.forEach(column -> {
for (String template : templates) if (!tableColumnNames.contains(column.getColumnName())) {
{ GenUtils.initColumnField(column, table);
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) genTableColumnMapper.insertGenTableColumn(column);
{ }
// 渲染模板 });
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
tpl.merge(context, sw); if (StringUtils.isNotEmpty(delColumns)) {
try genTableColumnMapper.deleteGenTableColumns(delColumns);
{ }
String path = getGenPath(table, template); }
FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
} /**
catch (IOException e) *
{ *
throw new CustomException("渲染模板失败,表名:" + table.getTableName()); * @param tableNames
} * @return
} */
} @Override
} public byte[] downloadCode(String[] tableNames) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
/** ZipOutputStream zip = new ZipOutputStream(outputStream);
* for (String tableName : tableNames) {
* generatorCode(tableName, zip);
* @param tableName }
*/ IOUtils.closeQuietly(zip);
@Override return outputStream.toByteArray();
@Transactional }
public void synchDb(String tableName)
{ /**
GenTable table = genTableMapper.selectGenTableByName(tableName); *
List<GenTableColumn> tableColumns = table.getColumns(); */
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); private void generatorCode(String tableName, ZipOutputStream zip) {
// 查询表信息
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
if (StringUtils.isEmpty(dbTableColumns)) // 查询列信息
{ List<GenTableColumn> columns = table.getColumns();
throw new CustomException("同步数据失败,原表结构不存在"); setPkColumn(table, columns);
}
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); VelocityInitializer.initVelocity();
dbTableColumns.forEach(column -> { VelocityContext context = VelocityUtils.prepareContext(table);
if (!tableColumnNames.contains(column.getColumnName()))
{ // 获取模板列表
GenUtils.initColumnField(column, table); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
genTableColumnMapper.insertGenTableColumn(column); for (String template : templates) {
} // 渲染模板
}); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); tpl.merge(context, sw);
if (StringUtils.isNotEmpty(delColumns)) try {
{ // 添加到zip
genTableColumnMapper.deleteGenTableColumns(delColumns); zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
} IOUtils.write(sw.toString(), zip, Constants.UTF8);
} IOUtils.closeQuietly(sw);
zip.flush();
/** zip.closeEntry();
* } catch (IOException e) {
* log.error("渲染模板失败,表名:" + table.getTableName(), e);
* @param tableNames }
* @return }
*/ }
@Override
public byte[] downloadCode(String[] tableNames) /**
{ *
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); *
ZipOutputStream zip = new ZipOutputStream(outputStream); * @param genTable
for (String tableName : tableNames) */
{ @Override
generatorCode(tableName, zip); public void validateEdit(GenTable genTable) {
} if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
IOUtils.closeQuietly(zip); String options = JSON.toJSONString(genTable.getParams());
return outputStream.toByteArray(); JSONObject paramsObj = JSONObject.parseObject(options);
} if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
throw new CustomException("树编码字段不能为空");
/** } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
* throw new CustomException("树父编码字段不能为空");
*/ } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
private void generatorCode(String tableName, ZipOutputStream zip) throw new CustomException("树名称字段不能为空");
{ }
// 查询表信息 }
GenTable table = genTableMapper.selectGenTableByName(tableName); }
// 设置主子表信息
setSubTable(table); /**
// 设置主键列信息 *
setPkColumn(table); *
* @param table
VelocityInitializer.initVelocity(); * @param columns
*/
VelocityContext context = VelocityUtils.prepareContext(table); public void setPkColumn(GenTable table, List<GenTableColumn> columns) {
for (GenTableColumn column : columns) {
// 获取模板列表 if (column.isPk()) {
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); table.setPkColumn(column);
for (String template : templates) break;
{ }
// 渲染模板 }
StringWriter sw = new StringWriter(); if (StringUtils.isNull(table.getPkColumn())) {
Template tpl = Velocity.getTemplate(template, Constants.UTF8); table.setPkColumn(columns.get(0));
tpl.merge(context, sw); }
try }
{
// 添加到zip /**
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); *
IOUtils.write(sw.toString(), zip, Constants.UTF8); *
IOUtils.closeQuietly(sw); * @param genTable
zip.flush(); */
zip.closeEntry(); public void setTableFromOptions(GenTable genTable) {
} JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
catch (IOException e) if (StringUtils.isNotNull(paramsObj)) {
{ String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
log.error("渲染模板失败,表名:" + table.getTableName(), e); String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
} String treeName = paramsObj.getString(GenConstants.TREE_NAME);
} String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
} String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
/** genTable.setTreeCode(treeCode);
* genTable.setTreeParentCode(treeParentCode);
* genTable.setTreeName(treeName);
* @param genTable genTable.setParentMenuId(parentMenuId);
*/ genTable.setParentMenuName(parentMenuName);
@Override }
public void validateEdit(GenTable genTable) }
{
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) /**
{ *
String options = JSON.toJSONString(genTable.getParams()); *
JSONObject paramsObj = JSONObject.parseObject(options); * @param table
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) * @param template
{ * @return
throw new CustomException("树编码字段不能为空"); */
} public static String getGenPath(GenTable table, String template) {
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) String genPath = table.getGenPath();
{ if (StringUtils.equals(genPath, "/")) {
throw new CustomException("树父编码字段不能为空"); return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
} }
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) return genPath + File.separator + VelocityUtils.getFileName(template, table);
{ }
throw new CustomException("树名称字段不能为空"); }
}
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
{
if (StringUtils.isEmpty(genTable.getSubTableName()))
{
throw new CustomException("关联子表的表名不能为空");
}
else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
{
throw new CustomException("子表关联的外键名不能为空");
}
}
}
}
/**
*
*
* @param table
*/
public void setPkColumn(GenTable table)
{
for (GenTableColumn column : table.getColumns())
{
if (column.isPk())
{
table.setPkColumn(column);
break;
}
}
if (StringUtils.isNull(table.getPkColumn()))
{
table.setPkColumn(table.getColumns().get(0));
}
if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
{
for (GenTableColumn column : table.getSubTable().getColumns())
{
if (column.isPk())
{
table.getSubTable().setPkColumn(column);
break;
}
}
if (StringUtils.isNull(table.getSubTable().getPkColumn()))
{
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
}
}
}
/**
*
*
* @param table
*/
public void setSubTable(GenTable table)
{
String subTableName = table.getSubTableName();
if (StringUtils.isNotEmpty(subTableName))
{
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
}
}
/**
*
*
* @param genTable
*/
public void setTableFromOptions(GenTable genTable)
{
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
if (StringUtils.isNotNull(paramsObj))
{
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode);
genTable.setTreeName(treeName);
genTable.setParentMenuId(parentMenuId);
genTable.setParentMenuName(parentMenuName);
}
}
/**
*
*
* @param table
* @param template
* @return
*/
public static String getGenPath(GenTable table, String template)
{
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/"))
{
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
}

@ -1,18 +1,18 @@
package com.ruoyi.gen.service; package com.ruoyi.gen.service;
import java.util.List;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import java.util.List;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public interface IGenTableColumnService public interface IGenTableColumnService {
{
/** /**
* *
* *
* @param tableId * @param tableId
* @return * @return
*/ */
@ -20,7 +20,7 @@ public interface IGenTableColumnService
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@ -28,7 +28,7 @@ public interface IGenTableColumnService
/** /**
* *
* *
* @param genTableColumn * @param genTableColumn
* @return * @return
*/ */
@ -36,7 +36,7 @@ public interface IGenTableColumnService
/** /**
* *
* *
* @param ids ID * @param ids ID
* @return * @return
*/ */

@ -1,19 +1,19 @@
package com.ruoyi.gen.service; package com.ruoyi.gen.service;
import com.ruoyi.gen.domain.GenTable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.ruoyi.gen.domain.GenTable;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public interface IGenTableService public interface IGenTableService {
{
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -21,7 +21,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -29,7 +29,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableNames * @param tableNames
* @return * @return
*/ */
@ -44,7 +44,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param id ID * @param id ID
* @return * @return
*/ */
@ -52,7 +52,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param genTable * @param genTable
* @return * @return
*/ */
@ -60,7 +60,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableIds ID * @param tableIds ID
* @return * @return
*/ */
@ -68,14 +68,14 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableList * @param tableList
*/ */
public void importGenTable(List<GenTable> tableList); public void importGenTable(List<GenTable> tableList);
/** /**
* *
* *
* @param tableId * @param tableId
* @return * @return
*/ */
@ -83,7 +83,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableName * @param tableName
* @return * @return
*/ */
@ -91,7 +91,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableName * @param tableName
* @return * @return
*/ */
@ -99,14 +99,14 @@ public interface IGenTableService
/** /**
* *
* *
* @param tableName * @param tableName
*/ */
public void synchDb(String tableName); public void synchDb(String tableName);
/** /**
* *
* *
* @param tableNames * @param tableNames
* @return * @return
*/ */
@ -114,7 +114,7 @@ public interface IGenTableService
/** /**
* *
* *
* @param genTable * @param genTable
*/ */
public void validateEdit(GenTable genTable); public void validateEdit(GenTable genTable);

@ -1,258 +1,217 @@
package com.ruoyi.gen.util; package com.ruoyi.gen.util;
import java.util.Arrays; import com.ruoyi.common.core.constant.GenConstants;
import org.apache.commons.lang3.RegExUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.gen.config.GenConfig;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.config.GenConfig; import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.gen.domain.GenTable; import org.apache.commons.lang3.RegExUtils;
import com.ruoyi.gen.domain.GenTableColumn;
import java.util.Arrays;
/**
* /**
* *
* @author ruoyi *
*/ * @author ruoyi
public class GenUtils */
{ public class GenUtils {
/** /**
* *
*/ */
public static void initTable(GenTable genTable, String operName) public static void initTable(GenTable genTable, String operName) {
{ genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setPackageName(GenConfig.getPackageName());
genTable.setPackageName(GenConfig.getPackageName()); genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
genTable.setModuleName(getModuleName(GenConfig.getPackageName())); genTable.setBusinessName(getBusinessName(genTable.getTableName()));
genTable.setBusinessName(getBusinessName(genTable.getTableName())); genTable.setFunctionName(replaceText(genTable.getTableComment()));
genTable.setFunctionName(replaceText(genTable.getTableComment())); genTable.setFunctionAuthor(GenConfig.getAuthor());
genTable.setFunctionAuthor(GenConfig.getAuthor()); genTable.setCreateBy(operName);
genTable.setCreateBy(operName); }
}
/**
/** *
* */
*/ public static void initColumnField(GenTableColumn column, GenTable table) {
public static void initColumnField(GenTableColumn column, GenTable table) String dataType = getDbType(column.getColumnType());
{ String columnName = column.getColumnName();
String dataType = getDbType(column.getColumnType()); column.setTableId(table.getTableId());
String columnName = column.getColumnName(); column.setCreateBy(table.getCreateBy());
column.setTableId(table.getTableId()); // 设置java字段名
column.setCreateBy(table.getCreateBy()); column.setJavaField(StringUtils.toCamelCase(columnName));
// 设置java字段名
column.setJavaField(StringUtils.toCamelCase(columnName)); if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) {
// 设置默认类型 column.setJavaType(GenConstants.TYPE_STRING);
column.setJavaType(GenConstants.TYPE_STRING); // 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) String htmlType = columnLength >= 500 ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
{ column.setHtmlType(htmlType);
// 字符串长度超过500设置为文本域 } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
Integer columnLength = getColumnLength(column.getColumnType()); column.setJavaType(GenConstants.TYPE_DATE);
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; column.setHtmlType(GenConstants.HTML_DATETIME);
column.setHtmlType(htmlType); } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
} column.setHtmlType(GenConstants.HTML_INPUT);
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{ // 如果是浮点型
column.setJavaType(GenConstants.TYPE_DATE); String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
column.setHtmlType(GenConstants.HTML_DATETIME); if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
} column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) }
{ // 如果是整形
column.setHtmlType(GenConstants.HTML_INPUT); else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
column.setJavaType(GenConstants.TYPE_INTEGER);
// 如果是浮点型 统一用BigDecimal }
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); // 长整形
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) else {
{ column.setJavaType(GenConstants.TYPE_LONG);
column.setJavaType(GenConstants.TYPE_BIGDECIMAL); }
} }
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) // 插入字段(默认所有字段都需要插入)
{ column.setIsInsert(GenConstants.REQUIRE);
column.setJavaType(GenConstants.TYPE_INTEGER);
} // 编辑字段
// 长整形 if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
else column.setIsEdit(GenConstants.REQUIRE);
{ }
column.setJavaType(GenConstants.TYPE_LONG); // 列表字段
} if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
} column.setIsList(GenConstants.REQUIRE);
}
// 插入字段(默认所有字段都需要插入) // 查询字段
column.setIsInsert(GenConstants.REQUIRE); if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
column.setIsQuery(GenConstants.REQUIRE);
// 编辑字段 }
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
{ // 查询字段类型
column.setIsEdit(GenConstants.REQUIRE); if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
} column.setQueryType(GenConstants.QUERY_LIKE);
// 列表字段 }
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) // 状态字段设置单选框
{ if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setIsList(GenConstants.REQUIRE); column.setHtmlType(GenConstants.HTML_RADIO);
} }
// 查询字段 // 类型&性别字段设置下拉框
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) else if (StringUtils.endsWithIgnoreCase(columnName, "type")
{ || StringUtils.endsWithIgnoreCase(columnName, "sex")) {
column.setIsQuery(GenConstants.REQUIRE); column.setHtmlType(GenConstants.HTML_SELECT);
} }
// 文件字段设置上传控件
// 查询字段类型 else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
if (StringUtils.endsWithIgnoreCase(columnName, "name")) column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE);
{ }
column.setQueryType(GenConstants.QUERY_LIKE); // 内容字段设置富文本控件
} else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
// 状态字段设置单选框 column.setHtmlType(GenConstants.HTML_EDITOR);
if (StringUtils.endsWithIgnoreCase(columnName, "status")) }
{ }
column.setHtmlType(GenConstants.HTML_RADIO);
} /**
// 类型&性别字段设置下拉框 *
else if (StringUtils.endsWithIgnoreCase(columnName, "type") *
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) * @param arr
{ * @param targetValue
column.setHtmlType(GenConstants.HTML_SELECT); * @return
} */
// 图片字段设置图片上传控件 public static boolean arraysContains(String[] arr, String targetValue) {
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) return Arrays.asList(arr).contains(targetValue);
{ }
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
} /**
// 文件字段设置文件上传控件 *
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) *
{ * @param packageName
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); * @return
} */
// 内容字段设置富文本控件 public static String getModuleName(String packageName) {
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) int lastIndex = packageName.lastIndexOf(".");
{ int nameLength = packageName.length();
column.setHtmlType(GenConstants.HTML_EDITOR); String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
} return moduleName;
} }
/** /**
* *
* *
* @param arr * @param tableName
* @param targetValue * @return
* @return */
*/ public static String getBusinessName(String tableName) {
public static boolean arraysContains(String[] arr, String targetValue) int lastIndex = tableName.lastIndexOf("_");
{ int nameLength = tableName.length();
return Arrays.asList(arr).contains(targetValue); String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
} return businessName;
}
/**
* /**
* * Java
* @param packageName *
* @return * @param tableName
*/ * @return
public static String getModuleName(String packageName) */
{ public static String convertClassName(String tableName) {
int lastIndex = packageName.lastIndexOf("."); boolean autoRemovePre = GenConfig.getAutoRemovePre();
int nameLength = packageName.length(); String tablePrefix = GenConfig.getTablePrefix();
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
return moduleName; String[] searchList = StringUtils.split(tablePrefix, ",");
} tableName = replaceFirst(tableName, searchList);
}
/** return StringUtils.convertToCamelCase(tableName);
* }
*
* @param tableName /**
* @return *
*/ *
public static String getBusinessName(String tableName) * @param replacementm
{ * @param searchList
int lastIndex = tableName.lastIndexOf("_"); * @return
int nameLength = tableName.length(); */
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); public static String replaceFirst(String replacementm, String[] searchList) {
return businessName; String text = replacementm;
} for (String searchString : searchList) {
if (replacementm.startsWith(searchString)) {
/** text = replacementm.replaceFirst(searchString, "");
* Java break;
* }
* @param tableName }
* @return return text;
*/ }
public static String convertClassName(String tableName)
{ /**
boolean autoRemovePre = GenConfig.getAutoRemovePre(); *
String tablePrefix = GenConfig.getTablePrefix(); *
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) * @param text
{ * @return
String[] searchList = StringUtils.split(tablePrefix, ","); */
tableName = replaceFirst(tableName, searchList); public static String replaceText(String text) {
} return RegExUtils.replaceAll(text, "(?:表|若依)", "");
return StringUtils.convertToCamelCase(tableName); }
}
/**
/** *
* *
* * @param columnType
* @param replacementm * @return
* @param searchList */
* @return public static String getDbType(String columnType) {
*/ if (StringUtils.indexOf(columnType, "(") > 0) {
public static String replaceFirst(String replacementm, String[] searchList) return StringUtils.substringBefore(columnType, "(");
{ } else {
String text = replacementm; return columnType;
for (String searchString : searchList) }
{ }
if (replacementm.startsWith(searchString))
{ /**
text = replacementm.replaceFirst(searchString, ""); *
break; *
} * @param columnType
} * @return
return text; */
} public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
/** String length = StringUtils.substringBetween(columnType, "(", ")");
* return Integer.valueOf(length);
* } else {
* @param text return 0;
* @return }
*/ }
public static String replaceText(String text)
{
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}
/**
*
*
* @param columnType
* @return
*/
public static String getDbType(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
return StringUtils.substringBefore(columnType, "(");
}
else
{
return columnType;
}
}
/**
*
*
* @param columnType
* @return
*/
public static Integer getColumnLength(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
}
else
{
return 0;
}
}
} }

@ -1,24 +1,22 @@
package com.ruoyi.gen.util; package com.ruoyi.gen.util;
import java.util.Properties;
import org.apache.velocity.app.Velocity;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import org.apache.velocity.app.Velocity;
import java.util.Properties;
/** /**
* VelocityEngine * VelocityEngine
* *
* @author ruoyi * @author ruoyi
*/ */
public class VelocityInitializer public class VelocityInitializer {
{
/** /**
* vm * vm
*/ */
public static void initVelocity() public static void initVelocity() {
{
Properties p = new Properties(); Properties p = new Properties();
try try {
{
// 加载classpath目录下的vm文件 // 加载classpath目录下的vm文件
p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
// 定义字符集 // 定义字符集
@ -26,9 +24,7 @@ public class VelocityInitializer
p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
// 初始化Velocity引擎指定配置Properties // 初始化Velocity引擎指定配置Properties
Velocity.init(p); Velocity.init(p);
} } catch (Exception e) {
catch (Exception e)
{
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

@ -1,361 +1,290 @@
package com.ruoyi.gen.util; package com.ruoyi.gen.util;
import java.util.ArrayList; import com.alibaba.fastjson.JSONObject;
import java.util.HashSet; import com.ruoyi.common.core.constant.GenConstants;
import java.util.List; import com.ruoyi.common.core.utils.DateUtils;
import org.apache.velocity.VelocityContext; import com.ruoyi.common.core.utils.StringUtils;
import com.alibaba.fastjson.JSONObject; import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.common.core.utils.DateUtils; import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.core.utils.StringUtils; import org.apache.velocity.VelocityContext;
import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn; import java.util.ArrayList;
import java.util.HashSet;
/** import java.util.List;
*
* /**
* @author ruoyi *
*/ *
public class VelocityUtils * @author ruoyi
{ */
/** 项目空间路径 */ @Slf4j
private static final String PROJECT_PATH = "main/java"; public class VelocityUtils {
/**
/** mybatis空间路径 */ *
private static final String MYBATIS_PATH = "main/resources/mapper"; */
private static final String PROJECT_PATH = "java";
/** 默认上级菜单,系统工具 */
private static final String DEFAULT_PARENT_MENU_ID = "3"; /**
* mybatis
/** */
* private static final String MYBATIS_PATH = "resources/mapper";
*
* @return /**
*/ *
public static VelocityContext prepareContext(GenTable genTable) */
{ private static final String DEFAULT_PARENT_MENU_ID = "3";
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName(); /**
String packageName = genTable.getPackageName(); *
String tplCategory = genTable.getTplCategory(); *
String functionName = genTable.getFunctionName(); * @return
*/
VelocityContext velocityContext = new VelocityContext(); public static VelocityContext prepareContext(GenTable genTable) {
velocityContext.put("tplCategory", genTable.getTplCategory()); String moduleName = genTable.getModuleName();
velocityContext.put("tableName", genTable.getTableName()); String businessName = genTable.getBusinessName();
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); String packageName = genTable.getPackageName();
velocityContext.put("ClassName", genTable.getClassName()); String tplCategory = genTable.getTplCategory();
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); String functionName = genTable.getFunctionName();
velocityContext.put("moduleName", genTable.getModuleName());
velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); VelocityContext velocityContext = new VelocityContext();
velocityContext.put("businessName", genTable.getBusinessName()); velocityContext.put("tplCategory", genTable.getTplCategory());
velocityContext.put("basePackage", getPackagePrefix(packageName)); velocityContext.put("tableName", genTable.getTableName());
velocityContext.put("packageName", packageName); velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("ClassName", genTable.getClassName());
velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
velocityContext.put("pkColumn", genTable.getPkColumn()); velocityContext.put("moduleName", genTable.getModuleName());
velocityContext.put("importList", getImportList(genTable)); velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName()));
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("businessName", genTable.getBusinessName());
velocityContext.put("columns", genTable.getColumns()); velocityContext.put("basePackage", getPackagePrefix(packageName));
velocityContext.put("table", genTable); velocityContext.put("packageName", packageName);
setMenuVelocityContext(velocityContext, genTable); velocityContext.put("author", genTable.getFunctionAuthor());
if (GenConstants.TPL_TREE.equals(tplCategory)) velocityContext.put("datetime", DateUtils.getDate());
{ velocityContext.put("pkColumn", genTable.getPkColumn());
setTreeVelocityContext(velocityContext, genTable); velocityContext.put("importList", getImportList(genTable.getColumns()));
} velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
if (GenConstants.TPL_SUB.equals(tplCategory)) velocityContext.put("columns", genTable.getColumns());
{ velocityContext.put("table", genTable);
setSubVelocityContext(velocityContext, genTable); setMenuVelocityContext(velocityContext, genTable);
} if (GenConstants.TPL_TREE.equals(tplCategory)) {
return velocityContext; setTreeVelocityContext(velocityContext, genTable);
} }
return velocityContext;
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) }
{
String options = genTable.getOptions(); public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
JSONObject paramsObj = JSONObject.parseObject(options); String options = genTable.getOptions();
String parentMenuId = getParentMenuId(paramsObj); JSONObject paramsObj = JSONObject.parseObject(options);
context.put("parentMenuId", parentMenuId); String parentMenuId = getParentMenuId(paramsObj);
} context.put("parentMenuId", parentMenuId);
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{ public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions(); String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options); JSONObject paramsObj = JSONObject.parseObject(options);
String treeCode = getTreecode(paramsObj); String treeCode = getTreecode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj); String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj); String treeName = getTreeName(paramsObj);
context.put("treeCode", treeCode); context.put("treeCode", treeCode);
context.put("treeParentCode", treeParentCode); context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName); context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable)); context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
{ context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); }
} if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
{ }
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); }
}
} /**
*
public static void setSubVelocityContext(VelocityContext context, GenTable genTable) *
{ * @return
GenTable subTable = genTable.getSubTable(); */
String subTableName = genTable.getSubTableName(); public static List<String> getTemplateList(String tplCategory) {
String subTableFkName = genTable.getSubTableFkName(); List<String> templates = new ArrayList<String>();
String subClassName = genTable.getSubTable().getClassName(); // templates.add("vm/java/domain.java.vm");
String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); // templates.add("vm/java/mapper.java.vm");
// templates.add("vm/java/service.java.vm");
context.put("subTable", subTable); // templates.add("vm/java/serviceImpl.java.vm");
context.put("subTableName", subTableName); // templates.add("vm/java/controller.java.vm");
context.put("subTableFkName", subTableFkName);
context.put("subTableFkClassName", subTableFkClassName); templates.add("vm/java-plus/domain.java.vm");
context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); templates.add("vm/java-plus/mapper.java.vm");
context.put("subClassName", subClassName); templates.add("vm/java-plus/service.java.vm");
context.put("subclassName", StringUtils.uncapitalize(subClassName)); templates.add("vm/java-plus/serviceImpl.java.vm");
context.put("subImportList", getImportList(genTable.getSubTable())); templates.add("vm/java-plus/controller.java.vm");
}
templates.add("vm/xml/mapper.xml.vm");
/** templates.add("vm/sql/sql.vm");
* templates.add("vm/js/api.js.vm");
* if (GenConstants.TPL_CRUD.equals(tplCategory)) {
* @return templates.add("vm/vue/index.vue.vm");
*/ } else if (GenConstants.TPL_TREE.equals(tplCategory)) {
public static List<String> getTemplateList(String tplCategory) templates.add("vm/vue/index-tree.vue.vm");
{ }
List<String> templates = new ArrayList<String>(); return templates;
templates.add("vm/java/domain.java.vm"); }
templates.add("vm/java/mapper.java.vm");
templates.add("vm/java/service.java.vm"); /**
templates.add("vm/java/serviceImpl.java.vm"); *
templates.add("vm/java/controller.java.vm"); */
templates.add("vm/xml/mapper.xml.vm"); public static String getFileName(String template, GenTable genTable) {
templates.add("vm/sql/sql.vm"); // 文件名称
templates.add("vm/js/api.js.vm"); String fileName = "";
if (GenConstants.TPL_CRUD.equals(tplCategory)) // 包路径
{ String packageName = genTable.getPackageName();
templates.add("vm/vue/index.vue.vm"); // 模块名
} String moduleName = genTable.getModuleName();
else if (GenConstants.TPL_TREE.equals(tplCategory)) // 大写类名
{ String className = genTable.getClassName();
templates.add("vm/vue/index-tree.vue.vm"); // 业务名称
} String businessName = genTable.getBusinessName();
else if (GenConstants.TPL_SUB.equals(tplCategory))
{ String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
templates.add("vm/vue/index.vue.vm"); String mybatisPath = MYBATIS_PATH + "/" + moduleName;
templates.add("vm/java/sub-domain.java.vm"); String vuePath = "vue";
}
return templates; if (template.contains("domain.java.vm")) {
} fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
} else if (template.contains("mapper.java.vm")) {
/** fileName = StringUtils.format("{}/dao.mysql/{}Mapper.java", javaPath, className);
* } else if (template.contains("service.java.vm")) {
*/ fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className);
public static String getFileName(String template, GenTable genTable) } else if (template.contains("serviceImpl.java.vm")) {
{ fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
// 文件名称 } else if (template.contains("controller.java.vm")) {
String fileName = ""; fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
// 包路径 } else if (template.contains("mapper.xml.vm")) {
String packageName = genTable.getPackageName(); fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
// 模块名 } else if (template.contains("sql.vm")) {
String moduleName = genTable.getModuleName(); fileName = businessName + "Menu.sql";
// 大写类名 } else if (template.contains("api.js.vm")) {
String className = genTable.getClassName(); fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
// 业务名称 } else if (template.contains("index.vue.vm")) {
String businessName = genTable.getBusinessName(); fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
} else if (template.contains("index-tree.vue.vm")) {
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
String mybatisPath = MYBATIS_PATH + "/" + moduleName; }
String vuePath = "vue"; return fileName;
}
if (template.contains("domain.java.vm"))
{ /**
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); *
} *
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) * @param packageName
{ * @return
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); */
} public static String getPackagePrefix(String packageName) {
else if (template.contains("mapper.java.vm")) int lastIndex = packageName.lastIndexOf(".");
{ String basePackage = StringUtils.substring(packageName, 0, lastIndex);
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); return basePackage;
} }
else if (template.contains("service.java.vm"))
{ /**
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); *
} *
else if (template.contains("serviceImpl.java.vm")) * @param columns
{ * @return
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); */
} public static HashSet<String> getImportList(List<GenTableColumn> columns) {
else if (template.contains("controller.java.vm")) HashSet<String> importList = new HashSet<String>();
{ for (GenTableColumn column : columns) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
} importList.add("java.util.Date");
else if (template.contains("mapper.xml.vm")) importList.add("com.fasterxml.jackson.annotation.JsonFormat");
{ } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); importList.add("java.math.BigDecimal");
} }
else if (template.contains("sql.vm")) }
{ return importList;
fileName = businessName + "Menu.sql"; }
}
else if (template.contains("api.js.vm")) /**
{ *
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); *
} * @param moduleName
else if (template.contains("index.vue.vm")) * @param businessName
{ * @return
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); */
} public static String getPermissionPrefix(String moduleName, String businessName) {
else if (template.contains("index-tree.vue.vm")) return StringUtils.format("{}:{}", moduleName, businessName);
{ }
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
} /**
return fileName; * ID
} *
* @param paramsObj
/** * @return ID
* */
* public static String getParentMenuId(JSONObject paramsObj) {
* @param packageName if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) {
* @return return paramsObj.getString(GenConstants.PARENT_MENU_ID);
*/ }
public static String getPackagePrefix(String packageName) return DEFAULT_PARENT_MENU_ID;
{ }
int lastIndex = packageName.lastIndexOf(".");
String basePackage = StringUtils.substring(packageName, 0, lastIndex); /**
return basePackage; *
} *
* @param paramsObj
/** * @return
* */
* public static String getTreecode(JSONObject paramsObj) {
* @param genTable if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
* @return return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
*/ }
public static HashSet<String> getImportList(GenTable genTable) return StringUtils.EMPTY;
{ }
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable(); /**
HashSet<String> importList = new HashSet<String>(); *
if (StringUtils.isNotNull(subGenTable)) *
{ * @param paramsObj
importList.add("java.util.List"); * @return
} */
for (GenTableColumn column : columns) public static String getTreeParentCode(JSONObject paramsObj) {
{ if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
{ }
importList.add("java.util.Date"); return StringUtils.EMPTY;
importList.add("com.fasterxml.jackson.annotation.JsonFormat"); }
}
else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) /**
{ *
importList.add("java.math.BigDecimal"); *
} * @param paramsObj
} * @return
return importList; */
} public static String getTreeName(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
/** return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
* }
* return StringUtils.EMPTY;
* @param moduleName }
* @param businessName
* @return /**
*/ *
public static String getPermissionPrefix(String moduleName, String businessName) *
{ * @param genTable
return StringUtils.format("{}:{}", moduleName, businessName); * @return
} */
public static int getExpandColumn(GenTable genTable) {
/** String options = genTable.getOptions();
* ID JSONObject paramsObj = JSONObject.parseObject(options);
* String treeName = paramsObj.getString(GenConstants.TREE_NAME);
* @param paramsObj int num = 0;
* @return ID for (GenTableColumn column : genTable.getColumns()) {
*/ if (column.isList()) {
public static String getParentMenuId(JSONObject paramsObj) num++;
{ String columnName = column.getColumnName();
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) if (columnName.equals(treeName)) {
{ break;
return paramsObj.getString(GenConstants.PARENT_MENU_ID); }
} }
return DEFAULT_PARENT_MENU_ID; }
} return num;
}
/** }
*
*
* @param paramsObj
* @return
*/
public static String getTreecode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_CODE))
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
return StringUtils.EMPTY;
}
/**
*
*
* @param paramsObj
* @return
*/
public static String getTreeParentCode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
return StringUtils.EMPTY;
}
/**
*
*
* @param paramsObj
* @return
*/
public static String getTreeName(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
return StringUtils.EMPTY;
}
/**
*
*
* @param genTable
* @return
*/
public static int getExpandColumn(GenTable genTable)
{
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
{
if (column.isList())
{
num++;
String columnName = column.getColumnName();
if (columnName.equals(treeName))
{
break;
}
}
}
return num;
}
}

@ -1,95 +1,95 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper"> <mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <resultMap type="com.ruoyi.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" /> <id property="columnId" column="column_id"/>
<result property="tableId" column="table_id" /> <result property="tableId" column="table_id"/>
<result property="columnName" column="column_name" /> <result property="columnName" column="column_name"/>
<result property="columnComment" column="column_comment" /> <result property="columnComment" column="column_comment"/>
<result property="columnType" column="column_type" /> <result property="columnType" column="column_type"/>
<result property="javaType" column="java_type" /> <result property="javaType" column="java_type"/>
<result property="javaField" column="java_field" /> <result property="javaField" column="java_field"/>
<result property="isPk" column="is_pk" /> <result property="isPk" column="is_pk"/>
<result property="isIncrement" column="is_increment" /> <result property="isIncrement" column="is_increment"/>
<result property="isRequired" column="is_required" /> <result property="isRequired" column="is_required"/>
<result property="isInsert" column="is_insert" /> <result property="isInsert" column="is_insert"/>
<result property="isEdit" column="is_edit" /> <result property="isEdit" column="is_edit"/>
<result property="isList" column="is_list" /> <result property="isList" column="is_list"/>
<result property="isQuery" column="is_query" /> <result property="isQuery" column="is_query"/>
<result property="queryType" column="query_type" /> <result property="queryType" column="query_type"/>
<result property="htmlType" column="html_type" /> <result property="htmlType" column="html_type"/>
<result property="dictType" column="dict_type" /> <result property="dictType" column="dict_type"/>
<result property="sort" column="sort" /> <result property="sort" column="sort"/>
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time"/>
</resultMap> </resultMap>
<sql id="selectGenTableColumnVo"> <sql id="selectGenTableColumnVo">
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
</sql> </sql>
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult"> <select id="selectGenTableColumnListByTableId" parameterType="com.ruoyi.gen.domain.GenTableColumn"
resultMap="GenTableColumnResult">
<include refid="selectGenTableColumnVo"/> <include refid="selectGenTableColumnVo"/>
where table_id = #{tableId} where table_id = #{tableId}
order by sort order by sort
</select> </select>
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position order by ordinal_position
</select> </select>
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> <insert id="insertGenTableColumn" parameterType="com.ruoyi.gen.domain.GenTableColumn" useGeneratedKeys="true"
keyProperty="columnId">
insert into gen_table_column ( insert into gen_table_column (
<if test="tableId != null and tableId != ''">table_id,</if> <if test="tableId != null and tableId != ''">table_id,</if>
<if test="columnName != null and columnName != ''">column_name,</if> <if test="columnName != null and columnName != ''">column_name,</if>
<if test="columnComment != null and columnComment != ''">column_comment,</if> <if test="columnComment != null and columnComment != ''">column_comment,</if>
<if test="columnType != null and columnType != ''">column_type,</if> <if test="columnType != null and columnType != ''">column_type,</if>
<if test="javaType != null and javaType != ''">java_type,</if> <if test="javaType != null and javaType != ''">java_type,</if>
<if test="javaField != null and javaField != ''">java_field,</if> <if test="javaField != null and javaField != ''">java_field,</if>
<if test="isPk != null and isPk != ''">is_pk,</if> <if test="isPk != null and isPk != ''">is_pk,</if>
<if test="isIncrement != null and isIncrement != ''">is_increment,</if> <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
<if test="isRequired != null and isRequired != ''">is_required,</if> <if test="isRequired != null and isRequired != ''">is_required,</if>
<if test="isInsert != null and isInsert != ''">is_insert,</if> <if test="isInsert != null and isInsert != ''">is_insert,</if>
<if test="isEdit != null and isEdit != ''">is_edit,</if> <if test="isEdit != null and isEdit != ''">is_edit,</if>
<if test="isList != null and isList != ''">is_list,</if> <if test="isList != null and isList != ''">is_list,</if>
<if test="isQuery != null and isQuery != ''">is_query,</if> <if test="isQuery != null and isQuery != ''">is_query,</if>
<if test="queryType != null and queryType != ''">query_type,</if> <if test="queryType != null and queryType != ''">query_type,</if>
<if test="htmlType != null and htmlType != ''">html_type,</if> <if test="htmlType != null and htmlType != ''">html_type,</if>
<if test="dictType != null and dictType != ''">dict_type,</if> <if test="dictType != null and dictType != ''">dict_type,</if>
<if test="sort != null">sort,</if> <if test="sort != null">sort,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
create_time create_time
)values( )values(
<if test="tableId != null and tableId != ''">#{tableId},</if> <if test="tableId != null and tableId != ''">#{tableId},</if>
<if test="columnName != null and columnName != ''">#{columnName},</if> <if test="columnName != null and columnName != ''">#{columnName},</if>
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
<if test="columnType != null and columnType != ''">#{columnType},</if> <if test="columnType != null and columnType != ''">#{columnType},</if>
<if test="javaType != null and javaType != ''">#{javaType},</if> <if test="javaType != null and javaType != ''">#{javaType},</if>
<if test="javaField != null and javaField != ''">#{javaField},</if> <if test="javaField != null and javaField != ''">#{javaField},</if>
<if test="isPk != null and isPk != ''">#{isPk},</if> <if test="isPk != null and isPk != ''">#{isPk},</if>
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
<if test="isRequired != null and isRequired != ''">#{isRequired},</if> <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
<if test="isInsert != null and isInsert != ''">#{isInsert},</if> <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
<if test="isEdit != null and isEdit != ''">#{isEdit},</if> <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
<if test="isList != null and isList != ''">#{isList},</if> <if test="isList != null and isList != ''">#{isList},</if>
<if test="isQuery != null and isQuery != ''">#{isQuery},</if> <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
<if test="queryType != null and queryType != ''">#{queryType},</if> <if test="queryType != null and queryType != ''">#{queryType},</if>
<if test="htmlType != null and htmlType != ''">#{htmlType},</if> <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if> <if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="sort != null">#{sort},</if> <if test="sort != null">#{sort},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate() sysdate()
) )
</insert> </insert>
<update id="updateGenTableColumn" parameterType="GenTableColumn"> <update id="updateGenTableColumn" parameterType="com.ruoyi.gen.domain.GenTableColumn">
update gen_table_column update gen_table_column
<set> <set>
column_comment = #{columnComment}, column_comment = #{columnComment},
@ -111,14 +111,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<delete id="deleteGenTableColumnByIds" parameterType="Long"> <delete id="deleteGenTableColumnByIds" parameterType="Long">
delete from gen_table_column where table_id in delete from gen_table_column where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")"> <foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId} #{tableId}
</foreach> </foreach>
</delete> </delete>
<delete id="deleteGenTableColumns"> <delete id="deleteGenTableColumns">
delete from gen_table_column where column_id in delete from gen_table_column where column_id in
<foreach collection="list" item="item" open="(" separator="," close=")"> <foreach collection="list" item="item" open="(" separator="," close=")">
#{item.columnId} #{item.columnId}
</foreach> </foreach>

@ -1,201 +1,182 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <mapper namespace="com.ruoyi.gen.mapper.GenTableMapper">
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.gen.mapper.GenTableMapper"> <resultMap type="com.ruoyi.gen.domain.GenTable" id="GenTableResult">
<id property="tableId" column="table_id"/>
<resultMap type="GenTable" id="GenTableResult"> <result property="tableName" column="table_name"/>
<id property="tableId" column="table_id" /> <result property="tableComment" column="table_comment"/>
<result property="tableName" column="table_name" /> <result property="className" column="class_name"/>
<result property="tableComment" column="table_comment" /> <result property="tplCategory" column="tpl_category"/>
<result property="subTableName" column="sub_table_name" /> <result property="packageName" column="package_name"/>
<result property="subTableFkName" column="sub_table_fk_name" /> <result property="moduleName" column="module_name"/>
<result property="className" column="class_name" /> <result property="businessName" column="business_name"/>
<result property="tplCategory" column="tpl_category" /> <result property="functionName" column="function_name"/>
<result property="packageName" column="package_name" /> <result property="functionAuthor" column="function_author"/>
<result property="moduleName" column="module_name" /> <result property="genType" column="gen_type"/>
<result property="businessName" column="business_name" /> <result property="genPath" column="gen_path"/>
<result property="functionName" column="function_name" /> <result property="options" column="options"/>
<result property="functionAuthor" column="function_author" /> <result property="createBy" column="create_by"/>
<result property="genType" column="gen_type" /> <result property="createTime" column="create_time"/>
<result property="genPath" column="gen_path" /> <result property="updateBy" column="update_by"/>
<result property="options" column="options" /> <result property="updateTime" column="update_time"/>
<result property="createBy" column="create_by" /> <result property="remark" column="remark"/>
<result property="createTime" column="create_time" /> <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
<result property="updateBy" column="update_by" /> </resultMap>
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" /> <resultMap type="com.ruoyi.gen.domain.GenTableColumn" id="GenTableColumnResult">
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" /> <id property="columnId" column="column_id"/>
</resultMap> <result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/>
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <result property="columnComment" column="column_comment"/>
<id property="columnId" column="column_id" /> <result property="columnType" column="column_type"/>
<result property="tableId" column="table_id" /> <result property="javaType" column="java_type"/>
<result property="columnName" column="column_name" /> <result property="javaField" column="java_field"/>
<result property="columnComment" column="column_comment" /> <result property="isPk" column="is_pk"/>
<result property="columnType" column="column_type" /> <result property="isIncrement" column="is_increment"/>
<result property="javaType" column="java_type" /> <result property="isRequired" column="is_required"/>
<result property="javaField" column="java_field" /> <result property="isInsert" column="is_insert"/>
<result property="isPk" column="is_pk" /> <result property="isEdit" column="is_edit"/>
<result property="isIncrement" column="is_increment" /> <result property="isList" column="is_list"/>
<result property="isRequired" column="is_required" /> <result property="isQuery" column="is_query"/>
<result property="isInsert" column="is_insert" /> <result property="queryType" column="query_type"/>
<result property="isEdit" column="is_edit" /> <result property="htmlType" column="html_type"/>
<result property="isList" column="is_list" /> <result property="dictType" column="dict_type"/>
<result property="isQuery" column="is_query" /> <result property="sort" column="sort"/>
<result property="queryType" column="query_type" /> <result property="createBy" column="create_by"/>
<result property="htmlType" column="html_type" /> <result property="createTime" column="create_time"/>
<result property="dictType" column="dict_type" /> <result property="updateBy" column="update_by"/>
<result property="sort" column="sort" /> <result property="updateTime" column="update_time"/>
<result property="createBy" column="create_by" /> </resultMap>
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <sql id="selectGenTableVo">
<result property="updateTime" column="update_time" /> select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
</resultMap> </sql>
<sql id="selectGenTableVo"> <select id="selectGenTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table <include refid="selectGenTableVo"/>
</sql> <where>
<if test="tableName != null and tableName != ''">
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
<include refid="selectGenTableVo"/> </if>
<where> <if test="tableComment != null and tableComment != ''">
<if test="tableName != null and tableName != ''"> AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
AND lower(table_name) like lower(concat('%', #{tableName}, '%')) </if>
</if> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
<if test="tableComment != null and tableComment != ''"> AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) </if>
</if> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') </if>
</if> </where>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> </select>
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if> <select id="selectDbTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
</where> select table_name, table_comment, create_time, update_time from information_schema.tables
</select> where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> AND table_name NOT IN (select table_name from gen_table)
select table_name, table_comment, create_time, update_time from information_schema.tables <if test="tableName != null and tableName != ''">
where table_schema = (select database()) AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' </if>
AND table_name NOT IN (select table_name from gen_table) <if test="tableComment != null and tableComment != ''">
<if test="tableName != null and tableName != ''"> AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
AND lower(table_name) like lower(concat('%', #{tableName}, '%')) </if>
</if> </select>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) <select id="selectDbTableListByNames" resultMap="GenTableResult">
</if> select table_name, table_comment, create_time, update_time from information_schema.tables
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d') and table_name in
</if> <foreach collection="array" item="name" open="(" separator="," close=")">
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> #{name}
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d') </foreach>
</if> </select>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
<select id="selectDbTableListByNames" resultMap="GenTableResult"> select table_name, table_comment, create_time, update_time from information_schema.tables
select table_name, table_comment, create_time, update_time from information_schema.tables where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) and table_name = #{tableName}
and table_name in </select>
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name} <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
</foreach> SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
</select> c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> LEFT JOIN gen_table_column c ON t.table_id = c.table_id
select table_name, table_comment, create_time, update_time from information_schema.tables where t.table_id = #{tableId} order by c.sort
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database()) </select>
and table_name = #{tableName}
</select> <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, FROM gen_table t
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort LEFT JOIN gen_table_column c ON t.table_id = c.table_id
FROM gen_table t where t.table_name = #{tableName} order by c.sort
LEFT JOIN gen_table_column c ON t.table_id = c.table_id </select>
where t.table_id = #{tableId} order by c.sort
</select> <insert id="insertGenTable" parameterType="com.ruoyi.gen.domain.GenTable" useGeneratedKeys="true"
keyProperty="tableId">
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> insert into gen_table (
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, <if test="tableName != null">table_name,</if>
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort <if test="tableComment != null and tableComment != ''">table_comment,</if>
FROM gen_table t <if test="className != null and className != ''">class_name,</if>
LEFT JOIN gen_table_column c ON t.table_id = c.table_id <if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
where t.table_name = #{tableName} order by c.sort <if test="packageName != null and packageName != ''">package_name,</if>
</select> <if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> <if test="functionName != null and functionName != ''">function_name,</if>
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, <if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort <if test="genType != null and genType != ''">gen_type,</if>
FROM gen_table t <if test="genPath != null and genPath != ''">gen_path,</if>
LEFT JOIN gen_table_column c ON t.table_id = c.table_id <if test="remark != null and remark != ''">remark,</if>
order by c.sort <if test="createBy != null and createBy != ''">create_by,</if>
</select> create_time
)values(
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> <if test="tableName != null">#{tableName},</if>
insert into gen_table ( <if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="tableName != null">table_name,</if> <if test="className != null and className != ''">#{className},</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if> <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="className != null and className != ''">class_name,</if> <if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if> <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="packageName != null and packageName != ''">package_name,</if> <if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="moduleName != null and moduleName != ''">module_name,</if> <if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="businessName != null and businessName != ''">business_name,</if> <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="functionName != null and functionName != ''">function_name,</if> <if test="genType != null and genType != ''">#{genType},</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if> <if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="genType != null and genType != ''">gen_type,</if> <if test="remark != null and remark != ''">#{remark},</if>
<if test="genPath != null and genPath != ''">gen_path,</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">remark,</if> sysdate()
<if test="createBy != null and createBy != ''">create_by,</if> )
create_time </insert>
)values(
<if test="tableName != null">#{tableName},</if> <update id="updateGenTable" parameterType="com.ruoyi.gen.domain.GenTable">
<if test="tableComment != null and tableComment != ''">#{tableComment},</if> update gen_table
<if test="className != null and className != ''">#{className},</if> <set>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> <if test="tableName != null">table_name = #{tableName},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if> <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if> <if test="className != null and className != ''">class_name = #{className},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if> <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if> <if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="genType != null and genType != ''">#{genType},</if> <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if> <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
sysdate() <if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
) <if test="options != null and options != ''">options = #{options},</if>
</insert> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<update id="updateGenTable" parameterType="GenTable"> update_time = sysdate()
update gen_table </set>
<set> where table_id = #{tableId}
<if test="tableName != null">table_name = #{tableName},</if> </update>
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="subTableName != null">sub_table_name = #{subTableName},</if> <delete id="deleteGenTableByIds" parameterType="Long">
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if> delete from gen_table where table_id in
<if test="className != null and className != ''">class_name = #{className},</if> <foreach collection="array" item="tableId" open="(" separator="," close=")">
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> #{tableId}
<if test="genType != null and genType != ''">gen_type = #{genType},</if> </foreach>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> </delete>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
<if test="options != null and options != ''">options = #{options},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>
</mapper> </mapper>

@ -0,0 +1,119 @@
package ${packageName}.controller;
import java.util.List;
import java.util.Set;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.${ClassName}Service;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
#if($table.crud)
import com.ruoyi.common.core.web.page.TableDataInfo;
#elseif($table.tree)
#end
/**
* ${functionName}Controller
*
* @author ${author}
* @date ${datetime}
*/
@RestController
@RequestMapping("/${businessName}")
public class ${ClassName}Controller extends BaseController
{
@Autowired
private ${ClassName}Service ${className}Service;
/**
* 查询${functionName}列表
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:list")
@GetMapping("/list")
#if($table.crud)
public TableDataInfo list(${ClassName} ${className})
{
startPage();
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
return AjaxResult.success(list);
}
#end
/**
* 导出${functionName}列表
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:export")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
{
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${businessName}");
}
/**
* 获取${functionName}详细信息
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:query")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
return AjaxResult.success(${className}Service.getById(${pkColumn.javaField}));
}
/**
* 新增${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:add")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.save(${className}) ? 1 : 0);
}
/**
* 修改${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:edit")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.update(new UpdateWrapper(${className})) ? 1 : 0);
}
/**
* 删除${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:remove")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.removeByIds(Set.of(${pkColumn.javaField}s)) ? ${pkColumn.javaField}s.length : 0);
}
}

@ -0,0 +1,58 @@
package ${packageName}.domain;
#foreach ($import in $importList)
import ${import};
#end
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.annotation.Excel;
#if($table.crud)
import com.ruoyi.common.core.web.domain.BaseEntity;
#elseif($table.tree)
import com.ruoyi.common.core.web.domain.TreeEntity;
#end
import lombok.Data;
import lombok.Builder;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* ${functionName}对象 ${tableName}
*
* @author ${author}
* @date ${datetime}
*/
#if($table.crud)
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#end
@Data
@Builder
@TableName("${tableName}")
public class ${ClassName} extends ${Entity}
{
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
/** $column.columnComment */
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
private $column.javaType $column.javaField;
#end
#end
}

@ -0,0 +1,14 @@
package ${packageName}.dao.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ${packageName}.domain.${ClassName};
/**
* ${functionName}Mapper接口
*
* @author ${author}
* @date ${datetime}
*/
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> {
}

@ -0,0 +1,13 @@
package ${packageName}.service;
import com.baomidou.mybatisplus.extension.service.IService;
import ${packageName}.domain.${ClassName};
/**
* ${functionName}Service接口
*
* @author ${author}
* @date ${datetime}
*/
public interface ${ClassName}Service extends IService<${ClassName}> {
}

@ -0,0 +1,27 @@
package ${packageName}.service.impl;
import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.core.utils.DateUtils;
#break
#end
#end
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import ${packageName}.dao.mysql.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.${ClassName}Service;
/**
* ${functionName}Service业务层处理
*
* @author ${author}
* @date ${datetime}
*/
@Service("${moduleName}${ClassName}Service")
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service {
}

@ -16,7 +16,7 @@ import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize; import com.ruoyi.common.security.annotation.PreAuthorize;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service; import ${packageName}.service.${ClassName}Service;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.utils.poi.ExcelUtil;
@ -36,7 +36,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
public class ${ClassName}Controller extends BaseController public class ${ClassName}Controller extends BaseController
{ {
@Autowired @Autowired
private I${ClassName}Service ${className}Service; private ${ClassName}Service ${className}Service;
/** /**
* 查询${functionName}列表 * 查询${functionName}列表

@ -1,105 +1,56 @@
package ${packageName}.domain; package ${packageName}.domain;
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
#end #end
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.annotation.Excel;
#if($table.crud || $table.sub) #if($table.crud)
import com.ruoyi.common.core.web.domain.BaseEntity; import com.ruoyi.common.core.web.domain.BaseEntity;
#elseif($table.tree) #elseif($table.tree)
import com.ruoyi.common.core.web.domain.TreeEntity; import com.ruoyi.common.core.web.domain.TreeEntity;
#end #end
import lombok.Data;
/** import lombok.Builder;
* ${functionName}对象 ${tableName} /**
* * ${functionName}对象 ${tableName}
* @author ${author} *
* @date ${datetime} * @author ${author}
*/ * @date ${datetime}
#if($table.crud || $table.sub) */
#set($Entity="BaseEntity") #if($table.crud)
#elseif($table.tree) #set($Entity="BaseEntity")
#set($Entity="TreeEntity") #elseif($table.tree)
#end #set($Entity="TreeEntity")
public class ${ClassName} extends ${Entity} #end
{ @Data
private static final long serialVersionUID = 1L; @Builder
public class ${ClassName} extends ${Entity}
#foreach ($column in $columns) {
#if(!$table.isSuperColumn($column.javaField)) private static final long serialVersionUID = 1L;
/** $column.columnComment */
#if($column.list) #foreach ($column in $columns)
#set($parentheseIndex=$column.columnComment.indexOf("")) #if(!$table.isSuperColumn($column.javaField))
#if($parentheseIndex != -1) /** $column.columnComment */
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #if($column.list)
#else #set($parentheseIndex=$column.columnComment.indexOf(""))
#set($comment=$column.columnComment) #if($parentheseIndex != -1)
#end #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#if($parentheseIndex != -1) #else
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") #set($comment=$column.columnComment)
#elseif($column.javaType == 'Date') #end
@JsonFormat(pattern = "yyyy-MM-dd") #if($parentheseIndex != -1)
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#else #elseif($column.javaType == 'Date')
@Excel(name = "${comment}") @JsonFormat(pattern = "yyyy-MM-dd")
#end @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#end #else
private $column.javaType $column.javaField; @Excel(name = "${comment}")
#end
#end #end
#end private $column.javaType $column.javaField;
#if($table.sub)
/** $table.subTable.functionName信息 */ #end
private List<${subClassName}> ${subclassName}List; #end
}
#end
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
public void set${AttrName}($column.javaType $column.javaField)
{
this.$column.javaField = $column.javaField;
}
public $column.javaType get${AttrName}()
{
return $column.javaField;
}
#end
#end
#if($table.sub)
public List<${subClassName}> get${subClassName}List()
{
return ${subclassName}List;
}
public void set${subClassName}List(List<${subClassName}> ${subclassName}List)
{
this.${subclassName}List = ${subclassName}List;
}
#end
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
#foreach ($column in $columns)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
.append("${column.javaField}", get${AttrName}())
#end
#if($table.sub)
.append("${subclassName}List", get${subClassName}List())
#end
.toString();
}
}

@ -9,7 +9,7 @@ import ${packageName}.domain.${ClassName};
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
public interface I${ClassName}Service public interface ${ClassName}Service
{ {
/** /**
* 查询${functionName} * 查询${functionName}

@ -17,7 +17,7 @@ import ${packageName}.domain.${subClassName};
#end #end
import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service; import ${packageName}.service.${ClassName}Service;
/** /**
* ${functionName}Service业务层处理 * ${functionName}Service业务层处理
@ -25,8 +25,8 @@ import ${packageName}.service.I${ClassName}Service;
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
@Service @Service("${moduleName}${ClassName}Service")
public class ${ClassName}ServiceImpl implements I${ClassName}Service public class ${ClassName}ServiceImpl implements ${ClassName}Service
{ {
@Autowired @Autowired
private ${ClassName}Mapper ${className}Mapper; private ${ClassName}Mapper ${className}Mapper;

@ -1,135 +1,93 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <mapper namespace="${packageName}.mapper.${ClassName}Mapper">
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper"> <resultMap type="${packageName}.domain.${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns)
<resultMap type="${ClassName}" id="${ClassName}Result"> <result property="${column.javaField}" column="${column.columnName}" />
#foreach ($column in $columns) #end
<result property="${column.javaField}" column="${column.columnName}" /> </resultMap>
#end
</resultMap> <sql id="select${ClassName}Vo">
#if($table.sub) select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
</sql>
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" notNullColumn="${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" /> <select id="select${ClassName}List" parameterType="${packageName}.domain.${ClassName}" resultMap="${ClassName}Result">
</resultMap> <include refid="select${ClassName}Vo"/>
<where>
<resultMap type="${subClassName}" id="${subClassName}Result"> #foreach($column in $columns)
#foreach ($column in $subTable.columns) #set($queryType=$column.queryType)
<result property="${column.javaField}" column="${column.columnName}" /> #set($javaField=$column.javaField)
#end #set($javaType=$column.javaType)
</resultMap> #set($columnName=$column.columnName)
#end #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query)
<sql id="select${ClassName}Vo"> #if($column.queryType == "EQ")
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
</sql> #elseif($queryType == "NE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result"> #elseif($queryType == "GT")
<include refid="select${ClassName}Vo"/> <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
<where> #elseif($queryType == "GTE")
#foreach($column in $columns) <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
#set($queryType=$column.queryType) #elseif($queryType == "LT")
#set($javaField=$column.javaField) <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
#set($javaType=$column.javaType) #elseif($queryType == "LTE")
#set($columnName=$column.columnName) <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #elseif($queryType == "LIKE")
#if($column.query) <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
#if($column.queryType == "EQ") #elseif($queryType == "BETWEEN")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if> <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
#elseif($queryType == "NE") #end
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if> #end
#elseif($queryType == "GT") #end
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if> </where>
#elseif($queryType == "GTE") </select>
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
#elseif($queryType == "LT") <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result">
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if> <include refid="select${ClassName}Vo"/>
#elseif($queryType == "LTE") where ${pkColumn.columnName} = #{${pkColumn.javaField}}
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if> </select>
#elseif($queryType == "LIKE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if> <insert id="insert${ClassName}" parameterType="${packageName}.domain.${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
#elseif($queryType == "BETWEEN") insert into ${tableName}
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if> <trim prefix="(" suffix=")" suffixOverrides=",">
#end #foreach($column in $columns)
#end #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
#end <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
</where> #end
</select> #end
</trim>
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end"> <trim prefix="values (" suffix=")" suffixOverrides=",">
#if($table.crud || $table.tree) #foreach($column in $columns)
<include refid="select${ClassName}Vo"/> #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
where ${pkColumn.columnName} = #{${pkColumn.javaField}} <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
#elseif($table.sub) #end
select#foreach($column in $columns) a.$column.columnName#if($velocityCount != $columns.size()),#end#end, #end
#foreach($column in $subTable.columns) b.$column.columnName#if($velocityCount != $subTable.columns.size()),#end#end </trim>
</insert>
from ${tableName} a
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName} <update id="update${ClassName}" parameterType="${packageName}.domain.${ClassName}">
where a.${pkColumn.columnName} = #{${pkColumn.javaField}} update ${tableName}
#end <trim prefix="SET" suffixOverrides=",">
</select> #foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
insert into ${tableName} #end
<trim prefix="(" suffix=")" suffixOverrides=","> #end
#foreach($column in $columns) </trim>
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) where ${pkColumn.columnName} = #{${pkColumn.javaField}}
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if> </update>
#end
#end <delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}">
</trim> delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
<trim prefix="values (" suffix=")" suffixOverrides=","> </delete>
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) <delete id="delete${ClassName}ByIds" parameterType="String">
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if> delete from ${tableName} where ${pkColumn.columnName} in
#end <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#end #{${pkColumn.javaField}}
</trim> </foreach>
</insert> </delete>
<update id="update${ClassName}" parameterType="${ClassName}">
update ${tableName}
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
#end
#end
</trim>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</update>
<delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}">
delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</delete>
<delete id="delete${ClassName}ByIds" parameterType="String">
delete from ${tableName} where ${pkColumn.columnName} in
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#{${pkColumn.javaField}}
</foreach>
</delete>
#if($table.sub)
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String">
delete from ${subTableName} where ${subTableFkName} in
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")">
#{${subTableFkclassName}}
</foreach>
</delete>
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="Long">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size()),#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end)
</foreach>
</insert>
#end
</mapper> </mapper>
Loading…
Cancel
Save