Commit 5962e7aa by 赵剑炜

修改了部分单警柜的方法

parent 0b1c8eda
......@@ -46,97 +46,96 @@ public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, Cabinet
@Override
@Transactional(rollbackFor = Exception.class)
public String AddOrUpdateBoxInfo(UpdateCabinetReq req) {
// Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
// .eq(Cabinet::getCabinetNum, req.getSerialNum()));
// if (ObjectUtil.isNull(cabinet)) {
// throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
// }
//
// List<UpdateCabinetBoxReq> addList = req.getCabinetBoxList();
// List<CabinetBox> existingBoxes = list(new LambdaQueryWrapper<CabinetBox>()
// .eq(CabinetBox::getCabinetId, cabinet.getId()));
//
// Map<Integer, CabinetBox> existingBoxMap = existingBoxes.stream()
// .collect(Collectors.toMap(CabinetBox::getNum, Function.identity()));
//
// List<CabinetBox> boxListAdd = new ArrayList<>();
//
// for (UpdateCabinetBoxReq boxReq : addList) {
// CabinetBox box = new CabinetBox();
// box.setCabinetId(cabinet.getId());
// box.setPower(boxReq.getPower());
// box.setEquipmentConfig(boxReq.getEquipmentConfig());
// box.setContainType(boxReq.getContainType());
// box.setState(0);
// box.setBoxName(boxReq.getBoxName());
// box.setNum(boxReq.getNum());
// box.setUpdateTime(new Date());
// // 在内存中比较是否存在相同 SerialNum 和相同 num 的数据
// CabinetBox existingBox = existingBoxMap.get(boxReq.getNum());
//
// if (existingBox != null) {
// // 如果存在,则更新数据
// box.setId(existingBox.getId());
// updateById(box);
// } else {
// // 如果不存在,则新增数据
// boxListAdd.add(box);
// }
// }
//
// Integer num = cabinet.getNum();//获取当前柜的总数量
// if (num == null) {
// num = 0;
// }
//
// // 更新 Cabinet 实体
// cabinet.setNum(num + addList.size());
// cabinetService.updateById(cabinet);
//
// if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
// {
// MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
// }
// // 批量保存新增的数据
// saveBatch(boxListAdd);
//
// return cabinet.getId();
return null;
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)) {
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
List<UpdateCabinetBoxReq> addList = req.getCabinetBoxList();
List<CabinetBox> existingBoxes = list(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId()));
Map<Integer, CabinetBox> existingBoxMap = existingBoxes.stream()
.collect(Collectors.toMap(CabinetBox::getNum, Function.identity()));
List<CabinetBox> boxListAdd = new ArrayList<>();
for (UpdateCabinetBoxReq boxReq : addList) {
CabinetBox box = new CabinetBox();
box.setCabinetId(cabinet.getId());
box.setPower(boxReq.getPower());
box.setEquipmentConfig(boxReq.getEquipmentConfig());
box.setContainType(boxReq.getContainType());
box.setState(1);
box.setBoxName(boxReq.getBoxName());
box.setNum(boxReq.getNum());
box.setUpdateTime(new Date());
// 在内存中比较是否存在相同 SerialNum 和相同 num 的数据
CabinetBox existingBox = existingBoxMap.get(boxReq.getNum());
if (existingBox != null) {
// 如果存在,则更新数据
box.setId(existingBox.getId());
updateById(box);
} else {
// 如果不存在,则新增数据
Integer num = cabinet.getNum();//获取当前柜的总数量
if (num == null) {
num = 0;
}
cabinet.setNum(num + addList.size());
boxListAdd.add(box);
}
}
cabinetService.updateById(cabinet);
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
}
// 批量保存新增的数据
saveBatch(boxListAdd);
return cabinet.getId();
}
//删除箱门
@Override
@Transactional(rollbackFor = Exception.class)
public String DeleteBox(UpdateCabinetReq req) {
// Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
// .eq(Cabinet::getCabinetNum, req.getSerialNum()));
// if (ObjectUtil.isNull(cabinet)){
// throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
// }
// CabinetBox one = getOne(new LambdaQueryWrapper<CabinetBox>()
// .eq(CabinetBox::getCabinetId, cabinet.getId())
// .eq(CabinetBox::getId,req.getId()));
// if (ObjectUtil.isNotNull(one)){
// throw new ServiceException(CabinetBoxExceptionEnum.CABINETBOX_IS_EXISTS);
// }
// //添加单警柜箱门信息默认状态为0正常
// List<String> boxNumList = req.getNumList();
// remove(new LambdaQueryWrapper<CabinetBox>()
// .eq(CabinetBox::getCabinetId, cabinet.getId())
// .in(CabinetBox::getNum, boxNumList));
//
// // 更新 Cabinet 实体的 num 字段
// Integer cabinetNum = cabinet.getNum();
// if (cabinetNum != null) {
// cabinet.setNum(cabinetNum - boxNumList.size());
// cabinetService.updateById(cabinet);
// }
// if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
// {
// MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
// }
// return cabinet.getId();
return null;
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)){
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
CabinetBox one = getOne(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId())
.eq(CabinetBox::getId,req.getId()));
if (ObjectUtil.isNotNull(one)){
throw new ServiceException(CabinetBoxExceptionEnum.CABINETBOX_IS_EXISTS);
}
//添加单警柜箱门信息默认状态为0正常
List<String> boxNumList = req.getNumList();
remove(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId())
.in(CabinetBox::getNum, boxNumList));
// 更新 Cabinet 实体的 num 字段
Integer cabinetNum = cabinet.getNum();
if (cabinetNum != null) {
cabinet.setNum(cabinetNum - boxNumList.size());
cabinetService.updateById(cabinet);
}
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
}
return cabinet.getId();
}
//判断箱子信息是否存在
@Override
......
......@@ -304,7 +304,8 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
// 查询单警柜的箱门信息
List<CabinetBox> list = cabinetBoxService.list(new LambdaQueryWrapper<CabinetBox>()
.eq(ObjectUtil.isNotEmpty(cabinet.getId()), CabinetBox::getCabinetId, cabinet.getId())
.eq(ObjectUtil.isNotEmpty(req.getContainType()), CabinetBox::getContainType, req.getContainType()));
.eq(ObjectUtil.isNotEmpty(req.getContainType()), CabinetBox::getContainType, req.getContainType())
.orderByAsc(CabinetBox::getNum));
List<CabinetBoxDto> boxList = list.stream()
.map(cabinetBox -> {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论