|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.hw.dms.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import com.hw.common.core.exception.ServiceException;
|
|
|
|
|
import com.hw.common.core.utils.DateUtils;
|
|
|
|
|
import com.hw.system.api.model.LoginUser;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -63,15 +64,38 @@ public class DmsBaseDeviceBomServiceImpl implements IDmsBaseDeviceBomService
|
|
|
|
|
if (dmsBaseDeviceBom.getParentId()==0){
|
|
|
|
|
dmsBaseDeviceBom.setAncestors("0");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
DmsBaseDeviceBom dmsBaseDeviceBom1 = new DmsBaseDeviceBom();
|
|
|
|
|
dmsBaseDeviceBom1.setDeviceBomId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
String ancestors = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(dmsBaseDeviceBom1).get(0).getAncestors();
|
|
|
|
|
dmsBaseDeviceBom.setAncestors(ancestors+","+dmsBaseDeviceBom.getParentId());
|
|
|
|
|
else {
|
|
|
|
|
DmsBaseDeviceBom selectDeviceBom = new DmsBaseDeviceBom();
|
|
|
|
|
selectDeviceBom.setDeviceBomId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
String ancestors = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(selectDeviceBom).get(0).getAncestors();
|
|
|
|
|
dmsBaseDeviceBom.setAncestors(ancestors + "," + dmsBaseDeviceBom.getParentId());
|
|
|
|
|
//遍历所有祖先节点,检查设备ID是否重复,设备的bom不能包含其设备本身
|
|
|
|
|
String ancestorsNode = dmsBaseDeviceBom.getAncestors();
|
|
|
|
|
for (String ancestorsOne : ancestorsNode.split(",")) {
|
|
|
|
|
if (ancestorsOne.equals("0")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DmsBaseDeviceBom DeviceBomUpdate = dmsBaseDeviceBomMapper.
|
|
|
|
|
selectDmsBaseDeviceBomByDeviceBomId(Long.parseLong(ancestorsOne));
|
|
|
|
|
if (dmsBaseDeviceBom.getDeviceId().equals(DeviceBomUpdate.getDeviceId())) {
|
|
|
|
|
throw new ServiceException("不能添加与祖先节点相同的设备编号");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//同一双亲节点的设备ID不能重复,不同双亲结点同一层级的兄弟节点可以重复
|
|
|
|
|
//顶级节点可以重复,顶级节点不进else
|
|
|
|
|
DmsBaseDeviceBom query = new DmsBaseDeviceBom();
|
|
|
|
|
query.setParentId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
// 查询父节点的所有子节点,即兄弟节点,都放到列表sibling中
|
|
|
|
|
List<DmsBaseDeviceBom> siblings = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(query);
|
|
|
|
|
// 遍历兄弟节点,检查设备ID是否重复
|
|
|
|
|
for (DmsBaseDeviceBom sibling : siblings) {
|
|
|
|
|
if (dmsBaseDeviceBom.getDeviceId().equals(sibling.getDeviceId())) {
|
|
|
|
|
throw new ServiceException("不能添加与兄弟节点相同的设备编号: " + dmsBaseDeviceBom.getDeviceId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dmsBaseDeviceBomMapper.insertDmsBaseDeviceBom(dmsBaseDeviceBom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改设备BOM信息
|
|
|
|
|
*
|
|
|
|
@ -86,10 +110,34 @@ public class DmsBaseDeviceBomServiceImpl implements IDmsBaseDeviceBomService
|
|
|
|
|
dmsBaseDeviceBom.setAncestors("0");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
DmsBaseDeviceBom dmsBaseDeviceBom1 = new DmsBaseDeviceBom();
|
|
|
|
|
dmsBaseDeviceBom1.setDeviceBomId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
String ancestors = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(dmsBaseDeviceBom1).get(0).getAncestors();
|
|
|
|
|
DmsBaseDeviceBom DeviceBom = new DmsBaseDeviceBom();
|
|
|
|
|
DeviceBom.setDeviceBomId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
String ancestors = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(DeviceBom).get(0).getAncestors();
|
|
|
|
|
dmsBaseDeviceBom.setAncestors(ancestors+","+dmsBaseDeviceBom.getParentId());
|
|
|
|
|
//遍历所有祖先节点,检查设备ID是否重复,设备的bom不能包含其设备本身
|
|
|
|
|
String ancestorsNode = dmsBaseDeviceBom.getAncestors();
|
|
|
|
|
for (String ancestorsOne : ancestorsNode.split(",")) {
|
|
|
|
|
if (ancestorsOne.equals("0")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DmsBaseDeviceBom DeviceBomUpdate = dmsBaseDeviceBomMapper.
|
|
|
|
|
selectDmsBaseDeviceBomByDeviceBomId(Long.parseLong(ancestorsOne));
|
|
|
|
|
if (dmsBaseDeviceBom.getDeviceId().equals(DeviceBomUpdate.getDeviceId())) {
|
|
|
|
|
throw new ServiceException("不能添加与祖先节点相同的设备编号");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//同一双亲节点的设备ID不能重复,不同双亲结点同一层级的兄弟节点可以重复
|
|
|
|
|
//顶级节点可以重复,顶级节点不进else
|
|
|
|
|
DmsBaseDeviceBom query = new DmsBaseDeviceBom();
|
|
|
|
|
query.setParentId(dmsBaseDeviceBom.getParentId());
|
|
|
|
|
// 查询父节点的所有子节点
|
|
|
|
|
List<DmsBaseDeviceBom> siblings = dmsBaseDeviceBomMapper.selectDmsBaseDeviceBomList(query);
|
|
|
|
|
// 查询父节点的所有子节点,即兄弟节点,都放到列表sibling中
|
|
|
|
|
for (DmsBaseDeviceBom sibling : siblings) {
|
|
|
|
|
if (dmsBaseDeviceBom.getDeviceId().equals(sibling.getDeviceId())) {
|
|
|
|
|
throw new ServiceException("不能添加与兄弟节点相同的设备编号: " + dmsBaseDeviceBom.getDeviceId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dmsBaseDeviceBom.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
return dmsBaseDeviceBomMapper.updateDmsBaseDeviceBom(dmsBaseDeviceBom);
|
|
|
|
|