diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java index db2dee7..084f101 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/QxProjectController.java @@ -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); + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java index 5fc57d2..b81fdae 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxProject.java @@ -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; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectImportManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectImportManage.java new file mode 100644 index 0000000..427d942 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectImportManage.java @@ -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; + +/** + *
+ * QxProjectManage + *
+ * + * @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