|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.manager.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.entity.enums.TaskStsType; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.constant.Constants; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.ExcelUtil; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.annotation.OperationLog; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.BaseParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.KeyValVo; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.PageParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Loc; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Task; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.TaskItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.WaitPakin; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.PakinIOStatus; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.LocService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.TaskItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.TaskService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WaitPakinService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.enums.LocStsType; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.impl.ConfigServiceImpl; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class TaskController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final Logger logger = LoggerFactory.getLogger(TaskController.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskService taskService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskItemService taskItemService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WaitPakinService waitPakinService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:list')") | 
|---|
|  |  |  | @PostMapping("/task/page") | 
|---|
|  |  |  | public R page(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<Task, BaseParam> pageParam = new PageParam<>(baseParam, Task.class); | 
|---|
|  |  |  | return R.ok().add(taskService.page(pageParam, pageParam.buildWrapper(true))); | 
|---|
|  |  |  | QueryWrapper<Task> queryWrapper = pageParam.buildWrapper(true); | 
|---|
|  |  |  | return R.ok().add(taskService.page(pageParam, queryWrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:list')") | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:remove')") | 
|---|
|  |  |  | @OperationLog("Delete 任务工作档") | 
|---|
|  |  |  | @ApiOperation("取消/删除工作极档") | 
|---|
|  |  |  | @PostMapping("/task/remove/{ids}") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R remove(@PathVariable Long[] ids) { | 
|---|
|  |  |  | if (Objects.isNull(ids) || ids.length < 1) { | 
|---|
|  |  |  | return R.error("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Short> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id); | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getId, ids).in(Task::getTaskStatus, longs)); | 
|---|
|  |  |  | if (tasks.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("任务已处执行状态不可取消!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Task task : tasks) { | 
|---|
|  |  |  | //恢复组托状态 | 
|---|
|  |  |  | WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>() | 
|---|
|  |  |  | .eq(WaitPakin::getBarcode, task.getBarcode()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (null != waitPakin) { | 
|---|
|  |  |  | waitPakin.setIoStatus(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)); | 
|---|
|  |  |  | if (!waitPakinService.updateById(waitPakin)) { | 
|---|
|  |  |  | return R.error("更新组托状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>() | 
|---|
|  |  |  | .eq(Loc::getCode, task.getTaskType() < 100 ? task.getTargLoc() : task.getOrgLoc()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (null != loc | 
|---|
|  |  |  | && (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type) | 
|---|
|  |  |  | || loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type))) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); | 
|---|
|  |  |  | if (!locService.updateById(loc)) { | 
|---|
|  |  |  | return R.error("更新库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!taskService.removeByIds(Arrays.asList(ids))) { | 
|---|
|  |  |  | return R.error("Delete Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!taskItemService.remove(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, ids))) { | 
|---|
|  |  |  | return R.error("Details delete Failed"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Delete Success").add(ids); | 
|---|
|  |  |  | return taskService.removeTask(ids, getLoginUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:list')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:update')") | 
|---|
|  |  |  | @ApiOperation("完成任务") | 
|---|
|  |  |  | @PostMapping("/task/complete/{id}") | 
|---|
|  |  |  | public R completeTask(@PathVariable String id) throws Exception { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | public R completeTask(@PathVariable Long id) throws Exception { | 
|---|
|  |  |  | if (Cools.isEmpty(id)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Short> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id); | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getId, id).in(Task::getTaskStatus, longs)); | 
|---|
|  |  |  | //        if (tasks.isEmpty()) { | 
|---|
|  |  |  | //            throw new CoolException("任务已处执行状态不可一键完成!!"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | taskService.completeTask(tasks); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | return R.ok("完成任务成功").add(taskService.operateComplete(id, getLoginUserId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 拣料出库(用于测试拣料出库) | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:update')") | 
|---|
|  |  |  | @ApiOperation("取消任务") | 
|---|
|  |  |  | @PostMapping("/task/cancel/{id}") | 
|---|
|  |  |  | public R cancelTask(@PathVariable String id) { | 
|---|
|  |  |  | @ApiOperation("拣料出库") | 
|---|
|  |  |  | @PostMapping("/task/pick/{id}") | 
|---|
|  |  |  | public R pickTask(@PathVariable Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | throw new CoolException("能数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return R.ok("出库完成").add(taskService.pickOrCheckTask(id, Constants.TASK_TYPE_OUT_PICK)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 盘点出库(用于测试盘点出库) | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:update')") | 
|---|
|  |  |  | @ApiOperation("盘点出库") | 
|---|
|  |  |  | @PostMapping("/task/check/{id}") | 
|---|
|  |  |  | public R checkTask(@PathVariable Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("能数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return R.ok(taskService.pickOrCheckTask(id, Constants.TASK_TYPE_OUT_CHECK)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    @PreAuthorize("hasAuthority('manager:task:update')") | 
|---|
|  |  |  | //    @ApiOperation("取消任务") | 
|---|
|  |  |  | //    @PostMapping("/task/cancel/{id}") | 
|---|
|  |  |  | //    public R cancelTask(@PathVariable String id) { | 
|---|
|  |  |  | //        if (Objects.isNull(id)) { | 
|---|
|  |  |  | //            throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return R.ok(); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:task:update')") | 
|---|
|  |  |  | @ApiOperation("任务出库置顶") | 
|---|
|  |  |  | @PostMapping("/task/top/{id}") | 
|---|
|  |  |  | public R setTop(@PathVariable String id) { | 
|---|
|  |  |  | public R setTop(@PathVariable Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Short> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id); | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getId, id).in(Task::getTaskStatus, longs)); | 
|---|
|  |  |  | if (tasks.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("任务已处执行状态不可一键置顶!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (!taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getSort, 100).eq(Task::getId, id))) { | 
|---|
|  |  |  | throw new CoolException("置顶失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception ex) { | 
|---|
|  |  |  | return R.error("任务异常,无法完成!!"); | 
|---|
|  |  |  | taskService.taskToTop(id, getLoginUserId()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | logger.error("UNK", e); | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|