Commit 3cfc62f1 authored by 李驰骋's avatar 李驰骋

源码生成调整、上传路径调整,区分静态目录文件

parent 8022f01b
...@@ -2,8 +2,10 @@ package com.ximai.web.controller.common; ...@@ -2,8 +2,10 @@ package com.ximai.web.controller.common;
import com.ximai.common.config.RuoYiConfig; import com.ximai.common.config.RuoYiConfig;
import com.ximai.common.constant.Constants; import com.ximai.common.constant.Constants;
import com.ximai.common.core.domain.AjaxResult;
import com.ximai.common.core.domain.AjaxResult2; import com.ximai.common.core.domain.AjaxResult2;
import com.ximai.common.core.domain.PreviewParameters; import com.ximai.common.core.domain.PreviewParameters;
import com.ximai.common.core.domain.model.UploadFileResult;
import com.ximai.common.utils.barcode.BarcodeUtil; import com.ximai.common.utils.barcode.BarcodeUtil;
import com.ximai.common.utils.data.StringUtils; import com.ximai.common.utils.data.StringUtils;
import com.ximai.common.utils.file.FileUploadUtils; import com.ximai.common.utils.file.FileUploadUtils;
...@@ -78,60 +80,26 @@ public class CommonController { ...@@ -78,60 +80,26 @@ public class CommonController {
} }
} }
public static void main(String[] args) {
String osName = System.getProperty("os.name");
if (osName.toLowerCase().contains("windows")) {
System.out.println("当前系统是Windows系统。");
} else {
System.out.println("当前系统不是Windows系统。");
}
System.out.println("Operating System Version: " + osName);
}
/** /**
* 通用上传请求(单个) * 通用上传请求(单个)
*/ */
@ApiOperation("文件上传")
@PostMapping("/upload") @PostMapping("/upload")
public AjaxResult2 uploadFile(@RequestParam("file") MultipartFile file) throws Exception { public AjaxResult<UploadFileResult> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
try { try {
// 上传文件路径 // 上传文件路径
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file); String fileName = FileUploadUtils.upload(filePath, file);
String url = ServerConfig.getUrl() + fileName; String url = ServerConfig.getUrl() + fileName;
AjaxResult2 ajax = AjaxResult2.success(); UploadFileResult rst = new UploadFileResult();
ajax.put("url", url); rst.setUrl(url);
ajax.put("fileName", fileName); rst.setFileName(fileName);
ajax.put("newFileName", FileUtils.getName(fileName)); rst.setOriginalFilename(file.getOriginalFilename());
ajax.put("originalFilename", file.getOriginalFilename()); rst.setSize(file.getSize());
// System.out.println(JSONObject.toJSONString(ajax)); return AjaxResult.success(rst);
return ajax;
} catch (Exception e) {
return AjaxResult2.error(e.getMessage());
}
}
/**
* 通用上传请求(单个)
*/
@PostMapping("/upload2")
public AjaxResult2 upload2(@RequestParam("file") MultipartFile file) throws Exception {
try {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = RuoYiConfig.getDownloadServerUrlStatic() + fileName;
AjaxResult2 ajax = AjaxResult2.success();
ajax.put("url", url);
ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", file.getOriginalFilename());
// System.out.println(JSONObject.toJSONString(ajax));
return ajax;
} catch (Exception e) { } catch (Exception e) {
return AjaxResult2.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
...@@ -178,7 +146,7 @@ public class CommonController { ...@@ -178,7 +146,7 @@ public class CommonController {
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource)); throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
} }
// 本地资源路径 // 本地资源路径
String localPath = RuoYiConfig.getProfileStatic(); String localPath = RuoYiConfig.getProfile();
// 数据库资源地址 // 数据库资源地址
String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
// 下载名称 // 下载名称
...@@ -309,15 +277,4 @@ public class CommonController { ...@@ -309,15 +277,4 @@ public class CommonController {
response.getOutputStream().close(); response.getOutputStream().close();
} }
public static String decode(String value) {
if (value == null) {
return value;
}
try {
return URLDecoder.decode(value, "utf-8");
} catch (Exception ex) {
return value;
}
}
} }
package com.ximai.web.controller.tool;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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.ximai.common.core.controller.BaseController;
import com.ximai.common.core.domain.AjaxResult;
import com.ximai.common.utils.data.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
/**
* swagger 用户测试方法
*
*/
@Api("用户信息管理")
@RestController
@RequestMapping("/test/user")
public class TestController extends BaseController
{
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
{
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
}
@ApiOperation("获取用户列表")
@GetMapping("/list")
public AjaxResult userList()
{
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
return AjaxResult.success(userList);
}
@ApiOperation("获取用户详细")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
@GetMapping("/{userId}")
public AjaxResult getUser(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
return AjaxResult.success(users.get(userId));
}
else
{
return error("用户不存在");
}
}
@ApiOperation("新增用户")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
@ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
@ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
})
@PostMapping("/save")
public AjaxResult save(UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return error("用户ID不能为空");
}
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("更新用户")
@PutMapping("/update")
public AjaxResult update(@RequestBody UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return error("用户ID不能为空");
}
if (users.isEmpty() || !users.containsKey(user.getUserId()))
{
return error("用户不存在");
}
users.remove(user.getUserId());
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("删除用户信息")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
@DeleteMapping("/{userId}")
public AjaxResult delete(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
users.remove(userId);
return success();
}
else
{
return error("用户不存在");
}
}
}
@ApiModel(value = "UserEntity", description = "用户实体")
class UserEntity
{
@ApiModelProperty("用户ID")
private Integer userId;
@ApiModelProperty("用户名称")
private String username;
@ApiModelProperty("用户密码")
private String password;
@ApiModelProperty("用户手机")
private String mobile;
public UserEntity()
{
}
public UserEntity(Integer userId, String username, String password, String mobile)
{
this.userId = userId;
this.username = username;
this.password = password;
this.mobile = mobile;
}
public Integer getUserId()
{
return userId;
}
public void setUserId(Integer userId)
{
this.userId = userId;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getMobile()
{
return mobile;
}
public void setMobile(String mobile)
{
this.mobile = mobile;
}
}
...@@ -9,8 +9,7 @@ ximai-mes: ...@@ -9,8 +9,7 @@ ximai-mes:
# 实例演示开关 # 实例演示开关
demoEnabled: true demoEnabled: true
# 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath) # 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath)
profile: D:/source_code/j2eeworkspace/xiaomi-mes/upload profile: D:/code/upload
#profile: /home/www/uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证 # 验证码类型 math 数组计算 char 字符验证
...@@ -57,7 +56,7 @@ spring: ...@@ -57,7 +56,7 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
url: jdbc:mysql://localhost:3307/mes-new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3307/xm_mes_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: 123456 password: 123456
# 从库数据源 # 从库数据源
...@@ -203,9 +202,9 @@ xss: ...@@ -203,9 +202,9 @@ xss:
#Mino配置 #Mino配置
minio: minio:
url: http://192.168.3.91:9000 url: http://localhost:9000
accessKey: minioadmin accessKey: admin
secretKey: minioadmin secretKey: admin123
bucketName: mes bucketName: mes
#远程连接SAP #远程连接SAP
......
...@@ -10,11 +10,6 @@ ximai-mes: ...@@ -10,11 +10,6 @@ ximai-mes:
demoEnabled: true demoEnabled: true
# 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath) # 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath)
profile: D:/code/upload profile: D:/code/upload
downloadServerUrl: http://192.168.3.91:200
downloadProfile: /upload
windowsProfile: C:\Users\1\Desktop\upload\prod
linuxProfile: /mnt
#profile: /home/www/uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证 # 验证码类型 math 数组计算 char 字符验证
......
...@@ -10,11 +10,6 @@ ximai-mes: ...@@ -10,11 +10,6 @@ ximai-mes:
demoEnabled: true demoEnabled: true
# 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath) # 文件路径 示例( Windows配置D:/ximai/uploadPath,Linux配置 /home/ximai/uploadPath)
profile: D:/code/upload profile: D:/code/upload
downloadServerUrl: http://192.168.3.91:200
downloadProfile: /upload
windowsProfile: C:\Users\1\Desktop\upload
linuxProfile: /mnt
#profile: /home/www/uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证 # 验证码类型 math 数组计算 char 字符验证
......
...@@ -36,15 +36,8 @@ public class RuoYiConfig { ...@@ -36,15 +36,8 @@ public class RuoYiConfig {
*/ */
private boolean demoEnabled; private boolean demoEnabled;
private String profile; private static String profile;
private String downloadProfile;
/**
* 上传路径
*/
private String windowsProfile;
private String linuxProfile;
private String downloadServerUrl;
/** /**
* 获取地址开关 * 获取地址开关
*/ */
...@@ -87,7 +80,7 @@ public class RuoYiConfig { ...@@ -87,7 +80,7 @@ public class RuoYiConfig {
this.demoEnabled = demoEnabled; this.demoEnabled = demoEnabled;
} }
public String getProfile() { public static String getProfile() {
return profile; return profile;
} }
...@@ -95,38 +88,6 @@ public class RuoYiConfig { ...@@ -95,38 +88,6 @@ public class RuoYiConfig {
this.profile = profile; this.profile = profile;
} }
public String getDownloadProfile() {
return downloadProfile;
}
public void setDownloadProfile(final String downloadProfile) {
this.downloadProfile = downloadProfile;
}
public String getWindowsProfile() {
return windowsProfile;
}
public void setWindowsProfile(final String windowsProfile) {
this.windowsProfile = windowsProfile;
}
public String getLinuxProfile() {
return linuxProfile;
}
public void setLinuxProfile(final String linuxProfile) {
this.linuxProfile = linuxProfile;
}
public String getDownloadServerUrl() {
return downloadServerUrl;
}
public void setDownloadServerUrl(final String downloadServerUrl) {
this.downloadServerUrl = downloadServerUrl;
}
public boolean isAddressEnabled() { public boolean isAddressEnabled() {
return addressEnabled; return addressEnabled;
} }
...@@ -155,24 +116,6 @@ public class RuoYiConfig { ...@@ -155,24 +116,6 @@ public class RuoYiConfig {
return config; return config;
} }
public static String getProfileStatic() {
return getConfig().profile;
}
public static String getWindowsProfileStatic() {
return getConfig().windowsProfile;
}
public static String getDownloadProfileStatic() {
return getConfig().downloadProfile;
}
public static String getLinuxProfileStatic() {
return getConfig().linuxProfile;
}
public static boolean getAddressEnabledStatic() { public static boolean getAddressEnabledStatic() {
return getConfig().addressEnabled; return getConfig().addressEnabled;
} }
...@@ -182,51 +125,35 @@ public class RuoYiConfig { ...@@ -182,51 +125,35 @@ public class RuoYiConfig {
return getConfig().captchaType; return getConfig().captchaType;
} }
public static String getDownloadServerUrlStatic() {
return getConfig().downloadServerUrl;
}
/** /**
* 获取导入上传路径 * 获取导入上传路径
*/ */
public static String getImportPath() { public static String getImportPath()
if (OS_NAME.toLowerCase().contains("windows")) { {
return getWindowsProfileStatic() + "/import"; return getProfile() + "/import";
} else {
return getLinuxProfileStatic() + "/import";
}
} }
/** /**
* 获取头像上传路径 * 获取头像上传路径
*/ */
public static String getAvatarPath() { public static String getAvatarPath()
if (OS_NAME.toLowerCase().contains("windows")) { {
return getWindowsProfileStatic() + "/avatar"; return getProfile() + "/static/avatar";
} else {
return getLinuxProfileStatic() + "/avatar";
}
} }
/** /**
* 获取下载路径 * 获取下载路径
*/ */
public static String getDownloadPath() { public static String getDownloadPath()
if (OS_NAME.toLowerCase().contains("windows")) { {
return getWindowsProfileStatic() + "/download"; return getProfile() + "/download/";
} else {
return getLinuxProfileStatic() + "/download";
}
} }
/** /**
* 获取上传路径 * 获取上传路径
*/ */
public static String getUploadPath() { public static String getUploadPath()
if (OS_NAME.toLowerCase().contains("windows")) { {
return getWindowsProfileStatic() + "/upload"; return getProfile() + "/upload";
} else {
return getLinuxProfileStatic() + "/upload";
}
} }
} }
package com.ximai.common.core.domain.model;
import lombok.Data;
@Data
public class UploadFileResult {
String url;
String fileName;
String originalFilename;
Long size;
}
...@@ -2,6 +2,7 @@ package com.ximai.common.utils.file; ...@@ -2,6 +2,7 @@ package com.ximai.common.utils.file;
import com.ximai.common.config.MinioConfig; import com.ximai.common.config.MinioConfig;
import com.ximai.common.config.RuoYiConfig; import com.ximai.common.config.RuoYiConfig;
import com.ximai.common.constant.Constants;
import com.ximai.common.exception.file.FileNameLengthLimitExceededException; import com.ximai.common.exception.file.FileNameLengthLimitExceededException;
import com.ximai.common.exception.file.FileSizeLimitExceededException; import com.ximai.common.exception.file.FileSizeLimitExceededException;
import com.ximai.common.exception.file.InvalidExtensionException; import com.ximai.common.exception.file.InvalidExtensionException;
...@@ -33,7 +34,7 @@ public class FileUploadUtils { ...@@ -33,7 +34,7 @@ public class FileUploadUtils {
/** /**
* 默认上传的地址 * 默认上传的地址
*/ */
private static String defaultBaseDir = RuoYiConfig.getProfileStatic(); private static String defaultBaseDir = RuoYiConfig.getProfile();
public static void setDefaultBaseDir(String defaultBaseDir) { public static void setDefaultBaseDir(String defaultBaseDir) {
FileUploadUtils.defaultBaseDir = defaultBaseDir; FileUploadUtils.defaultBaseDir = defaultBaseDir;
...@@ -181,9 +182,9 @@ public class FileUploadUtils { ...@@ -181,9 +182,9 @@ public class FileUploadUtils {
} }
public static final String getPathFileName(String uploadDir, String fileName) throws IOException { public static final String getPathFileName(String uploadDir, String fileName) throws IOException {
int dirLastIndex = RuoYiConfig.getProfileStatic().length() + 1; int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
String currentDir = StringUtils.substring(uploadDir, dirLastIndex); String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
return RuoYiConfig.getDownloadProfileStatic() + "/" + currentDir + "/" + fileName; return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
} }
/** /**
......
...@@ -62,7 +62,7 @@ public class ImageUtils { ...@@ -62,7 +62,7 @@ public class ImageUtils {
in = urlConnection.getInputStream(); in = urlConnection.getInputStream();
} else { } else {
// 本机地址 // 本机地址
String localPath = RuoYiConfig.getProfileStatic(); String localPath = RuoYiConfig.getProfile();
String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX);
in = new FileInputStream(downloadPath); in = new FileInputStream(downloadPath);
} }
......
...@@ -32,9 +32,9 @@ public class ResourcesConfig implements WebMvcConfigurer { ...@@ -32,9 +32,9 @@ public class ResourcesConfig implements WebMvcConfigurer {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
/** 本地文件上传路径 */ /** 本地静态文件上传路径 */
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
.addResourceLocations("file:" + RuoYiConfig.getProfileStatic() + "/"); .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");
/** swagger配置 */ /** swagger配置 */
registry.addResourceHandler("/swagger-ui/**") registry.addResourceHandler("/swagger-ui/**")
......
...@@ -101,7 +101,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -101,7 +101,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/**/*.html", "/**/*.html",
"/**/*.css", "/**/*.css",
"/**/*.js", "/**/*.js",
"/profile/**" "/profile/static/**"
).permitAll() ).permitAll()
.antMatchers("/swagger-ui.html").anonymous() .antMatchers("/swagger-ui.html").anonymous()
.antMatchers("*/doc.html").anonymous() .antMatchers("*/doc.html").anonymous()
......
...@@ -52,12 +52,12 @@ public class GenController extends BaseController { ...@@ -52,12 +52,12 @@ public class GenController extends BaseController {
@GetMapping(value = "/{tableId}") @GetMapping(value = "/{tableId}")
public AjaxResult getInfo(@PathVariable final Long tableId) { public AjaxResult getInfo(@PathVariable final Long tableId) {
final GenTable table = genTableService.selectGenTableById(tableId); final GenTable table = genTableService.selectGenTableById(tableId);
final List<GenTable> tables = genTableService.selectGenTableAll(); //final List<GenTable> tables = genTableService.selectGenTableAll();
//map.put("tables", tables);
final List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); final List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
final Map<String, Object> map = new HashMap<String, Object>(); final Map<String, Object> map = new HashMap<String, Object>();
map.put("info", table); map.put("info", table);
map.put("rows", list); map.put("rows", list);
map.put("tables", tables);
return AjaxResult.success(map); return AjaxResult.success(map);
} }
......
...@@ -44,6 +44,10 @@ public class GenTable extends BaseEntity ...@@ -44,6 +44,10 @@ public class GenTable extends BaseEntity
@NotBlank(message = "生成包路径不能为空") @NotBlank(message = "生成包路径不能为空")
private String packageName; private String packageName;
/** 生成包路径 */
@NotBlank(message = "子包名称")
private String childPackageName;
/** 生成模块名 */ /** 生成模块名 */
@NotBlank(message = "生成模块名不能为空") @NotBlank(message = "生成模块名不能为空")
private String moduleName; private String moduleName;
...@@ -368,4 +372,12 @@ public class GenTable extends BaseEntity ...@@ -368,4 +372,12 @@ public class GenTable extends BaseEntity
} }
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
} }
public String getChildPackageName() {
return childPackageName;
}
public void setChildPackageName(String childPackageName) {
this.childPackageName = childPackageName;
}
} }
...@@ -51,6 +51,11 @@ public class VelocityUtils ...@@ -51,6 +51,11 @@ public class VelocityUtils
velocityContext.put("businessName", genTable.getBusinessName()); velocityContext.put("businessName", genTable.getBusinessName());
velocityContext.put("basePackage", getPackagePrefix(packageName)); velocityContext.put("basePackage", getPackagePrefix(packageName));
velocityContext.put("packageName", packageName); velocityContext.put("packageName", packageName);
if(StringUtils.isNotEmpty(genTable.getChildPackageName())){
velocityContext.put("childPackageName", "."+genTable.getChildPackageName());
}else{
velocityContext.put("childPackageName", "");
}
velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("author", genTable.getFunctionAuthor());
velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn()); velocityContext.put("pkColumn", genTable.getPkColumn());
...@@ -165,6 +170,7 @@ public class VelocityUtils ...@@ -165,6 +170,7 @@ public class VelocityUtils
String fileName = ""; String fileName = "";
// 包路径 // 包路径
String packageName = genTable.getPackageName(); String packageName = genTable.getPackageName();
String childPackageName = genTable.getChildPackageName();
// 模块名 // 模块名
String moduleName = genTable.getModuleName(); String moduleName = genTable.getModuleName();
// 大写类名 // 大写类名
...@@ -173,56 +179,59 @@ public class VelocityUtils ...@@ -173,56 +179,59 @@ public class VelocityUtils
String businessName = genTable.getBusinessName(); String businessName = genTable.getBusinessName();
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
if(StringUtils.isNotEmpty(childPackageName)){
childPackageName = childPackageName+"/";
}
String mybatisPath = MYBATIS_PATH + "/" + moduleName; String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue"; String vuePath = "vue";
if (template.contains("domain.java.vm")) if (template.contains("domain.java.vm"))
{ {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); fileName = StringUtils.format("{}/domain/{}{}.java", javaPath, childPackageName, className);
} }
if (template.contains("dto-query.java.vm")) if (template.contains("dto-query.java.vm"))
{ {
fileName = StringUtils.format("{}/dto/{}Dto.java", javaPath, className); fileName = StringUtils.format("{}/dto/{}{}Dto.java", javaPath, childPackageName, className);
} }
if (template.contains("dto-create.java.vm")) if (template.contains("dto-create.java.vm"))
{ {
fileName = StringUtils.format("{}/dto/{}Create.java", javaPath, className); fileName = StringUtils.format("{}/dto/{}{}Create.java", javaPath, childPackageName, className);
} }
if (template.contains("dto-update.java.vm")) if (template.contains("dto-update.java.vm"))
{ {
fileName = StringUtils.format("{}/dto/{}Update.java", javaPath, className); fileName = StringUtils.format("{}/dto/{}{}Update.java", javaPath, childPackageName, className);
} }
if (template.contains("dto-excelImport.java.vm")) if (template.contains("dto-excelImport.java.vm"))
{ {
fileName = StringUtils.format("{}/dto/{}ExcelImport.java", javaPath, className); fileName = StringUtils.format("{}/dto/{}{}ExcelImport.java", javaPath, childPackageName, className);
} }
if (template.contains("dto-excelExport.java.vm")) if (template.contains("dto-excelExport.java.vm"))
{ {
fileName = StringUtils.format("{}/dto/{}ExcelExport.java", javaPath, className); fileName = StringUtils.format("{}/dto/{}{}ExcelExport.java", javaPath, childPackageName, className);
} }
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{ {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); fileName = StringUtils.format("{}/domain/{}{}.java", javaPath, childPackageName, genTable.getSubTable().getClassName());
} }
else if (template.contains("mapper.java.vm")) else if (template.contains("mapper.java.vm"))
{ {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); fileName = StringUtils.format("{}/mapper/{}{}Mapper.java", javaPath, childPackageName, className);
} }
else if (template.contains("service.java.vm")) else if (template.contains("service.java.vm"))
{ {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); fileName = StringUtils.format("{}/service/{}I{}Service.java", javaPath, childPackageName, className);
} }
else if (template.contains("serviceImpl.java.vm")) else if (template.contains("serviceImpl.java.vm"))
{ {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); fileName = StringUtils.format("{}/service/impl/{}{}ServiceImpl.java", javaPath, childPackageName, className);
} }
else if (template.contains("controller.java.vm")) else if (template.contains("controller.java.vm"))
{ {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); fileName = StringUtils.format("{}/controller/{}{}Controller.java", javaPath, childPackageName, className);
} }
else if (template.contains("mapper.xml.vm")) else if (template.contains("mapper.xml.vm"))
{ {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); fileName = StringUtils.format("{}/{}{}Mapper.xml", mybatisPath, childPackageName, className);
} }
else if (template.contains("sql.vm")) else if (template.contains("sql.vm"))
{ {
......
...@@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="className" column="class_name" /> <result property="className" column="class_name" />
<result property="tplCategory" column="tpl_category" /> <result property="tplCategory" column="tpl_category" />
<result property="packageName" column="package_name" /> <result property="packageName" column="package_name" />
<result property="childPackageName" column="child_package_name" />
<result property="moduleName" column="module_name" /> <result property="moduleName" column="module_name" />
<result property="businessName" column="business_name" /> <result property="businessName" column="business_name" />
<result property="functionName" column="function_name" /> <result property="functionName" column="function_name" />
...@@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
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, 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.child_package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
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 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 FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
...@@ -119,7 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -119,7 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
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, 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.child_package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
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 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 FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
...@@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
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, 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.child_package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
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 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 FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
...@@ -141,6 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -141,6 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="className != null and className != ''">class_name,</if> <if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if> <if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="packageName != null and packageName != ''">package_name,</if> <if test="packageName != null and packageName != ''">package_name,</if>
<if test="childPackageName != null and packageName != ''">child_package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if> <if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if> <if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if> <if test="functionName != null and functionName != ''">function_name,</if>
...@@ -156,6 +158,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -156,6 +158,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="className != null and className != ''">#{className},</if> <if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if> <if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="childPackageName != null and childPackageName != ''">#{childPackageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if> <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if> <if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if> <if test="functionName != null and functionName != ''">#{functionName},</if>
...@@ -180,7 +183,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -180,7 +183,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="genType != null and genType != ''">gen_type = #{genType},</if> <if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if> <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="childPackageName != null and childPackageName != ''">child_package_name = #{childPackageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if> <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if> <if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
......
package ${packageName}.controller; package ${packageName}.controller${childPackageName};
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -17,12 +17,12 @@ import com.ximai.common.core.controller.BaseController; ...@@ -17,12 +17,12 @@ import com.ximai.common.core.controller.BaseController;
import com.ximai.common.core.domain.AjaxResult; import com.ximai.common.core.domain.AjaxResult;
import com.ximai.common.enums.BusinessType; import com.ximai.common.enums.BusinessType;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain${childPackageName}.${ClassName};
import ${packageName}.dto.${ClassName}Dto; import ${packageName}.dto${childPackageName}.${ClassName}Dto;
import ${packageName}.dto.${ClassName}Create; import ${packageName}.dto${childPackageName}.${ClassName}Create;
import ${packageName}.dto.${ClassName}Update; import ${packageName}.dto${childPackageName}.${ClassName}Update;
import ${packageName}.dto.${ClassName}ExcelExport; import ${packageName}.dto${childPackageName}.${ClassName}ExcelExport;
import ${packageName}.service.I${ClassName}Service; import ${packageName}.service${childPackageName}.I${ClassName}Service;
import com.ximai.common.utils.poi.ExcelUtil; import com.ximai.common.utils.poi.ExcelUtil;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
......
package ${packageName}.domain; package ${packageName}.domain${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.dto; package ${packageName}.dto${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.dto; package ${packageName}.dto${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.dto; package ${packageName}.dto${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.dto; package ${packageName}.dto${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.dto; package ${packageName}.dto${childPackageName};
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
......
package ${packageName}.mapper; package ${packageName}.mapper${childPackageName};
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain${childPackageName}.${ClassName};
import ${packageName}.dto.${ClassName}Dto; import ${packageName}.dto${childPackageName}.${ClassName}Dto;
#if($table.sub) #if($table.sub)
import ${packageName}.domain.${subClassName}; import ${packageName}.domain${childPackageName}.${subClassName};
#end #end
/** /**
......
package ${packageName}.service; package ${packageName}.service${childPackageName};
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain${childPackageName}.${ClassName};
import ${packageName}.dto.${ClassName}Create; import ${packageName}.dto${childPackageName}.${ClassName}Create;
import ${packageName}.dto.${ClassName}Update; import ${packageName}.dto${childPackageName}.${ClassName}Update;
import ${packageName}.dto.${ClassName}Dto; import ${packageName}.dto${childPackageName}.${ClassName}Dto;
/** /**
* ${functionName}Service接口 * ${functionName}Service接口
......
package ${packageName}.service.impl; package ${packageName}.service.impl${childPackageName};
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -16,14 +16,14 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -16,14 +16,14 @@ import cn.hutool.core.bean.BeanUtil;
import java.util.ArrayList; import java.util.ArrayList;
import com.ximai.common.utils.data.StringUtils; import com.ximai.common.utils.data.StringUtils;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName}; import ${packageName}.domain${childPackageName}.${subClassName};
#end #end
import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.mapper${childPackageName}.${ClassName}Mapper;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain${childPackageName}.${ClassName};
import ${packageName}.dto.${ClassName}Create; import ${packageName}.dto${childPackageName}.${ClassName}Create;
import ${packageName}.dto.${ClassName}Update; import ${packageName}.dto${childPackageName}.${ClassName}Update;
import ${packageName}.dto.${ClassName}Dto; import ${packageName}.dto${childPackageName}.${ClassName}Dto;
import ${packageName}.service.I${ClassName}Service; import ${packageName}.service${childPackageName}.I${ClassName}Service;
/** /**
* ${functionName}Service业务层处理 * ${functionName}Service业务层处理
...@@ -111,7 +111,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service ...@@ -111,7 +111,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
return rows; return rows;
#else #else
${ClassName} ${className} = new ${ClassName}(); ${ClassName} ${className} = new ${ClassName}();
BeanUtil.copyProperties(proBom1Create, ${className}); BeanUtil.copyProperties(${className}Create, ${className});
return ${className}Mapper.insert${ClassName}(${className}); return ${className}Mapper.insert${ClassName}(${className});
#end #end
} }
...@@ -141,7 +141,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service ...@@ -141,7 +141,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
insert${subClassName}(${className}); insert${subClassName}(${className});
#end #end
${ClassName} ${className} = new ${ClassName}(); ${ClassName} ${className} = new ${ClassName}();
BeanUtil.copyProperties(proBom1Update, ${className}); BeanUtil.copyProperties(${className}Update, ${className});
return ${className}Mapper.update${ClassName}(${className}); return ${className}Mapper.update${ClassName}(${className});
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper"> <mapper namespace="${packageName}.mapper${childPackageName}.${ClassName}Mapper">
<resultMap type="${ClassName}" id="${ClassName}Result"> <resultMap type="${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns) #foreach ($column in $columns)
...@@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#end #end
</resultMap> </resultMap>
<resultMap type="${packageName}.dto.${ClassName}Dto" id="${ClassName}Result2"> <resultMap type="${packageName}.dto${childPackageName}.${ClassName}Dto" id="${ClassName}Result2">
#foreach ($column in $columns) #foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}" /> <result property="${column.javaField}" column="${column.columnName}" />
#end #end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment