AttrNameMapper.xml 3.2 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.sibu.orderHelper.integral.web.dao.IMAttrNameDao">
	<!-- 分类属性返回 -->
	<resultMap id="attrResponse" type="com.sibu.orderHelper.integral.reponse.AttrResponse">
		<id property="attrId" column="attr_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
		<result property="categoryId" column="category_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="attrName" column="attr_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="sortIndex" column="sort_index" javaType="java.lang.Integer" jdbcType="TINYINT"/>
		<collection property="valueBeans" ofType="com.sibu.orderHelper.integral.model.AttrValueBean" column="attr_id">
			<result property="valueId" column="value_id"/>
			<result property="attrId" column="attr_id"></result>
			<result property="attrValue" column="value" javaType="java.lang.String" jdbcType="VARCHAR"/>
		</collection>
	</resultMap>
	
	<!-- 查询分类属性列表 -->
	<select id="selectAttrList" resultMap="attrResponse" parameterType="java.util.Map">
		SELECT a.attr_id,a.category_id,a.attr_name,a.sort_index,v.attr_value as value,v.value_id FROM attr_name a LEFT JOIN attr_value v
		ON a.attr_id =v.attr_id
		<if test="categoryId != null and categoryId !=''">
			where a.category_id=#{categoryId}
		</if>
	</select>
	
	<!-- 查询分类属性明细 -->
	<select id="selectAttrDetail" resultMap="attrResponse" parameterType="java.util.Map">
		SELECT a.attr_id,a.category_id,a.attr_name,a.sort_index,v.attr_value as value,v.value_id FROM attr_name a LEFT JOIN attr_value v
		ON a.attr_id =v.attr_id
		where a.attr_id =#{attrId}
	</select>
	
	
	
	<!-- 保存对象,自动生成主键ID返回-->
	<insert id="save" parameterType="com.sibu.orderHelper.integral.reponse.AttrResponse" useGeneratedKeys="true" keyProperty="attrId">
		INSERT INTO attr_name (
			category_id,attr_name,sort_index
		) VALUES (
			#{categoryId},#{attrName},#{sortIndex}
		)
	</insert>
	<!-- 修改attr对象 -->
	<update id="update" parameterType="com.sibu.orderHelper.integral.reponse.AttrResponse">
		update attr_name 
		<trim prefix="set" suffixOverrides=",">
			<if test="attrName !=null and attrName!=''">
				attr_name =#{attrName} ,
			</if>
			<if test="sortIndex !=null">
				sort_index =#{sortIndex},
			</if>
		</trim>
		 where attr_id =#{attrId};
	</update>
	
	<!-- 按ID删除对象 -->
	<delete id="delete" parameterType="java.util.Map">
		delete from attr_name where attr_id =#{attrId};
	</delete>
	<!-- 查看属性的值是否已经被引用 -->
	<select id="selectAttrRefCount" resultType="java.lang.Integer" parameterType="java.lang.Long">
		SELECT COUNT(1) FROM `attr_ref`  WHERE attr_value_id IN(
			SELECT  value_id FROM`attr_value` WHERE attr_id =#{attrId}
		)
	</select>

	<!-- 查看属性名称在该分类中是否已存在,存在了不能重复添加 -->
	<select id="selectByAttrNameAndCategoryId" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM attr_name an WHERE an.`attr_name`=#{attrName} AND an.`category_id`=#{categoryId}
	</select>

</mapper>