package com.fzzy.api.service;
|
|
import com.bstek.dorado.annotation.Expose;
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.entity.*;
|
import com.fzzy.api.utils.RedisConst;
|
import com.fzzy.api.utils.RedisUtil;
|
import com.fzzy.api.view.repository.Api1105Rep;
|
import com.fzzy.api.view.repository.ApiConfsRep;
|
import com.fzzy.api.view.repository.GbAreaRep;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Set;
|
|
|
/**
|
* 基础数据接口
|
*/
|
@Component
|
public class ApiCommonService {
|
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private ApiConfsRep apiConfsRep;
|
@Autowired
|
private GbAreaRep gbAreaRep;
|
@Autowired
|
private Api1105Rep api1105Rep;
|
|
/**
|
* 刷新缓存- 接口配置参数
|
* apiCommonService#flushConfCache
|
*/
|
@Expose
|
public List<ApiConfs> flushConfCache() {
|
List<ApiConfs> list = apiConfsRep.findAll();
|
|
if (null == list || list.isEmpty()) return null;
|
|
String key;
|
for (ApiConfs conf : list) {
|
key = RedisConst.buildKey(RedisConst.KYE_CONF, conf.getKqdm());
|
redisUtil.set(key, conf);
|
}
|
return list;
|
}
|
|
/**
|
* 根据库区代码获取接口配置信息
|
*
|
* @return
|
*/
|
public List<ApiConfs> listCacheConf() {
|
String pattern = RedisConst.buildKey(RedisConst.KYE_CONF);
|
Set<String> keys = redisUtil.keys(pattern);
|
if (null == keys || keys.isEmpty()) {
|
return flushConfCache();
|
}
|
|
List<ApiConfs> result = new ArrayList<>();
|
for (String key : keys) {
|
result.add((ApiConfs) redisUtil.get(key));
|
}
|
|
return result;
|
}
|
|
public ApiConfs getConf(String kqdm) {
|
String key = RedisConst.buildKey(RedisConst.KYE_CONF, kqdm);
|
ApiConfs result = (ApiConfs) redisUtil.get(key);
|
|
if (null == result) {
|
List<ApiConfs> list = flushConfCache();
|
if (null == list || list.isEmpty()) return null;
|
for (ApiConfs conf : list) {
|
if (kqdm.equals(conf.getKqdm())) return conf;
|
}
|
}
|
|
return result;
|
}
|
|
public void updateCacheConf(ApiConfs conf) {
|
String key = RedisConst.buildKey(RedisConst.KYE_CONF, conf.getKqdm());
|
redisUtil.set(key, conf);
|
}
|
|
/**
|
* 刷新货位信息缓存
|
*/
|
public void flushApi1105Cache(List<Api1105> list) {
|
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
String key;
|
for (Api1105 api1105 : list) {
|
if (null == api1105.getBizId()) {
|
continue;
|
}
|
key = RedisConst.buildKey(Constant.API_CODE_1105, api1105.getHwdm());
|
redisUtil.set(key, api1105);
|
}
|
}
|
/**
|
* 刷新货位信息缓存
|
*/
|
public void flushApi1105Cache() {
|
List<Api1105> list = api1105Rep.findAll();
|
if(list!= null && list.size() > 0){
|
String key;
|
for (Api1105 api1105 : list) {
|
if (null == api1105.getBizId()) {
|
continue;
|
}
|
key = RedisConst.buildKey(Constant.API_CODE_1105, api1105.getBizId());
|
redisUtil.set(key, api1105);
|
}
|
}
|
}
|
/**
|
* 获取货位缓存
|
*
|
* @param bizId
|
* @return
|
*/
|
public Api1105 getApi1105Cache(String bizId) {
|
|
if (null == bizId) {
|
return null;
|
}
|
|
return (Api1105) redisUtil.get(RedisConst.buildKey(Constant.API_CODE_1105, bizId));
|
}
|
|
public void flushApi1103Cache(List<Api1103> list) {
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
String key;
|
for (Api1103 apiData : list) {
|
if (null == apiData.getCfdm()) {
|
continue;
|
}
|
key = RedisConst.buildKey(Constant.API_CODE_1103, apiData.getCfdm());
|
redisUtil.set(key, apiData);
|
}
|
}
|
|
public Api1103 getApi1103Cache(String id) {
|
if (null == id) {
|
return null;
|
}
|
return (Api1103) redisUtil.get(RedisConst.buildKey(Constant.API_CODE_1103, id));
|
}
|
|
public void flushApi1104Cache(List<Api1104> list) {
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
String key;
|
for (Api1104 apiData : list) {
|
if (null == apiData.getAjdh()) {
|
continue;
|
}
|
key = RedisConst.buildKey(Constant.API_CODE_1104, apiData.getAjdh());
|
redisUtil.set(key, apiData);
|
}
|
}
|
|
public Api1104 getApi1104Cache(String id) {
|
if (null == id) {
|
return null;
|
}
|
return (Api1104) redisUtil.get(RedisConst.buildKey(Constant.API_CODE_1104, id));
|
}
|
|
public void flushApi1102Cache(List<Api1102> list) {
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
String key;
|
for (Api1102 apiData : list) {
|
if (null == apiData.getKqdm()) {
|
continue;
|
}
|
key = RedisConst.buildKey(Constant.API_CODE_1102, apiData.getKqdm());
|
redisUtil.set(key, apiData);
|
}
|
}
|
|
public Api1102 getApi1102Cache(String id) {
|
if (null == id) {
|
return null;
|
}
|
return (Api1102) redisUtil.get(RedisConst.buildKey(Constant.API_CODE_1102, id));
|
}
|
|
/**
|
* 根据粮食产地获取编码
|
*
|
* @param foodLocationName
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public String getFoodLocationIdFromCache(String foodLocationName) {
|
String key = RedisConst.buildKey("GB_AREA");
|
List<GbArea> list = (List<GbArea>) redisUtil.get(key);
|
if (null == list) {
|
list = gbAreaRep.findAll();
|
redisUtil.set(key, list);
|
}
|
|
for (GbArea area : list) {
|
if(StringUtils.isEmpty(foodLocationName)){
|
return null;
|
}
|
if (area.getName().indexOf(foodLocationName) != -1) return area.getCode();
|
}
|
|
return null;
|
}
|
}
|