Commit 0de5a647 by 宋祥

1.工具类增加,批量新增

parent 99e0b22f
...@@ -12,7 +12,9 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -12,7 +12,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -59,6 +61,37 @@ public class DaoUtils { ...@@ -59,6 +61,37 @@ public class DaoUtils {
} }
/** /**
* insertBatch method.
*
* @param sql
* @param rows
*/
public static void batchInsert(String sql, List rows) {
// 创建人部门
List<String> orgIds = UserSessionUtils.getOrgId();
AssertUtils.isEmpty(orgIds, "当前用户未绑定部门,无法操作数据,请联系管理员!");
String depCode = orgIds.get(0);
for (Object row : rows) {
if (row instanceof DaoEPBase) {
DaoEPBase daoEPBase = (DaoEPBase) row;
try {
BeanUtils.setProperty(daoEPBase, "depCode", depCode);
} catch (Exception e) {
log.warn("写入创建人部门编码失败", e);
}
setCreator(daoEPBase);
} else if (row instanceof Map) {
Map map = (Map) row;
map.put("depCode", depCode);
setCreator(map);
}
}
Map paramMap = new HashMap();
paramMap.put("rows", rows);
DaoBase.getInstance().insert(sql, paramMap);
}
/**
* update method. * update method.
* *
* @param sql * @param sql
......
...@@ -124,11 +124,12 @@ public class ServiceXS3201B extends ServiceEPBase { ...@@ -124,11 +124,12 @@ public class ServiceXS3201B extends ServiceEPBase {
dbMainAuth.put("subjectId", groupId); dbMainAuth.put("subjectId", groupId);
dbMainAuth.put("recCreator", UserSessionUtils.getLoginName()); dbMainAuth.put("recCreator", UserSessionUtils.getLoginName());
dbMainAuth.put("recCreateTime", DateUtils.shortDateTime()); dbMainAuth.put("recCreateTime", DateUtils.shortDateTime());
dbMainAuth.put("archiveFlag", 0);
dbMainAuth.put("sortIndex", 0); dbMainAuth.put("sortIndex", 0);
return dbMainAuth; return dbMainAuth;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(filterAuths)) { if (CollectionUtils.isNotEmpty(filterAuths)) {
DaoUtils.insertBatch("XS07.insert", filterAuths); DaoUtils.batchInsert("XS07.batchInsert", filterAuths);
} }
} }
} }
......
...@@ -30,6 +30,18 @@ ...@@ -30,6 +30,18 @@
) )
</insert> </insert>
<insert id="batchInsert">
INSERT INTO ${platSchema}.XS_AUTHORIZATION (
SUBJECT_ID, SUBJECT_TYPE, OBJECT_ID, OBJECT_TYPE, OPERATION_TYPE, REC_CREATOR,
REC_CREATE_TIME, ARCHIVE_FLAG, SORT_INDEX
) VALUES
<iterate open="(" conjunction="), (" close=")" property="rows">
#rows[].subjectId#, #rows[].subjectType#, #rows[].objectId#, #rows[].objectType#,
#rows[].operationType#, #rows[].recCreator#, #rows[].recCreateTime#,
#rows[].archiveFlag#, #rows[].sortIndex#
</iterate>
</insert>
<select id="authorizationExists" resultClass="java.util.HashMap"> <select id="authorizationExists" resultClass="java.util.HashMap">
SELECT * FROM ${platSchema}.XS_AUTHORIZATION SELECT * FROM ${platSchema}.XS_AUTHORIZATION
WHERE 1=1 WHERE 1=1
......
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