完成上传接口

This commit is contained in:
刘名喜 2024-11-25 19:22:44 +08:00
parent 3a6d919429
commit e1019d455d
3 changed files with 72 additions and 6 deletions

View File

@ -61,11 +61,11 @@ public class UcmCtBaseController extends BaseController {
public String uploadBox(
@RequestBody List<Box> boxList
) {
boxList.forEach(box -> {
System.out.println(JSON.toJSONString(box));
});
return "失败,正在调试中...";
try {
return ucmCtBaseService.bindAndUnbindUcmCtBase(boxList);
} catch (Exception e) {
return e.getMessage();
}
}
/**

View File

@ -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<Box> boxList);
}

View File

@ -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<UcmCtMaterial> 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<Box> boxList) {
for (Box box : boxList) {
if (!box.getIsUnbind()) {
for (BoxItem boxItem : box.getBoxItemList()) {
UcmCtBase ucmCtBaseQuery = new UcmCtBase();
ucmCtBaseQuery.setCode(box.getBoxRfid().trim());
List<UcmCtBase> 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<BaseKnife> 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<UcmCtMaterial> 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<UcmCtBase> 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<BaseKnife> 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<UcmCtMaterial> 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";
}
}