yangys
2024-09-03 52ff3bda72646a532c3297e4843bc4d5aee8b949
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
<?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.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper">
    <resultMap id="BaseResultMap" type="com.qianwen.mdc.collect.entity.iotdb.DeviceState">
        <result column="workstation_id" jdbcType="BIGINT" property="workstationId"/>
        <result column="value_collect" jdbcType="BIGINT" property="valueCollect"/>
        <result column="calendar_code" jdbcType="VARCHAR" property="calendarCode"/>
        <result column="factory_year" jdbcType="INTEGER" property="factoryYear"/>
        <result column="factory_month" jdbcType="INTEGER" property="factoryMonth"/>
        <result column="factory_week" jdbcType="INTEGER" property="factoryWeek"/>
        <result column="factory_date" jdbcType="INTEGER" property="factoryDate"/>
        <result column="shift_index" jdbcType="INTEGER" property="shiftIndex"/>
        <result column="shift_time_type" jdbcType="INTEGER" property="shiftTimeType"/>
        <result column="wcs" jdbcType="INTEGER" property="wcs"/>
        <result column="rps" jdbcType="INTEGER" property="rps"/>
        <result column="is_sync" jdbcType="BOOLEAN" property="isSync"/>
        <result column="feedback_id" jdbcType="BIGINT" property="feedbackId"/>
        <result column="is_deleted" jdbcType="BOOLEAN" property="isDeleted"/>
        <result column="is_plan" jdbcType="BIGINT" property="isPlan"/>
        <result column="employee_id" jdbcType="BIGINT" property="employeeId"/>
    </resultMap>
    <!-- 
 
    <select id="getProcessingFeedbackState" resultType="org.springblade.posting.entity.tdengine.WorkstationState"
            parameterType="java.lang.Long">
        select *  FROM iot_data.super_state  WHERE workstation_id = #{workstationId} AND is_deleted != true  AND is_sync = false AND feedback_point_type != 0
    </select>
 
    <insert id="insert" parameterType="org.springblade.posting.entity.tdengine.WorkstationState">
        insert into iot_data.state_${workstationId} USING iot_data.super_state TAGS (${workstationId})
        values (#{ts}, #{valueCollect}, #{calendarCode}, #{factoryYear}, #{factoryMonth}, #{factoryWeek}, #{factoryDate},
            #{shiftIndex}, #{shiftTimeType}, #{wcs}, #{rps},#{isFixPoint},#{isSync}, #{isPlan},#{feedbackPointType},#{feedbackId},#{isDeleted}, #{employeeId})
    </insert>
 
    <insert id="batchInsert" >
        insert into
        <foreach separator=" " collection="list" item="item" index="index" >
            iot_data.state_${item.workstationId} USING iot_data.super_state TAGS (${item.workstationId}) values
             (#{item.ts}, #{item.valueCollect},#{item.calendarCode}, #{item.factoryYear}, #{item.factoryMonth}, #{item.factoryWeek}, #{item.factoryDate},
            #{item.shiftIndex}, #{item.shiftTimeType}, #{item.wcs}, #{item.rps},#{item.isFixPoint}, #{item.isSync}, #{item.isPlan},#{item.feedbackPointType},#{item.feedbackId},#{item.isDeleted}, #{item.employeeId})
        </foreach>
    </insert>
 
    <insert id="batchSave">
        insert into iot_data.state_${workstationId} USING iot_data.super_state TAGS (${workstationId}) values
        <foreach separator="," collection="list" item="item" index="index" >
            (#{item.ts}, #{item.valueCollect},#{item.calendarCode}, #{item.factoryYear}, #{item.factoryMonth}, #{item.factoryWeek}, #{item.factoryDate},
            #{item.shiftIndex}, #{item.shiftTimeType}, #{item.wcs}, #{item.rps}, #{item.isFixPoint},
             #{item.isSync}, #{item.isPlan},#{item.feedbackPointType},#{item.feedbackId},#{item.isDeleted}, #{item.employeeId})
        </foreach>
    </insert>
 
 
    <select id="getLastIsSyncNoFixPointState"
            resultType="org.springblade.posting.entity.tdengine.WorkstationState">
        select LAST_ROW(*), workstation_Id FROM iot_data.super_state  WHERE workstation_id = #{workstationId} AND is_deleted != true  AND is_sync = true and is_fix_point=false
    </select>
 
    
 
    <select id="getFirstWorkstationState" resultType="org.springblade.posting.entity.tdengine.WorkstationState"
            parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper">
        select First(*) FROM iot_data.super_state
            ${ew.customSqlSegment}
    </select>
    -->
    <sql id="all_columns">
    workstation_id,value_collect,calendar_code,factory_year,factory_month,factory_date,factory_week,shift_index,shift_time_type,wcs,rps,is_fix_point,is_sync,is_plan,feedback_point_type,feedback_id,is_deleted,employee_id
    </sql>
    <!--  resultType="com.qianwen.mdc.collect.entity.iotdb.DeviceState" -->
    <select id="lastSyncedNoFeedbackPointState" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.aggregate_state_${workstationId}
        where is_sync=true and is_fix_point=false and feedback_point_type=0 and is_deleted=false
        order by time desc limit 1
    </select>
    
    <select id="firstNotSyncedNofeedbackPointState" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.aggregate_state_${workstationId}
        where is_sync=false and is_fix_point=false and feedback_point_type=0 and is_deleted=false
        order by time asc limit 1
    </select>
    <!--  -->
     <select id="statesInTimeRange" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.state_${workstationId}
        <where>
            is_deleted=false
            <if test="timeRange.startTime != null">
                AND time &gt;= #{timeRange.startTime}
            </if>
             AND time &lt;= #{timeRange.endTime}
        </where>
        
        order by time asc
          align by device
    </select>
    
     <!-- 只能用as 和resultType的形式??? resultType="com.qianwen.mdc.collect.entity.iotdb.DeviceState"
     <select id="statesInTimeRange" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.state_${workstationId}
        <where>
            is_deleted=false
            <if test="timeRange.startTime != null">
                AND time &gt;= #{timeRange.startTime}
            </if>
             AND time &lt;= #{timeRange.endTime}
        </where>
        
        order by time asc
         align by device
    </select>-->
    <select id="fixPointCountByDate" resultType="Long">
        select count(factory_date) FROM root.f2.state_* where factory_date=#{factoryDate} and is_fix_point=true
    </select>
    
</mapper>