Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
95d59f83
Commit
95d59f83
authored
Nov 02, 2023
by
李秀明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(JCS)值班排版:并发导致数据错乱
parent
e2d64218
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
71 deletions
+70
-71
DateUtils.java
...ava/com/yeejoin/amos/boot/biz/common/utils/DateUtils.java
+15
-0
DutyCarServiceImpl.java
...ot/module/common/biz/service/impl/DutyCarServiceImpl.java
+28
-35
DutyPersonServiceImpl.java
...module/common/biz/service/impl/DutyPersonServiceImpl.java
+27
-36
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/utils/DateUtils.java
View file @
95d59f83
...
...
@@ -883,4 +883,19 @@ public class DateUtils {
Date
end
=
calendar
.
getTime
();
return
end
;
}
/**
* 获取指定月份的最后一天
* @param monthDate yyyy-MM
* @return yyyy-MM-dd
*/
public
static
String
getLastDayOfMonth
(
String
monthDate
)
{
String
[]
split
=
monthDate
.
split
(
"-"
);
int
year
=
Integer
.
parseInt
(
split
[
0
]);
int
month
=
Integer
.
parseInt
(
split
[
1
]);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
year
,
month
-
1
,
1
);
int
actualMaximum
=
calendar
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
return
year
+
"-"
+
month
+
"-"
+
actualMaximum
;
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-common-biz/src/main/java/com/yeejoin/amos/boot/module/common/biz/service/impl/DutyCarServiceImpl.java
View file @
95d59f83
...
...
@@ -93,7 +93,7 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
});
// 修改操作动态表单的方法,修改人陈浩 -------------end 2021-09-28
// 生成变更日志
createDutyPersonShiftLog
(
dutyCarDto
,
false
,
ActionStatus
.
METHOD_
UPDATE
.
getCode
());
createDutyPersonShiftLog
(
dutyCarDto
,
false
,
ActionStatus
.
METHOD_
ADD
.
getCode
());
// 3.返回保存后的数据
return
dutyCarDto
;
...
...
@@ -432,49 +432,42 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
}
@SuppressWarnings
(
"Duplicates"
)
public
void
createDutyPersonShiftLog
(
DutyCarDto
dutyCarDto
,
boolean
isInit
,
String
actionCode
)
{
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
()
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
List
<
DutyPersonShiftDto
>
dutyPersonShift
=
dutyCarDto
.
getDutyShift
();
final
String
groupCode
=
"dutyCar"
;
// 新建/更新排班时处理跨月数据
if
(!
isInit
&&
StringUtils
.
isNotBlank
(
actionCode
)
)
{
public
synchronized
void
createDutyPersonShiftLog
(
DutyCarDto
dutyCarDto
,
boolean
isInit
,
String
actionCode
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
List
<
DutyPersonShiftDto
>
dutyPersonShift
=
dutyCarDto
.
getDutyShift
();
final
String
groupCode
=
"dutyCar"
;
// 更新排班时处理
if
(!
isInit
&&
Objects
.
equals
(
actionCode
,
"update"
))
{
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
(
)
{
if
(
Objects
.
nonNull
(
dutyPersonShift
)
&&
!
dutyPersonShift
.
isEmpty
())
{
// 拿到排班月份 yyyy-MM
String
dutyDate
=
dateFormat
.
format
(
dutyPersonShift
.
get
(
0
).
getDutyDate
())
;
dutyDate
=
dutyDate
.
substring
(
0
,
7
);
String
month
=
dateFormat
.
format
(
dutyPersonShift
.
get
(
0
).
getDutyDate
()).
substring
(
0
,
7
);
String
startDate
=
month
+
"-01"
;
String
endDate
=
DateUtils
.
getLastDayOfMonth
(
month
);
String
today
=
dateFormat
.
format
(
new
Date
());
if
(
today
.
substring
(
0
,
7
).
equals
(
dutyDate
))
{
dutyDate
=
today
;
}
else
{
dutyDate
+=
"-01"
;
try
{
startDate
=
isAfterToday
(
dateFormat
.
parse
(
startDate
))
?
startDate
:
today
;
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
e
)
;
}
dutyPersonShiftLogMapper
.
delete
(
Wrappers
.<
DutyPersonShiftLog
>
lambdaQuery
()
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyCarDto
.
getUserName
())
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
duty
Date
)
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
dateFormat
.
format
(
new
Date
())
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyCarDto
.
getUserId
())
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
start
Date
)
.
le
(
DutyPersonShiftLog:
:
getDutyDate
,
endDate
)
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
);
}
dutyPersonShift
.
clear
();
try
{
List
<
Map
<
String
,
Object
>>
list
=
list
(
null
,
dateFormat
.
format
(
new
Date
()),
"9999-12-12"
);
list
=
list
.
stream
().
filter
(
map
->
Objects
.
equals
(
map
.
get
(
"userName"
),
dutyCarDto
.
getUserName
())).
collect
(
Collectors
.
toList
());
for
(
Map
<
String
,
Object
>
map
:
list
)
{
DutyCarDto
dutyCarDto
=
(
DutyCarDto
)
Bean
.
mapToBean
(
map
,
DutyCarDto
.
class
);
List
<
DutyPersonShiftDto
>
dutyShifts
=
dutyCarDto
.
getDutyShift
().
stream
().
filter
(
v
->
isAfterToday
(
v
.
getDutyDate
())).
collect
(
Collectors
.
toList
());
dutyPersonShift
.
addAll
(
dutyShifts
);
}
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
});
}
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
()
{
Set
<
String
>
dutyDates
=
dutyPersonShift
.
stream
().
map
(
v
->
dateFormat
.
format
(
v
.
getDutyDate
())).
collect
(
Collectors
.
toSet
());
if
(
dutyDates
.
isEmpty
())
{
return
;
...
...
@@ -483,7 +476,7 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
Wrappers
.<
DutyPersonShiftLog
>
lambdaQuery
()
.
in
(
DutyPersonShiftLog:
:
getDutyDate
,
dutyDates
)
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyCarDto
.
getUserName
())
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyCarDto
.
getUserId
())
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
).
stream
().
collect
(
Collectors
.
groupingBy
(
DutyPersonShiftLog:
:
getDutyDate
));
...
...
@@ -534,7 +527,7 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
Wrappers
.<
DutyPersonShiftLog
>
lambdaUpdate
()
.
eq
(
DutyPersonShiftLog:
:
getDutyDate
,
dutyPersonShiftDto
.
getDutyDate
())
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyCarDto
.
getUserName
())
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyCarDto
.
getUserId
())
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
);
}
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-common-biz/src/main/java/com/yeejoin/amos/boot/module/common/biz/service/impl/DutyPersonServiceImpl.java
View file @
95d59f83
...
...
@@ -534,50 +534,42 @@ public Object BuildScheduleDetails(String dutyDay, Long shiftId, String postType
}
@SuppressWarnings
(
"Duplicates"
)
public
void
createDutyPersonShiftLog
(
DutyPersonDto
dutyPersonDto
,
boolean
isInit
,
String
actionCode
)
{
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
()
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
List
<
DutyPersonShiftDto
>
dutyPersonShift
=
dutyPersonDto
.
getDutyShift
();
final
String
groupCode
=
"dutyPerson"
;
// 新建/更新排班时处理跨月数据
if
(!
isInit
&&
StringUtils
.
isNotBlank
(
actionCode
)
)
{
public
synchronized
void
createDutyPersonShiftLog
(
DutyPersonDto
dutyPersonDto
,
boolean
isInit
,
String
actionCode
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
List
<
DutyPersonShiftDto
>
dutyPersonShift
=
dutyPersonDto
.
getDutyShift
();
final
String
groupCode
=
"dutyPerson"
;
// 更新排班时处理
if
(!
isInit
&&
Objects
.
equals
(
actionCode
,
"update"
))
{
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
(
)
{
if
(
Objects
.
nonNull
(
dutyPersonShift
)
&&
!
dutyPersonShift
.
isEmpty
())
{
// 拿到排班月份 yyyy-MM
String
dutyDate
=
dateFormat
.
format
(
dutyPersonShift
.
get
(
0
).
getDutyDate
())
;
dutyDate
=
dutyDate
.
substring
(
0
,
7
);
String
month
=
dateFormat
.
format
(
dutyPersonShift
.
get
(
0
).
getDutyDate
()).
substring
(
0
,
7
);
String
startDate
=
month
+
"-01"
;
String
endDate
=
DateUtils
.
getLastDayOfMonth
(
month
);
String
today
=
dateFormat
.
format
(
new
Date
());
if
(
today
.
substring
(
0
,
7
).
equals
(
dutyDate
))
{
dutyDate
=
today
;
}
else
{
dutyDate
+=
"-01"
;
try
{
startDate
=
isAfterToday
(
dateFormat
.
parse
(
startDate
))
?
startDate
:
today
;
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
e
)
;
}
dutyPersonShiftLogMapper
.
delete
(
Wrappers
.<
DutyPersonShiftLog
>
lambdaQuery
()
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyPersonDto
.
getUserName
())
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
duty
Date
)
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
dateFormat
.
format
(
new
Date
())
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyPersonDto
.
getUserId
())
.
ge
(
DutyPersonShiftLog:
:
getDutyDate
,
start
Date
)
.
le
(
DutyPersonShiftLog:
:
getDutyDate
,
endDate
)
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
);
}
dutyPersonShift
.
clear
();
try
{
List
<
Map
<
String
,
Object
>>
list
=
list
(
null
,
dateFormat
.
format
(
new
Date
()),
"9999-12-12"
);
list
=
list
.
stream
().
filter
(
map
->
Objects
.
equals
(
map
.
get
(
"userName"
),
dutyPersonDto
.
getUserName
())).
collect
(
Collectors
.
toList
());
for
(
Map
<
String
,
Object
>
map
:
list
)
{
DutyCarDto
dutyCarDto
=
(
DutyCarDto
)
Bean
.
mapToBean
(
map
,
DutyCarDto
.
class
);
List
<
DutyPersonShiftDto
>
dutyShifts
=
dutyCarDto
.
getDutyShift
().
stream
().
filter
(
v
->
isAfterToday
(
v
.
getDutyDate
())).
collect
(
Collectors
.
toList
());
dutyPersonShift
.
addAll
(
dutyShifts
);
}
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
});
}
TransactionSynchronizationManager
.
registerSynchronization
(
new
TransactionSynchronization
()
{
@Override
public
void
afterCommit
()
{
Set
<
String
>
dutyDates
=
dutyPersonShift
.
stream
().
map
(
v
->
dateFormat
.
format
(
v
.
getDutyDate
())).
collect
(
Collectors
.
toSet
());
if
(
dutyDates
.
isEmpty
())
{
return
;
...
...
@@ -586,7 +578,7 @@ public Object BuildScheduleDetails(String dutyDay, Long shiftId, String postType
Wrappers
.<
DutyPersonShiftLog
>
lambdaQuery
()
.
in
(
DutyPersonShiftLog:
:
getDutyDate
,
dutyDates
)
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyPersonDto
.
getUserName
())
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyPersonDto
.
getUserId
())
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
).
stream
().
collect
(
Collectors
.
groupingBy
(
DutyPersonShiftLog:
:
getDutyDate
));
...
...
@@ -634,12 +626,11 @@ public Object BuildScheduleDetails(String dutyDay, Long shiftId, String postType
Wrappers
.<
DutyPersonShiftLog
>
lambdaUpdate
()
.
eq
(
DutyPersonShiftLog:
:
getDutyDate
,
dutyPersonShiftDto
.
getDutyDate
())
.
eq
(
DutyPersonShiftLog:
:
getGroupCode
,
groupCode
)
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
,
dutyPersonDto
.
getUserName
())
.
eq
(
DutyPersonShiftLog:
:
getDutyUser
Id
,
dutyPersonDto
.
getUserId
())
.
eq
(
DutyPersonShiftLog:
:
getIsDelete
,
false
)
);
}
}
;
}
});
}
...
...
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