package com.tievd.jyz.cache;
|
|
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.tievd.jyz.constants.SystemConstant;
|
import com.tievd.jyz.entity.*;
|
import com.tievd.jyz.service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* Author: wqy
|
* Date: 2023/3/9 9:37
|
*/
|
|
@Component
|
public class AlgorithmCache {
|
|
@Autowired
|
private ISysAlgorithmItemService sysAlgorithmItemService;
|
|
public static final String OIL_ALG_CODE = "C10001,C10003";
|
|
private static Map<String, SysAlgorithmItem> algorithmMap = new HashMap<>();
|
/** 所属阶段 1卸前 2卸中 3卸后 */
|
private static Map<Byte, List<SysAlgorithmItem>> phraseAlgorithmMap = new HashMap<>();
|
|
public static Map<String, SysAlgorithmItem> algorithmMap() {
|
return algorithmMap;
|
}
|
|
/**
|
* 获取卸油算法map
|
* @return
|
*/
|
public static Map<String, SysAlgorithmItem> oiloutAlgMap() {
|
Map<String, SysAlgorithmItem> oiloutMap = new HashMap<>();
|
for (Map.Entry<String, SysAlgorithmItem> entry : algorithmMap.entrySet()) {
|
if (entry.getValue().getRegion() == SystemConstant.INSTALL_ADDRESS_OIL_OUT.byteValue()) {
|
oiloutMap.put(entry.getKey(), entry.getValue());
|
}
|
}
|
return oiloutMap;
|
}
|
|
/**
|
*获取阶段算法
|
* @param phrase
|
* @return
|
*/
|
public static List<SysAlgorithmItem> getPhraseAlgorithmMap(Byte phrase) {
|
return phraseAlgorithmMap.get(phrase);
|
}
|
|
/**
|
* 初始化
|
*/
|
@PostConstruct
|
private void init(){
|
algorithmMap.clear();
|
phraseAlgorithmMap.clear();
|
List<SysAlgorithmItem> algorithmItems = sysAlgorithmItemService.list();
|
for(SysAlgorithmItem algorithmItem:algorithmItems){
|
algorithmMap.put(algorithmItem.getAlgorithmCode(),algorithmItem);
|
List<SysAlgorithmItem> sysAlgorithmItems = phraseAlgorithmMap.get(algorithmItem.getPhrase());
|
if(sysAlgorithmItems == null){
|
sysAlgorithmItems = new ArrayList<>();
|
phraseAlgorithmMap.put(algorithmItem.getPhrase(),sysAlgorithmItems);
|
}
|
sysAlgorithmItems.add(algorithmItem);
|
}
|
}
|
|
/**
|
* 获取算法行为
|
* @param algCode
|
* @return
|
*/
|
public static SysAlgorithmItem getAlgorithmMap(String algCode) {
|
return algorithmMap.get(algCode);
|
}
|
|
|
public static Model getEntity(String algCode) {
|
int type = algorithmMap.get(algCode).getAlgorithmType();
|
switch(type) {
|
case 1 : return new OilEvent();
|
case 2 : return new OiloutEvent();
|
case 3 : return new PatrolEvent();
|
case 4 : return new SpotcheckEvent();
|
default: return new OilEvent();
|
}
|
}
|
|
public static Class<? extends IService> getService(String algCode) {
|
int type = algorithmMap.get(algCode).getAlgorithmType();
|
switch(type) {
|
case 1 : return IOilEventService.class;
|
case 2 : return IOiloutEventService.class;
|
case 3 : return IPatrolEventService.class;
|
case 4 : return ISpotcheckEventService.class;
|
default: return IOilEventService.class;
|
}
|
}
|
|
}
|