|
@@ -37,6 +37,7 @@ import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
@@ -57,6 +58,7 @@ import org.springblade.manager.vo.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -649,10 +651,17 @@ public class WbsTreeContractController extends BladeController {
|
|
|
@ApiOperationSupport(order = 14)
|
|
|
@ApiOperation(value = "客户端-导入excel数据到对应元素表中(批量)", notes = "传入表的pKeyId、excel文件file")
|
|
|
public R<Map<String, Object>> importExcelList(@RequestParam Long pKeyId,
|
|
|
- @RequestParam Integer classify,
|
|
|
- @RequestParam Integer number,
|
|
|
- @RequestPart MultipartFile file){
|
|
|
+ @RequestPart MultipartFile file) {
|
|
|
WbsTreeContract byId = wbsTreeContractServiceImpl.getById(pKeyId);
|
|
|
+ List<String> integers = new ArrayList<>();
|
|
|
+ integers.add("4");
|
|
|
+ integers.add("5");
|
|
|
+ integers.add("6");
|
|
|
+
|
|
|
+ Integer classify = 1;
|
|
|
+ if (byId.getTableOwner() != null && integers.contains(byId.getTableOwner())) {
|
|
|
+ classify = 2;
|
|
|
+ }
|
|
|
//查询与当前表及所有复制表
|
|
|
List<WbsTreeContract> list = wbsTreeContractServiceImpl.list(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
.eq(WbsTreeContract::getPId, byId.getPId())
|
|
@@ -667,7 +676,7 @@ public class WbsTreeContractController extends BladeController {
|
|
|
|
|
|
//只记录当前这个表及它排序下的表
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
- if(Objects.equals(pKeyId, list.get(i).getPKeyId())){
|
|
|
+ if (Objects.equals(pKeyId, list.get(i).getPKeyId())) {
|
|
|
targetIndex = i;
|
|
|
break;
|
|
|
}
|
|
@@ -688,9 +697,6 @@ public class WbsTreeContractController extends BladeController {
|
|
|
SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//创建一个临时html路径
|
|
|
Long id = SnowFlakeUtil.getId();
|
|
|
String importExcelFilePath = FileUtils.getSysLocalFileUrl();
|
|
@@ -707,28 +713,48 @@ public class WbsTreeContractController extends BladeController {
|
|
|
WorksheetsCollection worksheets = workbook.getWorksheets();
|
|
|
workbook.saveToFile(importExcelTOHtmlPath, FileFormat.HTML);
|
|
|
int size = worksheets.size();
|
|
|
- //excel和表数据匹配
|
|
|
- if(size > list.size()){
|
|
|
- size = list.size();
|
|
|
+ //如果sheet比数据库中表多 则需要添加复制表
|
|
|
+ if (size > list.size()) {
|
|
|
+ //却几张复制几张 并且复制出来的排序要再最后
|
|
|
+ for (int i = 0; i < size - list.size(); i++) {
|
|
|
+ excelTabController.copeBussTab(pKeyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ list = wbsTreeContractServiceImpl.list(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .eq(WbsTreeContract::getPId, byId.getPId())
|
|
|
+ .eq(WbsTreeContract::getInitTableName, byId.getInitTableName())
|
|
|
+ .in(WbsTreeContract::getTableOwner, byId.getTableOwner())
|
|
|
+ .orderByAsc(WbsTreeContract::getSort)
|
|
|
+ .orderByAsc(WbsTreeContract::getFullName)
|
|
|
+ .orderByAsc(WbsTreeContract::getCreateTime)
|
|
|
+ );
|
|
|
+
|
|
|
+ //只记录当前这个表及它排序下的表
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ if (Objects.equals(pKeyId, list.get(i).getPKeyId())) {
|
|
|
+ targetIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (targetIndex != -1) {
|
|
|
+ list = list.subList(targetIndex, list.size());
|
|
|
+ }
|
|
|
}
|
|
|
+ if (size > list.size()) {
|
|
|
+ return R.fail("添加复制表失败");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//获取转换成功后的html路径
|
|
|
url_1 = importExcelTOHtmlPath.split("pdf//")[0];
|
|
|
|
|
|
for (int x = 0; x < size; x++) {
|
|
|
//结果集
|
|
|
- Map<String, Object> stringStringMap = new HashMap<>();
|
|
|
+ Map<String, String> stringStringMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
WbsTreeContract wbsTreeContract = list.get(x);
|
|
|
- stringStringMap.put("pkeyId",wbsTreeContract.getPKeyId());
|
|
|
- stringStringMap.put("nodeId",wbsTreeContract.getPId());
|
|
|
- stringStringMap.put("projectId",wbsTreeContract.getProjectId());
|
|
|
- stringStringMap.put("tabGroupId",wbsTreeContract.getTabGroupId());
|
|
|
- stringStringMap.put("contractId",wbsTreeContract.getContractId());
|
|
|
- stringStringMap.put("classify",classify);
|
|
|
- stringStringMap.put("isCollapseLoad",true);
|
|
|
- stringStringMap.put("isRenderForm",true);
|
|
|
+
|
|
|
//获取当前表htmlString
|
|
|
String htmlString_1 = wbsTreeContractServiceImpl.getHtmlString(String.valueOf(wbsTreeContract.getPKeyId()));
|
|
|
|
|
@@ -750,12 +776,23 @@ public class WbsTreeContractController extends BladeController {
|
|
|
Element td2 = tdElements2.get(j);
|
|
|
String keyName = getKeyNameFromChildElement(td1);
|
|
|
if (StringUtils.isNotEmpty(keyName)) {
|
|
|
+ String[] split = keyName.split("__");
|
|
|
+
|
|
|
String divValue = td2.text(); //获取文本值
|
|
|
if (StringUtils.isNotEmpty(divValue)) {
|
|
|
if (parseDateRange(divValue).size() == 2) {
|
|
|
//判断范围日期
|
|
|
List<String> dateArr = parseDateRange(divValue);
|
|
|
- stringStringMap.put(keyName, dateArr);
|
|
|
+ String value = stringStringMap.get(split[0]);
|
|
|
+
|
|
|
+ String dataValue = "['" + dateArr.get(0) + "','" + dateArr.get(1) + "']" + "_^_" + split[1];
|
|
|
+ if (value != null) {
|
|
|
+ value = value + "☆" + dataValue;
|
|
|
+ } else {
|
|
|
+ value = dataValue;
|
|
|
+ }
|
|
|
+ // key_1 1_^_1_1
|
|
|
+ stringStringMap.put(split[0], value);
|
|
|
continue;
|
|
|
}
|
|
|
//判断是否存在两个斜杠,且不在一起,那么视为日期格式
|
|
@@ -784,13 +821,92 @@ public class WbsTreeContractController extends BladeController {
|
|
|
divValue = outputDateFormat.format(date);
|
|
|
}
|
|
|
}
|
|
|
- stringStringMap.put(keyName, divValue);
|
|
|
+ String value = stringStringMap.get(split[0]);
|
|
|
+
|
|
|
+ String dataValue = divValue + "_^_" + split[1];
|
|
|
+ if (value != null) {
|
|
|
+ value = value + "☆" + dataValue;
|
|
|
+ } else {
|
|
|
+ value = dataValue;
|
|
|
+ }
|
|
|
+ stringStringMap.put(split[0], value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- maps.add(stringStringMap);
|
|
|
+ //先查询 如果有 则修改数据
|
|
|
+
|
|
|
+ String selectSql = "select * from " + byId.getInitTableName() + " where p_key_id = " + wbsTreeContract.getPKeyId();
|
|
|
+
|
|
|
+ Map<String, Object> initId = null;
|
|
|
+ try {
|
|
|
+ List<Map<String, Object>> hashMaps = jdbcTemplate.queryForList(selectSql);
|
|
|
+ if(CollectionUtil.isNotEmpty(hashMaps)){
|
|
|
+ initId = hashMaps.get(0);
|
|
|
+ }
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ initId = null;
|
|
|
+ }
|
|
|
+ String sql = null;
|
|
|
+ if (initId != null) {
|
|
|
+ sql = "update " + byId.getInitTableName() + " set ";
|
|
|
+ //导入的数据
|
|
|
+ Set<Map.Entry<String, String>> entries = stringStringMap.entrySet();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ Map<String, Object> finalInitId = initId;
|
|
|
+ entries.forEach(f -> {
|
|
|
+ //原先是否存在值 是否为☆拼接的多数据
|
|
|
+ String oldValue = (String) finalInitId.get(f.getKey());
|
|
|
+ if (StringUtils.isNotEmpty(oldValue)) {
|
|
|
+ //当前keu坐标与数据的对应关系
|
|
|
+ HashMap<String, String> newCoordinate = new HashMap<>();
|
|
|
+ //旧数据中需要保留的数据
|
|
|
+ List<String> oldRetainData = new ArrayList<>();
|
|
|
+ //导入的数据
|
|
|
+ String[] newSp = f.getValue().split("☆");
|
|
|
+ for (String s : newSp) {
|
|
|
+ //单个单元格的数据
|
|
|
+ String[] split1 = s.split("_\\^_");
|
|
|
+ newCoordinate.put(split1[1], split1[0]);
|
|
|
+ }
|
|
|
+ //旧数据
|
|
|
+ String[] oldSp = oldValue.split("☆");
|
|
|
+ for (String s : oldSp) {
|
|
|
+ //单个单元格的数据
|
|
|
+ String[] split1 = s.split("_\\^_");
|
|
|
+ //根据旧数据的坐标去新数据中查询
|
|
|
+ String s1 = newCoordinate.get(split1[1]);
|
|
|
+ //如果没有查询到就需要当前坐标数据
|
|
|
+ if (s1 == null) {
|
|
|
+ oldRetainData.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(oldRetainData)) {
|
|
|
+ f.setValue(f.getValue() + "☆" + StringUtils.join(oldRetainData, "☆"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(sb.toString())) {
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.append(f.getKey()).append("=").append("'").append(f.getValue()).append("'");
|
|
|
+ });
|
|
|
+ sql = sql + sb + "where id = " + initId.get("id");
|
|
|
+ } else {
|
|
|
+ Set<String> strings = stringStringMap.keySet();
|
|
|
+ Collection<String> values = stringStringMap.values();
|
|
|
+ //转换成sql能够使用的字符串
|
|
|
+ ArrayList<String> strings1 = new ArrayList<>();
|
|
|
+ values.forEach(f -> {
|
|
|
+ f = "'" + f + "'";
|
|
|
+ strings1.add(f);
|
|
|
+ });
|
|
|
+ long newPkId = SnowFlakeUtil.getId();
|
|
|
+ sql = "insert into " + byId.getInitTableName() + " (id,p_key_id," + StringUtils.join(strings, ",") + ") VALUES (" + newPkId + ", " + wbsTreeContract.getPKeyId() + ", " + StringUtils.join(strings1, ",") + ")";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ jdbcTemplate.execute(sql);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -808,18 +924,7 @@ public class WbsTreeContractController extends BladeController {
|
|
|
logger.info("执行方法【importExcel】结束,删除临时文件夹失败!");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- HashMap<String, Object> map1 = new HashMap<>();
|
|
|
- map1.put("orderList",maps);
|
|
|
-
|
|
|
-
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("dataInfo",map1);
|
|
|
-
|
|
|
- //调用保存接口
|
|
|
- excelTabController.saveBussData2(jsonObject,null);
|
|
|
-
|
|
|
- return R.data(jsonObject);
|
|
|
+ return R.success("ok");
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
} finally {
|