UserCompanyMapper.xml 1.76 KB
<?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.huaheng.pc.system.user.mapper.UserCompanyMapper">

	<select id="selectListEntityByEqual" resultType="com.huaheng.pc.system.user.domain.UserCompany">
        SELECT sc.id, sc.userId, sc.companyId, sc.companyCode, c.name
        FROM sys_user_company sc
        inner join company c on c.id = sc.companyId
        <where>
            <if test="id != null">
                AND sc.id = #{id}
            </if>
            <if test="userId != null">
                AND sc.userId = #{userId}
            </if>
            <if test="companyId != null">
                AND sc.companyId = #{companyId}
            </if>
            <if test="companyCode != null">
                AND sc.companyCode = #{companyCode}
            </if>
        </where>
	</select>

	<select id="countUserCompanyById" resultType="java.lang.Integer">
	    select count(1) from sys_user_company where companyId=#{companyId}
	</select>

	<insert id="batchUserCompany">
		insert into sys_user_company(userId, companyId) values
		<foreach item="item" index="index" collection="list" separator=",">
			(#{item.userId},#{item.companyId})
		</foreach>
	</insert>

	<delete id="deleteUserCompanyByUserId" >
		delete from sys_user_company where id in
	   (select a.id from (SELECT uc.id from sys_user_company uc
		left join company c on uc.companyId=c.id
		where uc.userId=${userId} and c.warehouseCode='${warehouseCode}') a)

	</delete>

	<delete id="deleteUserCompany" parameterType="Integer">
		delete from sys_user_company where userId in
		<foreach collection="array" item="userId" open="(" separator="," close=")">
			#{userId}
		</foreach>
	</delete>
	
</mapper>