Commit 2ddd2a21 by tyfanchz

增加数据生成类

1 parent 3fe033e8
...@@ -13,11 +13,6 @@ package cn.com.glsx.openplatform.model; ...@@ -13,11 +13,6 @@ package cn.com.glsx.openplatform.model;
*/ */
public class CustomerActionStatistics { public class CustomerActionStatistics {
/** /**
* 在线设备数
*/
private Integer onlineNumber;
/**
* id * id
*/ */
private Integer id; private Integer id;
...@@ -52,13 +47,10 @@ public class CustomerActionStatistics { ...@@ -52,13 +47,10 @@ public class CustomerActionStatistics {
*/ */
private Integer number; private Integer number;
public Integer getOnlineNumber() { /**
return onlineNumber; * 在线设备数
} */
private Integer onlineNumber;
public void setOnlineNumber(Integer onlineNumber) {
this.onlineNumber = onlineNumber;
}
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -116,17 +108,25 @@ public class CustomerActionStatistics { ...@@ -116,17 +108,25 @@ public class CustomerActionStatistics {
this.number = number; this.number = number;
} }
public Integer getOnlineNumber() {
return onlineNumber;
}
public void setOnlineNumber(Integer onlineNumber) {
this.onlineNumber = onlineNumber;
}
@Override @Override
public String toString() { public String toString() {
return "CustomerActionStatistics{" + return "CustomerActionStatistics{" +
"onlineNumber=" + onlineNumber + "id=" + id +
", id=" + id +
", customerId=" + customerId + ", customerId=" + customerId +
", customerName='" + customerName + '\'' + ", customerName='" + customerName + '\'' +
", deviceType='" + deviceType + '\'' + ", deviceType='" + deviceType + '\'' +
", type='" + type + '\'' + ", type='" + type + '\'' +
", statisticsTime='" + statisticsTime + '\'' + ", statisticsTime='" + statisticsTime + '\'' +
", number=" + number + ", number=" + number +
", onlineNumber=" + onlineNumber +
'}'; '}';
} }
} }
...@@ -47,6 +47,11 @@ public class CustomerNetworkStatistics { ...@@ -47,6 +47,11 @@ public class CustomerNetworkStatistics {
*/ */
private Integer onlineNumber; private Integer onlineNumber;
/**
* 联网次数
*/
private Integer onlineCount;
public Integer getId() { public Integer getId() {
return id; return id;
} }
...@@ -103,6 +108,14 @@ public class CustomerNetworkStatistics { ...@@ -103,6 +108,14 @@ public class CustomerNetworkStatistics {
this.onlineNumber = onlineNumber; this.onlineNumber = onlineNumber;
} }
public Integer getOnlineCount() {
return onlineCount;
}
public void setOnlineCount(Integer onlineCount) {
this.onlineCount = onlineCount;
}
@Override @Override
public String toString() { public String toString() {
return "CustomerNetworkStatistics{" + return "CustomerNetworkStatistics{" +
...@@ -113,6 +126,7 @@ public class CustomerNetworkStatistics { ...@@ -113,6 +126,7 @@ public class CustomerNetworkStatistics {
", type='" + type + '\'' + ", type='" + type + '\'' +
", statisticsTime='" + statisticsTime + '\'' + ", statisticsTime='" + statisticsTime + '\'' +
", onlineNumber=" + onlineNumber + ", onlineNumber=" + onlineNumber +
", onlineCount=" + onlineCount +
'}'; '}';
} }
} }
...@@ -3,7 +3,6 @@ package cn.com.glsx.openplatform.mapper; ...@@ -3,7 +3,6 @@ package cn.com.glsx.openplatform.mapper;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import cn.com.glsx.openplatform.model.ActivationData; import cn.com.glsx.openplatform.model.ActivationData;
import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.com.glsx.openplatform.model.ShipmentData; import cn.com.glsx.openplatform.model.ShipmentData;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -17,7 +16,7 @@ import org.apache.ibatis.annotations.Param; ...@@ -17,7 +16,7 @@ import org.apache.ibatis.annotations.Param;
*/ */
@Mapper @Mapper
public interface ActivationDataMapper { public interface ActivationDataMapper {
List<ActivationData> getActivationList(); List<ActivationData> selectActivationList();
int countByDate(@Param("startDate") Date startDate, @Param("endDate") Date endDate); int countByDate(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
...@@ -28,8 +27,4 @@ public interface ActivationDataMapper { ...@@ -28,8 +27,4 @@ public interface ActivationDataMapper {
List<String> selectDeviceTypeList(); List<String> selectDeviceTypeList();
List<ShipmentData> selectShipmentByType(@Param("deviceType") String deviceType); List<ShipmentData> selectShipmentByType(@Param("deviceType") String deviceType);
int updatePlatformDeviceActivation(@Param("device") PlatformDevice device,
@Param("startTime") Date startTime, @Param("endTime") Date endTime,
@Param("count") int count);
} }
...@@ -3,6 +3,7 @@ package cn.com.glsx.openplatform.mapper; ...@@ -3,6 +3,7 @@ package cn.com.glsx.openplatform.mapper;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import cn.com.glsx.openplatform.model.CustomerActionStatistics; import cn.com.glsx.openplatform.model.CustomerActionStatistics;
import cn.com.glsx.openplatform.model.DeviceNetworkDetail;
import cn.com.glsx.openplatform.model.PlatformDevice; import cn.com.glsx.openplatform.model.PlatformDevice;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -19,12 +20,17 @@ import org.apache.ibatis.annotations.Param; ...@@ -19,12 +20,17 @@ import org.apache.ibatis.annotations.Param;
public interface CustomerActionStatisticsMapper { public interface CustomerActionStatisticsMapper {
List<String> selectMonthList(); List<String> selectMonthList();
List<PlatformDevice> selectPlatformDevice(
@Param("statistics") CustomerActionStatistics statistics,
@Param("endDate") Date endDate);
List<DeviceNetworkDetail> selectDeviceFromDeviceNetworkDetail(
@Param("customerId") Integer customerId, @Param("endDate") Date endDate);
List<CustomerActionStatistics> selectByMonth(@Param("month") String month); List<CustomerActionStatistics> selectByMonth(@Param("month") String month);
Integer selectOnlineNumber(CustomerActionStatistics actionStatistics); Integer selectOnlineNumber(CustomerActionStatistics actionStatistics);
List<CustomerActionStatistics> selectByType(@Param("type") String type);
List<PlatformDevice> selectDeviceList( List<PlatformDevice> selectDeviceList(
@Param("actionStatistics") CustomerActionStatistics actionStatistics, @Param("actionStatistics") CustomerActionStatistics actionStatistics,
@Param("endDate") Date endDate, @Param("count") Integer count); @Param("endDate") Date endDate, @Param("count") Integer count);
......
...@@ -3,6 +3,7 @@ package cn.com.glsx.openplatform.mapper; ...@@ -3,6 +3,7 @@ package cn.com.glsx.openplatform.mapper;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import cn.com.glsx.openplatform.model.CustomerNetworkStatistics; import cn.com.glsx.openplatform.model.CustomerNetworkStatistics;
import cn.com.glsx.openplatform.model.PlatformDevice;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -16,11 +17,22 @@ import org.apache.ibatis.annotations.Param; ...@@ -16,11 +17,22 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface CustomerNetworkStatisticsMapper { public interface CustomerNetworkStatisticsMapper {
List<String> selectMonthList();
List<CustomerNetworkStatistics> selectByMonth(@Param("month") String month);
List<PlatformDevice> selectPlatformDevice(
@Param("statistics") CustomerNetworkStatistics statistics,
@Param("endDate") Date endDate);
List<CustomerNetworkStatistics> selectByDate(@Param("startDate") String startDate, List<CustomerNetworkStatistics> selectByDate(@Param("startDate") String startDate,
@Param("endDate") String endDate); @Param("endDate") String endDate);
List<CustomerNetworkStatistics> selectFromDeviceNetworkByDate(@Param("startDate") Date startDate, //List<CustomerNetworkStatistics> selectFromDeviceNetworkByDate(
@Param("endDate") Date endDate); // @Param("startDate") Date startDate,
// @Param("endDate") Date endDate);
List<CustomerNetworkStatistics> selectFromCustomerDeviceStatistics();
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<result column="type" jdbcType="TINYINT" property="type"/> <result column="type" jdbcType="TINYINT" property="type"/>
</resultMap> </resultMap>
<select id="getActivationList" resultType="cn.com.glsx.openplatform.model.ActivationData"> <select id="selectActivationList" resultType="cn.com.glsx.openplatform.model.ActivationData">
select id, month, customer_id customerId, customer, num, type select id, month, customer_id customerId, customer, num, type
from t_activation_data from t_activation_data
order by month; order by month;
...@@ -66,16 +66,4 @@ ...@@ -66,16 +66,4 @@
</if> </if>
</where> </where>
</select> </select>
<update id="updatePlatformDeviceActivation">
update t_platform_device
set activat_time = from_unixtime(
#{startTime,jdbcType=TIMESTAMP}
+ floor(rand() * (#{endTime,jdbcType=TIMESTAMP} - #{startTime,jdbcType=TIMESTAMP}))
)
where customer_id = #{device.customerId,jdbcType=INTEGER}
and device_type = #{device.deviceType,jdbcType=VARCHAR}
order by rand()
limit #{count}
</update>
</mapper> </mapper>
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
<result column="type" jdbcType="VARCHAR" property="type"/> <result column="type" jdbcType="VARCHAR" property="type"/>
<result column="statistics_time" jdbcType="VARCHAR" property="statisticsTime"/> <result column="statistics_time" jdbcType="VARCHAR" property="statisticsTime"/>
<result column="number" jdbcType="INTEGER" property="number"/> <result column="number" jdbcType="INTEGER" property="number"/>
<result column="online_number" jdbcType="INTEGER" property="onlineNumber"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, customer_id, customer_name, device_type, `type`, statistics_time, number id, customer_id, customer_name, device_type, `type`, statistics_time, number, online_number
</sql> </sql>
<select id="selectMonthList" resultType="java.lang.String"> <select id="selectMonthList" resultType="java.lang.String">
...@@ -24,8 +25,40 @@ ...@@ -24,8 +25,40 @@
from t_customer_action_statistics from t_customer_action_statistics
</select> </select>
<select id="selectPlatformDevice" resultType="cn.com.glsx.openplatform.model.PlatformDevice">
select id, device_sn deviceSn, device_type deviceType, version, customer_id customerId,
user_id, activat_time activatTime, status, create_time createTime
from t_platform_device
<where>
<if test="statistics.customerId != null">
and customer_id = #{statistics.customerId,jdbcType=INTEGER}
</if>
<if test="endDate != null">
and activat_time &lt; #{endDate,jdbcType=TIMESTAMP}
</if>
</where>
order by rand()
</select>
<select id="selectDeviceFromDeviceNetworkDetail"
resultType="cn.com.glsx.openplatform.model.DeviceNetworkDetail">
select dnd.device_sn deviceSn, dnd.create_time creatreTime
from t_device_network_detail dnd
left join t_platform_device pd on pd.device_sn = dnd.device_sn
<where>
<if test="customerId != null">
pd.customer_id = #{customerId,jdbcType=INTEGER}
</if>
<if test="endDate != null">
and dnd.create_time &lt; #{endDate,jdbcType=TIMESTAMP}
</if>
</where>
order by rand()
</select>
<select id="selectByMonth" resultMap="BaseResultMap"> <select id="selectByMonth" resultMap="BaseResultMap">
select id, customer_id, customer_name, device_type, type, statistics_time, number select id, customer_id, customer_name, device_type, type, statistics_time, number,
online_number
from t_customer_action_statistics from t_customer_action_statistics
<where> <where>
<if test="month != null and month != ''"> <if test="month != null and month != ''">
...@@ -48,16 +81,6 @@ ...@@ -48,16 +81,6 @@
group by customer_id, statistics_time group by customer_id, statistics_time
</select> </select>
<select id="selectByType" resultMap="BaseResultMap">
select id, customer_id, customer_name, device_type, type, statistics_time, number
from t_customer_action_statistics
<where>
<if test="type != null and type != ''">
and type = #{type,jdbcType=VARCHAR}
</if>
</where>
</select>
<select id="selectDeviceList" <select id="selectDeviceList"
resultType="cn.com.glsx.openplatform.model.PlatformDevice"> resultType="cn.com.glsx.openplatform.model.PlatformDevice">
select id, device_sn deviceSn, device_type deviceType select id, device_sn deviceSn, device_type deviceType
......
...@@ -12,45 +12,90 @@ ...@@ -12,45 +12,90 @@
<result column="type" jdbcType="VARCHAR" property="type"/> <result column="type" jdbcType="VARCHAR" property="type"/>
<result column="statistics_time" jdbcType="VARCHAR" property="statisticsTime"/> <result column="statistics_time" jdbcType="VARCHAR" property="statisticsTime"/>
<result column="online_number" jdbcType="INTEGER" property="onlineNumber"/> <result column="online_number" jdbcType="INTEGER" property="onlineNumber"/>
<result column="online_count" jdbcType="INTEGER" property="onlineCount"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, customer_id, customer_name, device_type, `type`, statistics_time, online_number id, customer_id, customer_name, device_type, `type`, statistics_time, online_number, online_count
</sql> </sql>
<select id="selectByDate" resultMap="BaseResultMap"> <select id="selectMonthList" resultType="java.lang.String">
select id, customer_id, customer_name, device_type, statistics_time, online_number select distinct statistics_time
from t_customer_device_statistics_new_doing_copy2 cns from t_customer_network_statistics
</select>
<select id="selectByMonth" resultMap="BaseResultMap">
select id, customer_id, customer_name, device_type, statistics_time, online_number,
online_count
from t_customer_network_statistics cns
<where> <where>
<if test="startDate != null"> <if test="month != null and month != ''">
and statistics_time >= #{startDate,jdbcType=VARCHAR} and statistics_time = #{month,jdbcType=VARCHAR}
</if>
</where>
</select>
<select id="selectPlatformDevice"
resultType="cn.com.glsx.openplatform.model.PlatformDevice">
select id, device_sn deviceSn, device_type deviceType, version version,
customer_id customerId, user_id userId, activat_time activatTime,
create_time createTime
from t_platform_device
<where>
<if test="statistics.customerId != null">
and customer_id = #{statistics.customerId,jdbcType=INTEGER}
</if> </if>
<if test="endDate != null"> <if test="endDate != null">
and statistics_time &lt; #{endDate,jdbcType=VARCHAR} and activat_time &lt; #{endDate,jdbcType=TIMESTAMP}
</if> </if>
and online_number > 0
</where> </where>
order by rand()
limit #{statistics.onlineNumber,jdbcType=INTEGER}
</select> </select>
<select id="selectFromDeviceNetworkByDate" resultMap="BaseResultMap"> <select id="selectByDate" resultMap="BaseResultMap">
select pd.customer_id customerId, pc.customer_name customerName, select id, customer_id, customer_name, device_type, statistics_time, online_number,
date_format(dnd.create_time, '%Y-%m') statisticsTime, online_count
count(pd.device_sn) onlineNumber from t_customer_network_statistics cns
from t_device_network_detail dnd
left join t_platform_device pd on pd.device_sn = dnd.device_sn
left join t_platform_customer pc on pc.id = pd.customer_id
<where> <where>
<if test="startDate != null"> <if test="startDate != null">
and dnd.create_time >= #{startDate,jdbcType=TIMESTAMP} and statistics_time >= #{startDate,jdbcType=VARCHAR}
</if> </if>
<if test="endDate != null"> <if test="endDate != null">
and dnd.create_time &lt; #{endDate,jdbcType=TIMESTAMP} and statistics_time &lt; #{endDate,jdbcType=VARCHAR}
</if> </if>
</where> </where>
group by pd.customer_id, statisticsTime
</select> </select>
<!--<select id="selectFromDeviceNetworkByDate" resultMap="BaseResultMap">-->
<!-- select pd.customer_id customerId, pc.customer_name customerName,-->
<!-- date_format(dnd.create_time, '%Y-%m') statisticsTime,-->
<!-- count(pd.device_sn) onlineNumber-->
<!-- from t_device_network_detail dnd-->
<!-- left join t_platform_device pd on pd.device_sn = dnd.device_sn-->
<!-- left join t_platform_customer pc on pc.id = pd.customer_id-->
<!-- <where>-->
<!-- <if test="startDate != null">-->
<!-- and dnd.create_time >= #{startDate,jdbcType=TIMESTAMP}-->
<!-- </if>-->
<!-- <if test="endDate != null">-->
<!-- and dnd.create_time &lt; #{endDate,jdbcType=TIMESTAMP}-->
<!-- </if>-->
<!-- </where>-->
<!-- group by pd.customer_id, statisticsTime-->
<!--</select>-->
<select id="selectFromCustomerDeviceStatistics" resultType="cn.com.glsx.openplatform.model.CustomerNetworkStatistics">
select customer_id customerId, customer_name customerName, device_type deviceType,
statistics_time statisticsTime, sum(online_number) onlineNumber,
sum(online_device_num) onlineDeviceNum
from t_customer_device_statistics
group by customer_id, statistics_time
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--@mbg.generated--> <!--@mbg.generated-->
select select
......
package cn.com.glsx.openplatform; //package cn.com.glsx.openplatform;
//
import java.util.Calendar; //import java.util.Calendar;
import java.util.Date; //import java.util.Date;
import java.util.List; //import java.util.List;
import cn.com.glsx.openplatform.mapper.CustomerNetworkStatisticsMapper; //import cn.com.glsx.openplatform.mapper.CustomerNetworkStatisticsMapper;
import cn.com.glsx.openplatform.model.CustomerNetworkStatistics; //import cn.com.glsx.openplatform.model.CustomerNetworkStatistics;
import cn.hutool.core.date.DateUtil; //import cn.hutool.core.date.DateUtil;
import org.junit.Test; //import org.junit.Test;
import org.junit.runner.RunWith; //import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; //import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
/** ///**
* <p>Description: // * <p>Description:
* <p>Project: rpc-openplatform-container // * <p>Project: rpc-openplatform-container
* // *
* @author wbh // * @author wbh
* @date 2021-01-02 // * @date 2021-01-02
*/ // */
@RunWith(SpringJUnit4ClassRunner.class) //@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class) //@SpringBootTest(classes = Main.class)
public class GenerateCustomerNetworkStatistic { //public class GenerateCustomerNetworkStatistic {
@Autowired // @Autowired
private CustomerNetworkStatisticsMapper customerNetworkStatisticsMapper; // private CustomerNetworkStatisticsMapper customerNetworkStatisticsMapper;
//
@Test // @Test
public void generateData() { // public void generateData() {
Date startDate = DateUtil.parse("2019-01-01", "yyyy-MM-dd"); // Date startDate = DateUtil.parse("2019-01-01", "yyyy-MM-dd");
Date endDate = DateUtil.parse("2021-01-01", "yyyy-MM-dd"); // Date endDate = DateUtil.parse("2021-01-01", "yyyy-MM-dd");
Calendar calendar = Calendar.getInstance(); // Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate); // calendar.setTime(startDate);
calendar.add(Calendar.MONTH, 1); // calendar.add(Calendar.MONTH, 1);
Date currentStartDate = startDate; // Date currentStartDate = startDate;
Date currentEndDate = calendar.getTime(); // Date currentEndDate = calendar.getTime();
while (currentStartDate.before(endDate)) { // while (currentStartDate.before(endDate)) {
List<CustomerNetworkStatistics> statisticsList = this.customerNetworkStatisticsMapper // List<CustomerNetworkStatistics> statisticsList = this.customerNetworkStatisticsMapper
.selectFromDeviceNetworkByDate(currentStartDate, currentEndDate); // .selectFromDeviceNetworkByDate(currentStartDate, currentEndDate);
if (!statisticsList.isEmpty()) { // if (!statisticsList.isEmpty()) {
this.customerNetworkStatisticsMapper.batchInsert(statisticsList); // this.customerNetworkStatisticsMapper.batchInsert(statisticsList);
} // }
currentStartDate = currentEndDate; // currentStartDate = currentEndDate;
calendar.add(Calendar.MONTH, 1); // calendar.add(Calendar.MONTH, 1);
currentEndDate = calendar.getTime(); // currentEndDate = calendar.getTime();
} // }
} // }
} //}
...@@ -12,7 +12,7 @@ import cn.com.glsx.openplatform.mapper.CustomerActionStatisticsMapper; ...@@ -12,7 +12,7 @@ import cn.com.glsx.openplatform.mapper.CustomerActionStatisticsMapper;
import cn.com.glsx.openplatform.model.CustomerActionStatistics; import cn.com.glsx.openplatform.model.CustomerActionStatistics;
import cn.com.glsx.openplatform.model.DeviceActionDetail; import cn.com.glsx.openplatform.model.DeviceActionDetail;
import cn.com.glsx.openplatform.model.PlatformDevice; import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
...@@ -39,48 +39,25 @@ public class GenerateDeviceActionDetailByCustomer { ...@@ -39,48 +39,25 @@ public class GenerateDeviceActionDetailByCustomer {
private static final Map<String, Integer[]> RAND_RANGE_MAP = new HashMap<>(); private static final Map<String, Integer[]> RAND_RANGE_MAP = new HashMap<>();
private static final Map<String, Integer> PERCENTAGE_MAP = new HashMap<>();
static { static {
RAND_RANGE_MAP.put("声控调用", new Integer[]{6, 9}); RAND_RANGE_MAP.put("声控调用", new Integer[]{6, 9});
RAND_RANGE_MAP.put("收音机使用", new Integer[]{28, 32}); RAND_RANGE_MAP.put("收音机使用", new Integer[]{28, 32});
RAND_RANGE_MAP.put("导航调用", new Integer[]{3, 6}); RAND_RANGE_MAP.put("导航调用", new Integer[]{3, 6});
RAND_RANGE_MAP.put("音乐使用", new Integer[]{14, 17}); RAND_RANGE_MAP.put("音乐使用", new Integer[]{14, 17});
RAND_RANGE_MAP.put("联网应用使用", new Integer[]{2, 5}); RAND_RANGE_MAP.put("联网应用使用", new Integer[]{2, 5});
}
//@Test PERCENTAGE_MAP.put("声控调用", 40);
//public void generateDeviceActionDetail() { PERCENTAGE_MAP.put("收音机使用", 70);
// this.initDeviceActionDetailWriter(null); PERCENTAGE_MAP.put("导航调用", 50);
// PERCENTAGE_MAP.put("音乐使用", 70);
// List<CustomerActionStatistics> actionStatisticsList = PERCENTAGE_MAP.put("联网应用使用", 40);
// this.customerActionStatisticsMapper.selectByType(null); }
// for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
// this.batchAddDeviceActionDetail(actionStatistics, null);
// }
//
// this.closeDeviceActionDetailWriter();
//}
//
//public void generateDeviceActionDetail2() {
// Date startDate = DateUtil.parse("2018-12", "yyyy-MM");
// Date endDate = DateUtil.parse("2021-01", "yyyy-MM");
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(startDate);
// Date currentStartDate = startDate;
// while (currentStartDate.before(endDate)) {
// this.initDeviceActionDetailWriter(startDate);
// calendar.add(Calendar.MONTH, 1);
// Date currentEndDate = calendar.getTime();
// List<CustomerActionStatistics> actionStatisticsList =
// this.customerActionStatisticsMapper.selectByMonth(
// currentStartDate, currentEndDate);
// for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
// this.batchAddDeviceActionDetail(actionStatistics, currentStartDate);
// }
// currentStartDate = currentEndDate;
// this.closeDeviceActionDetailWriter();
// }
//}
/**
* 根据客户设备行为统计表 t_customer_action_statistics 生成设备行为明细表 t_device_action_detail 数据
*/
@Test @Test
public void generateDeviceActionDetail() { public void generateDeviceActionDetail() {
List<String> monthList = this.customerActionStatisticsMapper.selectMonthList(); List<String> monthList = this.customerActionStatisticsMapper.selectMonthList();
...@@ -89,134 +66,68 @@ public class GenerateDeviceActionDetailByCustomer { ...@@ -89,134 +66,68 @@ public class GenerateDeviceActionDetailByCustomer {
List<CustomerActionStatistics> actionStatisticsList = List<CustomerActionStatistics> actionStatisticsList =
this.customerActionStatisticsMapper.selectByMonth(month); this.customerActionStatisticsMapper.selectByMonth(month);
for (CustomerActionStatistics actionStatistics : actionStatisticsList) { for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
Integer deviceCount = this.customerActionStatisticsMapper.selectOnlineNumber( String type = actionStatistics.getType();
actionStatistics); Integer number = actionStatistics.getNumber();
this.batchAddDeviceActionDetail(actionStatistics, deviceCount); Integer onlineNumber = actionStatistics.getOnlineNumber();
Date startDate = DateUtil.parse(actionStatistics.getStatisticsTime(),
"yyyy-MM");
Date endDate = DateUtil.offsetMonth(startDate, 1);
List<PlatformDevice> deviceList = this.customerActionStatisticsMapper
.selectPlatformDevice(actionStatistics, endDate);
if (!deviceList.isEmpty()) {
int percentage = PERCENTAGE_MAP.get(type);
// 取出对应比例的设备生成数据
int subCount = onlineNumber * percentage / 100;
List<PlatformDevice> subDeviceList = deviceList.subList(0, subCount);
this.addDeviceActionDetail(
subDeviceList.isEmpty() ? deviceList : subDeviceList,
type, startDate, number);
}
} }
this.closeDeviceActionDetailWriter(); this.closeDeviceActionDetailWriter();
} }
} }
private void batchAddDeviceActionDetail(CustomerActionStatistics actionStatistics, private void addDeviceActionDetail(List<PlatformDevice> deviceList,
int deviceCount) { String type, Date startDate, int count) {
Date statisticsDate = DateUtil.parse(actionStatistics.getStatisticsTime(), for (int i = 0; i < count; i++) {
"yyyy-MM"); PlatformDevice device = deviceList.get(i % deviceList.size());
DateTime endDate = DateUtil.offsetMonth(statisticsDate, 1); Calendar calendar = Calendar.getInstance();
Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate);
calendar.setTime(statisticsDate); int day = RandomUtil.randomInt(DateUtil.dayOfMonth(startDate),
// 设备行为类型 calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
String type = actionStatistics.getType(); int hour = RandomUtil.randomInt(6, 24);
// 该月需要生成数据的数量 int minute = RandomUtil.randomInt(60);
Integer neededNumber = actionStatistics.getNumber(); int second = RandomUtil.randomInt(60);
List<PlatformDevice> deviceList = this.customerActionStatisticsMapper.selectDeviceList( Date createTime = DateUtil.dateNew(startDate)
actionStatistics, endDate, deviceCount); .setField(DateField.DAY_OF_MONTH, day)
if (!deviceList.isEmpty()) { .setField(DateField.HOUR_OF_DAY, hour)
int index = 0; .setField(DateField.MINUTE, minute)
while (neededNumber > 0) { .setField(DateField.SECOND, second);
// 循环获取设备 DeviceActionDetail actionDetail = new DeviceActionDetail();
PlatformDevice device = deviceList.get(index % deviceList.size()); actionDetail.setDeviceSn(device.getDeviceSn());
index++; actionDetail.setType(type);
// 获取每种行为需要生成的随机数量 actionDetail.setCreateTime(createTime);
Integer[] randRange = RAND_RANGE_MAP.get(type); try {
int num = RandomUtil.randomInt(randRange[0], randRange[1]); String s = String.format(",\n('%s', '%s', '%s')",
int generatedNumber = num > neededNumber ? neededNumber : num; actionDetail.getDeviceSn(), actionDetail.getType(),
while (generatedNumber > 0) { DateUtil.formatDateTime(actionDetail.getCreateTime()));
this.addDeviceActionDetail(device, type, statisticsDate); this.deviceActionDetailWriter.write(s);
// 减去已经生成的数据数量 } catch (IOException e) {
generatedNumber--; e.printStackTrace();
neededNumber--;
}
} }
} }
//for (PlatformDevice device : deviceList) {
// // 获取每种行为需要生成的随机数量
// Integer[] randRange = RAND_RANGE_MAP.get(type);
// int num = RandomUtil.randomInt(randRange[0], randRange[1]);
// int generatedNumber = num > neededNumber ? neededNumber : num;
// while (generatedNumber > 0) {
// this.addDeviceActionDetail(device, type, statisticsDate);
// // 减去已经生成的数据数量
// generatedNumber--;
// neededNumber--;
// }
// if (neededNumber <= 0) {
// break;
// }
//}
//
//// 如果还没达到需要生成的数据量,则继续生成
//while (neededNumber > 0) {
// // 随机取一个设备生成行为数据
// PlatformDevice device = deviceList.get(RandomUtil.randomInt(deviceList.size()));
// this.addDeviceActionDetail(device, type, statisticsDate);
// neededNumber--;
//}
}
private void addDeviceActionDetail(PlatformDevice device, String type, Date startDate) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, RandomUtil.randomInt(maxDays) + 1);
calendar.set(Calendar.HOUR_OF_DAY, RandomUtil.randomInt(6, 24));
calendar.set(Calendar.MINUTE, RandomUtil.randomInt(60));
calendar.set(Calendar.SECOND, RandomUtil.randomInt(60));
DeviceActionDetail actionDetail = new DeviceActionDetail();
actionDetail.setDeviceSn(device.getDeviceSn());
actionDetail.setCreateTime(calendar.getTime());
actionDetail.setType(type);
try {
String s = String.format(",\n('%s', '%s', '%s')",
actionDetail.getDeviceSn(), actionDetail.getType(),
DateUtil.formatDateTime(actionDetail.getCreateTime()));
this.deviceActionDetailWriter.write(s);
} catch (IOException e) {
e.printStackTrace();
}
} }
//private void addDeviceActionDetail2(CustomerActionStatistics actionStatistics) {
// Date statisticsDate = DateUtil.parse(actionStatistics.getStatisticsTime(),
// "yyyy-MM");
// DateTime endDate = DateUtil.offsetMonth(statisticsDate, 1);
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(statisticsDate);
// int maxDays = calendar.get(Calendar.DAY_OF_MONTH);
// String type = actionStatistics.getType();
// int count = actionStatistics.getNumber() / DIVISION_MAP.get(type);
// // 查询在统计月底之前出货的设备
// List<PlatformDevice> deviceList = this.customerActionStatisticsMapper
// .selectDeviceList(actionStatistics, endDate, count);
// for (PlatformDevice device : deviceList) {
// calendar.set(Calendar.DAY_OF_MONTH, RandomUtil.randomInt(maxDays) + 1);
// calendar.set(Calendar.HOUR_OF_DAY, RandomUtil.randomInt(6, 24));
// calendar.set(Calendar.MINUTE, RandomUtil.randomInt(60));
// calendar.set(Calendar.SECOND, RandomUtil.randomInt(60));
// DeviceActionDetail actionDetail = new DeviceActionDetail();
// actionDetail.setDeviceSn(device.getDeviceSn());
// actionDetail.setCreateTime(calendar.getTime());
// actionDetail.setType(type);
// try {
// String s = String.format(",\n('%s', '%s', '%s')",
// actionDetail.getDeviceSn(), actionDetail.getType(),
// DateUtil.formatDateTime(actionDetail.getCreateTime()));
// this.deviceActionDetailWriter.write(s);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//}
private void initDeviceActionDetailWriter(String month) { private void initDeviceActionDetailWriter(String month) {
try { try {
String monthStr = month.replace("-", ""); String monthStr = month.replace("-", "");
String filename = String.format("D:/data/device-action-data-%s.sql", monthStr); String filename = String.format("D:/data/device-action-detail-%s.sql", monthStr);
this.deviceActionDetailWriter = FileUtil.getWriter(filename, this.deviceActionDetailWriter = FileUtil.getWriter(filename,
StandardCharsets.UTF_8, false); StandardCharsets.UTF_8, false);
//String headLine = String.format( String headLine = String.format(
// "insert into t_device_action_detail_%s (device_sn, type, create_time) values", "insert into t_device_action_detail_%s (device_sn, type, create_time) values",
// monthStr); monthStr);
String headLine = "insert into t_device_action_detail (device_sn, type, create_time) values";
this.deviceActionDetailWriter.write(headLine); this.deviceActionDetailWriter.write(headLine);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
package cn.com.glsx.openplatform;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
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.CustomerActionStatisticsMapper;
import cn.com.glsx.openplatform.model.CustomerActionStatistics;
import cn.com.glsx.openplatform.model.DeviceActionDetail;
import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
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 2021-01-03
*/
@Deprecated
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class)
public class GenerateDeviceActionDetailByCustomer2 {
@Autowired
private CustomerActionStatisticsMapper customerActionStatisticsMapper;
private BufferedWriter deviceActionDetailWriter;
private static final Map<String, Integer[]> RAND_RANGE_MAP = new HashMap<>();
static {
RAND_RANGE_MAP.put("声控调用", new Integer[]{6, 9});
RAND_RANGE_MAP.put("收音机使用", new Integer[]{28, 32});
RAND_RANGE_MAP.put("导航调用", new Integer[]{3, 6});
RAND_RANGE_MAP.put("音乐使用", new Integer[]{14, 17});
RAND_RANGE_MAP.put("联网应用使用", new Integer[]{2, 5});
}
//@Test
//public void generateDeviceActionDetail() {
// this.initDeviceActionDetailWriter(null);
//
// List<CustomerActionStatistics> actionStatisticsList =
// this.customerActionStatisticsMapper.selectByType(null);
// for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
// this.batchAddDeviceActionDetail(actionStatistics, null);
// }
//
// this.closeDeviceActionDetailWriter();
//}
//
//public void generateDeviceActionDetail2() {
// Date startDate = DateUtil.parse("2018-12", "yyyy-MM");
// Date endDate = DateUtil.parse("2021-01", "yyyy-MM");
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(startDate);
// Date currentStartDate = startDate;
// while (currentStartDate.before(endDate)) {
// this.initDeviceActionDetailWriter(startDate);
// calendar.add(Calendar.MONTH, 1);
// Date currentEndDate = calendar.getTime();
// List<CustomerActionStatistics> actionStatisticsList =
// this.customerActionStatisticsMapper.selectByDate(
// currentStartDate, currentEndDate);
// for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
// this.batchAddDeviceActionDetail(actionStatistics, currentStartDate);
// }
// currentStartDate = currentEndDate;
// this.closeDeviceActionDetailWriter();
// }
//}
@Test
public void generateDeviceActionDetail() {
List<String> monthList = this.customerActionStatisticsMapper.selectMonthList();
for (String month : monthList) {
this.initDeviceActionDetailWriter(month);
List<CustomerActionStatistics> actionStatisticsList =
this.customerActionStatisticsMapper.selectByMonth(month);
for (CustomerActionStatistics actionStatistics : actionStatisticsList) {
Integer deviceCount = this.customerActionStatisticsMapper.selectOnlineNumber(
actionStatistics);
this.batchAddDeviceActionDetail(actionStatistics, deviceCount);
}
this.closeDeviceActionDetailWriter();
}
}
private void batchAddDeviceActionDetail(CustomerActionStatistics actionStatistics,
int deviceCount) {
Date statisticsDate = DateUtil.parse(actionStatistics.getStatisticsTime(),
"yyyy-MM");
DateTime endDate = DateUtil.offsetMonth(statisticsDate, 1);
Calendar calendar = Calendar.getInstance();
calendar.setTime(statisticsDate);
// 设备行为类型
String type = actionStatistics.getType();
// 该月需要生成数据的数量
Integer neededNumber = actionStatistics.getNumber();
List<PlatformDevice> deviceList = this.customerActionStatisticsMapper.selectDeviceList(
actionStatistics, endDate, deviceCount);
if (!deviceList.isEmpty()) {
int index = 0;
while (neededNumber > 0) {
// 循环获取设备
PlatformDevice device = deviceList.get(index % deviceList.size());
index++;
// 获取每种行为需要生成的随机数量
Integer[] randRange = RAND_RANGE_MAP.get(type);
int num = RandomUtil.randomInt(randRange[0], randRange[1]);
int generatedNumber = num > neededNumber ? neededNumber : num;
while (generatedNumber > 0) {
this.addDeviceActionDetail(device, type, statisticsDate);
// 减去已经生成的数据数量
generatedNumber--;
neededNumber--;
}
}
}
//for (PlatformDevice device : deviceList) {
// // 获取每种行为需要生成的随机数量
// Integer[] randRange = RAND_RANGE_MAP.get(type);
// int num = RandomUtil.randomInt(randRange[0], randRange[1]);
// int generatedNumber = num > neededNumber ? neededNumber : num;
// while (generatedNumber > 0) {
// this.addDeviceActionDetail(device, type, statisticsDate);
// // 减去已经生成的数据数量
// generatedNumber--;
// neededNumber--;
// }
// if (neededNumber <= 0) {
// break;
// }
//}
//
//// 如果还没达到需要生成的数据量,则继续生成
//while (neededNumber > 0) {
// // 随机取一个设备生成行为数据
// PlatformDevice device = deviceList.get(RandomUtil.randomInt(deviceList.size()));
// this.addDeviceActionDetail(device, type, statisticsDate);
// neededNumber--;
//}
}
private void addDeviceActionDetail(PlatformDevice device, String type, Date startDate) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, RandomUtil.randomInt(maxDays) + 1);
calendar.set(Calendar.HOUR_OF_DAY, RandomUtil.randomInt(6, 24));
calendar.set(Calendar.MINUTE, RandomUtil.randomInt(60));
calendar.set(Calendar.SECOND, RandomUtil.randomInt(60));
DeviceActionDetail actionDetail = new DeviceActionDetail();
actionDetail.setDeviceSn(device.getDeviceSn());
actionDetail.setCreateTime(calendar.getTime());
actionDetail.setType(type);
try {
String s = String.format(",\n('%s', '%s', '%s')",
actionDetail.getDeviceSn(), actionDetail.getType(),
DateUtil.formatDateTime(actionDetail.getCreateTime()));
this.deviceActionDetailWriter.write(s);
} catch (IOException e) {
e.printStackTrace();
}
}
//private void addDeviceActionDetail2(CustomerActionStatistics actionStatistics) {
// Date statisticsDate = DateUtil.parse(actionStatistics.getStatisticsTime(),
// "yyyy-MM");
// DateTime endDate = DateUtil.offsetMonth(statisticsDate, 1);
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(statisticsDate);
// int maxDays = calendar.get(Calendar.DAY_OF_MONTH);
// String type = actionStatistics.getType();
// int count = actionStatistics.getNumber() / DIVISION_MAP.get(type);
// // 查询在统计月底之前出货的设备
// List<PlatformDevice> deviceList = this.customerActionStatisticsMapper
// .selectDeviceList(actionStatistics, endDate, count);
// for (PlatformDevice device : deviceList) {
// calendar.set(Calendar.DAY_OF_MONTH, RandomUtil.randomInt(maxDays) + 1);
// calendar.set(Calendar.HOUR_OF_DAY, RandomUtil.randomInt(6, 24));
// calendar.set(Calendar.MINUTE, RandomUtil.randomInt(60));
// calendar.set(Calendar.SECOND, RandomUtil.randomInt(60));
// DeviceActionDetail actionDetail = new DeviceActionDetail();
// actionDetail.setDeviceSn(device.getDeviceSn());
// actionDetail.setCreateTime(calendar.getTime());
// actionDetail.setType(type);
// try {
// String s = String.format(",\n('%s', '%s', '%s')",
// actionDetail.getDeviceSn(), actionDetail.getType(),
// DateUtil.formatDateTime(actionDetail.getCreateTime()));
// this.deviceActionDetailWriter.write(s);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//}
private void initDeviceActionDetailWriter(String month) {
try {
String monthStr = month.replace("-", "");
String filename = String.format("D:/data/device-action-data-%s.sql", monthStr);
this.deviceActionDetailWriter = FileUtil.getWriter(filename,
StandardCharsets.UTF_8, false);
//String headLine = String.format(
// "insert into t_device_action_detail_%s (device_sn, type, create_time) values",
// monthStr);
String headLine = "insert into t_device_action_detail (device_sn, type, create_time) values";
this.deviceActionDetailWriter.write(headLine);
} catch (IOException e) {
e.printStackTrace();
}
}
private void closeDeviceActionDetailWriter() {
try {
this.deviceActionDetailWriter.flush();
this.deviceActionDetailWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package cn.com.glsx.openplatform;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import cn.com.glsx.openplatform.mapper.CustomerNetworkStatisticsMapper;
import cn.com.glsx.openplatform.model.CustomerNetworkStatistics;
import cn.com.glsx.openplatform.model.DeviceNetworkDetail;
import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
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 2021-01-06
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class)
public class GenerateDeviceNetworkDetailByCustomer {
@Autowired
private CustomerNetworkStatisticsMapper customerNetworkStatisticsMapper;
private BufferedWriter deviceNetworkDetailWriter;
/**
* 根据客户联网统计表 t_customer_network_statistics 生成设备联网明细表 t_device_network_detail 数据
*/
@Test
public void generateDeviceNetworkDetail() {
// 取出所有月份,按月存储数据
List<String> monthList = this.customerNetworkStatisticsMapper.selectMonthList();
for (String month : monthList) {
this.initDeviceNetworkDetailWriter(month);
List<CustomerNetworkStatistics> networkStatisticsList =
this.customerNetworkStatisticsMapper.selectByMonth(month);
Date startDate = DateUtil.parse(month, "yyyy-MM");
Date endDate = DateUtil.offsetMonth(startDate, 1);
for (CustomerNetworkStatistics networkStatistics : networkStatisticsList) {
List<PlatformDevice> deviceList = this.customerNetworkStatisticsMapper
.selectPlatformDevice(networkStatistics, endDate);
Integer onlineCount = networkStatistics.getOnlineCount();
if (!deviceList.isEmpty()) {
this.addDeviceNetworkDetail(deviceList, startDate, onlineCount);
}
}
this.closeDeviceNetworkDetailWriter();
}
}
private void initDeviceNetworkDetailWriter(String month) {
try {
String monthStr = month.replace("-", "");
String filename = String.format("D:/data/device-network-detail-%s.sql",
monthStr);
this.deviceNetworkDetailWriter = FileUtil.getWriter(filename, StandardCharsets.UTF_8,
false);
String header = String.format(
"insert into t_device_network_detail_%s (device_sn, create_time) values",
monthStr);
this.deviceNetworkDetailWriter.write(header);
} catch (IOException e) {
e.printStackTrace();
}
}
private void closeDeviceNetworkDetailWriter() {
try {
this.deviceNetworkDetailWriter.flush();
this.deviceNetworkDetailWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void addDeviceNetworkDetail(List<PlatformDevice> deviceList, Date startDate, int count) {
for (int i = 0; i < count; i++) {
PlatformDevice device = deviceList.get(i % deviceList.size());
Date activatTime = device.getActivatTime();
Date createTime;
if (DateUtil.isSameMonth(startDate, activatTime)) {
long startMs = activatTime.getTime();
long endMs = DateUtil.dateNew(startDate)
.offset(DateField.MONTH, 1).getTime();
createTime = new Date(RandomUtil.randomLong(startMs, endMs));
} else {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
int day = RandomUtil.randomInt(DateUtil.dayOfMonth(startDate),
calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
int hour = RandomUtil.randomInt(24);
int minute = RandomUtil.randomInt(60);
int second = RandomUtil.randomInt(60);
createTime = DateUtil.dateNew(startDate).setField(DateField.DAY_OF_MONTH, day)
.setField(DateField.HOUR_OF_DAY, hour)
.setField(DateField.MINUTE, minute)
.setField(DateField.SECOND, second);
}
DeviceNetworkDetail networkDetail = new DeviceNetworkDetail();
networkDetail.setDeviceSn(device.getDeviceSn());
networkDetail.setCreateTime(createTime);
try {
String s = String.format(",\n('%s', '%s')",
networkDetail.getDeviceSn(),
DateUtil.formatDateTime(networkDetail.getCreateTime()));
this.deviceNetworkDetailWriter.write(s);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
...@@ -37,7 +37,7 @@ public class GeneratePlatformDevice { ...@@ -37,7 +37,7 @@ public class GeneratePlatformDevice {
private ActivationDataMapper activationDataMapper; private ActivationDataMapper activationDataMapper;
@Autowired @Autowired
private PlatformDeviceMapper deviceMapper; private PlatformDeviceMapper platformDeviceMapper;
private BufferedWriter platformDeviceWriter; private BufferedWriter platformDeviceWriter;
...@@ -45,6 +45,8 @@ public class GeneratePlatformDevice { ...@@ -45,6 +45,8 @@ public class GeneratePlatformDevice {
private static final Map<String, Integer> DEVICE_TYPE_MAP = new HashMap<>(); private static final Map<String, Integer> DEVICE_TYPE_MAP = new HashMap<>();
private int currentId = 874003;
static { static {
TYPE_MAP.put((byte) 1, "通信模组"); TYPE_MAP.put((byte) 1, "通信模组");
TYPE_MAP.put((byte) 2, "核心板"); TYPE_MAP.put((byte) 2, "核心板");
...@@ -141,7 +143,9 @@ public class GeneratePlatformDevice { ...@@ -141,7 +143,9 @@ public class GeneratePlatformDevice {
serialNumMap.put(serialDateStr, 0); serialNumMap.put(serialDateStr, 0);
} }
// 获取当天已经出货的量,作为起始序列号 // 获取当天已经出货的量,作为起始序列号
int startSerialNum = serialNumMap.get(serialDateStr) + 1; //int startSerialNum = serialNumMap.get(serialDateStr) + 1;
int startSerialNum = this.activationDataMapper.countByDate(serialDate,
DateUtil.offsetDay(serialDate, 1)) + 1;
int endSerialNum; int endSerialNum;
int randCount = goodsNum > 5000 ? RandomUtil.randomInt(4000, 5000) : goodsNum; int randCount = goodsNum > 5000 ? RandomUtil.randomInt(4000, 5000) : goodsNum;
// 计算终止序列号 // 计算终止序列号
...@@ -171,7 +175,7 @@ public class GeneratePlatformDevice { ...@@ -171,7 +175,7 @@ public class GeneratePlatformDevice {
private void initPlatformDeviceWriter() throws IOException { private void initPlatformDeviceWriter() throws IOException {
this.platformDeviceWriter = Files.newBufferedWriter( this.platformDeviceWriter = Files.newBufferedWriter(
Paths.get("D:/data/platform-device.sql")); Paths.get("D:/data/platform-device.sql"));
this.platformDeviceWriter.write("insert into t_platform_device (device_sn, device_type, version, customer_id, status, create_time, update_time, create_by, update_by) values"); this.platformDeviceWriter.write("insert into t_platform_device (id, device_sn, device_type, version, customer_id, status, create_time, update_time, create_by, update_by) values");
} }
private void closePlatformDeviceWriter() throws IOException { private void closePlatformDeviceWriter() throws IOException {
...@@ -190,6 +194,7 @@ public class GeneratePlatformDevice { ...@@ -190,6 +194,7 @@ public class GeneratePlatformDevice {
DateUtil.dayOfMonth(serialDate), DateUtil.dayOfMonth(serialDate),
serialNum); serialNum);
PlatformDevice device = new PlatformDevice(); PlatformDevice device = new PlatformDevice();
device.setId(this.currentId);
device.setDeviceSn(deviceSn); device.setDeviceSn(deviceSn);
device.setDeviceType(shipmentData.getDeviceType()); device.setDeviceType(shipmentData.getDeviceType());
device.setVersion(shipmentData.getVersion()); device.setVersion(shipmentData.getVersion());
...@@ -201,13 +206,16 @@ public class GeneratePlatformDevice { ...@@ -201,13 +206,16 @@ public class GeneratePlatformDevice {
device.setCreateBy(0); device.setCreateBy(0);
device.setUpdateBy(0); device.setUpdateBy(0);
try { try {
String s = String.format(",\n('%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d)", String s = String.format(",\n(%d, '%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d)",
this.currentId,
device.getDeviceSn(), device.getDeviceType(), device.getVersion(), device.getDeviceSn(), device.getDeviceType(), device.getVersion(),
device.getCustomerId(), device.getStatus(), device.getCustomerId(), device.getStatus(),
DateUtil.formatDateTime(device.getCreateTime()), DateUtil.formatDateTime(device.getCreateTime()),
DateUtil.formatDateTime(device.getUpdateTime()), DateUtil.formatDateTime(device.getUpdateTime()),
device.getCreateBy(), device.getUpdateBy()); device.getCreateBy(), device.getUpdateBy());
this.platformDeviceMapper.insertSelective(device);
this.platformDeviceWriter.write(s); this.platformDeviceWriter.write(s);
this.currentId++;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -217,7 +225,7 @@ public class GeneratePlatformDevice { ...@@ -217,7 +225,7 @@ public class GeneratePlatformDevice {
@Test @Test
public void generateDeviceActivationData() throws Exception { public void generateDeviceActivationData() throws Exception {
//查询数据库 //查询数据库
List<ActivationData> activationList = activationDataMapper.getActivationList(); List<ActivationData> activationList = activationDataMapper.selectActivationList();
for (ActivationData activationData : activationList) { for (ActivationData activationData : activationList) {
activationData.setTypeName(TYPE_MAP.get(activationData.getType())); activationData.setTypeName(TYPE_MAP.get(activationData.getType()));
String month = activationData.getMonth(); String month = activationData.getMonth();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!