Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
392cde98
Commit
392cde98
authored
Nov 26, 2024
by
xuepeng.chang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
头像中涉及手机号的重新传
parent
75f061d1
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
723 additions
and
4 deletions
+723
-4
UserController.java
...n/quantgroup/xyqb/controller/external/UserController.java
+2
-1
UserCenterController.java
...controller/internal/user/center/UserCenterController.java
+71
-3
IUserInfoRepository.java
...va/cn/quantgroup/xyqb/repository/IUserInfoRepository.java
+3
-0
HttpClientUtil.java
src/main/java/cn/quantgroup/xyqb/util/HttpClientUtil.java
+499
-0
QiNiuYunUtil.java
src/main/java/cn/quantgroup/xyqb/util/QiNiuYunUtil.java
+148
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/UserController.java
View file @
392cde98
...
...
@@ -545,7 +545,8 @@ public class UserController implements IBaseController {
* @yapi http://yapi.quantgroups.com/project/17/interface/api/9191
*/
@RequestMapping
(
"/token"
)
public
JsonResult
token
(
@RequestParam
String
token
,
@RequestParam
(
required
=
false
)
Integer
tenantId
,
@RequestHeader
(
value
=
Constants
.
X_AUTH_TENANT
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantIdHeader
)
{
public
JsonResult
token
(
@RequestParam
String
token
,
@RequestParam
(
required
=
false
)
Integer
tenantId
,
@RequestHeader
(
value
=
Constants
.
X_AUTH_TENANT
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantIdHeader
)
{
if
(
tenantId
==
null
)
{
tenantId
=
tenantIdHeader
;
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/center/UserCenterController.java
View file @
392cde98
...
...
@@ -11,6 +11,8 @@ import cn.quantgroup.xyqb.model.JsonResult;
import
cn.quantgroup.xyqb.model.UserInfoEntityBean
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.util.HttpClientUtil
;
import
cn.quantgroup.xyqb.util.QiNiuYunUtil
;
import
cn.quantgroup.xyqb.util.TenantUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
...
...
@@ -25,9 +27,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* Created by 11 on 2017/3/22.
...
...
@@ -44,6 +47,12 @@ public class UserCenterController implements IBaseController {
private
IUserService
userService
;
@Autowired
private
ApplicationEventPublisher
applicationEventPublisher
;
@Autowired
private
QiNiuYunUtil
qiNiuYunUtil
;
private
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
10
);
private
static
final
java
.
util
.
regex
.
Pattern
pattern
=
java
.
util
.
regex
.
Pattern
.
compile
(
"(\\d{11})"
);
@GetMapping
(
"/attach"
)
public
JsonResult
queryUserAttach
(
Long
userId
,
@RequestHeader
(
value
=
Constants
.
X_AUTH_TENANT
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
...
...
@@ -230,6 +239,8 @@ public class UserCenterController implements IBaseController {
return
JsonResult
.
buildSuccessResult
(
"保存成功"
,
UserInfoEntityBean
.
covert
(
userInfoEntity
));
}
/**
* 查询用户是否实名认证.
*
...
...
@@ -297,4 +308,61 @@ public class UserCenterController implements IBaseController {
return JsonResult.buildSuccessResultGeneric(userAttachedList);
}*/
@RequestMapping
(
"/refreshAvatar"
)
public
JsonResult
refreshAvatar
(
@RequestParam
(
value
=
"id"
,
required
=
false
)
Long
id
){
if
(
Objects
.
isNull
(
id
)){
id
=
0L
;
}
List
<
UserInfoEntity
>
allUserInfo
=
userInfoRepository
.
getAllUserInfo
(
id
);
while
(
allUserInfo
.
size
()>
0
){
long
l
=
System
.
currentTimeMillis
();
CountDownLatch
countDown
=
new
CountDownLatch
(
allUserInfo
.
size
());
for
(
UserInfoEntity
userInfoEntity
:
allUserInfo
)
{
executorService
.
execute
(()
->
{
try
{
String
avatarUrl
=
userInfoEntity
.
getPhoto
();
if
(
StringUtils
.
isEmpty
(
avatarUrl
)){
return
;
}
if
(
StringUtils
.
isEmpty
(
extractPhoneNumberFromUrl
(
avatarUrl
))){
return
;
}
byte
[]
avatarBytes
=
HttpClientUtil
.
download
(
avatarUrl
);
String
fileName
=
qiNiuYunUtil
.
upload
(
avatarBytes
,
".jpg"
);
userInfoEntity
.
setPhoto
(
fileName
);
userInfoRepository
.
save
(
userInfoEntity
);
}
catch
(
Exception
e
)
{
log
.
error
(
"refeshAvatar.error"
,
e
);
}
finally
{
countDown
.
countDown
();
}
});
}
try
{
countDown
.
await
();
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"refeshAvatar.error"
,
e
);
}
UserInfoEntity
userInfoEntity
=
allUserInfo
.
get
(
allUserInfo
.
size
()
-
1
);
log
.
info
(
"refeshAvatar.执行完的最大的id是:{},执行时间是:{}"
,
userInfoEntity
.
getId
(),
System
.
currentTimeMillis
()-
l
);
allUserInfo
=
new
ArrayList
<>();
// allUserInfo = userInfoRepository.getAllUserInfo(id);
}
return
JsonResult
.
buildSuccessResult
(
"刷新成功"
,
null
);
}
public
static
String
extractPhoneNumberFromUrl
(
String
url
)
{
// 使用正则表达式匹配手机号
java
.
util
.
regex
.
Matcher
matcher
=
pattern
.
matcher
(
url
);
if
(
matcher
.
find
())
{
return
matcher
.
group
(
1
);
}
return
null
;
}
}
src/main/java/cn/quantgroup/xyqb/repository/IUserInfoRepository.java
View file @
392cde98
...
...
@@ -20,6 +20,9 @@ public interface IUserInfoRepository extends JpaRepository<UserInfoEntity, Long>
List
<
UserInfoEntity
>
findByTenantIdAndPhoneNoIn
(
Integer
tenantId
,
List
<
String
>
phoneNos
);
List
<
UserInfoEntity
>
findByTenantIdAndUserIdIn
(
Integer
tenantId
,
List
<
Long
>
userIds
);
@Query
(
nativeQuery
=
true
,
value
=
"select * from user_info where photo REGEXP '[0-9]{11}' and id >?1 limit 500"
)
List
<
UserInfoEntity
>
getAllUserInfo
(
Long
id
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_info set email = ?1 where user_id = ?2 and tenant_id = ?3"
,
nativeQuery
=
true
)
...
...
src/main/java/cn/quantgroup/xyqb/util/HttpClientUtil.java
0 → 100644
View file @
392cde98
This diff is collapsed.
Click to expand it.
src/main/java/cn/quantgroup/xyqb/util/QiNiuYunUtil.java
0 → 100644
View file @
392cde98
package
cn
.
quantgroup
.
xyqb
.
util
;
import
cn.quantgroup.kms.qiniu.QiniuAuth
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.gson.Gson
;
import
com.qiniu.common.QiniuException
;
import
com.qiniu.http.Response
;
import
com.qiniu.storage.Region
;
import
com.qiniu.storage.UploadManager
;
import
com.qiniu.storage.model.DefaultPutRet
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
/**
* 七牛云上传工具类
*
* @author axq
*/
@Component
@Slf4j
public
class
QiNiuYunUtil
{
@Autowired
private
QiniuAuth
qiniuAuth
;
@Autowired
private
UploadManager
uploadManager
;
// @Autowired
// private QiniuyunProperties qiniuyunProperties;
private
static
final
String
bucket
=
"kdsp"
;
private
static
final
String
linkPrefix
=
"https://kdspstatic.q-gp.com/"
;
@Bean
public
UploadManager
uploadManager
()
{
//构造一个带指定 Region 对象的配置类
com
.
qiniu
.
storage
.
Configuration
cfg
=
new
com
.
qiniu
.
storage
.
Configuration
(
Region
.
huanan
());
//...其他参数参考类注释
return
new
UploadManager
(
cfg
);
}
/**
* 上传数据流
*
* @param uploadBytes 数据字节数组
* @return
*/
public
String
upload
(
byte
[]
uploadBytes
,
String
contentType
)
throws
Exception
{
//解析上传成功的结果
ByteArrayInputStream
byteInputStream
=
null
;
try
{
byteInputStream
=
new
ByteArrayInputStream
(
uploadBytes
);
String
upToken
=
qiniuAuth
.
getAuth
().
uploadToken
(
bucket
);
Response
response
=
uploadManager
.
put
(
byteInputStream
,
null
,
upToken
,
null
,
contentType
);
//解析上传成功的结果
DefaultPutRet
putRet
=
new
Gson
().
fromJson
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
return
linkPrefix
+
putRet
.
hash
;
}
catch
(
Exception
e
)
{
log
.
error
(
"七牛云上传文件异常"
,
e
);
throw
new
Exception
(
"上传数据流异常"
);
}
finally
{
if
(
byteInputStream
!=
null
)
{
try
{
byteInputStream
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"七牛云上传文件关闭流出现异常"
,
e
);
}
}
}
}
public
String
overrideUpload
(
byte
[]
uploadBytes
,
String
contentType
,
String
fileName
)
throws
Exception
{
//解析上传成功的结果
ByteArrayInputStream
byteInputStream
=
null
;
try
{
byteInputStream
=
new
ByteArrayInputStream
(
uploadBytes
);
String
upToken
=
qiniuAuth
.
getAuth
().
uploadToken
(
bucket
,
fileName
);
Response
response
=
uploadManager
.
put
(
byteInputStream
,
fileName
,
upToken
,
null
,
contentType
);
//解析上传成功的结果
DefaultPutRet
putRet
=
new
Gson
().
fromJson
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
return
linkPrefix
+
putRet
.
hash
;
}
catch
(
Exception
e
)
{
log
.
error
(
"七牛云上传文件异常,fileName:{}"
,
fileName
,
e
);
throw
new
Exception
(
"上传数据流异常"
);
}
finally
{
if
(
byteInputStream
!=
null
)
{
try
{
byteInputStream
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"overrideUpload七牛云上传文件关闭流出现异常"
,
e
);
}
}
}
}
public
String
overrideUploadFileName
(
byte
[]
uploadBytes
,
String
contentType
,
String
fileName
)
throws
Exception
{
//解析上传成功的结果
ByteArrayInputStream
byteInputStream
=
null
;
try
{
byteInputStream
=
new
ByteArrayInputStream
(
uploadBytes
);
log
.
info
(
"七牛云上传获取token,bucket:{},fileName:{}"
,
bucket
,
fileName
);
String
upToken
=
qiniuAuth
.
getAuth
().
uploadToken
(
bucket
,
fileName
);
log
.
info
(
"七牛云上传参数,fileName:{},upToken:{},contentType:{}"
,
fileName
,
upToken
,
contentType
);
Response
response
=
uploadManager
.
put
(
byteInputStream
,
fileName
,
upToken
,
null
,
contentType
);
//解析上传成功的结果
DefaultPutRet
putRet
=
new
Gson
().
fromJson
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
log
.
info
(
"七牛云上传结果,response:{},putRet:{}"
,
JSONObject
.
toJSONString
(
response
),
JSONObject
.
toJSONString
(
putRet
));
return
linkPrefix
+
putRet
.
key
;
}
catch
(
Exception
e
)
{
log
.
error
(
"七牛云上传文件异常,fileName:{}"
,
fileName
,
e
);
throw
new
Exception
(
"上传数据流异常"
);
}
finally
{
if
(
byteInputStream
!=
null
)
{
try
{
byteInputStream
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"overrideUploadFileName七牛云上传文件关闭流出现异常"
,
e
);
}
}
}
}
/**
* 上传本地文件
*
* @param localFilePath 本地文件路径
* @param fileName 上传保存文件名
* @return 文件外链
*/
public
String
upload
(
String
localFilePath
,
String
fileName
)
{
try
{
String
upToken
=
qiniuAuth
.
getAuth
().
uploadToken
(
bucket
);
Response
response
=
uploadManager
.
put
(
localFilePath
,
fileName
,
upToken
);
if
(
response
.
isOK
())
{
return
linkPrefix
+
fileName
;
}
}
catch
(
QiniuException
e
)
{
log
.
error
(
"七牛云上传本地文件:{} | 发生异常"
,
localFilePath
,
e
);
}
return
null
;
}
}
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