|
|
@@ -5,11 +5,17 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -22,8 +28,11 @@ public class IBPSRepository {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(IBPSRepository.class);
|
|
|
|
|
|
- @Value("${config.insertMode}")
|
|
|
- private String insertMode;
|
|
|
+ @Value("${config.qryMode}")
|
|
|
+ private String qryMode;
|
|
|
+
|
|
|
+ public static List<Map<String, Object>> userList = new ArrayList<>();
|
|
|
+ public static List<Map<String, Object>> posiList = new ArrayList<>();
|
|
|
|
|
|
public List<Map<String, Object>> qryExistData(){
|
|
|
List<Map<String, Object>> existList = null;
|
|
|
@@ -33,11 +42,110 @@ public class IBPSRepository {
|
|
|
return existList;
|
|
|
}
|
|
|
|
|
|
- public String getUserInfoByName(String UserName){
|
|
|
|
|
|
- return "";
|
|
|
+ public String saveToTable(List<Map<String, Object>> inputList, String TableName) {
|
|
|
+ String retValue = "fail";
|
|
|
+ if (inputList == null || inputList.isEmpty() || TableName == null || TableName.trim().isEmpty()) {
|
|
|
+ return retValue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 获取第一个Map的字段名作为表字段
|
|
|
+ Map<String, Object> firstRow = inputList.get(0);
|
|
|
+ String columns = String.join(",", firstRow.keySet());
|
|
|
+
|
|
|
+ // 构建占位符部分 (?,?,...)
|
|
|
+ String placeholders = String.join(",", Collections.nCopies(firstRow.size(), "?"));
|
|
|
+
|
|
|
+ // 构建完整SQL语句
|
|
|
+ String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", TableName, columns, placeholders);
|
|
|
+ log.info("executing sql: " + sql);
|
|
|
+ if(qryMode.equals("0")){
|
|
|
+ log.info("ready to insert:");
|
|
|
+ // 批量执行
|
|
|
+ jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
|
|
+ @Override
|
|
|
+ public void setValues(PreparedStatement ps, int i) throws SQLException {
|
|
|
+ Map<String, Object> row = inputList.get(i);
|
|
|
+ int index = 1;
|
|
|
+ for (Map.Entry<String, Object> entry : row.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+
|
|
|
+ if (key.contains("Time") && value instanceof Timestamp) {
|
|
|
+ ps.setTimestamp(index++, (Timestamp) value);
|
|
|
+ } else {
|
|
|
+ ps.setString(index++, value.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public int getBatchSize() {
|
|
|
+ return inputList.size();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ log.info("------qry mode,pretent to insert-------");
|
|
|
+ inputList.forEach(map -> {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ map.forEach((k, v) -> sb.append(k).append(":").append(v).append(","));
|
|
|
+ if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
|
|
|
+ log.info(sb.toString());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ retValue = "success";
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "insert failed:"+e.getMessage().split(";")[2];
|
|
|
+ }
|
|
|
+ return retValue;
|
|
|
}
|
|
|
|
|
|
- public void getBasicData(){}
|
|
|
+ /**
|
|
|
+ * 获取基础数据:
|
|
|
+ * LIS系统用户名对应金通用户信息
|
|
|
+ */
|
|
|
+ public void getBasicData(){
|
|
|
+ String sqlUser = "select id_,name_,positions_ from ibps_party_employee where status_='actived'";
|
|
|
+ userList = jdbcTemplate.queryForList(sqlUser);
|
|
|
+ String sqlPosi = "select * from ibps_party_position";
|
|
|
+ posiList = jdbcTemplate.queryForList(sqlPosi);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回用户ID@部门ID@部门名称
|
|
|
+ * @param userName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getUserInfoByName(String userName){
|
|
|
+ String retVal = "-1";
|
|
|
+ for (Map<String, Object> map : userList) {
|
|
|
+ if (map.get("name_").toString().equals(userName)) {
|
|
|
+ String userId = (String) map.get("id_");
|
|
|
+ String positionId = String.valueOf(map.get("positions_")).split(",")[0];
|
|
|
+ String positionName = (String) getPosiByID(positionId);
|
|
|
+ if (!positionName.equals("-1")) {
|
|
|
+ retVal = userId+"@"+positionId+"@"+positionName;
|
|
|
+ }else{
|
|
|
+ retVal = "-1^部门:"+positionName+"未找到!";
|
|
|
+ return retVal;
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
+ }
|
|
|
+ retVal = "-1^用户:"+userName+"未找到!";
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPosiByID(String positionId){
|
|
|
+ String retVal = "-1";
|
|
|
+ for (Map<String, Object> map : posiList) {
|
|
|
+ if (map.get("id_").toString().equals(positionId)) {
|
|
|
+ retVal = map.get("name_").toString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
+ }
|
|
|
|
|
|
}
|