package jnpf.dmsMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import jnpf.dmsEntity.permission.entity.DmsFileVersionEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.UUID; @Mapper public interface DmsFileVersionMapper extends BaseMapper { @Select("SELECT id, tenant_id, document_id, version_no, version_label, file_name, mime_type, size_bytes, " + "checksum_sha256, prepared_by, prepared_on, created_by, created_at FROM public.dms_file_versions " + "WHERE tenant_id = #{tenantId} AND id = #{id}") DmsFileVersionEntity selectByTenantAndId(@Param("tenantId") String tenantId, @Param("id") UUID id); @Select("SELECT v.id, v.tenant_id, v.document_id, v.version_no, v.version_label, v.file_name, " + "v.mime_type, v.size_bytes, v.checksum_sha256, v.prepared_by, v.prepared_on, " + "v.created_by, v.created_at FROM public.dms_file_versions v " + "JOIN public.dms_version_states s ON s.tenant_id = v.tenant_id " + "AND s.document_id = v.document_id AND s.file_version_id = v.id " + "WHERE v.tenant_id = #{tenantId} AND v.document_id = #{documentId} " + "AND s.lifecycle_status = 'EFFECTIVE' AND s.effective_from <= CURRENT_TIMESTAMP " + "AND (s.effective_to IS NULL OR CURRENT_TIMESTAMP < s.effective_to)") DmsFileVersionEntity selectCurrentEffective(@Param("tenantId") String tenantId, @Param("documentId") UUID documentId); @Select("SELECT COALESCE(MAX(version_no), 0) + 1 FROM public.dms_file_versions " + "WHERE tenant_id = #{tenantId} AND document_id = #{documentId}") long selectNextVersionNo(@Param("tenantId") String tenantId, @Param("documentId") UUID documentId); @Select({""}) List selectByTenantAndIds(@Param("tenantId") String tenantId, @Param("ids") List ids); }