80 lines
3.3 KiB
Java
80 lines
3.3 KiB
Java
|
|
package com.solution.rule.handler;
|
|||
|
|
|
|||
|
|
import cn.hutool.core.collection.CollUtil;
|
|||
|
|
import cn.hutool.core.util.ObjectUtil;
|
|||
|
|
import com.solution.common.constant.ExceptionConstants;
|
|||
|
|
import com.solution.common.constant.PlatformAndModuleConstants;
|
|||
|
|
import com.solution.rule.domain.PlatformComponent;
|
|||
|
|
import com.solution.rule.domain.RuleParam;
|
|||
|
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
|||
|
|
import com.solution.rule.domain.vo.ComponentCountVO;
|
|||
|
|
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
|||
|
|
import org.springframework.stereotype.Component;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.Iterator;
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 战斗机处理链
|
|||
|
|
* 规则:针对 F22 平台,后端返回的组件数量比前端传递的大1,
|
|||
|
|
* 如果数据库中 F22 平台所有组件总数小于前端数量+1,则返回该总数。
|
|||
|
|
*/
|
|||
|
|
@Component
|
|||
|
|
public class WarplaneHandler extends AbstractRuleChainHandler {
|
|||
|
|
|
|||
|
|
// 组件数量增量常量
|
|||
|
|
private static final long COMPONENT_COUNT_INCREMENT = 1;
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public RuleParam doHandler(RuleParam ruleParam) {
|
|||
|
|
// 1. 参数校验
|
|||
|
|
if (ObjectUtil.isEmpty(ruleParam) || CollUtil.isEmpty(ruleParam.getWeaponModelDTOList())) {
|
|||
|
|
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
List<WeaponModelDTO> dtoList = ruleParam.getWeaponModelDTOList();
|
|||
|
|
List<ComponentCountVO> databaseWeapons = ruleParam.getDatabaseWeapons();
|
|||
|
|
|
|||
|
|
List<PlatformWeaponAggregateVO> resultWeapons = new ArrayList<>();
|
|||
|
|
|
|||
|
|
//TODO获取所有组件以及count
|
|||
|
|
|
|||
|
|
Iterator<WeaponModelDTO> iterator = dtoList.iterator();
|
|||
|
|
while (iterator.hasNext()) {
|
|||
|
|
WeaponModelDTO dto = iterator.next();
|
|||
|
|
if(PlatformAndModuleConstants.RED_NEBO_M_1.equals(dto.getName())){
|
|||
|
|
List<PlatformComponent> components = dto.getComponents();
|
|||
|
|
List<PlatformComponent> componentList = new ArrayList<>();
|
|||
|
|
|
|||
|
|
//遍历前端数据的组件
|
|||
|
|
for (PlatformComponent component : components) {
|
|||
|
|
//遍历数据库数据
|
|||
|
|
for (ComponentCountVO databaseWeapon : databaseWeapons) {
|
|||
|
|
if(component.getName().equals(databaseWeapon.getComponentName())){
|
|||
|
|
PlatformComponent component1 = new PlatformComponent();
|
|||
|
|
component1.setName(databaseWeapon.getComponentName());
|
|||
|
|
if(databaseWeapon.getCount() > component.getNum()){
|
|||
|
|
component1.setNum(component.getNum() + COMPONENT_COUNT_INCREMENT);
|
|||
|
|
}else {
|
|||
|
|
component1.setNum(databaseWeapon.getCount());
|
|||
|
|
}
|
|||
|
|
//TODO 补充基本信息 暂未完成
|
|||
|
|
componentList.add(component1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO();
|
|||
|
|
platformVO.setPlatformName(dto.getName());
|
|||
|
|
platformVO.setComponents(componentList);
|
|||
|
|
resultWeapons.add(platformVO);
|
|||
|
|
iterator.remove();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
ruleParam.setResultWeapons(resultWeapons);
|
|||
|
|
return ruleParam;
|
|||
|
|
|
|||
|
|
// return super.doNextHandler(ruleParam);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|