Commit 5263c796 by 111-PC\111

[+]代码整改

1 parent 8b10edd1
package cn.com.glsx.modules.factory;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台信息枚举
*/
public enum PlatForm implements PlatformConstants{
TUYA {
@Override
public Integer getCode() {
return 0;
}
@Override
public String getValue() {
return "涂鸦";
}
@Override
public String getBeanName(){
return "oneselfStrategy";
}
},
XIAOMI {
@Override
public Integer getCode() {
return 1;
}
@Override
public String getValue() {
return "小米";
}
@Override
public String getBeanName(){
return "oneselfStrategy";
}
},;
public static String getValueByCode(Integer code) {
for (PlatForm platForm : PlatForm.values()) {
if (platForm.getCode().equals(code)) {
return platForm.getValue();
}
}
return null;
}
public static String getBeanNameByCode(Integer code) {
for (PlatForm platForm : PlatForm.values()) {
if (platForm.getCode().equals(code)) {
return platForm.getBeanName();
}
}
return null;
}
}
package cn.com.glsx.modules.factory;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台信息接口
*/
public interface PlatformConstants {
Integer getCode();
String getValue();
String getBeanName();
}
package cn.com.glsx.modules.factory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台接口工厂类
*/
@Service
public class PlatformFactory {
@Autowired
Map<String, PlatformStrategy> strategys = new ConcurrentHashMap<>(3);
public PlatformStrategy getStrategy(Integer platformCode) throws Exception{
PlatformStrategy strategy = strategys.get(PlatForm.getBeanNameByCode(platformCode));
if(strategy == null) {
throw new RuntimeException("no strategy defined");
}
return strategy;
}
}
package cn.com.glsx.modules.factory;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台统一对外接口
*/
public interface PlatformStrategy {
}
package cn.com.glsx.modules.factory.strategy;
import cn.com.glsx.modules.factory.PlatformStrategy;
import org.springframework.stereotype.Service;
@Service
public class TuyaStrategy implements PlatformStrategy {
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!