Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
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
haoban3.0
haoban-manage3.0
Commits
8a69d1a2
Commit
8a69d1a2
authored
Sep 28, 2022
by
徐高华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
企微pendingid
parent
35b05022
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
584 additions
and
29 deletions
+584
-29
QwPendingIdDTO.java
...in/java/com/gic/haoban/manage/api/dto/QwPendingIdDTO.java
+23
-0
BindApiService.java
...ava/com/gic/haoban/manage/api/service/BindApiService.java
+0
-12
MaidianLogApiService.java
...m/gic/haoban/manage/api/service/MaidianLogApiService.java
+0
-1
QwFriendApiService.java
...com/gic/haoban/manage/api/service/QwFriendApiService.java
+56
-0
WxEnterpriseRelatedMapper.java
.../manage/service/dao/mapper/WxEnterpriseRelatedMapper.java
+0
-2
HaoBanErrCode.java
...om/gic/haoban/manage/service/errorcode/HaoBanErrCode.java
+2
-2
QwLimitTimesBO.java
...com/gic/haoban/manage/service/pojo/bo/QwLimitTimesBO.java
+33
-0
WxEnterpriseRelationBO.java
...haoban/manage/service/pojo/bo/WxEnterpriseRelationBO.java
+45
-0
WxEnterpriseRelatedService.java
...an/manage/service/service/WxEnterpriseRelatedService.java
+5
-2
WxEnterpriseRelatedServiceImpl.java
.../service/service/impl/WxEnterpriseRelatedServiceImpl.java
+11
-1
BindApiServiceImpl.java
...n/manage/service/service/out/impl/BindApiServiceImpl.java
+0
-0
QwFriendApiServiceImpl.java
...nage/service/service/out/impl/QwFriendApiServiceImpl.java
+155
-0
QwInterfaceLimitEnum.java
.../gic/haoban/manage/service/util/QwInterfaceLimitEnum.java
+40
-0
QwTimesUtils.java
...java/com/gic/haoban/manage/service/util/QwTimesUtils.java
+212
-0
dubbo-haoban-manage-service.xml
...ervice/src/main/resources/dubbo-haoban-manage-service.xml
+2
-3
WxEnterpriseRelatedMapper.xml
...e/src/main/resources/mapper/WxEnterpriseRelatedMapper.xml
+0
-5
dubbo-haoban-manage-wx.xml
...ge3-wx/src/main/webapp/WEB-INF/dubbo-haoban-manage-wx.xml
+0
-1
No files found.
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/dto/QwPendingIdDTO.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
api
.
dto
;
import
java.io.Serializable
;
public
class
QwPendingIdDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
7791318666042954957L
;
private
String
externalUserId
;
private
String
pendingId
;
public
String
getExternalUserId
()
{
return
externalUserId
;
}
public
String
getPendingId
()
{
return
pendingId
;
}
public
void
setExternalUserId
(
String
externalUserId
)
{
this
.
externalUserId
=
externalUserId
;
}
public
void
setPendingId
(
String
pendingId
)
{
this
.
pendingId
=
pendingId
;
}
}
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/BindApiService.java
deleted
100644 → 0
View file @
35b05022
package
com
.
gic
.
haoban
.
manage
.
api
.
service
;
public
interface
BindApiService
{
void
clerkManagerTranfer
(
String
departmentId
,
String
fromClerkCode
,
String
toStaffDepartmentRelatedId
);
void
clerkUnbind
(
String
departmentId
,
String
fromClerkCode
,
String
toStaffId
,
String
manager
);
void
clerkSingleUnbind
(
String
fromClerkCode
,
String
departmentId
);
void
staffBind
(
String
departmentId
,
String
fromClerkCode
,
String
fromStaffDepartmentRelatedId
);
}
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/MaidianLogApiService.java
View file @
8a69d1a2
...
...
@@ -4,7 +4,6 @@ import com.gic.api.base.commons.Page;
import
com.gic.haoban.base.api.common.BasePageInfo
;
import
com.gic.haoban.manage.api.dto.MaidianLogDTO
;
import
java.util.List
;
public
interface
MaidianLogApiService
{
...
...
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/QwFriendApiService.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
api
.
service
;
import
java.util.List
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.haoban.manage.api.dto.QwPendingIdDTO
;
/**
*
* @ClassName: QwFriendApiService
* @Description: 企微好友
* @author xugh
* @date 2022年9月27日 上午10:09:14
*
*/
public
interface
QwFriendApiService
{
/**
*
* @Title: getPendingIdByUnionid
* @Description: 通过uniond获取好友id/pendingid
* @author xugh
* @param enterpriseId
* @param unionid
* @param openid 小程序或者服务号openid
* @return
* @throws
*/
public
ServiceResponse
<
QwPendingIdDTO
>
getPendingIdByUnionid
(
String
enterpriseId
,
String
unionid
,
String
openid
);
/**
*
* @Title: getPendingIdByExternalid
* @Description: 通过好友id查询pendingid
* @author xugh
* @param enterpriseId
* @param externalUserId
* @return
* @throws
*/
public
ServiceResponse
<
QwPendingIdDTO
>
getPendingIdByExternalid
(
String
enterpriseId
,
String
externalUserId
);
/**
*
* @Title: getPendingIdByExternalid
* @Description: 通过好友id查询pendingid
* @author xugh
* @param enterpriseId
* @param externalUserId
* @return
* @throws
*/
public
ServiceResponse
<
List
<
QwPendingIdDTO
>>
listPendingIdByExternalid
(
String
enterpriseId
,
List
<
String
>
externalUserIdList
);
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/dao/mapper/WxEnterpriseRelatedMapper.java
View file @
8a69d1a2
...
...
@@ -8,8 +8,6 @@ import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated;
public
interface
WxEnterpriseRelatedMapper
{
int
deleteByPrimaryKey
(
String
wxEnterpriseRelatedId
);
int
deleteByEnterpriseId
(
String
enterpriseId
)
;
int
insertSelective
(
TabHaobanWxEnterpriseRelated
record
);
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/errorcode/HaoBanErrCode.java
View file @
8a69d1a2
...
...
@@ -8,8 +8,8 @@ public enum HaoBanErrCode {
ERR_0001
(
"10100001"
,
"参数没有传"
),
ERR_10012
(
"10012"
,
"企业微信不存在"
),
ERR_OTHER
(
"9999"
,
"业务异常"
),
ERR_
100033
(
"100033"
,
"活码分组已经被关联,不可删除
"
)
ERR_100033
(
"100033"
,
"活码分组已经被关联,不可删除"
),
ERR_
2000
(
"2000"
,
"企微接口调用次数限制
"
)
;
private
String
code
;
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/pojo/bo/QwLimitTimesBO.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
pojo
.
bo
;
public
class
QwLimitTimesBO
{
private
int
month
;
private
int
day
;
private
int
hour
;
public
int
getMonth
()
{
return
month
;
}
public
int
getDay
()
{
return
day
;
}
public
int
getHour
()
{
return
hour
;
}
public
void
setMonth
(
int
month
)
{
this
.
month
=
month
;
}
public
void
setDay
(
int
day
)
{
this
.
day
=
day
;
}
public
void
setHour
(
int
hour
)
{
this
.
hour
=
hour
;
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/pojo/bo/WxEnterpriseRelationBO.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
pojo
.
bo
;
import
java.io.Serializable
;
public
class
WxEnterpriseRelationBO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
4140789670421435421L
;
private
String
wxEnterpriseRelatedId
;
private
String
wxEnterpriseId
;
private
String
enterpriseId
;
private
int
wxEnterpriseType
;
private
int
memberOpenCardFlag
;
public
String
getWxEnterpriseRelatedId
()
{
return
wxEnterpriseRelatedId
;
}
public
String
getWxEnterpriseId
()
{
return
wxEnterpriseId
;
}
public
int
getWxEnterpriseType
()
{
return
wxEnterpriseType
;
}
public
int
getMemberOpenCardFlag
()
{
return
memberOpenCardFlag
;
}
public
void
setWxEnterpriseRelatedId
(
String
wxEnterpriseRelatedId
)
{
this
.
wxEnterpriseRelatedId
=
wxEnterpriseRelatedId
;
}
public
void
setWxEnterpriseId
(
String
wxEnterpriseId
)
{
this
.
wxEnterpriseId
=
wxEnterpriseId
;
}
public
void
setWxEnterpriseType
(
int
wxEnterpriseType
)
{
this
.
wxEnterpriseType
=
wxEnterpriseType
;
}
public
void
setMemberOpenCardFlag
(
int
memberOpenCardFlag
)
{
this
.
memberOpenCardFlag
=
memberOpenCardFlag
;
}
public
String
getEnterpriseId
()
{
return
enterpriseId
;
}
public
void
setEnterpriseId
(
String
enterpriseId
)
{
this
.
enterpriseId
=
enterpriseId
;
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/WxEnterpriseRelatedService.java
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
service
;
import
java.util.List
;
import
com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise
;
import
com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated
;
import
java.util.List
;
import
com.gic.haoban.manage.service.pojo.bo.WxEnterpriseRelationBO
;
public
interface
WxEnterpriseRelatedService
{
...
...
@@ -37,4 +38,6 @@ public interface WxEnterpriseRelatedService {
void
setClerkEdit
(
String
id
,
int
clerkEditFlag
);
int
getRelationCount
(
String
enterpriseId
)
;
public
WxEnterpriseRelationBO
getHeadEnterprise
(
String
enterpriseId
)
;
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/impl/WxEnterpriseRelatedServiceImpl.java
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
impl
;
import
com.gic.commons.util.EntityUtil
;
import
com.gic.haoban.manage.service.dao.mapper.WxEnterpriseMapper
;
import
com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise
;
import
com.gic.haoban.manage.service.service.WxEnterpriseService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import
com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper
;
import
com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated
;
import
com.gic.haoban.manage.service.pojo.bo.WxEnterpriseRelationBO
;
import
com.gic.haoban.manage.service.service.WxEnterpriseRelatedService
;
import
java.util.ArrayList
;
...
...
@@ -75,4 +76,13 @@ public class WxEnterpriseRelatedServiceImpl implements WxEnterpriseRelatedServic
List
<
TabHaobanWxEnterpriseRelated
>
list
=
this
.
mapper
.
listByEnterpriseId
(
enterpriseId
)
;
return
list
.
size
();
}
@Override
public
WxEnterpriseRelationBO
getHeadEnterprise
(
String
enterpriseId
)
{
TabHaobanWxEnterpriseRelated
root
=
this
.
mapper
.
findRootWxEnterpriseByEnterpriseId
(
enterpriseId
)
;
if
(
null
!=
root
)
{
return
EntityUtil
.
changeEntityByJSON
(
WxEnterpriseRelationBO
.
class
,
root
);
}
return
null
;
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/BindApiServiceImpl.java
deleted
100644 → 0
View file @
35b05022
This diff is collapsed.
Click to expand it.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/QwFriendApiServiceImpl.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
out
.
impl
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.enterprise.api.constant.EnterpriseServiceEnum
;
import
com.gic.enterprise.api.service.EnterpriseUseForbidService
;
import
com.gic.haoban.manage.api.dto.QwPendingIdDTO
;
import
com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO
;
import
com.gic.haoban.manage.api.service.QwFriendApiService
;
import
com.gic.haoban.manage.service.config.Config
;
import
com.gic.haoban.manage.service.errorcode.HaoBanErrCode
;
import
com.gic.haoban.manage.service.pojo.bo.WxEnterpriseRelationBO
;
import
com.gic.haoban.manage.service.service.WxEnterpriseRelatedService
;
import
com.gic.haoban.manage.service.service.WxEnterpriseService
;
import
com.gic.haoban.manage.service.util.QwInterfaceLimitEnum
;
import
com.gic.haoban.manage.service.util.QwTimesUtils
;
import
com.gic.wechat.api.dto.qywx.PendingIdDTO
;
import
com.gic.wechat.api.service.qywx.QywxExternalUserService
;
@Service
(
"qwFriendApiService"
)
public
class
QwFriendApiServiceImpl
implements
QwFriendApiService
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
QwFriendApiService
.
class
);
@Autowired
private
EnterpriseUseForbidService
enterpriseUseForbidService
;
@Autowired
private
QywxExternalUserService
qywxExternalUserService
;
@Autowired
private
WxEnterpriseRelatedService
wxEnterpriseRelatedService
;
@Autowired
private
WxEnterpriseService
wxEnterpriseService
;
@Autowired
private
Config
config
;
@Override
public
ServiceResponse
<
QwPendingIdDTO
>
getPendingIdByUnionid
(
String
enterpriseId
,
String
unionid
,
String
openid
)
{
String
suiteid
=
config
.
getWxSuiteid
();
ServiceResponse
<
WxEnterpriseQwDTO
>
corpidResp
=
this
.
checkAndGetCorpid
(
enterpriseId
);
if
(!
corpidResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
corpidResp
.
getCode
(),
corpidResp
.
getMessage
());
}
WxEnterpriseQwDTO
qwDTO
=
corpidResp
.
getResult
();
String
wxEnterpriseId
=
qwDTO
.
getWxEnterpriseId
();
boolean
isLimit
=
QwTimesUtils
.
isLimit
(
wxEnterpriseId
,
enterpriseId
,
QwInterfaceLimitEnum
.
GET_PENDING_ID
);
if
(
isLimit
)
{
return
ServiceResponse
.
failure
(
HaoBanErrCode
.
ERR_2000
.
getCode
(),
HaoBanErrCode
.
ERR_2000
.
getMsg
());
}
String
corpid
=
qwDTO
.
getThirdCorpid
();
ServiceResponse
<
PendingIdDTO
>
qwResp
=
this
.
qywxExternalUserService
.
unionidToExternalUserid
(
corpid
,
suiteid
,
unionid
,
openid
,
1
);
QwTimesUtils
.
addTimes
(
wxEnterpriseId
,
QwInterfaceLimitEnum
.
GET_PENDING_ID
);
log
.
info
(
"获取pendingid,参数={},返回={}"
,
unionid
,
JSON
.
toJSONString
(
qwResp
));
if
(!
qwResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
qwResp
.
getCode
(),
qwResp
.
getMessage
());
}
QwPendingIdDTO
dto
=
new
QwPendingIdDTO
();
dto
.
setExternalUserId
(
qwResp
.
getResult
().
getExternal_userid
());
dto
.
setPendingId
(
qwResp
.
getResult
().
getPending_id
());
return
ServiceResponse
.
success
(
dto
);
}
@Override
public
ServiceResponse
<
QwPendingIdDTO
>
getPendingIdByExternalid
(
String
enterpriseId
,
String
externalUserId
)
{
String
suiteid
=
config
.
getWxSuiteid
();
ServiceResponse
<
WxEnterpriseQwDTO
>
corpidResp
=
this
.
checkAndGetCorpid
(
enterpriseId
);
if
(!
corpidResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
corpidResp
.
getCode
(),
corpidResp
.
getMessage
());
}
WxEnterpriseQwDTO
qwDTO
=
corpidResp
.
getResult
();
String
corpid
=
qwDTO
.
getThirdCorpid
();
ServiceResponse
<
List
<
PendingIdDTO
>>
qwResp
=
this
.
qywxExternalUserService
.
externalUseridToPendingId
(
corpid
,
suiteid
,
Arrays
.
asList
(
externalUserId
));
log
.
info
(
"获取pendingid,参数={},返回={}"
,
externalUserId
,
JSON
.
toJSONString
(
qwResp
));
if
(!
qwResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
qwResp
.
getCode
(),
qwResp
.
getMessage
());
}
List
<
PendingIdDTO
>
list
=
qwResp
.
getResult
();
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
QwPendingIdDTO
dto
=
new
QwPendingIdDTO
();
dto
.
setExternalUserId
(
list
.
get
(
0
).
getExternal_userid
());
dto
.
setPendingId
(
list
.
get
(
0
).
getPending_id
());
return
ServiceResponse
.
success
(
dto
);
}
return
ServiceResponse
.
failure
(
"9999"
,
"企微未查询到数据"
);
}
@Override
public
ServiceResponse
<
List
<
QwPendingIdDTO
>>
listPendingIdByExternalid
(
String
enterpriseId
,
List
<
String
>
externalUserIdList
)
{
if
(
CollectionUtils
.
isEmpty
(
externalUserIdList
)
||
externalUserIdList
.
size
()
>
1000
)
{
return
ServiceResponse
.
failure
(
"9999"
,
"外部联系人不能为空且每次最多1000条"
);
}
String
suiteid
=
config
.
getWxSuiteid
();
ServiceResponse
<
WxEnterpriseQwDTO
>
corpidResp
=
this
.
checkAndGetCorpid
(
enterpriseId
);
if
(!
corpidResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
corpidResp
.
getCode
(),
corpidResp
.
getMessage
());
}
WxEnterpriseQwDTO
qwDTO
=
corpidResp
.
getResult
();
String
corpid
=
qwDTO
.
getThirdCorpid
();
ServiceResponse
<
List
<
PendingIdDTO
>>
qwResp
=
this
.
qywxExternalUserService
.
externalUseridToPendingId
(
corpid
,
suiteid
,
externalUserIdList
);
log
.
info
(
"获取pendingid,参数={},返回={}"
,
externalUserIdList
,
JSON
.
toJSONString
(
qwResp
));
if
(!
qwResp
.
isSuccess
())
{
return
ServiceResponse
.
failure
(
qwResp
.
getCode
(),
qwResp
.
getMessage
());
}
List
<
PendingIdDTO
>
list
=
qwResp
.
getResult
();
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
List
<
QwPendingIdDTO
>
retList
=
new
ArrayList
<>();
for
(
PendingIdDTO
item
:
list
)
{
QwPendingIdDTO
dto
=
new
QwPendingIdDTO
();
dto
.
setExternalUserId
(
item
.
getExternal_userid
());
dto
.
setPendingId
(
item
.
getPending_id
());
retList
.
add
(
dto
);
}
return
ServiceResponse
.
success
(
retList
);
}
return
ServiceResponse
.
failure
(
"9999"
,
"企微未查询到数据"
);
}
// 判断企业是否能用企微
private
ServiceResponse
<
WxEnterpriseQwDTO
>
checkAndGetCorpid
(
String
enterpriseId
)
{
WxEnterpriseRelationBO
enterpriseRelation
=
this
.
wxEnterpriseRelatedService
.
getHeadEnterprise
(
enterpriseId
);
if
(
null
==
enterpriseRelation
)
{
// 非总部或不存在
return
ServiceResponse
.
failure
(
"9999"
,
"请确认商户是否有效且是总部"
);
}
Integer
code
=
this
.
enterpriseUseForbidService
.
selectPermissionStatus
(
enterpriseId
,
EnterpriseServiceEnum
.
HAO_BAN
.
getRightMenuCode
());
log
.
info
(
"好办是否到期停用={},{}"
,
enterpriseId
,
code
);
if
(
code
!=
0
&&
code
!=
1
)
{
return
ServiceResponse
.
failure
(
"9999"
,
"商户已停用"
);
}
int
memberOpenCardlag
=
enterpriseRelation
.
getMemberOpenCardFlag
();
if
(
memberOpenCardlag
!=
0
)
{
// 不在同一开放平台
return
ServiceResponse
.
failure
(
"9999"
,
"不在同一开放平台"
);
}
String
wxEnterpriseId
=
enterpriseRelation
.
getWxEnterpriseId
();
WxEnterpriseQwDTO
qwDTO
=
this
.
wxEnterpriseService
.
getQwInfo
(
wxEnterpriseId
);
return
ServiceResponse
.
success
(
qwDTO
);
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/QwInterfaceLimitEnum.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
public
enum
QwInterfaceLimitEnum
{
GET_PENDING_ID
(
"qw_limit_pending_id"
,
"unionid查询external_userid接口"
,
0
);
private
String
name
;
private
String
remark
;
private
int
type
;
private
QwInterfaceLimitEnum
(
String
name
,
String
remark
,
int
type
)
{
this
.
name
=
name
;
this
.
remark
=
remark
;
this
.
type
=
type
;
}
public
String
getName
()
{
return
name
;
}
public
String
getRemark
()
{
return
remark
;
}
public
int
getType
()
{
return
type
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
void
setRemark
(
String
remark
)
{
this
.
remark
=
remark
;
}
public
void
setType
(
int
type
)
{
this
.
type
=
type
;
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/QwTimesUtils.java
0 → 100644
View file @
8a69d1a2
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.redisson.api.RAtomicLong
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.commons.util.DateUtil
;
import
com.gic.enterprise.api.dto.EnterpriseDTO
;
import
com.gic.enterprise.api.service.EnterpriseService
;
import
com.gic.enterprise.service.CustomSettingApiService
;
import
com.gic.haoban.common.utils.DingUtils
;
import
com.gic.haoban.manage.service.pojo.bo.QwLimitTimesBO
;
import
com.gic.redis.data.util.RedisUtil
;
@Component
public
class
QwTimesUtils
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
QwTimesUtils
.
class
);
private
static
CustomSettingApiService
customSettingApiService
;
public
static
EnterpriseService
enterpriseService
;
@Autowired
public
void
setCustomSettingApiService
(
CustomSettingApiService
customSettingApiService
)
{
QwTimesUtils
.
customSettingApiService
=
customSettingApiService
;
}
@Autowired
public
void
setEnterpriseService
(
EnterpriseService
enterpriseService
)
{
QwTimesUtils
.
enterpriseService
=
enterpriseService
;
}
public
static
boolean
isLimit
(
String
wxEnterpriseId
,
String
enterpriseId
,
QwInterfaceLimitEnum
obj
)
{
QwLimitTimesBO
setTimeBO
=
getSettingTimes
(
wxEnterpriseId
,
obj
);
logger
.
info
(
"获取配置次数={},wxEnterpriseId={}"
,
JSON
.
toJSONString
(
setTimeBO
),
wxEnterpriseId
);
// 先判断月
String
interfaceName
=
obj
.
getName
();
Date
now
=
new
Date
();
String
dateStr
=
getDateStr
(
now
);
String
keyMonth
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
6
));
boolean
monthResult
=
timesCheck
(
1
,
keyMonth
,
obj
,
wxEnterpriseId
,
enterpriseId
,
now
,
setTimeBO
);
if
(
monthResult
)
{
logger
.
info
(
"月达到限制={}"
,
keyMonth
);
return
true
;
}
// 天
String
keyDay
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
8
));
boolean
dayResult
=
timesCheck
(
2
,
keyDay
,
obj
,
wxEnterpriseId
,
enterpriseId
,
now
,
setTimeBO
);
if
(
dayResult
)
{
logger
.
info
(
"天达到限制={}"
,
keyDay
);
return
true
;
}
// 小时
String
keyHour
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
10
));
boolean
hourResult
=
timesCheck
(
3
,
keyHour
,
obj
,
wxEnterpriseId
,
enterpriseId
,
now
,
setTimeBO
);
if
(
hourResult
)
{
logger
.
info
(
"小时达到限制={}"
,
keyHour
);
return
true
;
}
return
false
;
}
private
static
boolean
timesCheck
(
int
type
,
String
cacheKey
,
QwInterfaceLimitEnum
obj
,
String
wxEnterpriseId
,
String
enterpriseId
,
Date
now
,
QwLimitTimesBO
setTimeBO
)
{
Integer
doneTimes
=
RedisUtil
.
getCache
(
cacheKey
,
Integer
.
class
);
logger
.
info
(
"获取已调次数={},cacheKey={}"
,
doneTimes
,
cacheKey
);
if
(
null
==
doneTimes
)
{
return
false
;
}
int
setTimes
=
0
;
switch
(
type
)
{
case
1
:
setTimes
=
setTimeBO
.
getMonth
();
break
;
case
2
:
setTimes
=
setTimeBO
.
getDay
();
break
;
case
3
:
setTimes
=
setTimeBO
.
getHour
();
break
;
default
:
break
;
}
sendAlert
(
type
,
doneTimes
,
setTimes
,
obj
,
enterpriseId
,
now
);
if
(
doneTimes
>=
setTimes
)
{
return
true
;
}
return
false
;
}
private
static
QwLimitTimesBO
getSettingTimes
(
String
wxEnterpriseId
,
QwInterfaceLimitEnum
obj
)
{
String
key
=
String
.
format
(
"%s_%s"
,
obj
.
getName
(),
wxEnterpriseId
);
QwLimitTimesBO
times
=
getTimes
(
key
);
if
(
null
==
times
)
{
return
getTimes
(
obj
.
getName
());
}
return
times
;
}
private
static
QwLimitTimesBO
getTimes
(
String
key
)
{
JSONObject
searchParamMap
=
new
JSONObject
();
searchParamMap
.
put
(
"key"
,
key
);
ServiceResponse
<
Map
<
String
,
Object
>>
resp
=
customSettingApiService
.
getDetail
(
"tab_gic_map"
,
searchParamMap
.
toJSONString
());
if
(
resp
.
isSuccess
()
&&
null
!=
resp
.
getResult
())
{
QwLimitTimesBO
times
=
new
QwLimitTimesBO
();
times
=
JSON
.
parseObject
(
resp
.
getResult
().
get
(
"value"
).
toString
(),
QwLimitTimesBO
.
class
);
logger
.
info
(
"获取默认配置次数={},{}"
,
times
,
key
);
return
times
;
}
return
null
;
}
private
static
void
sendAlert
(
int
type
,
int
doneTimes
,
int
setTimes
,
QwInterfaceLimitEnum
obj
,
String
enterpriseId
,
Date
now
)
{
// 调用次数达上线
String
time
=
null
;
String
title
=
"已达上限"
;
boolean
sendFlag
=
false
;
if
(
doneTimes
>=
setTimes
)
{
sendFlag
=
true
;
if
(
type
==
1
)
{
time
=
DateUtil
.
dateToStr
(
now
,
"yyyy年MM月"
);
}
if
(
type
==
2
)
{
time
=
DateUtil
.
dateToStr
(
now
,
"yyyy年MM月dd日"
);
}
if
(
type
==
3
)
{
time
=
DateUtil
.
dateToStr
(
now
,
"yyyy年MM月dd日 HH:mm:ss"
);
}
}
else
if
(
type
==
1
||
type
==
2
)
{
switch
(
type
)
{
case
1
:
setTimes
=
setTimes
-
30000
;
break
;
case
2
:
setTimes
=
setTimes
-
300000
;
break
;
default
:
break
;
}
if
(
doneTimes
>=
setTimes
)
{
sendFlag
=
true
;
if
(
type
==
1
)
{
time
=
DateUtil
.
dateToStr
(
now
,
"yyyy年MM月"
);
}
if
(
type
==
2
)
{
DateUtil
.
dateToStr
(
now
,
"yyyy年MM月dd日"
);
}
title
=
"即将达到可调用次数"
;
}
}
if
(
sendFlag
)
{
EnterpriseDTO
enterpriseDTO
=
enterpriseService
.
getEnterpriseById
(
enterpriseId
);
String
brandName
=
enterpriseDTO
.
getBrandName
();
// 达到上限时文案
String
msg
=
String
.
format
(
"告警【%s】%s调用在【%s】%s"
,
brandName
,
obj
.
getRemark
(),
time
,
title
);
DingUtils
.
send
(
msg
,
false
);
}
}
public
static
void
addTimes
(
String
wxEnterpriseId
,
QwInterfaceLimitEnum
obj
)
{
String
interfaceName
=
obj
.
getName
();
Date
now
=
new
Date
();
String
dateStr
=
getDateStr
(
now
);
String
keyHour
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
10
));
addTimes
(
3
,
keyHour
);
String
keyDay
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
8
));
addTimes
(
2
,
keyDay
);
String
keyMonth
=
getCacheKey
(
wxEnterpriseId
,
interfaceName
,
dateStr
.
substring
(
0
,
6
));
addTimes
(
1
,
keyMonth
);
}
private
static
String
getCacheKey
(
String
wxEnterpriseId
,
String
interfacName
,
String
dateStr
)
{
return
new
StringBuilder
(
wxEnterpriseId
).
append
(
interfacName
).
append
(
dateStr
).
toString
();
}
// 1月 2天 3小时
private
static
void
addTimes
(
int
type
,
String
key
)
{
RAtomicLong
cache
=
RedisUtil
.
getRedisClient
().
getAtomicLong
(
key
);
long
val
=
cache
.
addAndGet
(
1
);
if
(
val
<=
1
)
{
switch
(
type
)
{
case
1
:
cache
.
expire
(
31
,
TimeUnit
.
DAYS
);
break
;
case
2
:
cache
.
expire
(
1
,
TimeUnit
.
DAYS
);
break
;
case
3
:
cache
.
expire
(
1
,
TimeUnit
.
HOURS
);
break
;
default
:
break
;
}
}
}
private
static
String
getDateStr
(
Date
now
)
{
String
dateStr
=
DateUtil
.
dateToStr
(
now
,
"yyyyMMddHHmmss"
);
return
dateStr
;
}
}
haoban-manage3-service/src/main/resources/dubbo-haoban-manage-service.xml
View file @
8a69d1a2
...
...
@@ -46,8 +46,6 @@
timeout=
"10000"
/>
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.MemberUnionidRelatedApiService"
ref=
"memberUnionidRelatedApiServiceImpl"
timeout=
"10000"
/>
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.BindApiService"
ref=
"bindApiServiceImpl"
timeout=
"10000"
/>
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.ApplicationSettingApiService"
ref=
"applicationSettingApiServiceImpl"
timeout=
"10000"
/>
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.AuditSettingApiService"
ref=
"auditSettingApiServiceImpl"
...
...
@@ -130,7 +128,8 @@
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.SyncHaobanToGicApiService"
ref=
"syncHaobanToGicApiServiceImpl"
timeout=
"10000"
/>
<dubbo:service
interface=
"com.gic.haoban.manage.api.service.ValidationCodeApiService"
ref=
"validationCodeApiServiceImpl"
/>
<dubbo:reference
interface=
"com.gic.wechat.api.service.qywx.QywxExternalUserService"
id=
"qywxExternalUserService"
/>
<dubbo:reference
interface=
"com.gic.enterprise.api.service.EnterpriseUseForbidService"
id=
"enterpriseUseForbidService"
/>
<dubbo:reference
interface=
"com.gic.enterprise.api.service.DepartmentService"
id=
"gicDepartmentService"
/>
<dubbo:reference
interface=
"com.gic.wechat.api.service.qywx.QywxDepartmentApiService"
...
...
haoban-manage3-service/src/main/resources/mapper/WxEnterpriseRelatedMapper.xml
View file @
8a69d1a2
...
...
@@ -27,11 +27,6 @@
from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.String"
>
delete
from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</delete>
<update
id=
"deleteByEnterpriseId"
>
update tab_haoban_wx_enterprise_related set status_flag = 0 , update_time=now() where enterprise_id=#{enterpriseId} and status_flag=1
...
...
haoban-manage3-wx/src/main/webapp/WEB-INF/dubbo-haoban-manage-wx.xml
View file @
8a69d1a2
...
...
@@ -27,7 +27,6 @@
<dubbo:reference
interface=
"com.gic.enterprise.api.service.StoreService"
id=
"storeService"
/>
<dubbo:reference
interface=
"com.gic.wechat.api.service.qywx.QywxCorpApiService"
id=
"qywxCorpApiService"
/>
<dubbo:reference
interface=
"com.gic.wechat.api.service.qywx.QywxUserApiService"
id=
"qywxUserApiService"
/>
<dubbo:reference
interface=
"com.gic.haoban.manage.api.service.BindApiService"
id=
"bindApiService"
/>
<dubbo:reference
interface=
"com.gic.haoban.manage.api.service.AuditApiService"
id=
"auditApiService"
/>
<dubbo:reference
interface=
"com.gic.haoban.manage.api.service.AuditSettingApiService"
id=
"auditSettingApiService"
/>
<dubbo:reference
interface=
"com.gic.dict.api.service.ManagerDictService"
id=
"managerDictService"
/>
...
...
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