1.优化新增编辑项目时可能出现的数组越界异常

2.优化查重流程,查重任务完毕删除ES中存储的索引,减少维护频率
3.优化部分类命名方式,见名知意
This commit is contained in:
panbaolin 2024-10-24 09:51:27 +08:00
parent d4a3244814
commit 890c4642ca
17 changed files with 176 additions and 158 deletions

View File

@ -2,8 +2,7 @@ package com.platform.check.actuator.china;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.parsing.BaseActurtor;
import com.platform.check.actuator.task.TaskCounter; import com.platform.check.actuator.task.TaskCounter;
import com.platform.check.actuator.task.TaskThreadMonitor; import com.platform.check.actuator.task.TaskThreadMonitor;
import com.platform.check.domain.CheckDocTask; import com.platform.check.domain.CheckDocTask;
@ -114,7 +113,7 @@ public abstract class Handler {
* 缓存文件解析执行器 * 缓存文件解析执行器
* @param acturtor * @param acturtor
*/ */
protected void cacheActurtor(BaseActurtor acturtor) { protected void cacheActurtor(AbstractBaseActurtor acturtor) {
TaskThreadMonitor.getInstance().offer(this.checkDocTask.getId(),acturtor); TaskThreadMonitor.getInstance().offer(this.checkDocTask.getId(),acturtor);
} }
} }

View File

