package cn.iocoder.yudao.module.mes.controller.admin.pro.scan; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.mes.controller.admin.pro.scan.vo.MesProScanEventCreateReqVO; import cn.iocoder.yudao.module.mes.controller.admin.pro.scan.vo.MesProScanEventRespVO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.mes.controller.admin.pro.scan.vo.MesProScanEventPageReqVO; import java.util.List; import java.util.Map; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.scan.MesProScanEventDO; import cn.iocoder.yudao.module.mes.service.pro.scan.MesProScanEventService; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import org.springframework.security.access.prepost.PreAuthorize; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @Tag(name = "管理后台 - MES 扫码入库") @RestController @RequestMapping("/mes/pro/scan-in") public class MesProScanEventController { @Resource private MesProScanEventService service; @PostMapping("/inbound") @PreAuthorize("@ss.hasPermission('mes:pro-scan-in:inbound')") @Operation(summary = "追溯码扫码入库(袋码/托盘码/批次码)") public CommonResult inbound(@Valid @RequestBody MesProScanEventCreateReqVO req) { return success(BeanUtils.toBean(service.createInbound(req), MesProScanEventRespVO.class)); } @GetMapping("/page") @PreAuthorize("@ss.hasPermission('mes:pro-scan-in:query')") @Operation(summary = "扫码事件分页") public CommonResult> page(@Valid MesProScanEventPageReqVO req) { PageResult page = service.getPage(req); return success(new PageResult<>(BeanUtils.toBean(page.getList(), MesProScanEventRespVO.class), page.getTotal())); } @GetMapping("/my-page") @PreAuthorize("@ss.hasPermission('mes:pro-scan-in:query')") @Operation(summary = "本人扫码作业记录") public CommonResult> myPage(@Valid MesProScanEventPageReqVO req) { req.setCreator(String.valueOf(cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId())); return page(req); } @GetMapping("/my-event") @PreAuthorize("@ss.hasAnyPermissions('mes:pro-scan-in:query','mes:pro-scan-in:inbound')") @Operation(summary = "核实本人扫码操作结果") public CommonResult myEvent(@RequestParam String eventId) { MesProScanEventDO event = service.getByEventId(eventId); String userId = String.valueOf(cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId()); return success(event != null && userId.equals(event.getCreator()) ? BeanUtils.toBean(event, MesProScanEventRespVO.class) : null); } @GetMapping("/latest") @PreAuthorize("@ss.hasPermission('mes:pro-scan-in:query')") @Operation(summary = "最新扫码事件") public CommonResult latest(@RequestParam(required = false) String deviceCode) { return success(BeanUtils.toBean(service.getLatest(deviceCode), MesProScanEventRespVO.class)); } @GetMapping("/dashboard") @PreAuthorize("@ss.hasPermission('mes:pro-scan-in:dashboard')") @Operation(summary = "扫码入库看板") public CommonResult> dashboard() { return success(service.getDashboard()); } }