| | |
| | | package com.zy.acs.manager.manager.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.manager.common.annotation.OperationLog; |
| | | import com.zy.acs.manager.common.domain.*; |
| | | import com.zy.acs.manager.common.utils.BusinessSortService; |
| | | import com.zy.acs.manager.common.utils.ExcelUtil; |
| | | import com.zy.acs.manager.core.service.MainService; |
| | | import com.zy.acs.manager.manager.controller.param.BusCreateParam; |
| | | import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam; |
| | | 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.manager.service.TaskService; |
| | | 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; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | |
| | | private StaService staService; |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private BusinessSortService businessSortService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:bus:list')") |
| | | @PostMapping("/bus/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Bus, BaseParam> pageParam = new PageParam<>(baseParam, Bus.class); |
| | | return R.ok().add(busService.page(pageParam, pageParam.buildWrapper(true))); |
| | | QueryWrapper<Bus> wrapper = pageParam.buildWrapper(true); |
| | | 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((int)tasks.stream().filter(task -> task.getTaskSts() != taskCompleteSts && task.getTaskSts() != taskCancelSts).count()); |
| | | record.setTasksNumTotal(tasks.size()); |
| | | } |
| | | } |
| | | return R.ok().add(page); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:bus:list')") |
| | |
| | | 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"); |
| | | } |
| | | |
| | | } |