|
|
@@ -1,8 +1,8 @@ |
|
|
|
package com.ningdatech.pmapi.projectlib.manage; |
|
|
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelReader; |
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
@@ -10,10 +10,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.basic.model.PageVo; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
import com.ningdatech.basic.util.ValidUtil; |
|
|
|
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent; |
|
|
|
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; |
|
|
|
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; |
|
|
|
import com.ningdatech.pmapi.projectlib.helper.ProjectHelper; |
|
|
|
import com.ningdatech.pmapi.projectlib.model.dto.AnnualLibImportDTO; |
|
|
|
import com.ningdatech.pmapi.projectlib.model.entity.Project; |
|
|
|
import com.ningdatech.pmapi.projectlib.model.req.ProjectApprovedReq; |
|
|
|
import com.ningdatech.pmapi.projectlib.model.req.ProjectIdReq; |
|
|
@@ -31,7 +33,6 @@ import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum.*; |
|
|
|
|
|
|
@@ -139,7 +140,60 @@ public class AnnualPlanLibManage { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void importAnnualPlan(MultipartFile file) { |
|
|
|
try (InputStream inputStream = file.getInputStream()) { |
|
|
|
EasyExcel.read(inputStream).sheet(0); |
|
|
|
EasyExcel.read(inputStream, new AnalysisEventListener<AnnualLibImportDTO>() { |
|
|
|
|
|
|
|
private List<Project> records = new ArrayList<>(); |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onException(Exception exception, AnalysisContext context) throws Exception { |
|
|
|
super.onException(exception, context); |
|
|
|
throw BizException.wrap("导入年度计划解析失败"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void invoke(AnnualLibImportDTO data, AnalysisContext context) { |
|
|
|
ValidUtil.valid(data); |
|
|
|
Project project = new Project(); |
|
|
|
project.setId(data.getProjectId()); |
|
|
|
project.setProjectName(data.getProjectName()); |
|
|
|
project.setProjectRemarks(data.getProjectRemarks()); |
|
|
|
project.setEngineeringSpeedOne(data.getEngineeringSpeedOne()); |
|
|
|
project.setEngineeringSpeedTwo(data.getEngineeringSpeedTwo()); |
|
|
|
project.setEngineeringSpeedThree(data.getEngineeringSpeedThree()); |
|
|
|
project.setEngineeringSpeedFour(data.getEngineeringSpeedFour()); |
|
|
|
project.setAnnualPlanAmount(data.getAnnualPlanAmount()); |
|
|
|
project.setDeclareOtherAmount(data.getDeclareOtherAmount()); |
|
|
|
project.setBuildBasis(data.getBuildBasis()); |
|
|
|
project.setBuildOrgName(data.getBuildUnitName()); |
|
|
|
project.setDeclareBankLendingAmount(data.getDeclareBankLendingAmount()); |
|
|
|
project.setDeclareGovOwnFinanceAmount(data.getDeclareGovOwnFinanceAmount()); |
|
|
|
project.setDeclareGovSuperiorFinanceAmount(data.getDeclareGovSuperiorFinanceAmount()); |
|
|
|
project.setDeclareHaveAmount(data.getDeclareHaveAmount()); |
|
|
|
project.setDeclareOtherAmount(data.getDeclareOtherAmount()); |
|
|
|
project.setContactName(data.getContactName()); |
|
|
|
project.setResponsibleMan(data.getResponsibleMan()); |
|
|
|
String[] dataArr = data.getBuildCycle().split("至"); |
|
|
|
project.setBeginTime(dataArr[0].trim()); |
|
|
|
project.setEndTime(dataArr[1].trim()); |
|
|
|
project.setProjectIntroduction(data.getProjectIntroduction()); |
|
|
|
project.setIsFirst(data.getIsFirst().equals("新建") ? 1 : 0); |
|
|
|
records.add(project); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed(AnalysisContext context) { |
|
|
|
if (records.isEmpty()) { |
|
|
|
throw BizException.wrap("导入年度计划为空"); |
|
|
|
} |
|
|
|
List<Long> projectIds = CollUtils.fieldList(records, Project::getId); |
|
|
|
long count = projectService.count(Wrappers.lambdaQuery(Project.class) |
|
|
|
.in(Project::getId, projectIds)); |
|
|
|
if (count != records.size()) { |
|
|
|
throw BizException.wrap("请确保所有项目都存在"); |
|
|
|
} |
|
|
|
projectService.updateBatchById(records); |
|
|
|
} |
|
|
|
}).sheet(0).doReadSync(); |
|
|
|
} catch (IOException e) { |
|
|
|
throw BizException.wrap("导入年度计划失败"); |
|
|
|
} |
|
|
|