java 值班管理_排班管理

这是一个Java实现的排班管理系统,包括获取当前周和月份的值班与休班人员列表,根据日期获取值班人员,保存和更新排班信息,以及自动排班功能。系统使用了Spring框架,通过TbfwSchedulingMapper和TbfwSchedulingPersonMapper接口操作数据,并结合CalendarUtil工具类处理日期和时间。
摘要由CSDN通过智能技术生成

1 packagecom.honghailt.dataextracter.service;2

3 importjava.util.ArrayList;4 importjava.util.Date;5 importjava.util.HashMap;6 importjava.util.List;7 importjava.util.Map;8

9 importorg.springframework.beans.factory.annotation.Autowired;10 importorg.springframework.stereotype.Service;11

12 importcom.honghailt.dataextracter.mappers.ds1.TbfwSchedulingMapper;13 importcom.honghailt.dataextracter.mappers.ds1.TbfwSchedulingPersonMapper;14 importcom.honghailt.dataextracter.model.OrderQuery;15 importcom.honghailt.dataextracter.model.TbfwScheduling;16 importcom.honghailt.dataextracter.model.TbfwSchedulingPerson;17 importcom.honghailt.dataextracter.model.User;18 importcom.honghailt.dataextracter.utils.CalendarUtil;19

20 @Service21 public classTbfwSchedulingService {22

23 @Autowired24 privateTbfwSchedulingMapper mapper;25 @Autowired26 privateTbfwSchedulingPersonMapper personMapper;27 @Autowired28 privateUserService userService;29

30 public Map>getPerson(OrderQuery order) {31 if(order.getBegintime()!=null){32 Date week1= CalendarUtil.getNowWeekBeginDate(order.getBegintime(),0);33 Date week2 =CalendarUtil.getNowWeekBeginDate(order.getBegintime(),6);34 order.setBegintime(week1);35 order.setEndtime(week2);36 }37 Map> map = new HashMap>();//38 List listZhiBan = new ArrayList();39 List listXiuBan = new ArrayList();40 List list =mapper.getTbfwSchedulingList(order);41 for(TbfwScheduling tbfwScheduling : list) {42 if(tbfwScheduling.getType().equals("值班")){43 List schedulingPersonList=personMapper.getTbfwSchedulingPersonList(tbfwScheduling);44 tbfwScheduling.setSchedulingPersonList(schedulingPersonList);45 listZhiBan.add(tbfwScheduling);46 }47 if(tbfwScheduling.getType().equals("休班")){48 List schedulingPersonList=personMapper.getTbfwSchedulingPersonList(tbfwScheduling);49 tbfwScheduling.setSchedulingPersonList(schedulingPersonList);50 listXiuBan.add(tbfwScheduling);51 }52 }53 map.put("值班", listZhiBan);54 map.put("休班", listXiuBan);55 // //TODO Auto-generated method stub

56 returnmap;57 }58

59 public Map>getPersonMonth(OrderQuery order) {60 if(order.getBegintime()!=null){61 //先获得查询日所在月的第一天所在周的星期一 和所在月的最后一天所在周的星期天

62 Date week1= CalendarUtil.getNowWeekBeginDate(CalendarUtil.getFirstDayOfMonth(order.getBegintime()),0);63 Date week2 =CalendarUtil.getNowWeekBeginDate(CalendarUtil.getDateOfLastDayOfMonth(order.getBegintime()),6);64 order.setBegintime(week1);65 order.setEndtime(week2);66 }67 Map> map = new HashMap>();//值班和休班所有TbfwScheduling

68 List listZhiBan = new ArrayList();69 List listXiuBan = new ArrayList();70 List list =mapper.getTbfwSchedulingList(order);//查询出所有

71 for(TbfwScheduling tbfwScheduling : list) {72 if(tbfwScheduling.getType().equals("值班")){//如果是值班

73 List schedulingPersonList=personMapper.getTbfwSchedulingPersonList(tbfwScheduling);74 tbfwScheduling.setSchedulingPersonList(schedulingPersonList);//把人放在值班list里,下面同上

75 listZhiBan.add(tbfwScheduling);76 }77 if(tbfwScheduling.getType().equals("休班")){78 List schedulingPersonList=personMapper.getTbfwSchedulingPersonList(tbfwScheduling);79 tbfwScheduling.setSchedulingPersonList(schedulingPersonList);80 listXiuBan.add(tbfwScheduling);81 }82 }83 map.put("值班", listZhiBan);84 map.put("休班", listXiuBan);85 // //TODO Auto-generated method stub

86 returnmap;87 }88

89

90

91 public ListgetPersonByDate(TbfwScheduling tbfwScheduling) {92 List schedulingPersonList=personMapper.getTbfwSchedulingPersonList(tbfwScheduling);93 returnschedulingPersonList;94 }95

96 public voidsaveTbfwScheduling(TbfwScheduling tbfwScheduling) {97 TbfwScheduling model;98 List schedulingList =mapper.getListByDateAndType(tbfwScheduling);99 if(schedulingList!=null && schedulingList.size()>0){100 model =schedulingList.get(0);101 }else{102 mapper.insert(tbfwScheduling);103 schedulingList =mapper.getListByDateAndType(tbfwScheduling);104 model =schedulingList.get(0);105 }106 String ids =tbfwScheduling.getIds();107 System.out.println(ids+"--------");108 if(ids ==null || ids.equals("")){109 personMapper.delete(model);110 }111

112 if(ids !=null && !ids.equals("")){113 personMapper.delete(model);114 String[] aa =ids.split(",");115 for(String str : aa) {116 String[] bb=str.split(":");117 personMapper.insert(model.getId(),bb[0],bb[1]);118 }119 }120 }121

122 /**

123 * 先把本月周所有星期一,然后根据单双周获得所有日期124 * 从人员表中获得符合条件的人,重新建一个list,把相等数量的人数放在里面125 * 然后把保存126 *@paramtbfwScheduling127 */

128 public voidautoTbfwScheduling(TbfwScheduling tbfwScheduling) {129 List userList =userService.getUserListByDept(tbfwScheduling);//获得所有人

130 int personN =this.getPersonNum(tbfwScheduling);//获得本月所要排班的人数

131 List list =new ArrayList();//把人放到这个列表中

132 int usedPerson =0; //定义用过的人

133 while(true){ //用于把人放到这个列表里

134 for (int i=0;i=personN+2){138 break;139 }140 }141 int aa=0;142 for(User user : list) {143 System.out.print(user.getUsrname()+" "+aa++);144 }145 if(tbfwScheduling!=null){146 Date chaxunDate =tbfwScheduling.getPaibanDate();//获得查询时间

147 int a=CalendarUtil.getWeekyofMonth(chaxunDate);//获得本月共几周

148 for(int i=0;i<=a;i++){//遍历周149 //获得第一周,第二周,第三周

150 Date date1 =CalendarUtil.getDayOfMonth(CalendarUtil.DateToDate(chaxunDate), i*7);//获得本月第一天,每次循环加7

151 usedPerson = this.savePerson(tbfwScheduling, date1, usedPerson, list);152 }153 }154

155 }156

157 public int savePerson(TbfwScheduling tbfwScheduling,Date date1,int usedPerson,Listlist){158 //单周的话值班12+4人

159 List list1= CalendarUtil.getDaysOfWeekDate(date1);//获得本周7天

160 for (int x=0;x

161 tbfwScheduling.setPaibanDate(list1.get(x));//设置第一周星期一的时间

162 TbfwScheduling model;163 List schedulingList = mapper.getListByDateAndType(tbfwScheduling);//查询是否有本日记录

164 if(schedulingList!=null && schedulingList.size()>0){//有就取,没有就添加

165 model =schedulingList.get(0);166 }else{167 mapper.insert(tbfwScheduling);168 schedulingList =mapper.getListByDateAndType(tbfwScheduling);169 model =schedulingList.get(0);170 }171 personMapper.delete(model);172

173 if(x<=4){174 if(model.getDept().equals("一组")){175 for (int b = 0; b < 1; b++) {176 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");177 usedPerson = usedPerson + 1;178

179 }180 }181 if(model.getDept().equals("二组")){182 for (int b = 0; b < 2; b++) {183 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");184 usedPerson = usedPerson + 1;185

186 }187 }188

189 }190 if( CalendarUtil.getDanShuangWeek(date1).equals("单周")){191 if(x==5){192 if(model.getDept().equals("一组")){193 for (int b = 0; b < 1; b++) {194 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");195 usedPerson = usedPerson + 1;196 System.out.println(usedPerson+"x=5)"+list.get(usedPerson).getUsrname() );197 }198 }199 if(model.getDept().equals("二组")){200 for (int b = 0; b < 2; b++) {201 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");202 usedPerson = usedPerson + 1;203 System.out.println(usedPerson+"x=5)"+list.get(usedPerson).getUsrname() );204 }205 }206 }207 if(x==6){208 if(model.getDept().equals("一组")){209 for (int b = 0; b < 1; b++) {210 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");211 usedPerson = usedPerson + 1;212

213 }214 for (int b = 0; b < 1; b++) {215 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),1+"");216 usedPerson = usedPerson + 1;217

218 }219 }220 if(model.getDept().equals("二组")){221 for (int b = 0; b < 2; b++) {222 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");223 usedPerson = usedPerson + 1;224

225 }226 for (int b = 0; b < 2; b++) {227 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),1+"");228 usedPerson = usedPerson + 1;229

230 }231 }232 }233 }234

