package com.vci.ubcs.code.util; import com.vci.ubcs.omd.feign.IAttributeClient; import com.vci.ubcs.omd.util.Tool; import com.vci.ubcs.omd.vo.AttributeVO; import org.springblade.core.tool.api.R; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class AttributeChecker { @Autowired(required = false) private IAttributeClient attributeClient; public static HashMap attrItemMap = new HashMap(); public static List attrItems = new ArrayList(); public void getAllAttribute() { if (attrItems == null) { R> R = attributeClient.getAll(); attrItems=R.getData(); List var4; int var3 = (var4 = attrItems).size(); for(int var2 = 0; var2 < var3; ++var2) { AttributeVO attrItem = var4.get(var2); attrItemMap.put(attrItem.getName(), attrItem); } } } public int isAttrValValid(String attrName, String attrVal) { // if (!BusinessConstants.BO_CONSTANTS.containsKey(attrName.toUpperCase())) { if (attrVal != null && !attrVal.trim().equals("")) { this.getAllAttribute(); AttributeVO attributeVO = (AttributeVO)attrItemMap.get(attrName); if (attributeVO == null) { return 0; } else { String attrType = attributeVO.getTypeKey(); int rs; if (attrType.equals("VTString")) { // rs = this.checkVTStringValValid(attributeVO, attrName, attrVal); rs = 0; } else if (attrType.equals("VTInteger")) { // rs = this.checkVTIntegerValValid(attributeVO, attrName, attrVal); rs = 0; } else if (attrType.equals("VTLong")) { // rs = this.checkVTLongValValid(attributeVO, attrName, attrVal); rs = 0; } else if (attrType.equals("VTDouble")) { // rs = this.checkVTDoubleValValid(attributeVO, attrName, attrVal); rs = 0; } else if (attrType.equals("VTBoolean")) { rs = 0; } else if (attrType.equals("VTImage")) { rs = 0; } else if (attrType.equals("VTDate")) { rs = 0; } else if (attrType.equals("VTTime")) { rs = 0; } else if (attrType.equals("VTDateTime")) { rs = 0; } else if (attrType.equals("VTNote")) { rs = 0; } else if (attrType.equals("VTFilePath")) { rs = 0; } else { rs = 0; } return rs; } } else { return 0; } // } else { // return 0; // } } /*private int checkVTStringValValid(AttributeVO attributeVO, String attrName, String attrVal) { String other =""; int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")); int length = attrVal.length(); return length > maxLength ? 1 : 0; } private int checkVTIntegerValValid(AttributeVO attributeVO, String attrName, String attrVal) { VTInteger obj = new VTInteger(Integer.valueOf(attrVal)); return !obj.checkRageValueByRage(attributeVO.rage) ? 2 : 0; } private int checkVTLongValValid(AttributeVO attributeVO, String attrName, String attrVal) { VTLong obj = new VTLong(Long.valueOf(attrVal)); return !obj.checkRageValueByRage(attributeVO.rage) ? 2 : 0; } private int checkVTDoubleValValid(AttributeVO attributeVO, String attrName, String attrVal) { VTDouble obj = new VTDouble(Double.valueOf(attrVal)); String other = attributeVO.other; int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")); int length = String.valueOf(attrVal).length() - 1; if (length >= maxLength && !obj.checkRageValueByRage(attributeVO.rage)) { return 3; } else if (!obj.checkRageValueByRage(attributeVO.rage)) { return 2; } else { return length >= maxLength ? 1 : 0; } }*/ }