|
@@ -1,35 +1,61 @@
|
|
|
package com.hfln.portal.infrastructure.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.hfln.portal.common.request.event.WebInOutParams;
|
|
|
import com.hfln.portal.infrastructure.mapper.PersonInOutMapper;
|
|
|
import com.hfln.portal.infrastructure.po.PersonInOutInfo;
|
|
|
import com.hfln.portal.infrastructure.service.PersonInOutService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class PersonInOutServiceImpl extends ServiceImpl<PersonInOutMapper, PersonInOutInfo> implements PersonInOutService {
|
|
|
@Override
|
|
|
- public PersonInOutInfo queryOneByDevId(Long devId, String countDate) {
|
|
|
+ public PersonInOutInfo queryLatestOneByDevId(Long devId) {
|
|
|
|
|
|
LambdaUpdateWrapper<PersonInOutInfo> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.eq(PersonInOutInfo::getDevId, devId)
|
|
|
- .eq(PersonInOutInfo::getCountDate, countDate);
|
|
|
+ .orderByDesc(PersonInOutInfo::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
return this.baseMapper.selectOne(wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Long countActive(Long tenantId) {
|
|
|
|
|
|
- LambdaUpdateWrapper<PersonInOutInfo> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(PersonInOutInfo::getTenantId, tenantId)
|
|
|
- .eq(PersonInOutInfo::getCountDate, DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now()))
|
|
|
- .ge(PersonInOutInfo::getCount, 3);
|
|
|
- return this.baseMapper.selectCount(wrapper);
|
|
|
+ return this.baseMapper.countActive(tenantId, LocalDateTime.now(), LocalDateTime.now().plusDays(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PersonInOutInfo> selectPage(WebInOutParams params) {
|
|
|
+
|
|
|
+
|
|
|
+ Page<PersonInOutInfo> page = new Page<>(params.getPageNo(), params.getPageSize());
|
|
|
+
|
|
|
+ // 2. 构建查询条件
|
|
|
+ LambdaQueryWrapper<PersonInOutInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ // 3. 添加日期条件
|
|
|
+ if (Objects.nonNull(params.getCreateTimeStart())) {
|
|
|
+ queryWrapper.ge(PersonInOutInfo::getCreateTime, params.getCreateTimeStart());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(params.getCreateTimeEnd())) {
|
|
|
+ queryWrapper.lt(PersonInOutInfo::getCreateTime, params.getCreateTimeEnd().plusDays(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(params.getDevId())) {
|
|
|
+ queryWrapper.eq(PersonInOutInfo::getDevId, params.getDevId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 设置排序
|
|
|
+ queryWrapper.orderByDesc(PersonInOutInfo::getCreateTime);
|
|
|
+ return this.baseMapper.selectPage(page, queryWrapper);
|
|
|
}
|
|
|
}
|