火力规则:装备匹配规则实现
This commit is contained in:
@@ -12,6 +12,7 @@ import com.solution.rule.domain.ultimately.dto.FireRuleInputDTO;
|
||||
import com.solution.rule.domain.ultimately.dto.FireRuleInputForceSideDTO;
|
||||
import com.solution.rule.domain.ultimately.dto.FireRuleInputRedWeaponElementDTO;
|
||||
import com.solution.rule.domain.ultimately.dto.FireRuleTaskInputDTO;
|
||||
import com.solution.rule.config.FireRuleMatchDefaultParams;
|
||||
import com.solution.rule.domain.ultimately.fact.DroolsFact;
|
||||
import com.solution.rule.domain.ultimately.vo.FireRuleOutputVO;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
@@ -27,6 +28,7 @@ import com.solution.rule.strategy.SceneStrategy;
|
||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||
import org.kie.api.KieBase;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.rule.FactHandle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -197,7 +199,7 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FireRuleOutputVO rule(FireRuleInputDTO task) {
|
||||
public FireRuleOutputVO rule(FireRuleInputDTO task) {
|
||||
if(ObjectUtil.isEmpty(task)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
@@ -207,10 +209,9 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
}
|
||||
//创建KieSession
|
||||
KieSession kieSession = kieBase.newKieSession();
|
||||
//设置Drools全局变量
|
||||
Map<String, Object> globalParams = new HashMap<>();
|
||||
// globalParams.putAll(FireRuleMatchDefaultParams.defaults());
|
||||
kieSession.setGlobal("globalParams", globalParams);
|
||||
kieSession.insert(globalParams);
|
||||
//获取红方阵营id
|
||||
String redObjectHandleId = getObjectHandle(task);
|
||||
if(ObjectUtil.isEmpty(redObjectHandleId)){
|
||||
@@ -229,16 +230,25 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
fireRuleOutputVO.setSourceFile(task.getSourceFile());
|
||||
|
||||
DroolsFact droolsFact = new DroolsFact();
|
||||
droolsFact.setRedWeapons(redWeapons);
|
||||
|
||||
// droolsFact.getFireRuleOutputVO().setRedWeapons(redWeapons);
|
||||
droolsFact.setRedWeapons(new ArrayList<>(redWeapons));
|
||||
droolsFact.setFireRuleOutputVO(fireRuleOutputVO);
|
||||
for (FireRuleTaskInputDTO fireRuleTaskInputDTO : tasks) {
|
||||
droolsFact.setTask(fireRuleTaskInputDTO);
|
||||
kieSession.insert(droolsFact);
|
||||
|
||||
FactHandle droolsFactHandle = null;
|
||||
try {
|
||||
for (FireRuleTaskInputDTO fireRuleTaskInputDTO : tasks) {
|
||||
droolsFact.setTask(fireRuleTaskInputDTO);
|
||||
if (droolsFactHandle == null) {
|
||||
droolsFactHandle = kieSession.insert(droolsFact);
|
||||
} else {
|
||||
kieSession.update(droolsFactHandle, droolsFact);
|
||||
}
|
||||
kieSession.fireAllRules();
|
||||
}
|
||||
} finally {
|
||||
kieSession.dispose();
|
||||
}
|
||||
|
||||
return droolsFact.getFireRuleOutputVO();
|
||||
return fireRuleOutputVO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user