Commit c8b34494 by tyfanchz

增加数据处理

1 parent 4c079730
Showing 17 changed files with 1163 additions and 0 deletions
package cn.com.glsx.openplatform.model;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2020-12-29
*/
public class ActivationData {
private Integer id;
private String month;
private String endMonth;
private Integer customerId;
private String customer;
private Integer num;
private Byte type;
private String typeName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getEndMonth() {
return endMonth;
}
public void setEndMonth(String endMonth) {
this.endMonth = endMonth;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}
package cn.com.glsx.openplatform.model;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
/**
* 客户行为统计表
*/
public class CustomerActionStatistics {
/**
* id
*/
private Integer id;
/**
* 客户id t_platform_customer表的id
*/
private Integer customerId;
/**
* 客户名称
*/
private String customerName;
/**
* 行为类型
*/
private String type;
/**
* 统计时间
*/
private String statisticsTime;
/**
* 活跃数
*/
private Integer activeNumber;
/**
* 激活增长数
*/
private Integer activationGrowth;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStatisticsTime() {
return statisticsTime;
}
public void setStatisticsTime(String statisticsTime) {
this.statisticsTime = statisticsTime;
}
public Integer getActiveNumber() {
return activeNumber;
}
public void setActiveNumber(Integer activeNumber) {
this.activeNumber = activeNumber;
}
public Integer getActivationGrowth() {
return activationGrowth;
}
public void setActivationGrowth(Integer activationGrowth) {
this.activationGrowth = activationGrowth;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", customerId=").append(customerId);
sb.append(", customerName=").append(customerName);
sb.append(", type=").append(type);
sb.append(", statisticsTime=").append(statisticsTime);
sb.append(", activeNumber=").append(activeNumber);
sb.append(", activationGrowth=").append(activationGrowth);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
package cn.com.glsx.openplatform.model;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
/**
* 客户联网统计表
*/
public class CustomerNetworkStatistics {
/**
* id
*/
private Integer id;
/**
* 客户id t_platform_customer表的id
*/
private Integer customerId;
/**
* 客户名称
*/
private String customerName;
/**
* 类型 1月 2年
*/
private Byte type;
/**
* 统计时间
*/
private String statisticsTime;
/**
* 活跃数
*/
private Integer activeNumber;
/**
* 激活增长数
*/
private Integer activationGrowth;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
}
public String getStatisticsTime() {
return statisticsTime;
}
public void setStatisticsTime(String statisticsTime) {
this.statisticsTime = statisticsTime;
}
public Integer getActiveNumber() {
return activeNumber;
}
public void setActiveNumber(Integer activeNumber) {
this.activeNumber = activeNumber;
}
public Integer getActivationGrowth() {
return activationGrowth;
}
public void setActivationGrowth(Integer activationGrowth) {
this.activationGrowth = activationGrowth;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", customerId=").append(customerId);
sb.append(", customerName=").append(customerName);
sb.append(", type=").append(type);
sb.append(", statisticsTime=").append(statisticsTime);
sb.append(", activeNumber=").append(activeNumber);
sb.append(", activationGrowth=").append(activationGrowth);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
package cn.com.glsx.openplatform.model;
import java.util.Date;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
/**
* 设备行为明细表
*/
public class DeviceActionDetail {
/**
* id
*/
private Integer id;
/**
* 设备号
*/
private String deviceSn;
/**
* 行为类型
*/
private String type;
/**
* 创建时间
*/
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDeviceSn() {
return deviceSn;
}
public void setDeviceSn(String deviceSn) {
this.deviceSn = deviceSn;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", deviceSn=").append(deviceSn);
sb.append(", type=").append(type);
sb.append(", createTime=").append(createTime);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
package cn.com.glsx.openplatform.model;
import java.util.Date;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
/**
* 设备联网明细表
*/
public class DeviceNetworkDetail {
/**
* id
*/
private Integer id;
/**
* 设备号
*/
private String deviceSn;
/**
* 创建时间
*/
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDeviceSn() {
return deviceSn;
}
public void setDeviceSn(String deviceSn) {
this.deviceSn = deviceSn;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", deviceSn=").append(deviceSn);
sb.append(", createTime=").append(createTime);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
package cn.com.glsx.openplatform.model;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2020-12-29
*/
public class ShipmentData {
private Integer id;
private String goodsTime;
private Integer goodsNum;
private Byte type;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getGoodsTime() {
return goodsTime;
}
public void setGoodsTime(String goodsTime) {
this.goodsTime = goodsTime;
}
public Integer getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(Integer goodsNum) {
this.goodsNum = goodsNum;
}
public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
}
@Override
public String toString() {
return "ShipmentData{" +
"id=" + id +
", goodsTime='" + goodsTime + '\'' +
", goodsNum=" + goodsNum +
", type=" + type +
'}';
}
}
package cn.com.glsx.openplatform.mapper;
import java.util.List;
import cn.com.glsx.openplatform.model.ActivationData;
import cn.com.glsx.openplatform.model.ShipmentData;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2020-12-29
*/
@Mapper
public interface ActivationDataMapper {
List<ActivationData> getActivationList();
int updateDeviceActivation(@Param("data") ActivationData data,
@Param("startTimeStr") String startTimeStr,
@Param("endTimeStr") String endTimeStr, @Param("num") int num);
List<ShipmentData> getShipmentList();
}
package cn.com.glsx.openplatform.mapper;
import cn.com.glsx.openplatform.model.CustomerActionStatistics;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
@Mapper
public interface CustomerActionStatisticsMapper {
int deleteByPrimaryKey(Integer id);
int insert(CustomerActionStatistics record);
int insertOrUpdate(CustomerActionStatistics record);
int insertOrUpdateSelective(CustomerActionStatistics record);
int insertSelective(CustomerActionStatistics record);
CustomerActionStatistics selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(CustomerActionStatistics record);
int updateByPrimaryKey(CustomerActionStatistics record);
int updateBatch(List<CustomerActionStatistics> list);
int updateBatchSelective(List<CustomerActionStatistics> list);
int batchInsert(@Param("list") List<CustomerActionStatistics> list);
}
\ No newline at end of file
package cn.com.glsx.openplatform.mapper;
import cn.com.glsx.openplatform.model.CustomerNetworkStatistics;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
@Mapper
public interface CustomerNetworkStatisticsMapper {
int deleteByPrimaryKey(Integer id);
int insert(CustomerNetworkStatistics record);
int insertOrUpdate(CustomerNetworkStatistics record);
int insertOrUpdateSelective(CustomerNetworkStatistics record);
int insertSelective(CustomerNetworkStatistics record);
CustomerNetworkStatistics selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(CustomerNetworkStatistics record);
int updateByPrimaryKey(CustomerNetworkStatistics record);
int updateBatch(List<CustomerNetworkStatistics> list);
int updateBatchSelective(List<CustomerNetworkStatistics> list);
int batchInsert(@Param("list") List<CustomerNetworkStatistics> list);
}
\ No newline at end of file
package cn.com.glsx.openplatform.mapper;
import java.util.Date;
import java.util.List;
import cn.com.glsx.openplatform.model.DeviceActionDetail;
import cn.com.glsx.openplatform.model.PlatformDevice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
@Mapper
public interface DeviceActionDetailMapper {
int countByMonth(@Param("startMonth") Date startMonth, @Param("endMonth") Date endMonth);
List<PlatformDevice> selectByMonth(@Param("startMonth") Date startMonth,
@Param("endMonth") Date endMonth, @Param("count") Integer count);
int deleteByPrimaryKey(Integer id);
int insert(DeviceActionDetail record);
int insertOrUpdate(DeviceActionDetail record);
int insertOrUpdateSelective(DeviceActionDetail record);
int insertSelective(DeviceActionDetail record);
DeviceActionDetail selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(DeviceActionDetail record);
int updateByPrimaryKey(DeviceActionDetail record);
int updateBatch(List<DeviceActionDetail> list);
int updateBatchSelective(List<DeviceActionDetail> list);
int batchInsert(@Param("list") List<DeviceActionDetail> list);
}
package cn.com.glsx.openplatform.mapper;
import cn.com.glsx.openplatform.model.DeviceNetworkDetail;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2021-01-02
*/
@Mapper
public interface DeviceNetworkDetailMapper {
int deleteByPrimaryKey(Integer id);
int insert(DeviceNetworkDetail record);
int insertOrUpdate(DeviceNetworkDetail record);
int insertOrUpdateSelective(DeviceNetworkDetail record);
int insertSelective(DeviceNetworkDetail record);
DeviceNetworkDetail selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(DeviceNetworkDetail record);
int updateByPrimaryKey(DeviceNetworkDetail record);
int updateBatch(List<DeviceNetworkDetail> list);
int updateBatchSelective(List<DeviceNetworkDetail> list);
int batchInsert(@Param("list") List<DeviceNetworkDetail> list);
}
\ No newline at end of file
<?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="cn.com.glsx.openplatform.mapper.ActivationDataMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.openplatform.model.ActivationData">
<!--@mbg.generated-->
<!--@Table t_activation_data-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="month" jdbcType="VARCHAR" property="month"/>
<result column="customer_id" jdbcType="INTEGER" property="customerId"/>
<result column="customer" jdbcType="VARCHAR" property="customer"/>
<result column="num" jdbcType="INTEGER" property="num"/>
<result column="type" jdbcType="TINYINT" property="type"/>
</resultMap>
<select id="getActivationList" resultType="cn.com.glsx.openplatform.model.ActivationData">
select id, month, customer_id customerId, customer, num, type
from t_activation_data
order by month;
</select>
<update id="updateDeviceActivation">
update t_platform_device
set customer_id = #{data.customerId,jdbcType=INTEGER},
activat_time = from_unixtime(
unix_timestamp(#{data.month,jdbcType=VARCHAR}) + floor(
rand() * (
unix_timestamp(#{data.endMonth,jdbcType=VARCHAR})
- unix_timestamp(#{data.month,jdbcType=VARCHAR}) + 1
)
)
)
where customer_id is null
and create_time > #{startTimeStr,jdbcType=VARCHAR}
and create_time &lt;= #{endTimeStr,jdbcType=VARCHAR}
and device_type = #{data.typeName,jdbcType=VARCHAR}
order by rand()
limit #{num,jdbcType=INTEGER}
</update>
<select id="getShipmentList" resultType="cn.com.glsx.openplatform.model.ShipmentData">
select id, goods_time goodsTime, goods_num goodsNum, type
from t_shipment_data
</select>
</mapper>
<?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="cn.com.glsx.openplatform.mapper.DeviceNetworkDetailMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.openplatform.model.DeviceNetworkDetail">
<!--@mbg.generated-->
<!--@Table t_device_network_detail-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="device_sn" jdbcType="VARCHAR" property="deviceSn"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, device_sn, create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from t_device_network_detail
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--@mbg.generated-->
delete
from t_device_network_detail
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail"
useGeneratedKeys="true">
<!--@mbg.generated-->
<selectKey order="AFTER" keyProperty="id" resultType="integer">
select LAST_INSERT_ID()
</selectKey>
insert into t_device_network_detail (device_sn, create_time)
values (#{deviceSn,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail"
useGeneratedKeys="true">
<!--@mbg.generated-->
<selectKey order="AFTER" keyProperty="id" resultType="integer">
select LAST_INSERT_ID()
</selectKey>
insert into t_device_network_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceSn != null and deviceSn != ''">
device_sn,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceSn != null and deviceSn != ''">
#{deviceSn,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail">
<!--@mbg.generated-->
update t_device_network_detail
<set>
<if test="deviceSn != null and deviceSn != ''">
device_sn = #{deviceSn,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail">
<!--@mbg.generated-->
update t_device_network_detail
set device_sn = #{deviceSn,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateBatch" parameterType="java.util.List">
<!--@mbg.generated-->
update t_device_network_detail
<trim prefix="set" suffixOverrides=",">
<trim prefix="device_sn = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.deviceSn,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>
<update id="updateBatchSelective" parameterType="java.util.List">
<!--@mbg.generated-->
update t_device_network_detail
<trim prefix="set" suffixOverrides=",">
<trim prefix="device_sn = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.deviceSn != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.deviceSn,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.createTime != null">
when id = #{item.id,jdbcType=INTEGER}
then #{item.createTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map"
useGeneratedKeys="true">
<!--@mbg.generated-->
insert into t_device_network_detail
(device_sn, create_time)
values
<foreach collection="list" item="item" separator=",">
(#{item.deviceSn,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP})
</foreach>
</insert>
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail"
useGeneratedKeys="true">
<!--@mbg.generated-->
insert into t_device_network_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
device_sn,
create_time,
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
#{deviceSn,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP},
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
device_sn = #{deviceSn,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
</trim>
</insert>
<insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id"
parameterType="cn.com.glsx.openplatform.model.DeviceNetworkDetail"
useGeneratedKeys="true">
<!--@mbg.generated-->
insert into t_device_network_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="deviceSn != null and deviceSn != ''">
device_sn,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="deviceSn != null and deviceSn != ''">
#{deviceSn,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
<if test="deviceSn != null and deviceSn != ''">
device_sn = #{deviceSn,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
</mapper>
package cn.com.glsx.openplatform;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.com.glsx.openplatform.mapper.ActivationDataMapper;
import cn.com.glsx.openplatform.mapper.PlatformDeviceMapper;
import cn.com.glsx.openplatform.model.ActivationData;
import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.com.glsx.openplatform.model.ShipmentData;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
* @date 2020-12-29
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class)
public class GenerateFakeData {
private static final Map<Byte, String> TYPE_MAP = new HashMap<>();
static {
TYPE_MAP.put((byte) 1, "通信模组");
TYPE_MAP.put((byte) 2, "核心板");
TYPE_MAP.put((byte) 3, "PCBA");
}
@Autowired
private ActivationDataMapper activationDataMapper;
@Autowired
private PlatformDeviceMapper deviceMapper;
@Test
public void test1() {
List<ShipmentData> shipmentList = activationDataMapper.getShipmentList();
for (ShipmentData shipmentData : shipmentList) {
String goodsTime = shipmentData.getGoodsTime();
int goodsNum = shipmentData.getGoodsNum() + RandomUtil.randomInt(1000, 2000);
Byte type = shipmentData.getType();
DateTime startTime = DateUtil.parse(goodsTime, "yyyy-MM-dd");
while (goodsNum > 0) {
int serialNum = 0;
int year = startTime.getField(DateField.YEAR);
int month = startTime.getField(DateField.MONTH);
int day = startTime.getField(DateField.DAY_OF_MONTH);
startTime = startTime.setField(DateField.HOUR_OF_DAY, RandomUtil.randomInt(24))
.setField(DateField.MINUTE, RandomUtil.randomInt(60))
.setField(DateField.SECOND, RandomUtil.randomInt(60));
int currentNum = goodsNum > 5000 ? RandomUtil.randomInt(4000, 5000) : goodsNum;
for (int i = 0; i < currentNum; i++) {
String sn = String.format("%d0%02d%02d%02d%04d", type, year % 100, month, day, serialNum);
PlatformDevice record = new PlatformDevice();
record.setDeviceSn(sn);
record.setDeviceType(TYPE_MAP.get(type));
record.setStatus(1);
record.setCreateTime(startTime);
record.setUpdateTime(record.getCreateTime());
record.setCreateBy(0);
record.setUpdateBy(0);
deviceMapper.insert(record);
serialNum++;
}
goodsNum -= currentNum;
startTime = startTime.offset(DateField.DAY_OF_MONTH, -1);
}
}
}
@Test
public void dataHanlder() throws Exception {
//查询数据库
List<ActivationData> activationList = activationDataMapper.getActivationList();
for (ActivationData activationData : activationList) {
activationData.setTypeName(TYPE_MAP.get(activationData.getType()));
String month = activationData.getMonth();
activationData.setEndMonth(getCurrentMonthLastDay(month) + " 23:59:59");
//String currentMonth = month;
//根据obj中month字段获取上月第一天和最后一天
int num = activationData.getNum(); //obj中number
//int real = 0;
//int time = 1;
//do {
String startTime = getPreMonthOneDay(month, -9);
String endTime = getPreMonthLastDay(month, -1);
//currentMonth = startTime;
int j = activationDataMapper.updateDeviceActivation(activationData,
startTime + " 00:00:00",
endTime + " 23:59:59", num);
//real += j;
//time--;
//} while (real < num && time > 0);
}
}
/**
* 从当前时间获取上个月的第一天
*/
private String getPreMonthOneDay(String startDate, int num) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = getPreMonth(startDate, num);
//获取某月最小天数
int firstDay = c.getActualMinimum(Calendar.DAY_OF_MONTH);
//设置日历中月份的最小天数
c.set(Calendar.DAY_OF_MONTH, firstDay);
// 上个月第一天
String startTime = format.format(c.getTime());
return startTime;
}
/**
* 从当前时间获取上个月的最后一天
*/
private String getPreMonthLastDay(String startDate, int num) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c2 = getPreMonth(startDate, num);
int lastDay = c2.getActualMaximum(Calendar.DAY_OF_MONTH);
c2.set(Calendar.DAY_OF_MONTH, lastDay);
String endTime = format.format(c2.getTime());
return endTime;
}
private String getCurrentMonthLastDay(String month) throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date date = format.parse(month);
c.setTime(date);
int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH, lastDay);
String endTime = format.format(c.getTime());
return endTime;
}
/**
* 从当前时间"yyyy-MM-dd"格式获取上个月的时间
*/
private Calendar getPreMonth(String startDate, int num) throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date date = format.parse(startDate);
c.setTime(date);
c.add(Calendar.MONTH, num);
return c;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!