Commit 107c7f4b by yangkuo

增加接口

parent 5ddf32e1
......@@ -76,4 +76,14 @@ public class ConfiguratorV2Controller {
businessKeyHelper.getDataSourceFlag(postValidationInputV2DTO.getBusinessKey()));
}
@ApiOperation(value = "异常验证", notes = "异常验证")
@PostMapping(value = "/tellMeWhy")
@ResponseStatus(HttpStatus.OK)
// @BizLog(action = "异常验证")
public TellMeWhyOutputDTO tellMeWhy(@RequestBody TellMeWhyInputDTO tellMeWhyInputDTO) {
return configuratorV2Service.tellMeWhy(tellMeWhyInputDTO,
businessKeyHelper.getTokenByBusinessKey(tellMeWhyInputDTO.getBusinessKey()),
businessKeyHelper.getDataSourceFlag(tellMeWhyInputDTO.getBusinessKey()));
}
}
package cn.com.uitech.config.dto;
//import com.lenovo.ccb.common.annotation.Key;
//import com.lenovo.ccb.common.annotation.Module;
import lombok.*;
import java.util.List;
/**
* @author leafinsight
*/
@Data
@Getter
@Setter
@NoArgsConstructor
@ToString
//@Module("异常验证")
public class TellMeWhyInputDTO {
// @Key(index=1,description = "业务关键字")
private String businessKey;
private String division;
private String bomCode;
// @Key(index=2,description = "操作人")
private String userCode;
private String role;
private String characteristicCode;
private String characteristicValueCode;
private List<BomInitializeOutputV2DTO.CharacteristicValuesBean> totalCharacteristicList;
private List<PreValidationInputV2DTO.SelectedCharacteristicBean> selectedCharacteristicList;
private String token;
private Boolean forceSelection;
private List<AttributesBeanDTO> attributes;
}
package cn.com.uitech.config.dto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
/**
* @author leafinsight
*/
@Getter
@Setter
@NoArgsConstructor
@ToString
public class TellMeWhyOutputDTO {
private List<String> conflictCharacteristicList;
private List<BomInitializeOutputV2DTO.CharacteristicValuesBean> activeValues;
private List<PreValidationInputV2DTO.SelectedCharacteristicBean> selectedCharacteristicList;
private String message;
private Boolean result;
private Boolean forceSelectionResult;
}
package cn.com.uitech.config.service;
import cn.com.uitech.config.dto.*;
import cn.com.uitech.config.entity.ODData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public interface ConfiguratorV2Service {
......@@ -17,6 +24,7 @@ public interface ConfiguratorV2Service {
*/
PreValidationOutputV2DTO preValidate(PreValidationInputV2DTO preValidationInputV2DTO, String token, String dataSourceFlag) ;
TellMeWhyOutputDTO tellMeWhy(TellMeWhyInputDTO tellMeWhyInputDTO, String token, String dataSourceFlag);
}
......@@ -242,6 +242,7 @@ public class ConfiguratorCacheServiceImpl implements ConfiguratorCacheService {
//是新的VT table
if (!aryData.containsKey(value.getId())) {
ODData odData = new ODData();
//第一个key是行号(lineCode)第二个key是r3Code value是v值code
Map<Integer, Map<String, List<String>>> arySingleVT = new HashMap<>();
Map<String, List<String>> aryLineVT = new HashMap<>();
List<String> aryCV = new ArrayList<>();
......@@ -250,8 +251,7 @@ public class ConfiguratorCacheServiceImpl implements ConfiguratorCacheService {
arySingleVT.put(value.getLinecode(), aryLineVT);
List<String> aryR3Code = new ArrayList<>();
for (ODChar odChar : aryChar
) {
for (ODChar odChar : aryChar ) {
if (value.getId().equals(odChar.getIdVT())) {
aryR3Code.add(odChar.getField().toString());
}
......@@ -263,7 +263,7 @@ public class ConfiguratorCacheServiceImpl implements ConfiguratorCacheService {
} else {
ODData odData = aryData.get(value.getId());
Map<Integer, Map<String, List<String>>> arySingleVT = odData.getAryData();
//是全新的行
//是全新的行 判断是否存在当前的行号 不存在则添加进去
if (!arySingleVT.containsKey((value.getLinecode()))) {
Map<String, List<String>> aryLineVT = new HashMap<>();
List<String> aryCV = new ArrayList<>();
......@@ -273,7 +273,7 @@ public class ConfiguratorCacheServiceImpl implements ConfiguratorCacheService {
aryData.put(value.getId(), odData);
} else {
Map<String, List<String>> aryLineVT = aryData.get(value.getId()).getAryData().get(value.getLinecode());
//是全新的特征
//是全新的特征 判断当前行号下是存在本次循环的特征,没有则直接添加
if (!aryLineVT.containsKey(value.getR3Code().toString())) {
List<String> aryCV = new ArrayList<>();
aryCV.add(value.getR3VCode().toString());
......
......@@ -12,10 +12,7 @@ import cn.com.uitech.config.repository.ModelBasicInfoRepository;
import cn.com.uitech.config.service.ConfiguratorCacheService;
import cn.com.uitech.config.service.ConfiguratorV2Service;
import cn.com.uitech.config.service.OdService;
import cn.com.uitech.config.utils.AttributesBeanUtil;
import cn.com.uitech.config.utils.DateUtil;
import cn.com.uitech.config.utils.HttpUtil;
import cn.com.uitech.config.utils.StringUtil;
import cn.com.uitech.config.utils.*;
import cn.com.uitech.config.vo.AttributesBeanVO;
import cn.com.uitech.config.vo.BOMCVCacheVO;
import cn.com.uitech.config.vo.BOMInitializeExResultVO;
......@@ -2033,5 +2030,312 @@ public class ConfiguratorV2ServiceImpl implements ConfiguratorV2Service {
return modelBasicInfo;
}
/////////////////////////////////////////////异常验证方法开始///////////////////////////////////////
public TellMeWhyOutputDTO tellMeWhy(TellMeWhyInputDTO tellMeWhyInputDTO, String token, String dataSourceFlag) {
if (token == null) {
return null;
}
TellMeWhyOutputDTO tellMeWhyOutputDTO = new TellMeWhyOutputDTO();
String bomCode = tellMeWhyInputDTO.getBomCode();
String r3Code = tellMeWhyInputDTO.getCharacteristicCode();
String r3VCode = tellMeWhyInputDTO.getCharacteristicValueCode();
String division = tellMeWhyInputDTO.getDivision();
//验证是否选配完全
//all
Map<String, List<Integer>> aryCVS = new HashMap<>(tellMeWhyInputDTO.getTotalCharacteristicList().size());
Map<String, Integer> cvDty = new HashMap<>(tellMeWhyInputDTO.getSelectedCharacteristicList().size());
tellMeWhyInputDTO.getTotalCharacteristicList().forEach(a -> aryCVS.put(a.getCharacteristicCode(),
a.getValues().stream().map(Integer::parseInt).collect(Collectors.toList())
));
tellMeWhyInputDTO.getSelectedCharacteristicList().forEach(a -> cvDty.put(a.getCharacteristicCode(), Integer.parseInt(a.getCharacteristicValueCode())));
cvDty.put(r3Code, Integer.parseInt(r3VCode));
Map<Integer, ODData> aryData = getVariantTable(token, bomCode, division, 1, aryCVS, dataSourceFlag);
Map<Integer, Map<String, List<Integer>>> aryResult = getTellMeWhy(r3Code, cvDty, aryData);
List<String> conflictCharacteristicList = new ArrayList<>();
//先把本身也加进去
conflictCharacteristicList.add(tellMeWhyInputDTO.getCharacteristicCode());
for (Integer key : aryResult.keySet()
) {
conflictCharacteristicList.removeAll(aryResult.get(key).keySet());
conflictCharacteristicList.addAll(aryResult.get(key).keySet());
}
//深度排查可选,入参为aryData, aryResult, r3Code, r3VCode, cvDty
List<String> deepConflictCharacteristics = deepInvestigation(aryData, aryResult, r3Code, r3VCode, cvDty, conflictCharacteristicList);
conflictCharacteristicList.removeAll(deepConflictCharacteristics);
conflictCharacteristicList.addAll(deepConflictCharacteristics);
deepConflictCharacteristics = deepInvestigation(aryData, aryResult, r3Code, r3VCode, cvDty, conflictCharacteristicList);
conflictCharacteristicList.removeAll(deepConflictCharacteristics);
conflictCharacteristicList.addAll(deepConflictCharacteristics);
tellMeWhyOutputDTO.setMessage("");
tellMeWhyOutputDTO.setResult(true);
tellMeWhyOutputDTO.setConflictCharacteristicList(conflictCharacteristicList.stream().distinct().collect(Collectors.toList()));
tellMeWhyOutputDTO.setSelectedCharacteristicList(tellMeWhyInputDTO.getSelectedCharacteristicList());
if (tellMeWhyInputDTO.getForceSelection()) {
//移除冲突的特征
tellMeWhyOutputDTO.getSelectedCharacteristicList().removeIf(i -> conflictCharacteristicList.contains(i.getCharacteristicCode())
|| i.getCharacteristicCode().equals(tellMeWhyInputDTO.getCharacteristicCode()));
//从头开始选一下,降低强选失败的概率
PreValidationOutputV2DTO preValidationOutputV2DTO = preValidate(
buildPreValidationInputV2DTO(tellMeWhyInputDTO.getDivision(),
tellMeWhyInputDTO.getBomCode(),
tellMeWhyInputDTO.getBusinessKey(),
tellMeWhyInputDTO.getUserCode(),
token, tellMeWhyInputDTO.getCharacteristicCode(),
tellMeWhyInputDTO.getCharacteristicValueCode(),
new ArrayList<>(),
tellMeWhyInputDTO.getAttributes()
),
token, dataSourceFlag);
//
Map<String, List<String>> activeCharacteristicValues = preValidationOutputV2DTO.getActiveValues().stream().collect(Collectors.toMap(
BomInitializeOutputV2DTO.CharacteristicValuesBean::getCharacteristicCode, BomInitializeOutputV2DTO.CharacteristicValuesBean::getValues
));
tellMeWhyOutputDTO.getSelectedCharacteristicList().removeIf(i ->
activeCharacteristicValues.containsKey(i.getCharacteristicCode())
&& !activeCharacteristicValues.get(i.getCharacteristicCode()).contains(i.getCharacteristicValueCode())
);
preValidationOutputV2DTO = preValidate(
buildPreValidationInputV2DTO(tellMeWhyInputDTO.getDivision(),
tellMeWhyInputDTO.getBomCode(),
tellMeWhyInputDTO.getBusinessKey(),
tellMeWhyInputDTO.getUserCode(),
token, tellMeWhyInputDTO.getCharacteristicCode(),
tellMeWhyInputDTO.getCharacteristicValueCode(),
tellMeWhyInputDTO.getSelectedCharacteristicList(),
tellMeWhyInputDTO.getAttributes()
),
token, dataSourceFlag);
tellMeWhyOutputDTO.setActiveValues(preValidationOutputV2DTO.getActiveValues());
tellMeWhyOutputDTO.setForceSelectionResult(preValidationOutputV2DTO.getResult());
}
return tellMeWhyOutputDTO;
}
@SuppressWarnings("Duplicates")
private Map<Integer, ODData> getVariantTable(String token, String bomCode, String division, int type, Object obj, String dataSourceFlag) {
Map<Integer, ODData> aryData = configuratorCacheService.getVariantTable(token, bomCode, division, dataSourceFlag);
if (obj == null) {
return aryData;
}
//noinspection AlibabaSwitchStatement
switch (type) {
case 1:
Map<String, List<String>> aryCVS = CastUtil.cast(obj);
//处理无效VT
for (Iterator<Map.Entry<Integer, ODData>> it = aryData.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Integer, ODData> item = it.next();
for (String chrCode : item.getValue().getAryChar()
) {
if (!aryCVS.containsKey(chrCode)) {
it.remove();
break;
}
}
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
return aryData;
}
private Map<Integer, Map<String, List<Integer>>> getTellMeWhy(
String r3Code,
Map<String, Integer> cvDty,
Map<Integer, ODData> aryData) {
Map<Integer, Map<String, List<Integer>>> aryResult = new HashMap<>(aryData.size());
if (aryData.size() > 0) {
{
String colName = StringUtil.trimLeadingCharacter(r3Code, '0');
int index = 0;
for (Map.Entry<Integer, ODData> dataEntry : aryData.entrySet()
) {
if (dataEntry.getValue().getAryChar().contains(colName)) {
List<String> aryCharacteristic = CastUtil.cast(StringUtil.intersect(cvDty.keySet(), CastUtil.cast(dataEntry.getValue().getAryChar())));
boolean validOD = false;
//variantTable表需要验证
if (aryCharacteristic.size() > 0) {
for (Map.Entry<Integer, Map<String, List<String>>> entry : dataEntry.getValue().getAryData().entrySet()
) {
boolean invalidRow = false;
for (String characteristic : aryCharacteristic
) {
//假如不匹配已选中的特征值,直接下一行
if (!entry.getValue().get(characteristic).contains(cvDty.get(characteristic).toString())) {
invalidRow = true;
break;
}
}
//找到一行就不用再继续找了
if (!invalidRow) {
validOD = true;
break;
}
}
}
if (!validOD) {
index += 1;
Map<String, List<Integer>> aryItem = new HashMap<>(dataEntry.getValue().getAryChar().size());
for (String characteristic : dataEntry.getValue().getAryChar()) {
if (!characteristic.equals(colName)) {
//当前与选中项冲突
if (cvDty.containsKey(characteristic)) {
aryItem.put(characteristic, new ArrayList<Integer>() {{
add(cvDty.get(characteristic));
}});
} else {
//不存在选中项集合
aryItem.put(characteristic, new ArrayList<Integer>() {{
add(0);
}});
}
}
}
aryResult.put(index, aryItem);
}
}
}
}
}
return aryResult;
}
private List<String> deepInvestigation(Map<Integer, ODData> aryData,
Map<Integer, Map<String, List<Integer>>> aryResult,
String r3Code,
String r3vCode,
Map<String, Integer> cvDty,
List<String> conflictCharacteristicList
) {
List<String> deepConflictCharacteristic = new ArrayList<>();
Map<String, List<String>> conflictCharacteristicValues = new HashMap<>();
if (aryData.size() > 0) {
for (Map.Entry<Integer, ODData> dataEntry : aryData.entrySet()) {
//VT表包含排除的特征
List<String> aryConflictCharacteristics = CastUtil.cast(StringUtil.intersect(conflictCharacteristicList, CastUtil.cast(dataEntry.getValue().getAryChar())));
if (dataEntry.getValue().getAryChar().contains(r3Code) && aryConflictCharacteristics.size() > 0) {
for (Map.Entry<Integer, Map<String, List<String>>> entry : dataEntry.getValue().getAryData().entrySet()) {
if (entry.getValue().get(r3Code).contains(r3vCode)) {
for (String conflictCharacteristic : aryConflictCharacteristics) {
if (conflictCharacteristicValues.containsKey(conflictCharacteristic)) {
conflictCharacteristicValues.get(conflictCharacteristic).removeAll(entry.getValue().get(conflictCharacteristic));
conflictCharacteristicValues.get(conflictCharacteristic).addAll(entry.getValue().get(conflictCharacteristic));
} else {
conflictCharacteristicValues.put(conflictCharacteristic, entry.getValue().get(conflictCharacteristic));
}
}
}
}
}
}
//遍历深度排除
for (Map.Entry<Integer, ODData> dataEntry : aryData.entrySet()) {
//根据已选特征取出所有有效的VT表
List<String> aryCharacteristic = CastUtil.cast(StringUtil.intersect(cvDty.keySet(), CastUtil.cast(dataEntry.getValue().getAryChar())));
//排除的特征所在的VT表
List<String> aryConflictCharacteristic = CastUtil.cast(StringUtil.intersect(conflictCharacteristicList, CastUtil.cast(dataEntry.getValue().getAryChar())));
aryCharacteristic.removeAll(aryConflictCharacteristic);
//要排除当前强选的特征,并且包含排除的特征所在的VT表
if (!aryCharacteristic.contains(r3Code) && aryConflictCharacteristic.size() > 0) {
boolean invalidRow = false;
boolean vtOk = false;
for (Map.Entry<Integer, Map<String, List<String>>> entry : dataEntry.getValue().getAryData().entrySet()) {
for (Map.Entry<String, List<String>> values : conflictCharacteristicValues.entrySet()) {
if (aryConflictCharacteristic.contains(values.getKey())) {
if (StringUtil.intersect(entry.getValue().get(values.getKey()), values.getValue()).size() == 0) {
invalidRow = true;
break;
}
}
}
//所有的排除行都满足了
if (!invalidRow) {
for (String characteristic : aryCharacteristic
) {
//假如不匹配已选中的特征值,直接下一行
if (!entry.getValue().get(characteristic).contains(cvDty.get(characteristic).toString())) {
invalidRow = true;
break;
}
}
//和其他已选特征都吻合,就不用遍历了
if (!invalidRow) {
vtOk = true;
break;
}
}
invalidRow = false;
}
if (!vtOk) {
deepConflictCharacteristic.removeAll(aryCharacteristic);
deepConflictCharacteristic.addAll(aryCharacteristic);
}
}
}
}
return deepConflictCharacteristic;
}
/////////////////////////////////////////////异常验证方法结束///////////////////////////////////////
}
......@@ -3,6 +3,7 @@ server:
spring:
redis:
host: ${REDIS_HOST:10.101.49.3}
port: ${REDIS_PORT:6379}
password: "CiEz-1309"
cto-database: 14
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment