Procházet zdrojové kódy

增加年度计划导入接口

tags/24080901
WendyYang před 1 rokem
rodič
revize
1d440ff5bf
3 změnil soubory, kde provedl 106 přidání a 5 odebrání
  1. +58
    -4
      pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/AnnualPlanLibManage.java
  2. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/AnnualLibImportDTO.java
  3. +47
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java

+ 58
- 4
pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/AnnualPlanLibManage.java Zobrazit soubor

@@ -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("导入年度计划失败");
}


+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/AnnualLibImportDTO.java Zobrazit soubor

@@ -52,7 +52,7 @@ public class AnnualLibImportDTO {

@NotNull(message = "年度投资额不能为空")
@ExcelProperty("年度投资额")
private BigDecimal annualPlanAMount;
private BigDecimal annualPlanAmount;

@ExcelProperty("自有资金")
@NotNull(message = "自由资金不能为空")


+ 47
- 0
pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java Zobrazit soubor

@@ -1,9 +1,15 @@
package com.ningdatech.pmapi.sys.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.sys.model.entity.Menu;
import com.ningdatech.pmapi.sys.model.entity.RoleMenu;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

@@ -34,4 +40,45 @@ class IMenuServiceTest extends AppTests {
});
}


@Autowired
private IRoleMenuService roleMenuService;

@Test
public void initMenu() {
/*String str = FileUtil.readString("/Users/wendy/Desktop/long_text_2023-02-13-15-28-42.txt", "UTF-8");
List<JSONObject> obj = JSONUtil.toList(str, JSONObject.class);
save(obj, 0);*/
menuService.list().forEach(w -> {
roleMenuService.save(new RoleMenu(){{
setRoleId(1L);
setMenuId(w.getId());
}});
});
}

public void save(List<JSONObject> objs, long parentId) {
objs.forEach(w -> {
Menu menu = new Menu();
menu.setActiveMenu(w.getStr("activeMenu"));
menu.setComponent(w.getStr("component"));
menu.setIcon(w.getStr("icon"));
menu.setPath(w.getStr("path"));
menu.setName(w.getStr("path").replace("/", ""));
menu.setTopMenu(w.getStr("topMenu"));
menu.setTitle(w.getStr("title"));
menu.setHidden(w.getBool("hidden"));
menu.setPid(parentId);
menu.setRedirect(w.getStr("redirect"));
menu.setSort(w.getInt("sort"));
menu.setDataScopeOption("");
menu.setHasDataScope(false);
menuService.save(menu);
List<JSONObject> children = w.getBeanList("children", JSONObject.class);
if (CollUtil.isNotEmpty(children)) {
save(children, menu.getId());
}
});
}

}

Načítá se…
Zrušit
Uložit