<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, hnqz All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: hnqz
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.WmWkAlbumMapper">

	<resultMap id="wmWkAlbumMap" type="com.qunzhixinxi.hnqz.admin.entity.WmWkAlbum">
		<id property="id" column="id"/>
		<result property="xcmc" column="xcmc"/>
		<result property="scfm" column="scfm"/>
		<result property="glyp" column="glyp"/>
		<result property="wb" column="wb"/>
		<result property="deptId" column="dept_id"/>
		<result property="delFlag" column="del_flag"/>
		<result property="enableFlag" column="enable_flag"/>
		<result property="tenantId" column="tenant_id"/>
		<result property="createTime" column="create_time"/>
		<result property="createUser" column="create_user"/>
		<result property="updateTime" column="update_time"/>
		<result property="updateUser" column="update_user"/>
		<result property="forwardNum" column="forward_num"/>
		<result property="temp1" column="temp1"/>
		<result property="score" column="score"/>
	</resultMap>

	<select id="pageByCondition" resultMap="wmWkAlbumMap">
		SELECT
			*
		FROM
			wm_wk_album m
		WHERE
		m.del_flag = 0
		and m.enable_flag = 0
		and m.id IN (
				SELECT
					re.album_id
				FROM
					re_album_drug re,
					wm_da_drug_ent_drugtable d
				WHERE
					d.id = re.drug_id

		<if test="query.drugIds != null and query.drugIds.size()>0">
			AND d.drug_ent_id IN
			<foreach item="item" index="index" collection="query.drugIds" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
			)
			order  by m.create_time desc
	</select>

	<select id="pageByConditionNew" resultMap="wmWkAlbumMap">
		SELECT
			*
		FROM
			wm_wk_album m
		WHERE
			m.del_flag = 0
		AND m.enable_flag = 0
		AND m.id IN (
			SELECT
				re.album_id
			FROM
				re_album_drug re,
				wm_da_drug_ent_drugtable d
			WHERE
				d.id = re.drug_id
			AND d.id IN (
				SELECT
					g.drug_id
				FROM
					re_dept_drug g
				WHERE
					g.dept_id = #{query.deptId}
			)
		)
		order  by m.create_time desc
	</select>
</mapper>
