From f72306be34e0f859b5ab08df32c4a41e4eaa92eb Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期三, 16 十月 2024 11:30:46 +0800
Subject: [PATCH] 添加每天完成设备数量统计定时任务

---
 pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml              |  126 +++++++++++++++++++++++++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java |   29 +++++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java           |   20 +++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java      |   49 +++++++++
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java          |   26 +++++
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java       |    6 
 6 files changed, 252 insertions(+), 4 deletions(-)

diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java
new file mode 100644
index 0000000..2d92cf6
--- /dev/null
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java
@@ -0,0 +1,29 @@
+package com.dy.pmsGlobal.daoOth;
+
+import com.dy.pmsGlobal.pojoOth.OthStatisticDevice;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface OthStatisticDeviceMapper {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(OthStatisticDevice record);
+
+    int insertSelective(OthStatisticDevice record);
+
+    OthStatisticDevice selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(OthStatisticDevice record);
+
+    int updateByPrimaryKey(OthStatisticDevice record);
+
+    /**
+     * 鏌ヨ鏈�澶ф棩鏈�+1,涓虹┖鍒欐煡璇㈣澶囨渶鏂扮姸鎬佽〃鐨勬渶灏忔棩鏈�,閮戒负绌鸿繑鍥炲綋鍓嶆棩鏈�
+     *
+     * @return
+     */
+    String selectMaxDate();
+
+    void insertBatch(@Param("maxDate") String maxDate);
+}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java
index 5b14996..361b274 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java
@@ -1,19 +1,34 @@
 package com.dy.pmsGlobal.pojoOth;
 
-import com.baomidou.mybatisplus.annotation.TableField;import java.util.Date;
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.*;
+
+import java.util.Date;
 
 /**
  * 鏂囦欢涓婁紶涓嬭浇鐢� 琛�
  */
+@TableName(value="oth_file_manage", autoResultMap = true)
+@Data
+@Builder
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
 public class OthFileManage {
 
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
     public Long id;
-
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
     public Long userId;
 
     /**
      * 鏂囦欢缂栧彿
      */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
     public Long fileId;
 
     /**
@@ -24,6 +39,7 @@
     /**
      * 涓婁紶鏃堕棿
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     public Date dt;
 
     @TableField(exist = false)
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java
new file mode 100644
index 0000000..cb3259a
--- /dev/null
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java
@@ -0,0 +1,49 @@
+package com.dy.pmsGlobal.pojoOth;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.*;
+
+import java.util.Date;
+
+@TableName(value="oth_statistic_device", autoResultMap = true)
+@Data
+@Builder
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
+public class OthStatisticDevice {
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    public Long id;
+
+    /**
+     * 缁熻鏃ユ湡
+     */
+    public String statisticDate;
+
+    /**
+     * 璁″垝缂栧彿
+     */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    public Long planId;
+
+    /**
+     * 浜у搧缂栧彿
+     */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    public Long proId;
+
+    /**
+     * 缁熻鏁�
+     */
+    public Integer number;
+
+    /**
+     * 鍒涘缓鏃堕棿
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    public Date dt;
+
+}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml
new file mode 100644
index 0000000..c25f811
--- /dev/null
+++ b/pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml
@@ -0,0 +1,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>
\ No newline at end of file
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java
index 29807fa..b5a9db9 100644
--- a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java
@@ -1,10 +1,9 @@
 package com.dy.pmsOther.config;
 
 import com.dy.common.schedulerTask.SchedulerTaskSupport;
-import com.dy.pmsGlobal.daoSta.StaDeviceProductionLogPastMapper;
+import com.dy.pmsOther.task.DeviceCountTask;
 import com.dy.pmsOther.task.WorkloadTask;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
@@ -16,5 +15,8 @@
         //姣忓ぉ浜哄憳宸ヤ綔閲忕粺璁�
         SchedulerTaskSupport.addDailyJob("workloadTask", "station", WorkloadTask.class,
                 null, 0, 5);
+        //姣忓ぉ瀹屾垚璁惧鏁伴噺缁熻
+        SchedulerTaskSupport.addDailyJob("deviceCountTask", "station", DeviceCountTask.class,
+                null,23,50);
     }
 }
\ No newline at end of file
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java
new file mode 100644
index 0000000..1d3720a
--- /dev/null
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java
@@ -0,0 +1,26 @@
+package com.dy.pmsOther.task;
+
+import com.dy.common.schedulerTask.TaskJob;
+import com.dy.common.springUtil.SpringContextUtil;
+import com.dy.pmsGlobal.daoOth.OthStatisticDeviceMapper;
+import com.dy.pmsGlobal.daoOth.OthStatisticWorkloadMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.transaction.annotation.Transactional;
+
+@Slf4j
+public class DeviceCountTask extends TaskJob {
+
+    @Override
+    @Transactional
+    public void execute(JobExecutionContext ctx) throws JobExecutionException {
+        log.info("鍚姩缁熻姣忔棩璁惧鐢熶骇鏁颁换鍔�");
+        OthStatisticWorkloadMapper  workloadMapper = SpringContextUtil.getBean(OthStatisticWorkloadMapper.class);
+        OthStatisticDeviceMapper statisticDeviceMapper = SpringContextUtil.getBean(OthStatisticDeviceMapper.class);
+        //鎵惧埌鏈�澶т竴鏉℃棩鏈熷姞1澶╅槻姝㈤噸澶嶇粺璁�
+        String maxDate = statisticDeviceMapper.selectMaxDate();
+        statisticDeviceMapper.insertBatch(maxDate);
+        log.info("缁熻姣忔棩璁惧鐢熶骇鏁颁换鍔$粨鏉�");
+    }
+}

--
Gitblit v1.8.0