Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit f797b3aa
由
sunke
编写于
2021-08-03 09:47:55 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
国际化配置
1 个父辈
e0aa4f81
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
227 行增加
和
60 行删除
src/main/java/com/neotel/smfcore/common/utils/StringUtils.java
src/main/java/com/neotel/smfcore/core/device/util/DataCache.java
src/main/java/com/neotel/smfcore/core/language/config/LocaleConfig.java
src/main/java/com/neotel/smfcore/core/language/util/MessageUtils.java
src/main/java/com/neotel/smfcore/core/system/enums/CacheKey.java
src/main/java/com/neotel/smfcore/core/system/service/dao/ICacheItemDao.java
src/main/java/com/neotel/smfcore/core/system/service/dao/impl/CacheItemDaoImpl.java
src/main/java/com/neotel/smfcore/core/system/service/po/CacheItem.java
src/main/java/com/neotel/smfcore/security/config/ConfigurerAdapter.java
src/main/java/com/neotel/smfcore/common/utils/StringUtils.java
查看文件 @
f797b3a
...
@@ -36,9 +36,9 @@ import java.util.Enumeration;
...
@@ -36,9 +36,9 @@ import java.util.Enumeration;
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
{
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
StringUtils
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
StringUtils
.
class
);
private
static
boolean
ipLocal
=
false
;
//
private static boolean ipLocal = false;
private
static
File
file
=
null
;
//
private static File file = null;
private
static
DbConfig
config
;
//
private static DbConfig config;
private
static
final
char
SEPARATOR
=
'_'
;
private
static
final
char
SEPARATOR
=
'_'
;
private
static
final
String
UNKNOWN
=
"unknown"
;
private
static
final
String
UNKNOWN
=
"unknown"
;
...
@@ -50,24 +50,24 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
...
@@ -50,24 +50,24 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
// .build();
// .build();
static
{
//
static {
SpringContextHolder
.
addCallBacks
(()
->
{
//
SpringContextHolder.addCallBacks(() -> {
StringUtils
.
ipLocal
=
SpringContextHolder
.
getProperties
(
"ip.local-parsing"
,
false
,
Boolean
.
class
);
//
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
if
(
ipLocal
)
{
//
if (ipLocal) {
/*
//
/*
* 此文件为独享 ,不必关闭
//
* 此文件为独享 ,不必关闭
*/
//
*/
String
path
=
"ip2region/ip2region.db"
;
//
String path = "ip2region/ip2region.db";
String
name
=
"ip2region.db"
;
//
String name = "ip2region.db";
try
{
//
try {
config
=
new
DbConfig
();
//
config = new DbConfig();
file
=
FileUtil
.
inputStreamToFile
(
new
ClassPathResource
(
path
).
getInputStream
(),
name
);
//
file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
log
.
error
(
e
.
getMessage
(),
e
);
//
log.error(e.getMessage(), e);
}
//
}
}
//
}
});
//
});
}
//
}
/**
/**
* 驼峰命名法工具
* 驼峰命名法工具
...
...
src/main/java/com/neotel/smfcore/core/device/util/DataCache.java
查看文件 @
f797b3a
...
@@ -9,11 +9,13 @@ import com.neotel.smfcore.core.barcode.utils.CodeResolve;
...
@@ -9,11 +9,13 @@ import com.neotel.smfcore.core.barcode.utils.CodeResolve;
import
com.neotel.smfcore.core.storage.bean.InventoryItem
;
import
com.neotel.smfcore.core.storage.bean.InventoryItem
;
import
com.neotel.smfcore.core.storage.enums.CHECKOUT_TYPE
;
import
com.neotel.smfcore.core.storage.enums.CHECKOUT_TYPE
;
import
com.neotel.smfcore.core.storage.service.po.StoragePos
;
import
com.neotel.smfcore.core.storage.service.po.StoragePos
;
import
com.neotel.smfcore.core.system.service.dao.ICacheItemDao
;
import
com.neotel.smfcore.core.system.service.dao.ISettingsDao
;
import
com.neotel.smfcore.core.system.service.dao.ISettingsDao
;
import
com.neotel.smfcore.core.barcode.bean.PlateSizeBean
;
import
com.neotel.smfcore.core.barcode.bean.PlateSizeBean
;
import
com.neotel.smfcore.core.system.service.manager.IDataLogManager
;
import
com.neotel.smfcore.core.system.service.manager.IDataLogManager
;
import
com.neotel.smfcore.core.storage.service.manager.IStorageManager
;
import
com.neotel.smfcore.core.storage.service.manager.IStorageManager
;
import
com.neotel.smfcore.core.storage.service.manager.IStoragePosManager
;
import
com.neotel.smfcore.core.storage.service.manager.IStoragePosManager
;
import
com.neotel.smfcore.core.system.service.po.CacheItem
;
import
com.neotel.smfcore.core.system.service.po.Settings
;
import
com.neotel.smfcore.core.system.service.po.Settings
;
import
com.neotel.smfcore.core.storage.service.po.Storage
;
import
com.neotel.smfcore.core.storage.service.po.Storage
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
...
@@ -41,25 +43,23 @@ public class DataCache {
...
@@ -41,25 +43,23 @@ public class DataCache {
private
IStorageManager
storageManager
;
private
IStorageManager
storageManager
;
@Autowired
@Autowired
private
IDataLogManager
dataLogManager
;
@Autowired
private
ISettingsDao
settingsDao
;
private
ISettingsDao
settingsDao
;
@Autowired
@Autowired
private
CodeResolve
codeResolve
;
private
CodeResolve
codeResolve
;
//
// @Autowired
@Autowired
// private IBarcodeManager barcodeManager;
private
ICacheItemDao
cacheItemDao
;
//
// @Autowired
// private IComponentManager componentManager;
//
/**
/**
* 是否需要推送温湿度报警值
* 是否需要推送温湿度报警值
*/
*/
public
static
Map
<
String
,
Boolean
>
needUpdateHumidityMap
=
new
ConcurrentHashMap
<>();
public
static
Map
<
String
,
Boolean
>
needUpdateHumidityMap
=
new
ConcurrentHashMap
<>();
//
/**
* 一些设置的缓存
*/
public
static
Map
<
String
,
Object
>
cacheMap
=
Maps
.
newConcurrentMap
();
/**
/**
* 出库方式
* 出库方式
*/
*/
...
@@ -68,6 +68,37 @@ public class DataCache {
...
@@ -68,6 +68,37 @@ public class DataCache {
@PostConstruct
@PostConstruct
public
void
initialize
()
{
public
void
initialize
()
{
settings
=
getSettings
();
settings
=
getSettings
();
initCacheItem
();
}
private
void
initCacheItem
(){
cacheMap
=
Maps
.
newConcurrentMap
();
List
<
CacheItem
>
all
=
cacheItemDao
.
findAll
();
for
(
CacheItem
cacheItem
:
all
)
{
cacheMap
.
put
(
cacheItem
.
getCacheKey
(),
cacheItem
.
getCacheValue
());
}
}
/**
* 获取缓存信息
* @param cacheKey
* @param <T>
* @return
*/
public
<
T
>
T
getCache
(
String
cacheKey
){
Object
value
=
cacheMap
.
get
(
cacheKey
);
if
(
value
!=
null
){
return
(
T
)
value
;
}
return
null
;
}
/**
* 更新缓存信息
*/
public
void
updateCache
(
String
cacheKey
,
Object
value
){
cacheItemDao
.
updateCacheItem
(
cacheKey
,
value
);
cacheMap
.
put
(
cacheKey
,
value
);
}
}
/**
/**
...
@@ -418,18 +449,4 @@ public class DataCache {
...
@@ -418,18 +449,4 @@ public class DataCache {
inventoryMap
.
put
(
cid
,
storageInventory
);
inventoryMap
.
put
(
cid
,
storageInventory
);
}
}
// public Map<String,String> allBoxNameMap(){
// Map<String, String> allBoxMap = Maps.newHashMap();
// for (Storage storage : getAllStorage().values()){
// if(storage.getBoxCount() > 1){
// for (int i=1;i<=storage.getBoxCount();i++){
// allBoxMap.put(storage.getCid()+"-"+i, storage.getName() + " BOX-" + i);
// }
// }else{
// allBoxMap.put(storage.getCid()+"-i", storage.getName());
// }
// }
// return allBoxMap;
// }
}
}
src/main/java/com/neotel/smfcore/core/language/config/LocaleConfig.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
language
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.i18n.LocaleChangeInterceptor
;
import
org.springframework.web.servlet.i18n.SessionLocaleResolver
;
import
java.util.Locale
;
/**
* 配置国际化语言
* Created by sunke on 2021/7/30.
*/
@Configuration
public
class
LocaleConfig
{
/**
* 默认解析器 其中locale表示默认语言
*/
@Bean
public
LocaleResolver
localeResolver
()
{
SessionLocaleResolver
localeResolver
=
new
SessionLocaleResolver
();
localeResolver
.
setDefaultLocale
(
Locale
.
CHINESE
);
return
localeResolver
;
}
/**
* 默认拦截器 其中lang表示切换语言的参数名
*/
@Bean
public
WebMvcConfigurer
localeInterceptor
()
{
return
new
WebMvcConfigurer
()
{
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
LocaleChangeInterceptor
localeInterceptor
=
new
LocaleChangeInterceptor
();
localeInterceptor
.
setParamName
(
"lang"
);
registry
.
addInterceptor
(
localeInterceptor
);
}
};
}
}
src/main/java/com/neotel/smfcore/core/language/util/MessageUtils.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
language
.
util
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
java.util.Locale
;
/**
* 国际化工具类
* Created by sunke on 2021/7/30.
*/
@Component
public
class
MessageUtils
{
private
static
MessageSource
messageSource
;
public
MessageUtils
(
MessageSource
messageSource
)
{
MessageUtils
.
messageSource
=
messageSource
;
}
public
String
getText
(
String
msgKey
,
Locale
locale
,
String
defaultMsg
)
{
return
getText
(
msgKey
,
null
,
locale
,
defaultMsg
);
}
public
String
getText
(
String
msgKey
,
String
[]
params
,
Locale
locale
,
String
defaultMsg
)
{
try
{
if
(
params
!=
null
)
{
return
messageSource
.
getMessage
(
msgKey
,
params
,
locale
);
}
else
{
return
messageSource
.
getMessage
(
msgKey
,
new
String
[]{},
locale
);
}
}
catch
(
Exception
ex
){
if
(
defaultMsg
!=
null
){
return
defaultMsg
;
}
return
msgKey
;
}
}
}
src/main/java/com/neotel/smfcore/core/system/enums/CacheKey.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
system
.
enums
;
/**
* Created by sunke on 2021/7/29.
*/
public
class
CacheKey
{
/**
* 支持语言列表
*/
public
static
final
String
LANGUAGE_KEY
=
"config.language"
;
}
src/main/java/com/neotel/smfcore/core/system/service/dao/ICacheItemDao.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
system
.
service
.
dao
;
import
com.neotel.smfcore.common.base.IBaseDao
;
public
interface
ICacheItemDao
extends
IBaseDao
{
void
updateCacheItem
(
String
cacheKey
,
Object
cacheValue
);
}
src/main/java/com/neotel/smfcore/core/system/service/dao/impl/CacheItemDaoImpl.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
system
.
service
.
dao
.
impl
;
import
com.neotel.smfcore.common.base.AbstractBaseDao
;
import
com.neotel.smfcore.core.system.service.dao.ICacheItemDao
;
import
com.neotel.smfcore.core.system.service.dao.ISettingsDao
;
import
com.neotel.smfcore.core.system.service.po.CacheItem
;
import
com.neotel.smfcore.core.system.service.po.Settings
;
import
org.springframework.stereotype.Service
;
@Service
public
class
CacheItemDaoImpl
extends
AbstractBaseDao
implements
ICacheItemDao
{
@Override
public
void
updateCacheItem
(
String
cacheKey
,
Object
cacheValue
){
CacheItem
cacheInfo
=
getCacheInfo
(
cacheKey
);
if
(
cacheInfo
==
null
){
cacheInfo
=
new
CacheItem
();
cacheInfo
.
setCacheKey
(
cacheKey
);
}
cacheInfo
.
setCacheValue
(
cacheValue
);
save
(
cacheInfo
);
}
private
CacheItem
getCacheInfo
(
String
cacheKey
){
return
findOneByCondition
(
new
String
[]{
"cacheKey"
},
new
String
[]{
cacheKey
});
}
@Override
public
Class
getEntityClass
()
{
return
CacheItem
.
class
;
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/com/neotel/smfcore/core/system/service/po/CacheItem.java
0 → 100644
查看文件 @
f797b3a
package
com
.
neotel
.
smfcore
.
core
.
system
.
service
.
po
;
import
com.neotel.smfcore.common.base.BasePo
;
import
lombok.Data
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.io.Serializable
;
/**
* 缓存信息
*/
@Data
@Document
public
class
CacheItem
extends
BasePo
implements
Serializable
{
private
String
cacheKey
=
""
;
private
Object
cacheValue
;
}
src/main/java/com/neotel/smfcore/security/config/ConfigurerAdapter.java
查看文件 @
f797b3a
...
@@ -53,24 +53,16 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
...
@@ -53,24 +53,16 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
@Bean
@Bean
public
CorsFilter
corsFilter
()
{
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
CorsConfiguration
config
=
new
CorsConfiguration
();
CorsConfiguration
config
=
new
CorsConfiguration
();
// 是否允许请求带有验证信息
//允许所有域名进行跨域调用
config
.
addAllowedOriginPattern
(
"*"
);
//替换这个
//允许跨越发送cookie
config
.
setAllowCredentials
(
true
);
config
.
setAllowCredentials
(
true
);
//放行全部原始头信息
// 允许访问的客户端域名
// (springboot2.4以上的加入这一段可解决 allowedOrigins cannot contain the special value "*"问题)
List
<
String
>
allowedOriginPatterns
=
new
ArrayList
<>();
allowedOriginPatterns
.
add
(
"*"
);
config
.
setAllowedOriginPatterns
(
allowedOriginPatterns
);
// 设置访问源地址
// config.addAllowedOrigin("*");
// 设置访问源请求头
config
.
addAllowedHeader
(
"*"
);
config
.
addAllowedHeader
(
"*"
);
//
设置访问源请求方法
//
允许所有请求方法跨域调用
config
.
addAllowedMethod
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
// 对接口配置跨域设置
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
config
);
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
return
new
CorsFilter
(
source
);
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论