package com.xcgl.weeklyschedule.controller; import java.io.IOException; import java.math.BigDecimal; import java.net.URI; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.ConstraintViolation; import javax.validation.Validator; import org.apache.log4j.Logger; import org.jeecgframework.core.beanvalidator.BeanValidators; import org.jeecgframework.core.common.controller.BaseController; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.DateUtils; import org.jeecgframework.core.util.ExceptionUtil; import org.jeecgframework.core.util.JeecgDataAutorUtils; import org.jeecgframework.core.util.MyBeanUtils; import org.jeecgframework.core.util.ResourceUtil; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.minidao.pojo.MiniDaoPage; import org.jeecgframework.p3.core.utils.common.StringUtils; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.UriComponentsBuilder; import com.xcgl.projecttask.entity.ProjecttaskEntity; import com.xcgl.reports.dao.XcglRptDao; import com.xcgl.utils.XcglConstant; import com.xcgl.utils.XcglDateUtils; import com.xcgl.weeklyschedule.dao.WeeklyScheduleMiniDao; import com.xcgl.weeklyschedule.entity.WeeklyScheduleDayDto; import com.xcgl.weeklyschedule.entity.WeeklySchedulePartiEntity; import com.xcgl.weeklyschedule.entity.WeeklyScheduleUtils; import com.xcgl.weeklyschedule.entity.WeeklyscheduleEntity; import com.xcgl.weeklyschedule.service.WeeklyScheduleServiceI; import com.xcgl.weixin.dao.WXDao; import com.xcgl.weixin.entity.WXMultiRowViewer; import com.xcgl.weixin.entity.WXMultiRowViewerDto; import com.xcgl.weixin.service.WXServiceI; import com.xcgl.weixin.utils.WXViewerUtils; import cn.com.lzt.arrangedutyoperate.dto.UserAndUserPersonnelDto; @Controller @RequestMapping(value = "/weeklyscheduleController") public class WeeklyScheduleController extends BaseController { private static final Logger logger = Logger.getLogger(WeeklyScheduleController.class); @Autowired WeeklyScheduleServiceI weeklyscheduleService ; @Autowired private SystemService systemService; @Autowired private Validator validator; @Autowired WXDao wxdao; @Autowired private WeeklyScheduleMiniDao weeklyScheduleMiniDao; @Autowired WXServiceI wxservice; @Autowired private XcglRptDao rptDao; /** * 工作周报列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("com/xcgl/weeklyschedule/weeklyscheduleList"); } @RequestMapping(params = "todayScheduledList") public ModelAndView dayScheduledList(HttpServletRequest request) { String date = request.getParameter("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd EEEE",Locale.CHINA); Date today = null; try { today = sdf.parse(date); } catch (ParseException e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); } request.setAttribute("date", date); request.setAttribute("title", sdf2.format(today)+" 工作安排"); request.setAttribute("htmlurl", "weeklyscheduleController.do?dayScheduledHtml&date="+date); return new ModelAndView("cn/com/lzt/wxviewer/wxMultirowViewer"); } @RequestMapping(params = "dayScheduledHtml") @ResponseBody public AjaxJson dayScheduledHtml(HttpServletRequest request, HttpServletResponse response, String date) { date = request.getParameter("date"); String message = null; AjaxJson j = new AjaxJson(); String html= ""; try { html = getDaySchelduledHtml(date); } catch (Exception e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); e.printStackTrace(); } j.setObj(html); j.setMsg(message); return j; } /** * @param date * @return * @throws Exception * @throws ParseException */ private String getDaySchelduledHtml(String date) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List dblist = weeklyscheduleService.getWeeklyScheduleDtosBySomeDate(sdf.parse(date)); Collections.sort(dblist); List showlist = new ArrayList(); for(WeeklyScheduleDayDto dbdto : dblist) { if(dbdto.getWhatAmZjl() != null && dbdto.getWhatAmZjl().length()>0) { WXMultiRowViewerDto damzjl = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // damzjl.setDivTitle(user.getRealName()+" 上午"); damzjl.setMainContent(""+user.getRealName()+": " + dbdto.getWhatAmZjl()+"【闵总安排】"); damzjl.setSecondContent(dbdto.getWhereAm() == null ? "地点:无" : "地点:"+dbdto.getWhereAm()); damzjl.setThirdContent(dbdto.getWhoNamesAm() == null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesAm()); damzjl.setRightTag("上午"); showlist.add(damzjl); } if(dbdto.getWhatAm() != null && dbdto.getWhatAm().length()>0) { WXMultiRowViewerDto dam = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dam.setDivTitle(user.getRealName()+" 上午"); dam.setMainContent(""+user.getRealName()+": " + dbdto.getWhatAm()); dam.setSecondContent(dbdto.getWhereAm() == null ? "地点:无" : "地点:"+dbdto.getWhereAm()); dam.setThirdContent(dbdto.getWhoNamesAm() == null ?"参与人:无" : "参与人:"+ dbdto.getWhoNamesAm()); dam.setRightTag("上午"); showlist.add(dam); } if(dbdto.getWhatPmZjl() != null && dbdto.getWhatPmZjl().length()>0) { WXMultiRowViewerDto dpmzjl = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dpmzjl.setDivTitle(user.getRealName()+" 下午"); dpmzjl.setMainContent(""+user.getRealName()+": "+dbdto.getWhatPmZjl()+"【闵总安排】"); dpmzjl.setSecondContent(dbdto.getWherePm()== null ? "地点:无" : "地点:"+dbdto.getWherePm()); dpmzjl.setThirdContent(dbdto.getWhoNamesPm()== null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesPm()); dpmzjl.setRightTag("下午"); showlist.add(dpmzjl); } if(dbdto.getWhatPm() != null && dbdto.getWhatPm().length()>0) { WXMultiRowViewerDto dpm = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dpm.setDivTitle(user.getRealName()+" 下午"); dpm.setMainContent(""+user.getRealName()+": "+dbdto.getWhatPm()); dpm.setSecondContent(dbdto.getWherePm()== null ? "地点:无" : "地点:"+dbdto.getWherePm()); dpm.setThirdContent(dbdto.getWhoNamesPm()== null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesPm()); dpm.setRightTag("下午"); showlist.add(dpm); } } WXMultiRowViewer viewer = new WXMultiRowViewer(); viewer.setRows(showlist); viewer.setTitle(date); viewer.setWarning(getNoSchedulePersons(date)); return WXViewerUtils.getWXMultiRowViewerHtml(viewer); } /** * @param date * @return * @throws Exception */ private String getNoSchedulePersons(String date) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List> userList = new ArrayList>(); userList = wxdao.getUsersByRoleCode(XcglConstant.ROLE_ZHOUBAO); List entits = weeklyscheduleService.getWeeklyScheduleBySomeDate(sdf.parse(date)); HashMap hm_user3schedule = new HashMap<>(); if(entits != null && entits.size()>0) { StringBuffer sb = new StringBuffer(); for(WeeklyscheduleEntity entity : entits) { String userid = entity.getUserid(); hm_user3schedule.put(userid, entity); } for(Map user : userList) { if(!hm_user3schedule.containsKey(user.get("id"))){ sb.append("【").append(user.get("realname")).append("】"); }else { WeeklyscheduleEntity entity = hm_user3schedule.get(user.get("id")); if(entity == null) { sb.append("【").append(user.get("realname")).append("】"); }else { String what = WeeklyScheduleUtils.getPersonalWhat(entity); if(what == null || what.length() == 0) { sb.append("【").append(user.get("realname")).append("】"); } } } } if(sb.length()>0) { sb.append("未提交周报."); } return sb.toString(); } return null; } @RequestMapping(params = "yesterdayWorkList") public ModelAndView yesterdayWorkList(HttpServletRequest request) { String date = request.getParameter("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd EEEE",Locale.CHINA); Date today = null; try { today = sdf.parse(date); } catch (ParseException e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); } Calendar cal = Calendar.getInstance(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, -1); request.setAttribute("date", sdf.format(cal.getTime())); request.setAttribute("title", sdf2.format(cal.getTime())+" 完成情况"); request.setAttribute("htmlurl", "weeklyscheduleController.do?yesterdayWorkHtml&date="+date); return new ModelAndView("cn/com/lzt/wxviewer/wxMultirowViewer"); } @RequestMapping(params = "yesterdayWorkHtml") @ResponseBody public AjaxJson yesterdayWorkHtml(HttpServletRequest request, HttpServletResponse response, String date) { date = request.getParameter("date"); String message = null; AjaxJson j = new AjaxJson(); String html= ""; try { html = getYestdayWorkAchievementsHtml(date); } catch (Exception e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); e.printStackTrace(); } j.setObj(html); j.setMsg(message); return j; } /** * @param date * @return * @throws Exception * @throws ParseException */ private String getYestdayWorkAchievementsHtml(String date) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date today = sdf.parse(date); Calendar cal = Calendar.getInstance(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, -1); List dblist = weeklyscheduleService.getWeeklyScheduleDtosBySomeDate(cal.getTime()); Collections.sort(dblist); List showlist = new ArrayList(); String weeklyid = null; List tasks = new ArrayList<>(); HashMap taskMap = new HashMap<>(); SimpleDateFormat sdftime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // 去掉boss for(int i=dblist.size()-1 ; i>-1 ; i--) { WeeklyScheduleDayDto dto = dblist.get(i); if(Globals.BOSS_ID.equals(dto.getUserid())) { dblist.remove(i); } } for(WeeklyScheduleDayDto dbdto : dblist) { if(weeklyid == null) { weeklyid = dbdto.getId(); String hql = "from ProjecttaskEntity where 1=1 and sourceid=? "; tasks = systemService.findHql(hql, weeklyid); for(ProjecttaskEntity task : tasks) { taskMap.put(sdftime.format(task.getPlanstarttime())+";"+task.getOwner(), task); } } ProjecttaskEntity taskEntityAm = taskMap.get(sdf.format(cal.getTime())+" 08:30:00;"+dbdto.getUserid()); ProjecttaskEntity taskEntityPm = taskMap.get(sdf.format(cal.getTime())+" 13:30:00;"+dbdto.getUserid()); if(dbdto.getWhatAmZjl() != null && dbdto.getWhatAmZjl().length()>0) { WXMultiRowViewerDto damzjl = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // damzjl.setDivTitle(user.getRealName()+" 上午"); damzjl.setMainContent(""+user.getRealName()+": "+dbdto.getWhatAmZjl()+"【闵总安排】"); damzjl.setSecondContent(dbdto.getWhereAm() == null ? "地点:无" : "地点:"+dbdto.getWhereAm()); damzjl.setThirdContent(dbdto.getWhoNamesAm() == null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesAm()); damzjl.setDeleteView(taskEntityAm != null && taskEntityAm.getTaskstatus() != null && XcglConstant.TASKSTATUS_DONE.equals(taskEntityAm.getTaskstatus())); if(damzjl.isDeleteView()) { damzjl.setRightTag("已完成"); }else { damzjl.setRightTag("未完成"); } showlist.add(damzjl); } if(dbdto.getWhatAm() != null && dbdto.getWhatAm().length()>0) { WXMultiRowViewerDto dam = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dam.setDivTitle(user.getRealName()+" 上午"); dam.setMainContent(""+user.getRealName()+": "+dbdto.getWhatAm()); dam.setSecondContent(dbdto.getWhereAm() == null ? "地点:无" : "地点:"+dbdto.getWhereAm()); dam.setThirdContent(dbdto.getWhoNamesAm() == null ?"参与人:无" : "参与人:"+ dbdto.getWhoNamesAm()); dam.setDeleteView(taskEntityAm != null && taskEntityAm.getTaskstatus() != null && XcglConstant.TASKSTATUS_DONE.equals(taskEntityAm.getTaskstatus())); if(dam.isDeleteView()) { dam.setRightTag("已完成"); }else { dam.setRightTag("未完成"); } showlist.add(dam); } if(dbdto.getWhatPmZjl() != null && dbdto.getWhatPmZjl().length()>0) { WXMultiRowViewerDto dpmzjl = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dpmzjl.setDivTitle(user.getRealName()+" 下午"); dpmzjl.setMainContent(""+user.getRealName()+": "+dbdto.getWhatPmZjl()+"【闵总安排】"); dpmzjl.setSecondContent(dbdto.getWherePm()== null ? "地点:无" : "地点:"+dbdto.getWherePm()); dpmzjl.setThirdContent(dbdto.getWhoNamesPm()== null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesPm()); dpmzjl.setDeleteView(taskEntityPm != null && taskEntityPm.getTaskstatus() != null && XcglConstant.TASKSTATUS_DONE.equals(taskEntityPm.getTaskstatus())); if(dpmzjl.isDeleteView()) { dpmzjl.setRightTag("已完成"); }else { dpmzjl.setRightTag("未完成"); } showlist.add(dpmzjl); } if(dbdto.getWhatPm() != null && dbdto.getWhatPm().length()>0) { WXMultiRowViewerDto dpm = new WXMultiRowViewerDto(); String userid = dbdto.getUserid(); TSUser user = systemService.get(TSUser.class, userid); // dpm.setDivTitle(user.getRealName()+" 下午"); dpm.setMainContent(""+user.getRealName()+": "+dbdto.getWhatPm()); dpm.setSecondContent(dbdto.getWherePm()== null ? "地点:无" : "地点:"+dbdto.getWherePm()); dpm.setThirdContent(dbdto.getWhoNamesPm()== null ? "参与人:无" : "参与人:"+dbdto.getWhoNamesPm()); dpm.setDeleteView(taskEntityPm != null && taskEntityPm.getTaskstatus() != null && XcglConstant.TASKSTATUS_DONE.equals(taskEntityPm.getTaskstatus())); if(dpm.isDeleteView()) { dpm.setRightTag("已完成"); }else { dpm.setRightTag("未完成"); } showlist.add(dpm); } } WXMultiRowViewer viewer = new WXMultiRowViewer(); viewer.setRows(showlist); viewer.setTitle(date); viewer.setWarning(getNoSchedulePersons(date)); return WXViewerUtils.getWXMultiRowViewerHtml(viewer); } @RequestMapping(params = "activitiOvertimeRpt") public ModelAndView activitiOvertimeRpt(HttpServletRequest request) { String date = request.getParameter("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd EEEE",Locale.CHINA); Date today = null; try { if(StringUtils.isEmpty(date)) date = "2020-03-21"; today = sdf.parse(date); } catch (ParseException e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); } Calendar cal = Calendar.getInstance(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, -1); request.setAttribute("date", sdf.format(cal.getTime())); request.setAttribute("title", "签报逾期情况"); request.setAttribute("htmlurl", "weeklyscheduleController.do?activitiOvertimeRptData&date="+date); request.setAttribute("defindedJS", "webpage/cn/com/lzt/contractreports/projectCostWarnRpt4ZJLDemo.js"); return new ModelAndView("cn/com/lzt/wxviewer/wxMultirowViewer"); } @RequestMapping(params = "activitiOvertimeRptData") @ResponseBody public AjaxJson activitiOvertimeRptData(HttpServletRequest request, HttpServletResponse response, String date) { date = request.getParameter("date"); String message = null; AjaxJson j = new AjaxJson(); String html= ""; try { html = activitiOvertimeRptDataHtml(); } catch (Exception e) { org.jeecgframework.core.util.LogUtil.error(e.getMessage()); e.printStackTrace(); } j.setObj(html); j.setMsg(message); return j; } private String activitiOvertimeRptDataHtml() throws Exception { List showlist = new ArrayList(); String tookTime = ResourceUtil.getConfigByName("activiti.task.tooktime"); List> rptData = rptDao.activitiOvertimeStats(Integer.valueOf(tookTime)); WXMultiRowViewerDto damzjl ; for (Map map : rptData) { damzjl = new WXMultiRowViewerDto(); damzjl.setMainContent(map.get("realname").toString()); String html = " " +"" +"" +"
逾期总数: "+map.get("overcount").toString()+"条
最长逾期天数: "+map.get("maxdaycount").toString()+"天
"; damzjl.setSecondContent(html); showlist.add(damzjl); } WXMultiRowViewer viewer = new WXMultiRowViewer(); viewer.setRows(showlist); return WXViewerUtils.getWXMultiRowViewerHtml(viewer); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid * @param user */ @RequestMapping(params = "datagrid") public void datagrid(WeeklyscheduleEntity weeklyschedule,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(WeeklyscheduleEntity.class, dataGrid); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, weeklyschedule, request.getParameterMap()); try{ //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.weeklyscheduleService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 删除工作周报 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(WeeklyscheduleEntity weeklyschedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); weeklyschedule = systemService.getEntity(WeeklyscheduleEntity.class, weeklyschedule.getId()); message = "工作周报删除成功"; try{ weeklyscheduleService.delete(weeklyschedule); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "工作周报删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 批量删除工作周报 * * @return */ @RequestMapping(params = "doBatchDel") @ResponseBody public AjaxJson doBatchDel(String ids,HttpServletRequest request){ String message = null; AjaxJson j = new AjaxJson(); message = "工作周报删除成功"; try{ for(String id:ids.split(",")){ WeeklyscheduleEntity weeklyschedule = systemService.getEntity(WeeklyscheduleEntity.class, id ); weeklyscheduleService.delete(weeklyschedule); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } }catch(Exception e){ e.printStackTrace(); message = "工作周报删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 添加工作周报 * * @param ids * @return */ @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(WeeklyscheduleEntity weeklyschedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "周工作计划保存成功"; if(weeklyschedule.getId() != null && weeklyschedule.getId().length()> 0) { doUpdate(weeklyschedule, request); }else { try{ String hql1 = "from WeeklyscheduleEntity where userid=? and mondate = ?"; List WeeklyscheduleEntityList = systemService.findHql(hql1, weeklyschedule.getUserid(),weeklyschedule.getMondate()); if(WeeklyscheduleEntityList.size() > 0) throw new BusinessException("已存在此用户周报,请刷新后,重新填写并保存。"); weeklyscheduleService.save(weeklyschedule); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); String zjlWhat = WeeklyScheduleUtils.getZjlWhat(weeklyschedule); if(StringUtils.isNotEmpty(zjlWhat)) { sendWXMsg4ZJLWhat(weeklyschedule.getUserid(), zjlWhat, weeklyschedule.getMondate() +"~"+weeklyschedule.getSundate()); } }catch(BusinessException be){ be.printStackTrace(); logger.error(be); message = "周工作计划保存失败,"+be.getMessage(); }catch(Exception e){ e.printStackTrace(); message = "周工作计划保存失败"; } } j.setMsg(message); return j; } /** * 更新工作周报 * * @param ids * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(WeeklyscheduleEntity weeklyschedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "工作周报更新成功"; WeeklyscheduleEntity t = weeklyscheduleService.get(WeeklyscheduleEntity.class, weeklyschedule.getId()); try { String zjlWhat = WeeklyScheduleUtils.getZjlWhatChanged(weeklyschedule,t); if(StringUtils.isNotEmpty(zjlWhat)) { sendWXMsg4ZJLWhat(weeklyschedule.getUserid(), zjlWhat, weeklyschedule.getMondate() +"~"+weeklyschedule.getSundate()); } //参与人员信息列表 List partiList = weeklyschedule.getPartiList(); MyBeanUtils.copyBeanNotNull2Bean(weeklyschedule, t); weeklyscheduleService.saveOrUpdate(t); //删除原参与人员明细,重新保存 String delSql = "delete from p_weeklyschedule_parti where scheduleid = ?"; systemService.executeSql(delSql, weeklyschedule.getId()); weeklyscheduleService.batchSave(partiList); systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "工作周报更新失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 工作周报新增页面跳转 * * @return */ @RequestMapping(params = "goAdd") public ModelAndView goAdd(WeeklyscheduleEntity weeklyschedule, HttpServletRequest req) { //传送过来界面中周一的日期 String currentMonDate = req.getParameter("currentMonDate"); String opt = req.getParameter("opt"); String managerflag = req.getParameter("managerflag"); String userid = req.getParameter("userid"); String curweekflag = "2"; List> userList = new ArrayList>(); //取下周所有日期从周一到周日 List weekday = new ArrayList(); //新增操作,非界面按钮触发 if(StringUtils.isEmpty(opt)){ weekday = XcglDateUtils.getWeekdays(XcglDateUtils.addDateDay( DateUtils.formatDate(new Date(),"yyyy-MM-dd"),7, new SimpleDateFormat("yyyy-MM-dd"))); }else { //界面按钮触发而来 if(opt.equals("next")) { weekday = XcglDateUtils.getWeekdays(XcglDateUtils.addDateDay( currentMonDate,7, new SimpleDateFormat("yyyy-MM-dd"))); }else if (opt.equals("before")) { weekday = XcglDateUtils.getWeekdays(XcglDateUtils.addDateDay( currentMonDate,-7, new SimpleDateFormat("yyyy-MM-dd"))); }else if (opt.equals("changeUser") || opt.equals("reload")) { weekday = XcglDateUtils.getWeekdays(currentMonDate); } } if(weekday.size() == 0 ) { req.setAttribute("ex", new Exception("界面参数错误,获取不到周计划日期,请联系系统管理员。")); return new ModelAndView("common/error"); } //如果是管理人员(例如总经办工作人员),则需要查询可做周计划的人员列表 if(StringUtils.isNotEmpty(managerflag) && managerflag.equals("1")) { userList = wxdao.getUsersByRoleCode(XcglConstant.ROLE_ZHOUBAO); req.setAttribute("useridList", userList); } // 参数中无人员,并且不是总经理安排工作,则取当前登录用户ID if(StringUtils.isEmpty(userid) && (StringUtils.isEmpty(managerflag) || !managerflag.equals("1"))) userid = ResourceUtil.getSessionUser().getId(); else if(StringUtils.isEmpty(userid) && StringUtils.isNotEmpty(managerflag) && managerflag.equals("1")) { //总经理安排工作,无人员id参数,则取uers第一个人 if(userList.size() > 0) userid = userList.get(0).get("id").toString(); else { req.setAttribute("ex", new Exception("未设置工作执行人员,请联系管理员处理。")); return new ModelAndView("common/error"); } } String hql1 = "from WeeklyscheduleEntity where userid=? and mondate = ?"; List WeeklyscheduleEntityList = systemService.findHql(hql1, userid,weekday.get(0)); List lastWeekday = XcglDateUtils.getWeekdays(XcglDateUtils.addDateDay( weekday.get(0),-7, new SimpleDateFormat("yyyy-MM-dd"))); List lastWeeklyscheduleEntityList = systemService.findHql(hql1, userid,lastWeekday.get(0)); StringBuffer notDone = new StringBuffer(); if (lastWeeklyscheduleEntityList != null && lastWeeklyscheduleEntityList.size() > 0) { //查询未完成任务 String hqlTask = "from ProjecttaskEntity where sourceid=? and taskstatus in ('0','1')"; List notDoneProjecttaskEntitylist = systemService.findHql(hqlTask, lastWeeklyscheduleEntityList.get(0).getId()); if(notDoneProjecttaskEntitylist != null ) { for(ProjecttaskEntity task:notDoneProjecttaskEntitylist) { notDone.append(task.getDescription()).append(";\r\n"); } } } if (WeeklyscheduleEntityList != null && WeeklyscheduleEntityList.size() > 0) { weeklyschedule = WeeklyscheduleEntityList.get(0); List> nameTimeList = weeklyScheduleMiniDao.getParticipantName(weeklyschedule.getId()); weeklyschedule = setRealNames(weeklyschedule, nameTimeList); weeklyschedule.setWeekFromTo(weeklyschedule.getMondate()+" 至 "+weeklyschedule.getSundate()); weeklyschedule.setNotdone(notDone.toString()); //如果下周周报已添加,则可以在本周继续编辑 req.setAttribute("weeklyschedulePage", weeklyschedule); }else { weeklyschedule = new WeeklyscheduleEntity(); weeklyschedule.setUserid(userid); weeklyschedule.setMondate(weekday.get(0)); weeklyschedule.setTuesdate(weekday.get(1)); weeklyschedule.setWeddate(weekday.get(2)); weeklyschedule.setThurdate(weekday.get(3)); weeklyschedule.setFridate(weekday.get(4)); weeklyschedule.setSatdate(weekday.get(5)); weeklyschedule.setSundate(weekday.get(6)); weeklyschedule.setWeekFromTo(weekday.get(0)+" 至 "+weekday.get(6)); weeklyschedule.setStatus(Globals.UNAPPROVED); weeklyschedule.setNotdone(notDone.toString()); req.setAttribute("weeklyschedulePage", weeklyschedule); } List curweekday = XcglDateUtils.getWeekdays(DateUtils.formatDate(new Date(),"yyyy-MM-dd")); if(curweekday.get(0).equals(weekday.get(0))) { curweekflag = "1"; }else if(curweekday.get(0).compareTo(weekday.get(0)) > 0) curweekflag = "0"; req.setAttribute("managerflag", managerflag); req.setAttribute("curweekflag", curweekflag); req.setAttribute("userid", userid); req.setAttribute("username", ResourceUtil.getSessionUser().getRealName()); return new ModelAndView("com/xcgl/weeklyschedule/weeklyschedule-add"); } private WeeklyscheduleEntity setRealNames(WeeklyscheduleEntity weeklyschedule, List> nameTimeList) { for(Map nameTime : nameTimeList) { String date = nameTime.get("datetime").toString(); String realNames = nameTime.get("realNames").toString(); //周一 if(weeklyschedule.getMondate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhomonamnames(realNames); }else if (weeklyschedule.getMondate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhomonpmnames(realNames); } //周二 else if(weeklyschedule.getTuesdate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhotuesamnames(realNames); }else if (weeklyschedule.getTuesdate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhotuespmnames(realNames); } //周三 else if(weeklyschedule.getWeddate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhowedamnames(realNames); }else if (weeklyschedule.getWeddate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhowedpmnames(realNames); } //周四 else if(weeklyschedule.getThurdate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhothuramnames(realNames); }else if (weeklyschedule.getThurdate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhothurpmnames(realNames); } //周五 else if(weeklyschedule.getFridate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhofriamnames(realNames); }else if (weeklyschedule.getFridate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhofripmnames(realNames); } //周六 else if(weeklyschedule.getSatdate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhosatamnames(realNames); }else if (weeklyschedule.getSatdate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhosatpmnames(realNames); } //周日 else if(weeklyschedule.getSundate().equals(date.substring(0,10)) && date.substring(10).equals("am")) { weeklyschedule.setWhosunamnames(realNames); }else if (weeklyschedule.getSundate().equals(date.substring(0,10)) && date.substring(10).equals("pm")) { weeklyschedule.setWhosunpmnames(realNames); } } return weeklyschedule; } /** * 工作周报编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(WeeklyscheduleEntity weeklyschedule, HttpServletRequest req) { if (StringUtil.isNotEmpty(weeklyschedule.getId())) { weeklyschedule = weeklyscheduleService.getEntity(WeeklyscheduleEntity.class, weeklyschedule.getId()); List> nameTimeList = weeklyScheduleMiniDao.getParticipantName(weeklyschedule.getId()); weeklyschedule = setRealNames(weeklyschedule, nameTimeList); req.setAttribute("weeklyschedulePage", weeklyschedule); } return new ModelAndView("com/xcgl/weeklyschedule/weeklyschedule-update"); } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name","weeklyscheduleController"); return new ModelAndView("common/upload/pub_excel_upload"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(WeeklyscheduleEntity weeklyschedule,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { CriteriaQuery cq = new CriteriaQuery(WeeklyscheduleEntity.class, dataGrid); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, weeklyschedule, request.getParameterMap()); List weeklyschedules = this.weeklyscheduleService.getListByCriteriaQuery(cq,false); modelMap.put(NormalExcelConstants.FILE_NAME,"工作周报"); modelMap.put(NormalExcelConstants.CLASS,WeeklyscheduleEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("工作周报列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,weeklyschedules); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 导出excel 使模板 * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(WeeklyscheduleEntity weeklyschedule,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME,"工作周报"); modelMap.put(NormalExcelConstants.CLASS,WeeklyscheduleEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("工作周报列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList()); return NormalExcelConstants.JEECG_EXCEL_VIEW; } @SuppressWarnings("unchecked") @RequestMapping(params = "importExcel", method = RequestMethod.POST) @ResponseBody public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) { AjaxJson j = new AjaxJson(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { List listWeeklyscheduleEntitys = ExcelImportUtil.importExcel(file.getInputStream(),WeeklyscheduleEntity.class,params); for (WeeklyscheduleEntity weeklyschedule : listWeeklyscheduleEntitys) { weeklyscheduleService.save(weeklyschedule); } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); logger.error(ExceptionUtil.getExceptionMessage(e)); }finally{ try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listWeeklyschedules=weeklyscheduleService.getList(WeeklyscheduleEntity.class); return listWeeklyschedules; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { WeeklyscheduleEntity task = weeklyscheduleService.get(WeeklyscheduleEntity.class, id); if (task == null) { return new ResponseEntity(HttpStatus.NOT_FOUND); } return new ResponseEntity(task, HttpStatus.OK); } @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity create(@RequestBody WeeklyscheduleEntity weeklyschedule, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(weeklyschedule); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ weeklyscheduleService.save(weeklyschedule); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = weeklyschedule.getId(); URI uri = uriBuilder.path("/rest/weeklyscheduleController/" + id).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity(headers, HttpStatus.CREATED); } @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity update(@RequestBody WeeklyscheduleEntity weeklyschedule) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(weeklyschedule); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ weeklyscheduleService.saveOrUpdate(weeklyschedule); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码. return new ResponseEntity(HttpStatus.NO_CONTENT); } @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable("id") String id) { weeklyscheduleService.deleteEntityById(WeeklyscheduleEntity.class, id); } @RequestMapping(params = "sendmsg") public AjaxJson sendmsg(HttpServletRequest request) { AjaxJson j = new AjaxJson(); weeklyscheduleService.sendWXMsgForWeeklySchedule(); String message = "微信消息发送成功"; j.setMsg(message); return j; } @RequestMapping(params = "genTask") public AjaxJson genTask(HttpServletRequest request) { AjaxJson j = new AjaxJson(); weeklyscheduleService.genWorkFromWeeklySchedule(); String message = "生成任务成功"; j.setMsg(message); return j; } @RequestMapping(params = "getPersonInfo") public void getPersonInfo(UserAndUserPersonnelDto userAndUserPersonnelDto, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { List> users = wxdao.getUsersByRoleCode("T_ZBJS"); List useridListAll = new ArrayList(); if(users.size() > 0) { for(Map map :users) { useridListAll.add(map.get("id").toString()); } userAndUserPersonnelDto.setUserIdList(useridListAll); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); List listUserAndUserPersonnelDto = weeklyScheduleMiniDao.getUserAndUserPersonnelNoPage(userAndUserPersonnelDto,authSql); Collections.sort(listUserAndUserPersonnelDto); dataGrid.setResults(listUserAndUserPersonnelDto); TagUtil.datagrid(response, dataGrid); } } @RequestMapping(params = "openPersonView") public ModelAndView openPersonView(HttpServletRequest request) { return new ModelAndView("com/xcgl/weeklyschedule/personSelectList"); } /* * 给员工发微信,提醒总经理安排变更,注意自己的工作计划 * */ private void sendWXMsg4ZJLWhat(String userid,String what,String date) { List> user = systemService .findForJdbc("select openid from t_s_user where id =? and openid is not null", userid); if (user.size() == 0) return; List> listParams = new ArrayList>(); Map oneMsg = new HashMap(); Map userMsgParms = new HashMap(); userMsgParms.put("first", "你有一个闵总新安排的事项,请及时关注"); userMsgParms.put("keyword1", date); userMsgParms.put("keyword2", what); userMsgParms.put("remark", "请登录慧管理系统查看详细周工作计划。"); oneMsg.put("openid", user.get(0).get("openid").toString()); oneMsg.put("userid", userid); oneMsg.put("tplParams", userMsgParms); // oneMsg.put("url", "http://test.shenqin.work:8080/hgl/dsdemoController.do?showNoOrderWarehouse"+"&openid="+user.get("openid")+"&schedule="+weekday.get(0)+","+weekday.get(1)); listParams.add(oneMsg); try { wxservice.sendMsgToWXForTodayWork(listParams); } catch (Exception e) { logger.error(e); } } }