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 fc58fc18
authored
Nov 10, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(工作队): 工作队添加修改人员时错误问题, 废弃原有写法 先移除工作队人员关系再保存新的人员关系
1 parent
00ac4a0a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
53 deletions
project-order/src/main/java/com/dituhui/pea/order/dao/OrgTeamEngineerDao.java
project-order/src/main/java/com/dituhui/pea/order/service/impl/BusinessTeamServiceImpl.java
project-order/src/main/java/com/dituhui/pea/order/dao/OrgTeamEngineerDao.java
View file @
fc58fc1
...
...
@@ -7,7 +7,6 @@ import org.springframework.data.jpa.repository.Modifying;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -36,4 +35,12 @@ public interface OrgTeamEngineerDao extends JpaRepository<OrgTeamEngineerEntity,
void
updateStatusByEngineerCodes
(
String
teamId
,
List
<
String
>
engineerCodes
,
int
status
);
List
<
OrgTeamEngineerEntity
>
findByEngineerCode
(
String
engineerCode
);
/**
* 移除工作队下的所有人员关联关系
*
* @param teamId 工作队
* @return 影响行数
*/
Integer
deleteByTeamId
(
String
teamId
);
}
project-order/src/main/java/com/dituhui/pea/order/service/impl/BusinessTeamServiceImpl.java
View file @
fc58fc1
...
...
@@ -40,9 +40,7 @@ import java.time.LocalTime;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
...
...
@@ -210,18 +208,31 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
orgTeamDao
.
save
(
entity
);
// 技术员列表
if
(
req
.
getEngineerCodes
()
!=
null
&&
!
req
.
getEngineerCodes
().
isEmpty
())
{
updateTeamEngineers
(
entity
,
req
.
getEngineerCodes
());
List
<
String
>
engineerCodes
=
req
.
getEngineerCodes
();
if
(
engineerCodes
!=
null
&&
!
engineerCodes
.
isEmpty
())
{
final
String
targetTeamId
=
String
.
valueOf
(
entity
.
getTeamId
());
List
<
String
>
targetTeamWorkDayOfWeek
=
List
.
of
(
entity
.
getWorkdays
().
split
(
","
));
judgeTeam
(
engineerCodes
,
targetTeamId
,
targetTeamWorkDayOfWeek
);
//移除原有关系映射
orgTeamEngineerDao
.
deleteByTeamId
(
targetTeamId
);
//新增新的关系映射
List
<
OrgTeamEngineerEntity
>
newRelation
=
engineerCodes
.
stream
().
map
(
t
->
{
OrgTeamEngineerEntity
relation
=
new
OrgTeamEngineerEntity
();
relation
.
setTeamId
(
targetTeamId
);
relation
.
setEngineerCode
(
t
);
relation
.
setCreateTime
(
LocalDateTime
.
now
());
relation
.
setUpdateTime
(
LocalDateTime
.
now
());
relation
.
setStatus
(
1
);
return
relation
;
}).
collect
(
Collectors
.
toList
());
orgTeamEngineerDao
.
saveAll
(
newRelation
);
}
return
Result
.
success
(
null
);
}
public
void
updateTeamEngineers
(
OrgTeamEntity
targetTeam
,
List
<
String
>
engineerCodes
)
{
// 获取现有的工作队和技术员之间的所有关系
final
String
targetTeamId
=
String
.
valueOf
(
targetTeam
.
getTeamId
());
List
<
String
>
targetTeamWorkDayOfWeek
=
List
.
of
(
targetTeam
.
getWorkdays
().
split
(
","
));
List
<
OrgTeamEngineerEntity
>
existingRelations
=
orgTeamEngineerDao
.
findAllByTeamId
(
targetTeamId
);
private
void
judgeTeam
(
List
<
String
>
engineerCodes
,
String
targetTeamId
,
List
<
String
>
targetTeamWorkDayOfWeek
)
{
// 查询工程师在其它工作队的工作时间以及当前工作队的工作时间
final
String
message
=
"工号为{0}的工程师在{1}工作队的周{2}已有工作日安排"
;
List
<
String
>
warnMessage
=
new
ArrayList
<>();
...
...
@@ -247,48 +258,6 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
if
(!
CollectionUtils
.
isEmpty
(
warnMessage
))
{
throw
new
BusinessException
(
StringUtils
.
join
(
warnMessage
,
";"
));
}
// 构建新的关系映射
Map
<
String
,
OrgTeamEngineerEntity
>
newRelationsMap
=
new
HashMap
<>();
for
(
String
engineerCode
:
engineerCodes
)
{
OrgTeamEngineerEntity
relation
=
new
OrgTeamEngineerEntity
();
relation
.
setTeamId
(
targetTeamId
);
relation
.
setEngineerCode
(
engineerCode
);
relation
.
setCreateTime
(
LocalDateTime
.
now
());
relation
.
setUpdateTime
(
LocalDateTime
.
now
());
relation
.
setStatus
(
1
);
newRelationsMap
.
put
(
engineerCode
,
relation
);
}
// 遍历现有的关系列表,更新关系的最后时间和状态
for
(
OrgTeamEngineerEntity
relation
:
existingRelations
)
{
String
engineerCode
=
relation
.
getEngineerCode
();
if
(
newRelationsMap
.
containsKey
(
engineerCode
))
{
OrgTeamEngineerEntity
newRelation
=
newRelationsMap
.
get
(
engineerCode
);
newRelation
.
setId
(
relation
.
getId
());
newRelation
.
setUpdateTime
(
LocalDateTime
.
now
());
newRelationsMap
.
put
(
engineerCode
,
newRelation
);
}
else
{
// 新的关系不再,设置为0(删除)
relation
.
setStatus
(
0
);
orgTeamEngineerDao
.
save
(
relation
);
}
}
// 遍历新的关系映射,创建新的关系
for
(
OrgTeamEngineerEntity
newRelation
:
newRelationsMap
.
values
())
{
if
(!
existingRelations
.
contains
(
newRelation
))
{
// 检查是否存在,已经存在的,只需要set status=1就可以了
OrgTeamEngineerEntity
exist
=
orgTeamEngineerDao
.
findByTeamIdAndEngineerCode
(
newRelation
.
getTeamId
(),
newRelation
.
getEngineerCode
());
if
(
null
!=
exist
&&
exist
.
getId
()
!=
null
)
{
exist
.
setStatus
(
1
);
orgTeamEngineerDao
.
save
(
exist
);
}
else
{
orgTeamEngineerDao
.
save
(
newRelation
);
}
}
}
}
@Override
...
...
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