gdg
2020-12-23 6207311d7df3d47d27fdd78de33f49875550f52f
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
<?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.nanometer.smartlab.dao.BaseMetaDao">
  <resultMap id="BaseMeta" type="com.nanometer.smartlab.entity.BaseMeta">
    <id property="id" column="id"/>
    <result property="groupId" column="group_id"></result>
    <result property="metaKey" column="meta_key"></result>
    <result property="metaValue" column="meta_value"></result>
    <result property="orderIndex" column="order_index"></result>
    <result property="memo" column="memo"></result>
    <result property="createTime" column="create_time"></result>
    <result property="updateTime" column="update_time"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
  </resultMap>
 
  <sql id="queryWhereSql">
    <if test="groupId != null and groupId != ''">
      and group_id = #{groupId}
    </if>
    <if test="keyword != null and keyword != ''">
      and (meta_key like #{keyword} or meta_value like #{keyword})
    </if>
    <if test="metaKey != null and metaKey != ''">
      and meta_key = #{metaKey}
    </if>
    <if test="metaValue != null and metaValue != ''">
      and meta_value = #{metaValue}
    </if>
    <if test="editId != null and editId != ''">
      and id != #{editId}
    </if>
  </sql>
 
  <select id="getBaseMeta" parameterType="java.lang.String"  resultMap="BaseMeta" >
    select * from base_meta
    where id = #{id} and valid_flag = 1
  </select>
 
  <select id="getAllBaseMeta" resultMap="BaseMeta">
    select * from base_meta
    where valid_flag = 1
  </select>
 
  <select id="getBaseMetaList" parameterType="java.util.Map" resultMap="BaseMeta">
    select * from base_meta
    where valid_flag = 1
    <include refid="queryWhereSql"/>
    order by group_id asc,meta_value desc, order_index asc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
  <select id="getBaseMetaTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1) from base_meta
    where valid_flag = 1
    <include refid="queryWhereSql"/>
  </select>
 
  <insert id="insertBaseMeta" parameterType="com.nanometer.smartlab.entity.BaseMeta">
    insert into base_meta(id, group_id, meta_key, meta_value, order_index, memo, create_time, update_time, valid_flag)
    values (#{id}, #{groupId}, #{metaKey}, #{metaValue}, #{orderIndex}, #{memo}, now(), now(), 1)
  </insert>
  <update id="updateBaseMeta" parameterType="com.nanometer.smartlab.entity.BaseMeta">
    update base_meta set group_id=#{groupId}, meta_key=#{metaKey}, meta_value=#{metaValue}, order_index=#{orderIndex},
    memo=#{memo}, update_time=now(), valid_flag=#{validFlag}
    where id=#{id}
  </update>
 
  <update id="deleteBaseMeta" parameterType="java.lang.String">
    update base_meta set valid_flag=0, update_time=now()
    where id=#{id}
  </update>
 
  <update id="deleteBaseMetas" parameterType="java.util.List">
    update base_meta set valid_flag=0, update_time=now()
    where id in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
</mapper>