异步加载列表更新有效时间的状态
controller
@RequiresPermissions ( "policy:blackHouseData:list" )
@GetMapping ( "/pageList" )
public TableDataInfo pageList ( BlackHouseDataQueryParam blackHouseConfig) {
CompletableFuture < List < BlackHouseData > > listCompletableFuture = blackHouseDataService. selectAsyncBlackHouseDataListByQueryParam ( blackHouseConfig) ;
List < BlackHouseData > blackHouseDataList = listCompletableFuture. join ( ) ;
return getDataTable ( blackHouseDataList) ;
}
service
@RequiresPermissions ( "policy:blackHouseData:list" )
@GetMapping ( "/pageList" )
public TableDataInfo pageList ( BlackHouseDataQueryParam blackHouseConfig) {
CompletableFuture < List < BlackHouseData > > listCompletableFuture = blackHouseDataService. selectAsyncBlackHouseDataListByQueryParam ( blackHouseConfig) ;
List < BlackHouseData > blackHouseDataList = listCompletableFuture. join ( ) ;
return getDataTable ( blackHouseDataList) ;
}
serviceImpl
@Override
public CompletableFuture < List < BlackHouseData > > selectAsyncBlackHouseDataListByQueryParam ( BlackHouseDataQueryParam blackHouseConfig) {
PageDomain pageDomain = TableSupport . buildPageRequest ( ) ;
Integer pageNum = pageDomain. getPageNum ( ) ;
Integer pageSize = pageDomain. getPageSize ( ) ;
String orderBy = SqlUtil . escapeOrderBySql ( pageDomain. getOrderBy ( ) ) ;
Boolean reasonable = pageDomain. getReasonable ( ) ;
return CompletableFuture . supplyAsync ( ( ) -> {
PageMethod . startPage ( pageNum, pageSize, orderBy) . setReasonable ( reasonable) ;
return blackHouseConfigMapper. selectBlackHouseDataListByQueryParam ( blackHouseConfig) ;
} ) . thenCompose ( blackHouseDataList -> toUpdateStatus ( blackHouseDataList)
. thenApply ( v -> {
PageMethod . startPage ( pageNum, pageSize, orderBy) . setReasonable ( reasonable) ;
return blackHouseConfigMapper. selectBlackHouseDataListByQueryParam ( blackHouseConfig) ;
} ) ) ;
}
@Resource
SqlSessionFactory sqlSessionFactory;
private CompletableFuture < Void > toUpdateStatus ( List < BlackHouseData > blackHouseDataList) {
return CompletableFuture . runAsync ( ( ) -> {
LocalDateTime nowDate = LocalDateTime . now ( ) ;
try ( SqlSession session = sqlSessionFactory. openSession ( ExecutorType . BATCH ) ) {
BlackHouseDataMapper mapper = session. getMapper ( BlackHouseDataMapper . class ) ;
for ( BlackHouseData bData : blackHouseDataList) {
Date shieldEndTime = bData. getShieldEndTime ( ) ;
Instant instant = shieldEndTime. toInstant ( ) ;
ZoneId zone = ZoneId . systemDefault ( ) ;
LocalDateTime shieldEndDate = LocalDateTime . ofInstant ( instant, zone) ;
if ( shieldEndDate. isBefore ( nowDate) ) {
bData. setStatus ( GdsYesNoEnum . NO . getCode ( ) ) ;
mapper. updateBlackHouseData ( bData) ;
}
}
session. commit ( ) ;
session. clearCache ( ) ;
} catch ( Exception e) {
e. printStackTrace ( ) ;
}
} ) ;
}
mapper
List < BlackHouseData > selectBlackHouseDataListByQueryParam ( BlackHouseDataQueryParam blackHouseConfig) ;
mapper.xml
< select id = " selectBlackHouseDataListByQueryParam" parameterType = " BlackHouseDataQueryParam" resultMap = " BlackHouseDataResult" >
< include refid = " selectBlackHouseDataVo" />
< where>
< if test = " keyId!= null " > and t.key_id= #{keyId}</ if>
< if test = " status != null " > and t.status = #{status}</ if>
</ where>
order by t.key_id desc
</ select>