AttrNameMapper.xml
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?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>