码迷,mamicode.com
首页 > 其他好文 > 详细

排班管理

时间:2014-07-20 10:19:20      阅读:719      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

  首先是action类型
 1
package com.honghailt.dataextracter.web; 2 3 import java.util.ArrayList; 4 import java.util.Date; 5 import java.util.LinkedHashMap; 6 import java.util.List; 7 import java.util.Map; 8 9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.stereotype.Controller; 11 import org.springframework.ui.ModelMap; 12 import org.springframework.web.bind.annotation.RequestMapping; 13 import org.springframework.web.bind.annotation.ResponseBody; 14 15 import com.honghailt.dataextracter.model.OrderQuery; 16 import com.honghailt.dataextracter.model.TbfwScheduling; 17 import com.honghailt.dataextracter.model.TbfwSchedulingPerson; 18 import com.honghailt.dataextracter.model.User; 19 import com.honghailt.dataextracter.service.TbfwSchedulingService; 20 import com.honghailt.dataextracter.service.UserService; 21 import com.honghailt.dataextracter.utils.CalendarUtil; 22 23 @Controller 24 public class TbfwSchedulingController { 25 @Autowired 26 private TbfwSchedulingService schedulingService; 27 @Autowired 28 private UserService userService; 29 30 /** 31 * 显示排班 一次显示一个月 32 * @param dept 33 * @param chaxunDate 34 * @param order 35 * @param modelMap 36 * @return 37 */ 38 @RequestMapping("/showTbfwScheduling") 39 public String showTbfwScheduling( Date chaxunDate,OrderQuery order, ModelMap modelMap){ 40 //查询日期,默认为当前时间sad 41 if(chaxunDate == null){ 42 chaxunDate = new Date(); 43 } 44 //部门,默认为软件售后部 45 if(order == null || order.getNick()==null){ 46 order.setNick("二组"); 47 } 48 List<String> depts = new ArrayList<String>(); 49 depts.add("一组"); 50 depts.add("二组"); 51 modelMap.put("depts", depts); 52 //上班类型 53 List<String> types = new ArrayList<String>(); 54 types.add("值班"); 55 types.add("休班"); 56 modelMap.put("types", types); 57 //一个月所有周日期放里面 58 Map<String,List<String>> weekMap = new LinkedHashMap<String, List<String>>(); 59 int a=CalendarUtil.getWeekyofMonth(chaxunDate);//一共几周 60 chaxunDate =CalendarUtil.DateToDate(chaxunDate); 61 for(int i=0;i<=a;i++){ 62 String ds=CalendarUtil.getDanShuangWeek(CalendarUtil.getDayOfMonth(chaxunDate, i*7)); 63 weekMap.put(i+" "+ds, CalendarUtil.getWeeksOfMonth(chaxunDate, i)); 64 } 65 modelMap.put("week",weekMap); 66 order.setBegintime(chaxunDate); 67 Map<String,List<TbfwScheduling>> maps= schedulingService.getPersonMonth(order); 68 modelMap.put("weekChina", CalendarUtil.getWeekName()); 69 modelMap.put("maps", maps); 70 modelMap.put("order", order); 71 modelMap.put("chaxunDate", chaxunDate); 72 return "/TbfwScheduling/TbfwScheduling"; 73 } 74 /** 75 * 修改添加排班 76 * @param chaxunDate 77 * @param order 78 * @param modelMap 79 * @return 80 */ 81 @RequestMapping("/editTbfwScheduling") 82 public String editTbfwScheduling( Date chaxunDate,OrderQuery order, ModelMap modelMap){ 83 //查询日期,默认为当前时间 84 if(chaxunDate == null){ 85 chaxunDate = new Date(); 86 } 87 //部门,默认为软件售后部 88 if(order == null || order.getNick()==null){ 89 order.setNick("二组"); 90 } 91 List<String> depts = new ArrayList<String>(); 92 depts.add("一组"); 93 depts.add("二组"); 94 modelMap.put("depts", depts); 95 //上班类型 96 List<String> types = new ArrayList<String>(); 97 types.add("值班"); 98 types.add("休班"); 99 modelMap.put("types", types); 100 //一个月所有周日期放里面 101 Map<String,List<String>> weekMap = new LinkedHashMap<String, List<String>>(); 102 int a=CalendarUtil.getWeekyofMonth(chaxunDate);//一共几周 103 chaxunDate =CalendarUtil.DateToDate(chaxunDate); 104 for(int i=0;i<=a;i++){ 105 String ds=CalendarUtil.getDanShuangWeek(CalendarUtil.getDayOfMonth(chaxunDate, i*7)); 106 weekMap.put(i+" "+ds, CalendarUtil.getWeeksOfMonth(chaxunDate, i)); 107 } 108 modelMap.put("week",weekMap); 109 order.setBegintime(chaxunDate); 110 Map<String,List<TbfwScheduling>> maps= schedulingService.getPersonMonth(order); 111 modelMap.put("weekChina", CalendarUtil.getWeekName()); 112 modelMap.put("maps", maps); 113 modelMap.put("order", order); 114 modelMap.put("chaxunDate", chaxunDate); 115 return "/TbfwScheduling/TbfwSchedulingEdit"; 116 } 117 /** 118 * 显示人员列表 119 * @param tbfwScheduling 120 * @param modelMap 121 * @return 122 */ 123 @RequestMapping("/queryTbfwScheduling") 124 public String queryTbfwScheduling(TbfwScheduling tbfwScheduling,ModelMap modelMap){ 125 List<User> userList =userService.getUserListByDept(tbfwScheduling); 126 List<TbfwSchedulingPerson> personList=schedulingService.getPersonByDate(tbfwScheduling); 127 modelMap.put("userList", userList); 128 modelMap.put("personList", personList); 129 return "/TbfwScheduling/TbfwSchedulingPersonList"; 130 } 131 132 /** 133 * 更新数据库 134 * @param tbfwScheduling 135 * @return 136 */ 137 @RequestMapping("/updateTbfwScheduling") 138 @ResponseBody 139 public String updateTbfwScheduling(TbfwScheduling tbfwScheduling){ 140 String msg=null; 141 schedulingService.saveTbfwScheduling(tbfwScheduling); 142 msg = "success"; 143 return msg; 144 } 145 /** 146 * 自动排班 147 * @param tbfwScheduling 148 * @return 149 */ 150 @RequestMapping("/autoTbfwScheduling") 151 @ResponseBody 152 public String autoTbfwScheduling(TbfwScheduling tbfwScheduling){ 153 String msg=null; 154 schedulingService.autoTbfwScheduling(tbfwScheduling); 155 msg = "success"; 156 return msg; 157 } 158 /** 159 * 2014-07-18 23:35:10 160 * 首先把人名列出来,根据班组 161 * 然后分排班还是休班 162 * 先根据时间和班组把人查询出来 163 * 然后循环list 164 * 小A,时间,一组,排班 数量 165 * @param order 166 * @param modelMap 167 * @return 168 */ 169 @RequestMapping("/statisticsTbfwScheduling") 170 public String statisticsTbfwScheduling(TbfwScheduling tbfwScheduling, ModelMap modelMap){ 171 if(tbfwScheduling == null || tbfwScheduling.getBeginTime()== null){ 172 tbfwScheduling.setBeginTime(CalendarUtil.getFirstDayOfMonth(new Date())); 173 tbfwScheduling.setEndTime(CalendarUtil.getDateOfLastDayOfMonth(new Date())); 174 } 175 System.out.println("aaa"); 176 //部门,默认为软件售后部 177 if(tbfwScheduling == null || tbfwScheduling.getDept() == null){ 178 tbfwScheduling.setDept("二组"); 179 } 180 List<String> depts = new ArrayList<String>(); 181 depts.add("一组"); 182 depts.add("二组"); 183 modelMap.put("depts", depts); 184 185 List<User> userList =userService.getUserListByDept(tbfwScheduling); 186 List<String> types = new ArrayList<String>(); 187 types.add("休班"); 188 types.add("值班"); 189 List<TbfwSchedulingPerson> personList =schedulingService.statisticsTbfwScheduling(tbfwScheduling); 190 modelMap.put("types", types); 191 modelMap.put("personList", personList); 192 modelMap.put("userList", userList); 193 // modelMap.put("tbfwScheduling", tbfwScheduling); 194 return "/TbfwScheduling/TbfwSchedulingStatistics"; 195 } 196 }

然后是service类
  1 package com.honghailt.dataextracter.service;
  2 
  3 import java.util.ArrayList;
  4 import java.util.Date;
  5 import java.util.HashMap;
  6 import java.util.List;
  7 import java.util.Map;
  8 
  9 import org.springframework.beans.factory.annotation.Autowired;
 10 import org.springframework.stereotype.Service;
 11 
 12 import com.honghailt.dataextracter.mappers.ds1.TbfwSchedulingMapper;
 13 import com.honghailt.dataextracter.mappers.ds1.TbfwSchedulingPersonMapper;
 14 import com.honghailt.dataextracter.model.OrderQuery;
 15 import com.honghailt.dataextracter.model.TbfwScheduling;
 16 import com.honghailt.dataextracter.model.TbfwSchedulingPerson;
 17 import com.honghailt.dataextracter.model.User;
 18 import com.honghailt.dataextracter.utils.CalendarUtil;
 19 
 20 @Service
 21 public class TbfwSchedulingService {
 22     
 23     @Autowired
 24     private TbfwSchedulingMapper mapper;
 25     @Autowired
 26     private TbfwSchedulingPersonMapper personMapper;
 27     @Autowired
 28     private UserService userService;
 29     
 30     public Map<String, List<TbfwScheduling>> 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<String, List<TbfwScheduling>> map = new HashMap<String, List<TbfwScheduling>>();//
 38         List<TbfwScheduling> listZhiBan = new ArrayList<TbfwScheduling>();
 39         List<TbfwScheduling> listXiuBan = new ArrayList<TbfwScheduling>();
 40         List<TbfwScheduling> list =mapper.getTbfwSchedulingList(order);
 41         for (TbfwScheduling tbfwScheduling : list) {
 42         if(tbfwScheduling.getType().equals("值班")){
 43             List<TbfwSchedulingPerson> schedulingPersonList= personMapper.getTbfwSchedulingPersonList(tbfwScheduling);
 44             tbfwScheduling.setSchedulingPersonList(schedulingPersonList);
 45             listZhiBan.add(tbfwScheduling);
 46         }
 47         if(tbfwScheduling.getType().equals("休班")){
 48             List<TbfwSchedulingPerson> 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         return map;
 57     }
 58 
 59     public Map<String, List<TbfwScheduling>> 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<String, List<TbfwScheduling>> map = new HashMap<String, List<TbfwScheduling>>();//值班和休班所有TbfwScheduling
 68         List<TbfwScheduling> listZhiBan = new ArrayList<TbfwScheduling>();
 69         List<TbfwScheduling> listXiuBan = new ArrayList<TbfwScheduling>();
 70         List<TbfwScheduling> list =mapper.getTbfwSchedulingList(order);//查询出所有
 71         for (TbfwScheduling tbfwScheduling : list) {
 72         if(tbfwScheduling.getType().equals("值班")){//如果是值班
 73             List<TbfwSchedulingPerson> schedulingPersonList= personMapper.getTbfwSchedulingPersonList(tbfwScheduling);
 74             tbfwScheduling.setSchedulingPersonList(schedulingPersonList);//把人放在值班list里,下面同上
 75             listZhiBan.add(tbfwScheduling);
 76         }
 77         if(tbfwScheduling.getType().equals("休班")){
 78             List<TbfwSchedulingPerson> 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         return map;
 87     }
 88     
 89     
 90     
 91     public List<TbfwSchedulingPerson> getPersonByDate(TbfwScheduling tbfwScheduling) {
 92         List<TbfwSchedulingPerson> schedulingPersonList= personMapper.getTbfwSchedulingPersonList(tbfwScheduling);
 93         return schedulingPersonList;
 94     }
 95 
 96     public void saveTbfwScheduling(TbfwScheduling tbfwScheduling) {
 97          TbfwScheduling  model;
 98          List<TbfwScheduling> 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      * @param tbfwScheduling
127      */
128     public void autoTbfwScheduling(TbfwScheduling tbfwScheduling) {
129         List<User> userList =userService.getUserListByDept(tbfwScheduling);//获得所有人
130         int personN =this.getPersonNum(tbfwScheduling);//获得本月所要排班的人数
131         List<User>  list =new ArrayList<User>();//把人放到这个列表中
132          int usedPerson =0; //定义用过的人
133         while(true){ //用于把人放到这个列表里
134             for (int i=0;i<userList.size();i++) {
135                 list.add(userList.get(i));
136             }
137             if(list.size()>=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,List<User> list){
158         //单周的话值班12+4人
159         List<Date> list1= CalendarUtil.getDaysOfWeekDate(date1);//获得本周7天
160         for (int x=0;x<list1.size();x++) {//遍历每天
161             tbfwScheduling.setPaibanDate(list1.get(x));//设置第一周星期一的时间
162              TbfwScheduling  model;
163              List<TbfwScheduling> 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         return usedPerson;
264         
265     }
266     
267     public int getPersonNum(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         return personNum;
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<list.size() ;a++) {
297 //                list2.add(list.get(a));
298 //            }
299 //            if(list2.size()==i){
300 //                break;
301 //            }
302 //        }
303 //        System.out.println(list2);
304 //    }
305 
306     public List<TbfwSchedulingPerson> statisticsTbfwScheduling(TbfwScheduling tbfwScheduling) {
307         List<TbfwSchedulingPerson> list =personMapper.statisticsTbfwScheduling(tbfwScheduling);
308         return list;
309     }
310     
311     
312 }    
mapper.xml
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 3         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 4 <mapper namespace="com.honghailt.dataextracter.mappers.ds1.TbfwSchedulingMapper">
 5    
 6      <select id="getTbfwSchedulingList"  resultType="TbfwScheduling">
 7         SELECT
 8             id,
 9             paibanDate,
10             type,
11             dept
12         FROM de_tbfw_order_scheduling
13         WHERE 1=1
14         and date(paibanDate) between #{begintime:DATE} and #{endtime:DATE}
15         and dept =#{nick}
16     </select>
17     <select id="getListByDateAndType"  resultType="TbfwScheduling">
18         SELECT
19             id,
20             paibanDate,
21             type,
22             dept
23         FROM de_tbfw_order_scheduling
24         WHERE 1=1
25         and date(paibanDate) = #{paibanDate} 
26         and type =  #{type} 
27         and dept = #{dept}
28     </select>
29     <insert id="insert">
30         INSERT INTO de_tbfw_order_scheduling
31         (
32          paibanDate,
33         type,
34          dept)
35         VALUES
36             (#{paibanDate},
37              #{type},
38              #{dept}
39              );
40     </insert>
41 </mapper>
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 3         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 4 <mapper namespace="com.honghailt.dataextracter.mappers.ds1.TbfwSchedulingPersonMapper">
 5    
 6      <select id="getTbfwSchedulingPersonList"  resultType="TbfwSchedulingPerson">
 7         SELECT
 8             a.id,
 9             b.id as tbfwSchedulingId,
10             a.userId,
11             a.baiban
12         FROM (de_tbfw_order_schedulingperson a LEFT JOIN de_tbfw_order_scheduling b 
13         on a.tbfwSchedulingId = b.id)
14         WHERE 1=1
15         and date(b.paibanDate) = #{paibanDate:DATE}
16         and b.type = #{type}
17         and b.dept = #{dept}
18     </select>
19     
20      <!--  <select id="getTbfwSchedulingPersonList"  resultType="TbfwSchedulingPerson">
21         SELECT
22             a.id,
23             b.id as tbfwSchedulingId,
24             c.usrno as userId,
25               c.usrname as usrname
26         FROM (de_tbfw_order_schedulingperson a LEFT JOIN de_tbfw_order_scheduling b 
27         on a.tbfwSchedulingId = b.id) LEFT JOIN databus_user c on c.usrno = a.userId
28         WHERE 1=1
29         and date(b.paibanDate) = #{paibanDate:DATE}
30         and b.type = #{type}
31         and b.dept = #{dept}
32     </select> -->
33     <delete id="delete">
34     DELETE from de_tbfw_order_schedulingperson
35     WHERE tbfwSchedulingId =#{id}
36     </delete>
37     <insert id="insert">
38      INSERT INTO de_tbfw_order_schedulingperson
39         (tbfwSchedulingId,
40          userId,
41          baiban)
42         VALUES
43             ( #{param1},
44              #{param2},
45              #{param3});
46     </insert>
47     
48     <select id="statisticsTbfwScheduling"  resultType="TbfwSchedulingPerson">
49     SELECT
50     COUNT(p.id) AS statisticsCount,
51     c.dept,
52     c.type,
53     p.userId,
54     p.baiban
55     FROM
56     de_tbfw_order_schedulingperson p ,
57     de_tbfw_order_scheduling c
58     where
59     p.tbfwSchedulingId = c.id
60     and
61     date(c.paibanDate) between #{beginTime:DATE} and #{endTime:DATE}
62     AND c.dept =#{dept} 
63     GROUP BY
64     p.userId,
65     c.dept,
66     c.type,
67     p.baiban
68     </select>
69     
70     
71     
72     
73     
74 </mapper>

 

 

1.jsp

 1 <div class="main">
 2     <div style="text-align: center; font-size: 14px; font-weight: bold;">排班信息</div>
 3     <form id="form1" action="<c:url value="/showTbfwScheduling.do"/>" method="post" autocomplete="off">
 4         <div>
 5             所在部门:
 6       <select name="nick" >
 7           <c:forEach items="${depts}" var="dd">
 8                     <option value="${dd}" <c:if test="${dd==order.nick}">selected</c:if>>${dd}</option>
 9             </c:forEach>
10           </select>
11         
12          当前日期:<input type="text" name="chaxunDate"
13                         value="<fmt:formatDate pattern="yyyy-MM-dd" value="${chaxunDate}"/>"
14                         style="width: 100px;" maxlength="10" onClick="WdatePicker()">
15             <input type="submit" id="query" value=" 查 询 "></div>
16     </form>
17    <table class="grid">
18    <tr>
19             <th  style="width:80px"> &nbsp;</th>
20                 <c:forEach items="${weekChina}" var="china">
21                     <th><center>${china}</center></th> <!--  遍历表头 -->
22                 </c:forEach>
23             </tr>
24    
25   <c:forEach items="${week}" var="week1">
26             <tr>
27             <th  style="width:80px"> ${fn:substring(week1.key,2,4)}</th>
28                 <c:forEach items="${week1.value}" var="day1">
29                     <th>
30                       <fmt:formatDate var="cx" value="${chaxunDate}" pattern="yyyy-MM-dd"/>
31                     <c:if test="${cx eq day1}">
32                     <font color=red >${cx} </c:if>
33                     </font>
34                     <c:if test="${cx ne day1}">
35                     ${day1}</c:if>
36                     </th> <!--  遍历表头 -->
37                 </c:forEach>
38             </tr>
39     <c:forEach items="${types}" var="row" varStatus="num">
40             <tr>
41                 <td>${row}</td>  <!--  遍历类型 -->
42                 <c:forEach items="${maps}" var="map" varStatus="num1">
43                     <c:if test="${row eq map.key}">
44                           <c:forEach items="${week1.value}" var="day">
45                               <td>
46                                 <c:forEach items="${map.value}" var="aa" varStatus="num2">
47                                  <fmt:formatDate var="paibanDate" value="${aa.paibanDate}" pattern="yyyy-MM-dd"/>
48                                    <c:if test="${paibanDate eq day }">
49                                           <c:forEach items="${aa.schedulingPersonList}" var="person" varStatus="num1">
50                                           <c:if test="${person.baiban eq 1}">
51                                           <font color = red>    ${person.userId}</font>
52                                           </c:if>
53                                               <c:if test="${person.baiban ne 1}">
54                                           ${person.userId} 
55                                           </c:if>
56                                           
57                                            </c:forEach>
58                                    </c:if>
59                                  </c:forEach> 
60                             &nbsp;</td>
61                         </c:forEach>
62                     </c:if>
63                 </c:forEach>
64             </tr>
65         </c:forEach>
66 </c:forEach>    
67   </table>  
68 </div>
<body>
<div class="main">
    <div style="text-align: center; font-size: 14px; font-weight: bold;">排班信息</div>
      <form id="form1" action="<c:url value="/editTbfwScheduling.do"/>" method="post" autocomplete="off">
      <table>
      <tr>
      <td>
                        <div>
                            所在部门:
                             <select name="nick">
                                <c:forEach items="${depts}" var="dd">
                                    <option value="${dd}"
                                        <c:if test="${dd==order.nick}">selected</c:if>>${dd}</option>
                                </c:forEach>
                            </select>
                             当前日期:
                             <input type="text" name="chaxunDate" id="chaxunDate"
                                value="<fmt:formatDate pattern="yyyy-MM-dd" value="${chaxunDate}"/>"
                                style="width: 100px;" maxlength="10" onClick="WdatePicker()">
                            <input type="submit" id="query" value=" 查 询 ">
                        </div>

                    </td>
         <td style="text-align: right;">
      <input type="button" value="统计" onclick="aa()"/>
      </td>            
      <td style="text-align: right;">
      <input type="button" value="一鍵排班" onclick="autoScheduling()"/>
      </td>
      </tr>
      </table>
      
    </form>
    <div class="progress" style="display:none;">
  <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 100%;">
    <span class="sr-only">正在排班 ,请等待...</span>
  </div>
</div>
   <table class="grid">
   <tr>
            <th  style="width:80px"> &nbsp;</th>
                <c:forEach items="${weekChina}" var="china">
                    <th><center>${china}</center></th> <!--  遍历表头 -->
                </c:forEach>
            </tr>
   
  <c:forEach items="${week}" var="week1">
            <tr>
            <th  style="width:80px"> ${fn:substring(week1.key,2,4)}</th>
                <c:forEach items="${week1.value}" var="day1">
                    <th>
                      <fmt:formatDate var="cx" value="${chaxunDate}" pattern="yyyy-MM-dd"/>
                    <c:if test="${cx eq day1}">
                    <font color=red >${cx} </c:if>
                    </font>
                    <c:if test="${cx ne day1}">
                    ${day1}</c:if>
                    </th> <!--  遍历表头 -->
                </c:forEach>
            </tr>
    <c:forEach items="${types}" var="row" varStatus="num">
            <tr>
                <td>${row}</td>  <!--  遍历类型 -->
                <c:forEach items="${maps}" var="map" varStatus="num1">
                    <c:if test="${row eq map.key}">
                          <c:forEach items="${week1.value}" var="day">
                          <td ondblclick="showtbfwList(‘${row}‘,this,‘${day}‘)">
                                <c:forEach items="${map.value}" var="aa" varStatus="num2">
                                 <fmt:formatDate var="paibanDate" value="${aa.paibanDate}" pattern="yyyy-MM-dd"/>
                                   <c:if test="${paibanDate eq day }">
                                          <c:forEach items="${aa.schedulingPersonList}" var="person" varStatus="num1">
                                          <c:if test="${person.baiban eq 1}">
                                          <font color = red>    ${person.userId}</font>
                                          </c:if>
                                              <c:if test="${person.baiban ne 1}">
                                          ${person.userId} 
                                          </c:if>
                                          
                                           </c:forEach>
                                   </c:if>
                                 </c:forEach> 
                            &nbsp;</td>
                        </c:forEach>
                    </c:if>
                </c:forEach>
            </tr>
        </c:forEach>
</c:forEach>    
  </table>  
     
     
</div>
<script type="text/javascript">
function aa(){
    $(form1).attr("action","statisticsTbfwScheduling.do");// 填充内容 
  //  document.form1.action ="";
    $(form1).submit();
}

function autoScheduling(){
    var dept = $("select[name=nick] option:selected").val();
    var day  = $("#chaxunDate").val();
     if (confirm("自动排班后,本月排班将会重新排列,请谨慎点击!")) {
         $("div.progress").show();
         if (true) {
                $.ajax({
                    url : "<c:url value="/autoTbfwScheduling.do"/>",
                    type : "post",
                    data : {
                        type : "值班",
                        paibanDate : day,
                        dept : dept
                    },
                    dataType : "text",
                    success : function(data) {
                        $("div.progress").hide();
                        if (data == "success") {
                            alert("排班成功!");
                        } else {
                            alert("排班失败!");
                        }
                    }
                });

            }
       return true;
     }
    
}
function showtbfwList(type, indexa,day) {
    
    var dept = $("select[name=nick] option:selected").val();
      var result = window.showModalDialog("queryTbfwScheduling.do?type=" + type+"&paibanDate="+day+"&dept="+dept, "help:no;scroll:no;dialogWidth:300px; dialogHeight:300px");
    var ids=getAllIds(result);
      if (true) {
            $.ajax({
                url : "<c:url value="/updateTbfwScheduling.do"/>",
                type : "post",
                data : {
                    type : type,
                    paibanDate : day,
                    ids : ids,
                    dept : dept
                },
                dataType : "text",
                success : function(data) {
                    if (data == "success") {
                        alert("添加成功!");
                        $(form1).submit();
                    } else {
                        alert("添加失败!");
                    }
                }
            });

            //indexa.innerHTML = getAllNames(result);
        }
    }
    
    function getAllNames(obj) {
        // 用来保存所有的属性名称和值
        var props = "";
        // 开始遍历
        for ( var i = 0; i < obj.length; i++) {
            props = obj[i].usrname + "," + props;
        }
        props = props.substring(0, props.length - 1);
        // 最后显示所有的属性
        return props;
    }
    function getAllIds(obj) {
        // 用来保存所有的属性名称和值
        var props = "";
        // 开始遍历
        for ( var i = 0; i < obj.length; i++) {
            props = obj[i].usrno +":"+obj[i].baibans + "," + props;
        }
        props = props.substring(0, props.length - 1);
        // 最后显示所有的属性
        return props;
    
    }
    function getAllBaiBan(obj) {
        // 用来保存所有的属性名称和值
        var props = "";
        // 开始遍历
        for ( var i = 0; i < obj.length; i++) {
            props = obj[i].baibans + "," + props;
        }
        props = props.substring(0, props.length - 1);
        // 最后显示所有的属性
        return props;
    
    }
    
</script>
</body>
<body>
    <div><% String str =""; %>  </div>
   <center> <table class="grid">
        <tr>
                <th style="width:80px" colspan="2">&nbsp;
               <fmt:formatDate pattern="yyyy-MM-dd" value="${tbfwScheduling.paibanDate}"/>
            ${tbfwScheduling.type}人员列表
            </th>
            </tr> <tr>
        <c:forEach items="${userList}" var="user" varStatus="num">
                <td>
                <input type="checkbox" 
                <c:forEach items="${personList}" var="person" >
                        <c:if test="${person.userId eq user.usrname}">
                       checked
                        </c:if>
                </c:forEach>
                   name="ids" value="${user.usrno}">
                   <input type="checkbox" 
                <c:forEach items="${personList}" var="person1" >
                        <c:if test="${person1.userId eq user.usrname}">
                        <c:if test="${person1.baiban eq ‘1‘}">
                            checked
                        </c:if>
                        </c:if>
                </c:forEach>
                   name="baibans" value="${user.usrno}">
                   <input type = "hidden" name = "userinfo" value = "{usrno:‘${user.usrname}‘,usrname:‘${user.usrname}‘}">
                   ${user.usrname}
                </td>
            <c:if test="${(num.index % 2 ) eq 1}"></tr><tr></c:if>
            <c:if test="${num.index eq 6}"><td>&nbsp;</td></tr><tr></c:if>
        </c:forEach>
        
    </table></center>
</div>
  <div><center> <input type="button" value="确定" onclick="validateadd()"/></center></div>
    <script language="javascript">
        function validateadd() {
                var rtn = [];
              $("input[name=ids]:checked").siblings("input[name=userinfo]").each(function(i,n){
                  eval("obj=" + $(this).val());
                  if($(this).siblings("input[name=baibans]:checked").size()>0) {
                      obj.baibans = 1;
                  } else {
                      obj.baibans = 0;
                  }
                  console.log(JSON.stringify(obj));
                  rtn.push(obj);
              });
            
              window.returnValue=rtn;
             // alert(rtn);
              window.close();
              
        }
    </script>
</body>

 

<body>

<div class="main">
    <div style="text-align: center; font-size: 14px; font-weight: bold;">排班信息</div>
    <form id="form1" action="<c:url value="/statisticsTbfwScheduling.do"/>" method="post" autocomplete="off">
        <div>
            所在部门:
      <select name="dept" >
          <c:forEach items="${depts}" var="dd">
                    <option value="${dd}" <c:if test="${dd==tbfwScheduling.dept}">selected</c:if>>${dd}</option>
            </c:forEach>
          </select>
        
         开始日期:<input type="text" name=beginTime
                        value="<fmt:formatDate pattern="yyyy-MM-dd" value="${tbfwScheduling.beginTime}"/>"
                        style="width: 100px;" maxlength="10" onClick="WdatePicker()">
         结束日期:<input type="text" name=endTime
                        value="<fmt:formatDate pattern="yyyy-MM-dd" value="${tbfwScheduling.endTime}"/>"
                        style="width: 100px;" maxlength="10" onClick="WdatePicker()">                     
            <input type="submit" id="query" value=" 查 询 "> 
             <input type="button" value="编辑" onclick="aa()"/>
            </div>
    </form>
   <table class="grid">
   <tr>
    <th>人员</th>        
    
     <c:forEach items="${types}" var="type1">
     <th>${type1}</th>
     </c:forEach>
    </tr>
  
  <c:forEach items="${userList}" var="user">
   <tr>
        <td > ${user.usrname}</td>
    <c:forEach items="${types}" var="type">
    <td style="text-align: center;"> &nbsp; 
    <c:forEach items="${personList}" var="person">    
        <c:if test="${person.userId eq user.usrname}">
        <c:if test="${person.type eq type }">
        <c:if test="${person.type eq ‘值班‘}">
        
        <c:if test="${person.baiban eq ‘1‘ }">
        白班:<font color =red>${person.statisticsCount}</font>
        </c:if>
        <c:if test="${person.baiban eq ‘0‘ }">
        晚班:${person.statisticsCount}
        </c:if>
        
        </c:if>
        <c:if test="${person.type eq ‘休班‘ }">
        休班:${person.statisticsCount}
        </c:if>
        
        </c:if>
        </c:if>
        </c:forEach>
    </td>
        </c:forEach>
        </tr>
    </c:forEach>    

  </table>  
</div>
<script type="text/javascript">
function aa(){
    $(form1).attr("action","editTbfwScheduling.do");// 填充内容 
  //  document.form1.action ="";
    $(form1).submit();
}
</script>
</body>

排班管理,布布扣,bubuko.com

排班管理

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/w8104254/p/3855852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!