package cn.com.lzt.projarrangedetail.controller; import cn.com.lzt.arrangeduty.entity.ArrangeDutyEntity; import cn.com.lzt.arrangeduty.service.ArrangeDutyServiceI; import cn.com.lzt.arrangedutyoperate.entity.ArrangeDutyOperateEntity; import cn.com.lzt.arrangedutyoperate.service.ArrangeDutyOperateServiceI; import cn.com.lzt.calendar.dto.CalendarAscDto; import cn.com.lzt.calendar.entity.CalendarEntity; import cn.com.lzt.calendar.service.CalendarServiceI; import cn.com.lzt.common.util.uuid.GetUUID; import cn.com.lzt.dialogDeal.service.UserDepartOrgDealServiceI; import cn.com.lzt.excel.HGLExcelConstant; import cn.com.lzt.excel.HGLExcelImportUtils; import cn.com.lzt.excel.entity.HGLExcelResult; import cn.com.lzt.projarrangedetail.dao.ProjArrangeDetailAndUserMiniDao; import cn.com.lzt.projarrangedetail.dto.ProjArrangeDetailAndUserDto; import cn.com.lzt.projarrangedetail.dto.UserArrangeCalendarDto; import cn.com.lzt.projarrangedetail.entity.ProjarrangeDetailEntity; import cn.com.lzt.projarrangedetail.service.ArrangeDutyAndOndutyServiceI; import cn.com.lzt.projarrangedetail.service.ProjarrangeDetailServiceI; import cn.com.lzt.projarrangegeneral.entity.ProjArrangeGeneralEntity; import cn.com.lzt.projarrangegeneral.service.ProjArrangeGeneralServiceI; import cn.com.lzt.projectpostdetail.entity.ProjectPostDetailEntity; import cn.com.lzt.tools.HGLDateUtils; import cn.com.lzt.userarrangedetail.entity.UserArrangeDetailHistoryEntity; import cn.com.lzt.userarrangedetail.service.UserArrangeDetailServiceI; import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity; import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI; import net.sf.json.JSONArray; import org.apache.commons.lang3.StringUtils; 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.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.*; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.enmus.ExcelType; import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; import org.jeecgframework.poi.excel.entity.vo.MapExcelConstants; import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.pojo.base.DictEntity; import org.jeecgframework.web.system.pojo.base.TSDepart; 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.*; 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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.io.IOException; import java.net.URI; import java.text.SimpleDateFormat; import java.util.*; import java.util.Map.Entry; /** * @Title: Controller * @Description: 项目排班详细表 * @author onlineGenerator * @date 2017-10-24 10:52:56 * @version V1.0 * */ @Controller @RequestMapping("/projarrangeDetailController") public class ProjarrangeDetailController extends BaseController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(ProjarrangeDetailController.class); //项目排班详细表 @Autowired private ProjarrangeDetailServiceI projarrangeDetailService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Autowired private TBusUserOptionsServiceI userOptionsService; //日历表 @Autowired private CalendarServiceI calendarService; //员工排班详情表 @Autowired private UserArrangeDetailServiceI userArrangeDetailService; //班次表 @Autowired private ArrangeDutyServiceI arrangeDutyService; //项目排班总览表 @Autowired private ProjArrangeGeneralServiceI projArrangeGeneralService; //排班操作表 @Autowired private ArrangeDutyOperateServiceI arrangeDutyOperateService; //排班总方法页 @Autowired private ArrangeDutyAndOndutyServiceI arrangeDutyAndOndutyServiceI; //项目排班自己总结公共方法; //ProjectArrangeCommonMethod commonMethod; // 用户和项目关系处理 @Autowired UserDepartOrgDealServiceI userDepartOrgDealServiceI; @Autowired ProjArrangeDetailAndUserMiniDao projDao; /** * 项目排班详细表列表 页面跳转 * @author zbw * 2017-11-24 * @param request * @param calendarAscDto * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request,CalendarAscDto calendarAscDto) { String pid=request.getParameter("pid"); String[] pidArr = null; String[] weekStr = new String[] {"一","二","三","四","五","六","日"}; HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); try { if(pid!=null){ pidArr=pid.split(","); if(pidArr != null && pidArr.length>0) { userOptionsService.saveUserOptions(tuser.getId(), pid, Globals.USER_OPTIONS_TYPE_PROJECT); } }else { TBusUserOptionsEntity options = userOptionsService.getOptionsByUserID(tuser.getId(), Globals.USER_OPTIONS_TYPE_PROJECT, true); if(options != null) { pid = options.getOptionId(); pidArr= new String[1]; pidArr[0] = pid; } } } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.error(e.getMessage()); } if(calendarAscDto.getYear()==null&&calendarAscDto.getMonth()==null){ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM"); String[] dateNumber=simpleDateFormat.format(new Date()).split("-"); calendarAscDto.setYear(Integer.parseInt(dateNumber[0])); calendarAscDto.setMonth(Integer.parseInt(dateNumber[1])); } List listCalendar=projarrangeDetailService.getCalendar(calendarAscDto); List> titlelist = new ArrayList>(); //日期列名字符串即主键id String calendaridStr=""; //日期列名字符串即主键id+星期几 String specialCalendar="[{"; for (int i =0;i map = new HashMap(); String monthTemp = String.valueOf(listCalendar.get(i).getMonth()); String dayTemp = String.valueOf(listCalendar.get(i).getDay()); String weekTemp = null; if((listCalendar.get(i).getWeek() != null)){ int weekInt= -1; try { weekInt =Integer.parseInt(listCalendar.get(i).getWeek()); }catch(Exception e) {} if(weekInt > 0 && weekInt < 8) { weekTemp = weekStr[weekInt-1]; } } if(weekTemp == null) { map.put("title", monthTemp+"月"+dayTemp+"日"); }else { map.put("title", monthTemp+"月"+dayTemp+"日"+" 星期"+weekTemp+""); } /*map.put("field", String.valueOf(listCalendar.get(i).getYear())+ String.valueOf(listCalendar.get(i).getMonth())+String.valueOf(listCalendar.get(i).getDay()));*/ map.put("field", listCalendar.get(i).getId()); titlelist.add(map); } specialCalendar += "}]"; request.setAttribute("specialCalendar",specialCalendar); String tempMonth=String.valueOf(calendarAscDto.getMonth()).length()==1?"0"+String.valueOf(calendarAscDto.getMonth()):String.valueOf(calendarAscDto.getMonth()); String yearmonth=String.valueOf(calendarAscDto.getYear())+"-"+tempMonth; request.setAttribute("calendaridStr",calendaridStr); request.setAttribute("titlelist",titlelist); request.setAttribute("yearmonth",yearmonth); request.setAttribute("usernamesearch",request.getParameter("usernamesearch")); if(pidArr!=null){ String id=pidArr[0]; TSDepart dePart = this.systemService.getEntity(TSDepart.class, id); request.setAttribute("pid",id); request.setAttribute("departname",dePart.getDepartname()); }else{ request.setAttribute("pid",pid); request.setAttribute("departname",null); } return new ModelAndView("cn/com/lzt/projarrangedetail/projarrangeDetailList"); } /** * 项目排班详细表列表 页面跳转 * @author zbw * 2017-11-24 * @param request * @param calendarAscDto * @return */ @RequestMapping(params = "listAll") public ModelAndView listAll(HttpServletRequest request,CalendarAscDto calendarAscDto) { String pid=request.getParameter("pid"); String[] pidArr = null; String[] weekStr = new String[] {"一","二","三","四","五","六","日"}; HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); try { if(pid!=null){ pidArr=pid.split(","); if(pidArr != null && pidArr.length>0) { userOptionsService.saveUserOptions(tuser.getId(), pid, Globals.USER_OPTIONS_TYPE_PROJECT); } }else { TBusUserOptionsEntity options = userOptionsService.getOptionsByUserID(tuser.getId(), Globals.USER_OPTIONS_TYPE_PROJECT, true); if(options != null) { pid = options.getOptionId(); pidArr= new String[1]; pidArr[0] = pid; } } } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.error(e.getMessage()); } if(calendarAscDto.getYear()==null&&calendarAscDto.getMonth()==null){ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM"); String[] dateNumber=simpleDateFormat.format(new Date()).split("-"); calendarAscDto.setYear(Integer.parseInt(dateNumber[0])); calendarAscDto.setMonth(Integer.parseInt(dateNumber[1])); } List listCalendar=projarrangeDetailService.getCalendar(calendarAscDto); List> titlelist = new ArrayList>(); //日期列名字符串即主键id String calendaridStr=""; //日期列名字符串即主键id+星期几 String specialCalendar="[{"; for (int i =0;i map = new HashMap(); String monthTemp = String.valueOf(listCalendar.get(i).getMonth()); String dayTemp = String.valueOf(listCalendar.get(i).getDay()); String weekTemp = null; if((listCalendar.get(i).getWeek() != null)){ int weekInt= -1; try { weekInt =Integer.parseInt(listCalendar.get(i).getWeek()); }catch(Exception e) {} if(weekInt > 0 && weekInt < 8) { weekTemp = weekStr[weekInt-1]; } } if(weekTemp == null) { map.put("title", monthTemp+"月"+dayTemp+"日"); }else { map.put("title", monthTemp+"月"+dayTemp+"日"+" 星期"+weekTemp+""); } /*map.put("field", String.valueOf(listCalendar.get(i).getYear())+ String.valueOf(listCalendar.get(i).getMonth())+String.valueOf(listCalendar.get(i).getDay()));*/ map.put("field", listCalendar.get(i).getId()); titlelist.add(map); } specialCalendar += "}]"; request.setAttribute("specialCalendar",specialCalendar); String tempMonth=String.valueOf(calendarAscDto.getMonth()).length()==1?"0"+String.valueOf(calendarAscDto.getMonth()):String.valueOf(calendarAscDto.getMonth()); String yearmonth=String.valueOf(calendarAscDto.getYear())+"-"+tempMonth; request.setAttribute("calendaridStr",calendaridStr); request.setAttribute("titlelist",titlelist); request.setAttribute("yearmonth",yearmonth); request.setAttribute("usernamesearch",request.getParameter("usernamesearch")); if(pidArr!=null){ String id=pidArr[0]; TSDepart dePart = this.systemService.getEntity(TSDepart.class, id); request.setAttribute("pid",id); request.setAttribute("departname",dePart.getDepartname()); }else{ request.setAttribute("pid",pid); request.setAttribute("departname",null); } return new ModelAndView("cn/com/lzt/projarrangedetail/projarrangeDetailAllList"); } /** * 排班审核查看详细 页面跳转 * * @return */ @RequestMapping(params = "generalDetailList") public ModelAndView generalDetailList(HttpServletRequest request,CalendarAscDto calendarAscDto) { String projarrangegeneralId=calendarAscDto.getId(); calendarAscDto.setId(""); String pid=request.getParameter("pid"); String[] pidArr = null; String[] weekStr = new String[] {"一","二","三","四","五","六","日"}; if(pid!=null){ pidArr=pid.split(","); } if(calendarAscDto.getYear()==null&&calendarAscDto.getMonth()==null){ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM"); String[] dateNumber=simpleDateFormat.format(new Date()).split("-"); calendarAscDto.setYear(Integer.parseInt(dateNumber[0])); calendarAscDto.setMonth(Integer.parseInt(dateNumber[1])); } List listCalendar=projarrangeDetailService.getCalendar(calendarAscDto); List> titlelist = new ArrayList>(); //日期列名字符串即主键id String calendaridStr=""; //日期列名字符串即主键id+星期几 String specialCalendar="[{"; for (int i=0;i map = new HashMap(); String monthTemp = String.valueOf(listCalendar.get(i).getMonth()); String dayTemp = String.valueOf(listCalendar.get(i).getDay()); String weekTemp = null; if((listCalendar.get(i).getWeek() != null)){ int weekInt= -1; try { weekInt =Integer.parseInt(listCalendar.get(i).getWeek()); }catch(Exception e) {} if(weekInt > 0 && weekInt < 8) { weekTemp = weekStr[weekInt-1]; } } if(weekTemp == null) { map.put("title", monthTemp+"月"+dayTemp+"日"); }else { map.put("title", monthTemp+"月"+dayTemp+"日"+" 星期"+weekTemp+""); } /*map.put("field", String.valueOf(listCalendar.get(i).getYear())+ String.valueOf(listCalendar.get(i).getMonth())+String.valueOf(listCalendar.get(i).getDay()));*/ map.put("field", listCalendar.get(i).getId()); titlelist.add(map); } specialCalendar+="}]"; request.setAttribute("specialCalendar",specialCalendar); String tempMonth=String.valueOf(calendarAscDto.getMonth()).length()==1?"0"+String.valueOf(calendarAscDto.getMonth()):String.valueOf(calendarAscDto.getMonth()); String yearmonth=String.valueOf(calendarAscDto.getYear())+"-"+tempMonth; request.setAttribute("calendaridStr",calendaridStr); request.setAttribute("titlelist",titlelist); request.setAttribute("yearmonth",yearmonth); if(pidArr!=null){ String id=pidArr[0]; TSDepart dePart = this.systemService.getEntity(TSDepart.class, id); request.setAttribute("pid",pidArr[0]); request.setAttribute("departname",dePart.getDepartname()); }else{ request.setAttribute("pid",pid); request.setAttribute("departname",null); } //审核表Id request.setAttribute("projarrangegeneralId",projarrangegeneralId); return new ModelAndView("cn/com/lzt/projarrangegeneral/generalDetailList"); } /** * 员工排班上报数据主页面 * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid * @param user */ @RequestMapping(params = "datagrid") public void datagrid(ProjArrangeDetailAndUserDto projArrangeDetailAndUserDto,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { long start = System.currentTimeMillis(); UserArrangeCalendarDto userArrangeCalendarDto=new UserArrangeCalendarDto(); int s=dataGrid.getField().indexOf("userid")+7; int e=dataGrid.getField().indexOf("workingDays")-1; //日期列名数组即主键id String[] calendaridArr=dataGrid.getField().substring(s, e).split(","); //String calendarid=""; List calendaridList=new ArrayList(); for (int i = 0; i < calendaridArr.length; i++) { calendaridList.add(calendaridArr[i]); } if(calendaridList.size()>0){ userArrangeCalendarDto.setCalendaridList(calendaridList); } projArrangeDetailAndUserDto.setYearmonth(request.getParameter("yearmonth")); String pid=request.getParameter("pid"); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } projArrangeDetailAndUserDto.setPid(pid); projArrangeDetailAndUserDto.setUserName(request.getParameter("usernamesearch")); //包括该项目id //根据项目id查询所有子节点id List ChildIdList=userDepartOrgDealServiceI.getChildIdByProjectDepartId(pid); projArrangeDetailAndUserDto.setChildDepartIdList(ChildIdList); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); //查询项目排班详细表数据 List projArrangeDetailAndUserDtolist = projarrangeDetailService.getProjArrangeDetailAndUserByPIdYearMonth( projArrangeDetailAndUserDto,authSql); dataGrid.setResults(projArrangeDetailAndUserDtolist); //班次名称如果被删除,则不用拼接此条数据 //只查询启用的数据 StringBuffer hql = new StringBuffer(" from ArrangeDutyEntity t where delete_flag <> '1' "); List arrangeDutyEntityList = arrangeDutyService.findHql(hql.toString()); List shiftIdList=new ArrayList(); for (int i = 0; i < arrangeDutyEntityList.size(); i++) { shiftIdList.add(arrangeDutyEntityList.get(i).getId()); } @SuppressWarnings("unchecked") List projectPostUserMiniDaoDtolistNew = dataGrid.getResults(); Map> extMap = new HashMap>(); for(ProjArrangeDetailAndUserDto temp:projectPostUserMiniDaoDtolistNew){ if(temp.getId()!=null){ Map m = new HashMap(); userArrangeCalendarDto.setProjarrangeDetailid(temp.getId()); //查询员工排班详情表数据 List userArrangeCalendarMiniDaoDtolist = getUserArrangeD(userArrangeCalendarDto); for (int i = 0; i < calendaridArr.length; i++) { for (int j = 0; j < userArrangeCalendarMiniDaoDtolist.size(); j++) { if(calendaridArr[i].equals(userArrangeCalendarMiniDaoDtolist.get(j).getCalendarid())){ if(shiftIdList.contains(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())){ m.put(calendaridArr[i], userArrangeCalendarMiniDaoDtolist.get(j).getShiftid()); }/*else if(shiftIdListDT.contains(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())){ m.put(calendaridArr[i], shiftIdMapDT.get(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())); }*/ } } } extMap.put(temp.getId(), m); }else{ Map m0 = new HashMap(); //String myId=String.valueOf((int)(Math.random()*100)); String myId=GetUUID.generate(); temp.setId(myId); extMap.put(temp.getId(), m0); } } long end = System.currentTimeMillis(); //System.out.println(end-start); if(extMap.size()==0){ TagUtil.datagrid(response, dataGrid); }else{ TagUtil.datagrid(response, dataGrid,extMap); } } /** * 员工排班上报数据主页面 * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid * @param user */ @RequestMapping(params = "datagridAll") public void datagridAll(ProjArrangeDetailAndUserDto projArrangeDetailAndUserDto,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { long start = System.currentTimeMillis(); UserArrangeCalendarDto userArrangeCalendarDto=new UserArrangeCalendarDto(); int s=dataGrid.getField().indexOf("userid")+7; int e=dataGrid.getField().indexOf("workingDays")-1; //日期列名数组即主键id String[] calendaridArr=dataGrid.getField().substring(s, e).split(","); //String calendarid=""; List calendaridList=new ArrayList(); for (int i = 0; i < calendaridArr.length; i++) { calendaridList.add(calendaridArr[i]); } if(calendaridList.size()>0){ userArrangeCalendarDto.setCalendaridList(calendaridList); } projArrangeDetailAndUserDto.setYearmonth(request.getParameter("yearmonth")); String pid=request.getParameter("pid"); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } projArrangeDetailAndUserDto.setPid(pid); projArrangeDetailAndUserDto.setUserName(request.getParameter("usernamesearch")); //包括该项目id //根据项目id查询所有子节点id List ChildIdList=userDepartOrgDealServiceI.getChildIdByProjectDepartId(pid); projArrangeDetailAndUserDto.setChildDepartIdList(ChildIdList); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); //查询项目排班详细表数据 List projArrangeDetailAndUserDtolist = projarrangeDetailService.getProjArrangeDetailAndUserByPIdYearMonth( projArrangeDetailAndUserDto,authSql); dataGrid.setResults(projArrangeDetailAndUserDtolist); //班次名称如果被删除,则不用拼接此条数据 //只查询启用的数据 StringBuffer hql = new StringBuffer(" from ArrangeDutyEntity t where delete_flag <> '1' "); List arrangeDutyEntityList = arrangeDutyService.findHql(hql.toString()); List shiftIdList=new ArrayList(); for (int i = 0; i < arrangeDutyEntityList.size(); i++) { shiftIdList.add(arrangeDutyEntityList.get(i).getId()); } @SuppressWarnings("unchecked") List projectPostUserMiniDaoDtolistNew=dataGrid.getResults(); Map> extMap = new HashMap>(); for(ProjArrangeDetailAndUserDto temp:projectPostUserMiniDaoDtolistNew){ if(temp.getId()!=null){ Map m = new HashMap(); userArrangeCalendarDto.setProjarrangeDetailid(temp.getId()); //查询员工排班详情表数据 List userArrangeCalendarMiniDaoDtolist=getUserArrangeD(userArrangeCalendarDto); for (int i = 0; i < calendaridArr.length; i++) { for (int j = 0; j < userArrangeCalendarMiniDaoDtolist.size(); j++) { if(calendaridArr[i].equals(userArrangeCalendarMiniDaoDtolist.get(j).getCalendarid())){ if(shiftIdList.contains(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())){ m.put(calendaridArr[i], userArrangeCalendarMiniDaoDtolist.get(j).getShiftid()); }/*else if(shiftIdListDT.contains(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())){ m.put(calendaridArr[i], shiftIdMapDT.get(userArrangeCalendarMiniDaoDtolist.get(j).getShiftid())); }*/ } } } extMap.put(temp.getId(), m); }else{ Map m0 = new HashMap(); //String myId=String.valueOf((int)(Math.random()*100)); String myId=GetUUID.generate(); temp.setId(myId); extMap.put(temp.getId(), m0); } } long end = System.currentTimeMillis(); //System.out.println(end-start); if(extMap.size()==0){ TagUtil.datagrid(response, dataGrid); }else{ TagUtil.datagrid(response, dataGrid,extMap); } } /** * 查询员工排班详情表 * @author zbw * 2017-10-26 * @param userArrangeCalendarMiniDaoDto * @return */ @RequestMapping(params = "getUserArrangeD") @ResponseBody public List getUserArrangeD(UserArrangeCalendarDto userArrangeCalendarDto) { //AjaxJson j = new AjaxJson(); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); List userArrangeCalendarDtolist = projarrangeDetailService.getUserArrangeCalendar( userArrangeCalendarDto,authSql); return userArrangeCalendarDtolist; } /** * 删除项目排班详细表 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(ProjarrangeDetailEntity projarrangeDetail, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); projarrangeDetail = systemService.getEntity(ProjarrangeDetailEntity.class, projarrangeDetail.getId()); message = "项目排班详细删除成功"; try{ projarrangeDetailService.delete(projarrangeDetail); 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(",")){ ProjarrangeDetailEntity projarrangeDetail = systemService.getEntity(ProjarrangeDetailEntity.class, id ); projarrangeDetailService.delete(projarrangeDetail); 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(ProjarrangeDetailEntity projarrangeDetail, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "项目排班详细添加成功"; try{ projarrangeDetailService.save(projarrangeDetail); systemService.addLog(message, Globals.Log_Type_INSERT, 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 = "doUpdate") @ResponseBody public AjaxJson doUpdate(ProjarrangeDetailEntity projarrangeDetail, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "项目排班详细更新成功"; ProjarrangeDetailEntity t = projarrangeDetailService.get(ProjarrangeDetailEntity.class, projarrangeDetail.getId()); try { MyBeanUtils.copyBeanNotNull2Bean(projarrangeDetail, t); projarrangeDetailService.saveOrUpdate(t); 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(ProjarrangeDetailEntity projarrangeDetail, HttpServletRequest req) { if (StringUtil.isNotEmpty(projarrangeDetail.getId())) { projarrangeDetail = projarrangeDetailService.getEntity(ProjarrangeDetailEntity.class, projarrangeDetail.getId()); req.setAttribute("projarrangeDetailPage", projarrangeDetail); } return new ModelAndView("cn/com/lzt/projarrangedetail/projarrangeDetail-add"); } /** * 项目排班详细表编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(ProjarrangeDetailEntity projarrangeDetail, HttpServletRequest req) { if (StringUtil.isNotEmpty(projarrangeDetail.getId())) { projarrangeDetail = projarrangeDetailService.getEntity(ProjarrangeDetailEntity.class, projarrangeDetail.getId()); req.setAttribute("projarrangeDetailPage", projarrangeDetail); } return new ModelAndView("cn/com/lzt/projarrangedetail/projarrangeDetail-update"); } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name","projarrangeDetailController"); return new ModelAndView("common/upload/pub_excel_upload"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(ProjarrangeDetailEntity projarrangeDetail,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { //获取用户名称 List baseUserList=systemService.queryDict("t_s_base_user", "id", "realname"); Map baseUserMap=new HashMap(); for (int i = 0; i < baseUserList.size(); i++) { baseUserMap.put(baseUserList.get(i).getTypecode(), baseUserList.get(i).getTypename()); } //获取班次名称 List arrangeDutyList=systemService.queryDict("t_bus_arrange_duty", "id", "duty_name"); Map arrangeDutyMap=new HashMap(); for (int i = 0; i < arrangeDutyList.size(); i++) { arrangeDutyMap.put(arrangeDutyList.get(i).getTypecode(), arrangeDutyList.get(i).getTypename()); } //获取项目岗位名称 List projectPostDetailList=systemService.queryDict("t_bus_project_post_detail", "id", "ptj_post_name"); Map projectPostDetailMap=new HashMap(); for (int i = 0; i < projectPostDetailList.size(); i++) { projectPostDetailMap.put(projectPostDetailList.get(i).getTypecode(), projectPostDetailList.get(i).getTypename()); } //获取项目名称 List departList=systemService.queryDict("t_s_depart", "id", "departname"); Map departMap=new HashMap(); for (int i = 0; i < departList.size(); i++) { departMap.put(departList.get(i).getTypecode(), departList.get(i).getTypename()); } String[] weekStr = new String[] {"一","二","三","四","五","六","日"}; //日历id List calendaridList=new ArrayList(); //标题 该list中用于存储标题的信息,每一个ExcelExportEntity 表示一列,根据List 的入栈顺序,由左至右,一次排序 List entityList = new ArrayList(); String yearmonth=projarrangeDetail.getYearmonth();; CalendarAscDto calendarAscDto=new CalendarAscDto(); if(projarrangeDetail.getYearmonth()!=null&&projarrangeDetail.getYearmonth().length()>0){ if(yearmonth.indexOf(",")!=-1){ yearmonth=projarrangeDetail.getYearmonth().split(",")[0]; } calendarAscDto.setYear(Integer.parseInt(yearmonth.split("-")[0])); calendarAscDto.setMonth(Integer.parseInt(yearmonth.split("-")[1])); }else{ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM"); String[] dateNumber=simpleDateFormat.format(new Date()).split("-"); calendarAscDto.setYear(Integer.parseInt(dateNumber[0])); calendarAscDto.setMonth(Integer.parseInt(dateNumber[1])); } List calendarAscDtoList=projarrangeDetailService.getCalendar(calendarAscDto); ExcelExportEntity head1=new ExcelExportEntity("项目名称", "pid", 15); entityList.add(head1); ExcelExportEntity head2=new ExcelExportEntity("月度", "yearmonth", 15); entityList.add(head2); ExcelExportEntity head3=new ExcelExportEntity("项目岗位", "pjtPostId", 15); entityList.add(head3); ExcelExportEntity head4=new ExcelExportEntity("员工姓名", "userid", 15); entityList.add(head4); for (int i = 0; i < calendarAscDtoList.size(); i++) { String monthTemp = String.valueOf(calendarAscDtoList.get(i).getMonth()); String dayTemp = String.valueOf(calendarAscDtoList.get(i).getDay()); String weekTemp = null; if((calendarAscDtoList.get(i).getWeek() != null)){ int weekInt= -1; try { weekInt =Integer.parseInt(calendarAscDtoList.get(i).getWeek()); }catch(Exception e) {} if(weekInt > 0 && weekInt < 8) { weekTemp = weekStr[weekInt-1]; } } String headstr = null; if(weekTemp == null) { headstr = monthTemp+"月"+dayTemp+"日"; }else { headstr = monthTemp+"月"+dayTemp+"日"+" 星期"+weekTemp+""; } ExcelExportEntity head= new ExcelExportEntity(headstr, calendarAscDtoList.get(i).getId(), 15); entityList.add(head); calendaridList.add(calendarAscDtoList.get(i).getId()); } ExcelExportEntity head5=new ExcelExportEntity("上班天数(日)", "workingDays", 15); entityList.add(head5); ExcelExportEntity head6=new ExcelExportEntity("超时加班(小时)", "timeOutOvertimeHours", 15); entityList.add(head6); ExcelExportEntity head7=new ExcelExportEntity("国定加班(小时)", "countryOvertimeHours", 15); entityList.add(head7); ExcelExportEntity head8=new ExcelExportEntity("值班天数(日)", "ondutyDays", 15); entityList.add(head8); ExcelExportEntity head9=new ExcelExportEntity("备注", "remark", 15); entityList.add(head9); //组建数据集 List> dataResult = new ArrayList>(); String pid=projarrangeDetail.getPid(); if(pid.equals(",")){ pid=null; } if(pid!=null&&pid.split(",").length>0){ pid=pid.split(",")[0]; } //班次名称如果被删除,则不用拼接此条数据 //只查询启用的数据 StringBuffer hql = new StringBuffer(" from ArrangeDutyEntity t where delete_flag <> '1' "); List arrangeDutyEntityList = arrangeDutyService.findHql(hql.toString()); List shiftIdList=new ArrayList(); for (int i = 0; i < arrangeDutyEntityList.size(); i++) { shiftIdList.add(arrangeDutyEntityList.get(i).getId()); } String projectname = departMap.get(pid); //包括该项目id //根据项目id查询所有子节点id List ChildIdList=userDepartOrgDealServiceI.getChildIdByProjectDepartId(pid); ProjArrangeDetailAndUserDto projArrangeDetailAndUserDto=new ProjArrangeDetailAndUserDto(); projArrangeDetailAndUserDto.setChildDepartIdList(ChildIdList); projArrangeDetailAndUserDto.setYearmonth(yearmonth); projArrangeDetailAndUserDto.setPid(pid); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); //查询项目排班详细表数据 List projArrangeDetailAndUserDtolist = projarrangeDetailService.getProjArrangeDetailAndUserByPIdYearMonth( projArrangeDetailAndUserDto,authSql); UserArrangeCalendarDto userArrangeCalendarDto=new UserArrangeCalendarDto(); for(int i=0;i map = new HashMap(); map.put("pid", departMap.get(projArrangeDetailAndUserDtolist.get(i).getPid())); map.put("yearmonth", projArrangeDetailAndUserDtolist.get(i).getYearmonth()); map.put("pjtPostId", projectPostDetailMap.get(projArrangeDetailAndUserDtolist.get(i).getPjtPostId())); map.put("userid", baseUserMap.get(projArrangeDetailAndUserDtolist.get(i).getUserid())); map.put("workingDays", projArrangeDetailAndUserDtolist.get(i).getWorkingDays()); map.put("timeOutOvertimeHours", projArrangeDetailAndUserDtolist.get(i).getTimeOutOvertimeHours()); map.put("countryOvertimeHours", projArrangeDetailAndUserDtolist.get(i).getCountryOvertimeHours()); map.put("ondutyDays", projArrangeDetailAndUserDtolist.get(i).getOndutyDays()); map.put("remark", projArrangeDetailAndUserDtolist.get(i).getRemark()); if(projArrangeDetailAndUserDtolist.get(i).getId()!=null){ userArrangeCalendarDto.setProjarrangeDetailid(projArrangeDetailAndUserDtolist.get(i).getId()); userArrangeCalendarDto.setCalendaridList(calendaridList); //查询员工排班详情表数据 List userArrangeCalendarDtolist=getUserArrangeD(userArrangeCalendarDto); for (int m = 0; m < calendarAscDtoList.size(); m++) { for (int k = 0; k < userArrangeCalendarDtolist.size(); k++) { if(calendarAscDtoList.get(m).getId().equals(userArrangeCalendarDtolist.get(k).getCalendarid())){ if(shiftIdList.contains(userArrangeCalendarDtolist.get(k).getShiftid())){ map.put(calendarAscDtoList.get(m).getId(), arrangeDutyMap.get(userArrangeCalendarDtolist.get(k).getShiftid())); } } } } } dataResult.add(map); } /*for(ProjArrangeDetailAndUserDto projArrangeDetailAndUser:projArrangeDetailAndUserDtolist){ Map map = new HashMap(); map.put("pid", departMap.get(projArrangeDetailAndUser.getPid())); map.put("yearmonth", projArrangeDetailAndUser.getYearmonth()); map.put("pjtPostId", projectPostDetailMap.get(projArrangeDetailAndUser.getPjtPostId())); map.put("userid", baseUserMap.get(projArrangeDetailAndUser.getUserid())); map.put("workingDays", projArrangeDetailAndUser.getWorkingDays()); map.put("timeOutOvertimeHours", projArrangeDetailAndUser.getTimeOutOvertimeHours()); map.put("countryOvertimeHours", projArrangeDetailAndUser.getCountryOvertimeHours()); map.put("ondutyDays", projArrangeDetailAndUser.getOndutyDays()); map.put("remark", projArrangeDetailAndUser.getRemark()); if(projArrangeDetailAndUser.getId()!=null){ userArrangeCalendarDto.setProjarrangeDetailid(projArrangeDetailAndUser.getId()); userArrangeCalendarDto.setCalendaridList(calendaridList); //查询员工排班详情表数据 List userArrangeCalendarDtolist=getUserArrangeD(userArrangeCalendarDto); for (int i = 0; i < calendarAscDtoList.size(); i++) { for (int j = 0; j < userArrangeCalendarDtolist.size(); j++) { if(calendarAscDtoList.get(i).getId().equals(userArrangeCalendarDtolist.get(j).getCalendarid())){ if(shiftIdList.contains(userArrangeCalendarDtolist.get(j).getShiftid())){ map.put(calendarAscDtoList.get(i).getId(), arrangeDutyMap.get(userArrangeCalendarDtolist.get(j).getShiftid())); } } } } } dataResult.add(map); }*/ modelMap.put(MapExcelConstants.ENTITY_LIST, entityList); modelMap.put(MapExcelConstants.MAP_LIST, dataResult); modelMap.put(NormalExcelConstants.FILE_NAME,"项目排班详细-"+projectname); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("项目排班详细列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); // return NormalExcelConstants.JEECG_EXCEL_VIEW; // return MapExcelConstants.JEECG_MAP_EXCEL_VIEW; return "hglexcelview"; } /** * 导出excel模板 * * @param request * @param response */ @RequestMapping(params = "exportXlsTemplate") public String exportXlsTemplateForArrange(ProjarrangeDetailEntity projarrangeDetail,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { String pid=projarrangeDetail.getPid(); if(pid.equals(",")){ pid=null; } if(pid!=null&&pid.split(",").length>0){ pid=pid.split(",")[0]; } //获取项目名称 TSDepart depart = systemService.findUniqueByProperty(TSDepart.class, "id", pid); String[] weekStr = new String[] {"一","二","三","四","五","六","日"}; //日历id List calendaridList=new ArrayList(); //标题 该list中用于存储标题的信息,每一个ExcelExportEntity 表示一列,根据List 的入栈顺序,由左至右,一次排序 List entityList = new ArrayList(); String yearmonth=projarrangeDetail.getYearmonth();; CalendarAscDto calendarAscDto=new CalendarAscDto(); if(projarrangeDetail.getYearmonth()!=null&&projarrangeDetail.getYearmonth().length()>0){ if(yearmonth.indexOf(",")!=-1){ yearmonth=projarrangeDetail.getYearmonth().split(",")[0]; } calendarAscDto.setYear(Integer.parseInt(yearmonth.split("-")[0])); calendarAscDto.setMonth(Integer.parseInt(yearmonth.split("-")[1])); }else{ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM"); String[] dateNumber=simpleDateFormat.format(new Date()).split("-"); calendarAscDto.setYear(Integer.parseInt(dateNumber[0])); calendarAscDto.setMonth(Integer.parseInt(dateNumber[1])); } List calendarAscDtoList=projarrangeDetailService.getCalendar(calendarAscDto); ExcelExportEntity head1=new ExcelExportEntity("项目名称", "pid", 15); entityList.add(head1); ExcelExportEntity head2=new ExcelExportEntity("月度", "yearmonth", 15); entityList.add(head2); ExcelExportEntity head3=new ExcelExportEntity("项目岗位", "pjtPostId", 15); entityList.add(head3); ExcelExportEntity head4=new ExcelExportEntity("员工姓名", "userid", 15); entityList.add(head4); for (int i = 0; i < calendarAscDtoList.size(); i++) { String monthTemp = String.valueOf(calendarAscDtoList.get(i).getMonth()); String dayTemp = String.valueOf(calendarAscDtoList.get(i).getDay()); String weekTemp = null; if((calendarAscDtoList.get(i).getWeek() != null)){ int weekInt= -1; try { weekInt =Integer.parseInt(calendarAscDtoList.get(i).getWeek()); }catch(Exception e) {} if(weekInt > 0 && weekInt < 8) { weekTemp = weekStr[weekInt-1]; } } String headstr = null; if(weekTemp == null) { headstr = monthTemp+"月"+dayTemp+"日"; }else { headstr = monthTemp+"月"+dayTemp+"日"+" 星期"+weekTemp+""; } ExcelExportEntity head= new ExcelExportEntity(headstr, calendarAscDtoList.get(i).getId(), 15); entityList.add(head); calendaridList.add(calendarAscDtoList.get(i).getId()); } //组建数据集 List> dataResult = new ArrayList>(); String hqlDute = " from ArrangeDutyEntity where pid =? or pid is null and delete_flag <> '1' "; List pArrangeList = systemService.findHql(hqlDute, pid); List pArrangeNamelist = new ArrayList(); for(ArrangeDutyEntity arrange : pArrangeList) { pArrangeNamelist.add(arrange.getDutyName()); } String projectname = depart.getDepartname(); //包括该项目id //根据项目id查询所有子节点id List ChildIdList=userDepartOrgDealServiceI.getChildIdByProjectDepartId(pid); ProjArrangeDetailAndUserDto projArrangeDetailAndUserDto=new ProjArrangeDetailAndUserDto(); projArrangeDetailAndUserDto.setChildDepartIdList(ChildIdList); projArrangeDetailAndUserDto.setYearmonth(yearmonth); projArrangeDetailAndUserDto.setPid(pid); //获取最新的人员与岗位匹配数据,预置到模板中 String projPostHistory = "SELECT\n" + " detail.userid as userid ,post.ptj_post_name as postname\n" + "FROM\n" + " (\n" + " SELECT\n" + " userid,max(yearmonth) as yearmonth\n" + " FROM\n" + " t_bus_projarrange_detail detail\n" + " WHERE\n" + " detail.pid =? \n" + " group by userid )temp \n" + "left join t_bus_projarrange_detail detail on temp.userid = detail.userid and temp.yearmonth = detail.yearmonth \n" + " left join t_bus_project_post_detail post on post.id = detail.pjt_postid"; List> userPostRes = systemService.findForJdbc(projPostHistory,pid); HashMap userPostMap = new HashMap(); for(Map userPost : userPostRes){ userPostMap.put(userPost.get("userid").toString(), userPost.get("postname").toString()); } //查询此项目所有当前在职人员 //人员姓名+身份证后四位,避免重复 String userSql = "select user.id as userid, concat(realname,right(idcard,4)) as realname \n" + "from t_s_base_user user left join t_s_user su on su.id = user.id \n" + "left join t_s_user_org uorg on user.id = uorg.user_id and uorg.ifpluralism = '0'\n" + "left join t_s_depart depart on depart.id = uorg.org_id\n" + "left join t_s_depart pdepart on pdepart.id = depart.parentdepartid\n" + "LEFT JOIN t_bus_user_personnel up ON up.userid = user.id \n"+ "where up.position_status in ('1','2') and user.delete_flag = '0' and (pdepart.id =? or depart.id = ? ) " + "order by convert(user.realname using gbk) collate gbk_Chinese_ci asc"; List> userRes = systemService.findForJdbc(userSql, pid,pid); for(Map oneUser : userRes){ Map map = new HashMap(); map.put("pid", depart.getDepartname()); map.put("yearmonth", yearmonth); map.put("pjtPostId", userPostMap.get(oneUser.get("userid").toString())); map.put("userid", oneUser.get("realname")); dataResult.add(map); } //查询项目所有岗位设置,做数据验证 String hqlPost = " from ProjectPostDetailEntity where pid =? and delete_flag <> '1' "; List postList = systemService.findHql(hqlPost, pid); List postNameList = new ArrayList(); for(ProjectPostDetailEntity post : postList) { postNameList.add(post.getPtjPostName()); } List> validParamMap = new ArrayList>(); Map paramArrange = new HashMap(); paramArrange.put(HGLExcelConstant.VALIDTIONSTRS, pArrangeNamelist); paramArrange.put(HGLExcelConstant.FIRSTROW,3); paramArrange.put(HGLExcelConstant.FIRSTCOL,4); paramArrange.put(HGLExcelConstant.ENDROW,dataResult.size()+2); paramArrange.put(HGLExcelConstant.ENDCOL,entityList.size()-1); validParamMap.add(paramArrange); Map paramPost = new HashMap(); paramPost.put(HGLExcelConstant.VALIDTIONSTRS, postNameList); paramPost.put(HGLExcelConstant.FIRSTROW,3); paramPost.put(HGLExcelConstant.FIRSTCOL,2); paramPost.put(HGLExcelConstant.ENDROW,dataResult.size()+2); paramPost.put(HGLExcelConstant.ENDCOL,2); validParamMap.add(paramPost); // // modelMap.put(HGLExcelConstant.VALIDTIONSTRS, pArrangeNamelist); // modelMap.put(HGLExcelConstant.FIRSTROW,3); // modelMap.put(HGLExcelConstant.FIRSTCOL,4); // modelMap.put(HGLExcelConstant.ENDROW,dataResult.size()+2); // modelMap.put(HGLExcelConstant.ENDCOL,entityList.size()-1); modelMap.put(HGLExcelConstant.VALIDPARAM, validParamMap); modelMap.put(HGLExcelConstant.CHECKPARAM,yearmonth); modelMap.put(MapExcelConstants.ENTITY_LIST, entityList); modelMap.put(MapExcelConstants.MAP_LIST, dataResult); modelMap.put(NormalExcelConstants.FILE_NAME,"项目排班模板-"+projectname+"-"+yearmonth); ExportParams exportp = new ExportParams("项目排班模板-"+projectname+"-"+yearmonth, "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息"); exportp.setType(ExcelType.XSSF); modelMap.put(NormalExcelConstants.PARAMS,exportp); return HGLExcelConstant.HGL_MAP_EXCEL_VIEW; } /** * 导出excel 使模板 * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(ProjarrangeDetailEntity projarrangeDetail,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME,"项目排班详细"); modelMap.put(NormalExcelConstants.CLASS,ProjarrangeDetailEntity.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 { String checkMsg = HGLExcelImportUtils.getCheckMsg(file.getInputStream(), 2, 0, 0); if(checkMsg.equals("false")) { j.setMsg("文件校验失败,必须上传系统导出的excel模板,请点击【导出排班模板】排班后再上传"); j.setSuccess(false); return j; } HGLExcelResult exceldata = HGLExcelImportUtils.getDataFromExcel(file.getInputStream(), 2, 1); String month = exceldata.getDataList().get(0).get(1); if(!month.equals(checkMsg)) { j.setMsg("文件月份校验失败,请先选择【排班月度】后点击【导出排班模板】,然后排班上传文件"); j.setSuccess(false); return j; } TSDepart depart = systemService.findUniqueByProperty(TSDepart.class, "departname", exceldata.getDataList().get(0).get(0)); String pid = depart.getId(); if(depart == null) { j.setMsg("项目名称错误,无法匹配系统所属部门档案"); j.setSuccess(false); return j; } List proGeneralL = systemService.findHql( " from ProjArrangeGeneralEntity where belongUnitid =? and yearmonth = ? ", pid,month); // List headList = exceldata.getHeaderList(); ProjArrangeGeneralEntity projGeneral = null; if(proGeneralL.size() > 0) { projGeneral = proGeneralL.get(0); if(projGeneral.getArrangeDutyStatus().equals(Globals.ARRANGESTATUS_2)) { j.setSuccess(false); j.setMsg("文件导入失败,排班已上报,不允许修改"); return j; } } TSUser user = ResourceUtil.getSessionUser(); List> res = systemService.findForJdbc( "select count(*) count from t_s_user_org uo where uo.user_id =? and uo.org_id = ? ",user.getId(),pid); if((Long)res.get(0).get("count") == 0) { j.setSuccess(false); j.setMsg("文件导入失败,用户【"+user.getRealName()+"】没有项目【"+depart.getDepartname()+"】管理权限,不允许导入"); return j; } //缓存项目岗位 String hqlPost = " from ProjectPostDetailEntity where pid =? and delete_flag <> '1' "; List postList = systemService.findHql(hqlPost, pid); Map projectPostDetailMap=new HashMap(); Map postdutyNumMap=new HashMap(); for(ProjectPostDetailEntity post : postList) { projectPostDetailMap.put(post.getPtjPostName(), post.getId()); postdutyNumMap.put(post.getPtjPostName(), post.getNeedNumber()); } //缓存班次map String hqlDute = " from ArrangeDutyEntity where pid =? or pid is null and delete_flag <> '1' "; List pArrangeList = systemService.findHql(hqlDute, pid); HashMap pArrangeMap = new HashMap(); for(ArrangeDutyEntity arrange : pArrangeList) { pArrangeMap.put(arrange.getDutyName(), arrange.getId()); } String checkResult = checkArrange(exceldata,pArrangeMap,projectPostDetailMap,postdutyNumMap); if(StringUtils.isNotEmpty(checkResult)) { j.setSuccess(false); j.setMsg("文件导入失败,排班内容错误,清单如下:
"+checkResult); return j; } //缓存日历,把excel中的所有日历都查询出来 HashMap calMap = new HashMap(); for(int i = 0 ; i < exceldata.getHeaderList().size(); i++) { String colTitle = exceldata.getHeaderList().get(i); if(colTitle.indexOf("月") > -1 && colTitle.indexOf("日") > -1) { String titleMonth = colTitle.substring(0, colTitle.indexOf("月")); String titleDay = colTitle.substring(colTitle.indexOf("月")+1, colTitle.indexOf("日")); List calList = systemService.findHql( " from CalendarEntity where month =? and year =? and day =? ", Integer.parseInt(titleMonth) ,Integer.parseInt(month.substring(0,4)),Integer.parseInt(titleDay)); calMap.put(colTitle,calList.get(0).getId()); } } //缓存项目人员 HashMap userMap = new HashMap(); String userSql = "select user.id as userid, concat(realname,right(idcard,4)) as realname \n" + "from t_s_base_user user left join t_s_user su on su.id = user.id \n" + "left join t_s_user_org uorg on user.id = uorg.user_id and uorg.ifpluralism = '0'\n" + "left join t_s_depart depart on depart.id = uorg.org_id\n" + "left join t_s_depart pdepart on pdepart.id = depart.parentdepartid\n" + "LEFT JOIN t_bus_user_personnel up ON up.userid = user.id \n"+ "where up.position_status in ('1','2') and user.delete_flag = '0' and pdepart.id =? or depart.id =? "; List> userRes = systemService.findForJdbc(userSql, pid,pid); for(Map oneRes :userRes) { userMap.put(oneRes.get("realname").toString(),oneRes.get("userid").toString()); } // List proGeneralL = systemService.findHql(" from ProjArrangeGeneralEntity where belongUnitid = ? and yearmonth = ?", pid,month); List headList = exceldata.getHeaderList(); if(null != projGeneral) { // projGeneral = proGeneralL.get(0); // if(!projGeneral.getArrangeDutyStatus().equals(Globals.ARRANGESTATUS_0)) { // j.setSuccess(false); // j.setMsg("文件导入失败,排班已上报,不允许修改"); // return j; // } List details = systemService.findByProperty(ProjarrangeDetailEntity.class, "projarrangeGeneralid", projGeneral.getId()); HashMap projMap = new HashMap(); for(ProjarrangeDetailEntity projentity : details) { projMap.put(projentity.getUserid(), projentity); } for(List data: exceldata.getDataList()) { Map myMap = new HashMap(); for(int i = 4 ; i < data.size(); i++) { if(!pArrangeMap.containsKey(data.get(i))) continue; myMap.put(calMap.get(headList.get(i)), pArrangeMap.get(data.get(i))); } if(projMap.get(userMap.get(data.get(3))) != null ){ ProjarrangeDetailEntity projarrangeDetailEntity=arrangeDutyAndOndutyServiceI.getDayAndTimeFO(projMap.get(userMap.get(data.get(3))),myMap); arrangeDutyAndOndutyServiceI.saveProjarrangeDetail(projarrangeDetailEntity, myMap, Globals.ARRANGESTATUS_0); }else if(userMap.containsKey(data.get(3))) { importSaveDetail(projGeneral, userMap, projectPostDetailMap, data, calMap, pArrangeMap, month, pid, headList); } } }else { String xiuxi = arrangeDutyService.getDUTYTYPE_xiuxiId(); //没有排班 projGeneral = new ProjArrangeGeneralEntity(); projGeneral.setBelongUnitid(pid); projGeneral.setYearmonth(month); projGeneral.setArrangeDutyStatus("0"); systemService.save(projGeneral); for(List data: exceldata.getDataList()) { if(userMap.containsKey(data.get(3))) { importSaveDetail(projGeneral, userMap, projectPostDetailMap, data, calMap, pArrangeMap, month, pid, headList); } } } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); logger.error(ExceptionUtil.getExceptionMessage(e)); }finally{ try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } private void importSaveDetail(ProjArrangeGeneralEntity projGeneral, HashMap userMap,Map projectPostDetailMap, List data,HashMap calMap,HashMap pArrangeMap,String month,String pid, ListheadList) throws Exception { ProjarrangeDetailEntity projentity = new ProjarrangeDetailEntity(); projentity.setProjarrangeGeneralid(projGeneral.getId()); projentity.setPjtPostId(projectPostDetailMap.get(data.get(2))); projentity.setUserid(userMap.get(data.get(3))); projentity.setYearmonth(month); projentity.setPid(pid); Map myMap = new HashMap(); for(int i = 4 ; i < data.size(); i++) { if(!pArrangeMap.containsKey(data.get(i))) continue; myMap.put(calMap.get(headList.get(i)), pArrangeMap.get(data.get(i))); } // projentity=arrangeDutyAndOndutyServiceI.getDayAndTimeFO(projentity,myMap); arrangeDutyAndOndutyServiceI.saveProjarrangeDetail(projentity, myMap, Globals.ARRANGESTATUS_0); } /** * 校验必输项 * 检查是否超出岗位设置人数限制 * */ private String checkArrange(HGLExcelResult exceldata,Map arrangeMap,Map postMap,Map postdutyNumMap) { StringBuffer unFormatStr = new StringBuffer(); List headList = exceldata.getHeaderList(); List> dataList = exceldata.getDataList(); for(int i = 0 ; i < dataList.size() ; i++) { List arrangeData = dataList.get(i); for(int j = 4; j < arrangeData.size(); j ++) { if(StringUtils.isEmpty(arrangeData.get(j))) { unFormatStr.append("【"+arrangeData.get(3)+"】"+headList.get(j)+"未排班;
"); } else if(!arrangeMap.containsKey(arrangeData.get(j))) { unFormatStr.append("【"+arrangeData.get(3)+"】"+headList.get(j)+"班次【"+arrangeData.get(j)+"】不存在;
"); } } if(StringUtils.isEmpty(arrangeData.get(2))) { unFormatStr.append("【"+arrangeData.get(3)+"】项目岗位不能为空;
"); } else if(!postMap.containsKey(arrangeData.get(2))) { unFormatStr.append("【"+arrangeData.get(3)+"】项目岗位【"+arrangeData.get(2)+"】不存在;
"); }else{ postdutyNumMap.put(arrangeData.get(2), postdutyNumMap.get(arrangeData.get(2))-1); } } for (Entry post : postdutyNumMap.entrySet()) { if(post.getValue() < 0) { unFormatStr.append("【"+post.getKey()+"】项目岗位超出岗位编制人数
"); } } return unFormatStr.toString(); } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listProjarrangeDetails=projarrangeDetailService.getList(ProjarrangeDetailEntity.class); return listProjarrangeDetails; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { ProjarrangeDetailEntity task = projarrangeDetailService.get(ProjarrangeDetailEntity.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 ProjarrangeDetailEntity projarrangeDetail, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(projarrangeDetail); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ projarrangeDetailService.save(projarrangeDetail); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = projarrangeDetail.getId(); URI uri = uriBuilder.path("/rest/projarrangeDetailController/" + 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 ProjarrangeDetailEntity projarrangeDetail) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(projarrangeDetail); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ projarrangeDetailService.saveOrUpdate(projarrangeDetail); } 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) { projarrangeDetailService.deleteEntityById(ProjarrangeDetailEntity.class, id); } /** * 前端获取日历表json数据 * @author zbw * 2017-10-24 * @param calendar * @param request * @param response * @return */ /*@RequestMapping(params = "getCalendar") @ResponseBody public AjaxJson getCalendar(CalendarEntity calendar, HttpServletRequest request, HttpServletResponse response) { AjaxJson j = new AjaxJson(); DataGrid dataGrid=new DataGrid(); dataGrid.setField("id,year,month,day,week,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,"); CriteriaQuery cq = new CriteriaQuery(CalendarEntity.class,dataGrid); //查询条件组装器 //org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, calendar, request.getParameterMap()); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, calendar, request.getParameterMap()); try{ //自定义追加查询条件 cq.eq("year", calendar.getYear()); cq.eq("month", calendar.getMonth()); //排序 Map map = new HashMap(); map.put("day", "asc"); cq.setOrder(map); //排序 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); List list=this.calendarService.getDataGridReturn(cq, true).getRows(); Map myMap=new HashMap(); myMap.put("0", list); j.setAttributes(myMap); return j; }*/ /** * 员工排班保存总方法 * * @author zbw * 2017-10-28 * @param strmap * @param calendaridStr * @param request * @param response * @return */ /*国定加班时长计算规则 1.节假日区分=国定 1.1国定加班时长=基准工时相加 //1.2轮流加班班次时(轮流加班值班国家法定节假日不会出现,所以不考虑) 超时加班时长计算规则 2.1.超时加班时长=月度国定节假日以外所有班次的基准工时-月度法定工作日天数*8 2.2.轮流加班班次时:超时加班时长相加 值班天数计算规则 值班天数=班次类型为值班时天数相加 3上班天数计算规则 3.1上班天数=班次类型为常班,日班,夜班时天数相加*/ @RequestMapping(params = "saveRows") @ResponseBody public AjaxJson saveRows(String strmap,String calendaridStr,String yearmonth,String pid,String arrangeDutyStatus, HttpServletRequest request, HttpServletResponse response){ AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } JSONArray jsonArray = JSONArray.fromObject(strmap); // 首先把字符串转成 JSONArray 对象 for (int k = 0; k < jsonArray.size(); k++) { //每一行的键值数据 Map map=jsonArray.getJSONObject(k); //日期calendarId String[] calendaridArr=calendaridStr.split(","); //List calendarIdList=extractIdListByComma(calendaridStr); //只有日期和班次键值数据 Map myMap=new HashMap(); //所有班次信息 //List shiftList=new ArrayList(); for (int i = 0; i < calendaridArr.length; i++) { for (Entry entryParam : map.entrySet()) { //System.out.println("key="+entryParam.getKey()+",value="+entryParam.getValue()); if(entryParam.getKey().equals(calendaridArr[i])){ myMap.put(entryParam.getKey(), entryParam.getValue()); //shiftList.add(entryParam.getValue().toString()); } } } ProjarrangeDetailEntity projarrangeDetailEntity=new ProjarrangeDetailEntity(); projarrangeDetailEntity.setId(map.get("id").toString()); projarrangeDetailEntity.setPjtPostId(map.get("pjtPostId").toString()); projarrangeDetailEntity.setUserid(map.get("userid").toString()); projarrangeDetailEntity.setYearmonth(yearmonth); projarrangeDetailEntity.setPid(pid); try { //天数和时间算法 projarrangeDetailEntity=arrangeDutyAndOndutyServiceI.getDayAndTimeFO(projarrangeDetailEntity,myMap); //项目排班详细表保存新增/更新的行数据 j=arrangeDutyAndOndutyServiceI.saveProjarrangeDetail(projarrangeDetailEntity,myMap,arrangeDutyStatus); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return j; } /** * 验证班次停用启用状态 * @author zbw * 2017-12-11 * @param strmap * @param request * @param response * @return */ @RequestMapping(params = "checkShiftStatus") @ResponseBody public AjaxJson checkShiftStatus(String strmap, HttpServletRequest request, HttpServletResponse response){ AjaxJson j = new AjaxJson(); List shiftIdList=new ArrayList(); JSONArray jsonArray = JSONArray.fromObject(strmap); // 首先把字符串转成 JSONArray 对象 for (int k = 0; k < jsonArray.size(); k++) { //每一行的键值数据 Map map=jsonArray.getJSONObject(k); for (Entry entryParam : map.entrySet()) { //System.out.println("key="+entryParam.getKey()+",value="+entryParam.getValue()); if(!shiftIdList.contains(entryParam.getValue().toString())){ shiftIdList.add(entryParam.getValue().toString()); } } } //班次名称查询只查询删除和停用的数据 StringBuffer hql = new StringBuffer(" from ArrangeDutyEntity t where status = '1' "); List arrangeDutyEntityListDT = arrangeDutyService.findHql(hql.toString()); List shiftIdListDT=new ArrayList(); Map shiftIdMapDT=new HashMap(); for (int i = 0; i < arrangeDutyEntityListDT.size(); i++) { shiftIdListDT.add(arrangeDutyEntityListDT.get(i).getId()); shiftIdMapDT.put(arrangeDutyEntityListDT.get(i).getId(), arrangeDutyEntityListDT.get(i).getDutyName()); } String msg=""; for (int i = 0; i < shiftIdList.size(); i++) { if(shiftIdListDT.contains(shiftIdList.get(i))){ if(msg.length()!=0){ msg+=","+shiftIdMapDT.get(shiftIdList.get(i)).toString(); }else{ msg=shiftIdMapDT.get(shiftIdList.get(i)).toString(); } } } if(msg.length()!=0){ msg+="为停用状态"; j.setMsg(msg); j.setSuccess(false); } return j; } /** * 上报总方法 * @author zbw * 2017-12-8 * @param yearmonth * @param pid * @param request * @param response * @return */ @RequestMapping(params = "putOutProjarrange") @ResponseBody public AjaxJson putOutProjarrange(String yearmonth,String pid, HttpServletRequest request, HttpServletResponse response){ AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } TSUser tSUser=ResourceUtil.getSessionUser(); try { //查询项目排班总览表数据 StringBuffer hql = new StringBuffer(" FROM ProjArrangeGeneralEntity where belongUnitid=? and yearmonth=? "); List projArrangeGeneralEntityList = systemService.findHql(hql.toString(),pid,yearmonth); if(projArrangeGeneralEntityList.size()>0){ //查询项目排班详细表数据计算排班人数 hql = new StringBuffer(" FROM ProjarrangeDetailEntity where pid=? and yearmonth=? "); List projarrangeDetailEntityList = systemService.findHql(hql.toString(),pid,yearmonth); projArrangeGeneralEntityList.get(0).setPeopleQuantity(projarrangeDetailEntityList.size()); projArrangeGeneralEntityList.get(0).setArrangeDutyStatus(Globals.ARRANGESTATUS_1); projArrangeGeneralEntityList.get(0).setReporterId(tSUser.getId()); } systemService.saveOrUpdate(projArrangeGeneralEntityList.get(0)); j.setSuccess(true); j.setMsg("操作成功"); } catch (Exception e) { j.setMsg("操作失败"); j.setSuccess(false); e.printStackTrace(); } return j; } /** * 月度排班总方法; * @author zbw * 2017-11-7 * @param arrangeDutyOperateId * @param yearmonth * @param pid * @param arrangeDutyStatus * @return */ @RequestMapping(params = "saveMonthArrangeDutyOperate") @ResponseBody public AjaxJson saveMonthArrangeDutyOperate(String arrangeDutyOperateId,String yearmonth,String pid,String arrangeDutyStatus){ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM-dd HH:mm:ss ms"); AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } try { long start = System.currentTimeMillis(); System.out.println(simpleDateFormat.format(new Date())); j=arrangeDutyAndOndutyServiceI.saveMonthArrangeDutyOperate(arrangeDutyOperateId, yearmonth, pid, arrangeDutyStatus); long end = System.currentTimeMillis(); System.out.println(end-start); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); j.setMsg("操作失败"); j.setSuccess(false); // throw new BusinessException(e.getMessage()); } return j; } /** * 轮流值班排班总方法; * @author zbw * 2017-11-7 * @param arrangeDutyOperateId * @param yearmonth * @param pid * @param arrangeDutyStatus * @return */ @RequestMapping(params = "saveOndutyArrangeDutyOperate") @ResponseBody public AjaxJson saveOndutyArrangeDutyOperate(String onDutyOperateId,String yearmonth,String pid,String arrangeDutyStatus){ AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } try { j=arrangeDutyAndOndutyServiceI.saveOndutyArrangeDutyOperate(onDutyOperateId, yearmonth, pid, arrangeDutyStatus); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); j.setSuccess(false); } return j; } /** * 异步验证是否已经上报,若已确认的话不能再次上报 * @author zbw * 2017-11-28 * @param pid * @param yearmonth * @return */ @RequestMapping(params = "checkMonthArrangeDutyStatus") @ResponseBody public AjaxJson checkMonthArrangeDutyStatus(String pid,String yearmonth){ AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } j=projarrangeDetailService.checkMonthArrangeDutyStatus(pid, yearmonth); return j; } /** * 月度排班总方法; * @author zbw * 2017-11-7 * @param arrangeDutyOperateId * @param yearmonth * @param pid * @param arrangeDutyStatus * @return */ /*@RequestMapping(params = "saveMonthArrangeDutyOperate") @ResponseBody public AjaxJson saveOnDutyOperate(String onDutyOperateId,String yearmonth,String pid,String arrangeDutyStatus){ AjaxJson j = new AjaxJson(); if(pid!=null&&pid.length()>0){ pid=pid.split(",")[0]; } j=projarrangeDetailService.saveMonthArrangeDutyOperate(onDutyOperateId, yearmonth, pid, arrangeDutyStatus); return j; }*/ /** * 异步判断是否可以行编辑 * @author zbw * 2017-11-12 * @param projarrangeDetailEntity * @return */ @RequestMapping(params = "getCheckEdit") @ResponseBody public AjaxJson getCheckEdit(ProjarrangeDetailEntity projarrangeDetailEntity){ AjaxJson j = new AjaxJson(); //根据主键id和月度查询项目排班详细表数据 StringBuffer hql = new StringBuffer(" from ProjarrangeDetailEntity t where t.id=? and t.yearmonth=? "); List projarrangeDetailList = projarrangeDetailService.findHql(hql.toString() , projarrangeDetailEntity.getId(),projarrangeDetailEntity.getYearmonth()); boolean flag=false; String runWay=""; if(projarrangeDetailList.size()!=0){ String userId=projarrangeDetailList.get(0).getUserid(); //根据月度查询项目排班操作表数据 hql = new StringBuffer(" from ArrangeDutyOperateEntity t where t.yearmonth=? "); List arrangeDutyOperateList = projarrangeDetailService.findHql(hql.toString() , projarrangeDetailEntity.getYearmonth()); for (int i = 0; i < arrangeDutyOperateList.size(); i++) { List userIdList = extractIdListByComma(arrangeDutyOperateList.get(i).getUserid()); if(userIdList.contains(userId)){ // if(arrangeDutyOperateList.get(i).getRunway().equals(Globals.other_jijiabanfei)|| // arrangeDutyOperateList.get(i).getRunway().equals(Globals.other_wujiabanfei)|| // arrangeDutyOperateList.get(i).getRunway().equals(Globals.f2t_jijiabanfei)|| // arrangeDutyOperateList.get(i).getRunway().equals(Globals.f2t_wujiabanfei)){ // flag=true; // break; // }else{ // runWay=ProjectArrangeCommonMethod.getRunWayByCode(arrangeDutyOperateList.get(i).getRunway()); // flag=false; // break; // } flag=true; break; }else{ runWay="无"; flag=false; } } }else{ runWay="无"; flag=false; } if(flag==false){ if(runWay=="无"){ j.setMsg("通过Excel导入的排班不能进行修改,请到Excel排班模板中修改后导入"); }else{ j.setMsg("当前员工运转方式为'"+runWay+"',不可以编辑班次。"); } j.setSuccess(false); } return j; } /** * 复制上个月的月度排班 * PS: * 1、只复制运转方式为做五休二的排班 * */ @RequestMapping(params = "copyLastMonthArrange") @ResponseBody public AjaxJson copyLastMonthArrange(String yearmonth,String pid, HttpServletRequest request, HttpServletResponse response){ AjaxJson j = new AjaxJson(); if(StringUtil.isEmpty(pid) || StringUtil.isEmpty(yearmonth)){ j.setMsg("项目以及排班月度不能为空。"); j.setSuccess(false); return j; } // StringBuffer hql = new StringBuffer(" from ArrangeDutyOperateEntity t where runway in ('").append(Globals.f2t_jijiabanfei) // .append("','").append(Globals.f2t_wujiabanfei).append("')"); // hql.append(" and t.yearmonth = ? and t.pid =? "); List curMonthArrangeDutyOptList = projDao.getArrangeDutyOperate4CopyLastMonth(yearmonth, pid); if(curMonthArrangeDutyOptList.size() > 0) { j.setMsg("本月做五休二运转方式已经进行了排班,不能复制上月排班"); j.setSuccess(false); return j; } // TSUser tSUser=ResourceUtil.getSessionUser(); try { String lastMonth = HGLDateUtils.addDateMonth(yearmonth, -1); // 先查询上个月的做五休二方式的排班list List lastMonthArrangeDutyOptList = projDao.getArrangeDutyOperate4CopyLastMonth(lastMonth,pid); String checkRet = checkUserConfig(lastMonthArrangeDutyOptList); if(StringUtils.isNotEmpty(checkRet)) { j.setMsg("复制排班失败,"+checkRet); j.setSuccess(false); return j; } String arrangeDutyOperateIds = ""; for( ArrangeDutyOperateEntity optEntity : lastMonthArrangeDutyOptList) { //清空原id,表示此条记录为新增 optEntity.setId(null); optEntity.setYearmonth(yearmonth); // ArrangeDutyOperateEntity t = new ArrangeDutyOperateEntity(); // MyBeanUtils.copyBeanNotNull2Bean(optEntity, t); AjaxJson aj = arrangeDutyOperateService.saveArrangeDutyOperate(optEntity,"1",arrangeDutyOperateIds); //把新增的排班oprate ID记录下来,为后续生成排班做准备 arrangeDutyOperateIds = aj.getAttributes().get("arrangeDutyOperateId").toString(); } saveMonthArrangeDutyOperate(arrangeDutyOperateIds, yearmonth, pid, "0"); j.setSuccess(true); j.setMsg("操作成功"); } catch (Exception e) { j.setMsg("操作失败"); j.setSuccess(false); e.printStackTrace(); } return j; } private String checkUserConfig(List lastMonthArrangeDutyOptList ) { String ret = ""; if(lastMonthArrangeDutyOptList == null || lastMonthArrangeDutyOptList.size() == 0) return ret; List> postConfig = systemService.findForJdbc("select id,ptj_post_name, need_number ,pid " + "from t_bus_project_post_detail where pid =? and delete_flag = 0 ", lastMonthArrangeDutyOptList.get(0).getPid()); HashMap configCountMap = new HashMap(); HashMap arrangeCountMap = new HashMap(); HashMap postNameMap = new HashMap(); for (Map map : postConfig) { postNameMap.put(map.get("id").toString(), map.get("ptj_post_name").toString()); configCountMap.put(map.get("id").toString(), Integer.valueOf( map.get("need_number").toString())); } // for (ArrangeDutyOperateEntity operate : lastMonthArrangeDutyOptList) { // if(configCountMap.get(operate.getPjtPostId()) >= operate.getDeployPeopleNum()) { // configCountMap.put(operate.getPjtPostId(), configCountMap.get(operate.getPjtPostId()) - operate.getDeployPeopleNum()); // }else { // ret = "岗位【"+postNameMap.get(operate.getPjtPostId())+"】排班人数超过项目岗位编制人数,请联系人力资源部"; // return ret; // } // } for (ArrangeDutyOperateEntity operate : lastMonthArrangeDutyOptList) { arrangeCountMap.put(operate.getPjtPostId(), arrangeCountMap.containsKey(operate.getPjtPostId()) ? arrangeCountMap.get(operate.getPjtPostId()) + operate.getDeployPeopleNum() : operate.getDeployPeopleNum()); } //检查岗位配置中各岗位配置数量,是否超出 for (Entry arrange : arrangeCountMap.entrySet()) { if(configCountMap.get(arrange.getKey()) < arrange.getValue()) { ret += String.format("
岗位【%s】,复制排班人数%d人,项目岗位编制人数%d人;", postNameMap.get(arrange.getKey()),arrange.getValue(),configCountMap.get(arrange.getKey())) ; } } return StringUtils.isNotEmpty(ret) ? "以下岗位超出编制,请联系人力资源部:"+ret :""; } @RequestMapping(params = "redoArrange") @ResponseBody public AjaxJson redoArrange(String yearmonth,String pid, HttpServletRequest request, HttpServletResponse response){ //检查是否可以恢复 AjaxJson j = checkRedo(yearmonth, pid); if(!j.isSuccess()) return j; TSDepart depart = systemService.findUniqueByProperty(TSDepart.class, "id", pid); try { ProjArrangeDetailAndUserDto paramDto = new ProjArrangeDetailAndUserDto(); //查询项目排班详细表数据 List projArrangeDetaillist = systemService.findHql( " FROM ProjarrangeDetailEntity where pid =? and yearmonth=? ", pid,yearmonth); projarrangeDetailService.getProjArrangeDetailAndUserByPIdYearMonth( paramDto,null); for(ProjarrangeDetailEntity projDetail: projArrangeDetaillist){ //查询员工排班历史详情表数据(历史只保留了一份) List historyList = systemService.findHql(" FROM UserArrangeDetailHistoryEntity where projarrangeDetailid = ?", projDetail.getId()); Map caldutyMap = new HashMap(); for(UserArrangeDetailHistoryEntity history:historyList) { caldutyMap.put(history.getCalendarid(),history.getShiftid()); } projDetail=arrangeDutyAndOndutyServiceI.getDayAndTimeFO(projDetail,caldutyMap); arrangeDutyAndOndutyServiceI.saveProjarrangeDetail(projDetail, caldutyMap, Globals.ARRANGESTATUS_0,false); } String message = "成功恢复项目【"+depart.getDepartname()+"】【"+yearmonth+"】月度排班"; j.setSuccess(true); j.setMsg(message); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); } catch (Exception e) { j.setMsg("操作失败"); j.setSuccess(false); e.printStackTrace(); } return j; } private AjaxJson checkRedo(String yearmonth,String pid) { AjaxJson j = new AjaxJson(); if(StringUtil.isEmpty(pid) || StringUtil.isEmpty(yearmonth)){ j.setMsg("项目以及排班月度不能为空。"); j.setSuccess(false); return j; } List projArrangeGenerallist = systemService.findHql( " FROM ProjArrangeGeneralEntity where belongUnitid =? and yearmonth=? ", pid,yearmonth); if(projArrangeGenerallist.size() == 0) { j.setMsg("当前项目月度【"+yearmonth+"】未排班,无可恢复数据"); j.setSuccess(false); return j; } if(projArrangeGenerallist.get(0).getArrangeDutyStatus().equals(Globals.ARRANGESTATUS_2)) { j.setMsg("当前项目月度【"+yearmonth+"】排班已上报,不能恢复"); j.setSuccess(false); return j; } return j; } /** * 用户选择机构列表跳转页面 * 项目名称选择 * @return */ /*@RequestMapping(params = "departZTreeSelect") public String departZTreeSelect(HttpServletRequest req) { req.setAttribute("orgIds", req.getParameter("orgIds")); return "cn/com/lzt/projarrangedetail/departZTreeSelect"; }*/ //update--start--by:jg_renjie--at:20160318 for:#942 【组件封装】组织机构弹出模式,目前是列表,得改造成树方式 //update-start--Author: os_renjie Date:20160529 for:TASK #1056 【bug】用户编辑,弹出组织机构,默认没选中 /*@RequestMapping(params = "getDepartZTreeInfo") @ResponseBody public AjaxJson getDepartZTreeInfo(HttpServletRequest request, HttpServletResponse response){ AjaxJson j = new AjaxJson(); String orgIds = request.getParameter("orgIds"); String[] ids = new String[]{}; if(StringUtils.isNotBlank(orgIds)){ orgIds = orgIds.substring(0, orgIds.length()-1); ids = orgIds.split("\\,"); } String parentid = request.getParameter("parentid"); List tSDeparts = new ArrayList(); StringBuffer hql = new StringBuffer(" from TSDepart t where 1=1 "); if(StringUtils.isNotBlank(parentid)){ TSDepart dePart = this.systemService.getEntity(TSDepart.class, parentid); hql.append(" and TSPDepart = ?"); tSDeparts = this.systemService.findHql(hql.toString(), dePart); } else { hql.append(" and t.orgType = ?"); tSDeparts = this.systemService.findHql(hql.toString(), "1"); } List> dateList = new ArrayList>(); if(tSDeparts.size()>0){ Map map = null; String sql = null; Object[] params = null; for(TSDepart depart:tSDeparts){ map = new HashMap(); map.put("id", depart.getId()); map.put("name", depart.getDepartname()); if(ids.length>0){ for(String id:ids){ if(id.equals(depart.getId())){ map.put("checked", true); } } } if(StringUtils.isNotBlank(parentid)){ map.put("pId", parentid); } else{ map.put("pId", "1"); } //根据id判断是否有子节点 sql = "select count(1) from t_s_depart t where t.parentdepartid = ?"; params = new Object[]{depart.getId()}; long count = this.systemService.getCountForJdbcParam(sql, params); if(count>0){ map.put("isParent",true); } dateList.add(map); } } net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(dateList); j.setMsg(jsonArray.toString()); return j; }*/ //update-start--Author: os_renjie Date:20160529 for:TASK #1056 【bug】用户编辑,弹出组织机构,默认没选中 //update--end--by:jg_renjie--at:20160318 for:#942 【组件封装】组织机构弹出模式,目前是列表,得改造成树方式 }