| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | //import com.qianwen.core.redis.cache.BladeRedis; |
| | | import com.qianwen.mdc.collect.dto.WorkstationDTO; |
| | | import com.qianwen.mdc.collect.entity.mgr.EmployeeOnOffWork; |
| | | import com.qianwen.mdc.collect.entity.mgr.GlobalWcsOfRps; |
| | | import com.qianwen.mdc.collect.entity.mgr.Workstation; |
| | | import com.qianwen.mdc.collect.mapper.mgr.EmployeeOnOffWorkMapper; |
| | | import com.qianwen.mdc.collect.mapper.mgr.GlobalWcsOfRpsMapper; |
| | | import com.qianwen.mdc.collect.service.WorkstationService; |
| | | import com.qianwen.mdc.collect.utils.redis.RedisUtil; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | //import com.qianwen.posting.convert.WorkstationConvert; |
| | | |
| | | //import com.qianwen.posting.entity.mysql.EmployeeOnOffWork; |
| | | |
| | | //import com.qianwen.posting.entity.mysql.Workstation; |
| | | //import com.qianwen.posting.mapper.mysql.EmployeeOnOffWorkMapper; |
| | | |
| | | //import com.qianwen.posting.service.IWorkstationService; |
| | | |
| | | @Component |
| | | public class WorkstationCache { |
| | |
| | | private GlobalWcsOfRpsMapper globalWcsOfRpsMapper; |
| | | @Autowired |
| | | private WorkstationService workstationService; |
| | | @Autowired |
| | | private EmployeeOnOffWorkMapper employeeOnOffWorkMapper; |
| | | |
| | | //private static final EmployeeOnOffWorkMapper employeeOnOffWorkMapper = (EmployeeOnOffWorkMapper) SpringUtil.getBean(EmployeeOnOffWorkMapper.class); |
| | | |
| | | |
| | |
| | | return wcsSetting; |
| | | } |
| | | |
| | | /* |
| | | public static Long getBelongToEmployeeForWorkstation(Long workstationId, Date timePoint) { |
| | | Long employeeId = null; |
| | | String redisKey = "posting:workstation".concat("::").concat("workstation:id:").concat(workstationId.toString() |
| | | .concat(EMPLOYEE)); |
| | | Set<EmployeeOnOffWork> employeeOnOffWorks = bladeRedis.sMembers(redisKey); |
| | | EmployeeOnOffWork matchRecord = null; |
| | | if (Func.isNotEmpty(employeeOnOffWorks)) |
| | | matchRecord = employeeOnOffWorks.stream().filter(item -> (item.getOnlineTime().getTime() <= timePoint.getTime() && (item.getOfflineTime() == null || item.getOfflineTime().getTime() > timePoint.getTime()))).findFirst().orElse(null); |
| | | if (Func.isNotEmpty(matchRecord)) { |
| | | employeeId = matchRecord.getOnEmployeeId(); |
| | | } else { |
| | | List<EmployeeOnOffWork> queryResult = employeeOnOffWorkMapper.selectList(Wrappers.<EmployeeOnOffWork>lambdaQuery() |
| | | .eq(EmployeeOnOffWork::getWorkstationId, workstationId) |
| | | .le(EmployeeOnOffWork::getOnlineTime, timePoint) |
| | | .and(wrapper -> wrapper.gt(EmployeeOnOffWork::getOfflineTime, timePoint).or().isNull(EmployeeOnOffWork::getOfflineTime))); |
| | | if (Func.isNotEmpty(queryResult)) { |
| | | employeeId = ((EmployeeOnOffWork)queryResult.get(0)).getOnEmployeeId(); |
| | | bladeRedis.sAdd(redisKey, new Object[] { queryResult.get(0) }); |
| | | bladeRedis.expire(redisKey, 259200L); |
| | | } |
| | | } |
| | | return employeeId; |
| | | }*/ |
| | | /** |
| | | * 获取工位在指定时间的上班员工 |
| | | * @param workstationId |
| | | * @param timePoint |
| | | * @return |
| | | */ |
| | | public Long getBelongToEmployeeForWorkstation(Long workstationId, Date timePoint) { |
| | | Long employeeId = null; |
| | | String redisKey = "posting:workstation".concat("::").concat("workstation:id:") |
| | | .concat(workstationId.toString().concat(EMPLOYEE)); |
| | | // Set<EmployeeOnOffWork> employeeOnOffWorks = bladeRedis.sMembers(redisKey); |
| | | |
| | | Set<EmployeeOnOffWork> employeeOnOffWorks = (Set<EmployeeOnOffWork>) redisUtil.sGet(redisKey); |
| | | EmployeeOnOffWork matchEmployee = null; |
| | | if (ObjectUtil.isNotEmpty(employeeOnOffWorks)) { |
| | | matchEmployee = employeeOnOffWorks.stream().filter( |
| | | item -> (item.getOnlineTime().getTime() <= timePoint.getTime() && (item.getOfflineTime() == null |
| | | || item.getOfflineTime().getTime() > timePoint.getTime()))) |
| | | .findFirst().orElse(null); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(matchEmployee)) { |
| | | employeeId = matchEmployee.getOnEmployeeId(); |
| | | } else { |
| | | List<EmployeeOnOffWork> queryResult = employeeOnOffWorkMapper.selectList( |
| | | Wrappers.<EmployeeOnOffWork>lambdaQuery().eq(EmployeeOnOffWork::getWorkstationId, workstationId) |
| | | .le(EmployeeOnOffWork::getOnlineTime, timePoint) |
| | | .and(wrapper -> wrapper.gt(EmployeeOnOffWork::getOfflineTime, timePoint).or() |
| | | .isNull(EmployeeOnOffWork::getOfflineTime))); |
| | | if (ObjectUtil.isNotEmpty(queryResult)) { |
| | | employeeId = ((EmployeeOnOffWork) queryResult.get(0)).getOnEmployeeId(); |
| | | //bladeRedis.sAdd(redisKey, new Object[] { queryResult.get(0) }); |
| | | //bladeRedis.expire(redisKey, 259200L); |
| | | redisUtil.sSetAndTime(redisKey, 259200L, new Object[] { queryResult.get(0) }); |
| | | } |
| | | } |
| | | return employeeId; |
| | | } |
| | | } |