From e936e8e6136f837fefe79f6304c918ec0c0f0d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=90=8D=E5=96=9C?= Date: Mon, 25 Nov 2024 19:22:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=B8=8A=E4=BC=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wm/controller/UcmCtBaseController.java | 14 ++-- .../ktg/mes/wm/service/IUcmCtBaseService.java | 3 + .../wm/service/impl/UcmCtBaseServiceImpl.java | 65 ++++++++++++++++++- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java index 9efe0dd..44efc76 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java @@ -9,9 +9,12 @@ import com.ktg.common.enums.BusinessType; import com.ktg.common.utils.poi.ExcelUtil; import com.ktg.mes.md.domain.BaseKnife; import com.ktg.mes.md.mapper.BaseKnifeMapper; +import com.ktg.mes.md.mapper.UcmCtMaterialMapper2; import com.ktg.mes.wm.domain.UcmCtBase; +import com.ktg.mes.wm.domain.UcmCtMaterial; import com.ktg.mes.wm.domain.box.Box; import com.ktg.mes.wm.domain.box.BoxItem; +import com.ktg.mes.wm.mapper.UcmCtBaseMapper; import com.ktg.mes.wm.service.IUcmCtBaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -61,11 +65,11 @@ public class UcmCtBaseController extends BaseController { public String uploadBox( @RequestBody List boxList ) { - boxList.forEach(box -> { - System.out.println(JSON.toJSONString(box)); - }); - - return "失败,正在调试中..."; + try { + return ucmCtBaseService.bindAndUnbindUcmCtBase(boxList); + } catch (Exception e) { + return e.getMessage(); + } } /** diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java index c1b56ee..524d9a2 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java @@ -1,6 +1,7 @@ package com.ktg.mes.wm.service; import com.ktg.mes.wm.domain.UcmCtBase; +import com.ktg.mes.wm.domain.box.Box; import java.util.List; @@ -63,4 +64,6 @@ public interface IUcmCtBaseService int bindUcmCtBase(String boxCode, String itemCode); int unbindUcmCtBase(String boxCode, String itemCode); + + String bindAndUnbindUcmCtBase(List boxList); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java index 20ae27e..0e95464 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java @@ -6,6 +6,8 @@ import com.ktg.mes.md.mapper.BaseKnifeMapper; import com.ktg.mes.md.mapper.UcmCtMaterialMapper2; import com.ktg.mes.wm.domain.UcmCtBase; import com.ktg.mes.wm.domain.UcmCtMaterial; +import com.ktg.mes.wm.domain.box.Box; +import com.ktg.mes.wm.domain.box.BoxItem; import com.ktg.mes.wm.mapper.UcmCtBaseMapper; import com.ktg.mes.wm.service.IUcmCtBaseService; import org.springframework.beans.factory.annotation.Autowired; @@ -142,7 +144,7 @@ public class UcmCtBaseServiceImpl implements IUcmCtBaseService { ucmCtMaterialQuery.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId()); List ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery); if (!ucmCtMaterialList.isEmpty()) - throw new RuntimeException("解绑失败,该物料已经绑定该料箱"); + throw new RuntimeException("绑定失败,该物料已经绑定该料箱"); UcmCtMaterial ucmCtMaterial = new UcmCtMaterial(); ucmCtMaterial.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId())); @@ -181,4 +183,65 @@ public class UcmCtBaseServiceImpl implements IUcmCtBaseService { return ucmCtMaterialList.size(); } + + @Transactional + @Override + public String bindAndUnbindUcmCtBase(List boxList) { + for (Box box : boxList) { + if (!box.getIsUnbind()) { + for (BoxItem boxItem : box.getBoxItemList()) { + UcmCtBase ucmCtBaseQuery = new UcmCtBase(); + ucmCtBaseQuery.setCode(box.getBoxRfid().trim()); + List ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery); + if (ucmCtBaseList.isEmpty()) + throw new RuntimeException(String.format("绑定失败,料箱“%s”不存在", box.getBoxRfid().trim())); + + BaseKnife baseKnifeQuery = new BaseKnife(); + baseKnifeQuery.setRfid(boxItem.getBoxItemRfid().trim()); + List baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeQuery); + if (baseKnifeList.isEmpty()) + throw new RuntimeException(String.format("绑定失败,物料“%s”不存在", boxItem.getBoxItemRfid().trim())); + + UcmCtMaterial ucmCtMaterialQuery = new UcmCtMaterial(); + ucmCtMaterialQuery.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId())); + ucmCtMaterialQuery.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId()); + List ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery); + if (!ucmCtMaterialList.isEmpty()) + throw new RuntimeException(String.format("绑定失败,物料“%s”已经绑定料箱“%s”", boxItem.getBoxItemRfid().trim(), box.getBoxRfid().trim())); + + UcmCtMaterial ucmCtMaterial = new UcmCtMaterial(); + ucmCtMaterial.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId())); + ucmCtMaterial.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId()); + ucmCtMaterial.setCreateTime(new Date(System.currentTimeMillis())); + ucmCtMaterialMapper2.insertUcmCtMaterial(ucmCtMaterial); + } + } else { + for (BoxItem boxItem : box.getBoxItemList()) { + UcmCtBase ucmCtBaseQuery = new UcmCtBase(); + ucmCtBaseQuery.setCode(box.getBoxRfid().trim()); + List ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery); + if (ucmCtBaseList.isEmpty()) + throw new RuntimeException(String.format("解绑失败,料箱“%s”不存在", box.getBoxRfid().trim())); + + BaseKnife baseKnifeQuery = new BaseKnife(); + baseKnifeQuery.setRfid(boxItem.getBoxItemRfid().trim()); + List baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeQuery); + if (baseKnifeList.isEmpty()) + throw new RuntimeException(String.format("解绑失败,物料“%s”不存在", boxItem.getBoxItemRfid().trim())); + + UcmCtMaterial ucmCtMaterialQuery = new UcmCtMaterial(); + ucmCtMaterialQuery.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId())); + ucmCtMaterialQuery.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId()); + List ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery); + if (ucmCtMaterialList.isEmpty()) + throw new RuntimeException(String.format("解绑失败,物料“%s”并未绑定料箱“%s”", boxItem.getBoxItemRfid().trim(), box.getBoxRfid().trim())); + + ucmCtMaterialList.forEach(item -> { + ucmCtMaterialMapper2.deleteUcmCtMaterialByCtMaterialId(item.getCtMaterialId()); + }); + } + } + } + return "OK"; + } }