|
@@ -2,22 +2,30 @@ package org.springblade.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import io.reactivex.Single;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.springblade.business.entity.DatumPoint;
|
|
import org.springblade.business.entity.DatumPoint;
|
|
|
|
+import org.springblade.business.excel.DatumPointExcel;
|
|
|
|
+import org.springblade.business.excel.DatumPointxyExcel;
|
|
|
|
+import org.springblade.business.excel.MileageExcel;
|
|
import org.springblade.business.mapper.DatumPointMapper;
|
|
import org.springblade.business.mapper.DatumPointMapper;
|
|
import org.springblade.business.utils.ExcelUtil;
|
|
import org.springblade.business.utils.ExcelUtil;
|
|
|
|
+import org.springblade.common.utils.BaseUtils;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.tool.api.R;
|
|
import org.springblade.core.tool.api.R;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
import org.springblade.manager.feign.FormulaClient;
|
|
import org.springblade.manager.feign.FormulaClient;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yangyj
|
|
* @author yangyj
|
|
@@ -28,6 +36,7 @@ import java.util.*;
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class DatumPointService extends BaseServiceImpl<DatumPointMapper, DatumPoint> {
|
|
public class DatumPointService extends BaseServiceImpl<DatumPointMapper, DatumPoint> {
|
|
private final FormulaClient formulaClient;
|
|
private final FormulaClient formulaClient;
|
|
|
|
+ private final JdbcTemplate jdbc;
|
|
public R<Object> site(Long contractId,Long pkId,String key) throws FileNotFoundException {
|
|
public R<Object> site(Long contractId,Long pkId,String key) throws FileNotFoundException {
|
|
Map<String,Object> result = new HashMap<>();
|
|
Map<String,Object> result = new HashMap<>();
|
|
if(Func.isNotEmpty(contractId)&&Func.isNotEmpty(pkId)&&Func.isNotEmpty(key)) {
|
|
if(Func.isNotEmpty(contractId)&&Func.isNotEmpty(pkId)&&Func.isNotEmpty(key)) {
|
|
@@ -70,155 +79,214 @@ public class DatumPointService extends BaseServiceImpl<DatumPointMapper, DatumPo
|
|
}
|
|
}
|
|
return R.data(result);
|
|
return R.data(result);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public R importData(MultipartFile file, Long contractId, Long projectId, Integer dataType) throws Exception {
|
|
|
|
- List<String> level=new ArrayList<>();
|
|
|
|
- level.add("一级");
|
|
|
|
- level.add("二级");
|
|
|
|
- level.add("三级");
|
|
|
|
- level.add("四级");
|
|
|
|
|
|
+ public static List<String> LEVEL = new ArrayList<>(Arrays.asList("一级","二级","三级","四级"));
|
|
|
|
+ public R importExcel(MultipartFile file, Long contractId, Long projectId, Integer dataType) {
|
|
try {
|
|
try {
|
|
- Workbook wb = WorkbookFactory.create(file.getInputStream());
|
|
|
|
- Sheet sheet = wb.getSheetAt(0);
|
|
|
|
- List<DatumPoint> importList = new ArrayList<>();
|
|
|
|
- Row row1=sheet.getRow(0);
|
|
|
|
- if(dataType==0){
|
|
|
|
- String dengji= ExcelUtil.getValue(row1.getCell(2)).toString();
|
|
|
|
- String beizhu=ExcelUtil.getValue(row1.getCell(3)).toString();
|
|
|
|
- if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
|
|
|
|
- return R.fail("导入的数据格式有错,请对准导入模板确认!");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(dataType==1){
|
|
|
|
- String dengji=ExcelUtil.getValue(row1.getCell(4)).toString();
|
|
|
|
- String beizhu=ExcelUtil.getValue(row1.getCell(5)).toString();
|
|
|
|
- if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
|
|
|
|
- return R.fail("导入的数据格式有错,请对准导入模板确认!");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 1; ; i++) {
|
|
|
|
- Row row = sheet.getRow(i);
|
|
|
|
- if(row == null) {
|
|
|
|
- break;
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ List<DatumPointxyExcel> data = org.springblade.core.excel.util.ExcelUtil.read(file,DatumPointxyExcel.class);
|
|
|
|
+ if(Func.isNotEmpty(data)){
|
|
|
|
+ List<String> names=data.stream().map(DatumPointxyExcel::getName).filter(Func::isNotBlank).collect(Collectors.toList());
|
|
|
|
+ List<String> checkNames= new ArrayList<>();
|
|
|
|
+ if(Func.isNotEmpty(names)){
|
|
|
|
+ checkNames= this.jdbc.queryForList("select name from t_om_datum_point where is_deleted=0 and type="+dataType+" and contract_id ="+contractId+" and name in('"+String.join("','",names)+"')",String.class);
|
|
}
|
|
}
|
|
- if(dataType==0) {
|
|
|
|
- DatumPoint obj = new DatumPoint();
|
|
|
|
- for (int j = 0; j < 4; j++) {
|
|
|
|
- String value = (String) ExcelUtil.getValue(row.getCell(j));
|
|
|
|
- if (StringUtil.isEmpty(value)) {
|
|
|
|
- value = "";
|
|
|
|
- }
|
|
|
|
- String msg="";
|
|
|
|
- //判断测站点名称是否为空
|
|
|
|
- String name=(String)ExcelUtil.getValue(row.getCell(0));
|
|
|
|
- if(StringUtil.isEmpty(name)){
|
|
|
|
- msg="第"+i+"行,测站点名称为空,请输入!";
|
|
|
|
- return R.fail(msg);
|
|
|
|
- }
|
|
|
|
- //判断,同一合同段下,测站点名称是否重复
|
|
|
|
- if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
|
|
|
|
- msg="第"+i+"行,测站点:"+name+"已存在,请修改";
|
|
|
|
- return R.fail(msg);
|
|
|
|
|
|
+ List<String> finalCheckNames = checkNames;
|
|
|
|
+ Map<Boolean,List<DatumPointxyExcel>> map = data.stream().collect(Collectors.partitioningBy(d->Func.isNotBlank(d.getName())&&LEVEL.contains(d.getLevel())&&!finalCheckNames.contains(d.getName())));
|
|
|
|
+ List<DatumPointxyExcel> checked = map.get(true);
|
|
|
|
+ List<DatumPointxyExcel> fail=map.get(false);
|
|
|
|
+ if(Func.isNotEmpty(checked)){
|
|
|
|
+ List<DatumPoint> result= checked.stream().map(d->{
|
|
|
|
+ DatumPoint dp = new DatumPoint();
|
|
|
|
+ BeanUtils.copyProperties(d,dp);
|
|
|
|
+ if(BaseUtils.isNumber(d.getH())){
|
|
|
|
+ dp.setH(Func.toDouble(d.getH()));
|
|
}
|
|
}
|
|
- switch (j) {
|
|
|
|
- case 0:
|
|
|
|
- obj.setName(value);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- obj.setH(Double.parseDouble(value));
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- //判断等级是否为:一级、二级、三级、四级
|
|
|
|
- if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
|
|
|
|
- if(!level.contains(value)){
|
|
|
|
- msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
|
|
|
|
- return R.fail(msg);
|
|
|
|
- }
|
|
|
|
- obj.setLevel(value);
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- obj.setRemark(value);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
|
|
+ if(dataType==1){
|
|
|
|
+ if(BaseUtils.isNumber(d.getX())){
|
|
|
|
+ dp.setX(Func.toDouble(d.getX()));
|
|
|
|
+ }
|
|
|
|
+ if(BaseUtils.isNumber(d.getY())){
|
|
|
|
+ dp.setY(Func.toDouble(d.getY()));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- }
|
|
|
|
- obj.setContractId(contractId);
|
|
|
|
- obj.setProjectId(projectId);
|
|
|
|
- obj.setCreateTime(new Date());
|
|
|
|
- obj.setType(dataType);
|
|
|
|
- importList.add(obj);
|
|
|
|
|
|
+ dp.setContractId(contractId);
|
|
|
|
+ dp.setProjectId(projectId);
|
|
|
|
+ dp.setCreateTime(new Date());
|
|
|
|
+ dp.setType(dataType);
|
|
|
|
+ return dp;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ this.saveBatch(result);
|
|
|
|
+ sb.append(result.size()).append("条记录导入成功");
|
|
}
|
|
}
|
|
- if(dataType==1){
|
|
|
|
- DatumPoint obj = new DatumPoint();
|
|
|
|
- for (int j = 0; j < 6; j++) {
|
|
|
|
- String value = (String) ExcelUtil.getValue(row.getCell(j));
|
|
|
|
- if (StringUtil.isEmpty(value)) {
|
|
|
|
- value = "";
|
|
|
|
- }
|
|
|
|
- String msg="";
|
|
|
|
- //判断测站点名称是否为空
|
|
|
|
- String name=(String)ExcelUtil.getValue(row.getCell(0));
|
|
|
|
- if(StringUtil.isEmpty(name)){
|
|
|
|
- msg="第"+i+"行,测站点名称为空,请输入!";
|
|
|
|
- return R.fail(msg);
|
|
|
|
- }
|
|
|
|
- //判断,同一合同段下,测站点名称是否重复
|
|
|
|
- if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
|
|
|
|
- msg="第"+i+"行,测站点:"+name+"已存在,请修改";
|
|
|
|
- return R.fail(msg);
|
|
|
|
- }
|
|
|
|
- switch (j) {
|
|
|
|
- case 0:
|
|
|
|
- obj.setName(value);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- obj.setX(Double.parseDouble(value));
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- obj.setY(Double.parseDouble(value));
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- obj.setH(Double.parseDouble(value));
|
|
|
|
- break;
|
|
|
|
- case 4:
|
|
|
|
- //判断等级是否为:一级、二级、三级、四级
|
|
|
|
- if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
|
|
|
|
- if(!level.contains(value)){
|
|
|
|
- msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
|
|
|
|
- return R.fail(msg);
|
|
|
|
- }
|
|
|
|
- obj.setLevel(value);
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case 5:
|
|
|
|
- obj.setRemark(value);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- obj.setContractId(contractId);
|
|
|
|
- obj.setProjectId(projectId);
|
|
|
|
- obj.setCreateTime(new Date());
|
|
|
|
- obj.setType(dataType);
|
|
|
|
- importList.add(obj);
|
|
|
|
|
|
+ if(Func.isNotEmpty(fail)){
|
|
|
|
+ List<String> error=fail.stream().map(e->{
|
|
|
|
+ if(Func.isEmpty(e.getName())){
|
|
|
|
+ return "第"+(data.indexOf(e)+1)+"条记录测站点名称为空";
|
|
|
|
+ }else if(!LEVEL.contains(e.getLevel())){
|
|
|
|
+ return e.getName()+"等级必须为一级、二级、三级、四级";
|
|
|
|
+ }else{
|
|
|
|
+ return e.getName()+"已存在";
|
|
|
|
+ }
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ sb.append(String.join(";",error));
|
|
}
|
|
}
|
|
|
|
+ return R.success(sb.toString());
|
|
}
|
|
}
|
|
- //批量保存
|
|
|
|
- this.saveBatch(importList);
|
|
|
|
- return R.success("导入成功");
|
|
|
|
- } catch (Exception e){
|
|
|
|
|
|
+ return R.fail("数据无效");
|
|
|
|
+ }catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- return R.fail("执行异常");
|
|
|
|
|
|
+ return R.fail("导入失败");
|
|
}
|
|
}
|
|
|
|
|
|
- //导出数据
|
|
|
|
|
|
+// public R importData_bak(MultipartFile file, Long contractId, Long projectId, Integer dataType) throws Exception {
|
|
|
|
+// List<String> level=new ArrayList<>();
|
|
|
|
+// level.add("一级");
|
|
|
|
+// level.add("二级");
|
|
|
|
+// level.add("三级");
|
|
|
|
+// level.add("四级");
|
|
|
|
+// try {
|
|
|
|
+// Workbook wb = WorkbookFactory.create(file.getInputStream());
|
|
|
|
+// Sheet sheet = wb.getSheetAt(0);
|
|
|
|
+// List<DatumPoint> importList = new ArrayList<>();
|
|
|
|
+// Row row1=sheet.getRow(0);
|
|
|
|
+// if(dataType==0){
|
|
|
|
+// String dengji= ExcelUtil.getValue(row1.getCell(2)).toString();
|
|
|
|
+// String beizhu=ExcelUtil.getValue(row1.getCell(3)).toString();
|
|
|
|
+// if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
|
|
|
|
+// return R.fail("导入的数据格式有错,请对准导入模板确认!");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if(dataType==1){
|
|
|
|
+// String dengji=ExcelUtil.getValue(row1.getCell(4)).toString();
|
|
|
|
+// String beizhu=ExcelUtil.getValue(row1.getCell(5)).toString();
|
|
|
|
+// if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
|
|
|
|
+// return R.fail("导入的数据格式有错,请对准导入模板确认!");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// for (int i = 1; ; i++) {
|
|
|
|
+// Row row = sheet.getRow(i);
|
|
|
|
+// if(row == null) {
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+// if(dataType==0) {
|
|
|
|
+// DatumPoint obj = new DatumPoint();
|
|
|
|
+// for (int j = 0; j < 4; j++) {
|
|
|
|
+// String value = (String) ExcelUtil.getValue(row.getCell(j));
|
|
|
|
+// if (StringUtil.isEmpty(value)) {
|
|
|
|
+// value = "";
|
|
|
|
+// }
|
|
|
|
+// String msg="";
|
|
|
|
+// //判断测站点名称是否为空
|
|
|
|
+// String name=(String)ExcelUtil.getValue(row.getCell(0));
|
|
|
|
+// if(StringUtil.isEmpty(name)){
|
|
|
|
+// msg="第"+i+"行,测站点名称为空,请输入!";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// //判断,同一合同段下,测站点名称是否重复
|
|
|
|
+// if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
|
|
|
|
+// msg="第"+i+"行,测站点:"+name+"已存在,请修改";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// switch (j) {
|
|
|
|
+// case 0:
|
|
|
|
+// obj.setName(value);
|
|
|
|
+// break;
|
|
|
|
+// case 1:
|
|
|
|
+// obj.setH(Double.parseDouble(value));
|
|
|
|
+// break;
|
|
|
|
+// case 2:
|
|
|
|
+// //判断等级是否为:一级、二级、三级、四级
|
|
|
|
+// if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
|
|
|
|
+// if(!level.contains(value)){
|
|
|
|
+// msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// obj.setLevel(value);
|
|
|
|
+// }
|
|
|
|
+// break;
|
|
|
|
+// case 3:
|
|
|
|
+// obj.setRemark(value);
|
|
|
|
+// break;
|
|
|
|
+// default:
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// obj.setContractId(contractId);
|
|
|
|
+// obj.setProjectId(projectId);
|
|
|
|
+// obj.setCreateTime(new Date());
|
|
|
|
+// obj.setType(dataType);
|
|
|
|
+// importList.add(obj);
|
|
|
|
+// }
|
|
|
|
+// if(dataType==1){
|
|
|
|
+// DatumPoint obj = new DatumPoint();
|
|
|
|
+// for (int j = 0; j < 6; j++) {
|
|
|
|
+// String value = (String) ExcelUtil.getValue(row.getCell(j));
|
|
|
|
+// if (StringUtil.isEmpty(value)) {
|
|
|
|
+// value = "";
|
|
|
|
+// }
|
|
|
|
+// String msg="";
|
|
|
|
+// //判断测站点名称是否为空
|
|
|
|
+// String name=(String)ExcelUtil.getValue(row.getCell(0));
|
|
|
|
+// if(StringUtil.isEmpty(name)){
|
|
|
|
+// msg="第"+i+"行,测站点名称为空,请输入!";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// //判断,同一合同段下,测站点名称是否重复
|
|
|
|
+// if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
|
|
|
|
+// msg="第"+i+"行,测站点:"+name+"已存在,请修改";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// switch (j) {
|
|
|
|
+// case 0:
|
|
|
|
+// obj.setName(value);
|
|
|
|
+// break;
|
|
|
|
+// case 1:
|
|
|
|
+// obj.setX(Double.parseDouble(value));
|
|
|
|
+// break;
|
|
|
|
+// case 2:
|
|
|
|
+// obj.setY(Double.parseDouble(value));
|
|
|
|
+// break;
|
|
|
|
+// case 3:
|
|
|
|
+// obj.setH(Double.parseDouble(value));
|
|
|
|
+// break;
|
|
|
|
+// case 4:
|
|
|
|
+// //判断等级是否为:一级、二级、三级、四级
|
|
|
|
+// if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
|
|
|
|
+// if(!level.contains(value)){
|
|
|
|
+// msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
|
|
|
|
+// return R.fail(msg);
|
|
|
|
+// }
|
|
|
|
+// obj.setLevel(value);
|
|
|
|
+// }
|
|
|
|
+// break;
|
|
|
|
+// case 5:
|
|
|
|
+// obj.setRemark(value);
|
|
|
|
+// break;
|
|
|
|
+// default:
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// obj.setContractId(contractId);
|
|
|
|
+// obj.setProjectId(projectId);
|
|
|
|
+// obj.setCreateTime(new Date());
|
|
|
|
+// obj.setType(dataType);
|
|
|
|
+// importList.add(obj);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// //批量保存
|
|
|
|
+// this.saveBatch(importList);
|
|
|
|
+// return R.success("导入成功");
|
|
|
|
+// } catch (Exception e){
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+// return R.fail("执行异常");
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ /*导出数据*/
|
|
public List<DatumPoint> exportExcel( String contractId , Integer type, String search){
|
|
public List<DatumPoint> exportExcel( String contractId , Integer type, String search){
|
|
if(StringUtil.isBlank(search)){
|
|
if(StringUtil.isBlank(search)){
|
|
search="";
|
|
search="";
|