<?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.OthStatisticWorkloadMapper"> 
 | 
  
 | 
    <resultMap id="BaseResultMap" type="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload"> 
 | 
            <id property="id" column="id" jdbcType="BIGINT"/> 
 | 
            <result property="statisticDate" column="statistic_date" jdbcType="DATE"/> 
 | 
            <result property="userId" column="user_id" jdbcType="BIGINT"/> 
 | 
            <result property="userName" column="user_name" jdbcType="VARCHAR"/> 
 | 
            <result property="type" column="type" jdbcType="VARCHAR"/> 
 | 
            <result property="nodeContent" column="node_content" jdbcType="VARCHAR"/> 
 | 
            <result property="number" column="number" jdbcType="INTEGER"/> 
 | 
    </resultMap> 
 | 
  
 | 
    <sql id="Base_Column_List"> 
 | 
        id,statistic_date,user_id, 
 | 
        user_name,type,node_content, 
 | 
        number 
 | 
    </sql> 
 | 
  
 | 
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> 
 | 
        select 
 | 
        <include refid="Base_Column_List" /> 
 | 
        from oth_statistic_workload 
 | 
        where  id = #{id,jdbcType=BIGINT}  
 | 
    </select> 
 | 
  
 | 
    <select id="selectMaxDate" resultType="java.lang.String"> 
 | 
        SELECT COALESCE( 
 | 
                       (SELECT DATE_ADD(MAX(statistic_date), INTERVAL 1 DAY) FROM oth_statistic_workload), 
 | 
                       (SELECT DATE_FORMAT(MIN(out_time),'%Y-%m-%d') FROM sta_device_last), 
 | 
                       DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY),'%Y-%m-%d') -- 如果两个表都没有数据,返回前一天时间  无用 
 | 
                   ) AS max_date; 
 | 
    </select> 
 | 
  
 | 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> 
 | 
        delete from oth_statistic_workload 
 | 
        where  id = #{id,jdbcType=BIGINT}  
 | 
    </delete> 
 | 
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload" useGeneratedKeys="true"> 
 | 
        insert into oth_statistic_workload 
 | 
        ( id,statistic_date,user_id 
 | 
        ,user_name,type,node_content 
 | 
        ,number) 
 | 
        values (#{id,jdbcType=BIGINT},#{statisticDate,jdbcType=DATE},#{userId,jdbcType=BIGINT} 
 | 
        ,#{userName,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{nodeContent,jdbcType=VARCHAR} 
 | 
        ,#{number,jdbcType=INTEGER}) 
 | 
    </insert> 
 | 
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload" useGeneratedKeys="true"> 
 | 
        insert into oth_statistic_workload 
 | 
        <trim prefix="(" suffix=")" suffixOverrides=","> 
 | 
                <if test="id != null">id,</if> 
 | 
                <if test="statisticDate != null">statistic_date,</if> 
 | 
                <if test="userId != null">user_id,</if> 
 | 
                <if test="userName != null">user_name,</if> 
 | 
                <if test="type != null">type,</if> 
 | 
                <if test="nodeContent != null">node_content,</if> 
 | 
                <if test="number != null">number,</if> 
 | 
        </trim> 
 | 
        <trim prefix="values (" suffix=")" suffixOverrides=","> 
 | 
                <if test="id != null">#{id,jdbcType=BIGINT},</if> 
 | 
                <if test="statisticDate != null">#{statisticDate,jdbcType=DATE},</if> 
 | 
                <if test="userId != null">#{userId,jdbcType=BIGINT},</if> 
 | 
                <if test="userName != null">#{userName,jdbcType=VARCHAR},</if> 
 | 
                <if test="type != null">#{type,jdbcType=VARCHAR},</if> 
 | 
                <if test="nodeContent != null">#{nodeContent,jdbcType=VARCHAR},</if> 
 | 
                <if test="number != null">#{number,jdbcType=INTEGER},</if> 
 | 
        </trim> 
 | 
    </insert> 
 | 
    <insert id="insertBatch"> 
 | 
        INSERT INTO oth_statistic_workload 
 | 
        (statistic_date,user_id 
 | 
        ,user_name,type,node_content 
 | 
        ,number) 
 | 
         WITH  total as (select 
 | 
             DISTINCT(t.device_no) device_no,t.curr_node,t.node_content,t.number,p.pro_name, p.plan_name,u.id user_id,u.`name` user_name 
 | 
            FROM 
 | 
              (select * from sta_device_production_log_past 
 | 
               where repair_id IS NULL and out_time BETWEEN #{startDt} AND #{endDt} 
 | 
               union 
 | 
               select * from sta_device_production_log 
 | 
               where repair_id IS NULL and out_time BETWEEN #{startDt} AND #{endDt} 
 | 
               ) t 
 | 
               left join (select pap.id,pap.`name` as plan_name,pp.`name` as pro_name 
 | 
               from  pr_assembly_plan pap, plt_product pp where pap.pro_id = pp.id) p on t.plan_id = p.id 
 | 
               left JOIN ba_user u on u.id=t.updated_by) 
 | 
        select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id, user_name,'计划任务' AS type, node_content ,sum(number) as number  from total where curr_node IS NOT NULL GROUP BY user_id,user_name,node_content 
 | 
        UNION 
 | 
        select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date, user_id,  user_name,'临时任务' AS type, node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no !='' AND device_no IS NOT NULL) 
 | 
        GROUP BY user_id,user_name,node_content 
 | 
        UNION 
 | 
        select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id , user_name,'临时任务(无设备码)' AS type,node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no IS NULL OR device_no ='') 
 | 
        GROUP BY user_id,user_name,node_content; 
 | 
    </insert> 
 | 
    <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload"> 
 | 
        update oth_statistic_workload 
 | 
        <set> 
 | 
                <if test="statisticDate != null"> 
 | 
                    statistic_date = #{statisticDate,jdbcType=DATE}, 
 | 
                </if> 
 | 
                <if test="userId != null"> 
 | 
                    user_id = #{userId,jdbcType=BIGINT}, 
 | 
                </if> 
 | 
                <if test="userName != null"> 
 | 
                    user_name = #{userName,jdbcType=VARCHAR}, 
 | 
                </if> 
 | 
                <if test="type != null"> 
 | 
                    type = #{type,jdbcType=VARCHAR}, 
 | 
                </if> 
 | 
                <if test="nodeContent != null"> 
 | 
                    node_content = #{nodeContent,jdbcType=VARCHAR}, 
 | 
                </if> 
 | 
                <if test="number != null"> 
 | 
                    number = #{number,jdbcType=INTEGER}, 
 | 
                </if> 
 | 
        </set> 
 | 
        where   id = #{id,jdbcType=BIGINT}  
 | 
    </update> 
 | 
    <update id="updateByPrimaryKey" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload"> 
 | 
        update oth_statistic_workload 
 | 
        set  
 | 
            statistic_date =  #{statisticDate,jdbcType=DATE}, 
 | 
            user_id =  #{userId,jdbcType=BIGINT}, 
 | 
            user_name =  #{userName,jdbcType=VARCHAR}, 
 | 
            type =  #{type,jdbcType=VARCHAR}, 
 | 
            node_content =  #{nodeContent,jdbcType=VARCHAR}, 
 | 
            number =  #{number,jdbcType=INTEGER} 
 | 
        where   id = #{id,jdbcType=BIGINT}  
 | 
    </update> 
 | 
</mapper> 
 |