main
黄海 9 months ago
parent 4f76958cc9
commit c4fe061b80

@ -20,6 +20,7 @@ import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
import io.github.yedaxia.apidocs.ApiDoc;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.io.File;
@ -124,7 +125,7 @@ public class DataEaseController extends Controller {
// identity_id=1 省
// identity_id=2 市
// identity_id=3 县
List<Record> list = dm.getDataSetByIdentityId(identity_id,area_name);
List<Record> list = dm.getDataSetByIdentityId(identity_id, area_name);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
@ -253,4 +254,50 @@ public class DataEaseController extends Controller {
kv.set("message", "上传成功");
renderJson(kv);
}
/**
*
*
* @param dataset_id id
*/
@Before(GET.class)
@IsLoginInterface({})
@IsNumericInterface({"dataset_id"})
public void getDataSet(int dataset_id) {
List<Record> list = dm.getDataSet(dataset_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param dataset_id id
* @param data
*/
@Before(POST.class)
@IsLoginInterface({})
public void saveDataSet(int dataset_id, String data) {
//登录的人员
int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id"));
String person_id = CookieUtil.getValue(getRequest(), "person_id");
//获取他是哪个城市或者县区的管理员
//行政区划码
String area_code = rm.getAreaCode(identity_id, person_id);
//根据区域码,获取区域名称
String area_name = rm.getAreaName(area_code);
//父亲的区域名称
String parent_area_name = rm.getParentAreaName(area_name);
JSONArray jsonArray = JSONArray.fromObject(data);
for (Object o : jsonArray) {
JSONObject jo = (JSONObject) o;
jo.put("行政区划", area_name);
jo.put("上级行政区划", parent_area_name);
}
//保存
dm.saveDataSet(identity_id, dataset_id, area_name, jsonArray);
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
}
}

@ -7,6 +7,7 @@ import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
@ -39,7 +40,7 @@ public class DataEaseModel {
String table_name = record.getStr("table_name");
sql = "select count(1) as c from `" + table_name + "`";
if (identity_id > 1) {
sql += " where `行政区划`='" + area_name + "'";
sql += " where `行政区划`='" + area_name + "'";
}
int cnt = Db.use(DB_NAME).queryInt(sql);
record.set("fill_count", cnt);
@ -560,4 +561,43 @@ public class DataEaseModel {
String sql = "select * from ds_db.t_dm_area where province_id=? and level_id=5";
return Db.find(sql, provinceId);
}
/**
*
*
* @param dataset_id id
* @return
*/
public List<Record> getDataSet(int dataset_id) {
String tableName = getTableName(dataset_id);
String sql = "select * from `" + tableName + "`";
return Db.use(DB_NAME).find(sql);
}
/**
*
*
* @param dataset_id id
* @param ja json
*/
public void saveDataSet(int identity_id, int dataset_id, String area_name, JSONArray ja) {
String tableName = getTableName(dataset_id);
String sql = "delete from `" + tableName + "` where `行政区划`=?";
Db.use(DB_NAME).update(sql);
List<Record> list = new ArrayList<>();
for (int i = 0; i < ja.size(); i++) {
JSONObject jsonObject = ja.getJSONObject(i);
//遍历jo的每一个属性
// 或者使用keySet和for-each循环遍历
Record record = new Record();
for (Object key : jsonObject.keySet()) {
Object value = jsonObject.get(key);
if (value.equals("null")) value = null;
record.set(key.toString(), value);
}
list.add(record);
}
Db.use(DB_NAME).batchSave(tableName, list, 100);
}
}

Loading…
Cancel
Save