|
@@ -1,6 +1,9 @@ |
|
|
package com.ningdatech.pmapi.projectlib.manage; |
|
|
package com.ningdatech.pmapi.projectlib.manage; |
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader; |
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
@@ -13,12 +16,15 @@ import com.ningdatech.basic.model.PageVo; |
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
import com.ningdatech.basic.util.ValidUtil; |
|
|
import com.ningdatech.basic.util.ValidUtil; |
|
|
import com.ningdatech.pmapi.common.constant.CommonConst; |
|
|
import com.ningdatech.pmapi.common.constant.CommonConst; |
|
|
|
|
|
import com.ningdatech.pmapi.common.enumeration.CommonEnum; |
|
|
import com.ningdatech.pmapi.common.helper.UserInfoHelper; |
|
|
import com.ningdatech.pmapi.common.helper.UserInfoHelper; |
|
|
import com.ningdatech.pmapi.common.model.entity.ExcelExportWriter; |
|
|
import com.ningdatech.pmapi.common.model.entity.ExcelExportWriter; |
|
|
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; |
|
|
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; |
|
|
import com.ningdatech.pmapi.common.util.ExcelDownUtil; |
|
|
import com.ningdatech.pmapi.common.util.ExcelDownUtil; |
|
|
import com.ningdatech.pmapi.datascope.model.DataScopeDTO; |
|
|
import com.ningdatech.pmapi.datascope.model.DataScopeDTO; |
|
|
import com.ningdatech.pmapi.datascope.utils.DataScopeUtil; |
|
|
import com.ningdatech.pmapi.datascope.utils.DataScopeUtil; |
|
|
|
|
|
import com.ningdatech.pmapi.projectlib.constant.ImportTemplateConstant; |
|
|
|
|
|
import com.ningdatech.pmapi.projectlib.enumeration.ImportTemplateEnum; |
|
|
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; |
|
|
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; |
|
|
import com.ningdatech.pmapi.projectlib.helper.ProjectHelper; |
|
|
import com.ningdatech.pmapi.projectlib.helper.ProjectHelper; |
|
|
import com.ningdatech.pmapi.projectlib.model.dto.AnnualLibImportDTO; |
|
|
import com.ningdatech.pmapi.projectlib.model.dto.AnnualLibImportDTO; |
|
@@ -35,6 +41,7 @@ import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; |
|
|
import com.ningdatech.pmapi.user.util.LoginUserUtil; |
|
|
import com.ningdatech.pmapi.user.util.LoginUserUtil; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
@@ -42,6 +49,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
import static com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum.*; |
|
|
import static com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum.*; |
|
@@ -162,65 +170,109 @@ public class AnnualPlanLibManage { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void importAnnualPlan(MultipartFile file) { |
|
|
|
|
|
try (InputStream inputStream = file.getInputStream()) { |
|
|
|
|
|
EasyExcel.read(inputStream, new AnalysisEventListener<AnnualLibImportDTO>() { |
|
|
|
|
|
|
|
|
|
|
|
private final List<Project> records = new ArrayList<>(); |
|
|
|
|
|
|
|
|
public void importAnnualPlan(ImportTemplateEnum template, MultipartFile file) { |
|
|
|
|
|
String contentType = file.getContentType(); |
|
|
|
|
|
if (!contentType.equals(ExcelUtil.XLS_CONTENT_TYPE) && |
|
|
|
|
|
!contentType.equals(ExcelUtil.XLSX_CONTENT_TYPE) |
|
|
|
|
|
) { |
|
|
|
|
|
throw BizException.wrap("导入失败,不支持的文件类型,请按照提供的模板导入文件!"); |
|
|
|
|
|
} |
|
|
|
|
|
try (InputStream inputStream = file.getInputStream(); |
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(inputStream)) { |
|
|
|
|
|
Map<String, String> alias; |
|
|
|
|
|
List<String> title = ImportTemplateConstant.getTemplateTitle(template); |
|
|
|
|
|
switch (template) { |
|
|
|
|
|
case ANNUAL_PLAN: |
|
|
|
|
|
alias = new HashMap<>(title.size()); |
|
|
|
|
|
alias.put(title.get(0), "id"); |
|
|
|
|
|
alias.put(title.get(1), "projectId"); |
|
|
|
|
|
alias.put(title.get(2), "projectName"); |
|
|
|
|
|
alias.put(title.get(3), "projectIntroduction"); |
|
|
|
|
|
alias.put(title.get(4), "buildBasis"); |
|
|
|
|
|
alias.put(title.get(5), "isFirst"); |
|
|
|
|
|
alias.put(title.get(6), "buildCycle"); |
|
|
|
|
|
alias.put(title.get(7), "declaredAmount"); |
|
|
|
|
|
alias.put(title.get(8), "annualPlanAmount"); |
|
|
|
|
|
alias.put(title.get(9), "declareHaveAmount"); |
|
|
|
|
|
alias.put(title.get(10), "declareGovOwnFinanceAmount"); |
|
|
|
|
|
alias.put(title.get(11), "declareGovSuperiorFinanceAmount"); |
|
|
|
|
|
alias.put(title.get(12), "declareBankLendingAmount"); |
|
|
|
|
|
alias.put(title.get(13), "declareOtherAmount"); |
|
|
|
|
|
alias.put(title.get(14), "firstQuarter"); |
|
|
|
|
|
alias.put(title.get(15), "secondQuarter"); |
|
|
|
|
|
alias.put(title.get(16), "thirdQuarter"); |
|
|
|
|
|
alias.put(title.get(17), "fourthQuarter"); |
|
|
|
|
|
alias.put(title.get(18), "buildUnitName"); |
|
|
|
|
|
alias.put(title.get(19), "contactName"); |
|
|
|
|
|
alias.put(title.get(20), "responsibleMan"); |
|
|
|
|
|
alias.put(title.get(21), "projectRemarks"); |
|
|
|
|
|
reader.setHeaderAlias(alias); |
|
|
|
|
|
importAnnualPlanData(reader.readAll(AnnualLibImportDTO.class)); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BizException("不支持的数据导入类型"); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onException(Exception exception, AnalysisContext context) throws Exception { |
|
|
|
|
|
super.onException(exception, context); |
|
|
|
|
|
throw BizException.wrap("导入年度计划解析失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void importAnnualPlanData(List<AnnualLibImportDTO> importDataList) { |
|
|
|
|
|
if (CollectionUtils.isEmpty(importDataList)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
List<Project> projectList = new ArrayList<>(); |
|
|
|
|
|
List<Long> projectIds = CollUtils.fieldList(importDataList, AnnualLibImportDTO::getProjectId); |
|
|
|
|
|
Assert.isTrue(projectIds.size() == importDataList.size(), "项目ID不可重复"); |
|
|
|
|
|
Long userId = LoginUserUtil.getUserId(); |
|
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
|
importDataList.forEach(w -> { |
|
|
|
|
|
Project project = new Project(); |
|
|
|
|
|
project.setCreateBy(userId); |
|
|
|
|
|
project.setCreateOn(now); |
|
|
|
|
|
project.setUpdateBy(userId); |
|
|
|
|
|
project.setUpdateOn(now); |
|
|
|
|
|
|
|
|
@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("新建".equals(data.getIsFirst()) ? 1 : 0); |
|
|
|
|
|
records.add(project); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
project.setId(w.getProjectId()); |
|
|
|
|
|
project.setProjectName(w.getProjectName()); |
|
|
|
|
|
project.setProjectIntroduction(w.getProjectIntroduction()); |
|
|
|
|
|
// 建设依据(立项依据忽略) |
|
|
|
|
|
if (CommonConst.NEW_CONSTRUCTION.equals(w.getIsFirst())){ |
|
|
|
|
|
project.setIsFirst(CommonEnum.YES.getCode()); |
|
|
|
|
|
}else if (CommonConst.CONTINUED_CONSTRUCTION.equals(w.getIsFirst())){ |
|
|
|
|
|
project.setIsFirst(CommonEnum.NO.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
String buildCycle = w.getBuildCycle(); |
|
|
|
|
|
int index = buildCycle.indexOf(CommonConst.MONTH); |
|
|
|
|
|
if (-1 == index){ |
|
|
|
|
|
throw new BizException("项目ID为%s的建设起止年限格式不正确,请按照"); |
|
|
|
|
|
} |
|
|
|
|
|
String beginTime = buildCycle.substring(0, index + 1); |
|
|
|
|
|
project.setBeginTime(beginTime); |
|
|
|
|
|
String endTime = buildCycle.substring(index + 2); |
|
|
|
|
|
project.setEndTime(endTime); |
|
|
|
|
|
project.setDeclareAmount(w.getDeclaredAmount()); |
|
|
|
|
|
project.setAnnualPlanAmount(w.getAnnualPlanAmount()); |
|
|
|
|
|
project.setDeclareHaveAmount(w.getDeclareHaveAmount()); |
|
|
|
|
|
project.setDeclareGovOwnFinanceAmount(w.getDeclareGovOwnFinanceAmount()); |
|
|
|
|
|
project.setDeclareGovSuperiorFinanceAmount(w.getDeclareGovSuperiorFinanceAmount()); |
|
|
|
|
|
project.setDeclareBankLendingAmount(w.getDeclareBankLendingAmount()); |
|
|
|
|
|
project.setDeclareOtherAmount(w.getDeclareOtherAmount()); |
|
|
|
|
|
project.setEngineeringSpeedOne(w.getFirstQuarter()); |
|
|
|
|
|
project.setEngineeringSpeedTwo(w.getSecondQuarter()); |
|
|
|
|
|
project.setEngineeringSpeedThree(w.getThirdQuarter()); |
|
|
|
|
|
project.setEngineeringSpeedFour(w.getFourthQuarter()); |
|
|
|
|
|
|
|
|
@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("导入年度计划失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
project.setBuildOrgName(w.getBuildUnitName()); |
|
|
|
|
|
project.setContactName(w.getContactName()); |
|
|
|
|
|
project.setResponsibleMan(w.getResponsibleMan()); |
|
|
|
|
|
project.setProjectRemarks(w.getProjectRemarks()); |
|
|
|
|
|
projectList.add(project); |
|
|
|
|
|
}); |
|
|
|
|
|
LambdaQueryWrapper<Project> delQuery = Wrappers.lambdaQuery(Project.class) |
|
|
|
|
|
.in(Project::getId, projectIds); |
|
|
|
|
|
projectService.remove(delQuery); |
|
|
|
|
|
projectService.saveBatch(projectList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void updateAnnualPlan(ProjectDTO req) { |
|
|
public void updateAnnualPlan(ProjectDTO req) { |
|
@@ -304,4 +356,14 @@ public class AnnualPlanLibManage { |
|
|
} |
|
|
} |
|
|
return user; |
|
|
return user; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
String a = "2023年3月至2023年11月"; |
|
|
|
|
|
int index = a.indexOf("-"); |
|
|
|
|
|
String b = a.substring(0, index + 1); |
|
|
|
|
|
System.out.println(b); |
|
|
|
|
|
String c = a.substring(index + 2); |
|
|
|
|
|
System.out.println(c); |
|
|
|
|
|
} |
|
|
} |
|
|
} |