Fancy
2024-10-18 3f4c3b0257ae514e2f07f554c33eb95b1ce01b05
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
<?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.dy.pmsGlobal.daoOth.OthStatisticDeviceMapper">
  <resultMap id="BaseResultMap" type="com.dy.pmsGlobal.pojoOth.OthStatisticDevice">
    <!--@mbg.generated-->
    <!--@Table oth_statistic_device-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="statistic_date" jdbcType="VARCHAR" property="statisticDate" />
    <result column="plan_id" jdbcType="BIGINT" property="planId" />
    <result column="pro_id" jdbcType="BIGINT" property="proId" />
    <result column="number" jdbcType="INTEGER" property="number" />
    <result column="dt" jdbcType="TIMESTAMP" property="dt" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, statistic_date, plan_id, pro_id, `number`, dt
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from oth_statistic_device
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from oth_statistic_device
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticDevice" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into oth_statistic_device (statistic_date, plan_id, pro_id, 
      `number`, dt)
    values (#{statisticDate,jdbcType=VARCHAR}, #{planId,jdbcType=BIGINT}, #{proId,jdbcType=BIGINT}, 
      #{number,jdbcType=INTEGER}, #{dt,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticDevice" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into oth_statistic_device
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="statisticDate != null">
        statistic_date,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
      <if test="proId != null">
        pro_id,
      </if>
      <if test="number != null">
        `number`,
      </if>
      <if test="dt != null">
        dt,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="statisticDate != null">
        #{statisticDate,jdbcType=VARCHAR},
      </if>
      <if test="planId != null">
        #{planId,jdbcType=BIGINT},
      </if>
      <if test="proId != null">
        #{proId,jdbcType=BIGINT},
      </if>
      <if test="number != null">
        #{number,jdbcType=INTEGER},
      </if>
      <if test="dt != null">
        #{dt,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticDevice">
    <!--@mbg.generated-->
    update oth_statistic_device
    <set>
      <if test="statisticDate != null">
        statistic_date = #{statisticDate,jdbcType=VARCHAR},
      </if>
      <if test="planId != null">
        plan_id = #{planId,jdbcType=BIGINT},
      </if>
      <if test="proId != null">
        pro_id = #{proId,jdbcType=BIGINT},
      </if>
      <if test="number != null">
        `number` = #{number,jdbcType=INTEGER},
      </if>
      <if test="dt != null">
        dt = #{dt,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticDevice">
    <!--@mbg.generated-->
    update oth_statistic_device
    set statistic_date = #{statisticDate,jdbcType=VARCHAR},
      plan_id = #{planId,jdbcType=BIGINT},
      pro_id = #{proId,jdbcType=BIGINT},
      `number` = #{number,jdbcType=INTEGER},
      dt = #{dt,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
  <select id="selectMaxDate" resultType="java.lang.String">
    SELECT COALESCE(
        (SELECT DATE_ADD(MAX(statistic_date), INTERVAL 1 DAY) FROM oth_statistic_device),
        (SELECT DATE_FORMAT(MIN(out_line_time),'%Y-%m-%d') FROM sta_device_last where status =2 and out_line_time is not null),
        DATE_FORMAT(NOW() ,'%Y-%m-%d') -- 如果两个表都没有数据,返回当前时间
    ) AS max_date;
  </select>
 
  <insert id="insertBatch">
    insert into oth_statistic_device (statistic_date,plan_id,pro_id,number,dt)
 
    SELECT DATE_FORMAT(t.out_line_time,'%Y-%m-%d') statistic_date,t.plan_id,plan.pro_id,count(t.device_no) number,now() dt
    from sta_device_last t
           left join pr_assembly_plan plan on t.plan_id=plan.id
    where t.status =2
      and t.out_line_time &gt; #{maxDate}
    GROUP BY t.plan_id,DATE_FORMAT(t.out_line_time,'%Y-%m-%d')
  </insert>
</mapper>