| | |
| | | @RequestMapping(value = "/schedulePage") |
| | | public String schedulePage(Integer lineId, Integer companyId, Model model) { |
| | | TLine line = tLineService.selectById(lineId); |
| | | TCompany company = itCompanyService.selectById(companyId); |
| | | TLineCompany lineCompany = itLineCompanyService.selectOne(new EntityWrapper<TLineCompany>() |
| | | .eq("lineId", lineId).eq("companyId", companyId)); |
| | | List<TLineCompany> lineCompanies = getLineCompanies(lineId); |
| | | TLineCompany currentLineCompany = null; |
| | | if (companyId != null) { |
| | | currentLineCompany = checkLineCompany(lineId, companyId); |
| | | } |
| | | if (currentLineCompany == null && lineCompanies.size() > 0) { |
| | | currentLineCompany = lineCompanies.get(0); |
| | | companyId = currentLineCompany.getCompanyId(); |
| | | } |
| | | model.addAttribute("lineId", lineId); |
| | | model.addAttribute("companyId", companyId); |
| | | model.addAttribute("lineName", line == null ? "" : line.getName()); |
| | | model.addAttribute("companyName", company == null ? "" : company.getName()); |
| | | model.addAttribute("autoPlan", lineCompany == null || lineCompany.getAutoPlan() == null ? 2 : lineCompany.getAutoPlan()); |
| | | model.addAttribute("companyName", getLineCompanyNames(lineCompanies)); |
| | | model.addAttribute("autoPlan", currentLineCompany == null || currentLineCompany.getAutoPlan() == null ? 2 : currentLineCompany.getAutoPlan()); |
| | | return PREFIX + "tLine_schedule.html"; |
| | | } |
| | | |
| | |
| | | @ResponseBody |
| | | public Object scheduleMonth(Integer lineId, Integer companyId, String month) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | if (SinataUtil.isEmpty(month)) { |
| | | month = new SimpleDateFormat("yyyy-MM").format(new Date()); |
| | |
| | | cal.set(Calendar.DAY_OF_MONTH, maxDay); |
| | | String monthEnd = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); |
| | | |
| | | Integer companyType = getCompanyType(companyId); |
| | | List<Map<String, Object>> stats = lineShiftDriverMapper.getMonthScheduleStats(lineId, monthStart, monthEnd, companyId, companyType); |
| | | List<Map<String, Object>> stats = lineShiftDriverMapper.getMonthScheduleStats(lineId, monthStart, monthEnd, companyId, null); |
| | | Map<String, Integer> dayAssignMap = new HashMap<>(); |
| | | for (Map<String, Object> stat : stats) { |
| | | dayAssignMap.put(String.valueOf(stat.get("dayStr")), Integer.parseInt(String.valueOf(stat.get("assignNum")))); |
| | |
| | | @ResponseBody |
| | | public Object scheduleDayDetail(Integer lineId, Integer companyId, String day) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | Integer companyType = getCompanyType(companyId); |
| | | List<Map<String, Object>> shiftList = lineShiftDriverMapper.getDayShiftSchedule(lineId, day, companyId, companyType); |
| | | List<Map<String, Object>> shiftList = lineShiftDriverMapper.getDayShiftSchedule(lineId, day, companyId, null); |
| | | for (Map<String, Object> shift : shiftList) { |
| | | Integer lineShiftId = Integer.valueOf(String.valueOf(shift.get("lineShiftId"))); |
| | | List<Map<String, Object>> drivers = lineShiftDriverMapper.getDayShiftDrivers(lineShiftId, day, companyId, companyType); |
| | | List<Map<String, Object>> drivers = lineShiftDriverMapper.getDayShiftDrivers(lineShiftId, day, companyId, null); |
| | | int carNum = shift.get("carNum") == null ? 0 : Integer.parseInt(String.valueOf(shift.get("carNum"))); |
| | | int assignNum = shift.get("assignNum") == null ? 0 : Integer.parseInt(String.valueOf(shift.get("assignNum"))); |
| | | shift.put("drivers", drivers); |
| | |
| | | @ResponseBody |
| | | public Object scheduleDrivers(Integer lineId, Integer companyId, Integer lineShiftId, String day) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | Integer companyType = getCompanyType(companyId); |
| | | return ResultUtil.success(lineShiftDriverMapper.getAvailableDrivers(lineId, lineShiftId, day, companyId, companyType)); |
| | | return ResultUtil.success(lineShiftDriverMapper.getAvailableDrivers(lineId, lineShiftId, day, companyId, null)); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | |
| | | @ResponseBody |
| | | public Object scheduleAdd(Integer lineId, Integer companyId, Integer lineShiftId, String day, @RequestParam String driverIds) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | TLineShift shift = itLineShiftService.selectById(lineShiftId); |
| | | if (shift == null || shift.getState() == 3 || !shift.getLineId().equals(lineId)) { |
| | | return ResultUtil.error("班次不存在"); |
| | | } |
| | | Date dayDate = parseDay(day); |
| | | Integer companyType = getCompanyType(companyId); |
| | | List<Map<String, Object>> currentDrivers = lineShiftDriverMapper.getDayShiftDrivers(lineShiftId, day, companyId, companyType); |
| | | List<Map<String, Object>> currentDrivers = lineShiftDriverMapper.getDayShiftDrivers(lineShiftId, day, companyId, null); |
| | | int currentAssignNum = currentDrivers == null ? 0 : currentDrivers.size(); |
| | | int carNum = shift.getCarNum() == null ? 0 : shift.getCarNum(); |
| | | if (currentAssignNum >= carNum) { |
| | |
| | | if (driverIdList.size() <= 0) { |
| | | return ResultUtil.error("请选择司机"); |
| | | } |
| | | List<Map<String, Object>> availableDrivers = lineShiftDriverMapper.getAvailableDrivers(lineId, lineShiftId, day, companyId, companyType); |
| | | List<Map<String, Object>> availableDrivers = lineShiftDriverMapper.getAvailableDrivers(lineId, lineShiftId, day, companyId, null); |
| | | Map<Integer, Integer> seatMap = new HashMap<>(); |
| | | for (Map<String, Object> driver : availableDrivers) { |
| | | Integer driverId = Integer.valueOf(String.valueOf(driver.get("driverId"))); |
| | |
| | | @ResponseBody |
| | | public Object scheduleDelete(Integer scheduleId, Integer lineId, Integer companyId) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | LineShiftDriver record = lineShiftDriverMapper.selectById(scheduleId); |
| | | if (record == null) { |
| | |
| | | return ResultUtil.error("排班记录线路不匹配"); |
| | | } |
| | | TDriver driver = tDriverService.selectById(record.getDriverId()); |
| | | if (driver == null || !checkDriverBelongCompany(driver, companyId)) { |
| | | if (driver == null || !checkDriverBelongLineCompanies(driver, lineId)) { |
| | | return ResultUtil.error("司机企业信息不匹配"); |
| | | } |
| | | lineShiftDriverMapper.deleteById(scheduleId); |
| | |
| | | @ResponseBody |
| | | public Object scheduleCopy(Integer lineId, Integer companyId, String sourceStart, String sourceEnd, String targetStart) { |
| | | try { |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | | return ResultUtil.error("线路未关联该企业"); |
| | | if (!hasLineCompanies(lineId)) { |
| | | return ResultUtil.error("线路未关联企业"); |
| | | } |
| | | Date sourceStartDate = parseDay(sourceStart); |
| | | Date sourceEndDate = parseDay(sourceEnd); |
| | |
| | | if (sourceEndDate.before(sourceStartDate)) { |
| | | return ResultUtil.error("复制结束日期不能早于开始日期"); |
| | | } |
| | | Integer companyType = getCompanyType(companyId); |
| | | List<LineShiftDriver> sourceList = lineShiftDriverMapper.getManualSchedulesForCopy(lineId, sourceStart, sourceEnd, companyId, companyType); |
| | | List<LineShiftDriver> sourceList = lineShiftDriverMapper.getManualSchedulesForCopy(lineId, sourceStart, sourceEnd, companyId, null); |
| | | int addNum = 0; |
| | | int skipNum = 0; |
| | | for (LineShiftDriver source : sourceList) { |
| | |
| | | public Object scheduleAutoPlan(Integer lineId, Integer companyId, Integer autoPlan) { |
| | | if (autoPlan == null || (autoPlan != 1 && autoPlan != 2)) { |
| | | return ResultUtil.error("智能排班参数错误"); |
| | | } |
| | | if (companyId == null) { |
| | | companyId = getDefaultLineCompanyId(lineId); |
| | | } |
| | | TLineCompany lineCompany = checkLineCompany(lineId, companyId); |
| | | if (lineCompany == null) { |
| | |
| | | return itLineCompanyService.selectOne(new EntityWrapper<TLineCompany>().eq("lineId", lineId).eq("companyId", companyId)); |
| | | } |
| | | |
| | | private List<TLineCompany> getLineCompanies(Integer lineId) { |
| | | if (lineId == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return itLineCompanyService.selectList(new EntityWrapper<TLineCompany>().eq("lineId", lineId).orderBy("id", true)); |
| | | } |
| | | |
| | | private boolean hasLineCompanies(Integer lineId) { |
| | | return getLineCompanies(lineId).size() > 0; |
| | | } |
| | | |
| | | private Integer getDefaultLineCompanyId(Integer lineId) { |
| | | List<TLineCompany> lineCompanies = getLineCompanies(lineId); |
| | | if (lineCompanies.size() <= 0) { |
| | | return null; |
| | | } |
| | | return lineCompanies.get(0).getCompanyId(); |
| | | } |
| | | |
| | | private String getLineCompanyNames(List<TLineCompany> lineCompanies) { |
| | | if (lineCompanies == null || lineCompanies.size() <= 0) { |
| | | return ""; |
| | | } |
| | | List<String> names = new ArrayList<>(); |
| | | for (TLineCompany lineCompany : lineCompanies) { |
| | | if (lineCompany == null || lineCompany.getCompanyId() == null) { |
| | | continue; |
| | | } |
| | | TCompany company = itCompanyService.selectById(lineCompany.getCompanyId()); |
| | | if (company != null && SinataUtil.isNotEmpty(company.getName())) { |
| | | names.add(company.getName()); |
| | | } |
| | | } |
| | | return String.join("、", names); |
| | | } |
| | | |
| | | private Integer getCompanyType(Integer companyId) { |
| | | TCompany company = itCompanyService.selectById(companyId); |
| | | return company == null ? null : company.getType(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | private boolean checkDriverBelongLineCompanies(TDriver driver, Integer lineId) { |
| | | if (driver == null || lineId == null) { |
| | | return false; |
| | | } |
| | | List<TLineCompany> lineCompanies = getLineCompanies(lineId); |
| | | for (TLineCompany lineCompany : lineCompanies) { |
| | | if (checkDriverBelongCompany(driver, lineCompany.getCompanyId())) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private Date parseDay(String day) throws Exception { |
| | | return new SimpleDateFormat("yyyy-MM-dd").parse(day); |
| | | } |