main
黄海 1 year ago
parent 707cb335a2
commit 4874ce5227

@ -1,6 +1,7 @@
package com.dsideal.QingLong.Zbdc.Model;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
@ -521,6 +522,22 @@ public class ZbdcModel {
return Db.find(sql, bureau_id, year);
}
/**
*
*
* @param table_name
* @return
*/
public Map<String, String> getDataType(String table_name) {
String sql = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = ?";
List<Record> list = Db.find(sql, table_name);
Map<String, String> _map = new HashMap<>();
for (Record record : list) {
_map.put(record.getStr("column_name"), record.getStr("data_type"));
}
return _map;
}
/**
*
*
@ -532,6 +549,8 @@ public class ZbdcModel {
public void saveXxzbdc(int dcb_id, int id, int year, String bureau_id, String json) {
//哪些物理表
String table_name = getXxzbdcTableName(dcb_id);
//字段名与数据类型的对应关系
Map<String, String> _map = getDataType(table_name);
Record record = new Record();
if (id > 0) {//修改
@ -543,12 +562,21 @@ public class ZbdcModel {
}
//解析json里面的字段名称和值对record进行填充
JSONObject jsonObject = JSONObject.parseObject(json);
// 将JSONObject转换为Map然后遍历键值对
Map<String, Object> map = jsonObject;
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
if (!_map.containsKey(key)) continue;
Object value = entry.getValue();
if (_map.get(key).equals("integer")) {
record.set(key, Integer.parseInt(value.toString()));
} else if (_map.get(key).equals("character varying")) {
record.set(key, value.toString());
} else if (_map.get(key).equals("date")) {
record.set(key, DateUtil.parse(value.toString(), "yyyy-MM-dd"));
} else if (_map.get(key).equals("real")) {
record.set(key, Double.parseDouble(value.toString()));
}
record.set(key, value);
}
if (id > 0) {

Loading…
Cancel
Save