优化分组树的添加

结构优化
648540858 2023-11-10 17:41:20 +08:00
parent e96b39935d
commit abbb5643c5
2 changed files with 21 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.List;
@ -70,6 +71,16 @@ public class GroupServiceImpl implements IGroupService {
assert group.getCommonGroupDeviceId() != null;
group.setCommonGroupCreateTime(DateUtil.getNow());
group.setCommonGroupUpdateTime(DateUtil.getNow());
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(group.getCommonGroupParentId());
if (ObjectUtils.isEmpty(group.getCommonGroupParentId().trim()) || channelIdType.equals(Gb28181CodeType.BUSINESS_GROUP)) {
group.setCommonGroupParentId(null);
}
if (ObjectUtils.isEmpty(group.getCommonGroupTopId().trim())) {
Gb28181CodeType channelIdTypeForItem = SipUtils.getChannelIdType(group.getCommonGroupDeviceId());
if (channelIdTypeForItem.equals(Gb28181CodeType.BUSINESS_GROUP)) {
group.setCommonGroupTopId(group.getCommonGroupDeviceId());
}
}
return groupMapper.add(group) > 0;
}

View File

@ -27,20 +27,22 @@ public interface GroupMapper {
" WHERE common_group_device_id = #{deviceId} ")
Group queryByDeviceId(@Param("deviceId") String deviceId);
@Insert("INSERT INTO wvp_common_group (" +
@Insert(value = " <script>" +
"INSERT INTO wvp_common_group (" +
"common_group_device_id, " +
"common_group_name, " +
"common_group_parent_id, " +
"<if test='group.commonGroupParentId != null'>common_group_parent_id, </if>" +
"common_group_top_id, " +
"common_group_update_time, " +
"common_group_create_time ) " +
"VALUES (" +
"#{commonGroupDeviceId}, " +
"#{commonGroupName}, " +
"#{commonGroupParentId}, " +
"#{commonGroupTopId}, " +
"#{commonGroupUpdateTime}, " +
"#{commonGroupCreateTime})")
"#{group.commonGroupDeviceId}, " +
"#{group.commonGroupName}, " +
"<if test='group.commonGroupParentId != null'>#{group.commonGroupParentId}, </if>" +
"#{group.commonGroupTopId}, " +
"#{group.commonGroupUpdateTime}, " +
"#{group.commonGroupCreateTime})" +
"</script>")
int add(@Param("group") Group group);
@Delete("delete from wvp_common_group where common_group_id = #{id}")