Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
ops
Commits
5f1ea899
Commit
5f1ea899
authored
Oct 14, 2025
by
wujipeng
Browse files
扣子证书替换接口优化,证书定时提醒
parent
6b100d2f
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/controller/CertificateController.java
View file @
5f1ea899
package
com.ruzhoukj.sms.controller
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.platform.model.resp.Result
;
import
com.ruzhoukj.sms.entity.CertificateEntity
;
import
com.ruzhoukj.sms.entity.kzReminderEntity
;
import
com.ruzhoukj.sms.pojo.dto.CertificateDTO
;
import
com.ruzhoukj.sms.service.CertificateService
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ruzhoukj.sms.service.KzReminderService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
@Slf4j
@RequestMapping
(
"/certificate"
)
@RestController
public
class
CertificateController
{
@Resource
private
CertificateService
certificateService
;
@Resource
private
KzReminderService
kzReminderService
;
@PostMapping
(
"/reminder"
)
public
Result
<
String
>
reminder
(
@RequestBody
CertificateDTO
certificateDTO
)
{
kzReminderService
.
save
(
kzReminderEntity
.
builder
()
.
time
(
certificateDTO
.
getTime
())
.
phone
(
certificateDTO
.
getPhone
())
.
email
(
certificateDTO
.
getEmail
())
.
userName
(
certificateDTO
.
getUserName
())
.
content
(
certificateDTO
.
getContent
())
.
build
());
log
.
info
(
"提醒人信息---------{}"
,
certificateDTO
);
return
Result
.
data
(
"定时通知设置成功"
);
}
@GetMapping
(
"/replace"
)
public
Boolean
replace
(
@RequestParam
(
"fileName"
)
String
fileName
)
{
return
true
;
public
Result
<
Boolean
>
replace
(
@RequestParam
(
"url"
)
String
url
,
@RequestParam
(
"name"
)
String
name
)
{
log
.
info
(
"url-------------{}"
,
url
);
log
.
info
(
"name-------------{}"
,
name
);
InputStream
inputStream
;
try
{
inputStream
=
downloadAsStream
(
url
);
}
catch
(
IOException
e
)
{
return
Result
.
data
(
false
);
}
CertificateEntity
certificate
=
certificateService
.
getOne
(
new
LambdaQueryWrapper
<
CertificateEntity
>().
eq
(
CertificateEntity:
:
getName
,
name
));
if
(
ObjectUtils
.
isEmpty
(
certificate
))
{
return
Result
.
data
(
false
);
}
return
Result
.
data
(
uploadFile
(
name
,
certificate
.
getPath
(),
inputStream
));
}
/**
* 从指定的URL下载文件并返回输入流
*
* @param fileUrl 文件的完整URL地址
* @return InputStream 文件内容的输入流,需要由调用方关闭
* @throws IOException 当网络连接失败或HTTP响应码非200时抛出
*/
public
static
InputStream
downloadAsStream
(
String
fileUrl
)
throws
IOException
{
URL
url
=
new
URL
(
fileUrl
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
// 设置连接参数
connection
.
setConnectTimeout
(
10000
);
// 10秒连接超时
connection
.
setReadTimeout
(
60000
);
// 60秒读取超时
connection
.
setRequestMethod
(
"GET"
);
// 设置User-Agent,防止被服务器拒绝[2,3,5](@ref)
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
);
// 检查HTTP响应状态[6,7](@ref)
int
responseCode
=
connection
.
getResponseCode
();
if
(
responseCode
!=
HttpURLConnection
.
HTTP_OK
)
{
connection
.
disconnect
();
throw
new
IOException
(
"HTTP请求失败,响应码: "
+
responseCode
+
" - "
+
connection
.
getResponseMessage
());
}
// 返回输入流,注意:调用方需要负责关闭这个流[8](@ref)
return
connection
.
getInputStream
();
}
public
static
Boolean
uploadFile
(
@RequestParam
(
"name"
)
String
fileName
,
@RequestParam
(
"path"
)
String
filePath
,
InputStream
inputStream
)
{
if
(
fileName
==
null
||
fileName
.
isEmpty
()
||
filePath
==
null
||
filePath
.
isEmpty
())
{
return
true
;
}
File
directory
=
new
File
(
filePath
);
if
(!
directory
.
exists
())
{
directory
.
mkdirs
();
}
File
outputFile
=
new
File
(
directory
,
fileName
);
// 使用Spring的StreamUtils进行流拷贝
try
(
FileOutputStream
outputStream
=
new
FileOutputStream
(
outputFile
))
{
StreamUtils
.
copy
(
inputStream
,
outputStream
);
return
true
;
}
catch
(
IOException
e
)
{
return
false
;
}
finally
{
// 确保关闭输入流,如果它不由Spring管理的话
try
{
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
}
catch
(
IOException
ignored
)
{
}
}
}
}
\ No newline at end of file
src/main/java/com/ruzhoukj/sms/dao/KzReminderMapper.java
0 → 100644
View file @
5f1ea899
package
com.ruzhoukj.sms.dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.ruzhoukj.sms.entity.kzReminderEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* @author : wujipeng
* @date : 2025/10/14 16:30
* @Version: 1.0
* @Desc : 描述信息
*/
@Mapper
public
interface
KzReminderMapper
extends
BaseMapper
<
kzReminderEntity
>
{
}
src/main/java/com/ruzhoukj/sms/entity/CertificateEntity.java
View file @
5f1ea899
...
...
@@ -13,12 +13,9 @@ public class CertificateEntity {
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@TableField
(
"
file_
name"
)
private
String
fileN
ame
;
@TableField
(
"name"
)
private
String
n
ame
;
@TableField
(
"local_path"
)
private
String
localPath
;
@TableField
(
"linux_path"
)
private
String
linuxPath
;
@TableField
(
"path"
)
private
String
path
;
}
\ No newline at end of file
src/main/java/com/ruzhoukj/sms/entity/kzReminderEntity.java
0 → 100644
View file @
5f1ea899
package
com.ruzhoukj.sms.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.Date
;
/**
* @author : wujipeng
* @date : 2025/10/14 16:28
* @Version: 1.0
* @Desc : 描述信息
*/
@Data
@TableName
(
"kz_reminder"
)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
kzReminderEntity
{
@TableId
(
type
=
IdType
.
ASSIGN_ID
)
private
String
id
;
@TableField
(
"user_name"
)
private
String
userName
;
private
String
phone
;
private
String
email
;
private
String
content
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
time
;
}
src/main/java/com/ruzhoukj/sms/pojo/dto/CertificateDTO.java
0 → 100644
View file @
5f1ea899
package
com.ruzhoukj.sms.pojo.dto
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.ruzhoukj.sms.entity.CertificateEntity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.Date
;
/**
* @author : wujipeng
* @date : 2025/10/14 14:35
* @Version: 1.0
* @Desc : 描述信息
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
CertificateDTO
extends
CertificateEntity
{
@ApiModelProperty
(
value
=
"用户名"
)
private
String
userName
;
@ApiModelProperty
(
value
=
"手机号"
)
private
String
phone
;
@ApiModelProperty
(
value
=
"邮箱"
)
private
String
email
;
@ApiModelProperty
(
value
=
"通知内容"
)
private
String
content
;
@ApiModelProperty
(
value
=
"时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
time
;
}
src/main/java/com/ruzhoukj/sms/service/KzReminderService.java
0 → 100644
View file @
5f1ea899
package
com.ruzhoukj.sms.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.ruzhoukj.sms.entity.kzReminderEntity
;
/**
* @author : wujipeng
* @date : 2025/10/14 16:31
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
KzReminderService
extends
IService
<
kzReminderEntity
>
{
}
src/main/java/com/ruzhoukj/sms/service/impl/KzReminderServiceImpl.java
0 → 100644
View file @
5f1ea899
package
com.ruzhoukj.sms.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ruzhoukj.sms.dao.KzReminderMapper
;
import
com.ruzhoukj.sms.entity.kzReminderEntity
;
import
com.ruzhoukj.sms.service.KzReminderService
;
import
org.springframework.stereotype.Service
;
/**
* @author : wujipeng
* @date : 2025/10/14 16:31
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public
class
KzReminderServiceImpl
extends
ServiceImpl
<
KzReminderMapper
,
kzReminderEntity
>
implements
KzReminderService
{
}
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