main
黄海 2 years ago
parent e2105eb68c
commit 59cf2419d0

@ -1,5 +1,7 @@
package com.dsideal.QingLong.Collect.Controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Collect.Model.CollectModel;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
@ -146,8 +148,46 @@ public class CollectController extends Controller {
*/
@Before({POST.class})
@IsLoginInterface({})
public void saveSheet() {
public void saveSheet(String json) {
JSONArray ja;
try {
ja = JSONArray.parseArray(json);
} catch (Exception err) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "上报的json数据格式不正确请检查后重传");
renderJson(kv);
return;
}
//遍历每行数据根据data_type_id+ t_collect_datatype 表 ,修改 pg_data_type,web_data_type,excel_data_type三个属性
//然后再保存
List<Record> writeList = new ArrayList<>();
for (Object o : ja) {
JSONObject jo = (JSONObject) o;
int job_id = jo.getInteger("job_id");
int sheet_index = jo.getInteger("sheet_index");
int column_index = jo.getInteger("column_index");
int data_type_id = jo.getInteger("data_type_id");
String column_name = jo.getString("column_name");
String original_name = jo.getString("original_name");
boolean allow_blank = jo.getBoolean("allow_blank");
String options = jo.getString("options");
Record record = new Record();
record.set("job_id", job_id);
record.set("sheet_index", sheet_index);
record.set("column_index", column_index);
record.set("data_type_id", data_type_id);
record.set("column_name", column_name);
record.set("original_name", original_name);
record.set("allow_blank", allow_blank);
record.set("options", options);
writeList.add(record);
}
cm.saveSheet(writeList);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**

@ -89,9 +89,6 @@ public class CollectModel {
writeRecord.set("column_index", colIdx);
writeRecord.set("column_name", column_name);
writeRecord.set("original_name", memo);
writeRecord.set("pg_data_type", "varchar(2048)");
writeRecord.set("web_data_type", "文本");
writeRecord.set("excel_data_type", "String");
writeRecord.set("data_type_id", 1);
writeRecord.set("allow_blank", true);
writeRecord.set("options", "");
@ -137,5 +134,18 @@ public class CollectModel {
return Db.find(sql, job_id, sheet_index);
}
/**
* Sheet
*
* @param writeList
*/
public void saveSheet(List<Record> writeList) {
if (writeList.size() == 0) return;
int job_id = writeList.get(0).getInt("job_id");
int sheet_index = writeList.get(0).getInt("sheet_index");
String sql = "delete from t_collect_job_sheet_col where job_id=? and sheet_index=?";
Db.update(sql, job_id, sheet_index);
Db.batchSave("t_collect_job_sheet_col", writeList, 100);
}
}
Loading…
Cancel
Save