刘小明
2024-10-16 f72306be34e0f859b5ab08df32c4a41e4eaa92eb
添加每天完成设备数量统计定时任务
4个文件已添加
2个文件已修改
256 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFileManage.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/AppStartupRunner.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticDeviceMapper.java
New file
@@ -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);
}
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)
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthStatisticDevice.java
New file
@@ -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;
}
pms-parent/pms-global/src/main/resources/mapper/OthStatisticDeviceMapper.xml
New file
@@ -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>
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);
    }
}
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/DeviceCountTask.java
New file
@@ -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("统计每日设备生产数任务结束");
    }
}