313 lines
17 KiB
XML
313 lines
17 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.app.mapper.AppResourceMapper">
|
|
|
|
<resultMap type="AppResource" id="AppResourceResult">
|
|
<result property="id" column="id" />
|
|
<result property="resourceTitle" column="resource_title" />
|
|
<result property="showImg" column="show_img" />
|
|
<result property="explain" column="explain" />
|
|
<result property="resourceType" column="resource_type" />
|
|
<result property="keyword" column="keyword" />
|
|
<result property="isShow" column="is_show" />
|
|
<result property="isAd" column="is_ad" />
|
|
<result property="adNumber" column="ad_number" />
|
|
<result property="priceFen" column="price_fen" />
|
|
<result property="virtualProductId" column="virtual_product_id" />
|
|
<result property="downNum" column="down_num" />
|
|
<result property="weight" column="weight" />
|
|
<result property="delFlag" column="del_flag" />
|
|
<result property="createBy" column="create_by" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="remark" column="remark" />
|
|
</resultMap>
|
|
|
|
<resultMap id="AppResourceAppResourceListResult" type="AppResource" extends="AppResourceResult">
|
|
<collection property="appResourceListList" notNullColumn="sub_id" javaType="java.util.List" resultMap="AppResourceListResult" />
|
|
</resultMap>
|
|
|
|
<resultMap type="AppResourceList" id="AppResourceListResult">
|
|
<result property="id" column="sub_id" />
|
|
<result property="listName" column="sub_list_name" />
|
|
<result property="listUrl" column="sub_list_url" />
|
|
<result property="password" column="sub_password" />
|
|
<result property="priceFen" column="sub_price_fen" />
|
|
<result property="status" column="sub_status" />
|
|
<result property="sortOrder" column="sub_sort_order" />
|
|
<result property="purchased" column="sub_purchased" />
|
|
<result property="appResourceId" column="sub_app_resource_id" />
|
|
</resultMap>
|
|
|
|
<sql id="selectAppResourceVo">
|
|
select a.id, a.resource_title, a.show_img, a.`explain`, a.resource_type, a.keyword,
|
|
a.is_show, a.is_ad, a.ad_number, a.price_fen,
|
|
(select vp.product_id from app_virtual_product vp
|
|
where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
|
|
a.down_num, a.weight, a.del_flag, a.create_by, a.create_time, a.remark
|
|
from app_resource a
|
|
</sql>
|
|
|
|
<select id="selectAppResourceList" parameterType="AppResource" resultMap="AppResourceResult">
|
|
<include refid="selectAppResourceVo"/>
|
|
<where>
|
|
<if test="resourceTitle != null and resourceTitle != ''"> and a.resource_title like concat('%', #{resourceTitle}, '%')</if>
|
|
<if test="showImg != null and showImg != ''"> and a.show_img = #{showImg}</if>
|
|
<if test="explain != null and explain != ''"> and a.`explain` = #{explain}</if>
|
|
<if test="resourceType != null "> and a.resource_type = #{resourceType}</if>
|
|
<if test="isShow != null "> and a.is_show = #{isShow}</if>
|
|
<if test="isAd != null "> and a.is_ad = #{isAd}</if>
|
|
<if test="adNumber != null "> and a.ad_number = #{adNumber}</if>
|
|
<if test="downNum != null "> and a.down_num = #{downNum}</if>
|
|
<if test="weight != null "> and a.weight = #{weight}</if>
|
|
<if test="keyword != null and keyword != ''"> and (a.keyword like concat('%', #{keyword}, '%') or a.resource_title like concat('%', #{keyword}, '%'))</if>
|
|
</where> ORDER BY a.weight desc, a.create_time desc
|
|
</select>
|
|
|
|
<select id="selectAppResourceById" parameterType="Long" resultMap="AppResourceAppResourceListResult">
|
|
select a.id, a.resource_title, a.show_img, a.`explain`,a.`keyword`, a.resource_type, a.is_show, a.is_ad, a.ad_number, a.price_fen,
|
|
(select vp.product_id from app_virtual_product vp where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
|
|
a.down_num, a.weight, a.del_flag, a.create_by, a.create_time, a.remark,
|
|
b.id as sub_id, b.list_name as sub_list_name, b.list_url as sub_list_url,
|
|
b.password as sub_password, b.price_fen as sub_price_fen,
|
|
b.status as sub_status, b.sort_order as sub_sort_order,
|
|
0 as sub_purchased, b.app_resource_id as sub_app_resource_id
|
|
from app_resource a
|
|
left join app_resource_list b on b.app_resource_id = a.id
|
|
where a.id = #{id}
|
|
order by b.sort_order asc, b.id asc
|
|
</select>
|
|
|
|
<select id="selectAppResourceListById" parameterType="Long" resultType="AppResourceList">
|
|
select id, list_name as listName, list_url as listUrl, password,
|
|
price_fen as priceFen, status, sort_order as sortOrder,
|
|
app_resource_id as appResourceId
|
|
from app_resource_list
|
|
where id = #{id}
|
|
limit 1
|
|
</select>
|
|
|
|
<select id="selectHighestEntitledResourceList" resultType="AppResourceList">
|
|
select rl.id, rl.list_name as listName, rl.list_url as listUrl, rl.password,
|
|
rl.price_fen as priceFen, rl.status, rl.sort_order as sortOrder,
|
|
rl.app_resource_id as appResourceId
|
|
from app_resource_entitlement re
|
|
inner join app_resource_list rl on rl.id = re.resource_list_id
|
|
where re.user_id = #{userId}
|
|
and re.resource_id = #{resourceId}
|
|
and re.status = 1
|
|
order by rl.sort_order desc, rl.id desc
|
|
limit 1
|
|
</select>
|
|
|
|
<insert id="insertAppResource" parameterType="AppResource" useGeneratedKeys="true" keyProperty="id">
|
|
insert into app_resource
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="resourceTitle != null and resourceTitle != ''">resource_title,</if>
|
|
<if test="showImg != null and showImg != ''">show_img,</if>
|
|
<if test="explain != null">`explain`,</if>
|
|
<if test="resourceType != null">resource_type,</if>
|
|
<if test="keyword != null and keyword != ''">keyword,</if>
|
|
<if test="isShow != null">is_show,</if>
|
|
<if test="isAd != null">is_ad,</if>
|
|
<if test="adNumber != null">ad_number,</if>
|
|
<if test="priceFen != null">price_fen,</if>
|
|
<if test="downNum != null">down_num,</if>
|
|
<if test="weight != null">weight,</if>
|
|
<if test="delFlag != null">del_flag,</if>
|
|
<if test="createBy != null">create_by,</if>
|
|
<if test="createTime != null">create_time,</if>
|
|
<if test="remark != null">remark,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="resourceTitle != null and resourceTitle != ''">#{resourceTitle},</if>
|
|
<if test="showImg != null and showImg != ''">#{showImg},</if>
|
|
<if test="explain != null">#{explain},</if>
|
|
<if test="resourceType != null">#{resourceType},</if>
|
|
<if test="keyword != null and keyword != ''">#{keyword},</if>
|
|
<if test="isShow != null">#{isShow},</if>
|
|
<if test="isAd != null">#{isAd},</if>
|
|
<if test="adNumber != null">#{adNumber},</if>
|
|
<if test="priceFen != null">#{priceFen},</if>
|
|
<if test="downNum != null">#{downNum},</if>
|
|
<if test="weight != null">#{weight},</if>
|
|
<if test="delFlag != null">#{delFlag},</if>
|
|
<if test="createBy != null">#{createBy},</if>
|
|
<if test="createTime != null">#{createTime},</if>
|
|
<if test="remark != null">#{remark},</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateAppResource" parameterType="AppResource">
|
|
update app_resource
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="resourceTitle != null and resourceTitle != ''">resource_title = #{resourceTitle},</if>
|
|
<if test="showImg != null and showImg != ''">show_img = #{showImg},</if>
|
|
<if test="explain != null">`explain` = #{explain},</if>
|
|
<if test="resourceType != null">resource_type = #{resourceType},</if>
|
|
<if test="keyword != null and keyword != ''">keyword = #{keyword},</if>
|
|
<if test="isShow != null">is_show = #{isShow},</if>
|
|
<if test="isAd != null">is_ad = #{isAd},</if>
|
|
<if test="adNumber != null">ad_number = #{adNumber},</if>
|
|
<if test="priceFen != null">price_fen = #{priceFen},</if>
|
|
<if test="downNum != null">down_num = #{downNum},</if>
|
|
<if test="weight != null">weight = #{weight},</if>
|
|
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
|
<if test="createBy != null">create_by = #{createBy},</if>
|
|
<if test="createTime != null">create_time = #{createTime},</if>
|
|
<if test="remark != null">remark = #{remark},</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<delete id="deleteAppResourceById" parameterType="Long">
|
|
delete from app_resource where id = #{id}
|
|
</delete>
|
|
|
|
<delete id="deleteAppResourceByIds" parameterType="String">
|
|
delete from app_resource where id in
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</delete>
|
|
|
|
<delete id="deleteAppResourceListByAppResourceIds" parameterType="String">
|
|
delete from app_resource_list where app_resource_id in
|
|
<foreach item="appResourceId" collection="array" open="(" separator="," close=")">
|
|
#{appResourceId}
|
|
</foreach>
|
|
</delete>
|
|
|
|
<delete id="deleteAppResourceListByAppResourceId" parameterType="Long">
|
|
delete from app_resource_list where app_resource_id = #{appResourceId}
|
|
</delete>
|
|
|
|
<insert id="batchAppResourceList">
|
|
insert into app_resource_list
|
|
(id, list_name, list_url, password, price_fen, status, sort_order, app_resource_id) values
|
|
<foreach item="item" index="index" collection="list" separator=",">
|
|
(#{item.id}, #{item.listName}, #{item.listUrl}, #{item.password},
|
|
#{item.priceFen}, #{item.status}, #{item.sortOrder}, #{item.appResourceId})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<select id="countOrderedRemovedResourceLists" resultType="int">
|
|
select count(1)
|
|
from app_virtual_order vo
|
|
inner join app_resource_list rl on rl.id = vo.resource_list_id
|
|
where rl.app_resource_id = #{resourceId}
|
|
<if test="retainedIds != null and retainedIds.size() > 0">
|
|
and rl.id not in
|
|
<foreach item="id" collection="retainedIds" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</if>
|
|
</select>
|
|
|
|
<select id="countVirtualOrdersByResourceId" parameterType="Long" resultType="int">
|
|
select count(1) from app_virtual_order where resource_id = #{resourceId}
|
|
</select>
|
|
|
|
<select id="selectAppResourceByIdAndUserId" resultMap="AppResourceAppResourceListResult">
|
|
select a.id, a.resource_title, a.show_img, a.`explain`, a.`keyword`, a.resource_type, a.is_show,
|
|
case
|
|
when #{userId} is not null
|
|
and (
|
|
(a.is_ad in (2, 3)
|
|
and exists(select 1 from app_integral_record ir
|
|
where ir.resource_id = a.id and ir.user_id = #{userId}
|
|
and ir.source = '资源兑换' and ir.is_add = 1))
|
|
or
|
|
(a.is_ad = 3
|
|
and exists(select 1 from app_resource_entitlement re
|
|
where re.resource_id = a.id and re.user_id = #{userId}
|
|
and re.status = 1 and re.resource_list_id is null))
|
|
)
|
|
then 0
|
|
else a.is_ad
|
|
end as is_ad,
|
|
a.ad_number, a.price_fen,
|
|
(select vp.product_id from app_virtual_product vp
|
|
where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
|
|
a.down_num, a.weight, a.del_flag, a.create_by, a.create_time, a.remark,
|
|
b.id as sub_id, b.list_name as sub_list_name,
|
|
case when
|
|
a.is_ad not in (2, 3)
|
|
or (
|
|
#{userId} is not null and (
|
|
exists(select 1 from app_integral_record ir
|
|
where ir.resource_id = a.id and ir.user_id = #{userId}
|
|
and ir.source = '资源兑换' and ir.is_add = 1)
|
|
or exists(select 1 from app_resource_entitlement re
|
|
left join app_resource_list owned_rl
|
|
on owned_rl.id = re.resource_list_id
|
|
where re.resource_id = a.id and re.user_id = #{userId}
|
|
and re.status = 1
|
|
and (re.resource_list_id is null
|
|
or (owned_rl.app_resource_id = a.id
|
|
and owned_rl.sort_order >= b.sort_order)))
|
|
)
|
|
)
|
|
then b.list_url else null end as sub_list_url,
|
|
case when
|
|
a.is_ad not in (2, 3)
|
|
or (
|
|
#{userId} is not null and (
|
|
exists(select 1 from app_integral_record ir
|
|
where ir.resource_id = a.id and ir.user_id = #{userId}
|
|
and ir.source = '资源兑换' and ir.is_add = 1)
|
|
or exists(select 1 from app_resource_entitlement re
|
|
left join app_resource_list owned_rl
|
|
on owned_rl.id = re.resource_list_id
|
|
where re.resource_id = a.id and re.user_id = #{userId}
|
|
and re.status = 1
|
|
and (re.resource_list_id is null
|
|
or (owned_rl.app_resource_id = a.id
|
|
and owned_rl.sort_order >= b.sort_order)))
|
|
)
|
|
)
|
|
then b.password else null end as sub_password,
|
|
b.price_fen as sub_price_fen, b.status as sub_status,
|
|
b.sort_order as sub_sort_order,
|
|
case when
|
|
a.is_ad not in (2, 3)
|
|
or (
|
|
#{userId} is not null and (
|
|
exists(select 1 from app_integral_record ir
|
|
where ir.resource_id = a.id and ir.user_id = #{userId}
|
|
and ir.source = '资源兑换' and ir.is_add = 1)
|
|
or exists(select 1 from app_resource_entitlement re
|
|
left join app_resource_list owned_rl
|
|
on owned_rl.id = re.resource_list_id
|
|
where re.resource_id = a.id and re.user_id = #{userId}
|
|
and re.status = 1
|
|
and (re.resource_list_id is null
|
|
or (owned_rl.app_resource_id = a.id
|
|
and owned_rl.sort_order >= b.sort_order)))
|
|
)
|
|
)
|
|
then 1 else 0 end as sub_purchased,
|
|
b.app_resource_id as sub_app_resource_id
|
|
from app_resource a
|
|
left join app_resource_list b on b.app_resource_id = a.id
|
|
and (
|
|
a.is_ad != 3
|
|
or b.status = 1
|
|
or (
|
|
#{userId} is not null
|
|
and exists(select 1 from app_resource_entitlement re
|
|
left join app_resource_list owned_rl
|
|
on owned_rl.id = re.resource_list_id
|
|
where re.resource_id = a.id and re.user_id = #{userId}
|
|
and re.status = 1
|
|
and (re.resource_list_id is null
|
|
or (owned_rl.app_resource_id = a.id
|
|
and owned_rl.sort_order >= b.sort_order)))
|
|
)
|
|
)
|
|
where a.id = #{id}
|
|
order by b.sort_order asc, b.id asc
|
|
</select>
|
|
</mapper>
|