package com.qianwen.smartman.modules.mdc.controller; import java.util.List; import java.util.stream.Collectors; import javax.validation.Valid; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.support.Condition; import com.qianwen.core.mp.support.Query; import com.qianwen.core.scanner.modular.stereotype.ApiResource; import com.qianwen.core.tool.api.R; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.cache.RegionCache; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.modules.cps.service.IWorkstationService; import com.qianwen.smartman.modules.cps.vo.WorkstationVO; import com.qianwen.smartman.modules.mdc.dto.WorkstationEndAndStartImmediateFeedBackDTO; import com.qianwen.smartman.modules.mdc.dto.WorkstationEndImmediateFeedBackDTO; import com.qianwen.smartman.modules.mdc.dto.WorkstationFeedBackQueryDTO; import com.qianwen.smartman.modules.mdc.dto.WorkstationImmediateFeedBackDTO; import com.qianwen.smartman.modules.mdc.dto.WorkstationNoImmediateFeedBackDTO; import com.qianwen.smartman.modules.mdc.entity.WorkstationFeedback; import com.qianwen.smartman.modules.mdc.entity.WorkstationFeedbackDetail; import com.qianwen.smartman.modules.mdc.enums.FeedbackDetailStatus; import com.qianwen.smartman.modules.mdc.enums.FeedbackStatus; import com.qianwen.smartman.modules.mdc.service.IWorkstationFeedbackDetailService; import com.qianwen.smartman.modules.mdc.service.IWorkstationFeedbackService; import com.qianwen.smartman.modules.mdc.vo.WorkstationFeedBackDetailVO; import com.qianwen.smartman.modules.mdc.vo.WorkstationFeedBackVO; import com.qianwen.smartman.modules.mdc.vo.WorkstationFeedbackInfoVO; import com.qianwen.smartman.modules.mdc.wrapper.WorkstationFeedBackDetailWrapper; import com.qianwen.smartman.modules.mdc.wrapper.WorkstationFeedbackWrapper; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Assert; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @Api(value = "工位反馈", tags = {"工位反馈"}) @ApiResource({"blade-cps/workstation-wcs-feedback"}) @RestController /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/mdc/controller/WorkstationFeedbackController.class */ public class WorkstationFeedbackController { private final IWorkstationFeedbackService wcsFeedbackService; private final IWorkstationService workstationService; private final IWorkstationFeedbackDetailService detailService; public WorkstationFeedbackController(final IWorkstationFeedbackService wcsFeedbackService, final IWorkstationService workstationService, final IWorkstationFeedbackDetailService detailService) { this.wcsFeedbackService = wcsFeedbackService; this.workstationService = workstationService; this.detailService = detailService; } @ApiOperationSupport(order = -2) @GetMapping({"/get/{id}"}) @ApiOperation("H5:根据ID获取反馈详情") public R getById(@PathVariable Long id) { WorkstationFeedback feedback = this.wcsFeedbackService.cachedById(id); return R.data(WorkstationFeedbackWrapper.build().entityVO(feedback)); } @ApiOperationSupport(order = -1) @GetMapping({"/latest"}) @ApiOperation("根据工位ID获取最新反馈信息") public R latestByWorkstationId(@RequestParam Long workstationId) { WorkstationFeedback feedback = this.wcsFeedbackService.getImmediateFeedback(workstationId); if (feedback == null) { WorkstationFeedbackDetail detail = this.detailService.latestFeedbackByWorkstationId(workstationId); if (detail == null) { return R.data( null); } return R.data(WorkstationFeedbackWrapper.entityVO(detail)); } return R.data(WorkstationFeedbackWrapper.build().entityVO(feedback)); } @PostMapping({"/page"}) @ApiOperationSupport @ApiOperation("工位反馈分页列表查询") public R> page(Query query, @RequestBody WorkstationFeedBackQueryDTO queryDTO) { IPage page = this.detailService.page(Condition.getPage(query), Lambda.eq(WorkstationFeedbackDetail::getStatus, Integer.valueOf(FeedbackDetailStatus.EFFECTED.getValue())) .eq(WorkstationFeedbackDetail::getCancel, Boolean.FALSE) .in(Func.isNotEmpty(queryDTO.getWorkstationGroupId()), WorkstationFeedbackDetail::getWorkstationId, this.workstationService .getWorkstationByGroupIds(ListUtil.toList(new String[] { queryDTO.getWorkstationGroupId() })).stream().map(WorkstationVO::getId).collect(Collectors.toList())) .eq(Func.isNotEmpty(queryDTO.getWorkstationId()), WorkstationFeedbackDetail::getWorkstationId, queryDTO.getWorkstationId()) .ge(Func.isNotEmpty(queryDTO.getStartDate()), WorkstationFeedbackDetail::getStartTime, queryDTO.getStartDate()) .le(Func.isNotEmpty(queryDTO.getEndDate()), WorkstationFeedbackDetail::getEndTime, queryDTO.getEndDate()) .in(Func.isNotEmpty(queryDTO.getFeedBackStatus()), WorkstationFeedbackDetail::getWcs, queryDTO.getFeedBackStatus()) .nested(Func.isNotEmpty(queryDTO.getStartDate()), w -> w.apply(Func.isNotEmpty(queryDTO.getStartDate()), String.format("'%s' between start_time and end_time", new Object[] { queryDTO.getStartDate() }), new Object[0]).or().apply(Func.isNotEmpty(queryDTO.getEndDate()), String.format("'%s' between start_time and end_time", new Object[] { queryDTO.getEndDate() }), new Object[0]).orderByDesc(WorkstationFeedbackDetail::getStartTime))); /* IPage page = this.detailService.page(Condition.getPage(query), (Wrapper) ((ExtraLambdaQueryWrapper) Lambda.eq((v0) -> { return v0.getStatus(); }, Integer.valueOf(FeedbackDetailStatus.EFFECTED.getValue())).eq((v0) -> { return v0.getCancel(); }, Boolean.FALSE)).in(Func.isNotEmpty(queryDTO.getWorkstationGroupId()), (v0) -> { return v0.getWorkstationId(); }, (Collection) this.workstationService.getWorkstationByGroupIds(ListUtil.toList(new String[]{queryDTO.getWorkstationGroupId()})).stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList())).eq(Func.isNotEmpty(queryDTO.getWorkstationId()), (v0) -> { return v0.getWorkstationId(); }, queryDTO.getWorkstationId()).ge(Func.isNotEmpty(queryDTO.getStartDate()), (v0) -> { return v0.getStartTime(); }, queryDTO.getStartDate()).le(Func.isNotEmpty(queryDTO.getEndDate()), (v0) -> { return v0.getEndTime(); }, queryDTO.getEndDate()).in(Func.isNotEmpty(queryDTO.getFeedBackStatus()), (v0) -> { return v0.getWcs(); }, queryDTO.getFeedBackStatus()).nested(Func.isNotEmpty(queryDTO.getStartDate()), w -> { ((ExtraLambdaQueryWrapper) w.apply(Func.isNotEmpty(queryDTO.getStartDate()), String.format("'%s' between start_time and end_time", queryDTO.getStartDate()), new Object[0]).or()).apply(Func.isNotEmpty(queryDTO.getEndDate()), String.format("'%s' between start_time and end_time", queryDTO.getEndDate()), new Object[0]); }).orderByDesc((v0) -> { return v0.getStartTime(); }));*/ return R.data(WorkstationFeedBackDetailWrapper.build().pageVO(page)); } @DeleteMapping @ApiOperationSupport(order = 1) @ApiOperation(value = "批量撤销反馈", notes = "传入的是feedbackId") public R cancelWorkstationFeedbacks(@RequestBody List ids) { return R.status(this.detailService.cancelWorkstationFeedbacks(ids)); } @ApiOperationSupport(order = 2) @GetMapping({"/workingstation-feedback-info"}) @ApiOperation("H5: 分页获取各个工位当前反馈信息") public R> feedbackInfo(Query query, @RequestParam @ApiParam("排除持续反馈工位 true: 排除 false: 不排除") boolean excludeImmediate) { IPage page = this.wcsFeedbackService.workstationPage(query, excludeImmediate); return R.data(page); } @PostMapping({"/start-feedback-by-immediate"}) @ApiOperationSupport(order = 3) @ApiOperation(value = "H5: 状态即时反馈登记", notes = "工位即时反馈, 进行中的反馈") public R startFeedbackByImmediate(@Valid @RequestBody WorkstationImmediateFeedBackDTO immediateFeedBackDTO) { return R.status(this.wcsFeedbackService.startFeedbackByImmediate(immediateFeedBackDTO)); } @PostMapping({"/start-feedback-by-no-immediate"}) @ApiOperationSupport(order = 4) @ApiOperation(value = "H5: 时间段反馈", notes = "时间段反馈") public R startFeedbackByNoImmediate(@Validated @RequestBody WorkstationNoImmediateFeedBackDTO noImmediateFeedBackDTO) { if (noImmediateFeedBackDTO.getStartTime().compareTo(noImmediateFeedBackDTO.getEndTime()) >= 0) { throw new ServiceException("开始时间必须小于结束时间"); } return R.status(this.wcsFeedbackService.startFeedbackByNoImmediate(noImmediateFeedBackDTO)); } @PostMapping({"/overwrite-feedback-check"}) @ApiOperationSupport(order = 4) @ApiOperation(value = "查询是否有覆盖的反馈", notes = "data true: 会覆盖反馈,提示 false: 不会覆盖反馈,不提示直接提交") public R overwriteFeedback(@Validated @RequestBody WorkstationNoImmediateFeedBackDTO noImmediateFeedBackDTO) { return R.data(Boolean.valueOf(this.detailService.overwriteFeedbackCheck(noImmediateFeedBackDTO))); } @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL) @PutMapping({"/end-feedback"}) @ApiOperation(value = "H5: 结束反馈", notes = "结束指定工位进行中的反馈记录") public R endFeedback(@Valid @RequestBody WorkstationEndImmediateFeedBackDTO workstationEndImmediateFeedBackDTO) { return R.status(this.wcsFeedbackService.endFeedback(workstationEndImmediateFeedBackDTO)); } @ApiOperationSupport(order = 6) @PutMapping({"/end-and-start-again-feedback"}) @ApiOperation(value = "H5: 结束再次发起反馈", notes = "结束并再次发起反馈") public R endAndStartAgainFeedback(@Valid @RequestBody WorkstationEndAndStartImmediateFeedBackDTO endAgainFeedbackDTO) { return R.status(this.wcsFeedbackService.endAndStartAgainFeedback(endAgainFeedbackDTO)); } @ApiOperationSupport(order = 7) @GetMapping({"/today-feedback"}) @ApiOperation(value = "H5:今日反馈,历史反馈", notes = "查询工位今日反馈记录") public R> todayFeedback(@RequestParam Long workstationId) { return R.data(WorkstationFeedBackDetailWrapper.build().listVO(this.detailService.todayFeedback(workstationId))); } @PostMapping({"/feedback-status"}) @ApiOperationSupport(order = 8) @ApiOperation(value = "查询工位状态", notes = "查询是否有未计算的反馈记录, true:有正在计算的记录, false: 没有") public R feedbackStatus(@RequestBody List workstationIds) { Assert.notEmpty(workstationIds); boolean exist = (this.wcsFeedbackService.count(Lambda.in(WorkstationFeedback::getWorkstationId, workstationIds) .nested(w -> w.eq(WorkstationFeedback::getStatus, FeedbackStatus.SYNCING.getValue()) .or().eq(WorkstationFeedback::getStatus, FeedbackStatus.WAIT_SYNC.getValue()))) != 0); /* boolean exist = this.wcsFeedbackService.count((Wrapper) Lambda.in((v0) -> { return v0.getWorkstationId(); }, workstationIds).nested(w -> { ExtraLambdaQueryWrapper extraLambdaQueryWrapper = (ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) w.eq((v0) -> { return v0.getStatus(); }, FeedbackStatus.SYNCING.getValue())).or()).eq((v0) -> { return v0.getStatus(); }, FeedbackStatus.WAIT_SYNC.getValue()); })) != 0;*/ return R.data(Boolean.valueOf(exist)); } }