火力规则:java静态方法实现规则
This commit is contained in:
@@ -9,6 +9,7 @@ import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.domain.simplerulepojo.Weapon;
|
||||
import com.solution.rule.domain.simplerulepojo.fact.FactTask;
|
||||
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.domain.ultimately.fact.DroolsFact;
|
||||
@@ -209,8 +210,20 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
//设置Drools全局变量
|
||||
Map<String, Object> globalParams = new HashMap<>();
|
||||
kieSession.setGlobal("globalParams", globalParams);
|
||||
kieSession.insert(globalParams);
|
||||
//获取红方阵营id
|
||||
String redObjectHandleId = getObjectHandle(task);
|
||||
if(ObjectUtil.isEmpty(redObjectHandleId)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
//获取所有武器库
|
||||
List<FireRuleInputRedWeaponElementDTO> allWeapons = task.getEquipments();
|
||||
//获取红方武器库
|
||||
List<FireRuleInputRedWeaponElementDTO> redWeapons = task.getRedWeapons();
|
||||
List<FireRuleInputRedWeaponElementDTO> redWeapons = allWeapons.stream()
|
||||
.filter(weapon -> redObjectHandleId.equals(weapon.getOwnerForceSide()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
//创建返回数据
|
||||
FireRuleOutputVO fireRuleOutputVO = new FireRuleOutputVO();
|
||||
fireRuleOutputVO.setSourceFile(task.getSourceFile());
|
||||
@@ -259,4 +272,15 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
return ruleMapper.findAllBasicPlatformComponents();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取红方阵营id
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
private String getObjectHandle(FireRuleInputDTO task){
|
||||
List<FireRuleInputForceSideDTO> forceSides = task.getForceSides();
|
||||
List<FireRuleInputForceSideDTO> collect = forceSides.stream().filter(f -> "红方".equals(f.getForceSideName())).collect(Collectors.toList());
|
||||
return collect.get(0).getObjectHandle();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user