mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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
            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.id = #{id}
    </select>
 
    <!--查询指定行数据-->
    <select id="queryAllByLimit" 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.id != null">
                and cccmr.id = #{dto.id}
            </if>
            <if test="dto.modelId != null">
                and cccmr.model_id = #{dto.modelId}
            </if>
            <if test="dto.modelSpecsId != null">
                and cccmr.model_specs_id = #{dto.modelSpecsId}
            </if>
            <if test="dto.modelSpecsChildrenId != null">
                and cccmr.model_specs_children_id = #{dto.modelSpecsChildrenId}
            </if>
        </where>
        order by cccmr.id desc
    </select>
 
    <!--查询所有数据-->
    <select id="queryAllByList" 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.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 cccmr.id 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.ComChangeCarModelVo">
        SELECT
        cccm.`name`,
        cccm.`min_price`,
        cccm.`images`,
        cccb.`name` AS brandName,
        cccm.id
        FROM
        com_change_car_model AS cccm
        LEFT JOIN com_change_car_model_relation AS cccmr 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>
            and cccm.is_del = 2 and cccm.status = 1
            <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>
        group by cccm.id
        <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>