|  |  |  | 
|---|
|  |  |  | import com.zy.acs.manager.manager.entity.Bus; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.entity.Task; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.enums.BusStsType; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.service.BusService; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.service.LocService; | 
|---|
|  |  |  | import com.zy.acs.manager.manager.service.StaService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.acs.manager.system.controller.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<Bus, BaseParam> pageParam = new PageParam<>(baseParam, Bus.class); | 
|---|
|  |  |  | QueryWrapper<Bus> wrapper = pageParam.buildWrapper(true); | 
|---|
|  |  |  | if (createTimeDesc(pageParam.getOrders())) { | 
|---|
|  |  |  | wrapper.last(businessSortService.getSql(BusStsType.class, "bus_sts")); | 
|---|
|  |  |  | if (hasCreateTimeDesc(pageParam.getOrders())) { | 
|---|
|  |  |  | //            wrapper.last(businessSortService.getOrderBySql(BusStsType.class, "bus_sts")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | PageParam<Bus, BaseParam> page = busService.page(pageParam, wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long taskCompleteSts = TaskStsType.COMPLETE.val(); | 
|---|
|  |  |  | long taskCancelSts = TaskStsType.CANCEL.val(); | 
|---|
|  |  |  | for (Bus record : page.getRecords()) { | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBusId, record.getId())); | 
|---|
|  |  |  | if (!Cools.isEmpty(tasks)) { | 
|---|
|  |  |  | record.setTaskIds(tasks.stream().map(Task::getId).collect(Collectors.toList())); | 
|---|
|  |  |  | record.setTasksNum(tasks.size()); | 
|---|
|  |  |  | record.setTasksNum((int)tasks.stream().filter(task -> task.getTaskSts() != taskCompleteSts && task.getTaskSts() != taskCancelSts).count()); | 
|---|
|  |  |  | record.setTasksNumTotal(tasks.size()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(page); | 
|---|
|  |  |  | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(busService.list(), Bus.class), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:bus:update')") | 
|---|
|  |  |  | @OperationLog("Cancel Bus") | 
|---|
|  |  |  | @GetMapping("/bus/cancel/{id}") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R cancel(@PathVariable Long id) { | 
|---|
|  |  |  | Bus bus = busService.getById(id); | 
|---|
|  |  |  | if (null == bus) { | 
|---|
|  |  |  | return R.error("Cancel Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!bus.getBusStsEl().equals(BusStsType.RECEIVE.toString())) { | 
|---|
|  |  |  | return R.error("Cancel Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .eq(Task::getBusId, bus.getId()) | 
|---|
|  |  |  | .in(Task::getTaskSts, TaskStsType.INIT.val(), TaskStsType.WAITING.val())); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskList)) { | 
|---|
|  |  |  | for (Task task : taskList) { | 
|---|
|  |  |  | taskService.cancel(task.getId(), getLoginUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (0 == taskService.count(new LambdaQueryWrapper<Task>().eq(Task::getBusId, bus.getId()).eq(Task::getTaskSts, TaskStsType.COMPLETE.val()))) { | 
|---|
|  |  |  | bus.setBusSts(BusStsType.CANCEL.val()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | bus.setBusSts(BusStsType.FINISH.val()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | bus.setUpdateTime(new Date()); | 
|---|
|  |  |  | bus.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | if (!busService.updateById(bus)) { | 
|---|
|  |  |  | return R.error("Cancel Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Cancel Success"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|