1.优化新增编辑项目时可能出现的数组越界异常
2.优化查重流程,查重任务完毕删除ES中存储的索引,减少维护频率 3.优化部分类命名方式,见名知意
This commit is contained in:
parent
d4a3244814
commit
890c4642ca
|
@ -2,8 +2,7 @@ package com.platform.check.actuator.china;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
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.TaskThreadMonitor;
|
||||
import com.platform.check.domain.CheckDocTask;
|
||||
|
@ -114,7 +113,7 @@ public abstract class Handler {
|
|||
* 缓存文件解析执行器
|
||||
* @param acturtor
|
||||
*/
|
||||
protected void cacheActurtor(BaseActurtor acturtor) {
|
||||
protected void cacheActurtor(AbstractBaseActurtor acturtor) {
|
||||
TaskThreadMonitor.getInstance().offer(this.checkDocTask.getId(),acturtor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.platform.check.actuator.china;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.platform.check.actuator.parsing.BaseActurtor;
|
||||
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
|
||||
import com.platform.check.actuator.parsing.ImgParsingActurtor;
|
||||
import com.platform.check.domain.CheckFile;
|
||||
import com.platform.check.enums.FileSuffix;
|
||||
|
@ -46,7 +45,7 @@ public class ImgHandler extends Handler {
|
|||
}
|
||||
if(flag) {
|
||||
String poolName = "img-parsing-Pool";
|
||||
BaseActurtor imgParsingActurtor = new ImgParsingActurtor();
|
||||
AbstractBaseActurtor imgParsingActurtor = new ImgParsingActurtor();
|
||||
imgParsingActurtor.init(
|
||||
super.checkDocumentService,
|
||||
super.checkRepeatedDocumentService,
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.platform.check.actuator.china;
|
|||
|
||||
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.domain.CheckFile;
|
||||
import com.platform.check.enums.FileSuffix;
|
||||
|
@ -46,7 +46,7 @@ public class PDFHandler extends Handler {
|
|||
}
|
||||
if(flag) {
|
||||
String poolName = "pdf-parsing-Pool";
|
||||
BaseActurtor pdfGroupActurtor = new PDFParsingGroupActurtor();
|
||||
AbstractBaseActurtor pdfGroupActurtor = new PDFParsingGroupActurtor();
|
||||
pdfGroupActurtor.init(
|
||||
super.checkDocumentService,
|
||||
super.checkRepeatedDocumentService,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.platform.check.actuator.china;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.platform.check.actuator.parsing.BaseActurtor;
|
||||
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
|
||||
import com.platform.check.actuator.parsing.WordParsingActurtor;
|
||||
import com.platform.check.domain.CheckFile;
|
||||
import com.platform.check.enums.FileSuffix;
|
||||
|
@ -32,7 +31,7 @@ public class WordHandler extends Handler{
|
|||
}
|
||||
if(flag) {
|
||||
//如果此次任务是word解析
|
||||
BaseActurtor wordParsingThread = new WordParsingActurtor();
|
||||
AbstractBaseActurtor wordParsingThread = new WordParsingActurtor();
|
||||
wordParsingThread.init(
|
||||
super.checkDocTask,
|
||||
super.checkDocumentService,
|
||||
|
|
|
@ -46,7 +46,7 @@ import lombok.Setter;
|
|||
* @author 86187
|
||||
*
|
||||
*/
|
||||
public abstract class BaseActurtor extends Thread{
|
||||
public abstract class AbstractBaseActurtor extends Thread{
|
||||
|
||||
@Getter @Setter
|
||||
protected volatile boolean isStop = false;
|
|
@ -38,7 +38,7 @@ import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|||
* @author 86187
|
||||
*
|
||||
*/
|
||||
public abstract class DocParsingActurtor extends BaseActurtor{
|
||||
public abstract class AbstractDocParsingActurtor extends AbstractBaseActurtor{
|
||||
|
||||
/** 单步骤占比 */
|
||||
protected Double stepProportion;
|
|
@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtExceptionHandler{
|
||||
public class ImgParsingActurtor extends AbstractBaseActurtor implements Thread.UncaughtExceptionHandler{
|
||||
|
||||
/** 图片校验单步骤占比 */
|
||||
private Double checkStepProportion;
|
||||
|
@ -101,8 +101,7 @@ public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtE
|
|||
|
||||
/**
|
||||
* 解析图片
|
||||
* @param fileList
|
||||
* @throws InterruptedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void parseImgs() throws Exception{
|
||||
if(CollectionUtils.isNotEmpty(checkFiles) && !super.isStop) {
|
||||
|
@ -153,7 +152,7 @@ public class ImgParsingActurtor extends BaseActurtor implements Thread.UncaughtE
|
|||
if(super.isStop) {
|
||||
return;
|
||||
}
|
||||
BaseActurtor wordParsingThread = new ImgWordParsingActurtor();
|
||||
AbstractBaseActurtor wordParsingThread = new ImgWordParsingActurtor();
|
||||
wordParsingThread.init(
|
||||
checkDocTask,
|
||||
checkDocumentService,
|
||||
|
|
|
@ -19,7 +19,7 @@ import cn.textcheck.engine.report.Reporter;
|
|||
* @author 86187
|
||||
*
|
||||
*/
|
||||
public class ImgWordParsingActurtor extends DocParsingActurtor{
|
||||
public class ImgWordParsingActurtor extends AbstractDocParsingActurtor{
|
||||
|
||||
/**
|
||||
* 计算任务步骤占比
|
||||
|
|
|
@ -44,7 +44,7 @@ import cn.hutool.core.util.ArrayUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class PDFParsingActurtor extends BaseActurtor{
|
||||
public class PDFParsingActurtor extends AbstractBaseActurtor{
|
||||
|
||||
/** 存储解析过程中图片和文档路径 */
|
||||
private String sectionPath;
|
||||
|
|
|
@ -38,7 +38,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class PDFParsingGroupActurtor extends BaseActurtor implements Thread.UncaughtExceptionHandler{
|
||||
public class PDFParsingGroupActurtor extends AbstractBaseActurtor implements Thread.UncaughtExceptionHandler{
|
||||
|
||||
/** 前部分单步骤占比 */
|
||||
private Double stepProportion;
|
||||
|
@ -138,7 +138,7 @@ public class PDFParsingGroupActurtor extends BaseActurtor implements Thread.Unca
|
|||
if(super.isStop) {
|
||||
return;
|
||||
}
|
||||
BaseActurtor wordParsingThread = new PDFWordParsingActurtor();
|
||||
AbstractBaseActurtor wordParsingThread = new PDFWordParsingActurtor();
|
||||
wordParsingThread.init(
|
||||
checkDocTask,
|
||||
checkDocumentService,
|
||||
|
|
|
@ -13,12 +13,14 @@ import com.platform.check.enums.FileSuffix;
|
|||
import com.platform.check.enums.PDFParsingSectionPath;
|
||||
import cn.textcheck.engine.pojo.Paper;
|
||||
import cn.textcheck.engine.report.Reporter;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* pdf识别后所属word文档解析
|
||||
* @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);
|
||||
} catch (Exception 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class WordParsingActurtor extends DocParsingActurtor{
|
||||
public class WordParsingActurtor extends AbstractDocParsingActurtor{
|
||||
|
||||
/**
|
||||
* 计算任务步骤占比
|
||||
|
|
|
@ -2,12 +2,11 @@ package com.platform.check.actuator.task;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.platform.check.actuator.parsing.BaseActurtor;
|
||||
import com.platform.check.actuator.parsing.AbstractBaseActurtor;
|
||||
|
||||
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();
|
||||
|
||||
|
@ -15,13 +14,13 @@ public class TaskThreadMonitor {
|
|||
return taskThreadMonitor;
|
||||
}
|
||||
|
||||
public void offer(String taskId,BaseActurtor baseActurtor) {
|
||||
public void offer(String taskId,AbstractBaseActurtor baseActurtor) {
|
||||
synchronized (taskThreadMap) {
|
||||
taskThreadMap.put(taskId, baseActurtor);
|
||||
}
|
||||
}
|
||||
|
||||
public BaseActurtor take(String taskId){
|
||||
public AbstractBaseActurtor take(String taskId){
|
||||
synchronized (taskThreadMap) {
|
||||
if(!taskThreadMap.isEmpty() && taskThreadMap.containsKey(taskId)) {
|
||||
return taskThreadMap.get(taskId);
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Splitter;
|
||||
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.TaskQueue;
|
||||
import com.platform.check.actuator.task.TaskThreadMonitor;
|
||||
|
@ -341,13 +341,14 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
|
|||
if(Objects.isNull(task)){
|
||||
throw new BusinessException("查重任务不存在!");
|
||||
}
|
||||
if (StringUtils.isNotBlank(task.getFilterWordFilePath())){
|
||||
String filterWordFilePath = task.getFilterWordFilePath();
|
||||
File filterWordFile = new File(filterWordFilePath);
|
||||
if(filterWordFile.exists()){
|
||||
FileUtils.deleteDirectory(filterWordFilePath);
|
||||
}
|
||||
}
|
||||
//删除过滤词文件
|
||||
// if (StringUtils.isNotBlank(task.getFilterWordFilePath())){
|
||||
// String filterWordFilePath = task.getFilterWordFilePath();
|
||||
// File filterWordFile = new File(filterWordFilePath);
|
||||
// if(filterWordFile.exists()){
|
||||
// FileUtils.deleteDirectory(filterWordFilePath);
|
||||
// }
|
||||
// }
|
||||
//删除文档查重任务对应的报告信息
|
||||
checkReportService.deleteReport(taskId);
|
||||
//删除关联表
|
||||
|
@ -357,11 +358,11 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
|
|||
//删除当前查重任务对应的提交/退回记录
|
||||
descriptionService.deleteByTaskId(taskId);
|
||||
//删除文档查重任务对应的文件信息
|
||||
String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
|
||||
File taskFile = new File(taskFilePath);
|
||||
if(taskFile.exists()){
|
||||
FileUtils.deleteDirectory(taskFilePath);
|
||||
}
|
||||
// String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
|
||||
// File taskFile = new File(taskFilePath);
|
||||
// if(taskFile.exists()){
|
||||
// FileUtils.deleteDirectory(taskFilePath);
|
||||
// }
|
||||
//删除任务报告对应文件信息
|
||||
String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId;
|
||||
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){
|
||||
//判断一下任务id是否存在
|
||||
if(Objects.nonNull(checkTask.getId())){
|
||||
|
@ -574,7 +579,7 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
|
|||
}else {
|
||||
//如果此任务正在运行时进行停止的话那么则唤醒任务锁把资源让给其他任务
|
||||
//停止任务线程
|
||||
BaseActurtor acturtor = TaskThreadMonitor.getInstance().take(project.getCurrentTaskId());
|
||||
AbstractBaseActurtor acturtor = TaskThreadMonitor.getInstance().take(project.getCurrentTaskId());
|
||||
if(Objects.nonNull(acturtor)) {
|
||||
acturtor.stopTask();
|
||||
}
|
||||
|
|
|
@ -147,4 +147,11 @@ public interface ICheckUnitService extends IService<CheckUnit> {
|
|||
* @return
|
||||
*/
|
||||
List<CheckUnit> findByUnitNames(List<String> unitNames);
|
||||
|
||||
/**
|
||||
* 添加参数单位
|
||||
* @param unitName
|
||||
* @return
|
||||
*/
|
||||
CheckUnit saveCheckUnit(String unitName);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ import com.platform.system.service.ISysDeptService;
|
|||
import com.platform.system.service.ISysDictDataService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -102,87 +103,63 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
|
|||
if (StringUtils.isBlank(vo.getProcurementContent())){
|
||||
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<>();
|
||||
List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper);
|
||||
//存放单位id
|
||||
List<String> projectIds = new ArrayList<>();
|
||||
//声明项目
|
||||
CheckProject entity = new CheckProject();
|
||||
//判断是否参与单位为空
|
||||
if(StringUtils.isNotBlank(vo.getParticipateUnit())){
|
||||
//获取参与单位信息
|
||||
String units = vo.getParticipateUnit();
|
||||
//切割单位名称
|
||||
String[] unitNames = units.split(",");
|
||||
//判断单位名称
|
||||
if(unitNames.length<2){
|
||||
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
|
||||
//以存储单位名称为key,以存储单位id为value
|
||||
Map<String,String> unitMap = new LinkedHashMap<>();
|
||||
|
||||
//获取参与单位信息
|
||||
String units = vo.getParticipateUnit();
|
||||
String[] unitNames = units.split(",");
|
||||
if(unitNames.length<2){
|
||||
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
|
||||
}
|
||||
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
|
||||
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());
|
||||
}
|
||||
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
|
||||
if(list.size()!=unitNames.length){
|
||||
throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增");
|
||||
}
|
||||
//判断是否存在单位 如果当前数据库中不存在单位信息
|
||||
if(checkUnits.size()<=0){
|
||||
for (String unitName:unitNames) {
|
||||
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());
|
||||
}
|
||||
}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());
|
||||
}
|
||||
}else{
|
||||
//遍历循环
|
||||
for (String unitName:unitNames) {
|
||||
for (int i=0;i<checkUnits.size();i++) {
|
||||
//如果当前单位名称存在于数据库中,直接将id添加到集合中
|
||||
if(checkUnits.get(i).getUnitName().equals(unitName.replaceAll("\\s*",""))){
|
||||
unitMap.put(checkUnits.get(i).getUnitName(),checkUnits.get(i).getId());
|
||||
break;
|
||||
}else {
|
||||
if(i==checkUnits.size()-1){
|
||||
final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
|
||||
unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//设置此字段内容为中标单位id
|
||||
vo.setWinningUnit(unitMap.getOrDefault(vo.getWinningUnit(),StringPool.EMPTY));
|
||||
|
||||
}
|
||||
if(Objects.isNull(vo.getBidOpeningTime())){
|
||||
throw new BusinessException(500, "开标时间不能为空!");
|
||||
}
|
||||
//如果中标单位不为空
|
||||
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);
|
||||
//声明项目
|
||||
CheckProject entity = new CheckProject();
|
||||
Object json = JSONArray.toJSON(unitMap.values());
|
||||
BeanUtils.copyProperties(vo, entity);
|
||||
entity.setParticipateUnit(json.toString());
|
||||
entity.setAuditStatus(AuditStatus.NOT_AUDIT.getCode());
|
||||
|
@ -205,67 +182,64 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
|
|||
if (StringUtils.isBlank(vo.getProcurementContent())){
|
||||
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<>();
|
||||
List<CheckUnit> checkUnits = checkUnitMapper.selectList(projectQueryWrapper);
|
||||
List<String> projectIds = new ArrayList<>();
|
||||
//声明项目
|
||||
CheckProject entity = new CheckProject();
|
||||
//判断是否参与单位为空
|
||||
if(StringUtils.isNotBlank(vo.getParticipateUnit())){
|
||||
//获取参与单位信息
|
||||
String units = vo.getParticipateUnit();
|
||||
String[] unitNames = units.split(",");
|
||||
if(unitNames.length<2){
|
||||
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
|
||||
}
|
||||
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
|
||||
if(list.size()!=unitNames.length){
|
||||
throw new BusinessException("当前输入的参与单位中,有单位名称重复,请检查后重新新增");
|
||||
//以存储单位名称为key,以存储单位id为value
|
||||
Map<String,String> unitMap = new LinkedHashMap<>();
|
||||
|
||||
//获取参与单位信息
|
||||
String units = vo.getParticipateUnit();
|
||||
String[] unitNames = units.split(",");
|
||||
if(unitNames.length<2){
|
||||
throw new BusinessException("参与单位必须两家以上,单位名称间需要用中文,隔开");
|
||||
}
|
||||
List<String> list = Arrays.stream(unitNames).distinct().collect(Collectors.toList());
|
||||
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 (int i=0;i<checkUnits.size();i++) {
|
||||
//如果当前单位名称存在于数据库中,直接将id添加到集合中
|
||||
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;
|
||||
}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());
|
||||
final CheckUnit checkUnit = checkUnitService.saveCheckUnit(unitName);
|
||||
unitMap.put(checkUnit.getUnitName(),checkUnit.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Objects.isNull(vo.getBidOpeningTime())){
|
||||
throw new BusinessException(500, "开标时间不能为空!");
|
||||
}
|
||||
//如果中标单位不为空
|
||||
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());
|
||||
}
|
||||
|
||||
//设置此字段内容为中标单位id
|
||||
vo.setWinningUnit(unitMap.getOrDefault(vo.getWinningUnit(),StringPool.EMPTY));
|
||||
//声明项目
|
||||
CheckProject entity = new CheckProject();
|
||||
HiBeanUtils.dataFormatter(vo, entity);
|
||||
Object json = JSONArray.toJSON(projectIds);
|
||||
Object json = JSONArray.toJSON(unitMap.values());
|
||||
entity.setParticipateUnit(json.toString());
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
@ -451,7 +425,9 @@ public class CheckProjectServiceImpl extends ServiceImpl<CheckProjectMapper, Che
|
|||
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())) {
|
||||
CheckUnit tender = checkUnitService.getById(entity.getWinningUnit());
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.platform.project.service.impl;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.platform.common.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
@ -43,8 +44,11 @@ import org.springframework.beans.BeanUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -625,4 +629,24 @@ public class CheckUnitServiceImpl extends ServiceImpl<CheckUnitMapper, CheckUnit
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user