Browse Source

Merge branch '20230904-project-collection-2.0' of http://git.ningdatech.com/liushuai/project-management into dev

master
PoffyZhang 1 year ago
parent
commit
6c6d62508f
5 changed files with 343 additions and 25 deletions
  1. +3
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/constant/RegionConst.java
  2. +32
    -25
      pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java
  3. +176
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/collection/SaveCollectionTest331125.java
  4. +53
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/file/CommonInputStreamResource.java
  5. +79
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/file/ProvinceOssTest.java

+ 3
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/constant/RegionConst.java View File

@@ -27,6 +27,9 @@ public interface RegionConst {
String RC_LS_SBJ_IRS = "331101";
//遂昌县
String RC_SC = "331123";
//丽水开发区
String LS_KF = "331118";
String LS_KF_NAME = "开发区";

/**
* 中国行政区划编码


+ 32
- 25
pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java View File

@@ -590,37 +590,44 @@ public class GovProjectCollectionManage {

// 4.保存 建设项目 实施信息
GovBizProjectCimplementDTO cimplement = saveDTO.getCimplement();
BeanUtil.copyProperties(cimplement, draft, CopyOptions.create()
.setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE));
draft.setBaseBidCode(baseProjId + "-1");
draft.setBaseChanFileCimplement(cimplement.getBaseChanFile());
draft.setBaseLogAggregationCimplement(cimplement.getBaseLogAggregation());
draft.setBaseBusinessMetricsCimplement(cimplement.getBaseBusinessMetrics());
draft.setBaseEstaSummFileCimplement(cimplement.getBaseEstaSummFile());
draft.setBaseInforLevelFileCimplement(cimplement.getBaseInforLevelFile());
draft.setBaseEngineerPostpoFileCimplement(cimplement.getBaseEngineerPostpoFile());
draft.setBaseUserConsFileCimplement(cimplement.getBaseUserConsFile());
draft.setBasePasswAssessFileCimplement(cimplement.getBasePasswAssessFile());
draft.setBaseThirdAcceptFileCimplement(cimplement.getBaseThirdAcceptFile());
draft.setBaseFinalExpertOpinionFileCimplement(cimplement.getBaseFinalExpertOpinionFile());
if(Objects.nonNull(cimplement)){
BeanUtil.copyProperties(cimplement, draft, CopyOptions.create()
.setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE));
draft.setBaseBidCode(baseProjId + "-1");
draft.setBaseChanFileCimplement(cimplement.getBaseChanFile());
draft.setBaseLogAggregationCimplement(cimplement.getBaseLogAggregation());
draft.setBaseBusinessMetricsCimplement(cimplement.getBaseBusinessMetrics());
draft.setBaseEstaSummFileCimplement(cimplement.getBaseEstaSummFile());
draft.setBaseInforLevelFileCimplement(cimplement.getBaseInforLevelFile());
draft.setBaseEngineerPostpoFileCimplement(cimplement.getBaseEngineerPostpoFile());
draft.setBaseUserConsFileCimplement(cimplement.getBaseUserConsFile());
draft.setBasePasswAssessFileCimplement(cimplement.getBasePasswAssessFile());
draft.setBaseThirdAcceptFileCimplement(cimplement.getBaseThirdAcceptFile());
draft.setBaseFinalExpertOpinionFileCimplement(cimplement.getBaseFinalExpertOpinionFile());
}

// 5.保存 运维项目 实施信息
GovBizProjectMimplementDTO mimplement = saveDTO.getMimplement();
BeanUtil.copyProperties(mimplement, draft, CopyOptions.create()
.setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE));
draft.setBaseLogAggregationMimplement(mimplement.getBaseLogAggregation());
draft.setBaseBusinessMetricsMimplement(mimplement.getBaseBusinessMetrics());
draft.setBaseChanFileMimplement(mimplement.getBaseChanFile());
draft.setBaseEstaSummFileMimplement(mimplement.getBaseEstaSummFile());
draft.setBaseInforLevelFileMimplement(mimplement.getBaseInforLevelFile());
draft.setBaseEngineerPostpoFileMimplement(mimplement.getBaseEngineerPostpoFile());
draft.setBaseThirdAcceptFileMimplement(mimplement.getBaseThirdAcceptFile());
draft.setBaseUserConsFileMimplement(mimplement.getBaseUserConsFile());
draft.setBaseFinalExpertOpinionFileCimplement(mimplement.getBaseFinalExpertOpinionFile());
if(Objects.nonNull(mimplement)){
BeanUtil.copyProperties(mimplement, draft, CopyOptions.create()
.setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE));
draft.setBaseLogAggregationMimplement(mimplement.getBaseLogAggregation());
draft.setBaseBusinessMetricsMimplement(mimplement.getBaseBusinessMetrics());
draft.setBaseChanFileMimplement(mimplement.getBaseChanFile());
draft.setBaseEstaSummFileMimplement(mimplement.getBaseEstaSummFile());
draft.setBaseInforLevelFileMimplement(mimplement.getBaseInforLevelFile());
draft.setBaseEngineerPostpoFileMimplement(mimplement.getBaseEngineerPostpoFile());
draft.setBaseThirdAcceptFileMimplement(mimplement.getBaseThirdAcceptFile());
draft.setBaseUserConsFileMimplement(mimplement.getBaseUserConsFile());
draft.setBaseFinalExpertOpinionFileCimplement(mimplement.getBaseFinalExpertOpinionFile());

}

// 6.保存 采购信息
List<GovBizProjectProcureDTO> procures = saveDTO.getProcures();
draft.setProcure(JSON.toJSONString(procures));
if(Objects.nonNull(procures)){
draft.setProcure(JSON.toJSONString(procures));
}

draftService.saveOrUpdate(draft);



+ 176
- 0
pmapi/src/test/java/com/ningdatech/pmapi/collection/SaveCollectionTest331125.java View File

@@ -0,0 +1,176 @@
package com.ningdatech.pmapi.collection;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.common.constant.BizConst;
import com.ningdatech.pmapi.common.constant.RegionConst;
import com.ningdatech.pmapi.gov.contants.BizProjectContant;
import com.ningdatech.pmapi.gov.manage.GovProjectCollectionManage;
import com.ningdatech.pmapi.gov.model.dto.GovBizProjectApplyDTO;
import com.ningdatech.pmapi.gov.model.dto.GovBizProjectBaseinfoDTO;
import com.ningdatech.pmapi.gov.model.dto.GovBizProjectSaveDTO;
import com.ningdatech.pmapi.gov.model.entity.*;
import com.ningdatech.pmapi.gov.service.*;
import com.ningdatech.pmapi.projectdeclared.utils.GenerateProjectCodeUtil;
import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.*;
import java.time.LocalDateTime;
import java.util.Objects;

/**
* @Classname SaveCollectionTest
* @Description
* @Date 2023/9/4 17:43
* @Author PoffyZhang
*/
public class SaveCollectionTest331125 extends AppTests {//

@Autowired
private GovProjectCollectionManage manage;

@Autowired
private GenerateProjectCodeUtil projectCodeUtil;

@Autowired
private IGovBizProjectBaseinfoService baseinfoService;
@Autowired
private IGovBizProjectApplyService applyService;
@Autowired
private IGovBizProjectApproveService approveService;
@Autowired
private IGovBizProjectCimplementService cimplementService;
@Autowired
private IGovBizProjectMimplementService mimplementService;
@Autowired
private IGovBizProjectProcureService procureService;

@Test
public void importData() throws Exception {
Workbook wb;
File f = new File("C:\\Users\\PoffyZhang\\Desktop\\丽水市项目底数清单.xlsx");
wb = readExcel(new FileInputStream(f),f.getName());
Row row = null;
if(wb != null) {
//获取第一个sheet
Sheet sheet = wb.getSheetAt(0);
//获取最大行数
int rownum = sheet.getPhysicalNumberOfRows();

//获取第一行
row = sheet.getRow(0);
//获取最大列数
for (int i = 1; i < rownum; i++) {
row = sheet.getRow(i);
if(Objects.isNull(row) || Objects.isNull(row.getCell(0))){
break;
}
GovBizProjectSaveDTO saveDTO = new GovBizProjectSaveDTO();

GovBizProjectBaseinfoDTO baseinfoDTO = new GovBizProjectBaseinfoDTO();
//
String projName = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
baseinfoDTO.setBaseProjName(projName);
baseinfoDTO.setBaseAreaCode(RegionConst.LS_KF + BizConst.NINE_AREA_CODE_LAST);
baseinfoDTO.setBaseAreaName(RegionConst.LS_KF_NAME);
baseinfoDTO.setAreaCode(RegionConst.RC_LS);
baseinfoDTO.setIsEffective(BizProjectContant.ProjectCollection.IS_EFFECTIVE);
baseinfoDTO.setTongTime(LocalDateTime.now());
baseinfoDTO.setBizTime(LocalDateTime.now());
baseinfoDTO.setOp("insert");
String principal = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
baseinfoDTO.setBaseProjPrincipal(principal);
String contacts = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
baseinfoDTO.setBaseProjContacts(contacts);
baseinfoDTO.setBaseProjType("01");
saveDTO.setBaseinfo(baseinfoDTO);

GovBizProjectApplyDTO applyDTO = new GovBizProjectApplyDTO();
String baseProjSetYear = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
applyDTO.setBaseProjSetYear(baseProjSetYear);
String baseProjIntro = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;
applyDTO.setBaseProjIntro(baseProjIntro);
saveDTO.setApply(applyDTO);
//生产编号
String projId = projectCodeUtil.generateProjectCode(saveDTO);
saveDTO.setBaseProjId(projId);
saveDTO.getBaseinfo().setBaseProjId(projId);
saveDTO.getApply().setBaseProjId(projId);
UserInfoDetails user = new UserInfoDetails();
user.setRegionCode(RegionConst.LS_KF);
user.setUsername("系统导入");
String save = "";
try{
GovBizProjectBaseinfo old = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class)
.eq(GovBizProjectBaseinfo::getBaseProjName, projName)
.last(BizConst.LIMIT_1));
if(Objects.isNull(old)){
save = manage.save(saveDTO, user);
}else{
System.out.println(projName + ",重复了 要改到经开区里");
String newProjId = old.getBaseProjId().replace("331100000","331118000");
baseinfoService.update(Wrappers.lambdaUpdate(GovBizProjectBaseinfo.class)
.eq(GovBizProjectBaseinfo::getBaseProjName, projName)
.eq(GovBizProjectBaseinfo::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectBaseinfo::getBaseAreaCode,RegionConst.LS_KF + BizConst.NINE_AREA_CODE_LAST)
.set(GovBizProjectBaseinfo::getBaseProjId,newProjId));
applyService.update(Wrappers.lambdaUpdate(GovBizProjectApply.class)
.eq(GovBizProjectApply::getBaseProjName, projName)
.eq(GovBizProjectApply::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectApply::getBaseProjId,newProjId));
approveService.update(Wrappers.lambdaUpdate(GovBizProjectApprove.class)
.eq(GovBizProjectApprove::getBaseProjName, projName)
.eq(GovBizProjectApprove::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectApprove::getBaseProjId,newProjId));
cimplementService.update(Wrappers.lambdaUpdate(GovBizProjectCimplement.class)
.eq(GovBizProjectCimplement::getBaseProjName, projName)
.eq(GovBizProjectCimplement::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectCimplement::getBaseProjId,newProjId));
mimplementService.update(Wrappers.lambdaUpdate(GovBizProjectMimplement.class)
.eq(GovBizProjectMimplement::getBaseProjName, projName)
.eq(GovBizProjectMimplement::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectMimplement::getBaseProjId,newProjId));
procureService.update(Wrappers.lambdaUpdate(GovBizProjectProcure.class)
.eq(GovBizProjectProcure::getBaseProjName, projName)
.eq(GovBizProjectProcure::getBaseProjId, old.getBaseProjId())
.set(GovBizProjectProcure::getBaseProjId,newProjId));
}
}catch (Exception e){
e.printStackTrace();
}
System.out.println(JSON.toJSONString(save));
}
}

System.out.println("导入完成");
}

