Commit 63821e7a authored by 赵啸非's avatar 赵啸非

修复部分sqlXml生成缺陷

parent 47daf42d
...@@ -84,7 +84,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor ...@@ -84,7 +84,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor
// } // }
userEntity = userService.doLogin(loginName, password, ip); userEntity = userService.doLogin(loginName, password, ip);
userEntity.setLastLoginAddress(ip); userEntity.setLastLoginAddress(ip);
saveCurrUser(request, response, userEntity); // saveCurrUser(request, response, userEntity);
recordSysLog(request, userEntity, "用户登录系统成功!"); recordSysLog(request, userEntity, "用户登录系统成功!");
// 返回拥有的菜单数据 // 返回拥有的菜单数据
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId()); Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
...@@ -121,7 +121,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor ...@@ -121,7 +121,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor
@RequestMapping("logout") @RequestMapping("logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception { public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
recordSysLog(request, "退出登录"); recordSysLog(request, "退出登录");
super.removeCurrUser(request, response); // super.removeCurrUser(request, response);
this.deleteBlackCookie(request, response); this.deleteBlackCookie(request, response);
} }
...@@ -284,7 +284,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor ...@@ -284,7 +284,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor
} }
} }
@Override // @Override
protected void saveCurrUser(HttpServletRequest request, HttpServletResponse response, IUser user, int maxAge) { protected void saveCurrUser(HttpServletRequest request, HttpServletResponse response, IUser user, int maxAge) {
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY); String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
String cookieDomain = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_DOMAIN); String cookieDomain = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_DOMAIN);
......
...@@ -92,6 +92,8 @@ public class GentableColumnEntityExt extends BaseEntityLong { ...@@ -92,6 +92,8 @@ public class GentableColumnEntityExt extends BaseEntityLong {
if ("Long".equals(javaType)) { if ("Long".equals(javaType)) {
if (ObjectUtils.isEmpty(defaultValue)) { if (ObjectUtils.isEmpty(defaultValue)) {
defaultValue = "null"; defaultValue = "null";
}else{
defaultValue= defaultValue+"L";
} }
} else if ("Integer".equals(javaType)) { } else if ("Integer".equals(javaType)) {
if ("year".equals(columnName)) { if ("year".equals(columnName)) {
...@@ -107,11 +109,14 @@ public class GentableColumnEntityExt extends BaseEntityLong { ...@@ -107,11 +109,14 @@ public class GentableColumnEntityExt extends BaseEntityLong {
} else if ("String".equals(javaType)) { } else if ("String".equals(javaType)) {
if (ObjectUtils.isEmpty(defaultValue)) { if (ObjectUtils.isEmpty(defaultValue)) {
defaultValue = "\"\""; defaultValue = "\"\"";
}else{
defaultValue= "\""+defaultValue+"\"";
} }
} else if ("BigDecimal".equals(javaType)) { } else if ("BigDecimal".equals(javaType)) {
defaultValue = "BigDecimal.ZERO"; defaultValue = "BigDecimal.ZERO";
} else if ("Date".equals(javaType)) { } else if ("Date".equals(javaType)) {
defaultValue = "new Date()"; // defaultValue = "new Date()";
defaultValue = "null";
} else { } else {
defaultValue = "null"; defaultValue = "null";
} }
......
...@@ -319,6 +319,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -319,6 +319,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
Template template = FreeMarkerUtils.getTemplate(temp); Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw); template.process(data, sw);
zip.putNextEntry(new ZipEntry(zipPath)); zip.putNextEntry(new ZipEntry(zipPath));
IOUtils.write(sw.toString(), zip, Constant.UTF8); IOUtils.write(sw.toString(), zip, Constant.UTF8);
} catch (Exception e) { } catch (Exception e) {
log.error("异常", e); log.error("异常", e);
...@@ -509,13 +510,13 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -509,13 +510,13 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
gentableEntity.getColumns().stream() gentableEntity.getColumns().stream()
.filter(f -> f.getDict() != null) .filter(f -> f.getDict() != null)
.map(item -> { .map(item -> {
Map enumData = FreeMarkerUtils.prepareSetFreeMarkerDataByEnum(item.getDict(), item.getColumnComment(), item.getColumnName(), item.getJavaType()); Map enumData = FreeMarkerUtils.prepareSetFreeMarkerDataByEnum(item.getDict(), item.getColumnComment(), item.getJavaField(), item.getJavaType());
try { try {
FreeMarkerUtils.initFreeMarker(genFreePath(temp)); FreeMarkerUtils.initFreeMarker(genFreePath(temp));
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp); Template template = FreeMarkerUtils.getTemplate(temp);
template.process(enumData, sw); template.process(enumData, sw);
String enumFileName = FreeMarkerUtils.getEnumFileName(item.getColumnName()); String enumFileName = FreeMarkerUtils.getEnumFileName(item.getJavaField());
File file = new File(enumFileName); File file = new File(enumFileName);
if (file.exists()) { if (file.exists()) {
return item; return item;
......
...@@ -442,10 +442,6 @@ public class FreeMarkerUtils { ...@@ -442,10 +442,6 @@ public class FreeMarkerUtils {
fileName = StringUtils.format("{}/{}/model/{}Query.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/model/{}Query.java", javaPath, businessName, className);
} }
// else if (template.contains("entityAndQuery.java.ftl")) {
// fileName = StringUtils.format("{}/{}/model/{}Entity.java", javaPath, businessName, className);
// }
else if (template.contains("dao.java.ftl")) { else if (template.contains("dao.java.ftl")) {
fileName = StringUtils.format("{}/{}/dao/{}Dao.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/dao/{}Dao.java", javaPath, businessName, className);
} else if (template.contains("daoImpl.java.ftl")) { } else if (template.contains("daoImpl.java.ftl")) {
......
...@@ -64,7 +64,16 @@ public class GenUtils { ...@@ -64,7 +64,16 @@ public class GenUtils {
} }
column.setQueryType("="); column.setQueryType("=");
// 设置java字段名 // 设置java字段名
boolean upperCase = StrUtil.isUpperCase(columnName);
int i = StrUtil.indexOf(columnName, "_".charAt(0));
if(upperCase&&i==-1){
column.setJavaField(StrUtil.swapCase(columnName));
}else{
column.setJavaField(StrUtil.toCamelCase(columnName)); column.setJavaField(StrUtil.toCamelCase(columnName));
}
// 设置默认类型 // 设置默认类型
column.setJavaType(GenConstants.TYPE_STRING); column.setJavaType(GenConstants.TYPE_STRING);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
...@@ -178,12 +187,18 @@ public class GenUtils { ...@@ -178,12 +187,18 @@ public class GenUtils {
temp = temp.replaceAll(";", ","); temp = temp.replaceAll(";", ",");
String[] split = checkSplitStr(temp, ","); String[] split = checkSplitStr(temp, ",");
if (split.length > 0) { if (split.length > 0) {
Arrays.asList(split).stream().peek(item -> { Arrays.asList(split).stream().peek(item -> {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
//判断分割如果存在. 则分割成key value
String[] vals = checkSplitStr(item, ".");
if(vals.length>1){
map.put("num", vals[0].trim());
map.put("value", vals[1].trim());
}else{
map.put("num", item.trim()); map.put("num", item.trim());
map.put("value", item.trim()); map.put("value", item.trim());
}
if (ObjectUtils.isEmpty(column.getDict())) { if (ObjectUtils.isEmpty(column.getDict())) {
column.setDict(new ArrayList<>()); column.setDict(new ArrayList<>());
} }
...@@ -380,5 +395,12 @@ public class GenUtils { ...@@ -380,5 +395,12 @@ public class GenUtils {
String name = "aaa"; String name = "aaa";
System.out.println(Arrays.stream(name.split("_")).collect(Collectors.joining("."))); System.out.println(Arrays.stream(name.split("_")).collect(Collectors.joining(".")));
System.out.println(Arrays.stream("data".split(".")).collect(Collectors.joining("/"))); System.out.println(Arrays.stream("data".split(".")).collect(Collectors.joining("/")));
String colName="TRIGGER_NAMEa";
System.out.println(StrUtil.isUpperCase(colName));
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -1047,7 +1047,7 @@ ...@@ -1047,7 +1047,7 @@
"mock": "{}", "mock": "{}",
"mock_url": "${appInfo.path}/param/list", "mock_url": "${appInfo.path}/param/list",
"request": { "request": {
"url": "{{baseUrl}}${appInfo.path}/office/param/list", "url": "{{baseUrl}}${appInfo.path}/param/list",
"description": "字典参数列表查询", "description": "字典参数列表查询",
"event": { "event": {
"pre_script": "", "pre_script": "",
...@@ -1504,14 +1504,14 @@ ...@@ -1504,14 +1504,14 @@
"type":"integer", "type":"integer",
"description":"当前页", "description":"当前页",
"mock":{ "mock":{
"mock":"@integer(1,10)" "mock":"1"
} }
}, },
"size":{ "size":{
"type":"integer", "type":"integer",
"description":"每页条数,值为-1,查询所有记录", "description":"每页条数,值为-1,查询所有记录",
"mock":{ "mock":{
"mock":"@integer(-1,100)" "mock":"20"
} }
} }
<#list table.columns as column> <#list table.columns as column>
......
...@@ -56,16 +56,15 @@ client.global.set("${ClassName}_id", JSON.parse(response.body).data.id); ...@@ -56,16 +56,15 @@ client.global.set("${ClassName}_id", JSON.parse(response.body).data.id);
%} %}
###${functionName}查看 ###${functionName}查看
GET {{baseUrl}}/${RequestMapping}/info?id={{${ClassName}_id}} GET {{baseUrl}}/${RequestMapping}/info?id=1
Accept: application/json
###${functionName}编辑 ###${functionName}编辑
GET {{baseUrl}}/${RequestMapping}/edit?id={{${ClassName}_id}} GET {{baseUrl}}/${RequestMapping}/edit?id=1
Accept: application/json Accept: application/json
###${functionName}删除 ###${functionName}删除
GET {{baseUrl}}/${RequestMapping}/delete?id={{${ClassName}_id}} GET {{baseUrl}}/${RequestMapping}/delete?id=1
Authorization: {{authToken}} Authorization: {{authToken}}
Accept: application/json Accept: application/json
......
...@@ -8,6 +8,8 @@ package ${packageName}.service.impl; ...@@ -8,6 +8,8 @@ package ${packageName}.service.impl;
<#else > <#else >
<#assign Service = "AbstractCRUDServiceImpl"> <#assign Service = "AbstractCRUDServiceImpl">
</#if> </#if>
import org.springframework.beans.BeanUtils;
import java.util.function.Function;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.${Service}; import com.mortals.framework.service.impl.${Service};
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
...@@ -60,6 +62,26 @@ public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${Class ...@@ -60,6 +62,26 @@ public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${Class
<#if table.tplCategory=="sub"> <#if table.tplCategory=="sub">
@Autowired @Autowired
private ${subClassName}Service ${subclassName}Service; private ${subClassName}Service ${subclassName}Service;
@Override
protected void findAfter(${ClassName}Entity params,PageInfo pageInfo, Context context, List<${ClassName}Entity> list) throws AppException {
fillSubData(list);
super.findAfter(params,pageInfo, context, list);
}
@Override
protected void findAfter(${ClassName}Entity params, Context context, List<${ClassName}Entity> list) throws AppException {
fillSubData(list);
super.findAfter(params, context, list);
}
private void fillSubData(List<${ClassName}Entity> list) {
List<${pkColumn.javaType}> idList = list.stream().map(i -> i.get${pkColumn.javaField?cap_first}()).collect(Collectors.toList());
${subClassName}Query ${subclassName}Query = new ${subClassName}Query();
${subclassName}Query.set${subTableFkClassName}List(idList);
Map<${pkColumn.javaType}, List<${subClassName}Entity>> ${subclassName}ListMap = ${subclassName}Service.find(${subclassName}Query).stream().collect(Collectors.groupingBy(${subClassName}Entity::get${subTableFkClassName}));
list.forEach(item -> item.set${subClassName}List(${subclassName}ListMap.get(item.get${pkColumn.javaField?cap_first}())));
}
${Temp} ${Temp}
@Override @Override
protected void saveAfter(${ClassName}Entity entity, Context context) throws AppException { protected void saveAfter(${ClassName}Entity entity, Context context) throws AppException {
...@@ -118,6 +140,27 @@ public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${Class ...@@ -118,6 +140,27 @@ public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${Class
<#elseif table.tplCategory=="subone"> <#elseif table.tplCategory=="subone">
@Autowired @Autowired
private ${subClassName}Service ${subclassName}Service; private ${subClassName}Service ${subclassName}Service;
@Override
protected void findAfter(${ClassName}Entity params,PageInfo pageInfo, Context context, List<${ClassName}Entity> list) throws AppException {
fillSubData(list);
super.findAfter(params,pageInfo, context, list);
}
@Override
protected void findAfter(${ClassName}Entity params, Context context, List<${ClassName}Entity> list) throws AppException {
fillSubData(list);
super.findAfter(params, context, list);
}
private void fillSubData(List<${ClassName}Entity> list) {
List<${pkColumn.javaType}> idList = list.stream().map(i -> i.get${pkColumn.javaField?cap_first}()).collect(Collectors.toList());
if(ObjectUtils.isEmpty(idList)) return;
${subClassName}Query ${subclassName}Query = new ${subClassName}Query();
${subclassName}Query.set${subTableFkClassName}List(idList);
Map<${pkColumn.javaType}, ${subClassName}Entity> ${subclassName}Map = ${subclassName}Service.find(${subclassName}Query).stream().collect(Collectors.toMap(${subClassName}Entity::get${subTableFkClassName}, Function.identity(), (n1, n2) -> n1));
list.forEach(item -> item.set${subClassName}Entity(${subclassName}Map.get(item.get${pkColumn.javaField?cap_first}())));
}
${Temp} ${Temp}
@Override @Override
protected void saveAfter(${ClassName}Entity entity, Context context) throws AppException { protected void saveAfter(${ClassName}Entity entity, Context context) throws AppException {
......
...@@ -20,15 +20,15 @@ ...@@ -20,15 +20,15 @@
<result property="${column.javaField}" column="${column.columnName}" /> <result property="${column.javaField}" column="${column.columnName}" />
</#if> </#if>
</#list> </#list>
${SubArray} <#-- ${SubArray}-->
</resultMap> </resultMap>
<#if table.tplCategory=="sub" ||table.tplCategory=="subone"> <#-- <#if table.tplCategory=="sub" ||table.tplCategory=="subone">
<resultMap type="${subClassName}Entity" id="${subClassName}Entity-Map"> <resultMap type="${subClassName}Entity" id="${subClassName}Entity-Map">
<#list subTable.columns as column> <#list subTable.columns as column>
<result property="${column.javaField}" column="${column.columnName}" /> <result property="${column.javaField}" column="${column.columnName}" />
</#list> </#list>
</resultMap> </resultMap>
</#if> </#if>-->
<#-- 判断是否分表,如果分表 则不指定表名 --> <#-- 判断是否分表,如果分表 则不指定表名 -->
<#if table.dividedTableType==0 > <#if table.dividedTableType==0 >
...@@ -248,13 +248,13 @@ ...@@ -248,13 +248,13 @@
<#elseif subTableFkType=="String"> <#elseif subTableFkType=="String">
<#assign ParameterType>java.lang.String</#assign> <#assign ParameterType>java.lang.String</#assign>
</#if> </#if>
<select id="get${subClassName}By${subTableFkClassName}" parameterType="${ParameterType}" resultMap="${subClassName}Entity-Map"> <#-- <select id="get${subClassName}By${subTableFkClassName}" parameterType="${ParameterType}" resultMap="${subClassName}Entity-Map">
select <include refid="_columns_sub"/> select <include refid="_columns_sub"/>
from ${TempSubTable} as b from ${TempSubTable} as b
<trim suffixOverrides="where" suffix=""> <trim suffixOverrides="where" suffix="">
where b.${subTableFkName} = <#noparse>#</#noparse>{${pkColumn.columnName}} where b.${subTableFkName} = <#noparse>#</#noparse>{${pkColumn.columnName}}
</trim> </trim>
</select> </select>-->
</#if> </#if>
...@@ -313,6 +313,10 @@ ...@@ -313,6 +313,10 @@
<!-- 条件映射-代参数 --> <!-- 条件映射-代参数 -->
<sql id="_condition_param_"> <sql id="_condition_param_">
<bind name="conditionParamRef" value="<#noparse>${_conditionParam_}</#noparse>"/> <bind name="conditionParamRef" value="<#noparse>${_conditionParam_}</#noparse>"/>
<if test="permissionSql != null and permissionSql != ''">
<#noparse>${permissionSql}</#noparse>
</if>
<if test="conditionParamRef.containsKey('id')"> <if test="conditionParamRef.containsKey('id')">
<if test="conditionParamRef.id != null"> <if test="conditionParamRef.id != null">
<#noparse>${_conditionType_}</#noparse> a.${pkColumn.columnName}=<#noparse>#{${_conditionParam_}.id}</#noparse> <#noparse>${_conditionType_}</#noparse> a.${pkColumn.columnName}=<#noparse>#{${_conditionParam_}.id}</#noparse>
......
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