编辑操作,根据前端传来的id去数据库查询不属于自己实体的集合。然后再跟前端传来的某个唯一属性做比对。相等即抛异常,不相等编辑成功。
字面上不好理解,贴上需求图
@Transactional
@Override
public int updateLogisticsProperty(LogisticsProperty logisticsProperty)
{
logisticsPropertyMapper.selectList(new LambdaQueryWrapper<LogisticsProperty>().ne(LogisticsProperty::getId,logisticsProperty.getId())).forEach(
item ->{
if (item.getPropertyName().equals(logisticsProperty.getPropertyName())){
throw new CustomException("编辑错误,该物流属性名称:"+logisticsProperty.getPropertyName()+"已经存在!");
}
if (item.getSort().intValue()==logisticsProperty.getSort().intValue()){
throw new CustomException("编辑错误,该物流属性序号:"+logisticsProperty.getSort()+"已经存在!");
}
});
logisticsProperty.setUpdateTime(DateUtils.getNowDate());
int i = logisticsPropertyMapper.updateLogisticsProperty(logisticsProperty);
return i;
}