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
c40771c1
Commit
c40771c1
authored
Sep 03, 2024
by
wujipeng
Browse files
合同定时短信邮箱提醒
parent
17647892
Changes
11
Show whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/controller/ContractController.java
View file @
c40771c1
...
...
@@ -5,6 +5,7 @@ import com.ruzhoukj.sms.common.Result;
import
com.ruzhoukj.sms.pojo.dto.ContractDTO
;
import
com.ruzhoukj.sms.pojo.vo.ContractVO
;
import
com.ruzhoukj.sms.service.ContractService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -16,6 +17,7 @@ import java.util.List;
* @version 1.0
* @create 2024-09-02 16:47
*/
@Api
(
tags
=
"合同管理"
)
@RestController
@RequestMapping
(
"/contract"
)
public
class
ContractController
{
...
...
src/main/java/com/ruzhoukj/sms/controller/SSLController.java
View file @
c40771c1
...
...
@@ -5,6 +5,7 @@ import com.ruzhoukj.sms.common.Result;
import
com.ruzhoukj.sms.pojo.dto.SSLDTO
;
import
com.ruzhoukj.sms.pojo.vo.SSLVO
;
import
com.ruzhoukj.sms.service.SSLService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -16,6 +17,7 @@ import java.util.List;
* @version 1.0
* @create 2024-09-03 10:18
*/
@Api
(
tags
=
"运维项目"
)
@RestController
@RequestMapping
(
"/ssl"
)
public
class
SSLController
{
...
...
src/main/java/com/ruzhoukj/sms/controller/ScheduleController.java
View file @
c40771c1
...
...
@@ -5,6 +5,7 @@ import com.ruzhoukj.sms.common.Result;
import
com.ruzhoukj.sms.pojo.dto.ScheduleDTO
;
import
com.ruzhoukj.sms.pojo.vo.ScheduleVO
;
import
com.ruzhoukj.sms.service.ScheduleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -16,6 +17,7 @@ import java.util.List;
* @version 1.0
* @create 2024-09-03 10:53
*/
@Api
(
tags
=
"运维排期"
)
@RestController
@RequestMapping
(
"/schedule"
)
public
class
ScheduleController
{
...
...
src/main/java/com/ruzhoukj/sms/dao/ContractDao.java
View file @
c40771c1
...
...
@@ -41,4 +41,11 @@ public interface ContractDao extends BaseMapper<ContractEntity> {
* @return ContractVO
*/
ContractVO
selectParentContract
(
@Param
(
"homId"
)
String
homId
);
/**
* 查询近7天到期的合同信息
*
* @return List<ContractVO>
*/
List
<
ContractVO
>
selectSevenDaysContract
();
}
src/main/java/com/ruzhoukj/sms/entity/ContractEntity.java
View file @
c40771c1
...
...
@@ -53,6 +53,10 @@ public class ContractEntity {
@TableField
(
"renew_contract_code"
)
private
String
renewContractCode
;
@ApiModelProperty
(
value
=
"用户id"
)
@TableField
(
"user_id"
)
private
String
userId
;
@ApiModelProperty
(
value
=
"剩余天数"
)
@TableField
(
exist
=
false
)
private
Integer
remainingDays
;
...
...
src/main/java/com/ruzhoukj/sms/service/ContractService.java
View file @
c40771c1
...
...
@@ -61,4 +61,11 @@ public interface ContractService extends IService<ContractEntity> {
* @return ContractVO
*/
ContractVO
getContract
(
String
id
);
/**
* 查询近七天要到期的合同信息
*
* @return List<ContractVO>
*/
List
<
ContractVO
>
selectSevenDaysContract
();
}
src/main/java/com/ruzhoukj/sms/service/impl/ContractServiceImpl.java
View file @
c40771c1
...
...
@@ -85,4 +85,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractDao, ContractEntity
public
ContractVO
getContract
(
String
id
)
{
return
BeanUtil
.
copyProperties
(
baseMapper
.
selectById
(
id
),
ContractVO
.
class
);
}
@Override
public
List
<
ContractVO
>
selectSevenDaysContract
()
{
return
baseMapper
.
selectSevenDaysContract
();
}
}
src/main/java/com/ruzhoukj/sms/task/ContractTask.java
0 → 100644
View file @
c40771c1
package
com.ruzhoukj.sms.task
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
com.ruzhoukj.sms.common.NumberConstant
;
import
com.ruzhoukj.sms.entity.SmsInformEntity
;
import
com.ruzhoukj.sms.entity.UserEntity
;
import
com.ruzhoukj.sms.pojo.vo.ContractVO
;
import
com.ruzhoukj.sms.service.ContractService
;
import
com.ruzhoukj.sms.service.SmsInformService
;
import
com.ruzhoukj.sms.service.UserService
;
import
com.ruzhoukj.sms.util.DateUtils
;
import
com.ruzhoukj.sms.util.EmailUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
/**
* @author wujipeng
* @version 1.0
* @create 2024-09-03 11:08
*/
@Component
@Slf4j
public
class
ContractTask
{
@Resource
private
ContractService
contractService
;
@Resource
private
UserService
userService
;
@Resource
private
SmsInformService
smsInformService
;
//每天查询一次七天内要到期的合同
@Scheduled
(
cron
=
"0 0 10 * * ?"
)
public
void
contractRemind
()
{
List
<
ContractVO
>
list
=
contractService
.
selectSevenDaysContract
();
//要到期的合同
if
(
CollUtil
.
isNotEmpty
(
list
)
&&
list
.
size
()
>
NumberConstant
.
ZERO
)
{
for
(
ContractVO
contractVO
:
list
)
{
String
userId
=
contractVO
.
getUserId
();
UserEntity
user
=
userService
.
getById
(
userId
);
if
(
BeanUtil
.
isNotEmpty
(
user
))
{
//发送邮件
EmailUtil
.
contractReminder
(
user
.
getName
(),
user
.
getEmail
(),
contractVO
);
//保存短信通知
int
num
=
(
int
)
DateUtils
.
daysBetween
(
new
Date
(),
contractVO
.
getEndTime
());
smsInformService
.
save
(
SmsInformEntity
.
builder
()
.
date
(
contractVO
.
getEndTime
())
.
name
(
user
.
getName
())
.
num
(
num
)
.
phone
(
user
.
getPhone
())
.
serviceName
(
"合同"
+
contractVO
.
getCode
())
.
build
());
}
}
}
}
}
src/main/java/com/ruzhoukj/sms/task/ProjectTask.java
View file @
c40771c1
...
...
@@ -50,7 +50,7 @@ public class ProjectTask {
for
(
String
id
:
ids
)
{
UserEntity
userEntity
=
userService
.
getUserByLeader
(
id
);
if
(
BeanUtil
.
isNotEmpty
(
userEntity
))
{
EmailUtil
.
contra
ctReminder
(
userEntity
.
getName
(),
userEntity
.
getEmail
(),
projectEntity
);
EmailUtil
.
proje
ctReminder
(
userEntity
.
getName
(),
userEntity
.
getEmail
(),
projectEntity
);
smsInformService
.
save
(
SmsInformEntity
.
builder
()
.
date
(
endTime
)
.
name
(
userEntity
.
getName
())
...
...
src/main/java/com/ruzhoukj/sms/util/EmailUtil.java
View file @
c40771c1
...
...
@@ -2,6 +2,7 @@ package com.ruzhoukj.sms.util;
import
com.ruzhoukj.sms.entity.ProjectEntity
;
import
com.ruzhoukj.sms.entity.SSLEntity
;
import
com.ruzhoukj.sms.pojo.vo.ContractVO
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.mail.Message
;
...
...
@@ -127,7 +128,7 @@ public class EmailUtil {
}
}
public
static
void
contra
ctReminder
(
String
name
,
String
email
,
ProjectEntity
projectEntity
)
{
public
static
void
proje
ctReminder
(
String
name
,
String
email
,
ProjectEntity
projectEntity
)
{
final
String
username
=
"2404263178@qq.com"
;
final
String
password
=
"eryzvsveckiudiee"
;
...
...
@@ -170,6 +171,56 @@ public class EmailUtil {
Transport
.
send
(
message
);
log
.
info
(
"Email sent successfully"
);
}
catch
(
MessagingException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
void
contractReminder
(
String
name
,
String
email
,
ContractVO
contractVO
)
{
final
String
username
=
"2404263178@qq.com"
;
final
String
password
=
"eryzvsveckiudiee"
;
// QQ Mail SMTP server information
Properties
props
=
new
Properties
();
props
.
put
(
"mail.smtp.auth"
,
"true"
);
props
.
put
(
"mail.smtp.starttls.enable"
,
"true"
);
props
.
put
(
"mail.smtp.host"
,
"smtp.qq.com"
);
props
.
put
(
"mail.smtp.port"
,
"587"
);
Session
session
=
Session
.
getInstance
(
props
,
new
javax
.
mail
.
Authenticator
()
{
@Override
protected
javax
.
mail
.
PasswordAuthentication
getPasswordAuthentication
()
{
return
new
javax
.
mail
.
PasswordAuthentication
(
username
,
password
);
}
});
try
{
Message
message
=
new
MimeMessage
(
session
);
message
.
setSubject
(
"项目到期提醒"
);
message
.
setFrom
(
new
InternetAddress
(
username
));
// 添加多个收件人
String
[]
toAddresses
=
{
email
};
message
.
setRecipients
(
Message
.
RecipientType
.
TO
,
InternetAddress
.
parse
(
String
.
join
(
", "
,
toAddresses
)));
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\n"
);
stringJoiner
.
add
(
"尊敬的"
+
name
+
","
);
stringJoiner
.
add
(
"您和"
+
contractVO
.
getClient
()
+
"签订的:"
+
contractVO
.
getCode
()
+
"合同即将到期。"
);
stringJoiner
.
add
(
"合同签订时间为:"
+
DateUtils
.
formatDate
(
contractVO
.
getBeginTime
())
+
","
);
stringJoiner
.
add
(
"具体到期时间为:"
+
DateUtils
.
formatDate
(
contractVO
.
getEndTime
())
+
","
);
stringJoiner
.
add
(
"距今还有:"
+
(
int
)
DateUtils
.
daysBetween
(
new
Date
(),
contractVO
.
getEndTime
())
+
"天"
);
stringJoiner
.
add
(
"请您及时进行处理,以确保合同的连续性。"
);
stringJoiner
.
add
(
"From:研发部"
);
message
.
setText
(
stringJoiner
.
toString
());
Transport
.
send
(
message
);
log
.
info
(
"Email sent successfully"
);
}
catch
(
MessagingException
e
)
{
...
...
src/main/resources/com/ruzhoukj/sms/dao/ContractDao.xml
View file @
c40771c1
...
...
@@ -12,7 +12,8 @@
begin_time as beginTime,
end_time as endTime,
renew_contract as renewContract,
renew_contract_code as renewContractCode
renew_contract_code as renewContractCode,
user_id as userId
from
contract
where
...
...
@@ -30,7 +31,8 @@
begin_time as beginTime,
end_time as endTime,
renew_contract as renewContract,
renew_contract_code as renewContractCode
renew_contract_code as renewContractCode,
user_id as userId
from
contract
where
...
...
@@ -51,7 +53,8 @@
begin_time as beginTime,
end_time as endTime,
renew_contract as renewContract,
renew_contract_code as renewContractCode
renew_contract_code as renewContractCode,
user_id as userId
from
contract
where
...
...
@@ -62,4 +65,24 @@
limit
1
</select>
<select
id=
"selectSevenDaysContract"
resultType=
"com.ruzhoukj.sms.pojo.vo.ContractVO"
>
select id,
parent_id as parentId,
hom_id as homId,
code,
client,
begin_time as beginTime,
end_time as endTime,
renew_contract as renewContract,
renew_contract_code as renewContractCode,
user_id as userId
from
contract
where
end_time
between
current_date
and
date_add(current_date, interval 7 day)
</select>
</mapper>
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