|
@@ -45,6 +45,8 @@ public class CostModelWxPriceServiceImpl extends ServiceImpl<CostModelWxPriceMap
|
|
|
/**
|
|
|
* 通过excel导入数据
|
|
|
*如果数据重复,删除重复的数据,然后在写入数据库
|
|
|
+ * 当前是取数据库中所有的数据进行比较,如果确定哪个字段是必须有值不能为null,可以根据该字段找出来相应数据再进行比较 --sl
|
|
|
+ *
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @return
|
|
@@ -62,68 +64,47 @@ public class CostModelWxPriceServiceImpl extends ServiceImpl<CostModelWxPriceMap
|
|
|
try {
|
|
|
//1.从excel中获取到数据放入到list中
|
|
|
List<CostModelWxPrice> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
|
|
|
- System.out.println("从excel表中获取的数据");
|
|
|
- list.forEach(System.out::println);
|
|
|
- System.out.println(list.getClass());
|
|
|
- System.out.println(list.getClass().getName());
|
|
|
+// System.out.println("从excel表中获取的数据");
|
|
|
+// list.forEach(System.out::println);
|
|
|
|
|
|
//2.新建一个list来给list中的数据去重
|
|
|
List<CostModelWxPrice> listNew = new ArrayList<>();
|
|
|
for(CostModelWxPrice wxp:list){
|
|
|
-// System.out.println(wxp);
|
|
|
-// System.out.println(wxp.getWxProject());
|
|
|
-// System.out.println(wxp.getWxCompany());
|
|
|
-// System.out.println(wxp.getDanjia().getClass());
|
|
|
-// String wxpj = wxp.getWxProject(); //外协项目
|
|
|
-// String wxcom = wxp.getWxCompany(); //外协单位
|
|
|
-// String dj = wxp.getDanjia(); //单价
|
|
|
-// String unit = wxp.getUnit(); //计量单位
|
|
|
if (!listNew.contains(wxp)) {
|
|
|
listNew.add(wxp);
|
|
|
}
|
|
|
}
|
|
|
- System.out.println("列表去重后的数据");
|
|
|
- listNew.forEach(System.out::println);
|
|
|
- System.out.println(listNew.getClass());
|
|
|
- System.out.println(listNew.getClass().getName());
|
|
|
+// System.out.println("列表去重后的数据");
|
|
|
+// listNew.forEach(System.out::println);
|
|
|
|
|
|
//3.从数据库中读取全部表中数据
|
|
|
List<CostModelWxPrice> list1 = getWXPAllDetailList();
|
|
|
- System.out.println("从数据库中取出的数据");
|
|
|
- list1.forEach(System.out::println);
|
|
|
- System.out.println(list1.getClass());
|
|
|
- System.out.println(list1.getClass().getName());
|
|
|
+// System.out.println("从数据库中取出的数据");
|
|
|
+// list1.forEach(System.out::println);
|
|
|
|
|
|
Iterator<CostModelWxPrice> iterator = listNew.iterator();
|
|
|
//4.判断去重后的listNew中是否有数据已经在数据库中记录过了,如果已经保存过直接删掉
|
|
|
while(iterator.hasNext()){
|
|
|
CostModelWxPrice wxpNew = iterator.next();
|
|
|
- System.out.println("进入第一层循环");
|
|
|
- System.out.println(wxpNew);
|
|
|
- if((wxpNew.getWxProject()!=null)&(wxpNew.getDanjia()!=null)&(wxpNew.getUnit()!=null)&(wxpNew.getWxCompany()!=null)){
|
|
|
- for(CostModelWxPrice wxp1:list1){
|
|
|
- System.out.println("进入第二层循环判断数据是否已经存在");
|
|
|
-// System.out.println(wxp1);
|
|
|
- if((wxpNew.getWxProject().equals(wxp1.getWxProject()))&(wxpNew.getDanjia().equals(wxp1.getDanjia()))&(wxpNew.getUnit().equals(wxp1.getUnit()))&(wxpNew.getWxCompany().equals(wxp1.getWxCompany()))){
|
|
|
- System.out.println("进入判断");
|
|
|
+ if((wxpNew.getWxProject()==null)&(wxpNew.getDanjia()==null)&(wxpNew.getUnit()==null)&(wxpNew.getWxCompany()==null)){
|
|
|
+ //System.out.println("当前数据内容都为空,删除");
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for(CostModelWxPrice wxp1:list1) {
|
|
|
+ if((Objects.equals(wxpNew.getWxProject(), wxp1.getWxProject()))&(Objects.equals(wxpNew.getDanjia(), wxp1.getDanjia()))&(Objects.equals(wxpNew.getUnit(), wxp1.getUnit()))&(Objects.equals(wxpNew.getWxCompany(), wxp1.getWxCompany()))){
|
|
|
iterator.remove();
|
|
|
- System.out.println("当前元素重复,进行删除");
|
|
|
+ //System.out.println("当前元素重复,进行删除");
|
|
|
//listNew.forEach(System.out::println); //foreach中不能remove,不然会报错java.util.ConcurrentModificationException
|
|
|
- System.out.println();
|
|
|
break;//因为wxpNew元素已经被删除了,所有此段循环可以跳过了
|
|
|
}
|
|
|
- System.out.println("第二层循环还在");
|
|
|
}
|
|
|
}
|
|
|
- else{//如果外协价格表中的四个字段中有值为null,则删除该条记录
|
|
|
- iterator.remove();
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
- System.out.println("最终需要存入的数据");
|
|
|
- listNew.forEach(System.out::println);
|
|
|
- System.out.println(listNew.getClass());
|
|
|
- System.out.println(listNew.getClass().getName());
|
|
|
+// System.out.println("最终需要存入的数据");
|
|
|
+// listNew.forEach(System.out::println);
|
|
|
+// System.out.println(listNew.getClass());
|
|
|
+// System.out.println(listNew.getClass().getName());
|
|
|
|
|
|
//update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
long start = System.currentTimeMillis();
|