|
|
@@ -0,0 +1,391 @@
|
|
|
+<?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.fs.his.mapper.FsUserBindWxMapper">
|
|
|
+
|
|
|
+ <resultMap type="FsUserBindWx" id="FsUserBindWxResult">
|
|
|
+ <result property="id" column="id" />
|
|
|
+ <result property="fsUserId" column="fs_user_id" />
|
|
|
+ <result property="unionId" column="union_id" />
|
|
|
+ <result property="maOpenId" column="ma_open_id" />
|
|
|
+ <result property="mpOpenId" column="mp_open_id" />
|
|
|
+ <result property="bizType" column="biz_type" />
|
|
|
+ <result property="companyId" column="company_id" />
|
|
|
+ <result property="companyUserId" column="company_user_id" />
|
|
|
+ <result property="bindUserId" column="bind_user_id" />
|
|
|
+ <result property="externalContactId" column="external_contact_id" />
|
|
|
+ <result property="userCompanyUserId" column="user_company_user_id" />
|
|
|
+ <result property="type" column="type" />
|
|
|
+ <result property="createTime" column="create_time" />
|
|
|
+ <result property="updateTime" column="update_time" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <sql id="selectFsUserBindWxVo">
|
|
|
+ select id, fs_user_id, union_id, ma_open_id, mp_open_id, biz_type,
|
|
|
+ company_id, company_user_id, bind_user_id, external_contact_id, user_company_user_id, type,
|
|
|
+ create_time, update_time
|
|
|
+ from fs_user_bind_wx
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="selectFsUserBindWxById" parameterType="Long" resultMap="FsUserBindWxResult">
|
|
|
+ <include refid="selectFsUserBindWxVo"/>
|
|
|
+ where id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectFsUserBindWxList" parameterType="FsUserBindWx" resultMap="FsUserBindWxResult">
|
|
|
+ <include refid="selectFsUserBindWxVo"/>
|
|
|
+ <where>
|
|
|
+ <if test="fsUserId != null">and fs_user_id = #{fsUserId}</if>
|
|
|
+ <if test="unionId != null and unionId != ''">and union_id = #{unionId}</if>
|
|
|
+ <if test="maOpenId != null and maOpenId != ''">and ma_open_id = #{maOpenId}</if>
|
|
|
+ <if test="mpOpenId != null and mpOpenId != ''">and mp_open_id = #{mpOpenId}</if>
|
|
|
+ <if test="bizType != null">and biz_type = #{bizType}</if>
|
|
|
+ <if test="companyId != null">and company_id = #{companyId}</if>
|
|
|
+ <if test="companyUserId != null">and company_user_id = #{companyUserId}</if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="insertFsUserBindWx" parameterType="FsUserBindWx" useGeneratedKeys="true" keyProperty="id">
|
|
|
+ insert into fs_user_bind_wx
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="fsUserId != null">fs_user_id,</if>
|
|
|
+ <if test="unionId != null">union_id,</if>
|
|
|
+ <if test="maOpenId != null">ma_open_id,</if>
|
|
|
+ <if test="mpOpenId != null">mp_open_id,</if>
|
|
|
+ <if test="bizType != null">biz_type,</if>
|
|
|
+ <if test="companyId != null">company_id,</if>
|
|
|
+ <if test="companyUserId != null">company_user_id,</if>
|
|
|
+ <if test="bindUserId != null">bind_user_id,</if>
|
|
|
+ <if test="externalContactId != null">external_contact_id,</if>
|
|
|
+ <if test="userCompanyUserId != null">user_company_user_id,</if>
|
|
|
+ <if test="type != null">type,</if>
|
|
|
+ <if test="createTime != null">create_time,</if>
|
|
|
+ <if test="updateTime != null">update_time,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="fsUserId != null">#{fsUserId},</if>
|
|
|
+ <if test="unionId != null">#{unionId},</if>
|
|
|
+ <if test="maOpenId != null">#{maOpenId},</if>
|
|
|
+ <if test="mpOpenId != null">#{mpOpenId},</if>
|
|
|
+ <if test="bizType != null">#{bizType},</if>
|
|
|
+ <if test="companyId != null">#{companyId},</if>
|
|
|
+ <if test="companyUserId != null">#{companyUserId},</if>
|
|
|
+ <if test="bindUserId != null">#{bindUserId},</if>
|
|
|
+ <if test="externalContactId != null">#{externalContactId},</if>
|
|
|
+ <if test="userCompanyUserId != null">#{userCompanyUserId},</if>
|
|
|
+ <if test="type != null">#{type},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="updateTime != null">#{updateTime},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <update id="updateFsUserBindWx" parameterType="FsUserBindWx">
|
|
|
+ update fs_user_bind_wx
|
|
|
+ <trim prefix="SET" suffixOverrides=",">
|
|
|
+ <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
|
|
|
+ <if test="unionId != null">union_id = #{unionId},</if>
|
|
|
+ <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
|
|
|
+ <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
|
|
|
+ <if test="bizType != null">biz_type = #{bizType},</if>
|
|
|
+ <if test="companyId != null">company_id = #{companyId},</if>
|
|
|
+ <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
|
|
|
+ <if test="bindUserId != null">bind_user_id = #{bindUserId},</if>
|
|
|
+ <if test="externalContactId != null">external_contact_id = #{externalContactId},</if>
|
|
|
+ <if test="userCompanyUserId != null">user_company_user_id = #{userCompanyUserId},</if>
|
|
|
+ <if test="type != null">type = #{type},</if>
|
|
|
+ <if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
+ </trim>
|
|
|
+ where id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <delete id="deleteFsUserBindWxById" parameterType="Long">
|
|
|
+ delete from fs_user_bind_wx where id = #{id}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <delete id="deleteFsUserBindWxByIds" parameterType="Long">
|
|
|
+ delete from fs_user_bind_wx where id in
|
|
|
+ <foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <select id="selectUnassignedUserList" parameterType="com.fs.his.domain.vo.UnassignedUserQuery" resultType="com.fs.his.domain.vo.UnassignedUserVO">
|
|
|
+ SELECT
|
|
|
+ fu.user_id AS userId,
|
|
|
+ fu.nick_name AS nickName,
|
|
|
+ fu.avatar AS avatar,
|
|
|
+ fu.phone AS phone,
|
|
|
+ fu.create_time AS createTime,
|
|
|
+ bx.id AS bindId,
|
|
|
+ IF(bx.id IS NOT NULL, 1, 0) AS bindStatus
|
|
|
+ FROM
|
|
|
+ fs_user fu
|
|
|
+ LEFT JOIN fs_user_bind_wx bx ON fu.user_id = bx.fs_user_id
|
|
|
+ WHERE
|
|
|
+ fu.biz_type = 1
|
|
|
+ AND fu.phone IS NOT NULL
|
|
|
+ AND fu.phone != ''
|
|
|
+ AND fu.union_id IS NULL
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND fu.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <if test="nickName != null and nickName != ''">
|
|
|
+ AND fu.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="phoneMk != null and phoneMk != ''">
|
|
|
+ AND fu.phone = #{phoneMk}
|
|
|
+ </if>
|
|
|
+ <if test="phone != null and phone != ''">
|
|
|
+ AND fu.phone LIKE CONCAT('%', #{phone}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="bindStatus != null and bindStatus != ''">
|
|
|
+ <choose>
|
|
|
+ <when test="bindStatus == 0">
|
|
|
+ AND bx.id IS NULL
|
|
|
+ </when>
|
|
|
+ <when test="bindStatus == 1">
|
|
|
+ AND bx.id IS NOT NULL
|
|
|
+ </when>
|
|
|
+ </choose>
|
|
|
+ </if>
|
|
|
+ group by fu.user_id
|
|
|
+ ORDER BY fu.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectBoundUserIds" resultType="java.lang.Long">
|
|
|
+ SELECT fs_user_id FROM fs_user_bind_wx
|
|
|
+ WHERE fs_user_id IN
|
|
|
+ <foreach item="userId" collection="userIds" open="(" separator="," close=")">
|
|
|
+ #{userId}
|
|
|
+ </foreach>
|
|
|
+ AND company_id = #{companyId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="batchInsertBindIgnore">
|
|
|
+ INSERT IGNORE INTO fs_user_bind_wx (fs_user_id, company_id, create_time)
|
|
|
+ VALUES
|
|
|
+ <foreach item="item" collection="list" separator=",">
|
|
|
+ (#{item.fsUserId}, #{item.companyId}, NOW())
|
|
|
+ </foreach>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <select id="selectBindListByFsUserId" parameterType="Long" resultType="com.fs.his.domain.vo.BindListVO">
|
|
|
+ SELECT
|
|
|
+ bx.id AS id,
|
|
|
+ bx.fs_user_id AS fsUserId,
|
|
|
+ bx.company_id AS companyId,
|
|
|
+ bx.biz_type AS bizType,
|
|
|
+ bx.create_time AS createTime,
|
|
|
+ c.company_name AS companyName,
|
|
|
+ bx.company_user_id AS companyUserId,
|
|
|
+ cu.nick_name AS companyUserName,
|
|
|
+ cu.user_name AS companyUserAccount,
|
|
|
+ bx.type AS type,
|
|
|
+ bx.bind_user_id AS bindUserId,
|
|
|
+ bx.external_contact_id AS externalContactId,
|
|
|
+ ec.name AS externalContactName,
|
|
|
+ ec.avatar AS externalContactAvatar,
|
|
|
+ fucu.project_id AS projectId
|
|
|
+ FROM fs_user_bind_wx bx
|
|
|
+ LEFT JOIN company c ON bx.company_id = c.company_id
|
|
|
+ LEFT JOIN company_user cu ON bx.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN qw_external_contact ec ON bx.external_contact_id = ec.id
|
|
|
+ LEFT JOIN fs_user_company_user fucu ON bx.user_company_user_id = fucu.id
|
|
|
+ WHERE bx.fs_user_id = #{fsUserId}
|
|
|
+ ORDER BY bx.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectUserDetailByFsUserId" parameterType="Long" resultType="com.fs.his.domain.vo.UserDetailVO">
|
|
|
+ SELECT
|
|
|
+ user_id AS userId,
|
|
|
+ nick_name AS nickName,
|
|
|
+ avatar AS avatar,
|
|
|
+ phone AS phone,
|
|
|
+ create_time AS createTime,
|
|
|
+ sex AS sex
|
|
|
+ FROM fs_user
|
|
|
+ WHERE user_id = #{fsUserId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectCompanyBindUserList" parameterType="com.fs.his.domain.vo.CompanyBindUserQuery" resultType="com.fs.his.domain.vo.CompanyBindUserVO">
|
|
|
+ SELECT
|
|
|
+ bx.id AS id,
|
|
|
+ fu.user_id AS userId,
|
|
|
+ fu.nick_name AS nickName,
|
|
|
+ fu.avatar AS avatar,
|
|
|
+ fu.phone AS phone,
|
|
|
+ bx.create_time AS createTime,
|
|
|
+ bx.bind_user_id AS bindUserId,
|
|
|
+ bx.type AS type,
|
|
|
+ bx.external_contact_id AS externalContactId,
|
|
|
+ ec.name AS externalContactName,
|
|
|
+ ec.avatar AS externalContactAvatar,
|
|
|
+ bx.company_user_id AS companyUserId,
|
|
|
+ cu.nick_name AS companyUserName,
|
|
|
+ cu.user_name AS companyUserAccount,
|
|
|
+ fucu.project_id AS projectId
|
|
|
+ FROM fs_user_bind_wx bx
|
|
|
+ LEFT JOIN fs_user fu ON bx.fs_user_id = fu.user_id
|
|
|
+ LEFT JOIN qw_external_contact ec ON bx.external_contact_id = ec.id
|
|
|
+ LEFT JOIN company_user cu ON bx.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN fs_user_company_user fucu ON bx.user_company_user_id = fucu.id
|
|
|
+ WHERE 1=1
|
|
|
+ <if test="companyId != null">
|
|
|
+ AND bx.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <if test="companyUserId != null">
|
|
|
+ AND bx.company_user_id = #{companyUserId}
|
|
|
+ </if>
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND fu.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <if test="nickName != null and nickName != ''">
|
|
|
+ AND fu.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="phoneMk != null and phoneMk != ''">
|
|
|
+ AND fu.phone = #{phoneMk}
|
|
|
+ </if>
|
|
|
+ <if test="bindStatus != null">
|
|
|
+ <choose>
|
|
|
+ <when test="bindStatus == 0">
|
|
|
+ AND bx.bind_user_id IS NULL
|
|
|
+ </when>
|
|
|
+ <when test="bindStatus == 1">
|
|
|
+ AND bx.bind_user_id IS NOT NULL
|
|
|
+ </when>
|
|
|
+ </choose>
|
|
|
+ </if>
|
|
|
+ <if test="assignStatus != null">
|
|
|
+ <choose>
|
|
|
+ <when test="assignStatus == 0">
|
|
|
+ AND bx.company_user_id IS NULL
|
|
|
+ </when>
|
|
|
+ <when test="assignStatus == 1">
|
|
|
+ AND bx.company_user_id IS NOT NULL
|
|
|
+ </when>
|
|
|
+ </choose>
|
|
|
+ </if>
|
|
|
+ ORDER BY bx.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectAssociatedUserList" parameterType="com.fs.his.domain.vo.AssociatedUserQuery" resultType="com.fs.his.domain.vo.AssociatedUserVO">
|
|
|
+ SELECT
|
|
|
+ fu.user_id AS userId,
|
|
|
+ fu.nick_name AS nickName,
|
|
|
+ fu.avatar AS avatar
|
|
|
+ FROM fs_user fu
|
|
|
+ INNER JOIN fs_user_company_user fc ON fu.user_id = fc.user_id
|
|
|
+ WHERE fu.create_time > '2026-03-01 00:00:00' AND fu.union_id IS NOT NULL
|
|
|
+ <if test="companyId != null">
|
|
|
+ AND fc.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <if test="companyUserId != null">
|
|
|
+ AND fc.company_user_id = #{companyUserId}
|
|
|
+ </if>
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND fu.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <if test="nickName != null and nickName != ''">
|
|
|
+ AND fu.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
|
|
+ </if>
|
|
|
+ ORDER BY fu.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectFsUserWxInfo" parameterType="Long" resultType="com.fs.his.domain.vo.FsUserWxInfoVO">
|
|
|
+ SELECT
|
|
|
+ user_id AS userId,
|
|
|
+ union_id AS unionId,
|
|
|
+ ma_open_id AS maOpenId,
|
|
|
+ mp_open_id AS mpOpenId
|
|
|
+ FROM fs_user
|
|
|
+ WHERE user_id = #{userId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <update id="updateBindWxUser">
|
|
|
+ UPDATE fs_user_bind_wx
|
|
|
+ SET bind_user_id = #{bindUserId},
|
|
|
+ company_user_id = #{companyUserId},
|
|
|
+ union_id = #{unionId},
|
|
|
+ ma_open_id = #{maOpenId},
|
|
|
+ mp_open_id = #{mpOpenId},
|
|
|
+ external_contact_id = #{externalContactId},
|
|
|
+ user_company_user_id = #{userCompanyUserId},
|
|
|
+ type = #{type}
|
|
|
+ WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <update id="unbindWxUser" parameterType="Long">
|
|
|
+ UPDATE fs_user_bind_wx
|
|
|
+ SET bind_user_id = NULL,
|
|
|
+ union_id = NULL,
|
|
|
+ ma_open_id = NULL,
|
|
|
+ mp_open_id = NULL,
|
|
|
+ external_contact_id = NULL,
|
|
|
+ user_company_user_id = NULL,
|
|
|
+ type = 1
|
|
|
+ WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <select id="selectBoundUserInfo" parameterType="Long" resultType="com.fs.his.domain.vo.AssociatedUserVO">
|
|
|
+ SELECT
|
|
|
+ user_id AS userId,
|
|
|
+ nick_name AS nickName,
|
|
|
+ avatar AS avatar
|
|
|
+ FROM fs_user
|
|
|
+ WHERE user_id = #{userId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectBindWxByUserIdAndCmpanyUserId" resultType="com.fs.his.domain.FsUserBindWx">
|
|
|
+ SELECT id,union_id,ma_open_id,mp_open_id FROM fs_user_bind_wx WHERE fs_user_id = #{userId} AND company_user_id = #{companyUserId} AND bind_user_id IS NOT NULL
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectExternalContactList" parameterType="com.fs.his.domain.vo.ExternalContactQuery" resultType="com.fs.his.domain.vo.ExternalContactVO">
|
|
|
+ SELECT
|
|
|
+ ec.id AS id,
|
|
|
+ ec.name AS name,
|
|
|
+ ec.avatar AS avatar,
|
|
|
+ ec.external_user_id AS externalUserId,
|
|
|
+ qc.corp_name AS corpName
|
|
|
+ FROM qw_external_contact ec
|
|
|
+ INNER JOIN qw_company qc ON ec.corp_id = qc.corp_id
|
|
|
+ WHERE ec.status != 4
|
|
|
+ <if test="companyId != null">
|
|
|
+ AND ec.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <if test="companyUserId != null">
|
|
|
+ AND ec.company_user_id = #{companyUserId}
|
|
|
+ </if>
|
|
|
+ <if test="name != null and name != ''">
|
|
|
+ AND ec.name LIKE CONCAT('%', #{name}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="corpName != null and corpName != ''">
|
|
|
+ AND qc.corp_name LIKE CONCAT('%', #{corpName}, '%')
|
|
|
+ </if>
|
|
|
+ ORDER BY ec.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectExternalContactById" parameterType="Long" resultType="com.fs.his.domain.vo.ExternalContactVO">
|
|
|
+ SELECT
|
|
|
+ id AS id,
|
|
|
+ name AS name,
|
|
|
+ avatar AS avatar,
|
|
|
+ external_user_id AS externalUserId
|
|
|
+ FROM qw_external_contact
|
|
|
+ WHERE id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <update id="batchAssignCompanyUser">
|
|
|
+ UPDATE fs_user_bind_wx
|
|
|
+ SET company_user_id = #{companyUserId}
|
|
|
+ WHERE id IN
|
|
|
+ <foreach collection="ids" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <update id="unassignCompanyUser">
|
|
|
+ UPDATE fs_user_bind_wx SET company_user_id = NULL WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+</mapper>
|