huanghongfa
2022-04-13 c7cb86db957dc7fbf6ca30270a71a43f5b31eccf
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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.panzhihua.service_community.dao.ComChangeCarModelRelationMapper">
 
    <resultMap type="com.panzhihua.service_community.entity.ComChangeCarModelRelation"
               id="ComChangeCarModelRelationMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="modelId" column="model_id" jdbcType="INTEGER"/>
        <result property="modelSpecsId" column="model_specs_id" jdbcType="INTEGER"/>
        <result property="modelSpecsChildrenId" column="model_specs_children_id" jdbcType="INTEGER"/>
    </resultMap>
 
    <!--查询单个-->
    <select id="queryById" resultType="com.panzhihua.common.model.vos.common.ComChangeCarModelRelationVo">
        select
          id, model_id, model_specs_id, model_specs_children_id
        from com_change_car_model_relation
        where id = #{id}
    </select>
 
    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultType="com.panzhihua.common.model.vos.common.ComChangeCarModelRelationVo">
        select
        id, model_id, model_specs_id, model_specs_children_id
        from com_change_car_model_relation
        <where>
            <if test="dto.id != null">
                and id = #{dto.id}
            </if>
            <if test="dto.modelId != null">
                and model_id = #{dto.modelId}
            </if>
            <if test="dto.modelSpecsId != null">
                and model_specs_id = #{dto.modelSpecsId}
            </if>
            <if test="dto.modelSpecsChildrenId != null">
                and model_specs_children_id = #{dto.modelSpecsChildrenId}
            </if>
        </where>
        order by create_at desc
    </select>
 
    <!--查询所有数据-->
    <select id="queryAllByList" resultType="com.panzhihua.common.model.vos.common.ComChangeCarModelRelationVo">
        select
        id, model_id, model_specs_id, model_specs_children_id
        from com_change_car_model_relation
        <where>
            <if test="dto.id != null">
                and id = #{dto.id}
            </if>
            <if test="dto.modelId != null">
                and model_id = #{dto.modelId}
            </if>
            <if test="dto.modelSpecsId != null">
                and model_specs_id = #{dto.modelSpecsId}
            </if>
            <if test="dto.modelSpecsChildrenId != null">
                and model_specs_children_id = #{dto.modelSpecsChildrenId}
            </if>
        </where>
        order by create_at desc
    </select>
 
    <select id="queryAllByModelId" resultType="com.panzhihua.common.model.vos.common.ComChangeCarModelRelationVo">
        SELECT
            cccmr.id,
            cccmr.model_id,
            cccmr.model_specs_id,
            cccmr.model_specs_children_id,
            cccm.`name` as modelName,
            cccm.`min_price` as minPrice,
            cccm.`images`,
            cccb.`name` as brandName,
            cccms.`name` as specsName,
            cccmsc.`name` as specsChildrenName
        FROM
            com_change_car_model_relation as cccmr
            left join com_change_car_model as cccm on cccm.id = cccmr.model_id
            left join com_change_car_model_specs as cccms on cccms.id = cccmr.model_specs_id
            left join com_change_car_model_specs_children as cccmsc on cccmsc.id = cccmr.model_specs_children_id
            left join com_change_car_brand as cccb on cccb.id = cccm.brand_id
        where cccmr.model_id = #{modelId}
    </select>
 
    <select id="queryAllByAppletsLimit" resultType="com.panzhihua.common.model.vos.common.ComChangeCarModelRelationVo">
        SELECT
            cccmr.id,
            cccmr.model_id,
            cccmr.model_specs_id,
            cccmr.model_specs_children_id,
            cccm.`name` as modelName,
            cccm.`min_price` as minPrice,
            cccm.`images`,
            cccb.`name` as brandName,
            cccms.`name` as specsName,
            cccmsc.`name` as specsChildrenName
        FROM
            com_change_car_model_relation as cccmr
            left join com_change_car_model as cccm on cccm.id = cccmr.model_id
            left join com_change_car_model_specs as cccms on cccms.id = cccmr.model_specs_id
            left join com_change_car_model_specs_children as cccmsc on cccmsc.id = cccmr.model_specs_children_id
            left join com_change_car_brand as cccb on cccb.id = cccm.brand_id
        <where>
            <if test="dto.brandIds != null and dto.brandIds.size > 0">
                and cccm.brand_id in
                <foreach collection='dto.brandIds' item='id' index='index' open='(' close=')' separator=',' >
                    #{id}
                </foreach>
            </if>
            <if test="dto.specsChildrenIds != null and dto.specsChildrenIds.size > 0">
                and cccmr.model_specs_children_id in
                <foreach collection='dto.specsChildrenIds' item='id' index='index' open='(' close=')' separator=',' >
                    #{id}
                </foreach>
            </if>
            <if test="dto.keyWord != null and dto.keyWord !=''">
                and cccm.`name` like concat('%',#{dto.keyWord},'%')
            </if>
        </where>
        <if test="dto.priceSort != null and dto.priceSort == 1">
            order by cccm.`min_price` asc
        </if>
        <if test="dto.priceSort != null and dto.priceSort == 2">
            order by cccm.`min_price` desc
        </if>
    </select>
 
</mapper>