java 员工轮询值班排班 开发设计(mysql+redis)
生活随笔
收集整理的這篇文章主要介紹了
java 员工轮询值班排班 开发设计(mysql+redis)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
JAVA 員工輪詢 值班 排班
?
1.設(shè)計一個值班歷史紀錄表 duty_employee_history(area_id,dept_id) 聯(lián)合主鍵,存放已值班過的數(shù)據(jù)
area_id? int(11) NOT NULL? ?區(qū)域?dep_id? int(11) NOT NULL 部門employee_ids? ?varchar(2000) NOT NULL? 已值班過的 ,號分隔 格式 ,12,22,3,45, 前后要有逗號 防止 45 匹配456 這樣的數(shù)據(jù)2.值班表 duty
? 從值班表中拿到當前部門當前區(qū)域 正在值班的employee? ?List<Integer>? ?dutyEmpIdList? ?(可以存放到Redis)
3.? 從duty_history 中拿出? 當前排班部門區(qū)域的唯一一條數(shù)據(jù)DutyEmployeeHistory?、 一個部門區(qū)域只有一條數(shù)據(jù),可以不擔心效率問題
DutyEmployeeHistory dutyEmployeeHistory = dutyEmployeeHistoryDao.selectByPrimaryKey(key); //如果為null 插入一條新的 第一個值班人員從值班人員list中隨便拿一個 if(null == dutyEmployeeHistory){dutyEmployeeHistory = new DutyEmployeeHistory();dutyEmployeeHistory.setOrgAreaId(areaId);dutyEmployeeHistory.setDepId(deptId);dutyEmployeeHistory.setFlowTypeId(flowTypeId);dutyEmployeeHistory.setEmployeeIds(","+dutyEmpIdList.get(0)+","); //第一個值班人員dutyEmployeeHistoryDao.insertSelective(dutyEmployeeHistory);return dutyEmpIdList.get(0); //返回第一個值班人員 }else {//遍歷值班員工,如果在已經(jīng)值班歷史中沒有,則將該員工追加到歷史 employeeIds 后面//返回追加的該員工 即當前值班的員工String employeeIds = dutyEmployeeHistory.getEmployeeIds();for (Integer empId:dutyEmpIdList) {boolean contains = employeeIds.contains("," + empId + ",");if(!contains){//如果已值班員工中不存在 當前員工,追加后面返回即可employeeIds+=empId+",";dutyEmployeeHistory.setEmployeeIds(employeeIds);dutyEmployeeHistoryDao.updateByPrimaryKeySelective(dutyEmployeeHistory);return empId;}}//該列表員工都已值過班,比較先后順序 最后面的為最新的值班數(shù)據(jù)。Integer result = dutyEmpIdList.get(0);int index = employeeIds.indexOf("," + result + ",");int temp_index = 0;//判斷 該list中的值班員工在 歷史中的順序,順序越靠前的優(yōu)先值班for (int i=0;i<dutyEmpIdList.size();i++) {temp_index = employeeIds.indexOf("," + dutyEmpIdList.get(i) + ",");if(temp_index<index){index = temp_index;result = dutyEmpIdList.get(i);}}//修改 duty_employee_history 表中的值班數(shù)據(jù)。employeeIds = employeeIds.replaceAll(","+result+",",",");employeeIds+=result+",";dutyEmployeeHistory.setEmployeeIds(employeeIds);dutyEmployeeHistoryDao.updateByPrimaryKeySelective(dutyEmployeeHistory); return result; //該result為當前值班的員工 }?
?
有好方案? 還望騷擾? ?共同進步!!!!
?
?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的java 员工轮询值班排班 开发设计(mysql+redis)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 罗斯蒙特流量计调试需要考虑的两大方面
- 下一篇: 2018:寒冬下的温暖