更新后端,采用Springboot+mybatis

This commit is contained in:
季圣华
2018-12-19 23:54:53 +08:00
parent bb6f5528a7
commit 5cc26a22f2
1672 changed files with 52804 additions and 156085 deletions

View File

@@ -0,0 +1,59 @@
package com.jsh.erp.service;
import com.jsh.erp.utils.AnnotationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
/**
* @author jishenghua 2018-10-7 15:25:09
*/
@Service
public class InterfaceContainer {
private final Map<String, Integer> nameTypeMap;
private final Map<Integer, ICommonQuery> configComponentMap;
public InterfaceContainer() {
nameTypeMap = new HashMap<>();
configComponentMap = new HashMap<>();
}
@Autowired(required = false)
private void init(ICommonQuery[] configComponents) {
for (ICommonQuery configComponent : configComponents) {
ResourceInfo info = AnnotationUtils.getAnnotation(configComponent, ResourceInfo.class);
if (info != null) {
initResourceInfo(info);
configComponentMap.put(info.type(), configComponent);
}
}
}
public int getResourceType(String apiName) {
if (!nameTypeMap.containsKey(apiName))
throw new RuntimeException("资源:" + apiName + "的组件不存在");
return nameTypeMap.get(apiName);
}
public ICommonQuery getCommonQuery(String apiName) {
return getCommonQuery(this.getResourceType(apiName));
}
private ICommonQuery getCommonQuery(int resourceType) {
Assert.isTrue(configComponentMap.containsKey(resourceType));
return configComponentMap.get(resourceType);
}
private synchronized void initResourceInfo(ResourceInfo info) {
if (nameTypeMap.containsKey(info.value())) {
Assert.isTrue(nameTypeMap.get(info.value()).equals(info.type()));
} else {
nameTypeMap.put(info.value(), info.type());
}
}
}