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 8a458707
authored
Jul 07, 2023
by
王力
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_engineer_filter' into 'develop'
修改 See merge request !160
2 parents
81c0cfaf
a200436d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
546 additions
and
515 deletions
project-order/src/main/java/com/dituhui/pea/order/controller/EngineerController.java
project-order/src/main/java/com/dituhui/pea/order/service/EngineerService.java
project-order/src/main/java/com/dituhui/pea/order/service/impl/EngineerServiceImpl.java
project-order/src/main/java/com/dituhui/pea/order/controller/EngineerController.java
View file @
8a45870
...
...
@@ -20,11 +20,16 @@ public class EngineerController {
private
EngineerService
engineerService
;
@GetMapping
(
"/engineer/info/list"
)
public
Result
<?>
getEngineerInfoList
(
@RequestParam
long
page
,
@RequestParam
long
size
)
{
public
Result
<?>
getEngineerInfoList
(
@RequestParam
String
levelType
,
@RequestParam
String
levelValue
,
@RequestParam
long
page
,
@RequestParam
long
size
,
@RequestParam
(
required
=
false
)
String
kind
,
@RequestParam
(
required
=
false
)
String
key
)
{
// 获取工程师基础信息列表
Result
<?>
res
=
null
;
try
{
res
=
engineerService
.
getEngineerInfoList
(
page
,
size
);
res
=
engineerService
.
getEngineerInfoList
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
...
...
@@ -44,11 +49,16 @@ public class EngineerController {
}
@GetMapping
(
"/engineer/skill/list"
)
public
Result
<?>
getEngineerSkillList
(
@RequestParam
long
page
,
@RequestParam
long
size
)
{
public
Result
<?>
getEngineerSkillList
(
@RequestParam
String
levelType
,
@RequestParam
String
levelValue
,
@RequestParam
long
page
,
@RequestParam
long
size
,
@RequestParam
(
required
=
false
)
String
kind
,
@RequestParam
(
required
=
false
)
String
key
)
{
// 获取工程师技能信息列表
Result
<?>
res
=
null
;
try
{
res
=
engineerService
.
getEngineerSkillList
(
page
,
size
);
res
=
engineerService
.
getEngineerSkillList
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
...
...
@@ -79,11 +89,16 @@ public class EngineerController {
}
@GetMapping
(
"/engineer/business/list"
)
public
Result
<?>
getEngineerBusinessList
(
@RequestParam
long
page
,
@RequestParam
long
size
)
{
public
Result
<?>
getEngineerBusinessList
(
@RequestParam
String
levelType
,
@RequestParam
String
levelValue
,
@RequestParam
long
page
,
@RequestParam
long
size
,
@RequestParam
(
required
=
false
)
String
kind
,
@RequestParam
(
required
=
false
)
String
key
)
{
// 技术员业务属性配置列表
Result
<?>
res
=
null
;
try
{
res
=
engineerService
.
getEngineerBusinessList
(
page
,
size
);
res
=
engineerService
.
getEngineerBusinessList
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
...
...
project-order/src/main/java/com/dituhui/pea/order/service/EngineerService.java
View file @
8a45870
...
...
@@ -8,16 +8,16 @@ import java.util.List;
public
interface
EngineerService
{
// 获取公司列表
Result
<?>
getEngineerInfoList
(
long
page
,
long
size
);
Result
<?>
getEngineerInfoList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
);
Result
<?>
getEngineerInfoDetail
(
String
engineerCode
);
// 获取工程师技能列表
Result
<?>
getEngineerSkillList
(
long
page
,
long
size
);
Result
<?>
getEngineerSkillList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
);
Result
<?>
getEngineerSkillDetail
(
String
engineerCode
);
Result
<?>
engineerSkillUpdate
(
String
engineerCode
,
List
<
String
>
categoryIds
);
// 工程师业务属性配置列表
Result
<?>
getEngineerBusinessList
(
long
page
,
long
size
);
Result
<?>
getEngineerBusinessList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
);
Result
<?>
getEngineerBusinessDetail
(
String
engineerCode
);
// 技术员业务属性配置修改
...
...
project-order/src/main/java/com/dituhui/pea/order/service/impl/EngineerServiceImpl.java
View file @
8a45870
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.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.dituhui.pea.common.BusinessException
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.order.common.TimeUtils
;
...
...
@@ -7,10 +11,6 @@ import com.dituhui.pea.order.dao.*;
import
com.dituhui.pea.order.dto.*
;
import
com.dituhui.pea.order.entity.*
;
import
com.dituhui.pea.order.service.EngineerService
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -25,506 +25,522 @@ import java.util.stream.Collectors;
@Service
public
class
EngineerServiceImpl
implements
EngineerService
{
@Autowired
private
EngineerInfoMPDao
engineerInfoMPDao
;
@Autowired
private
EngineerSkillMPDao
engineerSkillMPDao
;
@Autowired
private
OrgGroupMPDao
orgGroupMPDao
;
@Autowired
private
EngineerBusinessMPDao
engineerBusinessDao
;
@Autowired
private
OrderRequestDao
orderRequestDao
;
@Autowired
private
OrderAppointmentDao
orderAppointmentDao
;
@Autowired
private
EngineerInfoDao
engineerInfoDao
;
@Autowired
private
CapacityEngineerStatDao
capacityEngineerStatDao
;
@Transactional
@Override
public
Result
<?>
getEngineerInfoList
(
long
page
,
long
size
)
{
// 查询工程师信息
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
page
,
size
);
List
<
EngineerInfo
>
records
=
pg
.
getRecords
();
// 获取groupIds
List
<
String
>
groupIds
=
records
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
// 获取Map<groupId, groupName>
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
// 设置返回值
EngineerInfoListResp
res
=
new
EngineerInfoListResp
();
res
.
setContent
(
this
.
packEngineerInfos
(
records
,
groupNames
));
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerInfoDetail
(
String
engineerCode
)
throws
BusinessException
{
// 获取技术员基础信息详情
// 获取技术员列表
List
<
EngineerInfo
>
records
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
records
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<
String
>
groupIds
=
records
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
List
<
EngineerInfoListResp
.
EngineerInfo
>
items
=
this
.
packEngineerInfos
(
records
,
groupNames
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
getEngineerSkillList
(
long
page
,
long
size
)
{
// 获取技术员技能列表
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
page
,
size
);
List
<
EngineerInfo
>
engineers
=
pg
.
getRecords
();
EngineerSkillListResp
res
=
new
EngineerSkillListResp
();
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
res
.
setContent
(
this
.
packEngineerSkills
(
engineers
));
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerSkillDetail
(
String
engineerCode
)
throws
BusinessException
{
// 获取工程师技能详情
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
engineers
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<
EngineerSkillListResp
.
EngineerSkill
>
items
=
this
.
packEngineerSkills
(
engineers
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
engineerSkillUpdate
(
String
engineerCode
,
List
<
String
>
categoryIds
)
{
// 更新技术员技能
// 先将所有技能更新为0-不可用状态
LambdaUpdateWrapper
<
EngineerSkill
>
wrapper
=
new
LambdaUpdateWrapper
<>();
wrapper
.
eq
(
EngineerSkill:
:
getEngineerCode
,
engineerCode
).
set
(
EngineerSkill:
:
getStatus
,
0
);
engineerSkillMPDao
.
update
(
null
,
wrapper
);
if
(
categoryIds
.
isEmpty
())
{
return
null
;
}
// 更新categoryIds状态为1
wrapper
.
eq
(
EngineerSkill:
:
getEngineerCode
,
engineerCode
);
wrapper
.
in
(
EngineerSkill:
:
getCategoryId
,
categoryIds
);
wrapper
.
set
(
EngineerSkill:
:
getStatus
,
1
);
int
n
=
engineerSkillMPDao
.
update
(
null
,
wrapper
);
if
(
categoryIds
.
size
()
==
n
)
{
// 更新记录条数等于提交记录条数
return
null
;
}
// 可能存在engineerSkill表不存在的记录,需要补充录入
List
<
Integer
>
statuses
=
new
ArrayList
<
Integer
>(
Arrays
.
asList
(
1
,
0
));
List
<
String
>
engineerCodes
=
new
ArrayList
<>(
Collections
.
singletonList
(
engineerCode
));
HashMap
<
String
,
List
<
String
>>
engineerSkills
=
this
.
queryEngineerSkills
(
engineerCodes
,
statuses
);
Set
<
String
>
sInput
=
new
HashSet
<>(
categoryIds
);
Set
<
String
>
sDB
=
new
HashSet
<>(
engineerSkills
.
get
(
engineerCode
));
sInput
.
removeAll
(
sDB
);
for
(
String
categoryId
:
sInput
)
{
EngineerSkill
e
=
new
EngineerSkill
();
e
.
setEngineerCode
(
engineerCode
);
e
.
setCategoryId
(
categoryId
);
e
.
setStatus
(
1
);
engineerSkillMPDao
.
insert
(
e
);
}
return
null
;
}
@Transactional
@Override
public
Result
<?>
getEngineerBusinessList
(
long
page
,
long
size
)
{
// 技术员业务属性配置列表
// 查询技术员列表
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
page
,
size
);
List
<
EngineerInfo
>
engineers
=
pg
.
getRecords
();
// 查询技术员业务属性
EngineerBusinessListResp
res
=
new
EngineerBusinessListResp
();
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
res
.
setContent
(
this
.
packEngineerBusinesses
(
engineers
));
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerBusinessDetail
(
String
engineerCode
)
{
// 获取技术员业务熟悉详情
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
engineers
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<?>
items
=
this
.
packEngineerBusinesses
(
engineers
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
engineerBusinessUpdate
(
String
engineerCode
,
Integer
maxNum
,
Integer
maxMinute
,
String
departure
,
String
priority
)
{
// 技术员业务属性配置修改
LambdaUpdateWrapper
<
EngineerBusiness
>
wrapper
=
new
LambdaUpdateWrapper
<>();
wrapper
.
eq
(
EngineerBusiness:
:
getEngineerCode
,
engineerCode
);
wrapper
.
set
(
maxNum
>=
0
,
EngineerBusiness:
:
getMaxNum
,
maxNum
);
wrapper
.
set
(
maxMinute
>=
0
,
EngineerBusiness:
:
getMaxMinute
,
maxMinute
);
Integer
dep
=
(
departure
.
equals
(
"配件仓"
))
?
1
:
2
;
wrapper
.
set
(
EngineerBusiness:
:
getDeparture
,
dep
);
int
pri
;
if
(
priority
.
equals
(
"高"
))
{
pri
=
3
;
}
else
if
(
priority
.
equals
(
"中"
))
{
pri
=
2
;
}
else
{
pri
=
1
;
}
wrapper
.
set
(
EngineerBusiness:
:
getPriority
,
pri
);
// 更新字段
engineerBusinessDao
.
update
(
null
,
wrapper
);
return
Result
.
success
(
null
);
}
private
IPage
<
EngineerInfo
>
queryEngineerInfoIPage
(
long
page
,
long
size
)
{
// 分页查询工程师基础信息
LambdaQueryWrapper
<
EngineerInfo
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
orderByAsc
(
EngineerInfo:
:
getGroupId
);
lqw
.
orderByAsc
(
EngineerInfo:
:
getEngineerCode
);
IPage
<
EngineerInfo
>
pg
=
new
Page
(
page
,
size
);
engineerInfoMPDao
.
selectPage
(
pg
,
lqw
);
return
pg
;
}
private
HashMap
<
String
,
String
>
queryGroupNames
(
List
<
String
>
groupIds
)
{
//查询小组名称映射关系
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
if
(
groupIds
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
OrgGroup
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
select
(
OrgGroup:
:
getGroupId
,
OrgGroup:
:
getGroupName
);
lqw
.
in
(
OrgGroup:
:
getGroupId
,
groupIds
);
List
<
OrgGroup
>
groups
=
orgGroupMPDao
.
selectList
(
lqw
);
for
(
OrgGroup
g
:
groups
)
{
map
.
put
(
g
.
getGroupId
(),
g
.
getGroupName
());
}
return
map
;
}
private
HashMap
<
String
,
List
<
String
>>
queryEngineerSkills
(
List
<
String
>
engineerCodes
,
List
<
Integer
>
statuses
)
{
// 获取engineerCode对应的技能表, HashMap<engineerCode, List<skillId>>
HashMap
<
String
,
List
<
String
>>
map
=
new
HashMap
<>();
if
(
engineerCodes
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
EngineerSkill
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
in
(
EngineerSkill:
:
getEngineerCode
,
engineerCodes
);
lqw
.
in
(
EngineerSkill:
:
getStatus
,
statuses
);
List
<
EngineerSkill
>
records
=
engineerSkillMPDao
.
selectList
(
lqw
);
Comparator
<
EngineerSkill
>
ec
=
Comparator
.
comparing
(
EngineerSkill:
:
getEngineerCode
,
String
.
CASE_INSENSITIVE_ORDER
);
List
<
EngineerSkill
>
results
=
records
.
stream
().
sorted
(
ec
).
collect
(
Collectors
.
toList
());
// 根据engineerCode分组
Map
<
String
,
List
<
EngineerSkill
>>
g
=
results
.
stream
().
collect
(
Collectors
.
groupingBy
(
EngineerSkill:
:
getEngineerCode
));
for
(
String
engineerCode
:
g
.
keySet
())
{
// 技术员技能ID列表
List
<
String
>
skillIds
=
g
.
get
(
engineerCode
).
stream
().
map
(
EngineerSkill:
:
getCategoryId
).
collect
(
Collectors
.
toList
());
map
.
put
(
engineerCode
,
skillIds
);
}
return
map
;
}
private
HashMap
<
String
,
EngineerBusiness
>
queryEngineerBusiness
(
List
<
String
>
engineerCodes
)
{
HashMap
<
String
,
EngineerBusiness
>
map
=
new
HashMap
<>();
if
(
engineerCodes
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
EngineerBusiness
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
in
(
EngineerBusiness:
:
getEngineerCode
,
engineerCodes
);
List
<
EngineerBusiness
>
records
=
engineerBusinessDao
.
selectList
(
lqw
);
for
(
EngineerBusiness
r
:
records
)
{
map
.
put
(
r
.
getEngineerCode
(),
r
);
}
return
map
;
}
private
List
<
EngineerInfoListResp
.
EngineerInfo
>
packEngineerInfos
(
List
<
EngineerInfo
>
engineers
,
HashMap
<
String
,
String
>
groups
)
{
String
groupName
,
age
,
kind
;
List
<
EngineerInfoListResp
.
EngineerInfo
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerInfoListResp
.
EngineerInfo
item
=
new
EngineerInfoListResp
.
EngineerInfo
();
item
.
setEngineerCode
(
e
.
getEngineerCode
());
item
.
setNumber
(
e
.
getEngineerCode
());
item
.
setName
(
e
.
getName
());
item
.
setSex
(
e
.
getGender
());
item
.
setPhone
(
e
.
getPhone
());
item
.
setAddress
(
e
.
getAddress
());
item
.
setGrade
(
e
.
getGrade
());
// group name
groupName
=
groups
.
getOrDefault
(
e
.
getGroupId
(),
""
);
item
.
setGroupName
(
groupName
);
// 年龄
age
=
this
.
getEngineerAge
(
e
.
getBirth
());
item
.
setAge
(
age
);
// 工作类型:全职/兼职
kind
=
(
e
.
getKind
()
==
1
)
?
"fullJob"
:
"partJob"
;
item
.
setKind
(
kind
);
if
(
e
.
getCredentials
()
!=
null
)
{
item
.
setCredentials
(
Arrays
.
asList
(
e
.
getCredentials
().
split
(
"、"
)));
}
else
{
item
.
setCredentials
(
new
ArrayList
<
String
>());
}
// 标签
List
<
String
>
tags
=
new
ArrayList
<>();
if
(
e
.
getTags
()
!=
null
&&
!
e
.
getTags
().
isEmpty
())
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
e
.
getTags
().
entrySet
())
{
tags
.
add
(
String
.
format
(
"%s+%s"
,
entry
.
getKey
(),
entry
.
getValue
().
toString
()));
}
}
item
.
setTags
(
tags
);
items
.
add
(
item
);
}
return
items
;
}
private
List
<
EngineerSkillListResp
.
EngineerSkill
>
packEngineerSkills
(
List
<
EngineerInfo
>
engineers
)
{
// 获取groupId类表
List
<
String
>
groupIds
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
// 获取技术员code列表
List
<
String
>
engineerCodes
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toList
());
// 获取技术员的可用技能列表
List
<
Integer
>
statuses
=
new
ArrayList
<
Integer
>(
List
.
of
(
1
));
HashMap
<
String
,
List
<
String
>>
engineerSkills
=
this
.
queryEngineerSkills
(
engineerCodes
,
statuses
);
List
<
String
>
emptySkills
=
Collections
.
emptyList
();
List
<
EngineerSkillListResp
.
EngineerSkill
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerSkillListResp
.
EngineerSkill
skill
=
new
EngineerSkillListResp
.
EngineerSkill
();
skill
.
setEngineerCode
(
e
.
getEngineerCode
());
skill
.
setEngineerName
(
e
.
getName
());
skill
.
setGroupName
(
groupNames
.
getOrDefault
(
e
.
getGroupId
(),
""
));
skill
.
setUpdateTime
(
TimeUtils
.
IsoTimestamp2DateTime
(
e
.
getUpdateTime
()));
// 获取一个工程师的技能列表
skill
.
setCategoryIds
(
engineerSkills
.
getOrDefault
(
e
.
getEngineerCode
(),
emptySkills
));
items
.
add
(
skill
);
}
return
items
;
}
private
List
<
EngineerBusinessListResp
.
EngineerBusiness
>
packEngineerBusinesses
(
List
<
EngineerInfo
>
engineers
)
{
// 获取技术员code列表
List
<
String
>
engineerCodes
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toList
());
List
<
String
>
groupIds
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
HashMap
<
String
,
EngineerBusiness
>
buss
=
this
.
queryEngineerBusiness
(
engineerCodes
);
List
<
EngineerBusinessListResp
.
EngineerBusiness
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerBusinessListResp
.
EngineerBusiness
item
=
new
EngineerBusinessListResp
.
EngineerBusiness
();
item
.
setEngineerCode
(
e
.
getEngineerCode
());
item
.
setGroupName
(
groupNames
.
getOrDefault
(
e
.
getGroupId
(),
""
));
item
.
setEngineerName
(
e
.
getName
());
item
.
setKind
((
e
.
getKind
()
==
1
)
?
"fullJob"
:
"partJob"
);
EngineerBusiness
b
=
buss
.
getOrDefault
(
e
.
getEngineerCode
(),
null
);
if
(
b
==
null
)
{
item
.
setAddress
(
""
);
item
.
setLocation
(
""
);
item
.
setDeparture
(
""
);
item
.
setMaxMinute
(
0
);
item
.
setMaxNum
(
0
);
item
.
setPriority
(
"低"
);
}
else
{
item
.
setAddress
(
b
.
getAddress
());
item
.
setLocation
(
String
.
format
(
"%s,%s"
,
b
.
getX
(),
b
.
getY
()));
item
.
setDeparture
((
b
.
getDeparture
()
==
1
)
?
"配件仓"
:
"住址"
);
item
.
setMaxMinute
(
b
.
getMaxMinute
());
item
.
setMaxNum
(
b
.
getMaxNum
());
String
priority
;
if
(
b
.
getPriority
()
==
3
)
{
priority
=
"高"
;
}
else
if
(
b
.
getPriority
()
==
2
)
{
priority
=
"中"
;
}
else
{
priority
=
"低"
;
}
item
.
setPriority
(
priority
);
}
items
.
add
(
item
);
}
return
items
;
}
private
HashMap
<
String
,
Integer
>
getEngineerSkillIds
(
List
<
String
>
skillIds
,
HashMap
<
String
,
Integer
>
engineerSkillIds
)
{
HashMap
<
String
,
Integer
>
map
=
new
HashMap
<>();
for
(
String
skillId
:
skillIds
)
{
map
.
put
(
skillId
,
engineerSkillIds
.
getOrDefault
(
skillId
,
0
));
}
return
map
;
}
private
String
getEngineerAge
(
String
birth
)
{
// 获取工程师年龄
if
(
birth
.
isEmpty
())
{
return
""
;
}
int
age
;
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
try
{
Date
birthDate
=
dateFormat
.
parse
(
birth
);
Calendar
birthCalendar
=
Calendar
.
getInstance
();
birthCalendar
.
setTime
(
birthDate
);
Calendar
nowCalendar
=
Calendar
.
getInstance
();
age
=
nowCalendar
.
get
(
Calendar
.
YEAR
)
-
birthCalendar
.
get
(
Calendar
.
YEAR
);
if
(
nowCalendar
.
get
(
Calendar
.
DAY_OF_YEAR
)
<
birthCalendar
.
get
(
Calendar
.
DAY_OF_YEAR
))
{
age
--;
}
}
catch
(
Exception
e
)
{
return
""
;
}
return
(
age
<=
0
)
?
""
:
Integer
.
toString
(
age
);
}
@Override
public
Result
<?>
getEngineersGanttList
(
EngineersGanttReqDTO
reqDTO
)
{
// 按日期返回技术员们当天的服务甘特图,不需要翻页
log
.
info
(
"getEngineersGanttList: {}"
,
reqDTO
);
List
<
OrderAppointmentEntity
>
orderAppointments
=
orderAppointmentDao
.
findByDateAndEngineerCodeIn
(
reqDTO
.
getDate
(),
reqDTO
.
getEngineerCodes
());
List
<
String
>
orderIds
=
orderAppointments
.
stream
().
map
(
OrderAppointmentEntity:
:
getOrderId
).
collect
(
Collectors
.
toList
());
Map
<
String
,
OrderRequestEntity
>
mapOrderRequest
=
getOrdersByOrderIds
(
orderIds
);
HashMap
<
String
,
List
<
EngineersGanttRespDTO
.
Order
>>
mapEngineers
=
new
HashMap
<>();
for
(
OrderAppointmentEntity
e
:
orderAppointments
)
{
log
.
info
(
"===== order_id: [{}]"
,
e
.
getOrderId
());
EngineersGanttRespDTO
.
Order
order
=
new
EngineersGanttRespDTO
.
Order
();
// todo 需要根据订单时间和状态,采用expectXXXX或者actualXXXX
order
.
setStartTime
(
e
.
getExpectStartTime
()).
setEndTime
(
e
.
getExpectEndTime
());
order
.
setOrderId
(
e
.
getOrderId
()).
setPreStatus
(
e
.
getPreStatus
());
order
.
setTips
(
getOrderTips
(
e
.
getOrderId
()));
order
.
setAppointmentStatus
(
mapOrderRequest
.
get
(
e
.
getOrderId
()).
getAppointmentStatus
());
List
<
EngineersGanttRespDTO
.
Order
>
orders
=
null
;
if
(
mapEngineers
.
containsKey
(
e
.
getEngineerCode
()))
{
orders
=
mapEngineers
.
get
(
e
.
getEngineerCode
());
}
else
{
orders
=
new
ArrayList
<>();
}
orders
.
add
(
order
);
mapEngineers
.
put
(
e
.
getEngineerCode
(),
orders
);
}
List
<
EngineersGanttRespDTO
.
GanttChart
>
engineers
=
new
ArrayList
<>();
for
(
String
engineerCode
:
reqDTO
.
getEngineerCodes
())
{
EngineerInfoEntity
engineerInfo
=
engineerInfoDao
.
getByEngineerCode
(
engineerCode
);
EngineersGanttRespDTO
.
GanttChart
engineer
=
new
EngineersGanttRespDTO
.
GanttChart
();
engineer
.
setEngineerCode
(
engineerCode
)
.
setStartTime
(
String
.
format
(
"%s 08:00"
,
reqDTO
.
getDate
()))
.
setEndTime
(
String
.
format
(
"%s 18:00"
,
reqDTO
.
getDate
()))
.
setHoliday
(
false
)
// todo
.
setEngineerName
(
engineerInfo
.
getName
())
.
setGrade
(
engineerInfo
.
getGrade
());
CapacityEngineerStatEntity
capacityEngineerStat
=
capacityEngineerStatDao
.
getByEngineerCodeAndWorkday
(
engineerCode
,
reqDTO
.
getDate
());
if
(
capacityEngineerStat
==
null
)
{
log
.
warn
(
"技术员当日的容量数据不存在,{}{}"
,
engineerCode
,
reqDTO
.
getDate
());
}
else
{
engineer
.
setCapTotal
(
capacityEngineerStat
.
getCapTotal
().
toString
()).
setCapUsed
(
capacityEngineerStat
.
getCapUsed
().
toString
());
}
if
(
mapEngineers
.
containsKey
(
engineerCode
)){
engineer
.
setOrders
(
mapEngineers
.
get
(
engineerCode
));
}
// engineer.setErrorTip(); todo
engineers
.
add
(
engineer
);
}
EngineersGanttRespDTO
data
=
new
EngineersGanttRespDTO
().
setDate
(
reqDTO
.
getDate
()).
setEngineers
(
engineers
);
return
Result
.
success
(
data
);
}
public
Map
<
String
,
OrderRequestEntity
>
getOrdersByOrderIds
(
List
<
String
>
orderIds
)
{
List
<
OrderRequestEntity
>
orders
=
orderRequestDao
.
findAllByOrderIdIn
(
orderIds
);
return
orders
.
stream
()
.
collect
(
Collectors
.
toMap
(
OrderRequestEntity:
:
getOrderId
,
order
->
order
));
}
private
List
<?>
getOrderTips
(
String
orderId
)
{
log
.
info
(
"==> getOrderTips: orderId[{}]"
,
orderId
);
OrderRequestEntity
order
=
orderRequestDao
.
getByOrderId
(
orderId
);
if
(
order
==
null
)
{
log
.
error
(
"对应的订单不存在!{}"
,
orderId
);
return
null
;
}
List
<
LabelValueDTO
>
tips
=
new
ArrayList
<>();
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"工单号码"
).
setValue
(
orderId
));
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"类型/品牌"
).
setValue
(
String
.
format
(
"%s %s"
,
order
.
getBrand
(),
order
.
getType
())));
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"电话/地址"
).
setValue
(
String
.
format
(
"%s %s\n %s"
,
order
.
getName
(),
order
.
getPhone
(),
order
.
getAddress
())));
if
(
StringUtils
.
isNotBlank
(
order
.
getApplyNote
()))
{
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"备注"
).
setValue
(
order
.
getApplyNote
()));
}
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"标签"
).
setValue
(
order
.
getTags
()));
return
tips
;
}
@Autowired
private
EngineerInfoMPDao
engineerInfoMPDao
;
@Autowired
private
EngineerSkillMPDao
engineerSkillMPDao
;
@Autowired
private
OrgGroupMPDao
orgGroupMPDao
;
@Autowired
private
EngineerBusinessMPDao
engineerBusinessDao
;
@Autowired
private
OrderRequestDao
orderRequestDao
;
@Autowired
private
OrderAppointmentDao
orderAppointmentDao
;
@Autowired
private
EngineerInfoDao
engineerInfoDao
;
@Autowired
private
CapacityEngineerStatDao
capacityEngineerStatDao
;
@Transactional
@Override
public
Result
<?>
getEngineerInfoList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
)
{
// 查询工程师信息
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
List
<
EngineerInfo
>
records
=
pg
.
getRecords
();
// 获取groupIds
List
<
String
>
groupIds
=
records
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
// 获取Map<groupId, groupName>
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
// 设置返回值
EngineerInfoListResp
res
=
new
EngineerInfoListResp
();
res
.
setContent
(
this
.
packEngineerInfos
(
records
,
groupNames
));
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerInfoDetail
(
String
engineerCode
)
throws
BusinessException
{
// 获取技术员基础信息详情
// 获取技术员列表
List
<
EngineerInfo
>
records
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
records
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<
String
>
groupIds
=
records
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
List
<
EngineerInfoListResp
.
EngineerInfo
>
items
=
this
.
packEngineerInfos
(
records
,
groupNames
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
getEngineerSkillList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
)
{
// 获取技术员技能列表
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
List
<
EngineerInfo
>
engineers
=
pg
.
getRecords
();
EngineerSkillListResp
res
=
new
EngineerSkillListResp
();
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
res
.
setContent
(
this
.
packEngineerSkills
(
engineers
));
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerSkillDetail
(
String
engineerCode
)
throws
BusinessException
{
// 获取工程师技能详情
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
engineers
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<
EngineerSkillListResp
.
EngineerSkill
>
items
=
this
.
packEngineerSkills
(
engineers
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
engineerSkillUpdate
(
String
engineerCode
,
List
<
String
>
categoryIds
)
{
// 更新技术员技能
// 先将所有技能更新为0-不可用状态
LambdaUpdateWrapper
<
EngineerSkill
>
wrapper
=
new
LambdaUpdateWrapper
<>();
wrapper
.
eq
(
EngineerSkill:
:
getEngineerCode
,
engineerCode
).
set
(
EngineerSkill:
:
getStatus
,
0
);
engineerSkillMPDao
.
update
(
null
,
wrapper
);
if
(
categoryIds
.
isEmpty
())
{
return
null
;
}
// 更新categoryIds状态为1
wrapper
.
eq
(
EngineerSkill:
:
getEngineerCode
,
engineerCode
);
wrapper
.
in
(
EngineerSkill:
:
getCategoryId
,
categoryIds
);
wrapper
.
set
(
EngineerSkill:
:
getStatus
,
1
);
int
n
=
engineerSkillMPDao
.
update
(
null
,
wrapper
);
if
(
categoryIds
.
size
()
==
n
)
{
// 更新记录条数等于提交记录条数
return
null
;
}
// 可能存在engineerSkill表不存在的记录,需要补充录入
List
<
Integer
>
statuses
=
new
ArrayList
<
Integer
>(
Arrays
.
asList
(
1
,
0
));
List
<
String
>
engineerCodes
=
new
ArrayList
<>(
Collections
.
singletonList
(
engineerCode
));
HashMap
<
String
,
List
<
String
>>
engineerSkills
=
this
.
queryEngineerSkills
(
engineerCodes
,
statuses
);
Set
<
String
>
sInput
=
new
HashSet
<>(
categoryIds
);
Set
<
String
>
sDB
=
new
HashSet
<>(
engineerSkills
.
get
(
engineerCode
));
sInput
.
removeAll
(
sDB
);
for
(
String
categoryId
:
sInput
)
{
EngineerSkill
e
=
new
EngineerSkill
();
e
.
setEngineerCode
(
engineerCode
);
e
.
setCategoryId
(
categoryId
);
e
.
setStatus
(
1
);
engineerSkillMPDao
.
insert
(
e
);
}
return
null
;
}
@Transactional
@Override
public
Result
<?>
getEngineerBusinessList
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
)
{
// 技术员业务属性配置列表
// 查询技术员列表
IPage
<
EngineerInfo
>
pg
=
this
.
queryEngineerInfoIPage
(
levelType
,
levelValue
,
page
,
size
,
kind
,
key
);
List
<
EngineerInfo
>
engineers
=
pg
.
getRecords
();
// 查询技术员业务属性
EngineerBusinessListResp
res
=
new
EngineerBusinessListResp
();
res
.
setTotal
(
pg
.
getTotal
());
res
.
setPages
(
pg
.
getPages
());
res
.
setPageCurrent
(
pg
.
getCurrent
());
res
.
setPageSize
(
pg
.
getSize
());
res
.
setContent
(
this
.
packEngineerBusinesses
(
engineers
));
return
Result
.
success
(
res
);
}
@Override
public
Result
<?>
getEngineerBusinessDetail
(
String
engineerCode
)
{
// 获取技术员业务熟悉详情
List
<
EngineerInfo
>
engineers
=
engineerInfoMPDao
.
selectByEngineerCode
(
engineerCode
);
if
(
engineers
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
List
<?>
items
=
this
.
packEngineerBusinesses
(
engineers
);
if
(
items
.
isEmpty
())
{
throw
new
BusinessException
(
"技术员不存在"
);
}
return
Result
.
success
(
items
.
get
(
0
));
}
@Transactional
@Override
public
Result
<?>
engineerBusinessUpdate
(
String
engineerCode
,
Integer
maxNum
,
Integer
maxMinute
,
String
departure
,
String
priority
)
{
// 技术员业务属性配置修改
LambdaUpdateWrapper
<
EngineerBusiness
>
wrapper
=
new
LambdaUpdateWrapper
<>();
wrapper
.
eq
(
EngineerBusiness:
:
getEngineerCode
,
engineerCode
);
wrapper
.
set
(
maxNum
>=
0
,
EngineerBusiness:
:
getMaxNum
,
maxNum
);
wrapper
.
set
(
maxMinute
>=
0
,
EngineerBusiness:
:
getMaxMinute
,
maxMinute
);
Integer
dep
=
(
departure
.
equals
(
"配件仓"
))
?
1
:
2
;
wrapper
.
set
(
EngineerBusiness:
:
getDeparture
,
dep
);
int
pri
;
if
(
priority
.
equals
(
"高"
))
{
pri
=
3
;
}
else
if
(
priority
.
equals
(
"中"
))
{
pri
=
2
;
}
else
{
pri
=
1
;
}
wrapper
.
set
(
EngineerBusiness:
:
getPriority
,
pri
);
// 更新字段
engineerBusinessDao
.
update
(
null
,
wrapper
);
return
Result
.
success
(
null
);
}
private
IPage
<
EngineerInfo
>
queryEngineerInfoIPage
(
String
levelType
,
String
levelValue
,
long
page
,
long
size
,
String
kind
,
String
key
)
{
// 分页查询工程师基础信息
// 查询技术员所在的groupIds
LambdaQueryWrapper
<
OrgGroup
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
select
(
OrgGroup:
:
getGroupId
);
wrapper
.
eq
(
levelType
.
equals
(
"cluster"
),
OrgGroup:
:
getClusterId
,
levelValue
);
wrapper
.
eq
(
levelType
.
equals
(
"branch"
),
OrgGroup:
:
getBranchId
,
levelValue
);
wrapper
.
eq
(
levelType
.
equals
(
"group"
),
OrgGroup:
:
getGroupId
,
levelValue
);
List
<
String
>
groupIds
=
orgGroupMPDao
.
selectList
(
wrapper
).
stream
().
map
(
OrgGroup:
:
getGroupId
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
EngineerInfo
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
in
(
groupIds
!=
null
&&
!
groupIds
.
isEmpty
(),
EngineerInfo:
:
getGroupId
,
groupIds
);
lqw
.
eq
(
kind
!=
null
&&
!
kind
.
isEmpty
(),
EngineerInfo:
:
getKind
,
(
kind
==
"fullJob"
)
?
1
:
2
);
if
(
key
!=
null
&&
!
key
.
isEmpty
())
{
lqw
.
or
().
like
(
EngineerInfo:
:
getPhone
,
key
);
lqw
.
or
().
like
(
EngineerInfo:
:
getName
,
key
);
lqw
.
or
().
like
(
EngineerInfo:
:
getEngineerCode
,
key
);
}
lqw
.
orderByAsc
(
EngineerInfo:
:
getGroupId
);
lqw
.
orderByAsc
(
EngineerInfo:
:
getEngineerCode
);
IPage
<
EngineerInfo
>
pg
=
new
Page
(
page
,
size
);
engineerInfoMPDao
.
selectPage
(
pg
,
lqw
);
return
pg
;
}
private
HashMap
<
String
,
String
>
queryGroupNames
(
List
<
String
>
groupIds
)
{
//查询小组名称映射关系
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
if
(
groupIds
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
OrgGroup
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
select
(
OrgGroup:
:
getGroupId
,
OrgGroup:
:
getGroupName
);
lqw
.
in
(
OrgGroup:
:
getGroupId
,
groupIds
);
List
<
OrgGroup
>
groups
=
orgGroupMPDao
.
selectList
(
lqw
);
for
(
OrgGroup
g
:
groups
)
{
map
.
put
(
g
.
getGroupId
(),
g
.
getGroupName
());
}
return
map
;
}
private
HashMap
<
String
,
List
<
String
>>
queryEngineerSkills
(
List
<
String
>
engineerCodes
,
List
<
Integer
>
statuses
)
{
// 获取engineerCode对应的技能表, HashMap<engineerCode, List<skillId>>
HashMap
<
String
,
List
<
String
>>
map
=
new
HashMap
<>();
if
(
engineerCodes
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
EngineerSkill
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
in
(
EngineerSkill:
:
getEngineerCode
,
engineerCodes
);
lqw
.
in
(
EngineerSkill:
:
getStatus
,
statuses
);
List
<
EngineerSkill
>
records
=
engineerSkillMPDao
.
selectList
(
lqw
);
Comparator
<
EngineerSkill
>
ec
=
Comparator
.
comparing
(
EngineerSkill:
:
getEngineerCode
,
String
.
CASE_INSENSITIVE_ORDER
);
List
<
EngineerSkill
>
results
=
records
.
stream
().
sorted
(
ec
).
collect
(
Collectors
.
toList
());
// 根据engineerCode分组
Map
<
String
,
List
<
EngineerSkill
>>
g
=
results
.
stream
().
collect
(
Collectors
.
groupingBy
(
EngineerSkill:
:
getEngineerCode
));
for
(
String
engineerCode
:
g
.
keySet
())
{
// 技术员技能ID列表
List
<
String
>
skillIds
=
g
.
get
(
engineerCode
).
stream
().
map
(
EngineerSkill:
:
getCategoryId
).
collect
(
Collectors
.
toList
());
map
.
put
(
engineerCode
,
skillIds
);
}
return
map
;
}
private
HashMap
<
String
,
EngineerBusiness
>
queryEngineerBusiness
(
List
<
String
>
engineerCodes
)
{
HashMap
<
String
,
EngineerBusiness
>
map
=
new
HashMap
<>();
if
(
engineerCodes
.
isEmpty
())
{
return
map
;
}
LambdaQueryWrapper
<
EngineerBusiness
>
lqw
=
new
LambdaQueryWrapper
<>();
lqw
.
in
(
EngineerBusiness:
:
getEngineerCode
,
engineerCodes
);
List
<
EngineerBusiness
>
records
=
engineerBusinessDao
.
selectList
(
lqw
);
for
(
EngineerBusiness
r
:
records
)
{
map
.
put
(
r
.
getEngineerCode
(),
r
);
}
return
map
;
}
private
List
<
EngineerInfoListResp
.
EngineerInfo
>
packEngineerInfos
(
List
<
EngineerInfo
>
engineers
,
HashMap
<
String
,
String
>
groups
)
{
String
groupName
,
age
,
kind
;
List
<
EngineerInfoListResp
.
EngineerInfo
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerInfoListResp
.
EngineerInfo
item
=
new
EngineerInfoListResp
.
EngineerInfo
();
item
.
setEngineerCode
(
e
.
getEngineerCode
());
item
.
setNumber
(
e
.
getEngineerCode
());
item
.
setName
(
e
.
getName
());
item
.
setSex
(
e
.
getGender
());
item
.
setPhone
(
e
.
getPhone
());
item
.
setAddress
(
e
.
getAddress
());
item
.
setGrade
(
e
.
getGrade
());
// group name
groupName
=
groups
.
getOrDefault
(
e
.
getGroupId
(),
""
);
item
.
setGroupName
(
groupName
);
// 年龄
age
=
this
.
getEngineerAge
(
e
.
getBirth
());
item
.
setAge
(
age
);
// 工作类型:全职/兼职
kind
=
(
e
.
getKind
()
==
1
)
?
"fullJob"
:
"partJob"
;
item
.
setKind
(
kind
);
if
(
e
.
getCredentials
()
!=
null
)
{
item
.
setCredentials
(
Arrays
.
asList
(
e
.
getCredentials
().
split
(
"、"
)));
}
else
{
item
.
setCredentials
(
new
ArrayList
<
String
>());
}
// 标签
List
<
String
>
tags
=
new
ArrayList
<>();
if
(
e
.
getTags
()
!=
null
&&
!
e
.
getTags
().
isEmpty
())
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
e
.
getTags
().
entrySet
())
{
tags
.
add
(
String
.
format
(
"%s+%s"
,
entry
.
getKey
(),
entry
.
getValue
().
toString
()));
}
}
item
.
setTags
(
tags
);
items
.
add
(
item
);
}
return
items
;
}
private
List
<
EngineerSkillListResp
.
EngineerSkill
>
packEngineerSkills
(
List
<
EngineerInfo
>
engineers
)
{
// 获取groupId类表
List
<
String
>
groupIds
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
// 获取技术员code列表
List
<
String
>
engineerCodes
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toList
());
// 获取技术员的可用技能列表
List
<
Integer
>
statuses
=
new
ArrayList
<
Integer
>(
List
.
of
(
1
));
HashMap
<
String
,
List
<
String
>>
engineerSkills
=
this
.
queryEngineerSkills
(
engineerCodes
,
statuses
);
List
<
String
>
emptySkills
=
Collections
.
emptyList
();
List
<
EngineerSkillListResp
.
EngineerSkill
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerSkillListResp
.
EngineerSkill
skill
=
new
EngineerSkillListResp
.
EngineerSkill
();
skill
.
setEngineerCode
(
e
.
getEngineerCode
());
skill
.
setEngineerName
(
e
.
getName
());
skill
.
setGroupName
(
groupNames
.
getOrDefault
(
e
.
getGroupId
(),
""
));
skill
.
setUpdateTime
(
TimeUtils
.
IsoTimestamp2DateTime
(
e
.
getUpdateTime
()));
// 获取一个工程师的技能列表
skill
.
setCategoryIds
(
engineerSkills
.
getOrDefault
(
e
.
getEngineerCode
(),
emptySkills
));
items
.
add
(
skill
);
}
return
items
;
}
private
List
<
EngineerBusinessListResp
.
EngineerBusiness
>
packEngineerBusinesses
(
List
<
EngineerInfo
>
engineers
)
{
// 获取技术员code列表
List
<
String
>
engineerCodes
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getEngineerCode
).
collect
(
Collectors
.
toList
());
List
<
String
>
groupIds
=
engineers
.
stream
().
map
(
EngineerInfo:
:
getGroupId
).
collect
(
Collectors
.
toList
());
HashMap
<
String
,
String
>
groupNames
=
this
.
queryGroupNames
(
groupIds
);
HashMap
<
String
,
EngineerBusiness
>
buss
=
this
.
queryEngineerBusiness
(
engineerCodes
);
List
<
EngineerBusinessListResp
.
EngineerBusiness
>
items
=
new
ArrayList
<>();
for
(
EngineerInfo
e
:
engineers
)
{
EngineerBusinessListResp
.
EngineerBusiness
item
=
new
EngineerBusinessListResp
.
EngineerBusiness
();
item
.
setEngineerCode
(
e
.
getEngineerCode
());
item
.
setGroupName
(
groupNames
.
getOrDefault
(
e
.
getGroupId
(),
""
));
item
.
setEngineerName
(
e
.
getName
());
item
.
setKind
((
e
.
getKind
()
==
1
)
?
"fullJob"
:
"partJob"
);
EngineerBusiness
b
=
buss
.
getOrDefault
(
e
.
getEngineerCode
(),
null
);
if
(
b
==
null
)
{
item
.
setAddress
(
""
);
item
.
setLocation
(
""
);
item
.
setDeparture
(
""
);
item
.
setMaxMinute
(
0
);
item
.
setMaxNum
(
0
);
item
.
setPriority
(
"低"
);
}
else
{
item
.
setAddress
(
b
.
getAddress
());
item
.
setLocation
(
String
.
format
(
"%s,%s"
,
b
.
getX
(),
b
.
getY
()));
item
.
setDeparture
((
b
.
getDeparture
()
==
1
)
?
"配件仓"
:
"住址"
);
item
.
setMaxMinute
(
b
.
getMaxMinute
());
item
.
setMaxNum
(
b
.
getMaxNum
());
String
priority
;
if
(
b
.
getPriority
()
==
3
)
{
priority
=
"高"
;
}
else
if
(
b
.
getPriority
()
==
2
)
{
priority
=
"中"
;
}
else
{
priority
=
"低"
;
}
item
.
setPriority
(
priority
);
}
items
.
add
(
item
);
}
return
items
;
}
private
HashMap
<
String
,
Integer
>
getEngineerSkillIds
(
List
<
String
>
skillIds
,
HashMap
<
String
,
Integer
>
engineerSkillIds
)
{
HashMap
<
String
,
Integer
>
map
=
new
HashMap
<>();
for
(
String
skillId
:
skillIds
)
{
map
.
put
(
skillId
,
engineerSkillIds
.
getOrDefault
(
skillId
,
0
));
}
return
map
;
}
private
String
getEngineerAge
(
String
birth
)
{
// 获取工程师年龄
if
(
birth
.
isEmpty
())
{
return
""
;
}
int
age
;
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
try
{
Date
birthDate
=
dateFormat
.
parse
(
birth
);
Calendar
birthCalendar
=
Calendar
.
getInstance
();
birthCalendar
.
setTime
(
birthDate
);
Calendar
nowCalendar
=
Calendar
.
getInstance
();
age
=
nowCalendar
.
get
(
Calendar
.
YEAR
)
-
birthCalendar
.
get
(
Calendar
.
YEAR
);
if
(
nowCalendar
.
get
(
Calendar
.
DAY_OF_YEAR
)
<
birthCalendar
.
get
(
Calendar
.
DAY_OF_YEAR
))
{
age
--;
}
}
catch
(
Exception
e
)
{
return
""
;
}
return
(
age
<=
0
)
?
""
:
Integer
.
toString
(
age
);
}
@Override
public
Result
<?>
getEngineersGanttList
(
EngineersGanttReqDTO
reqDTO
)
{
// 按日期返回技术员们当天的服务甘特图,不需要翻页
log
.
info
(
"getEngineersGanttList: {}"
,
reqDTO
);
List
<
OrderAppointmentEntity
>
orderAppointments
=
orderAppointmentDao
.
findByDateAndEngineerCodeIn
(
reqDTO
.
getDate
(),
reqDTO
.
getEngineerCodes
());
List
<
String
>
orderIds
=
orderAppointments
.
stream
().
map
(
OrderAppointmentEntity:
:
getOrderId
).
collect
(
Collectors
.
toList
());
Map
<
String
,
OrderRequestEntity
>
mapOrderRequest
=
getOrdersByOrderIds
(
orderIds
);
HashMap
<
String
,
List
<
EngineersGanttRespDTO
.
Order
>>
mapEngineers
=
new
HashMap
<>();
for
(
OrderAppointmentEntity
e
:
orderAppointments
)
{
log
.
info
(
"===== order_id: [{}]"
,
e
.
getOrderId
());
EngineersGanttRespDTO
.
Order
order
=
new
EngineersGanttRespDTO
.
Order
();
// todo 需要根据订单时间和状态,采用expectXXXX或者actualXXXX
order
.
setStartTime
(
e
.
getExpectStartTime
()).
setEndTime
(
e
.
getExpectEndTime
());
order
.
setOrderId
(
e
.
getOrderId
()).
setPreStatus
(
e
.
getPreStatus
());
order
.
setTips
(
getOrderTips
(
e
.
getOrderId
()));
order
.
setAppointmentStatus
(
mapOrderRequest
.
get
(
e
.
getOrderId
()).
getAppointmentStatus
());
List
<
EngineersGanttRespDTO
.
Order
>
orders
=
null
;
if
(
mapEngineers
.
containsKey
(
e
.
getEngineerCode
()))
{
orders
=
mapEngineers
.
get
(
e
.
getEngineerCode
());
}
else
{
orders
=
new
ArrayList
<>();
}
orders
.
add
(
order
);
mapEngineers
.
put
(
e
.
getEngineerCode
(),
orders
);
}
List
<
EngineersGanttRespDTO
.
GanttChart
>
engineers
=
new
ArrayList
<>();
for
(
String
engineerCode
:
reqDTO
.
getEngineerCodes
())
{
EngineerInfoEntity
engineerInfo
=
engineerInfoDao
.
getByEngineerCode
(
engineerCode
);
EngineersGanttRespDTO
.
GanttChart
engineer
=
new
EngineersGanttRespDTO
.
GanttChart
();
engineer
.
setEngineerCode
(
engineerCode
)
.
setStartTime
(
String
.
format
(
"%s 08:00"
,
reqDTO
.
getDate
()))
.
setEndTime
(
String
.
format
(
"%s 18:00"
,
reqDTO
.
getDate
()))
.
setHoliday
(
false
)
// todo
.
setEngineerName
(
engineerInfo
.
getName
())
.
setGrade
(
engineerInfo
.
getGrade
());
CapacityEngineerStatEntity
capacityEngineerStat
=
capacityEngineerStatDao
.
getByEngineerCodeAndWorkday
(
engineerCode
,
reqDTO
.
getDate
());
if
(
capacityEngineerStat
==
null
)
{
log
.
warn
(
"技术员当日的容量数据不存在,{}{}"
,
engineerCode
,
reqDTO
.
getDate
());
}
else
{
engineer
.
setCapTotal
(
capacityEngineerStat
.
getCapTotal
().
toString
()).
setCapUsed
(
capacityEngineerStat
.
getCapUsed
().
toString
());
}
if
(
mapEngineers
.
containsKey
(
engineerCode
))
{
engineer
.
setOrders
(
mapEngineers
.
get
(
engineerCode
));
}
// engineer.setErrorTip(); todo
engineers
.
add
(
engineer
);
}
EngineersGanttRespDTO
data
=
new
EngineersGanttRespDTO
().
setDate
(
reqDTO
.
getDate
()).
setEngineers
(
engineers
);
return
Result
.
success
(
data
);
}
public
Map
<
String
,
OrderRequestEntity
>
getOrdersByOrderIds
(
List
<
String
>
orderIds
)
{
List
<
OrderRequestEntity
>
orders
=
orderRequestDao
.
findAllByOrderIdIn
(
orderIds
);
return
orders
.
stream
()
.
collect
(
Collectors
.
toMap
(
OrderRequestEntity:
:
getOrderId
,
order
->
order
));
}
private
List
<?>
getOrderTips
(
String
orderId
)
{
log
.
info
(
"==> getOrderTips: orderId[{}]"
,
orderId
);
OrderRequestEntity
order
=
orderRequestDao
.
getByOrderId
(
orderId
);
if
(
order
==
null
)
{
log
.
error
(
"对应的订单不存在!{}"
,
orderId
);
return
null
;
}
List
<
LabelValueDTO
>
tips
=
new
ArrayList
<>();
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"工单号码"
).
setValue
(
orderId
));
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"类型/品牌"
).
setValue
(
String
.
format
(
"%s %s"
,
order
.
getBrand
(),
order
.
getType
())));
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"电话/地址"
).
setValue
(
String
.
format
(
"%s %s\n %s"
,
order
.
getName
(),
order
.
getPhone
(),
order
.
getAddress
())));
if
(
StringUtils
.
isNotBlank
(
order
.
getApplyNote
()))
{
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"备注"
).
setValue
(
order
.
getApplyNote
()));
}
tips
.
add
(
new
LabelValueDTO
().
setLabel
(
"标签"
).
setValue
(
order
.
getTags
()));
return
tips
;
}
}
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