1 importcn.hutool.core.util.StrUtil;2 importorg.apache.commons.beanutils.BeanMap;3 importorg.apache.shiro.authz.annotation.RequiresPermissions;4 importorg.springframework.beans.factory.annotation.Autowired;5 importorg.springframework.stereotype.Controller;6 importorg.springframework.ui.Model;7 import org.springframework.web.bind.annotation.*;8
9 importjavax.servlet.http.HttpServletRequest;10 importjava.sql.Timestamp;11 import java.util.*;12
13 /**
14 * 人员排班15 *@authorzzx16 * @email zhengzhaojava@163.com17 * @date 2020-08-18 13:32:2218 */
19
20 @Controller21 @RequestMapping("/centerInfo/personSchedul")22 public class PersonSchedulController extendsBaseController {23 @Autowired24 privatePersonSchedulService personSchedulService;25 /**
26 * @Description 页面初始化功能27 * @Author zhengzhaoxiang28 * @Date 2020/8/24 15:0329 * @Param [model]30 * @Return java.lang.String31 */
32 @GetMapping()33 @RequiresPermissions("centerInfo:personSchedul:personSchedul")34 String PersonSchedul(Model model){35 model.addAttribute("orgCode2",getOrgCode());36 return "centerInfo/perSchedul/personSchedul";37 }38
39 @ResponseBody40 @PostMapping("/list")41 public List list(@RequestParam Mapparams){42 //查询列表数据
43 List personSchedulList =personSchedulService.list(params);44 returnpersonSchedulList;45 }46
47 /**
48 * @Description 添加页面49 * @Author zhengzhaoxiang50 * @Date 2020/8/24 15:0051 * @Param [model]52 * @Return java.lang.String53 */
54 @GetMapping("/add")55 String add(HttpServletRequest request,Model model){56 String currDate = request.getParameter("date");57 //当前日期
58 model.addAttribute("currDate",currDate);59 model.addAttribute("orgCode",getOrgCode());60 return "centerInfo/perSchedul/add";61 }62
63 /**
64 * @Description 修改页面,同时返回 回显信息。65 * @Author zhengzhaoxiang66 * @Date 2020/8/24 15:0167 * @Param [id, model]68 * @Return java.lang.String69 */
70 @GetMapping("/edit/{id}")71 String edit(@PathVariable("id") Integer id,Model model){72 PersonSchedulDO personSchedul =personSchedulService.get(id);73 Map personSchedulMap = new HashMap<>();74 Map map = newBeanMap(personSchedul);75 personSchedulMap.putAll(map);76 Date startTime =personSchedul.getStartTime();77 String times =DateUtils.formatDate(startTime, DateUtils.DATE_TIME_PATTERN);78 //修改页面的日期和时间是分开存储的
79 if(StrUtil.isNotBlank(times)){80 String[] time = times.split(" ");81 personSchedulMap.put("beginDay",time[0]);82 personSchedulMap.put("beginTime",time[1].substring(0,5));83 }84 Date endTime =personSchedul.getEndTime();85 String endTimes =DateUtils.formatDate(endTime, DateUtils.DATE_TIME_PATTERN);86 if(StrUtil.isNotBlank(endTimes)){87 String[] time = endTimes.split(" ");88 personSchedulMap.put("endDay",time[0]);89 personSchedulMap.put("endTime",time[1].substring(0,5));90 }91 model.addAttribute("personSchedul", personSchedulMap);92 return "centerInfo/perSchedul/edit";93 }94
95 /**
96 * @Description 保存, 需求修改:为了方便后期单个任务的修改,这里将 开始时间 与 结束时间 区间进行拆分,每一个时间存储一个单独的任务,方便后期其他处理97 * @Author zhengzhaoxiang98 * @Date 2020/8/24 15:0099 * @Param100 * @Return101 */
102 @ResponseBody103 @PostMapping("/save")104 @RequiresPermissions("centerInfo:personSchedul:add")105 publicR save(HttpServletRequest request){106 //获取所属分拨中心
107 String orgCode = request.getParameter("orgCode");108 //获取员工姓名
109 String staffName = request.getParameter("staffName");110 //开始日期
111 String beginDay = request.getParameter("beginDay");112 //结束日期
113 String endDay = request.getParameter("endDay");114 //工作时间
115 String beginTime = request.getParameter("beginTime");116 //工作时间
117 String endTime = request.getParameter("endTime");118 //数据校验
119 R x =checkSaveAndUpdate(staffName, beginDay, endDay, beginTime, endTime,orgCode);120 if (x != null) returnx;121 //备注
122 String remark = request.getParameter("remark");123 //组装数据
124 PersonSchedulDO personSchedulDO =getPersonSchedulDO(orgCode, staffName, beginDay, beginDay, beginTime, endTime, remark);125 /**
126 * 组装保存的对象:根据 startDay 与 endDay 进行循环插入多条127 */
128 int start = Integer.valueOf(beginDay.replace("-", ""));129 int end = Integer.valueOf(endDay.replace("-", ""));130 //开始时间
131 String startTimeString =personSchedulDO.getStartTime().toString();132 //结束时间
133 String endTimeString =personSchedulDO.getEndTime().toString();134 for(int i=start; i<= end; i++){135 //开始时间
136 String dateAfterDays = DateUtils.getDateAfterNDays(startTimeString, i-start);137 //结束时间
138 String dateEndDays = DateUtils.getDateAfterNDays(endTimeString, i-start);139 //修改组装数据的 startTime 和 endTime
140 personSchedulDO.setStartTime(DateUtils.getDateFromString(dateAfterDays,DateUtils.DATE_FORMAT_DATETIME));141 personSchedulDO.setEndTime(DateUtils.getDateFromString(dateEndDays,DateUtils.DATE_FORMAT_DATETIME));142 //入库
143 personSchedulService.save(personSchedulDO);144 }145 returnR.ok();146 }147
148 /**
149 * @Description 增加修改时,数据封装150 * @Author zhengzhaoxiang151 * @Date 2020/8/24 15:05152 * @Param [orgCode, staffName, beginDay, endDay, beginTime, endTime, remark]153 * @Return com.yunda.base.centerInfo.domain.PersonSchedulDO154 */
155 privatePersonSchedulDO getPersonSchedulDO(String orgCode, String staffName, String beginDay, String endDay, String beginTime, String endTime, String remark) {156 //创建需要进行存库的对象
157 PersonSchedulDO personSchedulDO = newPersonSchedulDO();158 personSchedulDO.setOrgCode(orgCode);159 personSchedulDO.setStaffName(staffName);160 personSchedulDO.setRemark(remark);161 //组装时间
162 String newBegintime = beginDay + " " + beginTime + ":00";163 String newEndtime = endDay + " " + endTime + ":00";164
165 personSchedulDO.setStartTime(Timestamp.valueOf(newBegintime));166 personSchedulDO.setEndTime(Timestamp.valueOf(newEndtime));167 returnpersonSchedulDO;168 }169
170 /**
171 * @Description 修改172 * @Author zhengzhaoxiang173 * @Date 2020/8/24 15:02174 * @Param175 * @Return176 */
177 @ResponseBody178 @RequestMapping("/update")179 @RequiresPermissions("centerInfo:personSchedul:edit")180 publicR update( HttpServletRequest request){181 //获取用户ID
182 String id = request.getParameter("id");183 if(StrUtil.isBlank(id)){184 return R.error("id不能为空");185 }186 //获取所属分拨中心
187 String orgCode = request.getParameter("orgCode");188 //获取员工姓名
189 String staffName = request.getParameter("staffName");190 //工作日期
191 String beginDay = request.getParameter("beginDay");192 //工作时间
193 String beginTime = request.getParameter("beginTime");194 //工作时间
195 String endTime = request.getParameter("endTime");196 //数据校验
197 R x =checkSaveAndUpdate(staffName, beginDay, beginDay, beginTime, endTime,orgCode);198 if (x != null) returnx;199 //备注
200 String remark = request.getParameter("remark");201 //组装保存的对象
202 PersonSchedulDO personSchedulDO =getPersonSchedulDO(orgCode, staffName, beginDay, beginDay, beginTime, endTime, remark);203 personSchedulDO.setId(Integer.valueOf(id));204 personSchedulService.update(personSchedulDO);205 returnR.ok();206 }207
208 /**
209 * @Description 删除210 * @Author zhengzhaoxiang211 * @Date 2020/8/24 15:02212 * @Param213 * @Return214 */
215 @PostMapping( "/remove")216 @ResponseBody217 publicR remove( String id){218 if(StrUtil.isNotBlank(id) && personSchedulService.remove(Integer.valueOf(id))>0){219 returnR.ok();220 }221 returnR.error();222 }223
224 /**
225 * @Description 批量删除226 * @Author zhengzhaoxiang227 * @Date 2020/8/24 15:03228 * @Param229 * @Return230 */
231 @PostMapping( "/batchRemove")232 @ResponseBody233 @RequiresPermissions("centerInfo:personSchedul:batchRemove")234 public R remove(@RequestParam("ids[]") Integer[] ids){235 personSchedulService.batchRemove(ids);236 returnR.ok();237 }238
239
240 /**
241 * @Description 拖动任务时,进行时间上的处理242 * @Author zhengzhaoxiang243 * @Date 2020/8/24 15:04244 * @Param [request]245 * @Return com.yunda.base.common.utils.R246 */
247 @PostMapping("/dropView")248 @ResponseBody249 publicR dropView(HttpServletRequest request){250 String id = request.getParameter("id");251 if(StrUtil.isBlank(id)){252 return R.error("id 不能为空");253 }254 String dayDelta = request.getParameter("dayDelta");255 if(StrUtil.isBlank(dayDelta)){256 return R.error("dayDelta");257 }258 //拖动日期进行计算
259 PersonSchedulDO personSchedulDO =personSchedulService.get(Integer.valueOf(id));260 Date startTime =personSchedulDO.getStartTime();261 String dateTime =DateUtils.formatDate(startTime, DateUtils.DATE_TIME_PATTERN);262 String dateAfterNDays =DateUtils.getDateAfterNDays(dateTime, Integer.valueOf(dayDelta));263 //日期
264 Date dateFromString =DateUtils.getDateFromString(dateAfterNDays, DateUtils.DATE_TIME_PATTERN);265 personSchedulDO.setStartTime(dateFromString);266 //根据ID进行更新
267 personSchedulService.update(personSchedulDO);268 returnR.ok();269 }270 }