235 if( CalendarUtil.getDanShuangWeek(date1).equals("双周")){236 if(x>=5){237 if(model.getDept().equals("一组")){238 for (int b = 0; b < 1; b++) {239 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");240 usedPerson = usedPerson + 1;241 }242 for (int b = 0; b < 1; b++) {243 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),1+"");244 usedPerson = usedPerson + 1;245 }246 }247 if(model.getDept().equals("二组")){248 for (int b = 0; b < 2; b++) {249 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),0+"");250 usedPerson = usedPerson + 1;251

252 }253 for (int b = 0; b < 2; b++) {254 personMapper.insert(model.getId(), list.get(usedPerson).getUsrname(),1+"");255 usedPerson = usedPerson + 1;256

257 }258 }259 }260 }261 }262 //263 returnusedPerson;264

265 }266

267 public intgetPersonNum(TbfwScheduling tbfwScheduling){268 int personNum =0;269 if(tbfwScheduling!=null){270 Date chaxunDate =tbfwScheduling.getPaibanDate();271 int a=CalendarUtil.getWeekyofMonth(chaxunDate);//一共几周

272

273 for(int i=0;i<=a;i++){274 //获得第一周

275 Date date1 =CalendarUtil.getDayOfMonth(CalendarUtil.DateToDate(chaxunDate), i*7);//获得第一周

276 if(CalendarUtil.getDanShuangWeek(date1).equals("单周")){//单周的话值班6人277 //首先查询 本周日期,然后根据条件查询出来,有不变,周一到周五set人,没有就删除

278 personNum=personNum+10+6;279 //280 }else{281 personNum=personNum+10+8;282 }283 }284 }285 returnpersonNum;286 }287

288 //public static void main(String[] args) {289 //List list =new ArrayList<>();290 //list.add(1);291 //list.add(2);292 //List list2 =new ArrayList<>();293 //int i=10;294 //

295 //while(true){296 //for (int a=0; a

305

306 public ListstatisticsTbfwScheduling(TbfwScheduling tbfwScheduling) {307 List list =personMapper.statisticsTbfwScheduling(tbfwScheduling);308 returnlist;309 }310

311

312 }

mapper.xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值