<?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 > #{maxDate}
|
GROUP BY t.plan_id,DATE_FORMAT(t.out_line_time,'%Y-%m-%d')
|
</insert>
|
</mapper>
|