Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
3af6d8c3
Commit
3af6d8c3
authored
Jul 23, 2018
by
Menethil
Browse files
系统配置移至Core模块,添加系统配置基类以规范配置类的行为
parent
0e62f33e
Changes
9
Hide whitespace changes
Inline
Side-by-side
litemall-core/pom.xml
View file @
3af6d8c3
...
...
@@ -66,6 +66,10 @@
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.linlinjava
</groupId>
<artifactId>
litemall-db
</artifactId>
</dependency>
</dependencies>
<build>
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/Application.java
View file @
3af6d8c3
package
org.linlinjava.litemall.core
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
@SpringBootApplication
(
scanBasePackages
=
{
"org.linlinjava.litemall.core"
,
"org.linlinjava.litemall.db"
})
@MapperScan
(
"org.linlinjava.litemall.db.dao"
)
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/system/BaseConfig.java
0 → 100644
View file @
3af6d8c3
package
org.linlinjava.litemall.core.system
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* 配置基类,该类实际持有所有的配置,子类只是提供代理访问方法
*/
abstract
class
BaseConfig
{
//所有的配置均保存在该 HashMap 中
protected
static
Map
<
String
,
String
>
configs
=
new
HashMap
<>();
/**
* 子类实现该方法,并告知父类配置前缀,该前缀用来索引配置组用于简化访问和按组重读配置
*
* @return
*/
abstract
String
getPrefix
();
/**
* 添加配置到公共Map中
*
* @param key
* @param value
*/
public
static
void
addConfig
(
String
key
,
String
value
)
{
configs
.
put
(
key
,
value
);
}
/**
* 重载配置,传入子类的prefix
*/
public
static
void
reloadConfig
(
String
prefix
)
{
//先遍历删除该 prefix 所有配置
for
(
Iterator
<
Map
.
Entry
<
String
,
String
>>
it
=
configs
.
entrySet
().
iterator
();
it
.
hasNext
();
)
{
Map
.
Entry
<
String
,
String
>
item
=
it
.
next
();
if
(
item
.
getKey
().
startsWith
(
prefix
))
it
.
remove
();
}
ConfigService
.
getSystemConfigService
().
reloadConfig
(
prefix
);
}
/**
* 按String类型获取配置值
*
* @param keyName
* @return
*/
protected
static
String
getConfig
(
String
keyName
)
{
return
configs
.
get
(
keyName
);
}
/**
* 以Integer类型获取配置值
*
* @param keyName
* @return
*/
protected
static
Integer
getConfigInt
(
String
keyName
)
{
return
Integer
.
parseInt
(
configs
.
get
(
keyName
));
}
/**
* 以BigDecimal类型获取配置值
*
* @param keyName
* @return
*/
protected
static
BigDecimal
getConfigBigDec
(
String
keyName
)
{
return
new
BigDecimal
(
configs
.
get
(
keyName
));
}
}
litemall-
wx-api
/src/main/java/org/linlinjava/litemall/
wx/service
/ConfigService.java
→
litemall-
core
/src/main/java/org/linlinjava/litemall/
core/system
/ConfigService.java
View file @
3af6d8c3
package
org.linlinjava.litemall.
wx.service
;
package
org.linlinjava.litemall.
core.system
;
import
org.linlinjava.litemall.db.domain.LitemallSystem
;
import
org.linlinjava.litemall.db.service.LitemallSystemConfigService
;
...
...
@@ -6,16 +6,18 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 该类用于自动初始化数据库配置到BaseConfig中,以便BaseConfig的子类调用
*/
@Component
public
class
ConfigService
{
class
ConfigService
{
private
static
ConfigService
systemConfigService
;
//系统配置组
private
Map
<
String
,
String
>
systemConfig
;
static
ConfigService
getSystemConfigService
()
{
return
systemConfigService
;
}
@Autowired
private
LitemallSystemConfigService
litemallSystemConfigService
;
...
...
@@ -25,55 +27,28 @@ public class ConfigService {
}
/**
* 获取系统配置
*
* @param keyName 例如 : litemall.system.freight.value
* @return 返回该值的字符串
*/
public
String
getSysValue
(
String
keyName
)
{
keyName
=
"litemall.system."
+
keyName
;
return
systemConfig
.
get
(
keyName
);
}
/**
* 获取系统配置数值型
*
* @param keyName 例如 : litemall.system.freight.value
* @return 返回该值的字符串
*/
public
Integer
getSysValueInt
(
String
keyName
)
{
keyName
=
"litemall.system."
+
keyName
;
return
Integer
.
parseInt
(
systemConfig
.
get
(
keyName
));
}
/**
* 获取系统设置实例
*
* @return
*/
public
static
ConfigService
getCfg
()
{
return
systemConfigService
;
}
@PostConstruct
public
void
inist
()
{
systemConfigService
=
this
;
systemConfigService
.
systemConfig
=
new
HashMap
<>();
systemConfigService
.
inistConfigs
();
}
public
void
reloadConfig
(
String
prefix
)
{
List
<
LitemallSystem
>
list
=
litemallSystemConfigService
.
queryAll
();
for
(
LitemallSystem
item
:
list
)
{
//符合条件,添加
if
(
item
.
getKeyName
().
startsWith
(
prefix
))
BaseConfig
.
addConfig
(
item
.
getKeyName
(),
item
.
getKeyValue
());
}
}
/**
* 读取全部配置
*/
private
void
inistConfigs
()
{
List
<
LitemallSystem
>
list
=
litemallSystemConfigService
.
queryAll
();
for
(
LitemallSystem
item
:
list
)
{
//属于系统配置,放置到系统配置组
if
(
item
.
getKeyName
().
startsWith
(
"litemall.system"
))
systemConfig
.
put
(
item
.
getKeyName
(),
item
.
getKeyValue
());
BaseConfig
.
addConfig
(
item
.
getKeyName
(),
item
.
getKeyValue
());
}
}
}
}
\ No newline at end of file
litemall-
wx-api
/src/main/java/org/linlinjava/litemall/
wx/service
/SystemConfig.java
→
litemall-
core
/src/main/java/org/linlinjava/litemall/
core/system
/SystemConfig.java
View file @
3af6d8c3
package
org.linlinjava.litemall.
wx.service
;
package
org.linlinjava.litemall.
core.system
;
import
java.math.BigDecimal
;
...
...
@@ -6,52 +6,59 @@ import java.math.BigDecimal;
* 系统设置
*/
public
class
SystemConfig
{
public
class
SystemConfig
extends
BaseConfig
{
public
static
final
String
PRE_FIX
=
"litemall.system."
;
public
static
Integer
getNewLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.new"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.new"
);
}
public
static
Integer
getHotLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.hot"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.hot"
);
}
public
static
Integer
getBrandLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.brand"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.brand"
);
}
public
static
Integer
getTopicLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.topic"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.topic"
);
}
public
static
Integer
getCatlogListLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.catloglist"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.catloglist"
);
}
public
static
Integer
getCatlogMoreLimit
()
{
return
Config
Service
.
getCfg
().
getSysValueInt
(
"indexlimit.catloggood"
);
return
get
Config
Int
(
PRE_FIX
+
"indexlimit.catloggood"
);
}
public
static
String
getHotBannerTitle
()
{
return
Config
Service
.
getCfg
().
getSysValue
(
"banner.hot.title"
);
return
get
Config
(
PRE_FIX
+
"banner.hot.title"
);
}
public
static
String
getNewBannerTitle
()
{
return
Config
Service
.
getCfg
().
getSysValue
(
"banner.new.title"
);
return
get
Config
(
PRE_FIX
+
"banner.new.title"
);
}
public
static
String
getHotImageUrl
()
{
return
Config
Service
.
getCfg
().
getSysValue
(
"banner.hot.imageurl"
);
return
get
Config
(
PRE_FIX
+
"banner.hot.imageurl"
);
}
public
static
String
getNewImageUrl
()
{
return
Config
Service
.
getCfg
().
getSysValue
(
"banner.new.imageurl"
);
return
get
Config
(
PRE_FIX
+
"banner.new.imageurl"
);
}
public
static
BigDecimal
getFreight
()
{
return
new
BigDecimal
(
ConfigService
.
getCfg
().
getSysValue
(
"freight.value"
)
)
;
return
getConfigBigDec
(
PRE_FIX
+
"freight.value"
);
}
public
static
BigDecimal
getFreightLimit
()
{
return
new
BigDecimal
(
ConfigService
.
getCfg
().
getSysValue
(
"freight.limit"
));
return
getConfigBigDec
(
PRE_FIX
+
"freight.limit"
);
}
@Override
public
String
getPrefix
()
{
return
PRE_FIX
;
}
}
}
\ No newline at end of file
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java
View file @
3af6d8c3
...
...
@@ -8,7 +8,7 @@ import org.linlinjava.litemall.db.service.*;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
import
org.linlinjava.litemall.
wx.service
.SystemConfig
;
import
org.linlinjava.litemall.
core.system
.SystemConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
View file @
3af6d8c3
...
...
@@ -7,7 +7,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import
org.linlinjava.litemall.db.domain.*
;
import
org.linlinjava.litemall.db.service.*
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
import
org.linlinjava.litemall.
wx.service
.SystemConfig
;
import
org.linlinjava.litemall.
core.system
.SystemConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
View file @
3af6d8c3
...
...
@@ -5,7 +5,7 @@ import org.apache.commons.logging.LogFactory;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.db.domain.*
;
import
org.linlinjava.litemall.db.service.*
;
import
org.linlinjava.litemall.
wx.service
.SystemConfig
;
import
org.linlinjava.litemall.
core.system
.SystemConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
3af6d8c3
...
...
@@ -18,7 +18,7 @@ import org.linlinjava.litemall.db.service.*;
import
org.linlinjava.litemall.db.util.OrderHandleOption
;
import
org.linlinjava.litemall.db.util.OrderUtil
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
import
org.linlinjava.litemall.
wx.service
.SystemConfig
;
import
org.linlinjava.litemall.
core.system
.SystemConfig
;
import
org.linlinjava.litemall.wx.util.IpUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.PlatformTransactionManager
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment