public class CalculatorTimeUtil {@Resourceprivate SecurityUserService securityUserService;@Resourceprivate RedisUtils redisUtils;/*** 平均分配rediskey*/private final String redisKey = "executorList";/*** 超时时长(小时)*/public static final int IND_144 = 144;public static final int IND_168 = 168;/*** 根据起止时间,来计算时间差(小时)* @param workStartTime String 建单时间* @return float 小时*/public float getHours(String workStartTime){SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 获取当前系统时间String endTime = DateUtil.now();try{//建单时间戳long startTime = sf.parse(workStartTime).getTime();//当前系统时间戳long deadTime = sf.parse(endTime).getTime();return new BigDecimal(deadTime-startTime).divide(new BigDecimal(60*60*1000),2, RoundingMode.HALF_UP).floatValue();}catch (Exception e){e.printStackTrace();throw new PeachException("时间转换异常");}}/*** 小时转超时类型* @param hours float* @return String*/public String getType(float hours){String msg = "未超时";if (MagicNumber.IND_48 <= hours && hours <= MagicNumber.IND_72) {msg = "响应即将超时";} else if (MagicNumber.IND_72 < hours && hours < IND_144) {msg = "响应已超时";} else if (IND_144 <= hours && hours <= IND_168) {msg = "最终即将超时";} else if (IND_168 < hours) {msg = "最终已超时";}return msg;}/*** 自动分配规则* @return Long*/public synchronized Long autoAssign() {log.info("开始执行平均分配");Long executorId;List executorList;//从redis中获取Object executors = redisUtils.get(redisKey);if (null == executors) {log.info("redis中无key = {},数据",redisKey);//获取当前人员List list = securityUserService.getUserList();executorList = Lists.transform(list,(entity) -> {SecurityUserVO securityUserVO = new SecurityUserVO();BeanUtils.copyProperties(entity,securityUserVO);securityUserVO.setCount(0);return securityUserVO;});} else {log.info("redis key = {} , 缓存数据 = {}" , redisKey , JSONObject.toJSONString(executors));String executor = JSONUtil.toJsonStr(executors);JSONArray jsonArray = JSONUtil.parseArray(JSONUtil.toJsonStr(executor));executorList = jsonArray.toList(SecurityUserVO.class);}if (CollectionUtil.isNotEmpty(executorList)) {//获取当前最小值executorId = executorList.stream().min(Comparator.comparing(SecurityUserVO::getCount)).get().getId();log.info("平均分配被分配员工编号为:" + executorId);Long finalExecutorId = executorId;executorList.stream().filter(s -> s.getId() != null && finalExecutorId.equals(s.getId())).forEach(securityUserVO -> securityUserVO.setCount(securityUserVO.getCount() + 1));log.info("可分配员工list集合 = {}" + JSONObject.toJSONString(executorList));redisUtils.set(redisKey,executorList,600);return finalExecutorId;}return null;}}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!