|
|
@@ -18,11 +18,13 @@ import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnconfigMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnindicatorMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnobjectMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnconfigService;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -160,16 +162,21 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
IotWarnobject iotWarnobjectQuery = new IotWarnobject();
|
|
|
iotWarnobjectQuery.setTid(SecurityUtils.getTid());
|
|
|
iotWarnobjectQuery.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
- List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
- List<String> oldWarnObjIds = iotWarnobjectList.stream().map(IotWarnobject::getWoBid).collect(Collectors.toList());
|
|
|
- iotWarnobjectMapper.deleteIotWarnobjectByWoBids(oldWarnObjIds.toArray(new String[0]), SecurityUtils.getTid());
|
|
|
-
|
|
|
- List<IotWarnobject> warnobjects = iotWarnconfigEditReqVo.getIotWarnobjectList();
|
|
|
- for(IotWarnobject iotWarnobject : warnobjects){
|
|
|
- iotWarnobject.setWoBid(iotWarnobject.getUUId());
|
|
|
- iotWarnobject.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
- iotWarnobject.setTid(SecurityUtils.getTid());
|
|
|
- iotWarnobjectMapper.insertIotWarnobject(iotWarnobject);
|
|
|
+ // 获取配置的旧的告警对象
|
|
|
+ List<IotWarnobject> oldWarnObjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+ // 对比两个集合,获取不同的内容
|
|
|
+ Collection<IotWarnobject> differ = CollectionUtils.disjunction(oldWarnObjectList,iotWarnconfigEditReqVo.getIotWarnobjectList());
|
|
|
+ // 老数据中存在,新数据中不存在,代表被删除的数据
|
|
|
+ Collection<IotWarnobject> deleteData = CollectionUtils.subtract(oldWarnObjectList,differ);
|
|
|
+ List<String> deleteWarnObjectBids = deleteData.stream().map(IotWarnobject::getWoBid).collect(Collectors.toList());
|
|
|
+ iotWarnobjectMapper.deleteIotWarnobjectByWoBids(deleteWarnObjectBids.toArray(new String[0]), SecurityUtils.getTid());
|
|
|
+ // 老数据中不存在,新数据中存在,代表新增的数据
|
|
|
+ Collection<IotWarnobject> addData = CollectionUtils.subtract(iotWarnconfigEditReqVo.getIotWarnobjectList(),differ);
|
|
|
+ for(IotWarnobject addWarnObject : addData){
|
|
|
+ addWarnObject.setTid(SecurityUtils.getTid());
|
|
|
+ addWarnObject.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
+ addWarnObject.setWoBid(addWarnObject.getUUId());
|
|
|
+ iotWarnobjectMapper.insertIotWarnobject(addWarnObject);
|
|
|
}
|
|
|
for(IotWarnindicator iotWarnindicator : iotWarnconfigEditReqVo.getIotWarnindicatorList()){
|
|
|
iotWarnindicatorMapper.updateIotWarnindicator(iotWarnindicator);
|