Browse Source

modify:

1. 状态变更失败报错;
tags/24083001
WendyYang 3 months ago
parent
commit
ce3172882f
4 changed files with 20 additions and 18 deletions
  1. +1
    -3
      hz-pm-api/src/main/java/com/hz/pm/api/common/config/BeanConfig.java
  2. +11
    -13
      hz-pm-api/src/main/java/com/hz/pm/api/common/handler/CpuLoadTask.java
  3. +6
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/statemachine/util/TenderStateMachineUtil.java
  4. +2
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java

+ 1
- 3
hz-pm-api/src/main/java/com/hz/pm/api/common/config/BeanConfig.java View File

@@ -17,14 +17,12 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
@@ -55,7 +53,7 @@ public class BeanConfig {
converterList.remove(converterTarget);
}
HttpMessageConverter<?> converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
converterList.add(1,converter);
converterList.add(1, converter);

MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(


+ 11
- 13
hz-pm-api/src/main/java/com/hz/pm/api/common/handler/CpuLoadTask.java View File

@@ -4,8 +4,8 @@ import cn.hutool.core.date.StopWatch;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.system.oshi.OshiUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.lang.NonNull;
import org.springframework.scheduling.annotation.Scheduled;

@@ -25,16 +25,21 @@ import java.util.stream.Stream;
* @since 20:30 2024/3/5
*/
@Slf4j
@Profile("prod")
@Configuration
@ConditionalOnExpression("${cpu-load-task.open:false}")
public class CpuLoadTask {

private static final int LIMIT_COUNT = 2000000000;
private final AtomicInteger taskNo = new AtomicInteger(0);
public CpuLoadTask() {
CpuLoadThreadFactory threadFactory = new CpuLoadThreadFactory(Thread.MIN_PRIORITY);
fixedThreadPool = Executors.newFixedThreadPool(1, threadFactory);
}

private final ExecutorService fixedThreadPool;

private static final Integer CPU_LIMIT = 20;
private static final int LIMIT_COUNT = 1000000000;
private final AtomicInteger taskNo = new AtomicInteger(0);

private static final ExecutorService FIXED_THREAD_POOL;

private static class CpuLoadThreadFactory implements ThreadFactory {

@@ -53,13 +58,6 @@ public class CpuLoadTask {

}

static {
int logicalProcessorCount = OshiUtil.getProcessor().getLogicalProcessorCount();
int max = Math.max(logicalProcessorCount * CPU_LIMIT / 100, 1);
CpuLoadThreadFactory threadFactory = new CpuLoadThreadFactory(Thread.MIN_PRIORITY);
FIXED_THREAD_POOL = Executors.newFixedThreadPool(max, threadFactory);
}


@Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
public void run() {
@@ -67,7 +65,7 @@ public class CpuLoadTask {
log.info("当前CPU使用率:{}", cpuUsage);
if (cpuUsage < CPU_LIMIT) {
log.info("提交计算任务:{}", taskNo.incrementAndGet());
FIXED_THREAD_POOL.execute(() -> {
fixedThreadPool.execute(() -> {
StopWatch watch = new StopWatch();
watch.start();
long sum = Stream.generate(() -> RandomUtil.randomLong(1, LIMIT_COUNT))


+ 6
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/statemachine/util/TenderStateMachineUtil.java View File

@@ -1,5 +1,6 @@
package com.hz.pm.api.common.statemachine.util;

import cn.hutool.core.util.ObjUtil;
import com.hz.pm.api.common.statemachine.builder.impl.TenderStateMachineBuilderImpl;
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent;
import com.hz.pm.api.projectdeclared.model.entity.Purchase;
@@ -7,6 +8,7 @@ import com.hz.pm.api.projectdeclared.utils.ProjectIdCodeCacheUtil;
import com.hz.pm.api.projectlib.entity.PurchaseStatusChange;
import com.hz.pm.api.projectlib.model.enumeration.status.ITenderStatus;
import com.hz.pm.api.projectlib.service.IPurchaseStatusChangeService;
import com.ningdatech.basic.exception.BizException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
@@ -64,6 +66,10 @@ public class TenderStateMachineUtil implements AbstractStateMachineUtil<Purchase
stateMachine.sendEvent(message);
change.setAfterStatus(purchase.getStatus());
purchaseStatusChangeService.save(change);
if (ObjUtil.equal(change.getBeforeStatus(), change.getBeforeStatus())) {
log.error("状态变更失败:{} {}", purchase, event);
throw BizException.wrap("状态变更失败");
}
log.info("调用状态机后的标段状态为:{}", purchase.getStatus());
}



+ 2
- 2
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java View File

@@ -180,8 +180,8 @@ public class PurchaseManage {
query.exists(ExistsSqlConst.PROJECT_EXISTS_PURCHASE +
" and np.status = {0} ", req.getTabStatus());
} else if (TenderMainStatus.PURCHASE_FINISHED.eq(req.getTabStatus())) {
query.exists(ExistsSqlConst.PROJECT_EXISTS_PURCHASE_STATUS_CHANGE +
" and npsc.event = {0} ", TenderStateChangeEvent.SUBMIT_PURCHASE_CONSTRUCTION_INFO);
query.exists(ExistsSqlConst.PROJECT_EXISTS_STATUS_CHANGE +
" and npsc.event = {0} ", ProjectStateChangeEvent.SUBMIT_PURCHASE_CONTRACT_RECORD);
} else if (ProjectStatus.TO_BE_PURCHASED.eq(req.getTabStatus())) {
query.eq(Project::getStatus, ProjectStatus.TO_BE_PURCHASED.getCode());
} else {


Loading…
Cancel
Save