Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1cfbc28d
authored
Jul 14, 2023
by
wangli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
1 parent
fabbb478
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
126 deletions
project-order/src/main/java/com/dituhui/pea/order/service/impl/OrderAssignImpl.java
project-order/src/main/java/com/dituhui/pea/order/service/impl/OrderAssignImpl.java
View file @
1cfbc28
package
com
.
dituhui
.
pea
.
order
.
service
.
impl
;
package
com
.
dituhui
.
pea
.
order
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.dituhui.pea.common.BusinessException
;
import
com.dituhui.pea.common.BusinessException
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.order.common.OrderAssignCheck
;
import
com.dituhui.pea.order.common.OrderAssignCheck
;
import
com.dituhui.pea.order.common.TimeUtils
;
import
com.dituhui.pea.order.common.TimeUtils
;
import
com.dituhui.pea.order.dao.EngineerInfoMPDao
;
import
com.dituhui.pea.order.dao.*
;
import
com.dituhui.pea.order.dao.OrderAppointmentMPDao
;
import
com.dituhui.pea.order.dao.OrderEventMPDao
;
import
com.dituhui.pea.order.dao.OrderRequestMPDao
;
import
com.dituhui.pea.order.dto.LabelValueDTO
;
import
com.dituhui.pea.order.dto.LabelValueDTO
;
import
com.dituhui.pea.order.dto.OrderAssignRecommendResp
;
import
com.dituhui.pea.order.dto.OrderAssignRecommendResp
;
import
com.dituhui.pea.order.dto.TimeLineDTO
;
import
com.dituhui.pea.order.dto.TimeLineDTO
;
import
com.dituhui.pea.order.entity.EngineerInfo
;
import
com.dituhui.pea.order.entity.*
;
import
com.dituhui.pea.order.entity.OrderAppointment
;
import
com.dituhui.pea.order.entity.OrderEvent
;
import
com.dituhui.pea.order.entity.OrderRequest
;
import
com.dituhui.pea.order.service.CommonService
;
import
com.dituhui.pea.order.service.CommonService
;
import
com.dituhui.pea.order.service.OrderAssign
;
import
com.dituhui.pea.order.service.OrderAssign
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -27,10 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -27,10 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -55,6 +47,18 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -55,6 +47,18 @@ public class OrderAssignImpl implements OrderAssign {
@Autowired
@Autowired
private
OrderAssignCheck
orderAssignCheck
;
private
OrderAssignCheck
orderAssignCheck
;
@Autowired
private
OrgTeamMPDao
orgTeamMPDao
;
@Autowired
private
OrgTeamEngineerMPDao
orgTeamEngineerMPDao
;
@Autowired
private
SkillInfoMPDao
skillInfoMPDao
;
@Autowired
private
EngineerSkillGroupMPDao
engineerSkillGroupMPDao
;
@Transactional
@Transactional
@Override
@Override
public
Result
<?>
getOrderAssignRecommendEngineers
(
String
orderId
,
String
key
,
String
distance
,
String
recommend
)
{
public
Result
<?>
getOrderAssignRecommendEngineers
(
String
orderId
,
String
key
,
String
distance
,
String
recommend
)
{
...
@@ -67,18 +71,21 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -67,18 +71,21 @@ public class OrderAssignImpl implements OrderAssign {
String
date
=
TimeUtils
.
timestamp2DateTime
(
order
.
getExpectTimeBegin
(),
TimeUtils
.
DATE_GAP_FORMAT
);
String
date
=
TimeUtils
.
timestamp2DateTime
(
order
.
getExpectTimeBegin
(),
TimeUtils
.
DATE_GAP_FORMAT
);
// 获取group内的小组成员
// 获取group内的小组成员
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByGroupId
(
order
.
getOrgGroupId
());
List
<
String
>
engineerCodes
=
this
.
searchEngineerCodes
(
order
,
distance
,
key
,
recommend
);
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByEngineerCodes
(
engineerCodes
);
List
<
OrderAssignRecommendResp
.
Engineer
>
items
=
new
ArrayList
<>();
List
<
OrderAssignRecommendResp
.
Engineer
>
items
=
new
ArrayList
<>();
OrderRecommend
or
=
new
OrderRecommend
();
for
(
EngineerInfo
engineer
:
engineers
)
{
for
(
EngineerInfo
engineer
:
engineers
)
{
List
<
OrderAppointment
>
orderAppointments
=
orderAppointmentMPDao
.
selectByEngineerCodeAndDt
(
engineer
.
getEngineerCode
(),
order
.
getDt
());
RecommendResult
rr
=
or
.
recommend
(
order
,
orderAppointments
);
OrderAssignCheck
.
Result
result
=
orderAssignCheck
.
orderAssignCheck
(
orderId
,
engineer
.
getEngineerCode
());
if
(
rr
.
getIndex
()
==
-
1
)
{
log
.
info
(
"指派检查结果:{}"
,
result
);
if
(!
result
.
getCanAssign
())
{
continue
;
continue
;
}
}
List
<
OrderAppointment
>
orderAppointments
=
orderAppointmentMPDao
.
selectByEngineerCodeAndDt
(
engineer
.
getEngineerCode
(),
order
.
getDt
());
// 获取订单tips
// 获取订单tips
HashMap
<
String
,
List
<
LabelValueDTO
>>
orderTips
=
new
HashMap
<>();
HashMap
<
String
,
List
<
LabelValueDTO
>>
orderTips
=
new
HashMap
<>();
List
<
String
>
orderIds
=
orderAppointments
.
stream
().
map
(
OrderAppointment:
:
getOrderId
).
collect
(
Collectors
.
toList
());
List
<
String
>
orderIds
=
orderAppointments
.
stream
().
map
(
OrderAppointment:
:
getOrderId
).
collect
(
Collectors
.
toList
());
...
@@ -90,17 +97,19 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -90,17 +97,19 @@ public class OrderAssignImpl implements OrderAssign {
OrderAssignRecommendResp
.
Engineer
item
=
new
OrderAssignRecommendResp
.
Engineer
();
OrderAssignRecommendResp
.
Engineer
item
=
new
OrderAssignRecommendResp
.
Engineer
();
OrderAssignRecommendResp
.
InsertInfo
insertInfo
=
new
OrderAssignRecommendResp
.
InsertInfo
();
OrderAssignRecommendResp
.
InsertInfo
insertInfo
=
new
OrderAssignRecommendResp
.
InsertInfo
();
insertInfo
.
setNumber
(
String
.
format
(
"%d/%d"
,
r
r
.
index
+
1
,
orderAppointments
.
size
()
+
1
));
insertInfo
.
setNumber
(
String
.
format
(
"%d/%d"
,
r
esult
.
getIndex
()
,
orderAppointments
.
size
()
+
1
));
insertInfo
.
setTimeDesc
(
"+30分钟"
);
insertInfo
.
setTimeDesc
(
String
.
format
(
"+{%s}分钟"
,
result
.
getMinuteAddition
())
);
insertInfo
.
setDistanceDesc
(
"+4公里"
);
insertInfo
.
setDistanceDesc
(
String
.
format
(
"+{%s}公里"
,
result
.
getDistanceAddition
()
/
1000
)
);
item
.
setEngineerCode
(
engineer
.
getEngineerCode
());
item
.
setEngineerCode
(
engineer
.
getEngineerCode
());
item
.
setEngineerName
(
engineer
.
getName
());
item
.
setEngineerName
(
engineer
.
getName
());
item
.
setLocation
(
"120.753872,31.312792"
);
item
.
setLocation
(
String
.
format
(
"%s,%s"
,
order
.
getX
(),
order
.
getY
())
);
item
.
setInsertInfo
(
insertInfo
);
item
.
setInsertInfo
(
insertInfo
);
item
.
setDistanceDesc
(
"15.5公里"
);
item
.
setDistanceDesc
(
""
);
item
.
setTimeDesc
(
"520分钟"
);
item
.
setTimeDesc
(
""
);
item
.
setDesc
(
String
.
format
(
"将被插入在第%d单,受此影响原第%d单变化第%d单,第3单将增加5公里路程,比预计晚到30分钟,建议调整;"
,
rr
.
index
+
1
,
rr
.
index
+
1
,
rr
.
index
+
2
));
int
index
=
result
.
getIndex
()
+
1
;
item
.
setDesc
(
String
.
format
(
"将被插入在第%d单,受此影响原第%d单变化第%d单,第3单将增加%d公里路程,比预计晚到%d分钟,建议调整;"
,
index
,
index
,
index
+
1
,
result
.
getDistanceAddition
()
/
1000
,
result
.
getMinuteAddition
()));
item
.
setStartTime
(
String
.
format
(
"%s 08:00:00"
,
date
));
item
.
setStartTime
(
String
.
format
(
"%s 08:00:00"
,
date
));
item
.
setEndTime
(
String
.
format
(
"%s 18:00:00"
,
date
));
item
.
setEndTime
(
String
.
format
(
"%s 18:00:00"
,
date
));
item
.
setOrders
(
this
.
packTimelines
(
orderAppointments
,
orderTips
));
item
.
setOrders
(
this
.
packTimelines
(
orderAppointments
,
orderTips
));
...
@@ -126,24 +135,24 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -126,24 +135,24 @@ public class OrderAssignImpl implements OrderAssign {
boolean
record
=
false
;
boolean
record
=
false
;
OrderAppointment
op
=
orderAppointmentMPDao
.
getByOrderIdAndDt
(
orderId
,
order
.
getDt
());
OrderAppointment
op
=
orderAppointmentMPDao
.
getByOrderIdAndDt
(
orderId
,
order
.
getDt
());
if
(
op
!=
null
)
{
if
(
op
!=
null
)
{
record
=
true
;
record
=
true
;
}
}
if
(
op
!=
null
&&
!
order
.
getAppointmentStatus
().
equals
(
"NOT_ASSIGNED"
)
&&
op
.
getEngineerCode
().
equals
(
engineerCode
))
{
if
(
op
!=
null
&&
!
order
.
getAppointmentStatus
().
equals
(
"NOT_ASSIGNED"
)
&&
op
.
getEngineerCode
().
equals
(
engineerCode
))
{
throw
new
BusinessException
(
String
.
format
(
"订单已指派个技术员[%s], 不必重复指派给同一个技术员"
,
engineer
.
getName
()));
throw
new
BusinessException
(
String
.
format
(
"订单已指派个技术员[%s], 不必重复指派给同一个技术员"
,
engineer
.
getName
()));
}
}
OrderAssignCheck
.
Result
result
=
orderAssignCheck
.
orderAssignCheck
(
orderId
,
engineerCode
);
OrderAssignCheck
.
Result
result
=
orderAssignCheck
.
orderAssignCheck
(
orderId
,
engineerCode
);
log
.
info
(
"指派检查结果:{}"
,
result
);
log
.
info
(
"指派检查结果:{}"
,
result
);
if
(!
result
.
getCanAssign
())
{
if
(!
result
.
getCanAssign
())
{
throw
new
BusinessException
(
"指派失败, 未能找到合适的时间段, 请选择其他技术员"
);
throw
new
BusinessException
(
"指派失败, 未能找到合适的时间段, 请选择其他技术员"
);
}
}
Timestamp
expectStartTime
=
Timestamp
.
valueOf
(
result
.
getStart
());
;
Timestamp
expectStartTime
=
Timestamp
.
valueOf
(
result
.
getStart
());
Timestamp
expectEndTime
=
Timestamp
.
valueOf
(
result
.
getEnd
());
Timestamp
expectEndTime
=
Timestamp
.
valueOf
(
result
.
getEnd
());
// 更新或插入指派单
// 更新或插入指派单
if
(!
record
)
{
if
(!
record
)
{
op
=
new
OrderAppointment
();
op
=
new
OrderAppointment
();
}
}
op
.
setOrderId
(
orderId
);
op
.
setOrderId
(
orderId
);
...
@@ -160,7 +169,7 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -160,7 +169,7 @@ public class OrderAssignImpl implements OrderAssign {
op
.
setPreStatus
(
"CONFIRM"
);
op
.
setPreStatus
(
"CONFIRM"
);
op
.
setStatus
(
"ASSIGNED"
);
op
.
setStatus
(
"ASSIGNED"
);
if
(!
record
)
{
if
(!
record
)
{
orderAppointmentMPDao
.
insert
(
op
);
orderAppointmentMPDao
.
insert
(
op
);
}
else
{
}
else
{
orderAppointmentMPDao
.
updateById
(
op
);
orderAppointmentMPDao
.
updateById
(
op
);
...
@@ -174,15 +183,15 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -174,15 +183,15 @@ public class OrderAssignImpl implements OrderAssign {
orderRequestMPDao
.
update
(
null
,
wrapper
);
orderRequestMPDao
.
update
(
null
,
wrapper
);
// 工单变更登记
// 工单变更登记
commonService
.
addOrderEvent
(
orderId
,
""
,
"PEA-WEB"
,
"API"
,
"工单指派"
,
"工单指派"
,
""
);
commonService
.
addOrderEvent
(
orderId
,
""
,
"PEA-WEB"
,
"API"
,
"工单指派"
,
"工单指派"
,
""
);
return
Result
.
success
(
null
);
return
Result
.
success
(
null
);
}
}
@Override
@Override
public
Result
<?>
orderRevokeAssign
(
String
orderId
)
throws
BusinessException
{
public
Result
<?>
orderRevokeAssign
(
String
orderId
)
throws
BusinessException
{
OrderRequest
order
=
orderRequestMPDao
.
getByOrderId
(
orderId
);
OrderRequest
order
=
orderRequestMPDao
.
getByOrderId
(
orderId
);
if
(
order
==
null
){
if
(
order
==
null
)
{
throw
new
BusinessException
(
"订单不存在"
);
throw
new
BusinessException
(
"订单不存在"
);
}
}
...
@@ -214,16 +223,16 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -214,16 +223,16 @@ public class OrderAssignImpl implements OrderAssign {
}
}
@Override
@Override
public
Result
<?>
orderReschedule
(
String
orderId
,
LocalDateTime
expectBegin
,
LocalDateTime
expectEnd
,
String
expectDesc
)
throws
BusinessException
{
public
Result
<?>
orderReschedule
(
String
orderId
,
LocalDateTime
expectBegin
,
LocalDateTime
expectEnd
,
String
expectDesc
)
throws
BusinessException
{
// 工单改约接口(当前同放回工单池处理)
// 工单改约接口(当前同放回工单池处理)
OrderRequest
order
=
orderRequestMPDao
.
getByOrderId
(
orderId
);
OrderRequest
order
=
orderRequestMPDao
.
getByOrderId
(
orderId
);
if
(
order
==
null
){
if
(
order
==
null
)
{
throw
new
BusinessException
(
"订单不存在"
);
throw
new
BusinessException
(
"订单不存在"
);
}
}
if
(
order
.
getDt
().
isEqual
(
expectBegin
.
toLocalDate
()))
{
if
(
order
.
getDt
().
isEqual
(
expectBegin
.
toLocalDate
()))
{
throw
new
BusinessException
(
"改约日期不应与之前日期相同"
);
throw
new
BusinessException
(
"改约日期不应与之前日期相同"
);
}
}
if
(
LocalDate
.
now
().
isAfter
(
expectBegin
.
toLocalDate
())){
if
(
LocalDate
.
now
().
isAfter
(
expectBegin
.
toLocalDate
()))
{
throw
new
BusinessException
(
"改约日期不能小于今日"
);
throw
new
BusinessException
(
"改约日期不能小于今日"
);
}
}
...
@@ -260,10 +269,91 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -260,10 +269,91 @@ public class OrderAssignImpl implements OrderAssign {
return
Result
.
success
(
null
);
return
Result
.
success
(
null
);
}
}
private
List
<
String
>
searchEngineerCodes
(
Integer
distance
,
String
key
,
String
recommend
){
private
List
<
String
>
searchEngineerCodes
(
OrderRequest
order
,
String
distance
,
String
key
,
String
recommend
)
{
Set
<
String
>
engineerCodes1
=
this
.
searchEngineerByRecommend
(
order
,
recommend
);
if
(
engineerCodes1
.
isEmpty
())
{
log
.
info
(
"recommend:{}筛选条件未找到技术员"
,
recommend
);
return
new
ArrayList
<>();
}
if
(
StringUtils
.
isNotEmpty
(
key
))
{
Set
<
String
>
engineerCodes2
=
this
.
searchEngineerByKey
(
key
);
if
(
engineerCodes2
.
isEmpty
())
{
log
.
info
(
"key:{}筛选条件未找到技术员"
,
key
);
return
new
ArrayList
<>();
}
engineerCodes1
.
retainAll
(
engineerCodes2
);
if
(
engineerCodes1
.
isEmpty
())
{
log
.
info
(
"recommend:{} 与 key:{}筛选条件交集未找到技术员"
,
recommend
,
key
);
return
new
ArrayList
<>();
}
}
// 匹配技能
SkillInfo
skill
=
skillInfoMPDao
.
getByBrandAndTypeAndSkill
(
order
.
getBrand
(),
order
.
getType
(),
order
.
getSkill
());
if
(
skill
==
null
)
{
log
.
info
(
"skill_info表没有匹配到技能配置:{}-{}-{}"
,
order
.
getBrand
(),
order
.
getY
(),
order
.
getSkill
());
return
new
ArrayList
<>();
}
Set
<
String
>
engineerCodes3
=
engineerSkillGroupMPDao
.
selectBySkillGroupCode
(
skill
.
getSkillGroupCode
()).
stream
().
map
(
EngineerSkillGroup:
:
getEngineerCode
).
collect
(
Collectors
.
toSet
());
if
(
engineerCodes3
.
isEmpty
())
{
log
.
info
(
"没有匹配到技能相匹配的技术员:{}-{}-{}"
,
order
.
getBrand
(),
order
.
getType
(),
order
.
getSkill
());
return
new
ArrayList
<>();
}
engineerCodes1
.
retainAll
(
engineerCodes3
);
if
(
engineerCodes1
.
isEmpty
())
{
log
.
info
(
"recommend:{} 与 key:{}筛选条件, 与技术员所需要的技能:{}-{}-{}交集未找到技术员"
,
recommend
,
key
,
order
.
getBrand
(),
order
.
getType
(),
order
.
getSkill
());
return
new
ArrayList
<>();
}
if
(
StringUtils
.
isEmpty
(
distance
))
{
return
new
ArrayList
<>(
engineerCodes1
);
}
//进行距离匹配TODO
return
null
;
return
null
;
}
}
private
Set
<
String
>
searchEngineerByRecommend
(
OrderRequest
order
,
String
recommend
)
{
if
(
StringUtils
.
isNotEmpty
(
recommend
)
&&
recommend
.
equals
(
"team"
))
{
return
orgTeamEngineerMPDao
.
selectByTeamId
(
order
.
getOrgTeamId
()).
stream
().
map
(
OrgTeamEngineer:
:
getEngineerCode
).
collect
(
Collectors
.
toSet
());
}
String
levelType
;
String
levelValue
;
if
(
StringUtils
.
isEmpty
(
recommend
)
||
recommend
.
equals
(
"branch"
))
{
levelType
=
"branch"
;
levelValue
=
order
.
getOrgBranchId
();
}
else
if
(
recommend
.
equals
(
"group"
))
{
levelType
=
"group"
;
levelValue
=
order
.
getOrgGroupId
();
}
else
{
return
new
HashSet
<>();
}
LambdaQueryWrapper
<
OrgTeam
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
eq
(
levelType
.
equals
(
"cluster"
),
OrgTeam:
:
getClusterId
,
levelValue
);
lqw
.
eq
(
levelType
.
equals
(
"branch"
),
OrgTeam:
:
getBranchId
,
levelValue
);
lqw
.
eq
(
levelType
.
equals
(
"group"
),
OrgTeam:
:
getGroupId
,
levelValue
);
lqw
.
eq
(
levelType
.
equals
(
"team"
),
OrgTeam:
:
getTeamId
,
levelValue
);
List
<
String
>
groupIds
=
orgTeamMPDao
.
selectList
(
lqw
).
stream
().
map
(
OrgTeam:
:
getGroupId
).
collect
(
Collectors
.
toList
());
return
engineerInfoMPDao
.
selectByGroupIds
(
groupIds
).
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toSet
());
}
private
Set
<
String
>
searchEngineerByKey
(
String
key
)
{
LambdaQueryWrapper
<
EngineerInfo
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
eq
(
EngineerInfo:
:
getBeanStatus
,
1
);
if
(
StringUtils
.
isNotEmpty
(
key
))
{
lqw
.
and
(
w
->
w
.
like
(
EngineerInfo:
:
getPhone
,
key
)
.
or
()
.
like
(
EngineerInfo:
:
getName
,
key
)
.
or
()
.
like
(
EngineerInfo:
:
getEngineerCode
,
key
)
);
}
return
engineerInfoMPDao
.
selectList
(
lqw
).
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toSet
());
}
private
List
<
TimeLineDTO
>
packTimelines
(
List
<
OrderAppointment
>
orders
,
HashMap
<
String
,
List
<
LabelValueDTO
>>
orderTips
)
{
private
List
<
TimeLineDTO
>
packTimelines
(
List
<
OrderAppointment
>
orders
,
HashMap
<
String
,
List
<
LabelValueDTO
>>
orderTips
)
{
List
<
LabelValueDTO
>
empty
=
new
ArrayList
<>();
List
<
LabelValueDTO
>
empty
=
new
ArrayList
<>();
...
@@ -297,90 +387,4 @@ public class OrderAssignImpl implements OrderAssign {
...
@@ -297,90 +387,4 @@ public class OrderAssignImpl implements OrderAssign {
items
.
add
(
new
LabelValueDTO
(
"标签"
,
order
.
getTags
()));
items
.
add
(
new
LabelValueDTO
(
"标签"
,
order
.
getTags
()));
return
items
;
return
items
;
}
}
}
@Data
class
RecommendResult
{
int
index
;
LineSegment
seg
;
}
class
Recommend
{
public
RecommendResult
recommend
(
List
<
LineSegment
>
used
,
Line
task
)
{
used
.
sort
(
Comparator
.
comparingInt
(
a
->
a
.
start
));
String
taskId
=
task
.
id
;
int
taskLength
=
task
.
length
;
boolean
scheduled
=
false
;
int
startRange
=
480
;
int
endRange
=
1440
;
RecommendResult
result
=
new
RecommendResult
();
if
(!
scheduled
)
{
for
(
int
i
=
0
;
i
<=
used
.
size
();
i
++)
{
int
start
;
if
(
i
==
0
)
{
start
=
startRange
;
}
else
{
start
=
used
.
get
(
i
-
1
).
end
;
}
int
end
;
if
(
i
==
used
.
size
()
||
used
.
get
(
i
).
start
>
endRange
)
{
end
=
endRange
;
}
else
{
end
=
used
.
get
(
i
).
start
;
}
if
(
end
-
start
>=
taskLength
)
{
int
taskStart
=
start
;
int
taskEnd
=
start
+
taskLength
;
LineSegment
s
=
new
LineSegment
(
taskId
,
taskStart
,
taskEnd
);
result
.
setIndex
(
i
);
result
.
setSeg
(
s
);
return
result
;
}
}
}
result
.
setIndex
(-
1
);
result
.
setSeg
(
null
);
return
result
;
}
}
class
OrderRecommend
{
public
RecommendResult
recommend
(
OrderRequest
orderRequest
,
List
<
OrderAppointment
>
orderAppointments
)
{
List
<
LineSegment
>
used
=
new
ArrayList
<>();
for
(
OrderAppointment
o
:
orderAppointments
)
{
LineSegment
s
=
new
LineSegment
(
o
.
getOrderId
(),
this
.
Timestamp2LinePoint
(
o
.
getExpectStartTime
()),
this
.
Timestamp2LinePoint
(
o
.
getExpectEndTime
()));
used
.
add
(
s
);
}
Line
task
=
new
Line
(
orderRequest
.
getOrderId
(),
30
);
Recommend
r
=
new
Recommend
();
return
r
.
recommend
(
used
,
task
);
}
public
int
Timestamp2LinePoint
(
Timestamp
t
)
{
LocalDateTime
datetime
=
t
.
toLocalDateTime
();
return
datetime
.
getHour
()
*
60
+
datetime
.
getMinute
();
}
public
Timestamp
linePoint2Timestamp
(
int
x
,
String
date
)
{
int
base
=
60
;
int
hour
=
x
/
base
;
int
minute
=
x
%
base
;
String
datetime
=
String
.
format
(
"%s %d:%d:00"
,
date
,
hour
,
minute
);
return
Timestamp
.
valueOf
(
datetime
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment