Browse Source

modify:

1. 区县项目备案数据导入;
tags/24092001
WendyYang 3 months ago
parent
commit
b5a12c1164
3 changed files with 132 additions and 1 deletions
  1. +11
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java
  2. +4
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java
  3. +117
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectImportManage.java

+ 11
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java View File

@@ -1,5 +1,6 @@
package com.hz.pm.api.projectlib.controller;

import com.hz.pm.api.projectlib.manage.QxProjectImportManage;
import com.hz.pm.api.projectlib.manage.QxProjectManage;
import com.hz.pm.api.projectlib.model.dto.MhSystemReplaceInfoVO;
import com.hz.pm.api.projectlib.model.req.*;
@@ -10,7 +11,9 @@ import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;
@@ -30,6 +33,7 @@ import java.util.List;
public class QxProjectController {

private final QxProjectManage qxProjectManage;
private final QxProjectImportManage qxProjectImportManage;

@PostMapping("/submitProjectRecord")
@ApiOperation("项目备案")
@@ -77,4 +81,11 @@ public class QxProjectController {
return qxProjectManage.listReplaceInfo(projectId);
}

@PostMapping("importProject")
@ApiOperation("导入项目")
@PreAuthorize("hasAuthority('SUPER_ADMIN')")
public void importProject(MultipartFile file) {
qxProjectImportManage.importProject(file);
}

}

+ 4
- 1
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java View File

@@ -1,11 +1,11 @@
package com.hz.pm.api.projectlib.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.hz.pm.api.projectlib.model.enumeration.QxProjectStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
@@ -54,6 +54,9 @@ public class QxProject {
@ApiModelProperty("立项批复文件")
private String approvedFile;

@ApiModelProperty("投资总额")
private BigDecimal totalInvest;

@ApiModelProperty("创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createOn;


+ 117
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectImportManage.java View File

@@ -0,0 +1,117 @@
package com.hz.pm.api.projectlib.manage;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hz.pm.api.external.MhFileClient;
import com.hz.pm.api.projectlib.entity.QxProject;
import com.hz.pm.api.projectlib.model.enumeration.QxProjectStatus;
import com.hz.pm.api.projectlib.service.IQxProjectService;
import com.hz.pm.api.user.helper.MhUnitCache;
import com.hz.pm.api.user.model.dto.UnitDTO;
import com.hz.pm.api.user.model.entity.UserInfo;
import com.hz.pm.api.user.service.IUserInfoService;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.file.controller.FileController;
import com.ningdatech.file.entity.vo.result.FileResultVO;
import lombok.RequiredArgsConstructor;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* <p>
* QxProjectManage
* </p>
*
* @author WendyYang
* @since 10:42 2024/8/31
*/
@Component
@RequiredArgsConstructor
public class QxProjectImportManage {

private final IQxProjectService qxProjectService;
private final IUserInfoService userInfoService;
private final MhUnitCache mhUnitCache;
private final MhFileClient mhFileClient;
private final FileController fileController;


private UserInfo getUserInfo(String mhUserId) {
return userInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class)
.eq(UserInfo::getMhUserId, mhUserId)
.last("limit 1"));
}

@Transactional(rollbackFor = Exception.class)
public void importProject(MultipartFile file) {
try (InputStream is = file.getInputStream();
ExcelReader reader = ExcelUtil.getReader(is)) {
List<QxProject> projects = new ArrayList<>();
for (Map<String, Object> map : reader.readAll()) {
QxProject project = new QxProject();
project.setStatus(QxProjectStatus.DECLARED.getCode());
project.setProjectName(MapUtil.getStr(map, "项目名称"));
project.setProjectYear(MapUtil.getInt(map, "年度"));
project.setBuildOrgCode(MapUtil.getLong(map, "单位ID(同单位同步接口)"));
UnitDTO unit = mhUnitCache.getById(project.getBuildOrgCode());
if (unit != null) {
project.setUnitStrip(unit.getType().getStrip().getCode());
}
String totalInvestStr = MapUtil.getStr(map, "项目总投资估算");
if (NumberUtil.isNumber(totalInvestStr)) {
project.setTotalInvest(new BigDecimal(totalInvestStr));
}
project.setBuildOrgName(MapUtil.getStr(map, "单位名称"));
project.setCreateOn(LocalDateTimeUtil.of(MapUtil.getDate(map, "备案时间(时间戳)")));
project.setUpdateOn(project.getCreateOn());
UserInfo userInfo = getUserInfo(MapUtil.getStr(map, "创建人(同用户同步接口)"));
if (userInfo != null) {
project.setCreateBy(userInfo.getCreateBy());
project.setUpdateBy(userInfo.getCreateBy());
}
String constructionFileIds = MapUtil.getStr(map, "建设方案附件(多附件逗号隔开)");
String[] split = constructionFileIds.split(",");
if (split.length > 0) {
String fileIds = Arrays.stream(split).map(w -> {
File tmpFile = mhFileClient.downloadToTmpFile(w);
try (FileInputStream inputStream = new FileInputStream(tmpFile)) {
String mimeType = FileUtil.getMimeType(tmpFile.getPath());
MockMultipartFile multipartFile = new MockMultipartFile(tmpFile.getName(), tmpFile.getName(), mimeType, inputStream);
ApiResponse<FileResultVO> fileRet = fileController.upload(multipartFile, "default");
return fileRet.getData().getId().toString();
} catch (Exception e) {
throw BizException.wrap("建设方案上传失败");
} finally {
tmpFile.deleteOnExit();
}
}).collect(Collectors.joining(","));
project.setConstructionPlanFile(fileIds);
}
projects.add(project);
}
qxProjectService.saveBatch(projects);
} catch (IOException e) {
throw BizException.wrap("数据导入失败");
}
}

}

Loading…
Cancel
Save