//这个下面是单独函数
public static Workbook readExcel(InputStream is, String extString){
Workbook wb = null;
extString = extString.substring(extString.lastIndexOf("."));
try {
if(".xls".equals(extString)){
return wb = new HSSFWorkbook(is);
}else if(".xlsx".equals(extString)){
return wb = new XSSFWorkbook(is);
}else {
return wb = null;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return wb;
}
}

+ 53
- 0
pmapi/src/test/java/com/ningdatech/pmapi/file/CommonInputStreamResource.java View File

@@ -0,0 +1,53 @@
package com.ningdatech.pmapi.file;

import org.springframework.core.io.InputStreamResource;

import java.io.InputStream;

public class CommonInputStreamResource extends InputStreamResource {
/***
* 文件長度
*/
private int length;
/***
* 文件名稱
*/
private String fileName;
public CommonInputStreamResource(InputStream inputStream) {
super(inputStream);
}
public CommonInputStreamResource(InputStream inputStream, int length,String fileName) {
super(inputStream);
this.length = length;
this.fileName = fileName;
}
/**
* 覆写父类方法
* 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
* {@code The multi-part request contained parameter data (excluding uploaded files) that exceeded}
*
* @return
*/
@Override
public String getFilename() {
return this.fileName;
}
/**
* 覆写父类 contentLength 方法
* 因为 {@link org.springframework.core.io.AbstractResource#contentLength()}方法会重新读取一遍文件,
* 而上传文件时,restTemplate 会通过这个方法获取大小。然后当真正需要读取内容的时候,发现已经读完,会报如下错误。
* <code>
* java.lang.IllegalStateException: InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times
* at org.springframework.core.io.InputStreamResource.getInputStream(InputStreamResource.java:96)
* </code>
* <p>
* ref:com.amazonaws.services.s3.model.S3ObjectInputStream#available()
*
* @return
*/
@Override
public long contentLength() {
int estimate = length;
return estimate == 0 ? 1 : estimate;
}
}

+ 79
- 0
pmapi/src/test/java/com/ningdatech/pmapi/file/ProvinceOssTest.java View File

@@ -0,0 +1,79 @@
package com.ningdatech.pmapi.file;

import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.File;
import java.io.FileInputStream;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.mock.web.MockMultipartFile;
import org.apache.http.entity.ContentType;
import java.io.*;

/**
* @Classname ProvinceOssTest
* @Description
* @Date 2023/9/5 14:21
* @Author PoffyZhang
*/
public class ProvinceOssTest {

@Test
public void test() throws FileNotFoundException {
File f = new File("C:\\Users\\PoffyZhang\\Desktop\\市本级组织code已核对.xlsx");
String url = "https://pms.zj.gov.cn/prometheus-zhejiang_file_service/api/v1/file/uploadFile";
MultiValueMap<String,Object> params = new LinkedMultiValueMap<>();
byte[] fileBytes = getBytesByFile(f);
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytes);
CommonInputStreamResource commonInputStreamResource = new CommonInputStreamResource(inputStream,fileBytes.length,f.getName());
params.add("file",commonInputStreamResource);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("multipart/form-data");
headers.setContentType(type);
HttpEntity<MultiValueMap> formEntity = new HttpEntity(params, headers);
ResponseEntity<String> res = restTemplate.postForEntity(url, formEntity, String.class);
System.out.println(res);
}

public static MultipartFile getMultipartFile(File file) {
try{
FileInputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
return multipartFile;
}catch (Exception e){
e.printStackTrace();
}
return null;
}

//将文件转换成Byte数组
public static byte[] getBytesByFile(File file) {
try {
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
byte[] b = new byte[1000];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
byte[] data = bos.toByteArray();
bos.close();
return data;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

Loading…
Cancel
Save