yeg
2026-09-29 b78295e8da96c3e5e76befeef9582ce5273dbb74
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
<?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.battery.business.mapper.TBatteryGroupFieldMapper">
 
    <resultMap type="TBatteryGroupField" id="TBatteryGroupFieldResult">
        <id property="fieldId" column="field_id" />
        <result property="fieldName" column="field_name" />
        <result property="fieldType" column="field_type" />
        <result property="status" column="status" />
        <result property="delFlag" column="del_flag" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="remark" column="remark" />
    </resultMap>
 
    <sql id="selectBatteryGroupFieldVo">
        select field_id, field_name, field_type, status, del_flag, create_by, create_time,
               update_by, update_time, remark
        from t_battery_group_field
    </sql>
 
    <select id="selectBatteryGroupFieldById" parameterType="Long" resultMap="TBatteryGroupFieldResult">
        <include refid="selectBatteryGroupFieldVo" />
        where field_id = #{fieldId}
          and del_flag = 0
    </select>
 
    <select id="selectBatteryGroupFieldList" parameterType="TBatteryGroupField" resultMap="TBatteryGroupFieldResult">
        <include refid="selectBatteryGroupFieldVo" />
        <where>
            del_flag = 0
            <if test="fieldId != null">
                and field_id = #{fieldId}
            </if>
            <if test="fieldName != null and fieldName != ''">
                and field_name like concat('%', #{fieldName}, '%')
            </if>
            <if test="beginCreateTime != null and beginCreateTime != ''">
                and create_time &gt;= #{beginCreateTime}
            </if>
            <if test="endCreateTime != null and endCreateTime != ''">
                and create_time &lt;= #{endCreateTime}
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc, field_id desc
    </select>
 
    <select id="selectBatteryGroupFieldByName" parameterType="String" resultMap="TBatteryGroupFieldResult">
        <include refid="selectBatteryGroupFieldVo" />
        where field_name = #{fieldName}
          and del_flag = 0
        limit 1
    </select>
 
    <insert id="insertBatteryGroupField" parameterType="TBatteryGroupField" useGeneratedKeys="true" keyProperty="fieldId">
        insert into t_battery_group_field
        (field_name, field_type, status, del_flag, create_by, create_time, update_by, update_time, remark)
        values
        (#{fieldName}, #{fieldType}, #{status}, #{delFlag}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark})
    </insert>
 
    <update id="updateBatteryGroupField" parameterType="TBatteryGroupField">
        update t_battery_group_field
        set field_name = #{fieldName},
            field_type = #{fieldType},
            status = #{status},
            remark = #{remark},
            update_by = #{updateBy},
            update_time = #{updateTime}
        where field_id = #{fieldId}
          and del_flag = 0
    </update>
 
    <update id="updateBatteryGroupFieldStatus" parameterType="TBatteryGroupField">
        update t_battery_group_field
        set status = #{status},
            update_by = #{updateBy},
            update_time = #{updateTime}
        where field_id = #{fieldId}
          and del_flag = 0
    </update>
 
    <update id="deleteBatteryGroupFieldById">
        update t_battery_group_field
        set del_flag = field_id,
            update_by = #{updateBy},
            update_time = sysdate()
        where field_id = #{fieldId}
          and del_flag = 0
    </update>
 
    <select id="countFieldReferences" resultType="int">
        select
            (select count(1) from t_battery_group_template_field
             where field_id = #{fieldId} and del_flag = 0)
          + (select count(1) from t_battery_group_relation_field
             where battery_group_field_id = #{fieldId} and del_flag = '0')
          + (select count(1) from t_compare_report_field_template
             where template_type = 'compare' and JSON_CONTAINS(fields_json, JSON_OBJECT('fieldDefinitionId', #{fieldId})))
          + (select count(1) from t_formation_report_field_template
             where template_type = 'formation' and JSON_CONTAINS(fields_json, JSON_OBJECT('fieldDefinitionId', #{fieldId})))
    </select>
</mapper>