Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnooc_zydeepen-cggl_expert-manage-miniapp
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
孙德龙
cnooc_zydeepen-cggl_expert-manage-miniapp
Commits
74a7e641
Commit
74a7e641
authored
Nov 14, 2025
by
weisong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test
parent
bde8b9b5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
1 deletions
+180
-1
pom.xml
+5
-0
src/main/java/com/cnooc/expert/auth/service/impl/LoginServiceImpl.java
+1
-0
src/main/java/com/cnooc/expert/common/utils/KafkaProducerUtil.java
+79
-0
src/main/java/com/cnooc/expert/controller/auth/LoginController.java
+77
-1
src/main/resources/application.yml
+18
-0
No files found.
pom.xml
View file @
74a7e641
...
...
@@ -46,6 +46,11 @@
</dependency>
<dependency>
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka
</artifactId>
</dependency>
<dependency>
<groupId>
com.squareup.retrofit2
</groupId>
<artifactId>
retrofit
</artifactId>
<version>
2.9.0
</version>
...
...
src/main/java/com/cnooc/expert/auth/service/impl/LoginServiceImpl.java
View file @
74a7e641
...
...
@@ -175,6 +175,7 @@ public class LoginServiceImpl implements LoginService {
if
(!
flag
)
{
// 保存登录日志
//sysLogLoginService.save(login.getUsername(), Constant.FAIL, LoginOperationEnum.CAPTCHA_FAIL.getValue());
throw
new
BusinessException
(
GlobalErrorCodeConstants
.
CAPTCHA_EXPIRED
.
getCode
(),
GlobalErrorCodeConstants
.
CAPTCHA_EXPIRED
.
getMsg
());
}
//1.需要去库中查询,是否存在
...
...
src/main/java/com/cnooc/expert/common/utils/KafkaProducerUtil.java
0 → 100644
View file @
74a7e641
package
com
.
cnooc
.
expert
.
common
.
utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.kafka.support.SendResult
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.concurrent.ListenableFuture
;
import
org.springframework.util.concurrent.ListenableFutureCallback
;
@Component
public
class
KafkaProducerUtil
{
@Autowired
private
KafkaTemplate
<
String
,
Object
>
kafkaTemplate
;
/**
* 发送消息到指定主题
* @param topic 主题名称
* @param message 消息内容
*/
public
void
sendMessage
(
String
topic
,
Object
message
)
{
kafkaTemplate
.
send
(
topic
,
message
);
}
/**
* 发送消息到指定主题(带key)
* @param topic 主题名称
* @param key 消息key
* @param message 消息内容
*/
public
void
sendMessage
(
String
topic
,
String
key
,
Object
message
)
{
kafkaTemplate
.
send
(
topic
,
key
,
message
);
}
/**
* 发送消息到指定主题(带分区和key)
* @param topic 主题名称
* @param partition 分区
* @param key 消息key
* @param message 消息内容
*/
public
void
sendMessage
(
String
topic
,
Integer
partition
,
String
key
,
Object
message
)
{
kafkaTemplate
.
send
(
topic
,
partition
,
key
,
message
);
}
/**
* 异步发送消息,带回调函数
* @param topic 主题名称
* @param message 消息内容
* @param callback 回调函数
*/
public
void
sendMessageWithCallback
(
String
topic
,
Object
message
,
ListenableFutureCallback
<
SendResult
<
String
,
Object
>>
callback
)
{
ListenableFuture
<
SendResult
<
String
,
Object
>>
future
=
kafkaTemplate
.
send
(
topic
,
message
);
future
.
addCallback
(
callback
);
}
/**
* 异步发送消息,带默认回调
* @param topic 主题名称
* @param message 消息内容
*/
public
void
sendMessageWithCallback
(
String
topic
,
Object
message
)
{
ListenableFuture
<
SendResult
<
String
,
Object
>>
future
=
kafkaTemplate
.
send
(
topic
,
message
);
future
.
addCallback
(
new
ListenableFutureCallback
<
SendResult
<
String
,
Object
>>()
{
@Override
public
void
onSuccess
(
SendResult
<
String
,
Object
>
result
)
{
System
.
out
.
println
(
"发送消息成功: "
+
message
+
", offset: "
+
result
.
getRecordMetadata
().
offset
());
}
@Override
public
void
onFailure
(
Throwable
ex
)
{
System
.
err
.
println
(
"发送消息失败: "
+
message
+
", 错误: "
+
ex
.
getMessage
());
}
});
}
}
\ No newline at end of file
src/main/java/com/cnooc/expert/controller/auth/LoginController.java
View file @
74a7e641
package
com
.
cnooc
.
expert
.
controller
.
auth
;
import
com.
cnooc.expert.auth.service.LoginService
;
import
com.
alibaba.fastjson.JSON
;
import
com.cnooc.expert.auth.service.SysCaptchaService
;
import
com.cnooc.expert.common.constant.TokenConstants
;
import
com.cnooc.expert.common.response.ApiResult
;
import
com.cnooc.expert.auth.service.LoginService
;
import
com.cnooc.expert.common.utils.JwtUtils
;
import
com.cnooc.expert.common.utils.KafkaProducerUtil
;
import
com.cnooc.expert.external.expert.model.response.ExpertInfoResp
;
import
com.cnooc.expert.system.entity.pojo.ZhuanJiaUser
;
import
com.cnooc.expert.system.entity.vo.LoginVO
;
import
com.cnooc.expert.system.entity.vo.SysCaptchaVO
;
import
com.cnooc.expert.system.entity.vo.VerifyCodeVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
@Slf4j
@RestController
...
...
@@ -25,6 +35,72 @@ public class LoginController {
@Autowired
private
SysCaptchaService
sysCaptchaService
;
// 测试代码,先注掉
// @Autowired
// private KafkaProducerUtil kafkaProducerUtil;
//
// @Resource(name="redisCommonTemplate")
// private RedisTemplate<String, Object> redisTemplate;
//
// private ZhuanJiaUser convert2ZhuanjiaUser(ExpertInfoResp expertInfoResp){
// if( expertInfoResp == null ){
// return null;
// }
//
// ZhuanJiaUser zhuanJiaUser = new ZhuanJiaUser();
// zhuanJiaUser.setZhuanJiaGuid(expertInfoResp.getZhuanJiaGuid());
// zhuanJiaUser.setMobile(expertInfoResp.getMobile());
// zhuanJiaUser.setShenFenZheng(expertInfoResp.getShenFenZheng());
// zhuanJiaUser.setShiFouYiFaZhuanJia(expertInfoResp.getShiFouYiFaZhuanJia());
// zhuanJiaUser.setZhuanJiaCode(expertInfoResp.getZhuanJiaCode());
// zhuanJiaUser.setSuoShuBuMeng(expertInfoResp.getSuoShuBuMeng());
// zhuanJiaUser.setZhuanJiaName(expertInfoResp.getZhuanJiaName());
// zhuanJiaUser.setZhuanJiaShiXiangGuid(expertInfoResp.getZhuanJiaShiXiangGuid());
// zhuanJiaUser.setZhuanJiaZhuangTai(expertInfoResp.getZhuanJiaZhuangTai());
//
// return zhuanJiaUser;
// }
//
// /**
// * 手机号验证码/身份证号密码 登录功能
// * @return Result<String> 统一返回操作码及信息
// */
// @GetMapping("/test")
// public ApiResult<String> test() {
// // 校验loginType 不为空
//
//
// ExpertInfoResp expertInfoResp = new ExpertInfoResp();
// expertInfoResp.setZhuanJiaGuid("1234");
//
// ZhuanJiaUser zhuanJiaUser = convert2ZhuanjiaUser(expertInfoResp);
// zhuanJiaUser.setZhuanJiaZhuangTai((short)2);
// zhuanJiaUser.setMobile("18611383771");
// zhuanJiaUser.setZhuanJiaCode("ttt");
// zhuanJiaUser.setZhuanJiaGuid("11111111111");
// zhuanJiaUser.setZhuanJiaName("weisong");
// zhuanJiaUser.setSuoShuBuMeng("技术部");
//
//
// redisTemplate.opsForValue().set(TokenConstants.LOGIN_USER_KEY_ + zhuanJiaUser.getZhuanJiaGuid(), zhuanJiaUser, 48, TimeUnit.HOURS);
//
// log.info("set complete: "+TokenConstants.LOGIN_USER_KEY_ + zhuanJiaUser.getZhuanJiaGuid());
//
// ZhuanJiaUser zhuanjiaUser1 = (ZhuanJiaUser)redisTemplate.opsForValue().get(TokenConstants.LOGIN_USER_KEY_ + zhuanJiaUser.getZhuanJiaGuid());
//
// log.info("get complete:");
//
// log.info(JSON.toJSONString(zhuanjiaUser1));
//
//
// String token = JwtUtils.createToken("1234","ttttt");
// System.out.println("token is: "+token);
//
// kafkaProducerUtil.sendMessage("test-topic", zhuanjiaUser1);
// return ApiResult.success();
// }
/**
* 手机号验证码/身份证号密码 登录功能
* @param loginVO 登录表单
...
...
src/main/resources/application.yml
View file @
74a7e641
...
...
@@ -25,5 +25,23 @@ spring:
fail-on-unknown-properties
:
false
default-property-inclusion
:
non_null
kafka
:
# Kafka服务器地址
bootstrap-servers
:
localhost:9092
producer
:
key-serializer
:
org.apache.kafka.common.serialization.StringSerializer
value-serializer
:
org.springframework.kafka.support.serializer.JsonSerializer
properties
:
acks
:
all
retries
:
3
batch-size
:
16384
linger-ms
:
1
buffer-memory
:
33554432
server
:
port
:
9090
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