Skip to content

Commit

Permalink
Merge branch 'v3.5.6-RC1' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/src/main/java/com/yonyou/iuap/baseservice/persistence/mybatis/ext/adapter/DefaultMapperBuilder.java
#	core/src/main/java/com/yonyou/iuap/baseservice/support/generator/Strategy.java
#	persistence/pom.xml
  • Loading branch information
yangliangs committed Apr 2, 2019
2 parents 13b0216 + 9390bd8 commit 33ec6b8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.yonyou.iuap.baseservice.persistence.mybatis.ext.adapter;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ServiceLoader;

import com.yonyou.iuap.baseservice.persistence.mybatis.ext.utils.EntityUtil;
import com.yonyou.iuap.baseservice.support.generator.GeneratedValue;
import com.yonyou.iuap.baseservice.support.generator.Strategy;
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.MappedStatement.Builder;
import org.apache.ibatis.mapping.SqlCommandType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.yonyou.iuap.baseservice.persistence.mybatis.ext.support.Dialect;
import com.yonyou.iuap.baseservice.persistence.mybatis.ext.utils.EntityUtil;
import com.yonyou.iuap.baseservice.persistence.mybatis.ext.utils.FieldUtil;
import com.yonyou.iuap.baseservice.support.generator.GeneratedValue;
import com.yonyou.iuap.baseservice.support.generator.Strategy;
import org.apache.ibatis.mapping.SqlCommandType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -34,6 +36,7 @@ public SqlCommandType getSQLType() {

@Override
public String parseSQL(Method method, Class<?> entityClazz) {
StringBuilder resultSql = new StringBuilder();
StringBuilder columnSql = new StringBuilder();
StringBuilder valuesSql = new StringBuilder();
boolean isFirst = true;
Expand All @@ -44,9 +47,9 @@ public String parseSQL(Method method, Class<?> entityClazz) {
}
}
if(!isFirst) {
return "<script>\r\n"+new StringBuilder("INSERT INTO ").append(EntityUtil.getTableName(entityClazz))
.append(" (").append(columnSql).append(") \r\nVALUES (")
.append(valuesSql).append(")").toString()+"\r\n</script>";
return "<script>\r\n"+resultSql.append("INSERT INTO ").append(EntityUtil.getTableName(entityClazz))
.append(" <trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\" > ").append(columnSql).append(" </trim> \r\n<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\" > ")
.append(valuesSql).append("</trim>").toString()+"\r\n</script>";
}else {
log.error("无可插入字段:" + method.getName()+";\t"+entityClazz.getName());
throw new MapperException("无可插入字段:" + method.getName()+";\t"+entityClazz.getName());
Expand All @@ -57,17 +60,16 @@ private void build(Field field, StringBuilder columnSql, StringBuilder valuesSql
Column column = field.getAnnotation(Column.class);
columnSql.append("\r\n\t<if test=\""+field.getName()+" != null\">" );
valuesSql.append("\r\n\t<if test=\""+field.getName()+" != null\">" );
if(!isFirst) {
columnSql.append(",");
valuesSql.append(",");
}

if (column==null || StrUtil.isEmpty(column.name())) { //补充内容,比如驼峰规则
columnSql.append(FieldUtil.getColumnName(field));
valuesSql.append(FieldUtil.build4Mybatis(field));
}else {
columnSql.append(column.name());
valuesSql.append(FieldUtil.build4Mybatis(field));
}
columnSql.append(",");
valuesSql.append(",");
columnSql.append("</if>" );
valuesSql.append("</if>" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,19 @@ protected T executeInsert(T entity,boolean isSelective) {
if (isSelective) {
this.genericMapper.insertSelective(entity);
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("id",entity.getId());
if(entity.getId()==null){
queryParams.put("ts",entity.getTs());
}else{
queryParams.put("id",entity.getId());
}
List<T> refreshed = genericMapper.queryList(queryParams);
//insertSelective之后的信息完整化回传
if (refreshed.size()>0){
BeanUtils.copyProperties(refreshed.get(0) , entity);//insertSelective之后的信息完整化回传
if (entity.getId()==null){
BeanUtils.copyProperties(refreshed.get(refreshed.size()-1) , entity);
}else {
BeanUtils.copyProperties(refreshed.get(0) , entity);
}
}
} else
this.genericMapper.insert(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum Strategy {

UUID, //UUID
AUTOINC, //表自增
CUSTOM, //用户自定义
CONFIG; //Properties配置文件

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.yonyou.iuap.baseservice.support.generator.impl;


import com.yonyou.iuap.baseservice.support.generator.Generator;
import com.yonyou.iuap.baseservice.support.generator.Strategy;

import java.io.Serializable;

/**
* 不填充id靠表自增特性自动生成
*
* @author leon
* @date 2019/3/29
*/
public class AutoIncGenerator implements Generator {

@Override
public Strategy strategy() {
return Strategy.AUTOINC;
}

@Override
public String name() {
return "auto";
}

@Override
public Serializable generate(String module, Class<?> entityClazz) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
com.yonyou.iuap.baseservice.support.generator.impl.UUIDGenerator
com.yonyou.iuap.baseservice.support.generator.impl.UUIDGenerator
com.yonyou.iuap.baseservice.support.generator.impl.AutoIncGenerator
1 change: 1 addition & 0 deletions depracated/entity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<groupId>com.yonyou.iuap.baseservice</groupId>
<artifactId>iuap-pap-baseservice-entity</artifactId>
<version>3.5.6-RC1</version>
<name>iuap-pap-baseservice-entity</name>
<url>http://maven.apache.org</url>
<description>实体层能力强化框架,提供实体基本能力(乐观锁、审计日志、逻辑删除等)规范,以及构建数据库查询能力的数据模型映射注解。已移至core工程</description>
Expand Down
1 change: 1 addition & 0 deletions depracated/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<groupId>com.yonyou.iuap.baseservice</groupId>
<artifactId>iuap-pap-baseservice-service</artifactId>
<version>3.5.6-RC1</version>
<name>iuap-pap-baseservice-service</name>
<url>http://maven.apache.org</url>
<description>服务层封装框架,提供了多种CRUD能力的扩展和封装,并在此层实现了实体层的基本能力规范,代码已移至core包中</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
<id>rc</id>
<!-- 本模式开关控制 默认关闭false-->
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<finalName>${project.artifactId}-${project.version}-RC${timestamp}</finalName>
Expand Down

0 comments on commit 33ec6b8

Please sign in to comment.