Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
appletBusinessAnalysis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a1922eaa
authored
Dec 04, 2025
by
张富康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
sql异常处理
1 parent
e990e23c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
50 deletions
src/main/java/com/glsk/compute/fullupdatedata/QuerySql.java
src/main/java/com/glsk/exception/GlobalExceptionHandler.java
src/main/java/com/glsk/service/TalentAnalysisService.java
src/main/java/com/glsk/compute/fullupdatedata/QuerySql.java
View file @
a1922ea
...
...
@@ -2,6 +2,7 @@ package com.glsk.compute.fullupdatedata;
import
com.glsk.util.DateUtils
;
import
com.glsk.util.MysqlUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
...
...
@@ -13,6 +14,7 @@ import java.util.stream.Collectors;
* @author fangfang
* @create 2024-04-26 16:16
*/
@Slf4j
public
class
QuerySql
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// queryMerchantSupervision01(connInsert );
...
...
@@ -1053,6 +1055,7 @@ public class QuerySql {
public
static
String
getTalentAnalysisBasicData01
(
String
wherebusinesstypexxxxxx
,
String
whereentry_datexxxxxx
,
String
wheremobliePhonexxxxxx
,
Connection
connInsert
)
{
log
.
info
(
"wherebusinesstypexxxxxx={},whereentry_datexxxxxx={},wheremobliePhonexxxxxx={}"
,
wherebusinesstypexxxxxx
,
whereentry_datexxxxxx
,
wheremobliePhonexxxxxx
);
String
sql01
=
""
;
try
{
String
sql
=
"select querysql from business_analysis_query_sql where deleted_flag='N'\n"
+
...
...
@@ -1068,8 +1071,8 @@ public class QuerySql {
}
sql01
=
sql01
.
replace
(
"businesstypexxxxxx"
,
wherebusinesstypexxxxxx
)
.
replace
(
"entry_datexxxxxx"
,
whereentry_datexxxxxx
)
.
replace
(
"mob
li
ePhonexxxxxx"
,
wheremobliePhonexxxxxx
);
.
replace
(
"mob
il
ePhonexxxxxx"
,
wheremobliePhonexxxxxx
);
log
.
info
(
"sql01={}"
,
sql01
);
return
sql01
;
}
...
...
src/main/java/com/glsk/exception/GlobalExceptionHandler.java
View file @
a1922ea
...
...
@@ -3,8 +3,6 @@ package com.glsk.exception;
import
com.glsk.vo.RopResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.BindException
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
...
...
@@ -14,7 +12,6 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
...
...
@@ -38,21 +35,23 @@ public class GlobalExceptionHandler {
* 处理业务异常
*/
@ExceptionHandler
(
BusinessException
.
class
)
public
R
esponseEntity
<
RopResponse
<?>
>
handleBusinessException
(
BusinessException
e
)
{
public
R
opResponse
<?
>
handleBusinessException
(
BusinessException
e
)
{
log
.
error
(
"业务异常: code={}, message={}"
,
e
.
getCode
(),
e
.
getMessage
(),
e
);
RopResponse
<?>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
e
.
getCode
().
toString
());
restResult
.
setMessage
(
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
)
.
body
(
restResult
);
RopResponse
<
RopResponse
<?>>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"0"
);
restResult
.
setMessage
(
"调用服务成功!"
);
RopResponse
<?>
exceptionMessage
=
new
RopResponse
<>();
exceptionMessage
.
setCode
(
e
.
getCode
().
toString
());
exceptionMessage
.
setMessage
(
e
.
getMessage
());
restResult
.
setData
(
exceptionMessage
);
return
restResult
;
}
/**
* 参数校验异常统一处理
*/
@ExceptionHandler
({
MethodArgumentNotValidException
.
class
,
BindException
.
class
})
public
R
esponseEntity
<
RopResponse
<?>
>
handleValidationException
(
Exception
e
)
{
public
R
opResponse
<?
>
handleValidationException
(
Exception
e
)
{
BindingResult
bindingResult
=
null
;
if
(
e
instanceof
MethodArgumentNotValidException
)
{
bindingResult
=
((
MethodArgumentNotValidException
)
e
).
getBindingResult
();
...
...
@@ -67,41 +66,47 @@ public class GlobalExceptionHandler {
.
orElse
(
"参数校验失败"
);
log
.
error
(
"参数校验异常: {}"
,
message
,
e
);
RopResponse
<?>
restResult
=
new
RopResponse
<>();
restResult
.
setMessage
(
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
)
.
body
(
restResult
);
RopResponse
<
RopResponse
<?>>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"0"
);
restResult
.
setMessage
(
"调用服务成功!"
);
RopResponse
<?>
exceptionMessage
=
new
RopResponse
<>();
exceptionMessage
.
setMessage
(
e
.
getMessage
());
restResult
.
setData
(
exceptionMessage
);
return
restResult
;
}
/**
* 处理请求方法不支持异常
*/
@ExceptionHandler
(
HttpRequestMethodNotSupportedException
.
class
)
public
R
esponseEntity
<
RopResponse
<?>
>
handleHttpRequestMethodNotSupportedException
(
public
R
opResponse
<?
>
handleHttpRequestMethodNotSupportedException
(
HttpRequestMethodNotSupportedException
e
)
{
log
.
error
(
"请求方法不支持: {}"
,
e
.
getMessage
(),
e
);
RopResponse
<?>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"405"
);
restResult
.
setMessage
(
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
METHOD_NOT_ALLOWED
)
.
body
(
restResult
);
RopResponse
<
RopResponse
<?>>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"0"
);
restResult
.
setMessage
(
"调用服务成功!"
);
RopResponse
<?>
exceptionMessage
=
new
RopResponse
<>();
exceptionMessage
.
setCode
(
"405"
);
exceptionMessage
.
setMessage
(
"请求方法不支持"
);
restResult
.
setData
(
exceptionMessage
);
return
restResult
;
}
/**
* 处理媒体类型不支持异常
*/
@ExceptionHandler
(
HttpMediaTypeNotSupportedException
.
class
)
public
R
esponseEntity
<
RopResponse
<?>
>
handleHttpMediaTypeNotSupportedException
(
public
R
opResponse
<?
>
handleHttpMediaTypeNotSupportedException
(
HttpMediaTypeNotSupportedException
e
)
{
log
.
error
(
"媒体类型不支持: {}"
,
e
.
getMessage
(),
e
);
RopResponse
<?>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"415"
);
restResult
.
setMessage
(
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
UNSUPPORTED_MEDIA_TYPE
)
.
body
(
restResult
);
RopResponse
<
RopResponse
<?>>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"0"
);
restResult
.
setMessage
(
"调用服务成功!"
);
RopResponse
<?>
exceptionMessage
=
new
RopResponse
<>();
exceptionMessage
.
setCode
(
"415"
);
exceptionMessage
.
setMessage
(
"媒体类型不支持"
);
restResult
.
setData
(
exceptionMessage
);
return
restResult
;
}
...
...
@@ -109,11 +114,15 @@ public class GlobalExceptionHandler {
* 处理其他所有异常
*/
@ExceptionHandler
(
Exception
.
class
)
public
R
esponseEntity
<
RopResponse
<?>>
handleException
(
Exception
e
,
HttpServletRequest
request
)
{
public
R
opResponse
<?>
handleException
(
Exception
e
)
{
log
.
error
(
"系统异常: {}"
,
e
.
getMessage
(),
e
);
RopResponse
<?>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
ErrorCodeEnum
.
SYSTEM_ERROR
.
getCode
().
toString
());
restResult
.
setMessage
(
ErrorCodeEnum
.
SYSTEM_ERROR
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
restResult
);
RopResponse
<
RopResponse
<?>>
restResult
=
new
RopResponse
<>();
restResult
.
setCode
(
"0"
);
restResult
.
setMessage
(
"调用服务成功!"
);
RopResponse
<?>
exceptionMessage
=
new
RopResponse
<>();
exceptionMessage
.
setCode
(
ErrorCodeEnum
.
SYSTEM_ERROR
.
getCode
().
toString
());
exceptionMessage
.
setMessage
(
ErrorCodeEnum
.
SYSTEM_ERROR
.
getMessage
());
restResult
.
setData
(
exceptionMessage
);
return
restResult
;
}
}
\ No newline at end of file
src/main/java/com/glsk/service/TalentAnalysisService.java
View file @
a1922ea
...
...
@@ -102,7 +102,7 @@ public class TalentAnalysisService {
String
whereentry_datexxxxxx
=
""
;
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -402,7 +402,7 @@ public class TalentAnalysisService {
String
wherezz_statusxxxxxx
=
""
;
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -695,7 +695,7 @@ public class TalentAnalysisService {
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -854,7 +854,7 @@ public class TalentAnalysisService {
String
entry_datexxxxxx
=
""
;
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -972,7 +972,7 @@ public class TalentAnalysisService {
String
entry_datexxxxxx
=
""
;
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -1136,7 +1136,7 @@ public class TalentAnalysisService {
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -1265,7 +1265,7 @@ public class TalentAnalysisService {
String
entry_datexxxxxx
=
""
;
// 按省份查询
String
wheremobliePhonexxxxxx
=
""
;
if
(
ObjectUtil
.
isEmpty
(
req
.
getProvinceId
()))
{
if
(
ObjectUtil
.
is
Not
Empty
(
req
.
getProvinceId
()))
{
String
staffPhoneStr
=
StrUtil
.
join
(
","
,
staffPhoneList
.
stream
()
.
map
(
key
->
"'"
+
key
+
"'"
)
// 为每个键添加单引号
.
collect
(
Collectors
.
toList
()));
...
...
@@ -1418,6 +1418,8 @@ public class TalentAnalysisService {
" AND o.seller_user_id IS NOT NULL"
;
provinceStaffSt
=
connInsert
.
prepareStatement
(
provinceSql
);
provinceStaffSt
.
setInt
(
1
,
provinceId
);
// 打印sql日志
log
.
info
(
"provinceSql:{}"
,
provinceSql
);
provinceStaffRs
=
provinceStaffSt
.
executeQuery
();
List
<
String
>
sellerUserIds
=
new
ArrayList
<>();
while
(
provinceStaffRs
.
next
())
{
...
...
@@ -1437,6 +1439,8 @@ public class TalentAnalysisService {
" and del_flag = 0 group by staff_uuid, staff_phone"
;
staffPhoneSt
=
connQuery02
.
prepareStatement
(
staffPhoneSql
);
staffPhoneSt
.
setString
(
1
,
sellerUserIdsStr
);
// 打印sql日志
log
.
info
(
"staffPhoneSql:{}"
,
staffPhoneSql
);
staffPhoneRs
=
staffPhoneSt
.
executeQuery
();
while
(
staffPhoneRs
.
next
())
{
// 保存员工手机号进入list
...
...
@@ -1457,7 +1461,8 @@ public class TalentAnalysisService {
"where user_uuid = ?\n"
+
" and role_type = 1\n"
+
" and deleted_flag = 'N';"
;
canSeeProvinceSt
=
connInsert
.
prepareStatement
(
canSeeProvinceSql01
);
// 打印sql日志
log
.
info
(
"canSeeProvinceSql01:{}"
,
canSeeProvinceSql01
);
canSeeProvinceSt
.
setString
(
1
,
staffId
);
canSeeProvinceRs
=
canSeeProvinceSt
.
executeQuery
();
while
(
canSeeProvinceRs
.
next
())
{
...
...
@@ -1471,7 +1476,8 @@ public class TalentAnalysisService {
" on ur.region_id = pr.region_id and pr.deleted_flag = 'N'\n"
+
"where ur.user_id = ?\n"
+
" and ur.deleted_flag = 'N'"
;
canSeeProvinceSt
=
connInsert
.
prepareStatement
(
canSeeProvinceSql02
);
// 打印sql日志
log
.
info
(
"canSeeProvinceSql02:{}"
,
canSeeProvinceSql02
);
canSeeProvinceSt
.
setString
(
1
,
staffId
);
canSeeProvinceRs
=
canSeeProvinceSt
.
executeQuery
();
while
(
canSeeProvinceRs
.
next
())
{
...
...
@@ -1518,7 +1524,8 @@ public class TalentAnalysisService {
"WHERE o.seller_user_id IS NOT NULL"
;
}
provinceStaffSt
=
connInsert
.
prepareStatement
(
provinceSql
);
// 打印sql日志
log
.
info
(
"provinceStaffSql:{}"
,
provinceSql
);
provinceStaffSt
.
setInt
(
1
,
provinceId
);
provinceStaffRs
=
provinceStaffSt
.
executeQuery
();
List
<
String
>
sellerUserIds
=
new
ArrayList
<>();
...
...
@@ -1537,7 +1544,8 @@ public class TalentAnalysisService {
"from scrm_account.platform_merchant_staff\n"
+
"where staff_uuid in (?)\n"
+
" and del_flag = 0 group by staff_uuid, staff_phone"
;
staffPhoneSt
=
connQuery02
.
prepareStatement
(
staffPhoneSql
);
// 打印sql日志
log
.
info
(
"staffPhoneSql:{}"
,
staffPhoneSql
);
staffPhoneSt
.
setString
(
1
,
sellerUserIdsStr
);
staffPhoneRs
=
staffPhoneSt
.
executeQuery
();
while
(
staffPhoneRs
.
next
())
{
...
...
@@ -1563,6 +1571,8 @@ public class TalentAnalysisService {
" AND deleted_flag = 'N' "
+
"GROUP BY sub_merchant_id"
;
// 创建预编译语句(不拼接任何用户输入)
// 打印sql日志
log
.
info
(
"yqMerchantIdSql:{}"
,
yqMerchantIdSql
);
yqMerchantIdSt
=
connInsert
.
prepareStatement
(
yqMerchantIdSql
);
// 安全设置参数(staffId会自动转义)
// 判断 (1:精品升级业务负责人,2:精品升级业务服务商负责人,3:会员权益业务负责人,4:会员权益业务服务商负责人,5:1.1线上运营(原盯防负责人),
...
...
@@ -1594,6 +1604,8 @@ public class TalentAnalysisService {
"from scrm_account.platform_merchant_staff\n"
+
"where merchant_id in (?)\n"
+
" and del_flag = 0 group by staff_uuid, staff_phone"
;
// 打印sql日志
log
.
info
(
"staffPhoneSql:{}"
,
staffPhoneSql
);
staffPhoneSt
=
connQuery02
.
prepareStatement
(
staffPhoneSql
);
staffPhoneSt
.
setString
(
1
,
merchantIdsStr
);
staffPhoneRs
=
staffPhoneSt
.
executeQuery
();
...
...
@@ -1627,6 +1639,8 @@ public class TalentAnalysisService {
.
collect
(
Collectors
.
toList
()));
provinceStaffSt
.
setString
(
1
,
sellerUserIdsStr
);
provinceStaffSt
.
setInt
(
2
,
provinceId
);
// 打印sql日志
log
.
info
(
"provinceSql:{}"
,
provinceSql
);
provinceStaffRs
=
provinceStaffSt
.
executeQuery
();
List
<
String
>
sellerUserIds
=
new
ArrayList
<>();
while
(
provinceStaffRs
.
next
())
{
...
...
@@ -1654,8 +1668,6 @@ public class TalentAnalysisService {
closeQuietly
(
provinceStaffSt
);
closeQuietly
(
staffPhoneSt
);
closeQuietly
(
yqMerchantIdSt
);
closeQuietly
(
connQuery02
);
closeQuietly
(
connInsert
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment