@ -13,10 +13,7 @@ import org.springframework.util.StringUtils;
import javax.persistence.EntityManager ;
import javax.persistence.Query ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.StringJoiner ;
import java.util.* ;
/ * *
* @Description : 批 量 新 增 数 据 拼 接
@ -54,7 +51,7 @@ public class MesInsertBatchDaoImpl implements IMesInsertBatchDao {
public void insertMesRecyclablePackageBindingLogLimit ( List < MesRecyclablePackageBindingLog > logList , String organizeCode ) {
String fieldStr = " ` id` ,` create_date_time` ,` create_user` ,` description` ,` is_deleted` ,` is_valid` ,` organize_code` ,` remark` ,` system_sync_date_time` ,` system_sync_status` ,` hanger_code` ,` hanger_package_sn` ,` hanger_rule_code` ,` lot_number` ,` modify_type` ,` order_code` ,` package_sn` ,` part_name` ,` part_no` ,` product_sn` ,` qty` ,` status` ,` total_qty` ,` type_code` ";
String fieldStr = " id,create_date_time,create_user,description,is_deleted,is_valid,organize_code,remark,system_sync_date_time,system_sync_status,hanger_code,hanger_package_sn,hanger_rule_code,lot_number,modify_type,order_code,package_sn,part_name,part_no,product_sn,qty,status,total_qty,type_code";
//拼接字段
StringBuilder fieldBuilder = new StringBuilder ( ) ;
String [ ] splitField = fieldStr . split ( MesPcnExtConstWords . COMMA ) ;
@ -66,11 +63,9 @@ public class MesInsertBatchDaoImpl implements IMesInsertBatchDao {
if ( ! StringUtils . isEmpty ( mesShardingAppendOrg ) & & mesShardingAppendOrg . toUpperCase ( ) . equals ( CommonEnumUtil . TRUE_OR_FALSE . TRUE . name ( ) ) ) insertStr . append ( MesPcnExtConstWords . E_UNDERLINE ) . append ( organizeCode . toLowerCase ( ) ) ;
insertStr . append ( "(" ) . append ( fieldStr ) . append ( ") VALUES( " ) ;
//sql组装
Map < String , Object > parameterMap = new HashMap < > ( ) ;
StringBuilder builder = new StringBuilder ( ) ;
for ( int i = MesPcnExtConstWords . ZERO ; i < logList . size ( ) ; i + + ) {
Map < String , Object > parameterMap = new LinkedHashMap < > ( ) ;
int j = MesPcnExtConstWords . ZERO ;
builder . append ( insertStr ) . append ( fieldBuilder . substring ( MesPcnExtConstWords . ZERO , fieldBuilder . lastIndexOf ( MesPcnExtConstWords . COMMA ) - MesPcnExtConstWords . ONE ) . replaceAll ( "%s" , String . valueOf ( i ) ) ) . append ( " ); " ) ;
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j + + ] ) . add ( String . valueOf ( i ) ) . toString ( ) , snowflakeIdMaker . nextId ( ) ) ;
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j + + ] ) . add ( String . valueOf ( i ) ) . toString ( ) , logList . get ( i ) . getCreateDatetime ( ) ) ;
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j + + ] ) . add ( String . valueOf ( i ) ) . toString ( ) , logList . get ( i ) . getCreateUser ( ) ) ;
@ -95,12 +90,12 @@ public class MesInsertBatchDaoImpl implements IMesInsertBatchDao {
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j + + ] ) . add ( String . valueOf ( i ) ) . toString ( ) , logList . get ( i ) . getStatus ( ) ) ;
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j + + ] ) . add ( String . valueOf ( i ) ) . toString ( ) , logList . get ( i ) . getTotalQty ( ) ) ;
parameterMap . put ( new StringJoiner ( MesPcnExtConstWords . E_UNDERLINE ) . add ( splitField [ j ] ) . add ( String . valueOf ( i ) ) . toString ( ) , logList . get ( i ) . getTypeCode ( ) ) ;
Query queryObject = entityManager . createNativeQuery ( insertStr + fieldBuilder . substring ( MesPcnExtConstWords . ZERO , fieldBuilder . lastIndexOf ( MesPcnExtConstWords . COMMA ) - MesPcnExtConstWords . ONE ) . replaceAll ( "%s" , String . valueOf ( i ) ) + " ); " ) ;
//数据填充
for ( String key : parameterMap . keySet ( ) ) {
queryObject . setParameter ( key , parameterMap . get ( key ) ) ;
}
queryObject . executeUpdate ( ) ;
}
Query queryObject = entityManager . createNativeQuery ( builder . toString ( ) ) ;
//数据填充
for ( String key : parameterMap . keySet ( ) ) {
queryObject . setParameter ( key , parameterMap . get ( key ) ) ;
}
queryObject . executeUpdate ( ) ;
}
}