Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
e0fb87e9
Commit
e0fb87e9
authored
Jul 03, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
区域码迁移
parent
cb0f0f86
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
602 additions
and
14 deletions
+602
-14
UserSourceEnum.java
...oqi/security/admin/constant/enumerate/UserSourceEnum.java
+35
-0
AppUserDetail.java
...m/github/wxiaoqi/security/admin/entity/AppUserDetail.java
+1
-0
pom.xml
ace-modules/ace-admin/pom.xml
+5
-0
AdminBootstrap.java
...ava/com/github/wxiaoqi/security/admin/AdminBootstrap.java
+0
-1
AppPermissionService.java
...aoqi/security/admin/rpc/service/AppPermissionService.java
+40
-11
RedisKey.java
...n/java/com/xxfc/platform/universal/constant/RedisKey.java
+1
-2
RegionType.java
...java/com/xxfc/platform/universal/constant/RegionType.java
+58
-0
ResCode.java
...in/java/com/xxfc/platform/universal/constant/ResCode.java
+37
-0
RegionDTO.java
.../main/java/com/xxfc/platform/universal/dto/RegionDTO.java
+21
-0
SysRegion.java
...in/java/com/xxfc/platform/universal/entity/SysRegion.java
+35
-0
RegionFeign.java
...n/java/com/xxfc/platform/universal/feign/RegionFeign.java
+17
-0
ThirdFeign.java
...in/java/com/xxfc/platform/universal/feign/ThirdFeign.java
+2
-0
CustomIllegalParamException.java
...c/platform/universal/msg/CustomIllegalParamException.java
+8
-0
UniversalApplication.java
...ava/com/xxfc/platform/universal/UniversalApplication.java
+2
-0
SysRegionBiz.java
...in/java/com/xxfc/platform/universal/biz/SysRegionBiz.java
+190
-0
WebConfiguration.java
.../com/xxfc/platform/universal/config/WebConfiguration.java
+11
-0
SysRegionController.java
...fc/platform/universal/controller/SysRegionController.java
+87
-0
SysRegionMapper.java
...a/com/xxfc/platform/universal/mapper/SysRegionMapper.java
+24
-0
SysRegionMapper.xml
...rsal-server/src/main/resources/mapper/SysRegionMapper.xml
+28
-0
No files found.
ace-modules/ace-admin-api/src/main/java/com/github/wxiaoqi/security/admin/constant/enumerate/UserSourceEnum.java
0 → 100644
View file @
e0fb87e9
package
com
.
github
.
wxiaoqi
.
security
.
admin
.
constant
.
enumerate
;
/**
* @author libin
* @version 1.0
* @description 用户来源
* @data 2019/7/3 18:31
*/
public
enum
UserSourceEnum
{
APP
(
0
,
"APP"
),
APPLET
(
1
,
"小程序"
),
NEWPROMOTION
(
2
,
"新人推广"
);
private
int
code
;
private
String
source
;
UserSourceEnum
(
int
code
,
String
source
)
{
this
.
code
=
code
;
this
.
source
=
source
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getSource
()
{
return
source
;
}
public
void
setSource
(
String
source
)
{
this
.
source
=
source
;
}
}
ace-modules/ace-admin-api/src/main/java/com/github/wxiaoqi/security/admin/entity/AppUserDetail.java
View file @
e0fb87e9
...
...
@@ -31,5 +31,6 @@ public class AppUserDetail {
private
Long
createtime
;
private
Long
updatetime
;
private
Integer
isdel
;
private
Integer
channel
;
}
ace-modules/ace-admin/pom.xml
View file @
e0fb87e9
...
...
@@ -219,6 +219,11 @@
<version>
2.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.xxfc.platform
</groupId>
<artifactId>
xx-universal-api
</artifactId>
<version>
2.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<finalName>
ace-admin
</finalName>
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/AdminBootstrap.java
View file @
e0fb87e9
...
...
@@ -23,7 +23,6 @@ import tk.mybatis.spring.annotation.MapperScan;
@EnableDiscoveryClient
@EnableCircuitBreaker
@SpringBootApplication
@EnableFeignClients
(
value
=
{
"com.github.wxiaoqi.security"
,
"com.xxfc.platform"
},
defaultConfiguration
=
HeaderConfig
.
class
)
@EnableScheduling
@EnableAceAuthClient
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/service/AppPermissionService.java
View file @
e0fb87e9
package
com
.
github
.
wxiaoqi
.
security
.
admin
.
rpc
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.admin.biz.AppUserBiz
;
import
com.github.wxiaoqi.security.admin.biz.AppUserDetailBiz
;
import
com.github.wxiaoqi.security.admin.biz.AppUserLoginBiz
;
import
com.github.wxiaoqi.security.admin.biz.ElementBiz
;
import
com.github.wxiaoqi.security.admin.constant.RedisKey
;
import
com.github.wxiaoqi.security.admin.constant.enumerate.UserSourceEnum
;
import
com.github.wxiaoqi.security.admin.entity.*
;
import
com.github.wxiaoqi.security.admin.vo.AppUserVo
;
import
com.github.wxiaoqi.security.api.vo.authority.PermissionInfo
;
...
...
@@ -21,6 +21,8 @@ import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import
com.github.wxiaoqi.security.common.util.result.JsonResultUtil
;
import
com.xxfc.platform.activity.Feign.ActivityFeign
;
import
com.xxfc.platform.im.feign.ImFeign
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
com.xxfc.platform.universal.feign.RegionFeign
;
import
com.xxfc.platform.universal.feign.ThirdFeign
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -30,10 +32,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -62,6 +62,9 @@ public class AppPermissionService {
@Autowired
ActivityFeign
activityFeign
;
@Resource
private
RegionFeign
regionFeign
;
private
BCryptPasswordEncoder
encoder
=
new
BCryptPasswordEncoder
(
12
);
@Autowired
private
RedisTemplate
userRedisTemplate
;
...
...
@@ -73,7 +76,7 @@ public class AppPermissionService {
@Autowired
private
RestTemplate
restTemplate
;
private
static
final
String
BASE_IP_PARSING_URL
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
;
public
AppUserInfo
validate
(
String
username
,
String
password
)
{
...
...
@@ -207,6 +210,8 @@ public class AppPermissionService {
AppUserLogin
appUserLogin
=
new
AppUserLogin
();
//主要是ip地址
EntityUtils
.
setCreatAndUpdatInfo
(
appUserLogin
);
setCreateIPInfo
(
appUserLogin
);
appUserLogin
.
setUsername
(
username
);
appUserLogin
.
setPassword
(
password
);
appUserLogin
.
setIsdel
(
0
);
...
...
@@ -680,7 +685,7 @@ public class AppPermissionService {
*/
public
JSONObject
appletLoginByUserId
(
Integer
uid
)
{
JSONObject
data
=
autoLogin
(
uid
,
null
,
null
,
null
);
if
(
data
!=
null
){
if
(
data
.
getDate
(
"userId"
)
!=
null
){
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"用户不存在"
);
...
...
@@ -712,6 +717,8 @@ public class AppPermissionService {
AppUserLogin
appUserLogin
=
new
AppUserLogin
();
//主要是ip地址
EntityUtils
.
setCreatAndUpdatInfo
(
appUserLogin
);
setCreateIPInfo
(
appUserLogin
);
appUserLogin
.
setUsername
(
username
);
appUserLogin
.
setPassword
(
password
);
appUserLogin
.
setIsdel
(
0
);
...
...
@@ -729,6 +736,8 @@ public class AppPermissionService {
rsUserDetail
.
setCreatetime
(
now
);
rsUserDetail
.
setUpdatetime
(
now
);
rsUserDetail
.
setIsdel
(
0
);
//设置来源
rsUserDetail
.
setChannel
(
UserSourceEnum
.
APPLET
.
getCode
());
appUserDetailBiz
.
insertSelective
(
rsUserDetail
);
log
.
error
(
"注册:新增用户详情: "
+
userid
);
//自动登录获取优惠卷
...
...
@@ -792,19 +801,39 @@ public class AppPermissionService {
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
/**
* ip地址 信息解析
* @param appUserLogin
*/
public
void
setCreateIPInfo
(
AppUserLogin
appUserLogin
){
String
crtHost
=
appUserLogin
.
getCrtHost
();
String
ipinfo
=
restTemplate
.
getForObject
(
String
.
format
(
"%s%s"
,
BASE_IP_PARSING_URL
,
crtHost
),
String
.
class
);
String
ipinfo
=
restTemplate
.
getForObject
(
String
.
format
(
"%s%s"
,
IPCommon
.
BASE_IP_PARSING_URL
,
crtHost
),
String
.
class
);
String
base_data
=
JSONObject
.
parseObject
(
ipinfo
).
getString
(
IPCommon
.
BASE_DATA
);
JSONObject
ipJsonObject
=
JSONObject
.
parseObject
(
base_data
);
Integer
provinceCode
=
ipJsonObject
.
getInteger
(
IPCommon
.
PROVINCE_CODE
);
Integer
cityCode
=
ipJsonObject
.
getInteger
(
IPCommon
.
CITY_CODE
);
appUserLogin
.
setProvinceCode
(
provinceCode
);
appUserLogin
.
setCityCode
(
cityCode
);
// Integer provinceCode = ipJsonObject.getInteger(IPCommon.PROVINCE_CODE);
// Integer cityCode = ipJsonObject.getInteger(IPCommon.CITY_CODE);
//appUserLogin.setProvinceCode(provinceCode);
//appUserLogin.setCityCode(cityCode);
String
cityName
=
ipJsonObject
.
getString
(
IPCommon
.
CITY_NAME
);
RegionDTO
regionDTO
=
regionFeign
.
getRegionByCityName
(
cityName
);
if
(
null
!=
regionDTO
){
appUserLogin
.
setProvinceCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getParentId
())));
appUserLogin
.
setCityCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getId
())));
}
}
/**
* @author libin
* @version 1.0.0
* @dec ip返回字段名常量
*/
static
class
IPCommon
{
public
static
final
String
BASE_IP_PARSING_URL
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
;
public
static
final
String
BASE_DATA
=
"data"
;
public
static
final
String
PROVINCE_CODE
=
"region_id"
;
public
static
final
String
CITY_CODE
=
"city_id"
;
public
static
final
String
CITY_NAME
=
"city"
;
public
static
final
String
PROVINCE_NAME
=
"region"
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/constant/RedisKey.java
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
vehicle
.
constant
;
package
com
.
xxfc
.
platform
.
universal
.
constant
;
public
class
RedisKey
{
/**
...
...
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/constant/RegionType.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
constant
;
import
java.util.HashMap
;
import
java.util.Map
;
public
enum
RegionType
{
COUNTRY
(-
1
,
"国家"
),
//这一类型不存在db中,只是用于查询所有国家
REGION
(
0
,
"地区"
),
PROVINCE
(
1
,
"省/直辖市"
),
CITY
(
2
,
"市"
),
PREFECTUR
(
3
,
"县"
),
TOWN
(
4
,
"镇"
),
;
/**
* 编码
*/
private
Integer
code
;
/**
* 类型描述
*/
private
String
desc
;
private
static
Map
<
Integer
,
String
>
codeAndDesc
=
new
HashMap
<
Integer
,
String
>();
//Maps.newHashMap();
static
{
for
(
RegionType
constantType
:
RegionType
.
values
()){
codeAndDesc
.
put
(
constantType
.
getCode
(),
constantType
.
getDesc
());
}
}
RegionType
(
Integer
code
,
String
desc
){
this
.
code
=
code
;
this
.
desc
=
desc
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getDesc
()
{
return
desc
;
}
public
void
setDesc
(
String
desc
)
{
this
.
desc
=
desc
;
}
public
static
Boolean
exists
(
Integer
code
){
return
codeAndDesc
.
containsKey
(
code
);
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/constant/ResCode.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
constant
;
public
enum
ResCode
{
AUTH_FAIL
(-
1
,
"权限验证不通过"
),
INVALID_REST_REQ_PARAM
(
100000
,
"rest请求参数非法"
);
/**
* 返回码
*/
private
Integer
code
;
/**
* 描述
*/
private
String
desc
;
ResCode
(
Integer
code
,
String
desc
){
this
.
code
=
code
;
this
.
desc
=
desc
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getDesc
()
{
return
desc
;
}
public
void
setDesc
(
String
desc
)
{
this
.
desc
=
desc
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/dto/RegionDTO.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/3 17:51
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
RegionDTO
{
private
Long
id
;
private
Long
parentId
;
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/entity/SysRegion.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
entity
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.experimental.Tolerate
;
@Data
@Builder
(
toBuilder
=
true
)
public
class
SysRegion
{
@Tolerate
public
SysRegion
()
{
}
private
Long
id
;
/**
* 所属父地区id
*/
private
Long
parentId
;
private
String
name
;
/**
* 地区类型 0-国家 1-省/直辖市 2-市 3 - 镇、县
*/
private
Integer
type
;
/**
* 从左往右,第1,2位代表省代码,3、4为代表市代码,5-6位代表镇或县代码
*/
private
Integer
agencyId
;
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/feign/RegionFeign.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
feign
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
@FeignClient
(
value
=
"xx-universal"
,
contextId
=
"region"
)
public
interface
RegionFeign
{
/**
* 根据城市名查询
* @param city
* @return
*/
@GetMapping
(
"/sysRegion/region_name"
)
RegionDTO
getRegionByCityName
(
@RequestParam
(
value
=
"city"
)
String
city
);
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/feign/ThirdFeign.java
View file @
e0fb87e9
...
...
@@ -2,6 +2,7 @@ package com.xxfc.platform.universal.feign;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
com.xxfc.platform.universal.entity.Dictionary
;
import
com.xxfc.platform.universal.entity.OrderRefund
;
import
com.xxfc.platform.universal.vo.*
;
...
...
@@ -75,4 +76,5 @@ public interface ThirdFeign {
/***************************************** 违章 ********************************************/
@GetMapping
(
"/3p/tv/getRentViolation"
)
public
ObjectRestResponse
<
List
<
ViolationVO
>>
getRentViolation
(
@RequestParam
(
value
=
"rentViolationDTO"
)
Map
<
String
,
Object
>
rentViolationDTO
);
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/msg/CustomIllegalParamException.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
msg
;
public
class
CustomIllegalParamException
extends
RuntimeException
{
public
CustomIllegalParamException
(
String
msg
){
super
(
msg
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/UniversalApplication.java
View file @
e0fb87e9
...
...
@@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@SpringBootApplication
(
scanBasePackages
=
{
...
...
@@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
})
@EnableDiscoveryClient
@EnableAceAuthClient
@EnableScheduling
@EnableAceCache
@EnableTransactionManagement
@tk
.
mybatis
.
spring
.
annotation
.
MapperScan
(
basePackages
=
"com.xxfc.platform.universal.mapper"
)
...
...
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/SysRegionBiz.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
biz
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.google.common.collect.Lists
;
import
com.xxfc.platform.universal.constant.RedisKey
;
import
com.xxfc.platform.universal.constant.RegionType
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
com.xxfc.platform.universal.entity.SysRegion
;
import
com.xxfc.platform.universal.mapper.SysRegionMapper
;
import
com.xxfc.platform.universal.msg.CustomIllegalParamException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.joda.time.DateTime
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.core.task.TaskExecutor
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.weekend.WeekendSqls
;
import
java.util.List
;
@Service
@Slf4j
public
class
SysRegionBiz
extends
BaseBiz
<
SysRegionMapper
,
SysRegion
>
{
@Autowired
private
RedisTemplate
customRedisTemplate
;
//todo redis需要改为多实例
@Autowired
@Qualifier
(
value
=
"applicationTaskExecutor"
)
private
TaskExecutor
customTaskExecutor
;
/**
* 国家没有父地区,其parentId为0
*/
private
static
final
Long
PARENT_ID_NONE
=
0
l
;
public
List
<
SysRegion
>
getRegionsByCodes
(
List
<
Long
>
ids
){
List
<
String
>
redisCacheKeys
=
Lists
.
newArrayList
();
if
(
CollectionUtils
.
isEmpty
(
ids
)){
throw
new
CustomIllegalParamException
(
"empty id list"
);
}
for
(
Long
id:
ids
){
redisCacheKeys
.
add
(
RedisKey
.
SYS_REGION_CACHE_PREFIX
+
id
);
}
List
<
String
>
cachedRegionStrList
=
customRedisTemplate
.
opsForValue
().
multiGet
(
redisCacheKeys
);
List
<
SysRegion
>
rs
=
Lists
.
newArrayList
();
Boolean
hasCache
=
Boolean
.
TRUE
;
for
(
String
cachedRegionStr:
cachedRegionStrList
){
if
(
StringUtils
.
isBlank
(
cachedRegionStr
)){
hasCache
=
Boolean
.
FALSE
;
continue
;
}
else
{
rs
.
add
(
JSONObject
.
parseObject
(
cachedRegionStr
,
SysRegion
.
class
));
}
}
if
(!
hasCache
){
//从db读
rs
=
mapper
.
getByIdList
(
ids
);
}
return
rs
;
}
//获取相应地区类型对应在id的位数,作为对应parent查找其下地区的redis key组成部分
private
String
getPrefixOfAgencyId
(
Integer
type
,
Long
parentId
){
return
String
.
valueOf
(
parentId
);
}
/**
* 获取对应redis中的hash的key
* @param parentId
* @return
*/
private
String
getCacheRedisKey
(
Long
parentId
){
//获取相应地区类型对应在agencyId的位数
return
RedisKey
.
SYS_REGION_SONS_CACHE_PREFIX
+
parentId
;
}
/**
* 查询对应地区之下的地区
* @param id
* @return
*/
public
List
<
SysRegion
>
getSonRegion
(
Long
id
){
//从缓存中查询
String
redisKey
=
getCacheRedisKey
(
id
);
String
sysRegionListJson
=
String
.
valueOf
(
customRedisTemplate
.
opsForValue
().
get
(
redisKey
));
List
<
SysRegion
>
sysRegions
=
null
;
if
(
StringUtils
.
isNotBlank
(
sysRegionListJson
)){
sysRegions
=
JSONObject
.
parseArray
(
sysRegionListJson
,
SysRegion
.
class
);
}
if
(
CollectionUtils
.
isNotEmpty
(
sysRegions
)){
return
sysRegions
;
}
//不存在则异步开启刷新缓存任务
refreshCacheAsync
();
//从db中查询
return
getSonRegionNoCache
(
id
);
}
public
List
<
SysRegion
>
getSonRegionNoCache
(
Long
parentId
){
//从db中查询
SysRegion
param
=
new
SysRegion
();
param
.
setParentId
(
parentId
);
return
mapper
.
select
(
param
);
}
public
void
refreshCacheAsync
(){
customTaskExecutor
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
refreshCache
();
}
});
}
/**
* 刷新其孩子节点到缓存,并对其孩子迭代执行此操作
* @param parentId
*/
private
void
refreshCacheRegionAndSon
(
Long
parentId
){
List
<
SysRegion
>
sonRegions
=
getSonRegionNoCache
(
parentId
);
//把当前节点的子节点数据缓存
String
redisKey
=
getCacheRedisKey
(
parentId
);
customRedisTemplate
.
opsForValue
().
set
(
redisKey
,
JSON
.
toJSON
(
sonRegions
).
toString
());
log
.
info
(
"完成地区【"
+
parentId
+
"】的子地区数据缓存"
);
if
(
CollectionUtils
.
isEmpty
(
sonRegions
)
||
sonRegions
.
get
(
0
).
getType
().
equals
(
RegionType
.
CITY
.
getCode
())){
return
;
}
for
(
SysRegion
sonRegion:
sonRegions
){
//缓存每个地区
customRedisTemplate
.
opsForValue
().
set
(
RedisKey
.
SYS_REGION_CACHE_PREFIX
+
sonRegion
.
getId
(),
JSON
.
toJSON
(
sonRegion
).
toString
());
refreshCacheRegionAndSon
(
sonRegion
.
getId
());
}
}
/**
* 5分钟内刷新数据到缓存
*/
@Scheduled
(
cron
=
"0 */5 * * * *"
)
//每5分钟刷新一次数据
public
void
refreshCache
(){
String
redisLockKey
=
RedisKey
.
SYS_REGION_REFRESH_LOCK
+(
DateTime
.
now
().
getMinuteOfDay
()/
5
);
//同一日每5分钟只刷新一次
Boolean
suc
=
customRedisTemplate
.
opsForValue
().
setIfAbsent
(
redisLockKey
,
String
.
valueOf
(
DateTime
.
now
().
getMillis
()));
if
(!
suc
){
log
.
info
(
"刷新地区数据:获取乐观锁失败,不执行任务"
);
return
;
}
log
.
info
(
"刷新地区数据任务开始"
);
refreshCacheRegionAndSon
(
PARENT_ID_NONE
);
log
.
info
(
"刷新常量数据任务成功"
);
}
/**
* 5分钟内刷新数据到缓存
*/
public
List
<
SysRegion
>
selectCity
(){
List
<
SysRegion
>
selectByWeekendSql
=
mapper
.
selectByExample
(
new
Example
.
Builder
(
SysRegion
.
class
)
.
where
(
WeekendSqls
.<
SysRegion
>
custom
().
andLike
(
SysRegion:
:
getId
,
"%00"
)
.
andNotLike
(
SysRegion:
:
getId
,
"%0000"
))
.
build
());
return
selectByWeekendSql
;
}
/**
* 通过属性获取省
* @param type
* @return
*/
public
List
<
SysRegion
>
getSysRegionByType
(
Integer
type
){
SysRegion
sysRegion
=
new
SysRegion
();
sysRegion
.
setType
(
type
);
return
mapper
.
select
(
sysRegion
);
}
public
RegionDTO
findRegionByCityName
(
String
city
)
{
return
mapper
.
findByCityName
(
city
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/config/WebConfiguration.java
View file @
e0fb87e9
...
...
@@ -6,6 +6,8 @@ import com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.task.TaskExecutor
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -51,4 +53,13 @@ public class WebConfiguration implements WebMvcConfigurer {
Collections
.
addAll
(
list
,
urls
);
return
list
;
}
/* @Bean(name = "customTaskExecutor")
TaskExecutor getTaskExecutor(){
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(5);// 线程池维护线程的最少数量
threadPoolTaskExecutor.setMaxPoolSize(10);// 线程池维护线程的最大数量
threadPoolTaskExecutor.setQueueCapacity(50);// 缓存队列
return threadPoolTaskExecutor;
}*/
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/controller/SysRegionController.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONException
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.rest.BaseController
;
import
com.xxfc.platform.universal.biz.SysRegionBiz
;
import
com.xxfc.platform.universal.constant.ResCode
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
com.xxfc.platform.universal.entity.SysRegion
;
import
com.xxfc.platform.universal.msg.CustomIllegalParamException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.assertj.core.util.Arrays
;
import
org.springframework.web.bind.annotation.*
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.weekend.WeekendSqls
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sysRegion"
)
@IgnoreClientToken
@Slf4j
public
class
SysRegionController
extends
BaseController
<
SysRegionBiz
,
SysRegion
>
{
/**
* 父类id获取子类对象
* @param id
* @return
*/
@IgnoreUserToken
@RequestMapping
(
value
=
"/sons/{id}"
,
method
=
RequestMethod
.
GET
)
public
ObjectRestResponse
<
List
<
SysRegion
>>
getSonRegion
(
@PathVariable
Long
id
){
return
ObjectRestResponse
.
succ
(
baseBiz
.
getSonRegion
(
id
));
}
/**
* 通过属性获取省
* @param type
* @return
*/
@IgnoreUserToken
@RequestMapping
(
value
=
"/getSonRegionByType/{type}"
,
method
=
RequestMethod
.
GET
)
public
ObjectRestResponse
<
List
<
SysRegion
>>
getSysRegionByType
(
@PathVariable
Integer
type
){
return
ObjectRestResponse
.
succ
(
baseBiz
.
getSysRegionByType
(
type
));
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
ObjectRestResponse
<
List
<
SysRegion
>>
getRegion
(
@RequestParam
String
idListJson
){
try
{
List
<
Long
>
ids
=
JSON
.
parseArray
(
idListJson
,
Long
.
class
);
return
ObjectRestResponse
.
succ
(
baseBiz
.
getRegionsByCodes
(
ids
));
}
catch
(
JSONException
ex
)
{
return
ObjectRestResponse
.
createFailedResultMsg
(
ResCode
.
INVALID_REST_REQ_PARAM
.
getCode
());
}
catch
(
CustomIllegalParamException
ex
){
return
ObjectRestResponse
.
createFailedResultMsg
(
ResCode
.
INVALID_REST_REQ_PARAM
.
getCode
());
}
}
/**
* 根据多个id查找省份
* @param ids
* @return
*/
@GetMapping
(
"/getSysRegionByIds/{ids}"
)
public
ObjectRestResponse
getSysRegionByIds
(
@PathVariable
String
ids
){
Example
exam
=
Example
.
builder
(
SysRegion
.
class
)
.
where
(
WeekendSqls
.<
SysRegion
>
custom
()
.
andIn
(
SysRegion:
:
getId
,
Arrays
.
asList
(
ids
.
split
(
","
)))).
build
();
return
ObjectRestResponse
.
succ
(
baseBiz
.
selectByExample
(
exam
));
}
/**
* 通过城市名查询
* @param city
* @return
*/
@GetMapping
(
"/region_name"
)
public
RegionDTO
getRegionByCityName
(
@RequestParam
(
value
=
"city"
)
String
city
){
return
baseBiz
.
findRegionByCityName
(
city
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/mapper/SysRegionMapper.java
0 → 100644
View file @
e0fb87e9
package
com
.
xxfc
.
platform
.
universal
.
mapper
;
import
com.xxfc.platform.universal.dto.RegionDTO
;
import
com.xxfc.platform.universal.entity.SysRegion
;
import
org.springframework.data.repository.query.Param
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
import
java.util.Map
;
public
interface
SysRegionMapper
extends
Mapper
<
SysRegion
>
{
public
List
<
SysRegion
>
getAllByPage
(
Map
<
String
,
Object
>
params
);
public
List
<
SysRegion
>
getByIdList
(
List
<
Long
>
idList
);
//获取地区的编号
public
Integer
getNumber
(
@Param
(
"name"
)
String
name
);
//获取地区的编号
public
Integer
getNumberV2
(
@Param
(
"name"
)
String
name
,
@Param
(
"type"
)
Integer
type
);
RegionDTO
findByCityName
(
String
city
);
}
xx-universal/xx-universal-server/src/main/resources/mapper/SysRegionMapper.xml
0 → 100644
View file @
e0fb87e9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.xxfc.platform.universal.mapper.SysRegionMapper"
>
<select
id=
"getAllByPage"
parameterType=
"java.util.Map"
resultType=
"com.xxfc.platform.universal.entity.SysRegion"
>
select `id`, parent_id, `name`, `type`, agency_id from sys_region limit #{pageStart},${pageSize}
</select>
<select
id=
"getByIdList"
parameterType=
"java.util.List"
resultType=
"com.xxfc.platform.universal.entity.SysRegion"
>
select `id`, parent_id, `name`, `type`, agency_id from sys_region where id in
<foreach
collection=
"list"
index=
"i"
item=
"item"
open=
"("
close=
")"
separator=
","
>
#{item}
</foreach>
</select>
<select
id=
"getNumber"
resultType=
"Integer"
>
select `id` from sys_region where name like CONCAT('%',#{name},'%') limit 1
</select>
<select
id=
"getNumberV2"
resultType=
"Integer"
>
select `id` from sys_region where name like CONCAT('%',#{name},'%') and type=#{type} limit 1
</select>
<select
id=
"findByCityName"
resultType=
"com.xxfc.platform.universal.dto.RegionDTO"
>
select `id`,`parent_id` as `parentId` from `sys_region` where `type`=2 and `name` like concat('%',#{city} ,'%')
</select>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
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