main
黄海 9 months ago
parent e56b76f78a
commit 3e450d29e5

@ -14,7 +14,9 @@ import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
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;
@ -25,7 +27,6 @@ import java.util.List;
public class DataEaseController extends Controller {
DataEaseModel dm = new DataEaseModel();
ResourceModel rm = new ResourceModel();
BaseModel bm = new BaseModel();
String tempDir = System.getProperty("java.io.tmpdir");
// http://10.10.21.20:9000/dsBase/dataease/route?city_name=昆明市
// http://10.10.21.20:9000/dsBase/dataease/route?city_name=楚雄彝族自治州
@ -33,13 +34,13 @@ public class DataEaseController extends Controller {
// !!!必须发布后访问才能做到进入此接口,否则浏览器就走缓存,不进来这个接口了!!!
/**
*
*
*
* @param city_name
*/
@Before({GET.class})
@EmptyInterface({"city_name"})
public void route(String city_name) {
public void routeMap(String city_name) {
//大屏名称
String dataVisualizationName = BaseApplication.PropKit.get("dataEase.dataVisualizationName");
//发布的地址
@ -55,6 +56,40 @@ public class DataEaseController extends Controller {
redirect(publish_url + "/#/de-link/zud8IQ8J?attachParams=" + base64Str);
}
/**
*
*
* @param type_id
* @param area_name
*/
@Before({GET.class})
@EmptyInterface({"area_name"})
@IsNumericInterface({"type_id"})
public void route(int type_id, String area_name) {
//发布的地址
String publish_url = BaseApplication.PropKit.get("dataEase.publish_url");
//拼接一下URL的最终地址
JSONObject jo = new JSONObject();
jo.put("area_name", area_name);
String base64Str = Base64.encode(jo.toString());
switch (type_id) {
case 1:
publish_url = publish_url + "/#/de-link/zud8IQ8J";
break;
case 2:
publish_url = publish_url + "/#/de-link/zud8IQ8J";
break;
case 3:
publish_url = publish_url + "/#/de-link/zud8IQ8J";
break;
case 4:
publish_url = publish_url + "/#/de-link/zud8IQ8J";
break;
}
//跳转
redirect(publish_url + "?attachParams=" + base64Str);
}
/**
* identity_id,
*/
@ -70,57 +105,6 @@ public class DataEaseController extends Controller {
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param dataset_id id
*/
@Before(GET.class)
@IsLoginInterface({})
@IsNumericInterface({"dataset_id"})
public void getDataSetTable(int dataset_id) {
List<Record> list = dm.getDataSetTableContent(dataset_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param dataset_id id
* @param data
*/
@Before(POST.class)
@IsLoginInterface({})
public void saveDataSetTable(int dataset_id, String data) {
//登录的人员
int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id"));
String person_id = CookieUtil.getValue(getRequest(), "person_id");
//如果是市/州,名称
//如果是县区,名称
String xmqh = bm.getPersonInfo(person_id).getStr("person_name").replace("管理员", "");
JSONArray jsonArray = JSONArray.fromObject(data);
for (Object o : jsonArray) {
net.sf.json.JSONObject jo = (net.sf.json.JSONObject) o;
if (identity_id > 1 && jo.containsKey("行政区划") && !jo.getString("行政区划").equals(xmqh)) {
renderJson(CommonUtil.returnMessageJson(false, "数据集数据与当前登录人员所属行政区划不一致,请重新选择数据集!"));
return;
}
}
if (identity_id > 1) {
for (Object o : jsonArray) {
net.sf.json.JSONObject jo = (net.sf.json.JSONObject) o;
if (!jo.containsKey("行政区划")) {
renderJson(CommonUtil.returnMessageJson(false, "数据集数据不是省级管理员操作,但却没有行政区划的字段!"));
return;
}
break;
}
}
//保存
dm.saveDataSetTable(identity_id, dataset_id, xmqh, jsonArray);
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
}
/**
* Excel
*
@ -181,12 +165,39 @@ public class DataEaseController extends Controller {
/**
* Excel
* @param id id
*/
@Before(POST.class)
@IsLoginInterface({})
public void uploadExcel(int id) {
public void uploadExcel() {
//根据当前登录人员的身份,获取对应的数据集名称
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);
}
//上传的文件
UploadFile uploadFile = getFile("file", tempDir);
//数据集id
int id = getParaToInt("id");
//文件是不是以.xlsx为扩展名
if (!uploadFile.getFileName().endsWith(".xlsx")) {
renderJson(CommonUtil.returnMessageJson(false, "文件格式不正确,请上传.xlsx格式的文件"));
return;
}
//检查上传的excel获取它有哪些列与数据集的列是否一致
List<String> cols = dm.getColumnNamesFromExcel(uploadFile.getFile().getAbsolutePath());
//获取指定数据集有哪些列
//如果一致,那么需要先把数据集的指定行政区划列的表清空,再导入数据
//返回结果
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "上传成功");
renderJson(kv);
}
}

@ -8,8 +8,14 @@ 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;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -358,4 +364,28 @@ public class DataEaseModel {
ExcelCommonUtil.writeExcel(tableData, filePath, true);
return excelFileName;
}
/**
* Excel
* @param filePath
* @return
*/
public static List<String> getColumnNamesFromExcel(String filePath) {
List<String> columnNames = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(new File(filePath));
Workbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheetAt(0); // 读取第一个工作表
Row firstRow = sheet.getRow(0); // 假设第一行包含列名
if (firstRow != null) {
for (Cell cell : firstRow) {
columnNames.add(cell.getStringCellValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return columnNames;
}
}

Loading…
Cancel
Save