<?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.lyms.platform.permission.dao.master.DoctorTeamMapper">
<resultMap id="DoctorTeamResultMap" type="com.lyms.platform.permission.model.DoctorTeam">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="team_name" property="teamName" jdbcType="VARCHAR"/>
<result column="org_id" property="orgId" jdbcType="INTEGER"/>
<result column="orgname" property="orgName" jdbcType="VARCHAR"/>
<result column="created" property="created" jdbcType="TIMESTAMP"/>
</resultMap>
<resultMap id="UsersResultMap" type="com.lyms.platform.permission.model.Users">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="logincenter_id" property="logincenterId" jdbcType="INTEGER"/>
<result column="type" property="type" jdbcType="INTEGER"/>
<result column="org_id" property="orgId" jdbcType="INTEGER"/>
<result column="dept_id" property="deptId" jdbcType="INTEGER"/>
<result column="ks_id" property="ksId" jdbcType="INTEGER"/>
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="account" property="account" jdbcType="VARCHAR"/>
<result column="pwd" property="pwd" jdbcType="VARCHAR"/>
<result column="phone" property="phone" jdbcType="VARCHAR"/>
<result column="publish_id" property="publishId" jdbcType="INTEGER"/>
<result column="publish_name" property="publishName" jdbcType="VARCHAR"/>
<result column="yn" property="yn" jdbcType="INTEGER"/>
<result column="enable" property="enable" jdbcType="INTEGER"/>
<result column="modified" property="modified" jdbcType="TIMESTAMP"/>
<result column="created" property="created" jdbcType="TIMESTAMP"/>
<result column="remarks" property="remarks" jdbcType="VARCHAR"/>
<result column="last_login_time" property="lastLoginTime" jdbcType="TIMESTAMP"/>
<result column="foreign_id" property="foreignId" jdbcType="VARCHAR"/>
<result column="employee_id" property="employeeId" jdbcType="VARCHAR"/>
<result column="other_account" property="otherAccount" jdbcType="INTEGER"/>
<result column="zhiChenId" property="zhiChenId" jdbcType="INTEGER"/>
<result column="defaultpage" property="defaultPage" jdbcType="INTEGER"/>
<result column="doctorTeam_id" property="doctorTeamId" jdbcType="INTEGER"/>
<result column="teamname" property="teamName" jdbcType="INTEGER"/>
<result column="orgname" property="orgName" jdbcType="VARCHAR"/>
<result column="deptname" property="deptName" jdbcType="VARCHAR"/>
</resultMap>
<insert id="addDoctorTeam" parameterType="com.lyms.platform.permission.model.DoctorTeam">
insert into doctor_team
(team_name,org_id,created)
values
(#{teamName},#{orgId},#{created})
</insert>
<update id="updateDoctorTeam" parameterType="com.lyms.platform.permission.model.DoctorTeam">
update doctor_team
<set>
<if test="teamName != null and teamName != ''">
team_name = #{teamName,jdbcType=VARCHAR}
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="delDoctorTeam" parameterType="java.lang.Integer">
delete from doctor_team where id = #{id,jdbcType=INTEGER}
</delete>
<sql id="DoctorTeamLimit">
<if test="sort != null and sort != '' ">
order by ${sort}
<if test="need != null and need != ''">
limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
</if>
</if>
</sql>
<sql id="DoctorTeamCondition">
<where>
1 = 1
<if test="id != null and id >= 0">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="orgId != null and orgId >= 0">
and org_id = #{orgId,jdbcType=INTEGER}
</if>
<if test="teamName != null and teamName != ''">
and team_name like concat("%",#{teamName,jdbcType=VARCHAR},"%")
</if>
</where>
</sql>
<select id="queryListDoctorTeam" resultMap="DoctorTeamResultMap" parameterType="com.lyms.platform.permission.model.DoctorTeam">
select
d.id,d.team_name,d.org_id,o.name as orgname ,d.created
from doctor_team d left join organization o on d.org_id=o.id
<include refid="DoctorTeamCondition"/>
<include refid="DoctorTeamLimit"/>
</select>
<select id="queryListDoctorTeamCount" resultType="int" parameterType="com.lyms.platform.permission.model.UsersQuery">
select count(DISTINCT id)
from doctor_team
<include refid="DoctorTeamCondition"/>
</select>
<sql id="DoctorLimit">
<if test="sort != null and sort != '' ">
order by ${sort}
<if test="need != null and need != ''">
limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
</if>
</if>
</sql>
<sql id="DoctorCondition">
<where>
1 = 1
<if test="id != null and id >= 0">
and u.id = #{id,jdbcType=INTEGER}
</if>
<if test="orgId != null and orgId >= 0">
and u.org_id = #{orgId,jdbcType=INTEGER}
</if>
<if test="name != null and name != ''">
and u.name like concat("%",#{name,jdbcType=VARCHAR},"%")
</if>
<if test="deptId != null and deptId >= 0">
and u.dept_id = #{deptId,jdbcType=INTEGER}
</if>
<if test="doctorTeamId != null and doctorTeamId >= 0">
and u.doctorTeam_id = #{doctorTeamId,jdbcType=INTEGER}
</if>
</where>
</sql>
<select id="queryListDoctor" resultMap="UsersResultMap" parameterType="com.lyms.platform.permission.model.UsersQuery">
select
u.id,u.org_id,u.dept_id,u.name,u.phone,u.created,u.remarks,u.doctorTeam_id,
o.name as orgname,d.team_name as teamname,dp.name as deptname
from users u
left join organization o on u.org_id=o.id
left join doctor_team d on u.doctorTeam_id=d.id
left join departments dp on u.dept_id=dp.id
<include refid="DoctorCondition"/>
<include refid="DoctorLimit"/>
</select>
<select id="queryListDoctorCount" resultType="int" parameterType="com.lyms.platform.permission.model.UsersQuery">
select count(DISTINCT u.id)
from users u
left join organization o on u.org_id=o.id
left join doctor_team d on u.doctorTeam_id=d.id
left join departments dp on u.dept_id=dp.id
<include refid="DoctorCondition"/>
</select>
<update id="allotDoctorTeam" parameterType="com.lyms.platform.permission.model.UsersQuery">
update users
<set>
<if test="doctorTeamId != null and doctorTeamId >=0 ">
doctorTeam_id = #{doctorTeamId,jdbcType=VARCHAR}
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>