a-tuoheng-airline/src/main/resources/mapper/airline/AirlineFileGroupMapper.xml

151 lines
6.1 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.airline.mapper.AirlineFileGroupMapper">
<!-- 结果映射 -->
<resultMap id="AirlineFileGroupResult" type="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity">
<id property="groupId" column="group_id" />
<result property="groupName" column="group_name" />
<result property="userId" column="user_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="deletedBy" column="deleted_by" />
<result property="deletedTime" column="deleted_time" />
<result property="airlineCount" column="airline_count" />
</resultMap>
<!-- 结果映射 -->
<resultMap type="com.ruoyi.airline.mapper.entity.AirlineFileEntity" id="AirlineFileResult">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="airVendor" column="air_vendor" />
<result property="airType" column="air_type" />
<result property="fileName" column="file_name" />
<result property="fileUrl" column="file_url" />
<result property="type" column="type" />
<result property="source" column="source" />
<result property="status" column="status" />
<result property="fileMd5" column="file_md5" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="groupName" column="group_name" />
<result property="groupId" column="group_id" />
<result property="userId" column="user_id" />
</resultMap>
<!-- 检查分组名称是否唯一 -->
<select id="checkgroupNameUnique" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity" resultType="java.lang.Integer">
select count(1) from airline_file_group
where group_name = #{groupName}
and del_flag = 0
<if test="groupId != null">
and group_id != #{groupId}
</if>
<if test="userId != null">
and user_id = #{userId}
</if>
</select>
<!-- 删除分组(软删除) -->
<update id="deletegroup" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity">
update airline_file_group
set del_flag = 1,
deleted_by = #{deletedBy},
deleted_time = now()
where group_id = #{groupId}
<if test="userId != null">
and user_id = #{userId}
</if>
</update>
<!-- 更新分组 -->
<update id="updateGroup" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity">
update airline_file_group
set group_name = #{groupName},
update_by = #{updateBy},
update_time = now()
where group_id = #{groupId}
and del_flag = 0
<if test="userId != null">
and user_id = #{userId}
</if>
</update>
<!-- 插入分组 -->
<insert id="insertGroup" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity">
insert into airline_file_group (group_name, user_id, create_by, create_time, update_by, update_time, del_flag)
values (#{groupName}, #{userId}, #{createBy}, now(), #{updateBy}, now(), 0)
</insert>
<!-- 查询分组列表 -->
<select id="selectGroupList" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileGroupEntity" resultMap="AirlineFileGroupResult">
select
afg.group_id,
afg.group_name,
afg.user_id,
afg.create_by,
afg.create_time,
afg.update_by,
afg.update_time,
afg.del_flag,
afg.deleted_by,
afg.deleted_time,
COALESCE(airline_count.count, 0) as airline_count
from airline_file_group afg
left join (
select afgi.group_id, count(afgi.id) as count
from airline_file_group_info afgi
WHERE afgi.del_flag = 0
group by afgi.group_id
) airline_count on afg.group_id = airline_count.group_id
<where>
afg.del_flag = 0
<if test="groupName != null and groupName != ''">
and afg.group_name like concat('%', #{groupName}, '%')
</if>
<if test="userId != null">
and afg.user_id = #{userId}
</if>
</where>
</select>
<!-- 根据用户ID查询航线列表 -->
<select id="selectAirlineListByUserId" parameterType="com.ruoyi.airline.mapper.entity.AirlineFileEntity" resultMap="AirlineFileResult">
select
af.*,
afg.group_name
from airline_file af
left join airline_file_group_info afgi on af.id = afgi.airline_id and afgi.del_flag = 0
left join airline_file_group afg on afgi.group_id = afg.group_id and afg.del_flag = 0
<where>
<if test="userId != null">
and afg.user_id = #{userId}
</if>
<if test="name != null and name != ''">
and af.name like concat('%', #{name}, '%')
</if>
<if test="airVendor != null and airVendor != ''">
and af.air_vendor like concat('%', #{airVendor}, '%')
</if>
<if test="status != null">
and af.status = #{status}
</if>
<if test="type != null and type != ''">
and af.type = #{type}
</if>
</where>
<if test="updateTimeOrderBy != null and updateTimeOrderBy != ''">
order by af.update_time #{updateTimeOrderBy}
</if>
</select>
</mapper>