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
王蔡翾
operation_platform
Commits
7b817d2a
Commit
7b817d2a
authored
Mar 28, 2025
by
王蔡翾
Browse files
初始化
parent
42848b59
Changes
43
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/example/operation_platform/model/vo/OperationJobVO.java
View file @
7b817d2a
...
...
@@ -6,11 +6,11 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
OperationJobVO
extends
OperationJob
{
private
String
robotName
;
private
String
stationName
;
private
String
operationType
;
private
String
workerName
;
private
Integer
id
;
private
String
robotId
;
}
src/main/java/com/example/operation_platform/model/vo/RobotAndDrone.java
0 → 100644
View file @
7b817d2a
package
com.example.operation_platform.model.vo
;
import
lombok.Data
;
@Data
public
class
RobotAndDrone
{
private
String
robotName
;
private
String
robotId
;
private
String
droneId
;
}
src/main/java/com/example/operation_platform/model/vo/WorkerVO.java
View file @
7b817d2a
...
...
@@ -15,5 +15,6 @@ public class WorkerVO {
private
Integer
id
;
private
String
img
;
private
String
password
;
private
Integer
typeId
;
}
src/main/java/com/example/operation_platform/service/GuideService.java
View file @
7b817d2a
...
...
@@ -23,4 +23,5 @@ public interface GuideService extends IService<GuideEntity> {
* @return GuideVO
*/
List
<
GuideVO
>
queryguidelist
(
GuideDTO
guideDTO
);
void
updateall
(
GuideDTO
guideDTO
);
}
src/main/java/com/example/operation_platform/service/MessageService.java
View file @
7b817d2a
...
...
@@ -5,6 +5,9 @@ import com.example.operation_platform.model.dto.MessageDTO;
import
com.example.operation_platform.model.entity.MessageEntity
;
import
com.example.operation_platform.model.vo.MessageVO
;
import
com.example.operation_platform.model.vo.PeopleMessageVO
;
import
com.example.operation_platform.model.vo.RobotAndDrone
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.List
;
...
...
@@ -27,7 +30,7 @@ public interface MessageService extends IService<MessageEntity> {
* 根据泵站查询人员信息列表
* @param stationId stationId
*/
PeopleMessageVO
queryPeople
(
Long
stationId
,
Long
robotId
);
PeopleMessageVO
queryPeople
(
Long
stationId
);
/**
* 查询泵站人员信息列表
*
...
...
@@ -35,5 +38,11 @@ public interface MessageService extends IService<MessageEntity> {
* @return List<PeopleMessageVO>
*/
List
<
PeopleMessageVO
>
querymessageList
(
MessageDTO
messageDTO
);
MessageVO
querypeopleId
(
@Param
(
"stationId"
)
String
stationId
,
@Param
(
"robotId"
)
@RequestParam
(
required
=
false
)
Long
robotId
,
@Param
(
"droneId"
)
@RequestParam
(
required
=
false
)
Long
droneId
);
/*
* 根据泵站id查询智能设备信息
* @param stationId stationId
* @return List<MessageVO>
*/
List
<
RobotAndDrone
>
queryrobotBystationId
(
String
stationId
);
}
src/main/java/com/example/operation_platform/service/OperationItemService.java
View file @
7b817d2a
...
...
@@ -5,6 +5,7 @@ import com.example.operation_platform.model.dto.OperationItemDTO;
import
com.example.operation_platform.model.entity.OperationItem
;
import
com.example.operation_platform.model.vo.OperationItemVO
;
import
java.util.ArrayList
;
import
java.util.List
;
public
interface
OperationItemService
extends
IService
<
OperationItem
>
{
...
...
@@ -15,4 +16,12 @@ public interface OperationItemService extends IService<OperationItem> {
* @return List<OperationItemVO>
*/
List
<
OperationItemVO
>
queryItemList
(
OperationItemDTO
operationItemDTO
);
/**
* 通过itemId数组查看item信息
*
* @param strings strings
* @return List<OperationItem>
*/
List
<
OperationItem
>
queryByIdList
(
List
<
String
>
strings
);
}
src/main/java/com/example/operation_platform/service/WorkerService.java
View file @
7b817d2a
...
...
@@ -47,4 +47,5 @@ public interface WorkerService extends IService<WorkerEntity> {
List
<
WorkerVO
>
queryByType
(
Integer
id
);
boolean
isUsernameEmpty
(
Integer
workerId
);
}
src/main/java/com/example/operation_platform/service/impl/GuideServiceImpl.java
View file @
7b817d2a
...
...
@@ -21,4 +21,8 @@ public class GuideServiceImpl extends ServiceImpl<GuideMapper, GuideEntity> impl
public
List
<
GuideVO
>
queryguidelist
(
GuideDTO
guideDTO
)
{
return
baseMapper
.
queryguidelist
(
guideDTO
);
}
@Override
public
void
updateall
(
GuideDTO
guideDTO
)
{
baseMapper
.
updateall
(
guideDTO
);
}
}
src/main/java/com/example/operation_platform/service/impl/MessageServiceImpl.java
View file @
7b817d2a
...
...
@@ -6,6 +6,7 @@ import com.example.operation_platform.model.dto.MessageDTO;
import
com.example.operation_platform.model.entity.MessageEntity
;
import
com.example.operation_platform.model.vo.MessageVO
;
import
com.example.operation_platform.model.vo.PeopleMessageVO
;
import
com.example.operation_platform.model.vo.RobotAndDrone
;
import
com.example.operation_platform.service.MessageService
;
import
org.springframework.stereotype.Service
;
...
...
@@ -23,11 +24,22 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessageEntity
this
.
baseMapper
.
resetmessage
(
messageDTO
);
}
@Override
public
PeopleMessageVO
queryPeople
(
Long
stationId
,
Long
robotId
)
{
return
this
.
baseMapper
.
queryPeople
(
stationId
,
robotId
);
public
PeopleMessageVO
queryPeople
(
Long
stationId
)
{
return
this
.
baseMapper
.
queryPeople
(
stationId
);
}
@Override
public
List
<
PeopleMessageVO
>
querymessageList
(
MessageDTO
messageDTO
)
{
return
this
.
baseMapper
.
querymessageList
(
messageDTO
);
}
@Override
public
MessageVO
querypeopleId
(
String
stationId
,
Long
robotId
,
Long
droneId
)
{
if
(
robotId
==
null
&&
droneId
==
null
)
{
throw
new
IllegalArgumentException
(
"Either robotId or droneId must be provided"
);
}
return
this
.
baseMapper
.
querypeopleId
(
stationId
,
robotId
,
droneId
);
}
@Override
public
List
<
RobotAndDrone
>
queryrobotBystationId
(
String
stationId
)
{
return
this
.
baseMapper
.
queryrobotBystationId
(
stationId
);
}
}
src/main/java/com/example/operation_platform/service/impl/OperationDoServiceImpl.java
View file @
7b817d2a
...
...
@@ -6,30 +6,61 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
com.example.operation_platform.mapper.OperationDoMapper
;
import
com.example.operation_platform.model.dto.OperationDoDTO
;
import
com.example.operation_platform.model.entity.OperationDoEntity
;
import
com.example.operation_platform.model.entity.OperationItem
;
import
com.example.operation_platform.model.vo.OperationDoVO
;
import
com.example.operation_platform.service.OperationDoService
;
import
com.example.operation_platform.service.OperationItemService
;
import
com.google.common.collect.Lists
;
import
com.platform.utils.DateUtil
;
import
com.platform.utils.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java
.util.Dat
e
;
import
java.util.
List
;
import
java
x.annotation.Resourc
e
;
import
java.util.
*
;
@Service
public
class
OperationDoServiceImpl
extends
ServiceImpl
<
OperationDoMapper
,
OperationDoEntity
>
implements
OperationDoService
{
@Resource
private
OperationItemService
operationItemService
;
@Override
public
List
<
OperationDoVO
>
queryDoList
(
OperationDoDTO
operationDoDTO
)
{
//查看机器人运维项目
List
<
OperationDoVO
>
operationVOList
=
baseMapper
.
queryDoList
(
operationDoDTO
);
//处理items
Set
<
String
>
items
=
new
HashSet
<>();
operationVOList
.
forEach
(
operationDoVO
->
{
if
(
StringUtils
.
isNotEmpty
(
operationDoVO
.
getItemId
()))
{
List
<
String
>
itemIdList
=
Arrays
.
asList
(
operationDoVO
.
getItemId
().
split
(
","
));
itemIdList
.
forEach
(
itemId
->
items
.
add
(
itemId
));
}
});
//通过itemId数组查看item信息
List
<
OperationItem
>
operationItemList
=
operationItemService
.
queryByIdList
(
Lists
.
newArrayList
(
items
));
operationVOList
.
forEach
(
operationDoVO
->
{
if
(
StringUtils
.
isNotEmpty
(
operationDoVO
.
getItemId
()))
{
List
<
String
>
itemIdList
=
Arrays
.
asList
(
operationDoVO
.
getItemId
().
split
(
","
));
itemIdList
.
forEach
(
itemId
->
{
for
(
OperationItem
operationItem
:
operationItemList
)
{
String
itemName
=
null
;
if
(
itemId
.
equals
(
operationItem
.
getId
()))
{
if
(
StringUtils
.
isEmpty
(
itemName
))
{
itemName
=
operationItem
.
getOperationItem
();
}
else
{
itemName
=
itemName
+
","
+
operationItem
.
getOperationItem
();
}
operationDoVO
.
setOperationItems
(
itemName
);
}
}
});
}
});
return
operationVOList
;
}
@Override
public
void
stopDo
(
OperationDoDTO
operationDoDTO
)
{
this
.
baseMapper
.
stopDo
(
operationDoDTO
);
...
...
src/main/java/com/example/operation_platform/service/impl/OperationItemServiceImpl.java
View file @
7b817d2a
...
...
@@ -8,6 +8,7 @@ import com.example.operation_platform.model.vo.OperationItemVO;
import
com.example.operation_platform.service.OperationItemService
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
@Service
public
class
OperationItemServiceImpl
extends
ServiceImpl
<
OperationItemMapper
,
OperationItem
>
implements
OperationItemService
{
...
...
@@ -16,4 +17,9 @@ public class OperationItemServiceImpl extends ServiceImpl<OperationItemMapper, O
return
this
.
baseMapper
.
queryItemList
(
operationItemDTO
);
}
@Override
public
List
<
OperationItem
>
queryByIdList
(
List
<
String
>
itemIdList
)
{
return
baseMapper
.
queryByIdList
(
itemIdList
);
}
}
src/main/java/com/example/operation_platform/service/impl/RunLogServiceImpl.java
View file @
7b817d2a
...
...
@@ -15,7 +15,12 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
@Service
public
class
RunLogServiceImpl
extends
ServiceImpl
<
RunLogMapper
,
RunLogEntity
>
implements
RunLogService
{
...
...
@@ -35,13 +40,44 @@ public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> i
//查看机器人操作日志
if
(
runLogEntity
.
getType
().
equals
(
"uav"
))
{
uavOperateLogList
=
operateLogService
.
queryListByRunLogId
(
runLogEntity
.
getId
());
// 过滤出纯中文部分
uavOperateLogList
=
uavOperateLogList
.
stream
()
.
map
(
log
->
{
String
chineseMessage
=
extractChinese
(
log
.
getContent
());
// 提取中文
log
.
setContent
(
chineseMessage
);
// 更新日志信息
return
log
;
})
.
filter
(
log
->
!
log
.
getContent
().
isEmpty
())
// 过滤掉空日志
.
collect
(
Collectors
.
toList
());
}
return
uavOperateLogList
;
}
// 使用正则表达式提取中文
private
String
extractChinese
(
String
text
)
{
// 正则表达式匹配中文字符
Pattern
pattern
=
Pattern
.
compile
(
"[\u4e00-\u9fa5]+"
);
Matcher
matcher
=
pattern
.
matcher
(
text
);
// 提取所有匹配的中文字符
StringBuilder
chineseText
=
new
StringBuilder
();
while
(
matcher
.
find
())
{
chineseText
.
append
(
matcher
.
group
());
}
return
chineseText
.
toString
();
}
@Override
public
void
download
(
String
id
,
HttpServletResponse
httpServletResponse
)
{
List
<
UavOperateLogEntity
>
uavOperateLogList
=
getInfoById
(
id
);
// 手动转换时间格式
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
uavOperateLogList
.
forEach
(
log
->
{
if
(
log
.
getDataTime
()
!=
null
)
{
log
.
setDataTimeStr
(
dateFormat
.
format
(
log
.
getDataTime
()));
// 使用临时字段存储格式化后的时间
}
});
ExcelUtil
<
UavOperateLogEntity
>
uavOperateLogExcelUtil
=
new
ExcelUtil
<>(
UavOperateLogEntity
.
class
);
uavOperateLogExcelUtil
.
exportExcel
(
uavOperateLogList
,
"机器人运行日志.xlsx"
,
...
...
src/main/java/com/example/operation_platform/service/impl/WorkerServiceImpl.java
View file @
7b817d2a
...
...
@@ -35,4 +35,9 @@ public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, WorkerEntity> i
public
List
<
WorkerVO
>
queryByType
(
Integer
id
)
{
return
this
.
baseMapper
.
queryByType
(
id
);
}
@Override
public
boolean
isUsernameEmpty
(
Integer
workerId
)
{
WorkerEntity
workerEntity
=
baseMapper
.
selectById
(
workerId
);
return
workerEntity
==
null
||
workerEntity
.
getUsername
()
==
null
||
workerEntity
.
getUsername
().
isEmpty
();
}
}
src/main/java/com/example/operation_platform/task/OperationDoTask.java
View file @
7b817d2a
package
com.example.operation_platform.task
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.example.operation_platform.mapper.MessageMapper
;
import
com.example.operation_platform.mapper.OperationDoMapper
;
import
com.example.operation_platform.mapper.OperationJobMapper
;
import
com.example.operation_platform.mapper.WorkerMapper
;
import
com.example.operation_platform.model.entity.MessageEntity
;
import
com.example.operation_platform.model.entity.OperationDoEntity
;
import
com.example.operation_platform.model.entity.OperationJob
;
import
com.example.operation_platform.model.entity.WorkerEntity
;
import
com.example.operation_platform.model.vo.MessageNeedDataVo
;
import
com.platform.utils.AliSmsUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDate
;
import
java.util.
Li
st
;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.st
ream.Collectors
;
import
org.json.JSONObject
;
@Component
public
class
OperationDoTask
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
OperationDoTask
.
class
);
@Autowired
private
OperationDoMapper
operationDoMapper
;
@Autowired
private
OperationJobMapper
operationJobMapper
;
@Autowired
private
MessageMapper
messageMapper
;
@Autowired
private
WorkerMapper
workerMapper
;
@Autowired
private
AliSmsUtil
aliSmsUtil
;
@Scheduled
(
cron
=
"0 0 0 * * ?"
)
// 每天午夜执行
public
void
scheduleOperationJobs
()
{
...
...
@@ -30,10 +47,16 @@ public class OperationDoTask {
LocalDate
now
=
LocalDate
.
now
();
// 改用 LocalDate 类型
for
(
OperationDoEntity
operation
:
operations
)
{
// 获取 OperationEntity 实体
OperationDoEntity
operationEntity
=
operationDoMapper
.
selectById
(
operation
.
getId
());
if
(
operationEntity
==
null
||
operationEntity
.
getRunlogOrOperation
()
!=
0
)
{
continue
;
}
// 1. 获取计划参数
LocalDate
planStartDate
=
operation
.
getStartTime
();
// 直接使用 LocalDate
int
cycleDays
=
operation
.
getOperationCycle
();
int
durationDays
=
operation
.
get
Completion
Time
();
int
durationDays
=
operation
.
get
Finish
Time
();
// 2. 查询当前计划下的所有任务(按时间倒序)
List
<
OperationJob
>
existingJobs
=
operationJobMapper
.
selectList
(
...
...
@@ -44,7 +67,13 @@ public class OperationDoTask {
// 3. 自动生成新任务逻辑
if
(
existingJobs
.
isEmpty
())
{
createTwoJobs
(
operation
,
planStartDate
,
cycleDays
,
durationDays
);
if
(
now
.
isBefore
(
planStartDate
))
{
// 如果当前时间在计划开始时间之前,只创建一条任务
createOneJob
(
operation
,
planStartDate
,
durationDays
);
}
else
{
// 如果当前时间等于或在计划开始时间之后,创建两条任务
createTwoJobs
(
operation
,
planStartDate
,
cycleDays
,
durationDays
);
}
}
else
{
maintainTwoValidJobs
(
operation
,
existingJobs
,
cycleDays
,
durationDays
,
now
);
}
...
...
@@ -54,49 +83,97 @@ public class OperationDoTask {
}
}
private
void
createOneJob
(
OperationDoEntity
operation
,
LocalDate
startDate
,
int
durationDays
)
{
// 获取 OperationEntity 实体
OperationDoEntity
operationEntity
=
operationDoMapper
.
selectById
(
operation
.
getId
());
if
(
operationEntity
==
null
||
operationEntity
.
getRunlogOrOperation
()
!=
0
)
{
return
;
}
LocalDate
jobStart
=
startDate
;
LocalDate
jobEnd
=
jobStart
.
plusDays
(
durationDays
);
int
finishStatus
=
0
;
// 任务状态为0(未开始)
insertJob
(
operation
,
jobStart
,
jobEnd
,
finishStatus
);
}
private
void
createTwoJobs
(
OperationDoEntity
operation
,
LocalDate
startDate
,
int
cycleDays
,
int
durationDays
)
{
// 生成第一条任务
LocalDate
job1Start
=
startDate
;
LocalDate
job1End
=
job1Start
.
plusDays
(
durationDays
);
insertJob
(
operation
,
job1Start
,
job1End
);
// 生成第二条任务(下一周期)
LocalDate
job2Start
=
job1Start
.
plusDays
(
cycleDays
);
LocalDate
job2End
=
job2Start
.
plusDays
(
durationDays
);
insertJob
(
operation
,
job2Start
,
job2End
);
// 获取 OperationEntity 实体
OperationDoEntity
operationEntity
=
operationDoMapper
.
selectById
(
operation
.
getId
());
if
(
operationEntity
==
null
||
operationEntity
.
getRunlogOrOperation
()
!=
0
)
{
return
;
}
LocalDate
now
=
LocalDate
.
now
();
// 只有当operation状态为0(进行中)时才创建任务
if
(
"0"
.
equals
(
operation
.
getStatus
()))
{
// 生成第一条任务
LocalDate
job1Start
=
startDate
;
LocalDate
job1End
=
job1Start
.
plusDays
(
durationDays
);
int
job1Status
=
job1Start
.
isEqual
(
now
)
?
1
:
0
;
insertJob
(
operation
,
job1Start
,
job1End
,
job1Status
);
// 生成第二条任务(下一周期)
LocalDate
job2Start
=
job1Start
.
plusDays
(
cycleDays
);
LocalDate
job2End
=
job2Start
.
plusDays
(
durationDays
);
// 确保第二条任务开始时间在当前时间之后
if
(
job2Start
.
isAfter
(
now
))
{
int
job2Status
=
0
;
insertJob
(
operation
,
job2Start
,
job2End
,
job2Status
);
}
}
}
private
void
maintainTwoValidJobs
(
OperationDoEntity
operation
,
List
<
OperationJob
>
existingJobs
,
int
cycleDays
,
int
durationDays
,
LocalDate
now
)
{
// 获取 OperationEntity 实体
OperationDoEntity
operationEntity
=
operationDoMapper
.
selectById
(
operation
.
getId
());
if
(
operationEntity
==
null
||
operationEntity
.
getRunlogOrOperation
()
!=
0
)
{
return
;
}
// 检查所有任务的状态并更新
for
(
OperationJob
job
:
existingJobs
)
{
int
newStatus
=
calculateStatus
(
job
,
now
);
if
(
newStatus
!=
job
.
getFinishStatus
())
{
job
.
setFinishStatus
(
newStatus
);
operationJobMapper
.
updateById
(
job
);
}
}
// 获取最新的任务
OperationJob
latestJob
=
existingJobs
.
get
(
0
);
// 检查最新任务是否已过期
if
(
latestJob
.
getEndTime
().
isBefore
(
now
))
{
// 计算新任务开始时间(跳过当前周期)
LocalDate
newStart
=
latestJob
.
getStartTime
().
plusDays
(
cycleDays
*
2L
);
LocalDate
newEnd
=
newStart
.
plusDays
(
durationDays
);
insertJob
(
operation
,
newStart
,
newEnd
);
// 只有当operation状态为0(进行中)时才创建新任务
if
(
"0"
.
equals
(
operation
.
getStatus
()))
{
// 检查最新任务是否已过期
if
(
latestJob
.
getEndTime
().
isBefore
(
now
))
{
// 计算新任务开始时间(跳过当前周期)
LocalDate
newStart
=
latestJob
.
getStartTime
().
plusDays
(
cycleDays
);
LocalDate
newEnd
=
newStart
.
plusDays
(
durationDays
);
// 确保新任务开始时间在当前时间之后
if
(
newStart
.
isAfter
(
now
))
{
int
finishStatus
=
0
;
insertJob
(
operation
,
newStart
,
newEnd
,
finishStatus
);
return
;
// 插入新任务后立即返回,避免重复处理
}
}
}
}
private
void
insertJob
(
OperationDoEntity
operation
,
LocalDate
start
,
LocalDate
end
)
{
//builder模式实现插入
// OperationJob job = OperationJob.builder()
// .operationId(operation.getId())
// .startTime(start)
// .endTime(end)
// .finishStatus(0).build();
private
void
insertJob
(
OperationDoEntity
operation
,
LocalDate
start
,
LocalDate
end
,
int
finishStatus
)
{
// 创建一个OperationJob实例来安排或记录某个操作的执行
OperationJob
job
=
new
OperationJob
();
// 设置操作的唯一标识符,以便跟踪和管理
// 设置操作的唯一标识符,以便跟踪和管理
job
.
setOperationId
(
operation
.
getId
());
// 设置操作的开始时间,标志着操作执行的起始时刻
// 设置操作的开始时间,标志着操作执行的起始时刻
job
.
setStartTime
(
start
);
// 设置操作的结束时间,标志着操作执行的结束时刻
// 设置操作的结束时间,标志着操作执行的结束时刻
job
.
setEndTime
(
end
);
// 初始化操作的完成状态
为0,通常表示操作尚未完成或正在等待执行
job
.
setFinishStatus
(
0
);
// 初始化操作的完成状态
job
.
setFinishStatus
(
finishStatus
);
operationJobMapper
.
insert
(
job
);
}
...
...
@@ -108,53 +185,155 @@ public class OperationDoTask {
);
for
(
OperationJob
job
:
allJobs
)
{
// 首先检查任务是否已被人工完成(状态2或4)
if
(
job
.
getFinishStatus
()
==
2
||
job
.
getFinishStatus
()
==
4
)
{
continue
;
// 跳过已完成的任务
}
// 计算当前状态
int
newStatus
=
calculateStatus
(
job
,
now
);
if
(
newStatus
!=
job
.
getFinishStatus
())
{
job
.
setFinishStatus
(
newStatus
);
operationJobMapper
.
updateById
(
job
);
}
// 发送提前3天提醒(任务开始前3天的0点触发)
if
(
newStatus
==
0
)
{
checkAndSendSms
(
job
,
now
);
// 检查是否需要发送提醒(开始前7天内且任务未完成)
if
(
shouldSendReminder
(
job
,
now
))
{
if
(
job
.
getRunlogOrOperation
()
==
0
)
{
sendTaskNotificationSms
(
job
.
getOperationId
());
}
}
}
}
private
int
calculateStatus
(
OperationJob
job
,
LocalDate
now
)
{
if
(
job
.
getEndTime
().
isBefore
(
now
))
{
return
1
;
// 已过期
return
3
;
// 已过期
}
else
if
(
job
.
getStartTime
().
isAfter
(
now
))
{
return
0
;
// 未开始
}
else
{
return
0
;
// 进行中(start <= now < end)
return
1
;
// 进行中(start <= now < end)
}
}
private
void
checkAndSendSms
(
OperationJob
job
,
LocalDate
now
)
{
LocalDate
reminderDate
=
job
.
getStartTime
().
minusDays
(
7
);
if
(
now
.
isEqual
(
reminderDate
))
{
// 精确在提前3天的0点触发
sendAliyunSms
(
job
.
getOperationId
(),
job
.
getStartTime
());
// 精确匹配提醒日期,避免重复发送
if
(
now
.
isEqual
(
reminderDate
))
{
if
(
job
.
getRunlogOrOperation
()
==
0
)
{
sendTaskNotificationSms
(
job
.
getOperationId
());
}
}
}
//阿里云短信服务(示例伪代码)
private
void
sendAliyunSms
(
Integer
operationId
,
LocalDate
startTime
)
{
// // 1. 获取关联手机号(需根据业务逻辑实现)
// String phone = getPhoneByOperation(operationId);
//
// // 2. 构造请求参数
// SendSmsRequest request = new SendSmsRequest()
// .setPhoneNumbers(phone)
// .setSignName("YourSignName")
// .setTemplateCode("SMS_123456789")
// .setTemplateParam("{\"date\":\"" + startTime.toLocalDate() + "\"}");
//
// // 3. 发送请求
// try {
// SendSmsResponse response = aliyunClient.getAcsResponse(request);
// log.info("短信发送结果:{}", response.getCode());
// } catch (ClientException e) {
// log.error("短信发送失败", e);
// }
private
boolean
shouldSendReminder
(
OperationJob
job
,
LocalDate
now
)
{
// 任务已被人工完成(状态2或4)则不发送
if
(
job
.
getFinishStatus
()
==
2
||
job
.
getFinishStatus
()
==
4
)
{
return
false
;
}
// 计算距离任务开始时间的天数
long
daysUntilStart
=
ChronoUnit
.
DAYS
.
between
(
now
,
job
.
getStartTime
());
// 在开始前7天内(包括当天)发送提醒
return
daysUntilStart
<=
7
&&
daysUntilStart
>=
0
;
}
// 定时任务手动触发方法
public
void
runScheduleOperationJobsNow
()
{
scheduleOperationJobs
();
}
//阿里云短信服务
/**
* 发送任务通知短信
*
* @param operationId 操作ID
*/
private
void
sendTaskNotificationSms
(
Integer
operationId
)
{
// 调用 querymessage 方法获取 MessageNeedDataVo 对象
MessageNeedDataVo
messageNeedDataVo
=
operationDoMapper
.
querymessage
(
operationId
);
if
(
messageNeedDataVo
==
null
)
{
logger
.
error
(
"获取消息数据失败: 找不到操作ID={}的记录"
,
operationId
);
return
;
}
List
<
String
>
phones
=
getPhoneByOperation
(
operationId
);
for
(
String
phone
:
phones
){
// 构建短信模板参数
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"stationName"
,
messageNeedDataVo
.
getStationName
());
jsonObject
.
put
(
"device"
,
messageNeedDataVo
.
getRobotName
());
jsonObject
.
put
(
"alert"
,
messageNeedDataVo
.
getOperationType
());
jsonObject
.
put
(
"time"
,
messageNeedDataVo
.
getStartTime
());
aliSmsUtil
.
sendSms
(
phone
,
jsonObject
,
"SMS_481685150"
);
}
}
}
/**
* 获取操作关联的手机号列表
*
* @param operationId 操作ID
* @return 手机号列表
*/
private
List
<
String
>
getPhoneByOperation
(
Integer
operationId
)
{
// 1. 获取操作记录
OperationDoEntity
operation
=
operationDoMapper
.
selectById
(
operationId
);
if
(
operation
==
null
)
{
logger
.
error
(
"获取手机号失败: 找不到操作ID={}的记录"
,
operationId
);
return
Collections
.
emptyList
();
}
// 2. 获取站点相关的所有消息记录(使用selectList代替selectOne)
List
<
MessageEntity
>
messages
=
messageMapper
.
selectList
(
new
LambdaQueryWrapper
<
MessageEntity
>()
.
eq
(
MessageEntity:
:
getStationId
,
operation
.
getStationId
())
);
if
(
messages
==
null
||
messages
.
isEmpty
())
{
logger
.
error
(
"获取手机号失败: 找不到站点ID={}的消息记录"
,
operation
.
getStationId
());
return
Collections
.
emptyList
();
}
// 3. 收集所有有效的workerId
Set
<
Integer
>
workerIds
=
new
HashSet
<>();
for
(
MessageEntity
message
:
messages
)
{
if
(
message
.
getOperationMessage
()
!=
null
&&
!
message
.
getOperationMessage
().
isEmpty
())
{
try
{
Arrays
.
stream
(
message
.
getOperationMessage
().
split
(
","
))
.
map
(
String:
:
trim
)
.
filter
(
s
->
!
s
.
isEmpty
())
.
map
(
Integer:
:
parseInt
)
.
forEach
(
workerIds:
:
add
);
}
catch
(
NumberFormatException
e
)
{
logger
.
error
(
"解析操作消息失败: {}"
,
message
.
getOperationMessage
(),
e
);
continue
;
}
}
}
if
(
workerIds
.
isEmpty
())
{
logger
.
error
(
"获取手机号失败: 站点ID={}的消息记录中没有有效的workerId"
,
operation
.
getStationId
());
return
Collections
.
emptyList
();
}
// 4. 获取所有worker的电话号码
List
<
WorkerEntity
>
workers
=
workerMapper
.
selectList
(
new
LambdaQueryWrapper
<
WorkerEntity
>()
.
in
(
WorkerEntity:
:
getId
,
workerIds
)
.
isNotNull
(
WorkerEntity:
:
getPhoneNumber
)
);
// 5. 返回去重后的电话号码列表
return
workers
.
stream
()
.
map
(
WorkerEntity:
:
getPhoneNumber
)
.
filter
(
phone
->
phone
!=
null
&&
!
phone
.
isEmpty
())
.
distinct
()
.
collect
(
Collectors
.
toList
());
}
}
\ No newline at end of file
src/main/java/com/example/operation_platform/task/RunLogTask.java
0 → 100644
View file @
7b817d2a
package
com.example.operation_platform.task
;
public
class
RunLogTask
{
// public static void main(String[] args) {
// while (true) {
// try {
// checkStatusAndSendSMS();
// Thread.sleep(60000); // 每分钟检查一次
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
}
src/main/java/com/example/operation_platform/util/OperationUtil.java
0 → 100644
View file @
7b817d2a
package
com.example.operation_platform.util
;
public
class
OperationUtil
{
}
src/main/resources/application.yml
View file @
7b817d2a
...
...
@@ -30,4 +30,10 @@ mybatis-plus:
map-underscore-to-camel-case
:
true
logging
:
level
:
com.example.operation_platform.mapper
:
debug
# 这里的包路径需要指向你的 MyBatis Plus mapper 接口所在的包
\ No newline at end of file
com.example.operation_platform.mapper
:
debug
# 这里的包路径需要指向你的 MyBatis Plus mapper 接口所在的包
ruzhou
:
ali
:
sms
:
accessKeyId
:
LTAI5t9ynUemSWiT8rTgg1uh
accessKeySecret
:
biWNg6CI2EEwhXfsTmj4NZuxaWLnaf
signName
:
南京如昼信息科技
\ No newline at end of file
src/main/resources/mapper/GuideMapper.xml
View file @
7b817d2a
...
...
@@ -14,11 +14,16 @@
</select>
<select
id =
"queryguidelist"
resultType=
"com.example.operation_platform.model.vo.GuideVO"
>
select
tg.id id,
tg.name name,
tg.content content,
tg.img img
tg.robotcontent robotcontent,
tg.stationcontent stationcontent
from
tb_guide tg
</select>
<update
id=
"updateall"
parameterType=
"com.example.operation_platform.model.vo.GuideVO"
>
update tb_guide
set robotcontent = #{robotcontent},
stationcontent = #{stationcontent}
where id = 1
</update>
</mapper>
src/main/resources/mapper/MessageMapper.xml
View file @
7b817d2a
...
...
@@ -4,26 +4,26 @@
<select
id=
"queryrobotList"
resultType=
"com.example.operation_platform.model.vo.MessageVO"
>
select
tm.id id,
tor.name stationName,
b
r.name robotName,
tw.worker_name peopleName
,
tm.phone_number phoneNumber
,
tor.address address,
tm.station_id stationId,
tm.robot_id robotId
tm.id id,
tor.name stationName,
COALESCE(br.name, d
r.name
)
robotName,
tor.contact_phone phoneNumber
,
tor.contact peopleName
,
tor.address address,
tm.station_id stationId,
tm.robot_id robotId
,
tm.drone_id droneId
from
tb_message tm
tb_message tm
left join
bs_station tor
on tor.id = tm.station_id
bs_station tor
on tor.id = tm.station_id
left join
bs_robot br
on br.id = tm.robot_id
bs_robot br
on br.id = tm.robot_id
left join
tb_worker tw
on
tw
.id = tm.
peopl
e_id
uav_drone dr
on
dr
.id = tm.
dron
e_id
<where>
<if
test=
"robotName != null and robotName != ''"
>
and br.name like concat('%',#{robotName},'%')
...
...
@@ -46,17 +46,17 @@
<select
id=
"queryPeople"
resultType=
"com.example.operation_platform.model.vo.PeopleMessageVO"
>
SELECT
tm.id id,
t
w.worker_name peopleName
,
t
or.contact_phone phoneNumber
,
tp.worker_name softwareWorker,
ta.worker_name hardwareWorker,
tq.worker_name operationWorker,
t
w.phone_number
peopleN
umber
,
t
or.contact
peopleN
ame
,
tp.phone_number softwareNumber,
ta.phone_number hardwareNumber,
tq.phone_number operationNumber
FROM
tb_message tm
LEFT JOIN
tb_worker tw ON tm.people
_id = t
w
.id
LEFT JOIN
bs_station tor ON tm.station
_id = t
or
.id
LEFT JOIN tb_worker tp ON tm.software_worker = tp.id
LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id
LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id
...
...
@@ -64,9 +64,6 @@
<if
test=
"stationId != null and stationId != ''"
>
tm.station_id = #{stationId}
</if>
<if
test=
"robotId != null and robotId != ''"
>
tm.robot_id = #{robotId}
</if>
</select>
<select
id=
"querymessageList"
resultType=
"com.example.operation_platform.model.vo.PeopleMessageVO"
>
SELECT
...
...
@@ -82,7 +79,6 @@
tq.phone_number operationNumber
FROM
tb_message tm
LEFT JOIN tb_worker tw ON tm.people_id = tw.id
LEFT JOIN tb_worker tp ON tm.software_worker = tp.id
LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id
LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id
...
...
@@ -101,5 +97,73 @@
<!-- OR m.hardware_worker = #{worker_id}-->
<!-- OR m.operation_worker = #{worker_id};-->
<!-- </select>-->
<select
id=
"querypeopleId"
resultType=
"com.example.operation_platform.model.vo.MessageVO"
>
SELECT
tm.id,
sw.worker_name AS softwareWorker,
hw.worker_name AS hardwareWorker,
ow.worker_name AS operationWorker,
tm.warn_message AS warnMessage,
tm.operation_message AS operationMessage,
tm.software_worker AS softwareWorkerId,
tm.hardware_worker AS hardwareWorkerId,
tm.operation_worker AS operationWorkerId,
GROUP_CONCAT(DISTINCT warn_worker.worker_name SEPARATOR ', ') AS warnMessageNames,
GROUP_CONCAT(DISTINCT operation_worker.worker_name SEPARATOR ', ') AS operationMessageNames
FROM
tb_message tm
LEFT JOIN tb_worker sw ON sw.id = tm.software_worker
LEFT JOIN tb_worker hw ON hw.id = tm.hardware_worker
LEFT JOIN tb_worker ow ON ow.id = tm.operation_worker
LEFT JOIN (
SELECT
tm.id,
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(tm.warn_message, ',', numbers.n), ',', -1)) AS warn_id
FROM
tb_message tm
CROSS JOIN (
SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) numbers
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
AND numbers.n
<
= (LENGTH(tm.warn_message) - LENGTH(REPLACE(tm.warn_message, ',', '')) + 1)
) AS split_warn ON split_warn.id = tm.id
LEFT JOIN tb_worker warn_worker ON warn_worker.id = split_warn.warn_id
LEFT JOIN (
SELECT
tm.id,
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(tm.operation_message, ',', numbers.n), ',', -1)) AS operation_id
FROM
tb_message tm
CROSS JOIN (
SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) numbers
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
AND numbers.n
<
= (LENGTH(tm.operation_message) - LENGTH(REPLACE(tm.operation_message, ',', '')) + 1)
) AS split_operation ON split_operation.id = tm.id
LEFT JOIN tb_worker operation_worker ON operation_worker.id = split_operation.operation_id
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
GROUP BY
tm.id, sw.worker_name, hw.worker_name, ow.worker_name, tm.warn_message, tm.operation_message
</select>
<select
id=
"queryrobotBystationId"
resultType=
"com.example.operation_platform.model.vo.RobotAndDrone"
>
select
COALESCE(br.name, ud.name) robotName,
tm.robot_id robotId,
tm.drone_id droneId
from tb_message tm
left join
bs_robot br on tm.robot_id = br.id
left join
bs_station bs on tm.station_id = bs.id
left join
uav_drone ud on tm.drone_id = ud.id
where
tm.station_id = #{stationId}
</select>
</mapper>
\ No newline at end of file
src/main/resources/mapper/OPerationItemMapper.xml
View file @
7b817d2a
...
...
@@ -11,6 +11,22 @@
tb_operation_item tw
</select>
<select
id=
"queryByIdList"
resultType=
"com.example.operation_platform.model.entity.OperationItem"
>
select
tw.id id,
tw.operation_item operationItem,
tw.operation_guide operationGuide
from
tb_operation_item tw
<where>
<if
test=
"itemIdList != null and itemIdList.size() > 0"
>
tw.id in
<foreach
collection=
"itemIdList"
item=
"item"
open=
"("
separator=
","
close=
")"
>
#{itemIdList}
</foreach>
</if>
</where>
</select>
</mapper>
Prev
1
2
3
Next
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