fix
longz
2026-04-30 83ff381c5c0e62c98cb9e3dd8e1d82771b1dc23f
ManagementYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TLineController.java
@@ -454,14 +454,20 @@
    @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";
    }
@@ -472,9 +478,8 @@
    @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());
@@ -489,8 +494,7 @@
            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"))));
@@ -542,15 +546,13 @@
    @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);
@@ -571,12 +573,10 @@
    @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();
@@ -590,17 +590,15 @@
    @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) {
@@ -611,7 +609,7 @@
            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")));
@@ -665,9 +663,8 @@
    @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) {
@@ -681,7 +678,7 @@
                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);
@@ -699,9 +696,8 @@
    @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);
@@ -709,8 +705,7 @@
            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) {
@@ -752,6 +747,9 @@
    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) {
@@ -944,6 +942,42 @@
        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();
@@ -966,6 +1000,19 @@
        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);
    }