|
|
@ -81,7 +81,7 @@ public class ExlTableDataController { |
|
|
|
columnLqw.orderByAsc(ExlColumnConf::getSort); |
|
|
|
List<ExlColumnConf> columnList = exlColumnConfService.list(columnLqw); |
|
|
|
// query
|
|
|
|
boolean adminFlag = false; |
|
|
|
boolean adminFlag = exlTableUserService.checkAdmin(tableConf.getId(), AuthContextUtils.getSysUserId())>0; |
|
|
|
Map<String, Object> queryMap = buildQueryMap(map, columnList,adminFlag); |
|
|
|
String targetTableName = ExlConst.TABLE_NAME_PRE + tableConf.getTableName(); |
|
|
|
Long count = exlTableConfMapper.countData(targetTableName,queryMap); |
|
|
@ -254,6 +254,7 @@ public class ExlTableDataController { |
|
|
|
*/ |
|
|
|
@PostMapping("/batchSave") |
|
|
|
public R<?> batchSave( @RequestBody ExlBatchSaveBo saveBo){ |
|
|
|
final String ErrMsgKey = "errMsg"; |
|
|
|
List<Object> param = saveBo.getParam(); |
|
|
|
String tableConfigId = saveBo.getTb_config_cnf_id(); |
|
|
|
// table
|
|
|
@ -265,23 +266,9 @@ public class ExlTableDataController { |
|
|
|
List<ExlColumnConf> columnList = exlColumnConfService.list(columnLqw); |
|
|
|
|
|
|
|
String targetTableName = ExlConst.TABLE_NAME_PRE + tableConf.getTableName(); |
|
|
|
//移除旧历史
|
|
|
|
boolean executeFlag = true; |
|
|
|
//移除旧历史判断参数
|
|
|
|
int keyCount = (int) columnList.stream().filter(a -> a.getKeyFlag().equals(1)).count(); |
|
|
|
if(keyCount>0){ |
|
|
|
StringBuilder removeSql = new StringBuilder("delete from "+targetTableName+" where union_row_id in ("); |
|
|
|
for (int k = 0;k < param.size(); k++) { |
|
|
|
Object obj = param.get(k); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JsonUtil.objectToJson(obj)); |
|
|
|
String unionId = TableCreateSqlUtil.buildUnionId(columnList,jsonObject); |
|
|
|
removeSql.append("'"+unionId+"'"); |
|
|
|
if(k+1<param.size()){ |
|
|
|
removeSql.append(","); |
|
|
|
} |
|
|
|
} |
|
|
|
removeSql.append(");"); |
|
|
|
QsSqlSessionUtil.executeSql(removeSql.toString(),sqlSessionTemplate); |
|
|
|
} |
|
|
|
|
|
|
|
//insert into table (cloumns) values (vals),(vals)
|
|
|
|
StringBuilder insertSql = new StringBuilder("insert into "+targetTableName +"( `union_row_id`,"); |
|
|
|
for (int i = 0; i < columnList.size(); i++) { |
|
|
@ -299,6 +286,7 @@ public class ExlTableDataController { |
|
|
|
} |
|
|
|
} |
|
|
|
insertSql.append(")values"); |
|
|
|
List<JSONObject> errorResult = new ArrayList<>(); |
|
|
|
for (int k = 0; k < param.size(); k++) { |
|
|
|
Object obj = param.get(k); |
|
|
|
insertSql.append("("); |
|
|
@ -311,39 +299,96 @@ public class ExlTableDataController { |
|
|
|
for (int i = 0; i < columnList.size(); i++) { |
|
|
|
ExlColumnConf columnConf = columnList.get(i); |
|
|
|
String string = jsonObject.getString(columnConf.getColumnName()); |
|
|
|
if(string==null|| "null".equals(string)){ |
|
|
|
string = ""; |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(string) && columnConf.getNotNullFlag().equals(1)){ |
|
|
|
executeFlag = false; |
|
|
|
this.appendErrorMsg(ErrMsgKey, jsonObject, columnConf); |
|
|
|
continue; |
|
|
|
} |
|
|
|
insertSql.append("'"+string+"'"); |
|
|
|
if(columnConf.getColumnType().equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(SysUser::getCode,string); |
|
|
|
lqw.select(SysUser::getCode,SysUser::getName); |
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectList(lqw); |
|
|
|
if (sysUsers.size()>0){ |
|
|
|
String name = sysUsers.get(0).getName(); |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
String name = ""; |
|
|
|
if(string.length()>0){ |
|
|
|
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(SysUser::getCode,string); |
|
|
|
lqw.select(SysUser::getCode,SysUser::getName); |
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectList(lqw); |
|
|
|
if (sysUsers.size()>0){ |
|
|
|
name = sysUsers.get(0).getName(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(name) && columnConf.getScope()>0){ |
|
|
|
executeFlag = false; |
|
|
|
this.appendErrorMsg(ErrMsgKey, jsonObject, columnConf); |
|
|
|
continue; |
|
|
|
} |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
}else if(columnConf.getColumnType().equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(BmsSupplier::getCode,string); |
|
|
|
lqw.select(BmsSupplier::getCode,BmsSupplier::getName); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(lqw); |
|
|
|
if (supplierList.size()>0){ |
|
|
|
String name = supplierList.get(0).getName(); |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
String name = ""; |
|
|
|
if(string.length()>0){ |
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(BmsSupplier::getCode,string); |
|
|
|
lqw.select(BmsSupplier::getCode,BmsSupplier::getName); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(lqw); |
|
|
|
if (supplierList.size()>0){ |
|
|
|
name = supplierList.get(0).getName(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(name) && columnConf.getScope()>0){ |
|
|
|
executeFlag = false; |
|
|
|
this.appendErrorMsg(ErrMsgKey, jsonObject, columnConf); |
|
|
|
continue; |
|
|
|
} |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
} |
|
|
|
if(i+1<columnList.size()){ |
|
|
|
insertSql.append(", "); |
|
|
|
} |
|
|
|
} |
|
|
|
//添加错误信息
|
|
|
|
errorResult.add(jsonObject); |
|
|
|
insertSql.append(")"); |
|
|
|
if(k+1<param.size()){ |
|
|
|
insertSql.append(", "); |
|
|
|
} |
|
|
|
} |
|
|
|
QsSqlSessionUtil.executeSql(insertSql.toString(),sqlSessionTemplate); |
|
|
|
return R.ok(); |
|
|
|
|
|
|
|
//移除旧历史
|
|
|
|
if(executeFlag){ |
|
|
|
if(keyCount>0){ |
|
|
|
StringBuilder removeSql = new StringBuilder("delete from "+targetTableName+" where union_row_id in ("); |
|
|
|
for (int k = 0;k < param.size(); k++) { |
|
|
|
Object obj = param.get(k); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JsonUtil.objectToJson(obj)); |
|
|
|
String unionId = TableCreateSqlUtil.buildUnionId(columnList,jsonObject); |
|
|
|
removeSql.append("'"+unionId+"'"); |
|
|
|
if(k+1<param.size()){ |
|
|
|
removeSql.append(","); |
|
|
|
} |
|
|
|
} |
|
|
|
removeSql.append(");"); |
|
|
|
QsSqlSessionUtil.executeSql(removeSql.toString(),sqlSessionTemplate); |
|
|
|
} |
|
|
|
//执行批量保存
|
|
|
|
QsSqlSessionUtil.executeSql(insertSql.toString(),sqlSessionTemplate); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
Map<String,Object> objectMap = new HashMap<>(); |
|
|
|
objectMap.put("columnList",columnList); |
|
|
|
objectMap.put("data",errorResult); |
|
|
|
return R.error("数据异常",objectMap); |
|
|
|
} |
|
|
|
|
|
|
|
private void appendErrorMsg(String ErrMsgKey, JSONObject jsonObject, ExlColumnConf columnConf) { |
|
|
|
String tmp = jsonObject.getString(ErrMsgKey); |
|
|
|
if(tmp==null){ |
|
|
|
tmp = ""; |
|
|
|
} |
|
|
|
jsonObject.put(ErrMsgKey,tmp+ columnConf.getColumnHeader()+"数据无效或为空;"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|