|
@@ -1,6 +1,7 @@
|
|
|
package com.xc.luckysheet.db.server;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -34,8 +35,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -57,6 +60,9 @@ public class JfGridUpdateService {
|
|
|
@Resource(name = "postgresRecordSelectHandle")
|
|
|
private IRecordSelectHandle recordSelectHandle;
|
|
|
|
|
|
+ @Value("${file.writeRootPath}")
|
|
|
+ private String writeRootPath;
|
|
|
+
|
|
|
// @Resource(name = "mysqlRecordDataInsertHandle")
|
|
|
// private IRecordDataInsertHandle recordDataInsertHandle;
|
|
|
//
|
|
@@ -119,40 +125,54 @@ public class JfGridUpdateService {
|
|
|
*/
|
|
|
@Transactional(value = "postgresTxManager",rollbackFor = Exception.class)
|
|
|
public void saveSheet(SaveSheetRequest req) {
|
|
|
-
|
|
|
//删除历史
|
|
|
- List<String> mongodbKeys = new ArrayList<String>();//mongodb的key,用于删除
|
|
|
- recordSelectHandle.getBlockMergeByGridKey(req.getListId(), req.getIndex(), mongodbKeys);
|
|
|
- recordDelHandle.delDocuments(mongodbKeys);
|
|
|
-
|
|
|
- List<JSONObject> blocks = JfGridConfigModel.toDataSplit(req.getRowSize(), req.getColSize(), req.getSheet());
|
|
|
- List<GridRecordDataModel> list = new ArrayList<>(blocks.size());
|
|
|
- for(JSONObject block : blocks) {
|
|
|
- GridRecordDataModel model = new GridRecordDataModel();
|
|
|
-
|
|
|
- model.setBlock_id(block.getString("block_id").trim());
|
|
|
- model.setRow_col(null);
|
|
|
- model.setIndex(block.getString("index").trim());
|
|
|
- model.setList_id(req.getListId());
|
|
|
- model.setIs_delete(0);
|
|
|
-
|
|
|
- if(block.containsKey("status") && block.get("status")!=null){
|
|
|
- model.setStatus(block.getInteger("status"));
|
|
|
- }else{
|
|
|
- model.setStatus(0);
|
|
|
- }
|
|
|
-
|
|
|
- if(block.containsKey("order") && block.get("order")!=null){
|
|
|
- model.setOrder(block.getInteger("order"));
|
|
|
- }else{
|
|
|
- model.setOrder(null);
|
|
|
- }
|
|
|
- model.setJson_data(block);
|
|
|
-
|
|
|
- list.add(model);
|
|
|
- }
|
|
|
-
|
|
|
- recordDataInsertHandle.InsertIntoBatch(list);
|
|
|
+// List<String> mongodbKeys = new ArrayList<String>();//mongodb的key,用于删除
|
|
|
+// recordSelectHandle.getBlockMergeByGridKey(req.getListId(), req.getIndex(), mongodbKeys);
|
|
|
+// if(mongodbKeys.size() > 0) {
|
|
|
+// recordDelHandle.delDocuments(mongodbKeys);
|
|
|
+// }
|
|
|
+// List<String> listIdList = new ArrayList<>();
|
|
|
+// listIdList.add(req.getListId());
|
|
|
+// recordDelHandle.delete(listIdList);
|
|
|
+
|
|
|
+ //保存至文件
|
|
|
+ String fileName = req.getListId().concat(".json");
|
|
|
+ FileUtil.writeUtf8String(req.getSheet().toString(SerializerFeature.WriteMapNullValue),
|
|
|
+ writeRootPath.concat(File.separator).concat(fileName));
|
|
|
+
|
|
|
+
|
|
|
+// final List<String> idList = recordSelectHandle.getIdList(req.getListId(), req.getIndex());
|
|
|
+//
|
|
|
+// List<JSONObject> blocks = JfGridConfigModel.toDataSplit(req.getRowSize(), req.getColSize(), req.getSheet());
|
|
|
+// List<GridRecordDataModel> list = new ArrayList<>(blocks.size());
|
|
|
+// for(JSONObject block : blocks) {
|
|
|
+// GridRecordDataModel model = new GridRecordDataModel();
|
|
|
+//
|
|
|
+// model.setBlock_id(block.getString("block_id").trim());
|
|
|
+// model.setRow_col(null);
|
|
|
+// model.setIndex(block.getString("index").trim());
|
|
|
+// model.setList_id(req.getListId());
|
|
|
+// model.setIs_delete(0);
|
|
|
+//
|
|
|
+// if(block.containsKey("status") && block.get("status")!=null){
|
|
|
+// model.setStatus(block.getInteger("status"));
|
|
|
+// }else{
|
|
|
+// model.setStatus(0);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(block.containsKey("order") && block.get("order")!=null){
|
|
|
+// model.setOrder(block.getInteger("order"));
|
|
|
+// }else{
|
|
|
+// model.setOrder(null);
|
|
|
+// }
|
|
|
+// model.setJson_data(block);
|
|
|
+//
|
|
|
+// list.add(model);
|
|
|
+// }
|
|
|
+// recordDataInsertHandle.InsertIntoBatch(list);
|
|
|
+//
|
|
|
+// //删除历史
|
|
|
+// recordDelHandle.delDocuments(idList);
|
|
|
}
|
|
|
|
|
|
/**
|