|
|
@@ -0,0 +1,179 @@ |
|
|
|
package com.ningdatech.pmapi.projectCollection; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
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.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.projectlib.model.entity.Project; |
|
|
|
import com.ningdatech.pmapi.projectlib.service.IProjectService; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
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.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Classname ProjectCollection3Test |
|
|
|
* @Description |
|
|
|
* @Date 2023/9/7 15:08 |
|
|
|
* @Author PoffyZhang |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
public class ProjectCollection3Test extends AppTests { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectBaseinfoService baseinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectApplyService applyService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectApproveService approveService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectCimplementService cimplementService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectMimplementService mimplementService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IGovBizProjectProcureService procureService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GenerateProjectCodeUtil generateProjectCodeUtil; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IProjectService projectService; |
|
|
|
|
|
|
|
@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; |
|
|
|
Integer successed = 0; |
|
|
|
List<String> failed = Lists.newArrayList(); |
|
|
|
if(wb != null) { |
|
|
|
//获取第一个sheet |
|
|
|
Sheet sheet = wb.getSheetAt(0); |
|
|
|
//获取最大行数 |
|
|
|
int rownum = sheet.getPhysicalNumberOfRows(); |
|
|
|
|
|
|
|
//获取第一行 |
|
|
|
row = sheet.getRow(0); |
|
|
|
//获取最大列数 |
|
|
|
for (int i = 0; i < rownum; i++) { |
|
|
|
row = sheet.getRow(i); |
|
|
|
if(Objects.isNull(row) || Objects.isNull(row.getCell(0))){ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
GovBizProjectBaseinfo baseinfo = new GovBizProjectBaseinfo(); |
|
|
|
// |
|
|
|
String projName = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY; |
|
|
|
log.info("projName :{}",projName); |
|
|
|
GovBizProjectBaseinfo base = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) |
|
|
|
.eq(GovBizProjectBaseinfo::getBaseProjName, projName) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(Objects.isNull(base)){ |
|
|
|
log.info("没有匹配项目 :{}",projName); |
|
|
|
failed.add(projName); |
|
|
|
continue; |
|
|
|
} |
|
|
|
//否则 就去恢复 |
|
|
|
String baseProjId = base.getBaseProjId(); |
|
|
|
base.setDeleted(Boolean.FALSE); |
|
|
|
baseinfoService.updateById(base); |
|
|
|
|
|
|
|
GovBizProjectApply apply = applyService.getOne(Wrappers.lambdaQuery(GovBizProjectApply.class) |
|
|
|
.eq(GovBizProjectApply::getBaseProjId, baseProjId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(Objects.nonNull(apply)){ |
|
|
|
apply.setDeleted(Boolean.FALSE); |
|
|
|
applyService.updateById(apply); |
|
|
|
} |
|
|
|
|
|
|
|
GovBizProjectApprove approve = approveService.getOne(Wrappers.lambdaQuery(GovBizProjectApprove.class) |
|
|
|
.eq(GovBizProjectApprove::getBaseProjId, baseProjId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(Objects.nonNull(approve)){ |
|
|
|
approve.setDeleted(Boolean.FALSE); |
|
|
|
approveService.updateById(approve); |
|
|
|
} |
|
|
|
|
|
|
|
GovBizProjectCimplement cimplement = cimplementService.getOne(Wrappers.lambdaQuery(GovBizProjectCimplement.class) |
|
|
|
.eq(GovBizProjectCimplement::getBaseProjId, baseProjId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(Objects.nonNull(cimplement)){ |
|
|
|
cimplement.setDeleted(Boolean.FALSE); |
|
|
|
cimplementService.updateById(cimplement); |
|
|
|
} |
|
|
|
|
|
|
|
GovBizProjectMimplement mimplement = mimplementService.getOne(Wrappers.lambdaQuery(GovBizProjectMimplement.class) |
|
|
|
.eq(GovBizProjectMimplement::getBaseProjId, baseProjId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(Objects.nonNull(mimplement)){ |
|
|
|
mimplement.setDeleted(Boolean.FALSE); |
|
|
|
mimplementService.updateById(mimplement); |
|
|
|
} |
|
|
|
|
|
|
|
List<GovBizProjectProcure> procures = procureService.list(Wrappers.lambdaQuery(GovBizProjectProcure.class) |
|
|
|
.eq(GovBizProjectProcure::getBaseProjId, baseProjId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if(CollUtil.isNotEmpty(procures)){ |
|
|
|
for(GovBizProjectProcure procure : procures){ |
|
|
|
procure.setDeleted(Boolean.FALSE); |
|
|
|
procureService.updateById(procure); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
successed ++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.info("导入完成 :{}个",successed); |
|
|
|
log.info("导入失败 :{}",failed); |
|
|
|
} |
|
|
|
|
|
|
|
//这个下面是单独函数 |
|
|
|
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; |
|
|
|
} |
|
|
|
} |