package com.vci.web.initTask;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.vci.client.mw.ClientContextVariable;
|
import com.vci.client.mw.LaunchModeEnum;
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.framework.FrameworkServicePrx;
|
import com.vci.corba.omd.data.AttributeValue;
|
import com.vci.frameworkcore.constant.FrameWorkBtmTypeConstant;
|
import com.vci.frameworkcore.properties.VciFramworkCompatibilityProperties;
|
import com.vci.starter.web.annotation.config.VciConfigField;
|
import com.vci.starter.web.annotation.config.VciConfigModule;
|
import com.vci.starter.web.enumpck.SessionStorageTypeEnum;
|
import com.vci.starter.web.enumpck.UserSecretEnum;
|
import com.vci.starter.web.pagemodel.SessionInfo;
|
import com.vci.starter.web.properties.VciSessionProperties;
|
import com.vci.starter.web.util.ApplicationContextProvider;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
|
import com.vci.web.pageModel.OsAttributeVO;
|
import com.vci.web.properties.WebProperties;
|
import com.vci.web.service.OsAttributeServiceI;
|
import com.vci.web.service.VciMdServiceI;
|
import com.vci.web.service.impl.UIEngineServiceImpl;
|
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.beans.factory.annotation.Value;
|
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import java.lang.reflect.Field;
|
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.Method;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Locale;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 服务初始化
|
* @author weidy
|
* @date 2019/12/13
|
*/
|
@Component
|
public class VciWebInitTaskComponent implements ApplicationRunner {
|
|
/**
|
* 日志对象
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 是否兼容
|
*/
|
@Value("${user-table-compatibility:}")
|
private String compatibility;
|
|
/**
|
* 配置对象
|
*/
|
@Autowired
|
private WebProperties webProperties;
|
|
/**
|
* 平台调用客户端
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 会话的配置
|
*/
|
@Autowired(required = false)
|
private VciSessionProperties sessionProperties;
|
|
/**
|
* 引入兼容的配置
|
*/
|
@Autowired(required = false)
|
private VciFramworkCompatibilityProperties compatibilityProperties;
|
|
/**
|
* 属性的服务
|
*/
|
@Autowired
|
private OsAttributeServiceI attributeService;
|
|
/**
|
* markdown的服务
|
*/
|
@Autowired
|
private VciMdServiceI mdService;
|
|
|
/**
|
* 执行初始化
|
* @param args 启动的参数
|
*/
|
@Override
|
public void run(ApplicationArguments args) {
|
initCompatibility();
|
initSysadmin();
|
initClearSession();
|
initSetting();
|
// secretService.getMinDataSecret();
|
// secretService.getMinIpSecret();
|
// secretService.getMinUserSecret();
|
// initService.clearAllCache();
|
// initService.initServerCache();
|
mdService.scanAllMdFile();
|
initDefaultAttribute();
|
}
|
|
/**
|
* 初始化默认的属性
|
*/
|
private void initDefaultAttribute() {
|
try {
|
String attrJson = LocalFileUtil.readContentForFileInJar("DefaultAttribute.json");
|
if (StringUtils.isBlank(attrJson)) {
|
logger.info("没有读取到classpath*:DefaultAttribute.json文件的内容");
|
return;
|
}
|
List<OsAttributeVO> attributeVOS = JSONObject.parseArray(attrJson, OsAttributeVO.class);
|
if(!CollectionUtils.isEmpty(attributeVOS)){
|
attributeService.setDefaultAttributeVOs(attributeVOS.stream().sorted(((o1, o2) -> o1.getId().compareTo(o2.getId()))).collect(Collectors.toList()));
|
attributeService.setDefaultAttributeVOMap(attributeVOS.stream().collect(Collectors.toMap(s->s.getId().toLowerCase(Locale.ROOT), t->t)));
|
}
|
logger.info("读取默认属性完成");
|
}catch (Throwable e){
|
logger.error("读取classpath*:DefaultAttribute.json的内容并转换的时候出错了",e);
|
}
|
}
|
|
/**
|
* 清除会话的信息内容
|
*/
|
public void initClearSession(){
|
if((sessionProperties != null && sessionProperties.isClearSessionOnStart() )&&
|
SessionStorageTypeEnum.DATABASE.equals(SessionStorageTypeEnum.forValue(sessionProperties.getSessionInfoStorageType()))){
|
try {
|
platformClientUtil.getBOFactoryService().executeUpdateSqlByParams(" delete from VCI_SESSIONINFO ",new AttributeValue[0]);
|
}catch (Throwable e) {
|
if (logger.isErrorEnabled()) {
|
logger.error("清除会话信息", e);
|
}
|
}
|
}
|
}
|
|
|
/**
|
* 初始化兼容的内容
|
*/
|
public void initCompatibility(){
|
//设置兼容性的表格
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY = true;
|
String userBtmType = FrameWorkBtmTypeConstant.SM_USER_BTM_TYPE.toLowerCase();
|
String roleBtmType = FrameWorkBtmTypeConstant.SM_ROLE_BTM_TYPE.toLowerCase();
|
String deptBtmType = FrameWorkBtmTypeConstant.ORG_DEPARTMENT_BTM_TYPE.toLowerCase();
|
String functionBtmType = FrameWorkBtmTypeConstant.SM_FUNCTION_BTM_TYPE.toLowerCase();
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_BTM_MAP.put(userBtmType, "pluser");
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_BTM_MAP.put(roleBtmType, "plrole");
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_BTM_MAP.put(deptBtmType, "pldept");
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_BTM_MAP.put(functionBtmType, "plfunction");
|
//读取表格映射的字段
|
if (!CollectionUtils.isEmpty(compatibilityProperties.getUserTableFieldMap())) {
|
compatibilityProperties.getUserTableFieldMap().forEach((k, v) -> {
|
String key = userBtmType + VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_SEP + k.toLowerCase();
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_MAP.put(key, v);
|
});
|
}
|
if (!CollectionUtils.isEmpty(compatibilityProperties.getRoleTableFieldMap())) {
|
compatibilityProperties.getRoleTableFieldMap().forEach((k, v) -> {
|
String key = roleBtmType + VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_SEP + k.toLowerCase();
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_MAP.put(key, v);
|
});
|
}
|
if (!CollectionUtils.isEmpty(compatibilityProperties.getDeptTableFieldMap())) {
|
compatibilityProperties.getDeptTableFieldMap().forEach((k, v) -> {
|
String key = deptBtmType + VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_SEP + k.toLowerCase();
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_MAP.put(key, v);
|
});
|
}
|
if (!CollectionUtils.isEmpty(compatibilityProperties.getFunctionTableFieldMap())) {
|
compatibilityProperties.getFunctionTableFieldMap().forEach((k, v) -> {
|
String key = functionBtmType + VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_SEP + k.toLowerCase();
|
VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY_FIELD_MAP.put(key, v);
|
});
|
}
|
}
|
|
/**
|
* 初始化用户
|
*/
|
public void initSysadmin(){
|
SessionInfo sessionInfo = new SessionInfo();
|
sessionInfo.setUserId("sysAdmin");
|
sessionInfo.setUserName("系统管理员");
|
sessionInfo.setIp(WebUtil.getLocalIp());
|
sessionInfo.setUserOid("193C026F-7DB8-27B4-F383-4E8BE083FB07");
|
sessionInfo.setUserSecret(UserSecretEnum.PRIVACY.getValue()+"");
|
WebUtil.setSessionInfo(sessionInfo);
|
}
|
/**
|
* 初始化相关的配置信息
|
*/
|
public void initSetting() {
|
System.out.println("----初始化用于查询配置的用户----");
|
ClientContextVariable.setClientLanuchMode(LaunchModeEnum.WebApp);
|
System.out.println("----初始化用于查询配置的用户完成----");
|
System.out.println("----开始扫描有VciConfigModule注解的类----");
|
String[] namesForAnnotation = ApplicationContextProvider.getApplicationContext().getBeanNamesForAnnotation(VciConfigModule.class);
|
if(namesForAnnotation!=null && namesForAnnotation.length > 0){
|
for(String beanName : namesForAnnotation){
|
Object bean = ApplicationContextProvider.getApplicationContext().getBean(beanName);
|
List<Field> fields = WebUtil.getAllFieldForObj(bean.getClass());
|
Map<String,Field> configFieldMap = new HashMap<>();
|
List<Field> hasConfigFields = fields.stream().filter(s -> {
|
s.setAccessible(true);
|
return s.isAnnotationPresent(VciConfigField.class);
|
}).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(hasConfigFields)){
|
hasConfigFields.stream().forEach(field -> {
|
field.setAccessible(true);
|
VciConfigField vciConfigField = field.getAnnotation(VciConfigField.class);
|
if(vciConfigField == null){
|
vciConfigField = field.getDeclaredAnnotation(VciConfigField.class);
|
}
|
configFieldMap.put(vciConfigField.value(),field);
|
});
|
FrameworkServicePrx frameworkServicePrx = platformClientUtil.getFrameworkService();
|
configFieldMap.forEach((configField,field)->{
|
String configValue = null;
|
try {
|
configValue = frameworkServicePrx.getConfigValue(configField);
|
} catch (PLException vciError) {
|
if(logger.isErrorEnabled()){
|
logger.error(vciError.code,vciError);
|
}
|
}
|
Class<?> fieldType = field.getType();
|
Method method = WebUtil.getSetmethod(bean.getClass(), field);
|
Object value = null;
|
if(fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)){
|
value = ("on".equalsIgnoreCase(configValue) || "true".equalsIgnoreCase(configValue))?true:false;
|
}else if(fieldType.equals(Double.class) || fieldType.equals(double.class)){
|
value = WebUtil.getDouble(configValue);
|
}else if(fieldType.equals(Long.class) || fieldType.equals(long.class)){
|
value = WebUtil.getLong(configValue);
|
}else if(fieldType.equals(Float.class) || fieldType.equals(float.class)){
|
value = WebUtil.getFloat(configValue);
|
}else if(fieldType.equals(Integer.class) || fieldType.equals(int.class)){
|
value = WebUtil.getInt(configValue);
|
}else{
|
value = configValue;
|
}
|
try {
|
method.invoke(bean,value);
|
} catch (IllegalAccessException e) {
|
if(logger.isErrorEnabled()){
|
logger.error(e.getMessage(),e);
|
}
|
} catch (InvocationTargetException e) {
|
if(logger.isErrorEnabled()){
|
logger.error(e.getMessage(),e);
|
}
|
}
|
});
|
}
|
}
|
}
|
//只有当数据密级控制开启的情况下,才会控制流程发起时的密级
|
webProperties.setCheckSecretOnProcessStart(webProperties.isCheckClientSessionTimeout()&&webProperties.isSecretRight());
|
if(webProperties.isDebug()){
|
UIEngineServiceImpl.QUERY_BY_CACHE = false;
|
}
|
System.out.println("---读取服务端的配置文件完成---");
|
}
|
|
|
|
|
|
public String getCompatibility() {
|
return compatibility;
|
}
|
|
public void setCompatibility(String compatibility) {
|
this.compatibility = compatibility;
|
}
|
}
|