package com.vci.web.service.impl;
|
|
import com.vci.client.common.datatype.VTDouble;
|
import com.vci.client.common.datatype.VTInteger;
|
import com.vci.client.common.datatype.VTLong;
|
import com.vci.client.common.datatype.VTString;
|
import com.vci.client.mw.ClientSessionUtility;
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.omd.atm.AttributeDef;
|
import com.vci.dto.OsAttributeDTO;
|
import com.vci.omd.dataType.VTDataType;
|
import com.vci.pagemodel.OsEnumItemVO;
|
import com.vci.pagemodel.OsEnumVO;
|
import com.vci.pagemodel.OsUsedAttributeVO;
|
import com.vci.starter.poi.bo.WriteExcelData;
|
import com.vci.starter.poi.bo.WriteExcelOption;
|
import com.vci.starter.poi.util.ExcelUtil;
|
import com.vci.starter.web.annotation.log.VciUnLog;
|
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.BaseQueryObject;
|
import com.vci.starter.web.pagemodel.DataGrid;
|
import com.vci.starter.web.util.*;
|
import com.vci.model.OsAttributeDO;
|
import com.vci.pagemodel.OsAttributeVO;
|
import com.vci.web.properties.UsedNames;
|
import com.vci.web.service.OsAttributeServiceI;
|
import com.vci.web.service.OsBaseServiceI;
|
import com.vci.web.service.OsLinkTypeServiceI;
|
import com.vci.web.util.Func;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.swing.*;
|
import java.awt.*;
|
import java.io.File;
|
import java.util.*;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
//import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*;
|
import static com.vci.omd.constants.AttributeConstants.*;
|
|
/**
|
* 属性池服务 --已经调用了平台的服务,因此不在提供Dao层
|
* @author weidy
|
* @date 2021-2-15
|
*/
|
@Service
|
public class OsAttributeServiceImpl implements OsAttributeServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 平台的调用工具类
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 加载自身
|
*/
|
@Autowired(required = false)
|
@Lazy
|
private OsAttributeServiceI self;
|
|
/**
|
* 属性名称最大长度
|
*/
|
private Integer NAME_MAX_LENGTH = 28;
|
|
/**
|
* 系统中变量配置文件中配置的key
|
*/
|
private final String SYSUSEDNAMES = "sysUsedNames";
|
|
/**
|
* 数据库中关键字配置文件中配置的key
|
*/
|
private final String DATABASEUSEDNAMES = "dataBaseUsedNames";
|
|
/**
|
* 链接类型服务
|
*/
|
@Autowired(required = false)
|
@Lazy
|
private OsLinkTypeServiceI osLinkTypeServiceI;
|
|
/**
|
* 业务类型服务
|
*/
|
@Autowired(required = false)
|
@Lazy
|
private OsBtmServiceImpl osBtmService;
|
|
/**
|
* 默认的属性
|
*/
|
private static List<OsAttributeVO> defaultAttributeVOs = new ArrayList<>();
|
|
/**
|
* 默认属性的映射,key是小写
|
*/
|
private static Map<String,OsAttributeVO> defaultAttributeVOMap = new HashMap<>();
|
|
/**
|
* 获取默认的属性
|
* @return 默认的属性列表
|
*/
|
@Override
|
public List<OsAttributeVO> getDefaultAttributeVOs() {
|
return OsAttributeServiceImpl.defaultAttributeVOs;
|
}
|
|
/**
|
* 设置默认的属性
|
* @param defaultAttributeVOs 默认的属性列表
|
*/
|
@Override
|
public void setDefaultAttributeVOs(List<OsAttributeVO> defaultAttributeVOs) {
|
OsAttributeServiceImpl.defaultAttributeVOs = defaultAttributeVOs;
|
}
|
|
/**
|
* 获取的默认属性的映射
|
* @return 默认的属性映射
|
*/
|
@Override
|
public Map<String, OsAttributeVO> getDefaultAttributeVOMap() {
|
return OsAttributeServiceImpl.defaultAttributeVOMap;
|
}
|
|
/**
|
* 设置默认的属性的映射
|
* @param defaultAttributeVOMap 默认的属性映射
|
*/
|
@Override
|
public void setDefaultAttributeVOMap(Map<String, OsAttributeVO> defaultAttributeVOMap) {
|
OsAttributeServiceImpl.defaultAttributeVOMap = defaultAttributeVOMap;
|
}
|
|
/**
|
* 查询所有的属性
|
*
|
* @return 属性的显示对象
|
*/
|
@Override
|
public List<OsAttributeVO> selectAllAttribute() {
|
//后面两个分页数,完全没有用
|
try {
|
return attributeDO2VOs(Arrays.stream(platformClientUtil.getAttributeService().getAttributeDefs("",1,1)).collect(Collectors.toList()));
|
} catch (PLException vciError) {
|
throw WebUtil.getVciBaseException(vciError);
|
}
|
}
|
|
/**
|
* 查询所有的属性映射
|
*
|
* @return key是属性的英文名称小写,value是属性的显示对象
|
*/
|
@Override
|
@VciUnLog
|
public Map<String, OsAttributeVO> selectAllAttributeMap() {
|
return Optional.ofNullable(self.selectAllAttribute()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(),t->t,(o1,o2)->o1));
|
}
|
|
/**
|
* 根据多个属性名称查询属性
|
* @param attrNames
|
* @return
|
*/
|
@Override
|
public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException {
|
VciBaseUtil.alertNotNull(attrNames,"属性名");
|
List<OsAttributeVO> osAttributeVOS = new ArrayList<>();
|
for (int i = 0; i < attrNames.length; i++) {
|
AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefs(attrNames[i],1,1);
|
if(Func.isNotEmpty(attributeDefs)){
|
Arrays.stream(attributeDefs).forEach(attributeDef -> {
|
osAttributeVOS.add(attributeDO2VO(attributeDef));
|
});
|
}
|
}
|
return osAttributeVOS;
|
}
|
|
/**
|
* 属性的数据对象转换为显示对象
|
*
|
* @param attribItems 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public List<OsAttributeVO> attributeDO2VOs(Collection<AttributeDef> attribItems) {
|
List<OsAttributeVO> vos = new ArrayList<>();
|
Optional.ofNullable(attribItems).orElseGet(()->new ArrayList<>()).stream().forEach(attribItem -> {
|
vos.add(attributeDO2VO(attribItem));
|
});
|
return vos;
|
}
|
|
/**
|
* 属性的数据对象转换为显示对象
|
*
|
* @param attribItem 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public OsAttributeVO attributeDO2VO(AttributeDef attribItem) {
|
OsAttributeVO attributeVO = new OsAttributeVO();
|
if(attribItem!=null){
|
attributeVO.setOid(attribItem.oid);
|
attributeVO.setId(attribItem.name);
|
attributeVO.setCreator(attribItem.creator);
|
try {
|
attributeVO.setCreateTime(VciDateUtil.str2Date(String.valueOf(attribItem.createTime),VciDateUtil.DateTimeFormat));
|
attributeVO.setLastModifyTime(VciDateUtil.str2Date(String.valueOf(attribItem.modifyTime),VciDateUtil.DateTimeFormat));
|
attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat));
|
}catch (Throwable e){
|
|
}
|
attributeVO.setLastModifier(attribItem.modifier);
|
attributeVO.setName(attribItem.label);
|
attributeVO.setDescription(attribItem.description);
|
attributeVO.setAttributeDataType(attribItem.vtDataType);
|
attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType));
|
attributeVO.setDefaultValue(attribItem.defValue);
|
attributeVO.setRange(attribItem.rage);
|
attributeVO.setOther(attribItem.other);
|
//处理参照相关属性
|
if(StringUtils.isNotBlank(attribItem.other)) {
|
if (isReferAttr(attribItem.other)) {
|
//说明这个的确是参照字段
|
String[] others = attribItem.other.split(";");
|
for (String s : others) {
|
if (s.toLowerCase().contains("btm") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
|
attributeVO.setBtmTypeId(s.split("=")[1].trim());
|
}
|
//链接类型不支持
|
}
|
}
|
//必输和长度
|
String[] others = attribItem.other.split(";");
|
for (String s : others) {
|
if (s.toLowerCase().contains("allownull") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
|
boolean allownull = false;
|
if (s.split("=")[1].trim().toLowerCase().equals("yes")) {
|
allownull = true;
|
}
|
attributeVO.setNullableFlag(allownull);
|
}
|
if (s.toLowerCase().indexOf("length") > -1 && s.split("=").length > 1) {
|
int length = WebUtil.getInt(s.split("=")[1].trim());
|
if (length > 0) {
|
attributeVO.setAttrLength(length);
|
}
|
}
|
}
|
//枚举
|
if(isEnumAttr(attribItem.other)){
|
for (String s : others) {
|
if(s.contains("enumName") && s.split("=").length>1) {
|
attributeVO.setEnumId(s.split("=")[1].trim());
|
}
|
}
|
}
|
}
|
}
|
return attributeVO;
|
}
|
|
/**
|
* 属性的显示对象转换为数据对象
|
*
|
* @param attributeVO 显示对象
|
* @return 数据对象
|
*/
|
@Override
|
public AttributeDef attributeVO2DO(OsAttributeVO attributeVO) {
|
AttributeDef attribItem = new AttributeDef();
|
attribItem.oid = attributeVO.getOid();
|
attribItem.ts = VciDateUtil.date2Str(attributeVO.getTs(),VciDateUtil.DateTimeFormat);
|
attribItem.creator = attributeVO.getCreator();
|
attribItem.createTime = attributeVO.getCreateTime() != null?attributeVO.getCreateTime().getTime():null;
|
attribItem.modifier = attributeVO.getLastModifier();
|
attribItem.modifyTime = attributeVO.getLastModifyTime() != null ? attributeVO.getLastModifyTime().getTime():null;
|
attribItem.name = attributeVO.getId();
|
attribItem.label = attributeVO.getName();
|
attribItem.description = attributeVO.getDescription() == null ?"":attributeVO.getDescription();
|
attribItem.vtDataType = attributeVO.getAttributeDataType() == null ? VciFieldTypeEnum.VTString.name() : attributeVO.getAttributeDataType();
|
attribItem.defValue = attributeVO.getDefaultValue() == null?"":attributeVO.getDefaultValue();
|
attribItem.rage = attributeVO.getRange() == null ? "" : attributeVO.getRange();
|
//other需要自行处理
|
StringBuffer sb = new StringBuffer();
|
sb.append(ALLOWNULL).append(" = ").append(attributeVO.isNullableFlag() ? "yes" : "no").append(";");
|
VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(attributeVO.getAttributeDataType());
|
String[] otherInfos = attribItem.other.split(";");
|
int length = 0;
|
if(otherInfos!=null&& otherInfos.length > 0){
|
for(String s : otherInfos){
|
if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){
|
length = VciBaseUtil.getInt(s.split("=")[1]);
|
break;
|
}
|
}
|
}
|
switch (fieldTypeEnum) {
|
case VTDouble:
|
if(attributeVO.getAttrLength() == null){
|
attributeVO.setAttrLength(20);
|
}
|
if(attributeVO.getPrecisionLength() == null){
|
attributeVO.setPrecisionLength(2);
|
}
|
sb.append(ACCURACY).append(" = ").append(attributeVO.getPrecisionLength()).append(";");
|
sb.append(LENGTH).append(" = ").append(length > attributeVO.getAttrLength()?length:attributeVO.getAttrLength()).append(";");
|
|
break;
|
case VTInteger:
|
if (StringUtils.isNotBlank(attributeVO.getEnumId())) {
|
sb.append(ENUMNAME).append(" = ").append(attributeVO.getEnumId()).append(";");
|
}
|
break;
|
case VTString:
|
if (StringUtils.isNotBlank(attributeVO.getBtmTypeId())) {
|
//参照
|
sb.append(BTM).append(" = ").append(attributeVO.getBtmTypeId()).append(";");
|
//链接类型暂时不支持
|
}
|
sb.append(LENGTH).append(" = ").append(length > attributeVO.getAttrLength()?length:attributeVO.getAttrLength()).append(";");
|
if (StringUtils.isNotBlank(attributeVO.getEnumId())) {
|
sb.append(ENUMNAME).append(" = ").append(attributeVO.getEnumId()).append(";");
|
}
|
break;
|
default:
|
//不需要处理
|
break;
|
}
|
attribItem.other = sb.toString();
|
if (attribItem.other.endsWith(";")) {
|
attribItem.other = attribItem.other.substring(0, attribItem.other.length() - 1);
|
}
|
return attribItem;
|
}
|
|
/**
|
* 根据属性的名称获取属性对象
|
* @param attrCode 属性英文名称
|
* @return 属性的基本信息
|
*/
|
@Override
|
public OsAttributeVO getAttr(String attrCode) {
|
if(StringUtils.isBlank(attrCode)){
|
return null;
|
}
|
return self.selectAllAttributeMap().getOrDefault(attrCode.toLowerCase(),null);
|
}
|
|
/**
|
* 使用属性编号获取对象--批量
|
*
|
* @param attrCodes 属性的英文名称
|
* @return 属性的显示对象
|
*/
|
@Override
|
public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes) {
|
if(CollectionUtils.isEmpty(attrCodes)){
|
return null;
|
}
|
Map<String, OsAttributeVO> attributeVOMap = self.selectAllAttributeMap();
|
List<OsAttributeVO> attributeVOS = new ArrayList<>();
|
attrCodes.stream().forEach(attrCode->{
|
OsAttributeVO attributeVO = attributeVOMap.getOrDefault(attrCode.toLowerCase(),null);
|
if(attributeVO!=null){
|
attributeVOS.add(attributeVO);
|
}
|
});
|
return attributeVOS;
|
}
|
|
/**
|
* 批量添加属性
|
*
|
* @param attribItemList 属性的列表
|
*/
|
@Override
|
public void batchAddAttribute(List<AttributeDef> attribItemList) {
|
if(!CollectionUtils.isEmpty(attribItemList)){
|
attribItemList.stream().forEach(attribItem -> {
|
try {
|
platformClientUtil.getAttributeService().addAttributeDef(attribItem);
|
} catch (PLException e) {
|
throw WebUtil.getVciBaseException(e);
|
}
|
});
|
}
|
}
|
|
/**
|
* 批量编辑属性
|
* @param editAttrList 属性的列表
|
*/
|
@Override
|
public void batchEditAttribute(List<AttributeDef> editAttrList) {
|
if(!CollectionUtils.isEmpty(editAttrList)){
|
editAttrList.stream().forEach(attribItem -> {
|
try {
|
platformClientUtil.getAttributeService().modifyAttributeDef(attribItem);
|
} catch (PLException e) {
|
throw WebUtil.getVciBaseException(e);
|
}
|
});
|
}
|
}
|
|
/**
|
* 属性列表
|
*
|
* @param baseQueryObject 查询对象
|
* @return 属性的显示对象
|
*/
|
@Override
|
public DataGrid<OsAttributeVO> gridAttribute(BaseQueryObject baseQueryObject) {
|
return gridObject(baseQueryObject, OsAttributeDO.class,self.selectAllAttributeMap(),OsAttributeVO.class);
|
}
|
|
/**
|
* 添加单条属性
|
* @param osAttributeDTO
|
* @return true成功,false失败
|
*/
|
@Override
|
public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
|
//判空
|
VciBaseUtil.alertNotNull(
|
osAttributeDTO,"创建的属性对象",
|
osAttributeDTO.getId(),"属性名称",
|
osAttributeDTO.getAttributeDataType(),"属性类型"
|
);
|
//属性英文名称校验(判空、系统中判重、是否关键字、是否合规等)
|
checkName(osAttributeDTO.getId());
|
//检查默认值与属性类型是否匹配
|
checkDefValue(osAttributeDTO);
|
//dto对象转换为存储所需对象
|
AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
|
return platformClientUtil.getAttributeService().addAttributeDef(attributeDef);
|
}
|
|
/**
|
* 修改单条属性
|
* @param osAttributeDTO
|
* @return true成功,false失败
|
*/
|
@Override
|
public boolean updateAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
|
//判空
|
VciBaseUtil.alertNotNull(
|
osAttributeDTO,"修改的属性对象",
|
osAttributeDTO.getId(),"属性名称",
|
osAttributeDTO.getTs(),"事务TS",
|
osAttributeDTO.getAttributeDataType(),"属性类型"
|
);
|
|
//名称不允许修改所以不用查重
|
//但是需要检查属性是否存在
|
OsAttributeVO osAttributeVO = getByAttributeNames(new String[]{osAttributeDTO.getId()}).get(0);
|
if(Func.isEmpty(osAttributeVO) || Func.isBlank(osAttributeVO.getOid())){
|
throw new PLException("500",new String[]{"属性在系统中不存在,请刷新后重试!"});
|
}
|
//检查默认值与属性类型是否匹配
|
checkDefValue(osAttributeDTO);
|
boolean compatible = isCompatible(osAttributeVO,osAttributeDTO);
|
boolean hasInstance = hasInstance(osAttributeDTO.getName());
|
//产生数据, 并且不兼容
|
if(hasInstance && !compatible){
|
throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"});
|
}
|
String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
|
osAttributeDTO.setLastModifier(userId);
|
osAttributeDTO.setCreator(osAttributeVO.getCreator());
|
osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime());
|
osAttributeDTO.setLastModifyTime(new Date());
|
|
try {
|
AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
|
boolean mdSuccess = platformClientUtil.getAttributeService().modifyAttributeDef(attributeDef);
|
if(!mdSuccess){
|
return false;
|
}
|
|
//属性修改成功,修改业务类型, 链接类型中该属性字段
|
boolean alterApBoolean = this.alterAp(attributeDef.name);
|
if(!alterApBoolean){
|
logger.error("属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!");
|
throw new PLException("500",new String[]{"属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!"});
|
}
|
return true;
|
} catch (PLException e1) {
|
e1.printStackTrace();
|
}
|
return false;
|
}
|
|
/**
|
* DTO对象转实际存储所需的AttributeDef对象
|
* @param osAttributeDTO
|
* @return
|
*/
|
private AttributeDef osAttributeDTO2AttributeDef(OsAttributeDTO osAttributeDTO) {
|
AttributeDef attributeDef = new AttributeDef();
|
attributeDef.name = osAttributeDTO.getId().toLowerCase().replaceAll(" ", "");
|
attributeDef.label = osAttributeDTO.getName();
|
attributeDef.description = osAttributeDTO.getDescription();
|
attributeDef.vtDataType = (String)osAttributeDTO.getAttributeDataType();
|
attributeDef.defValue = Func.isBlank(osAttributeDTO.getDefaultValue()) ? "" : osAttributeDTO.getDefaultValue();
|
attributeDef.rage = Func.isBlank(osAttributeDTO.getRange()) ? "" : osAttributeDTO.getRange();
|
attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator();
|
attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat);
|
attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime();
|
attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier();
|
attributeDef.modifyTime = System.currentTimeMillis();
|
//other需要自行处理
|
StringBuffer sb = new StringBuffer();
|
sb.append(ALLOWNULL).append(" = ").append(osAttributeDTO.isNullableFlag() ? "yes" : "no").append(";");
|
VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(osAttributeDTO.getAttributeDataType());
|
String[] otherInfos = attributeDef.other.split(";");
|
int length = 0;
|
if(otherInfos!=null&& otherInfos.length > 0){
|
for(String s : otherInfos){
|
if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){
|
length = VciBaseUtil.getInt(s.split("=")[1]);
|
break;
|
}
|
}
|
}
|
switch (fieldTypeEnum) {
|
case VTDouble:
|
if(osAttributeDTO.getAttrLength() == null){
|
osAttributeDTO.setAttrLength(20);
|
}
|
if(osAttributeDTO.getPrecisionLength() == null){
|
osAttributeDTO.setPrecisionLength(2);
|
}
|
sb.append(ACCURACY).append(" = ").append(osAttributeDTO.getPrecisionLength()).append(";");
|
sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
|
|
break;
|
case VTInteger:
|
if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
|
sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
|
}
|
break;
|
case VTString:
|
if (StringUtils.isNotBlank(osAttributeDTO.getBtmTypeId())) {
|
//参照
|
sb.append(BTM).append(" = ").append(osAttributeDTO.getBtmTypeId()).append(";");
|
//链接类型暂时不支持
|
}
|
sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
|
if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
|
sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
|
}
|
break;
|
default:
|
//不需要处理
|
break;
|
}
|
attributeDef.other = sb.toString();
|
if (attributeDef.other.endsWith(";")) {
|
attributeDef.other = attributeDef.other.substring(0, attributeDef.other.length() - 1);
|
}
|
return attributeDef;
|
}
|
|
/**
|
* 修改属性时, 判断当前输入的属性是否能兼容之前的属性
|
* @param osAttributeVO 数据库中存储的
|
* @param osAttributeDTO 修改后的内容
|
* @return
|
*/
|
private boolean isCompatible(OsAttributeVO osAttributeVO/*数据库中存储的*/,OsAttributeDTO osAttributeDTO/*修改后的内容*/){
|
String dataType = osAttributeVO.getAttributeDataType();
|
//String other = osAttributeVO.getOther();
|
//String newOther = abItem.other == null ? "" : abItem.other;
|
String newType = osAttributeDTO.getAttributeDataType();
|
if(newType.equals(VTDataType.VTSTRING)){
|
if(dataType.equals(VTDataType.VTINTEGER) || dataType.equals(VTDataType.VTLONG)){
|
return true;
|
}
|
if(dataType.equals(VTDataType.VTSTRING)){
|
int length = osAttributeVO.getAttrLength();//Integer.valueOf(getOtherValueByType(other, "length"));
|
int newLen = osAttributeDTO.getAttrLength();//Integer.valueOf(getOtherValueByType(newOther, "length"));
|
if(length <= newLen){
|
return true;
|
}else{
|
return false;
|
}
|
}
|
}
|
|
if(newType.equals(dataType)){
|
return true;
|
}
|
|
return false;
|
}
|
|
/**
|
* 判断该属性是否已经在业务类型中, 或者链接类型中产生了数据
|
* @param abName
|
* @return
|
*/
|
private boolean hasInstance(String abName) throws PLException {
|
return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName);
|
}
|
|
/**
|
* 检查属性名称是否符合规范
|
* @param attributeName
|
* @return 没有返回值,存在问题直接抛出错误
|
*/
|
private void checkName(String attributeName) throws PLException {
|
if(attributeName.equals("")){
|
throw new PLException("500",new String[]{"注意,属性名不能为空!"});
|
}
|
|
if(!attributeName.matches("[a-z A-Z]*")){
|
throw new PLException("500",new String[]{"注意:属性名只能为英文字母!"+ NAME_MAX_LENGTH});
|
}
|
|
int length = attributeName.length();
|
if(length > NAME_MAX_LENGTH){
|
throw new PLException("500",new String[]{"属性名过长,属性名长度不能超过!"+ NAME_MAX_LENGTH});
|
}
|
|
String abName = attributeName.toLowerCase();
|
//检查属性名是否是为系统基础属性,如createTime,ts,oid等
|
if(usedBySystem(abName)){
|
throw new PLException("500",new String[]{"属性名无效,原因:属性名已被系统属性使用!"});
|
}
|
//检查属性名是否是关键字
|
if(usedByDataBase(abName)){
|
throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"});
|
}
|
//检查属性名是否已存在与系统中
|
if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
|
throw new PLException("500",new String[]{"属性名称在系统中已存在!"});
|
}
|
}
|
|
/**
|
* 检查默认值与属性类型是否匹配
|
* @param osAttributeDTO
|
* @return
|
*/
|
private void checkDefValue(OsAttributeDTO osAttributeDTO) throws PLException {
|
String defValue = osAttributeDTO.getDefaultValue();
|
String vtType = osAttributeDTO.getAttributeDataType();
|
String rages = osAttributeDTO.getRange();
|
if(defValue != null && !defValue.equals("")){
|
if(vtType.equals(VTDataType.VTSTRING)){
|
try{
|
String.valueOf(defValue);
|
}catch(Exception e){
|
throw new PLException("500",new String[]{"请输入String类型的默认值!"});
|
}
|
if(rages == null || rages.equals("")){
|
return;
|
}
|
VTString obj = new VTString(String.valueOf(defValue));
|
boolean flag = obj.checkRageValueByRage(rages);
|
if(!flag){
|
throw new PLException("500",new String[]{"默认值与值域冲突!"});
|
}
|
}else if(vtType.equals(VTDataType.VTINTEGER)){
|
try{
|
Integer.valueOf(defValue);
|
}catch(Exception e){
|
throw new PLException("500",new String[]{"请输入Integer类型的默认值!"});
|
}
|
if(rages == null || rages.equals("")){
|
return;
|
}
|
|
VTInteger obj = new VTInteger(Integer.valueOf(defValue));
|
boolean flag = obj.checkRageValueByRage(rages);
|
if(!flag){
|
throw new PLException("500",new String[]{"默认值与值域冲突!"});
|
}
|
}else if(vtType.equals(VTDataType.VTLONG)){
|
try{
|
Long.valueOf(defValue);
|
}catch(Exception e){
|
throw new PLException("500",new String[]{"请输入Long类型的默认值!"});
|
}
|
if(rages == null || rages.equals("")){
|
return;
|
}
|
|
VTLong obj = new VTLong(Long.valueOf(defValue));
|
boolean flag = obj.checkRageValueByRage(rages);
|
if(!flag){
|
throw new PLException("500",new String[]{"默认值与值域冲突!"});
|
}
|
}else if(vtType.equals(VTDataType.VTDOUBLE)){
|
try{
|
Double.valueOf(defValue);
|
}catch(Exception e){
|
throw new PLException("500",new String[]{"请输入Double类型的默认值!"});
|
}
|
if(rages == null || rages.equals("")){
|
return;
|
}
|
VTDouble obj = new VTDouble(Double.valueOf(defValue));
|
boolean flag = obj.checkRageValueByRage(rages);
|
if(!flag){
|
throw new PLException("500",new String[]{"默认值与值域冲突!"});
|
}
|
|
}
|
}
|
}
|
|
/**
|
* 检查该属性名是否被系统属性使用
|
* @param abName
|
* @return
|
*/
|
private boolean usedBySystem(String abName) {
|
boolean flag = false;
|
String[] names = UsedNames.getProperty(SYSUSEDNAMES).toUpperCase().split(",");
|
List<String> nameList = Arrays.asList(names);
|
if(nameList.contains(abName.toUpperCase())){
|
flag = true;
|
}
|
return flag;
|
}
|
|
/**
|
* 检查该属性名是否属于数据库关键字
|
* @param abName
|
* @return
|
*/
|
private boolean usedByDataBase(String abName){
|
boolean flag = false;
|
String[] names = UsedNames.getProperty(DATABASEUSEDNAMES).toUpperCase().split(",");
|
List<String> nameList = Arrays.asList(names);
|
if(nameList.contains(abName.toUpperCase())){
|
flag = true;
|
}
|
return flag;
|
}
|
|
/**
|
* 删除属性
|
* @param osAttributeDTOS
|
* @return true成功,false失败
|
*/
|
@Override
|
public boolean deleteAttributes(List<OsAttributeDTO> osAttributeDTOS) throws PLException {
|
VciBaseUtil.alertNotNull(osAttributeDTOS,"待删除的属性列表");
|
//平台的deleteEnumTypes方法必传三个参数,oid、name和ts
|
List<AttributeDef> attributeDefs = new ArrayList<>();
|
for(OsAttributeDTO osAttributeDTO : osAttributeDTOS){
|
//oid和ts判空
|
String oid = osAttributeDTO.getOid();
|
//name主要用来对缓存数据删除
|
String name = osAttributeDTO.getName();
|
Date ts = osAttributeDTO.getTs();
|
if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){
|
throw new PLException("500",new String[]{"待删除的属性列表中主键【oid】、调整时间【ts】、属性名【name】不能为空!"});
|
}
|
//判断枚举是否有被引用
|
List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name);
|
if(Func.isNotEmpty(usedAttrList)){
|
throw new PLException("500",new String[]{"删除的属性中,属性名称为:【" + name + "】,已被引用!"});
|
}
|
AttributeDef attributeDef = new AttributeDef();
|
attributeDef.oid = oid;
|
attributeDef.name = name;
|
attributeDef.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat);
|
attributeDefs.add(attributeDef);
|
}
|
if(Func.isEmpty(attributeDefs)){
|
return false;
|
}
|
return platformClientUtil.getAttributeService().deleteAttributeDefs(attributeDefs.toArray(new AttributeDef[attributeDefs.size()]));
|
}
|
|
/**
|
* 查看属性的使用范围
|
* @param attributeName
|
* @return key:属性 ,value使用该属性的业务类型
|
*/
|
@Override
|
public List<Map<String, String>> getUsedAttributeList(String attributeName) throws PLException {
|
if(Func.isBlank(attributeName)){
|
throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"});
|
}
|
String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName);
|
if(Func.isEmpty(btNames)){
|
return new ArrayList<>();
|
}
|
List<Map<String,String>> btmNameMapList = new ArrayList<>();
|
Arrays.stream(btNames).forEach(btName->{
|
Map<String, String> itemMap = new HashMap<>();
|
itemMap.put("attributeName",attributeName);
|
itemMap.put("source",btName);
|
btmNameMapList.add(itemMap);
|
});
|
return btmNameMapList;
|
}
|
|
/**
|
* 导出选中的属性
|
* @param exportFileName 导出的文件名
|
* @param attrNames 需要导出的属性名称
|
* @return
|
*/
|
@Override
|
public String exportAttributes(String exportFileName, String attrNames) throws PLException {
|
if(Func.isBlank(attrNames)){
|
throw new PLException("500",new String[]{"请勾选要导出的属性!"});
|
}
|
//界面没传名称,使用默认导出名称
|
exportFileName = Func.isBlank(exportFileName) ? "属性池中属性导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
|
//设置列名
|
List<String> columns = new ArrayList<>(
|
Arrays.asList("属性名", "标签", "描述",
|
"属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)",
|
"使用的枚举中文名称(标签)", "参照的业务类型编号", "参照的业务类型名称",
|
"属性长度", "小数精度位数","小数刻度位数","取值范围","创建时间")
|
);
|
|
//写excel
|
String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls";
|
try {
|
new File(excelPath).createNewFile();
|
} catch (Throwable e) {
|
throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
|
}
|
//设置列
|
List<WriteExcelData> excelDataList = new ArrayList<>();
|
//设置列头
|
for (int index = 0; index < columns.size(); index++) {
|
excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
|
}
|
//按照属性名查询属性,然后处理属性导出
|
List<String> enumNameList = Func.toStrList(attrNames);
|
List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(enumNameList);
|
if(Func.isEmpty(osAttributeVOS)){
|
excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!"));
|
}else{
|
//先按照属性类型排序,不同属性类型导出的数据乱的效果
|
osAttributeVOS.sort(Comparator.comparing(OsAttributeVO::getAttributeDataType));
|
for (int i = 0; i < osAttributeVOS.size(); i++) {
|
OsAttributeVO osAttributeVO = osAttributeVOS.get(i);
|
excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId()));
|
excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName()));
|
excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription()));
|
excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataTypeText()+(osAttributeVO.getAttributeDataType())));
|
excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag()));
|
excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue()));
|
excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId()));
|
excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName()));
|
excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getBtmTypeId()));
|
excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName()));
|
excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getAttrLength()));
|
excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength()));
|
excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength()));
|
excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange()));
|
excelDataList.add(new WriteExcelData(i+1,14, osAttributeVO.getCreateTime()));
|
}
|
}
|
WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
|
ExcelUtil.writeDataToFile(excelPath, excelOption);
|
return excelPath;
|
}
|
|
/**
|
* 是否默认的属性
|
*
|
* @param attr 属性编号
|
* @return true表示是默认属性
|
*/
|
@Override
|
public boolean isDefaultAttr(String attr) {
|
if(StringUtils.isBlank(attr)){
|
return false;
|
}
|
return getDefaultAttributeVOMap().containsKey(attr.toLowerCase(Locale.ROOT));
|
}
|
|
/**
|
* 是否为参照属性
|
* @param other 配置的其他
|
* @return true 是参照
|
*/
|
private boolean isReferAttr(String other){
|
if(StringUtils.isNotBlank(other)
|
&& (other.toLowerCase().contains("btm") || other.toLowerCase().contains("ltm"))){
|
//还不能确定,因为枚举的时候也会设置btm
|
String[] temp = other.split(";");
|
for(String s : temp){
|
if((s.contains("btm") || s.contains("ltm")) && s.split("=").length>1){
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
/**
|
* 是否为枚举的属性
|
* @param other 配置的内容
|
* @return true 是枚举
|
*/
|
private boolean isEnumAttr(String other){
|
if(StringUtils.isNotBlank(other)
|
&& other.contains("enumName")){
|
//还不能确定,因为枚举的时候也会设置btm
|
String[] temp = other.split(";");
|
for(String s : temp){
|
if(s.contains("enumName")&& s.split("=").length>1){
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
/**
|
* 清除缓存
|
*/
|
@Override
|
public void clearCache() {
|
|
}
|
|
/**
|
* 调用修改业务类型和连接类型中对应属性名的属性
|
* @param apName
|
* @return
|
* @throws PLException
|
*/
|
private boolean alterAp(String apName) throws PLException {
|
return osBtmService.alterAp(apName) && osLinkTypeServiceI.alterAp(apName);
|
}
|
|
}
|