@ -1,8 +1,7 @@
package com.platform.check.actuator.china; package com.platform.check.actuator.china;
import java.util.List; import java.util.List;
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.parsing.BaseActurtor;
import com.platform.check.actuator.parsing.ImgParsingActurtor; import com.platform.check.actuator.parsing.ImgParsingActurtor;
import com.platform.check.domain.CheckFile; import com.platform.check.domain.CheckFile;
import com.platform.check.enums.FileSuffix; import com.platform.check.enums.FileSuffix;
@ -46,7 +45,7 @@ public class ImgHandler extends Handler {
} }
if(flag) { if(flag) {
String poolName = "img-parsing-Pool"; String poolName = "img-parsing-Pool";
BaseActurtor imgParsingActurtor = new ImgParsingActurtor(); AbstractBaseActurtor imgParsingActurtor = new ImgParsingActurtor();
imgParsingActurtor.init( imgParsingActurtor.init(
super.checkDocumentService, super.checkDocumentService,
super.checkRepeatedDocumentService, super.checkRepeatedDocumentService,

View File

@ -2,7 +2,7 @@ package com.platform.check.actuator.china;
import java.util.List; import java.util.List;
import com.platform.check.actuator.parsing.BaseActurtor; import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.parsing.PDFParsingGroupActurtor; import com.platform.check.actuator.parsing.PDFParsingGroupActurtor;
import com.platform.check.domain.CheckFile; import com.platform.check.domain.CheckFile;
import com.platform.check.enums.FileSuffix; import com.platform.check.enums.FileSuffix;
@ -46,7 +46,7 @@ public class PDFHandler extends Handler {
} }
if(flag) { if(flag) {
String poolName = "pdf-parsing-Pool"; String poolName = "pdf-parsing-Pool";
BaseActurtor pdfGroupActurtor = new PDFParsingGroupActurtor(); AbstractBaseActurtor pdfGroupActurtor = new PDFParsingGroupActurtor();
pdfGroupActurtor.init( pdfGroupActurtor.init(
super.checkDocumentService, super.checkDocumentService,
super.checkRepeatedDocumentService, super.checkRepeatedDocumentService,

View File

@ -1,8 +1,7 @@
package com.platform.check.actuator.china; package com.platform.check.actuator.china;
import java.util.List; import java.util.List;
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.parsing.BaseActurtor;
import com.platform.check.actuator.parsing.WordParsingActurtor; import com.platform.check.actuator.parsing.WordParsingActurtor;
import com.platform.check.domain.CheckFile; import com.platform.check.domain.CheckFile;
import com.platform.check.enums.FileSuffix; import com.platform.check.enums.FileSuffix;
@ -32,7 +31,7 @@ public class WordHandler extends Handler{
} }
if(flag) { if(flag) {
//如果此次任务是word解析 //如果此次任务是word解析
BaseActurtor wordParsingThread = new WordParsingActurtor(); AbstractBaseActurtor wordParsingThread = new WordParsingActurtor();
wordParsingThread.init( wordParsingThread.init(
super.checkDocTask, super.checkDocTask,
super.checkDocumentService, super.checkDocumentService,

View File

@ -46,7 +46,7 @@ import lombok.Setter;
* @author 86187 * @author 86187
* *
*/ */
public abstract class BaseActurtor extends Thread{ public abstract class AbstractBaseActurtor extends Thread{
@Getter @Setter @Getter @Setter
protected volatile boolean isStop = false; protected volatile boolean isStop = false;

View File

@ -38,7 +38,7 @@ import org.apache.poi.xwpf.usermodel.XWPFParagraph;
* @author 86187 * @author 86187
* *
*/ */
public abstract class DocParsingActurtor extends BaseActurtor{ public abstract class AbstractDocParsingActurtor extends AbstractBaseActurtor{
/** 单步骤占比 */ /** 单步骤占比 */
protected Double stepProportion; protected Double stepProportion;

View File

@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
* *
*/ */
@Slf4j @Slf4j
public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtExceptionHandler{ public class ImgParsingActurtor extends AbstractBaseActurtor implements Thread.UncaughtExceptionHandler{
/** 图片校验单步骤占比 */ /** 图片校验单步骤占比 */
private Double checkStepProportion; private Double checkStepProportion;
@ -101,7 +101,6 @@ public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtE
/** /**
* 解析图片 * 解析图片
* @param fileList
* @throws InterruptedException * @throws InterruptedException
*/ */
private void parseImgs() throws Exception{ private void parseImgs() throws Exception{
@ -153,7 +152,7 @@ public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtE
if(super.isStop) { if(super.isStop) {
return; return;
} }
BaseActurtor wordParsingThread = new ImgWordParsingActurtor(); AbstractBaseActurtor wordParsingThread = new ImgWordParsingActurtor();
wordParsingThread.init( wordParsingThread.init(
checkDocTask, checkDocTask,
checkDocumentService, checkDocumentService,

View File

@ -19,7 +19,7 @@ import cn.textcheck.engine.report.Reporter;
* @author 86187 * @author 86187
* *
*/ */
public class ImgWordParsingActurtor extends DocParsingActurtor{ public class ImgWordParsingActurtor extends AbstractDocParsingActurtor{
/** /**
* 计算任务步骤占比 * 计算任务步骤占比

View File

@ -44,7 +44,7 @@ import cn.hutool.core.util.ArrayUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class PDFParsingActurtor extends BaseActurtor{ public class PDFParsingActurtor extends AbstractBaseActurtor{
/** 存储解析过程中图片和文档路径 */ /** 存储解析过程中图片和文档路径 */
private String sectionPath; private String sectionPath;

View File

@ -38,7 +38,7 @@ import lombok.extern.slf4j.Slf4j;
* *
*/ */
@Slf4j @Slf4j
public class PDFParsingGroupActurtor extends BaseActurtor implements Thread.UncaughtExceptionHandler{ public class PDFParsingGroupActurtor extends AbstractBaseActurtor implements Thread.UncaughtExceptionHandler{
/** 前部分单步骤占比 */ /** 前部分单步骤占比 */
private Double stepProportion; private Double stepProportion;
@ -138,7 +138,7 @@ public class PDFParsingGroupActurtor extends BaseActurtor implements Thread.Unca
if(super.isStop) { if(super.isStop) {
return; return;
} }
BaseActurtor wordParsingThread = new PDFWordParsingActurtor(); AbstractBaseActurtor wordParsingThread = new PDFWordParsingActurtor();
wordParsingThread.init( wordParsingThread.init(
checkDocTask, checkDocTask,
checkDocumentService, checkDocumentService,

View File

@ -13,12 +13,14 @@ import com.platform.check.enums.FileSuffix;
import com.platform.check.enums.PDFParsingSectionPath; import com.platform.check.enums.PDFParsingSectionPath;
import cn.textcheck.engine.pojo.Paper; import cn.textcheck.engine.pojo.Paper;
import cn.textcheck.engine.report.Reporter; import cn.textcheck.engine.report.Reporter;
import org.springframework.util.CollectionUtils;
/** /**
* pdf识别后所属word文档解析 * pdf识别后所属word文档解析
* @author 86187 * @author 86187
* *
*/ */
public class PDFWordParsingActurtor extends DocParsingActurtor{ public class PDFWordParsingActurtor extends AbstractDocParsingActurtor{
/** /**
* 计算任务步骤占比 * 计算任务步骤占比
@ -50,6 +52,15 @@ public class PDFWordParsingActurtor extends DocParsingActurtor{
ProgressQueue.getInstance().offer(backEvent); ProgressQueue.getInstance().offer(backEvent);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
}finally {
//PDF文档查重任务执行完毕删除ES存储的索引索引只用到页码需求查重完毕页码已存储到数据库
if (!CollectionUtils.isEmpty(super.checkFiles)){
for (CheckFile checkFile : super.checkFiles){
if(elasticsearchService.indexExists(checkFile.getId())){
elasticsearchService.deleteIndex(checkFile.getId());
}
}
}
} }
} }

View File

@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j;
* *
*/ */
@Slf4j @Slf4j
public class WordParsingActurtor extends DocParsingActurtor{ public class WordParsingActurtor extends AbstractDocParsingActurtor{
/** /**
* 计算任务步骤占比 * 计算任务步骤占比

View File

@ -2,12 +2,11 @@ package com.platform.check.actuator.task;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.parsing.BaseActurtor;
public class TaskThreadMonitor { public class TaskThreadMonitor {
private final Map<String,BaseActurtor> taskThreadMap = new HashMap<>(); private final Map<String, AbstractBaseActurtor> taskThreadMap = new HashMap<>();
private static TaskThreadMonitor taskThreadMonitor = new TaskThreadMonitor(); private static TaskThreadMonitor taskThreadMonitor = new TaskThreadMonitor();
@ -15,13 +14,13 @@ public class TaskThreadMonitor {
return taskThreadMonitor; return taskThreadMonitor;
} }
public void offer(String taskId,BaseActurtor baseActurtor) { public void offer(String taskId,AbstractBaseActurtor baseActurtor) {
synchronized (taskThreadMap) { synchronized (taskThreadMap) {
taskThreadMap.put(taskId, baseActurtor); taskThreadMap.put(taskId, baseActurtor);
} }
} }
public BaseActurtor take(String taskId){ public AbstractBaseActurtor take(String taskId){
synchronized (taskThreadMap) { synchronized (taskThreadMap) {
if(!taskThreadMap.isEmpty() && taskThreadMap.containsKey(taskId)) { if(!taskThreadMap.isEmpty() && taskThreadMap.containsKey(taskId)) {
return taskThreadMap.get(taskId); return taskThreadMap.get(taskId);

View File

@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.platform.check.actuator.parsing.BaseActurtor; import com.platform.check.actuator.parsing.AbstractBaseActurtor;
import com.platform.check.actuator.task.TaskCounter; import com.platform.check.actuator.task.TaskCounter;
import com.platform.check.actuator.task.TaskQueue; import com.platform.check.actuator.task.TaskQueue;
import com.platform.check.actuator.task.TaskThreadMonitor; import com.platform.check.actuator.task.TaskThreadMonitor;
@ -341,13 +341,14 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
if(Objects.isNull(task)){ if(Objects.isNull(task)){
throw new BusinessException("查重任务不存在!"); throw new BusinessException("查重任务不存在!");
} }
if (StringUtils.isNotBlank(task.getFilterWordFilePath())){ //删除过滤词文件
String filterWordFilePath = task.getFilterWordFilePath(); // if (StringUtils.isNotBlank(task.getFilterWordFilePath())){
File filterWordFile = new File(filterWordFilePath); // String filterWordFilePath = task.getFilterWordFilePath();
if(filterWordFile.exists()){ // File filterWordFile = new File(filterWordFilePath);
FileUtils.deleteDirectory(filterWordFilePath); // if(filterWordFile.exists()){
} // FileUtils.deleteDirectory(filterWordFilePath);
} // }
// }
//删除文档查重任务对应的报告信息 //删除文档查重任务对应的报告信息
checkReportService.deleteReport(taskId); checkReportService.deleteReport(taskId);
//删除关联表 //删除关联表
@ -357,11 +358,11 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
//删除当前查重任务对应的提交/退回记录 //删除当前查重任务对应的提交/退回记录
descriptionService.deleteByTaskId(taskId); descriptionService.deleteByTaskId(taskId);
//删除文档查重任务对应的文件信息 //删除文档查重任务对应的文件信息
String taskFilePath = properties.getTaskFilePath()+File.separator+taskId; // String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
File taskFile = new File(taskFilePath); // File taskFile = new File(taskFilePath);
if(taskFile.exists()){ // if(taskFile.exists()){
FileUtils.deleteDirectory(taskFilePath); // FileUtils.deleteDirectory(taskFilePath);
} // }
//删除任务报告对应文件信息 //删除任务报告对应文件信息
String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId; String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId;
File taskReportFile = new File(taskReportPath); File taskReportFile = new File(taskReportPath);
@ -534,6 +535,10 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
} }
} }
/**
* 从document目录下把原始上传的文件复制到task目录下查重任务使用的文件都在此处
* @param checkTask
*/
private void copyFile(CheckDocTask checkTask){ private void copyFile(CheckDocTask checkTask){
//判断一下任务id是否存在 //判断一下任务id是否存在
if(Objects.nonNull(checkTask.getId())){ if(Objects.nonNull(checkTask.getId())){
@ -574,7 +579,7 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
}else { }else {
//如果此任务正在运行时进行停止的话那么则唤醒任务锁把资源让给其他任务 //如果此任务正在运行时进行停止的话那么则唤醒任务锁把资源让给其他任务
//停止任务线程 //停止任务线程
BaseActurtor acturtor = TaskThreadMonitor.getInstance().take(project.getCurrentTaskId()); AbstractBaseActurtor acturtor = TaskThreadMonitor.getInstance().take(project.getCurrentTaskId());
if(Objects.nonNull(acturtor)) { if(Objects.nonNull(acturtor)) {
acturtor.stopTask(); acturtor.stopTask();
} }

View File

@ -147,4 +147,11 @@ public interface ICheckUnitService extends IService<CheckUnit> {
* @return * @return
*/ */
List<CheckUnit> findByUnitNames(List<String> unitNames); List<CheckUnit> findByUnitNames(List<String> unitNames);
/**
* 添加参数单位
* @param unitName
* @return
*/
CheckUnit saveCheckUnit(String unitName);
} }

View File

@ -50,6 +50,7 @@ import com.platform.system.service.ISysDeptService;
import com.platform.system.service.ISysDictDataService; import com.platform.system.service.ISysDictDataService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -102,87 +103,63 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
if (StringUtils.isBlank(vo.getProcurementContent())){ if (StringUtils.isBlank(vo.getProcurementContent())){
throw new BusinessException(500, "采购内容不能为空"); throw new BusinessException(500, "采购内容不能为空");
} }
if(Objects.isNull(vo.getBidOpeningTime())){
throw new BusinessException(500, "开标时间不能为空!");
}
if(StringUtils.isBlank(vo.getParticipateUnit())){
throw new BusinessException(500, "参与单位不能为空!");
}
if(StringUtils.isBlank(vo.getWinningUnit())){
throw new BusinessException(500, "中标单位不能为空!");
}
//查询当前所有单位名称 //查询当前所有单位名称
LambdaQueryWrapper<CheckUnit> projectQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<CheckUnit> projectQueryWrapper = new LambdaQueryWrapper<>();
List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper); List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper);
//存放单位id //以存储单位名称为key以存储单位id为value
List<String> projectIds = new ArrayList<>(); Map<String,String> unitMap = new LinkedHashMap<>();
//声明项目
CheckProject entity = new CheckProject(); //获取参与单位信息
//判断是否参与单位为空 String units = vo.getParticipateUnit();
if(StringUtils.isNotBlank(vo.getParticipateUnit())){ String[] unitNames = units.split("");
//获取参与单位信息 if(unitNames.length<2){
String units = vo.getParticipateUnit(); throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
//切割单位名称 }
String[] unitNames = units.split(""); List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
//判断单位名称 if(list.size()!=unitNames.length){
if(unitNames.length<2){ throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增");
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开"); }
if(!vo.getParticipateUnit().contains(vo.getWinningUnit())){
throw new BusinessException(500, "中标单位不在参与单位中!");
}
//如果数据库参与单位数据表为空界面表单参与单位不为空直接入库
if(CollectionUtils.isEmpty(checkUnits)){
for (String unitName:unitNames) {
final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
} }
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList()); }else{
if(list.size()!=unitNames.length){ //遍历循环
throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增"); for (String unitName:unitNames) {
} for (int i=0;i<checkUnits.size();i++) {
//判断是否存在单位 如果当前数据库中不存在单位信息 //如果当前单位名称存在于数据库中直接将id添加到集合中
if(checkUnits.size()<=0){ if(checkUnits.get(i).getUnitName().equals(unitName.replaceAll("\\s*",""))){
for (String unitName:unitNames) { unitMap.put(checkUnits.get(i).getUnitName(),checkUnits.get(i).getId());
CheckUnit projectEntity = new CheckUnit(); break;
projectEntity.setUnitName(unitName.replaceAll("\\s*","")); }else {
projectEntity.setUnitCode(String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli())); if(i==checkUnits.size()-1){
if (checkUnitService.checkNameUnique(unitName.replaceAll("\\s*",""), "")) { final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
throw new BusinessException(500, "单位名称已存在,添加失败!"); unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
}
if (checkUnitService.checkNameUnique(projectEntity.getUnitCode(), "")) {
throw new BusinessException(500, "单位编号已存在,添加失败!");
}
checkUnitService.save(projectEntity);
projectIds.add(projectEntity.getId());
}
}else { //如果当前数据库存在单位信息
//遍历循环
for (String unitName:unitNames) {
for (int i=0;i<checkUnits.size();i++) {
//如果当前单位名称存在于数据库中直接将id添加到集合中
if(checkUnits.get(i).getUnitName().equals(unitName.replaceAll("\\s*",""))){
projectIds.add(checkUnits.get(i).getId());
break;
}else {
if(i==checkUnits.size()-1){
//如果当前单位名称不存在则先进行新增再将id添加到集合中
CheckUnit projectEntity = new CheckUnit();
projectEntity.setUnitName(unitName.replaceAll("\\s*",""));
projectEntity.setUnitCode(String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
if (checkUnitService.checkNameUnique(unitName.replaceAll("\\s*",""), "")) {
throw new BusinessException(500, "单位名称已存在,添加失败!");
}
if (checkUnitService.checkNameUnique(projectEntity.getUnitCode(), "")) {
throw new BusinessException(500, "单位编号已存在,添加失败!");
}
checkUnitService.save(projectEntity);
projectIds.add(projectEntity.getId());
}
} }
} }
} }
} }
}
//设置此字段内容为中标单位id
vo.setWinningUnit(unitMap.getOrDefault(vo.getWinningUnit(),StringPool.EMPTY));
} //声明项目
if(Objects.isNull(vo.getBidOpeningTime())){ CheckProject entity = new CheckProject();
throw new BusinessException(500, "开标时间不能为空!"); Object json = JSONArray.toJSON(unitMap.values());
}
//如果中标单位不为空
if(StringUtils.isNotBlank(vo.getWinningUnit())){
List<String> participateUnits = Arrays.asList(vo.getParticipateUnit().split(""));
if(participateUnits.indexOf(vo.getWinningUnit())<0){
throw new BusinessException(500, "中标单位不在参与单位中!");
}
LambdaQueryWrapper<CheckUnit> tenderProjectQueryWrapper = new LambdaQueryWrapper<>();
tenderProjectQueryWrapper.eq(CheckUnit::getUnitName,vo.getWinningUnit().replaceAll("\\s*",""));
CheckUnit checkUnit = checkUnitMapper.selectOne(tenderProjectQueryWrapper);
vo.setWinningUnit(checkUnit.getId());
}
Object json = JSONArray.toJSON(projectIds);
BeanUtils.copyProperties(vo, entity); BeanUtils.copyProperties(vo, entity);
entity.setParticipateUnit(json.toString()); entity.setParticipateUnit(json.toString());
entity.setAuditStatus(AuditStatus.NOT_AUDIT.getCode()); entity.setAuditStatus(AuditStatus.NOT_AUDIT.getCode());
@ -205,67 +182,64 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
if (StringUtils.isBlank(vo.getProcurementContent())){ if (StringUtils.isBlank(vo.getProcurementContent())){
throw new BusinessException(500, "采购内容不能为空"); throw new BusinessException(500, "采购内容不能为空");
} }
if(Objects.isNull(vo.getBidOpeningTime())){
throw new BusinessException(500, "开标时间不能为空!");
}
if(StringUtils.isBlank(vo.getParticipateUnit())){
throw new BusinessException(500, "参与单位不能为空!");
}
if(StringUtils.isBlank(vo.getWinningUnit())){
throw new BusinessException(500, "中标单位不能为空!");
}
//查询当前所有单位名称 //查询当前所有单位名称
LambdaQueryWrapper<CheckUnit> projectQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<CheckUnit> projectQueryWrapper = new LambdaQueryWrapper<>();
List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper); List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper);
List<String> projectIds = new ArrayList<>(); //以存储单位名称为key以存储单位id为value
//声明项目 Map<String,String> unitMap = new LinkedHashMap<>();
CheckProject entity = new CheckProject();
//判断是否参与单位为空 //获取参与单位信息
if(StringUtils.isNotBlank(vo.getParticipateUnit())){ String units = vo.getParticipateUnit();
//获取参与单位信息 String[] unitNames = units.split("");
String units = vo.getParticipateUnit(); if(unitNames.length<2){
String[] unitNames = units.split(""); throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
if(unitNames.length<2){ }
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开"); List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
} if(list.size()!=unitNames.length){
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList()); throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增");
if(list.size()!=unitNames.length){ }
throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增"); if(!vo.getParticipateUnit().contains(vo.getWinningUnit())){
throw new BusinessException(500, "中标单位不在参与单位中!");
}
//如果数据库参与单位数据表为空界面表单参与单位不为空直接入库
if(CollectionUtils.isEmpty(checkUnits)){
for (String unitName:unitNames) {
final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
} }
}else{
//遍历循环 //遍历循环
for (String unitName:unitNames) { for (String unitName:unitNames) {
for (int i=0;i<checkUnits.size();i++) { for (int i=0;i<checkUnits.size();i++) {
//如果当前单位名称存在于数据库中直接将id添加到集合中 //如果当前单位名称存在于数据库中直接将id添加到集合中
if(checkUnits.get(i).getUnitName().equals(unitName.replaceAll("\\s*",""))){ if(checkUnits.get(i).getUnitName().equals(unitName.replaceAll("\\s*",""))){
projectIds.add(checkUnits.get(i).getId()); unitMap.put(checkUnits.get(i).getUnitName(),checkUnits.get(i).getId());
break; break;
}else { }else {
if(i==checkUnits.size()-1){ if(i==checkUnits.size()-1){
//如果当前单位名称不存在则先进行新增再将id添加到集合中 final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
CheckUnit projectEntity = new CheckUnit(); unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
projectEntity.setUnitName(unitName.replaceAll("\\s*",""));
projectEntity.setUnitCode(String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
if (checkUnitService.checkNameUnique(unitName.replaceAll("\\s*",""), "")) {
throw new BusinessException(500, "单位名称已存在,添加失败!");
}
if (checkUnitService.checkNameUnique(projectEntity.getUnitCode(), "")) {
throw new BusinessException(500, "单位编号已存在,添加失败!");
}
checkUnitService.save(projectEntity);
projectIds.add(projectEntity.getId());
} }
} }
} }
} }
} }
if(Objects.isNull(vo.getBidOpeningTime())){ //设置此字段内容为中标单位id
throw new BusinessException(500, "开标时间不能为空!"); vo.setWinningUnit(unitMap.getOrDefault(vo.getWinningUnit(),StringPool.EMPTY));
} //声明项目
//如果中标单位不为空 CheckProject entity = new CheckProject();
if(StringUtils.isNotBlank(vo.getWinningUnit())){
List<String> participateUnits = Arrays.asList(vo.getParticipateUnit().split(""));
if(participateUnits.indexOf(vo.getWinningUnit())<0){
throw new BusinessException(500, "中标单位不在参与单位中!");
}
LambdaQueryWrapper<CheckUnit> tenderProjectQueryWrapper = new LambdaQueryWrapper<>();
tenderProjectQueryWrapper.eq(CheckUnit::getUnitName,vo.getWinningUnit().replaceAll("\\s*",""));
CheckUnit checkUnit = checkUnitMapper.selectOne(tenderProjectQueryWrapper);
vo.setWinningUnit(checkUnit.getId());
}
HiBeanUtils.dataFormatter(vo, entity); HiBeanUtils.dataFormatter(vo, entity);
Object json = JSONArray.toJSON(projectIds); Object json = JSONArray.toJSON(unitMap.values());
entity.setParticipateUnit(json.toString()); entity.setParticipateUnit(json.toString());
return this.updateById(entity); return this.updateById(entity);
} }
@ -451,7 +425,9 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
unitNames+=tenderProject.getUnitName()+""; unitNames+=tenderProject.getUnitName()+"";
} }
} }
result.setParticipateUnit(unitNames.substring(0,unitNames.length()-1)); if(StringUtils.isNotBlank(unitNames)){
result.setParticipateUnit(unitNames.substring(0,unitNames.length()-1));
}
} }
if (StringUtils.isNotBlank(entity.getWinningUnit())) { if (StringUtils.isNotBlank(entity.getWinningUnit())) {
CheckUnit tender = checkUnitService.getById(entity.getWinningUnit()); CheckUnit tender = checkUnitService.getById(entity.getWinningUnit());

View File

@ -2,6 +2,7 @@ package com.platform.project.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.platform.common.exception.BusinessException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
@ -43,8 +44,11 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -625,4 +629,24 @@ public class CheckUnitServiceImpl extends ServiceImpl<CheckUnitMapper, CheckUnit
return checkUnits; return checkUnits;
} }
/**
* 添加参数单位
*
* @param unitName
* @return
*/
@Transactional
@Override
public CheckUnit saveCheckUnit(String unitName) {
//如果当前单位名称不存在则先进行新增再将id添加到集合中
CheckUnit projectEntity = new CheckUnit();
projectEntity.setUnitName(unitName.replaceAll("\\s*",""));
projectEntity.setUnitCode(String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
if (this.checkNameUnique(unitName.replaceAll("\\s*",""), "")) {
throw new BusinessException(500, "单位名称已存在,添加失败!");
}
this.save(projectEntity);
return projectEntity;
}
} }