|
@@ -1,11 +1,31 @@
|
|
|
package org.jeecg.modules.projectImportList.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.modules.projectChbSwf.entity.ProjectChbSwf;
|
|
|
+import org.jeecg.modules.projectChbSwf.service.IProjectChbSwfService;
|
|
|
+import org.jeecg.modules.projectChbWxf.entity.ProjectChbWxf;
|
|
|
+import org.jeecg.modules.projectChbWxf.service.IProjectChbWxfService;
|
|
|
+import org.jeecg.modules.projectChbZyf.entity.ProjectChbZyf;
|
|
|
+import org.jeecg.modules.projectChbZyf.service.IProjectChbZyfService;
|
|
|
+import org.jeecg.modules.projectImportList.convert.CHBConvert;
|
|
|
+import org.jeecg.modules.projectImportList.dto.ProjectChb;
|
|
|
+import org.jeecg.modules.projectImportList.dto.TasknoAndNd;
|
|
|
import org.jeecg.modules.projectImportList.entity.ProjectImportList;
|
|
|
import org.jeecg.modules.projectImportList.mapper.ProjectImportListMapper;
|
|
|
import org.jeecg.modules.projectImportList.service.IProjectImportListService;
|
|
|
+import org.jeecg.modules.projectKmbh.service.IKzksProjectKmbhService;
|
|
|
+import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
+import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 导入并下载
|
|
@@ -14,6 +34,128 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ProjectImportListServiceImpl extends ServiceImpl<ProjectImportListMapper, ProjectImportList> implements IProjectImportListService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IKzksProjectKmbhService kmbhService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IProjectChbSwfService swfService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IProjectChbWxfService wxfService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IProjectChbZyfService zyfService;
|
|
|
+
|
|
|
+ public List<TasknoAndNd> addTNlist(List<TasknoAndNd> tnList, String taskno, String nd){
|
|
|
+ for (TasknoAndNd tasknoAndNd : tnList){
|
|
|
+ if(taskno.equals(tasknoAndNd.getTaskno()) && nd.equals(tasknoAndNd.getNd())) return tnList;
|
|
|
+ else continue;
|
|
|
+ }
|
|
|
+ TasknoAndNd tn = new TasknoAndNd();
|
|
|
+ tn.setNd(nd);
|
|
|
+ tn.setTaskno(taskno);
|
|
|
+ tnList.add(tn);
|
|
|
+ return tnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ * 判断费用类别
|
|
|
+ * 根据年度、费用类别删除对应数据
|
|
|
+ * 对各个表进行新增
|
|
|
+ */
|
|
|
+ public Result<?> importExcel1(String strUrl, Class<ProjectChb> clazz) {
|
|
|
+
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = new FileInputStream(strUrl);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取上传文件对象
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(0);/*表格标题所占行数(默认是0)*/
|
|
|
+ params.setHeadRows(1);/*表头所占据的行数行数,默认1,代表标题占据一行*/
|
|
|
+ params.setNeedSave(true);
|
|
|
+ try {
|
|
|
+ List<ProjectChb> list = ExcelImportUtil.importExcel(inputStream, clazz, params);//导入的所有数据
|
|
|
+
|
|
|
+ List<ProjectChbSwf> swfList = new ArrayList<>();//事务费
|
|
|
+ List<ProjectChbZyf> zyfList = new ArrayList<>();//专用费
|
|
|
+ List<ProjectChbWxf> wxfList = new ArrayList<>();//外协费
|
|
|
+
|
|
|
+ List<TasknoAndNd> tnSWFList = new ArrayList<>();//事务费任务号年度集合——用于删除
|
|
|
+ List<TasknoAndNd> tnZYFList = new ArrayList<>();//专用费任务号年度集合——用于删除
|
|
|
+ List<TasknoAndNd> tnWXFList = new ArrayList<>();//外协费任务号年度集合——用于删除
|
|
|
+
|
|
|
+ for (ProjectChb chb: list){
|
|
|
+ String taskno = chb.getTaskno();
|
|
|
+ String nd = chb.getNd();
|
|
|
+ String kmbh = chb.getKmbh();
|
|
|
+ if(!Objects.equals(taskno,"") && !Objects.equals(nd,"") && !Objects.equals(kmbh,"")){
|
|
|
+ String fylb = kmbhService.getByNdAndKmbh(nd, kmbh);//费用类别
|
|
|
+ if(Objects.equals(fylb,"事务费")){
|
|
|
+ swfList.add(CHBConvert.INSTANCE.toSWF(chb));
|
|
|
+ tnSWFList = addTNlist(tnSWFList,taskno,nd);
|
|
|
+ }else if(Objects.equals(fylb,"专用费")){
|
|
|
+ zyfList.add(CHBConvert.INSTANCE.toZYF(chb));
|
|
|
+ tnZYFList = addTNlist(tnZYFList,taskno,nd);
|
|
|
+ }else if(Objects.equals(fylb,"外协费")){
|
|
|
+ wxfList.add(CHBConvert.INSTANCE.toWXF(chb));
|
|
|
+ tnWXFList = addTNlist(tnWXFList,taskno,nd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Map<String, Object> columnMap = new HashMap<>();
|
|
|
+ for(TasknoAndNd tasknoAndNd : tnSWFList){
|
|
|
+ columnMap = new HashMap<>();
|
|
|
+ columnMap.put("nd",tasknoAndNd.getNd());
|
|
|
+ columnMap.put("taskno",tasknoAndNd.getTaskno());
|
|
|
+ swfService.removeByMap(columnMap);
|
|
|
+ }
|
|
|
+ swfService.saveBatch(swfList);
|
|
|
+ for(TasknoAndNd tasknoAndNd : tnZYFList){
|
|
|
+ columnMap = new HashMap<>();
|
|
|
+ columnMap.put("nd",tasknoAndNd.getNd());
|
|
|
+ columnMap.put("taskno",tasknoAndNd.getTaskno());
|
|
|
+ zyfService.removeByMap(columnMap);
|
|
|
+ }
|
|
|
+ zyfService.saveBatch(zyfList);
|
|
|
+ for(TasknoAndNd tasknoAndNd : tnWXFList){
|
|
|
+ columnMap = new HashMap<>();
|
|
|
+ columnMap.put("nd",tasknoAndNd.getNd());
|
|
|
+ columnMap.put("taskno",tasknoAndNd.getTaskno());
|
|
|
+ wxfService.removeByMap(columnMap);
|
|
|
+ }
|
|
|
+ wxfService.saveBatch(wxfList);
|
|
|
+ log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
+ //update-end-author:taoyan date:20190528 for:批量插入数据
|
|
|
+ return Result.ok("文件导入成功!数据行数:" + list.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
+ String msg = e.getMessage();
|
|
|
+ log.error(msg, e);
|
|
|
+ if(msg!=null && msg.indexOf("Duplicate entry")>=0){
|
|
|
+ return Result.error("文件导入失败:有重复数据!");
|
|
|
+ }else{
|
|
|
+ return Result.error("文件导入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|