Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
rpc-openplatform
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3fe033e8
authored
Jan 05, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加数据生成类
1 parent
d4b664fa
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1412 additions
and
413 deletions
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/CustomerActionStatistics.java
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/CustomerNetworkStatistics.java
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/ShipmentData.java
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/ActivationDataMapper.java
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/CustomerActionStatisticsMapper.java
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/CustomerNetworkStatisticsMapper.java
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/DeviceActionDetailMapper.java
rpc-openplatform-container/src/main/resources/META-INF/orm/ActivationDataMapper.xml
rpc-openplatform-container/src/main/resources/META-INF/orm/CustomerActionStatisticsMapper.xml
rpc-openplatform-container/src/main/resources/META-INF/orm/CustomerNetworkStatisticsMapper.xml
rpc-openplatform-container/src/main/resources/META-INF/orm/DeviceActionDetailMapper.xml
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateCustomerActionStatistic.java
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateCustomerNetworkStatistic.java
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateDeviceActionDetail.java
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateDeviceActionDetailByCustomer.java
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateFakeData.java
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GeneratePlatformDevice.java
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/CustomerActionStatistics.java
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
.
model
;
/**
* <p>Description:
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
...
...
@@ -13,6 +13,11 @@ package cn.com.glsx.openplatform.model;
*/
public
class
CustomerActionStatistics
{
/**
* 在线设备数
*/
private
Integer
onlineNumber
;
/**
* id
*/
private
Integer
id
;
...
...
@@ -28,6 +33,11 @@ public class CustomerActionStatistics {
private
String
customerName
;
/**
* 设备类型
*/
private
String
deviceType
;
/**
* 行为类型
*/
private
String
type
;
...
...
@@ -38,14 +48,17 @@ public class CustomerActionStatistics {
private
String
statisticsTime
;
/**
*
活跃
数
*
统计
数
*/
private
Integer
activeN
umber
;
private
Integer
n
umber
;
/**
* 激活增长数
*/
private
Integer
activationGrowth
;
public
Integer
getOnlineNumber
()
{
return
onlineNumber
;
}
public
void
setOnlineNumber
(
Integer
onlineNumber
)
{
this
.
onlineNumber
=
onlineNumber
;
}
public
Integer
getId
()
{
return
id
;
...
...
@@ -71,6 +84,14 @@ public class CustomerActionStatistics {
this
.
customerName
=
customerName
;
}
public
String
getDeviceType
()
{
return
deviceType
;
}
public
void
setDeviceType
(
String
deviceType
)
{
this
.
deviceType
=
deviceType
;
}
public
String
getType
()
{
return
type
;
}
...
...
@@ -87,36 +108,25 @@ public class CustomerActionStatistics {
this
.
statisticsTime
=
statisticsTime
;
}
public
Integer
get
Active
Number
()
{
return
activeN
umber
;
public
Integer
getNumber
()
{
return
n
umber
;
}
public
void
setActiveNumber
(
Integer
activeNumber
)
{
this
.
activeNumber
=
activeNumber
;
}
public
Integer
getActivationGrowth
()
{
return
activationGrowth
;
}
public
void
setActivationGrowth
(
Integer
activationGrowth
)
{
this
.
activationGrowth
=
activationGrowth
;
public
void
setNumber
(
Integer
number
)
{
this
.
number
=
number
;
}
@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
return
"CustomerActionStatistics{"
+
"onlineNumber="
+
onlineNumber
+
", id="
+
id
+
", customerId="
+
customerId
+
", customerName='"
+
customerName
+
'\''
+
", deviceType='"
+
deviceType
+
'\''
+
", type='"
+
type
+
'\''
+
", statisticsTime='"
+
statisticsTime
+
'\''
+
", number="
+
number
+
'}'
;
}
}
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/CustomerNetworkStatistics.java
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
.
model
;
/**
* <p>Description:
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
...
...
@@ -28,24 +28,24 @@ public class CustomerNetworkStatistics {
private
String
customerName
;
/**
* 类型 1月 2年
*/
private
Byte
t
ype
;
* 设备类型
*/
private
String
deviceT
ype
;
/**
*
统计时间
*
类型 月 年
*/
private
String
statisticsTim
e
;
private
String
typ
e
;
/**
*
活跃数
*
统计时间
*/
private
Integer
activeNumber
;
private
String
statisticsTime
;
/**
*
激活增长
数
*
联网设备
数
*/
private
Integer
activationGrowth
;
private
Integer
onlineNumber
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -71,11 +71,19 @@ public class CustomerNetworkStatistics {
this
.
customerName
=
customerName
;
}
public
Byte
getType
()
{
public
String
getDeviceType
()
{
return
deviceType
;
}
public
void
setDeviceType
(
String
deviceType
)
{
this
.
deviceType
=
deviceType
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
Byte
type
)
{
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
...
...
@@ -87,36 +95,24 @@ public class CustomerNetworkStatistics {
this
.
statisticsTime
=
statisticsTime
;
}
public
Integer
getActiveNumber
()
{
return
activeNumber
;
}
public
void
setActiveNumber
(
Integer
activeNumber
)
{
this
.
activeNumber
=
activeNumber
;
}
public
Integer
getActivationGrowth
()
{
return
activationGrowth
;
public
Integer
getOnlineNumber
()
{
return
onlineNumber
;
}
public
void
set
ActivationGrowth
(
Integer
activationGrowth
)
{
this
.
activationGrowth
=
activationGrowth
;
public
void
set
OnlineNumber
(
Integer
onlineNumber
)
{
this
.
onlineNumber
=
onlineNumber
;
}
@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
();
return
"CustomerNetworkStatistics{"
+
"id="
+
id
+
", customerId="
+
customerId
+
", customerName='"
+
customerName
+
'\''
+
", deviceType='"
+
deviceType
+
'\''
+
", type='"
+
type
+
'\''
+
", statisticsTime='"
+
statisticsTime
+
'\''
+
", onlineNumber="
+
onlineNumber
+
'}'
;
}
}
\ No newline at end of file
}
rpc-openplatform-api/src/main/java/cn/com/glsx/openplatform/model/ShipmentData.java
View file @
3fe033e
...
...
@@ -14,7 +14,13 @@ public class ShipmentData {
private
Integer
goodsNum
;
private
Byte
type
;
private
String
deviceType
;
private
Integer
customerId
;
private
String
customerName
;
private
String
version
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -40,21 +46,35 @@ public class ShipmentData {
this
.
goodsNum
=
goodsNum
;
}
public
Byte
getType
()
{
return
type
;
public
String
getDeviceType
()
{
return
deviceType
;
}
public
void
setDeviceType
(
String
deviceType
)
{
this
.
deviceType
=
deviceType
;
}
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
void
setType
(
Byte
type
)
{
this
.
type
=
type
;
public
String
getVersion
(
)
{
return
version
;
}
@Override
public
String
toString
()
{
return
"ShipmentData{"
+
"id="
+
id
+
", goodsTime='"
+
goodsTime
+
'\''
+
", goodsNum="
+
goodsNum
+
", type="
+
type
+
'}'
;
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
}
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/ActivationDataMapper.java
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
.
mapper
;
import
java.util.Date
;
import
java.util.List
;
import
cn.com.glsx.openplatform.model.ActivationData
;
import
cn.com.glsx.openplatform.model.PlatformDevice
;
import
cn.com.glsx.openplatform.model.ShipmentData
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -17,9 +19,17 @@ import org.apache.ibatis.annotations.Param;
public
interface
ActivationDataMapper
{
List
<
ActivationData
>
getActivationList
();
int
countByDate
(
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
);
int
updateDeviceActivation
(
@Param
(
"data"
)
ActivationData
data
,
@Param
(
"startTimeStr"
)
String
startTimeStr
,
@Param
(
"endTimeStr"
)
String
endTimeStr
,
@Param
(
"num"
)
int
num
);
List
<
ShipmentData
>
getShipmentList
();
List
<
String
>
selectDeviceTypeList
();
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
);
}
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/CustomerActionStatisticsMapper.java
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
.
mapper
;
import
cn.com.glsx.openplatform.model.CustomerActionStatistics
;
import
java.util.Date
;
import
java.util.List
;
import
cn.com.glsx.openplatform.model.CustomerActionStatistics
;
import
cn.com.glsx.openplatform.model.PlatformDevice
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
* <p>Description:
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
...
...
@@ -15,6 +17,18 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public
interface
CustomerActionStatisticsMapper
{
List
<
String
>
selectMonthList
();
List
<
CustomerActionStatistics
>
selectByMonth
(
@Param
(
"month"
)
String
month
);
Integer
selectOnlineNumber
(
CustomerActionStatistics
actionStatistics
);
List
<
CustomerActionStatistics
>
selectByType
(
@Param
(
"type"
)
String
type
);
List
<
PlatformDevice
>
selectDeviceList
(
@Param
(
"actionStatistics"
)
CustomerActionStatistics
actionStatistics
,
@Param
(
"endDate"
)
Date
endDate
,
@Param
(
"count"
)
Integer
count
);
int
deleteByPrimaryKey
(
Integer
id
);
int
insert
(
CustomerActionStatistics
record
);
...
...
@@ -36,4 +50,4 @@ public interface CustomerActionStatisticsMapper {
int
updateBatchSelective
(
List
<
CustomerActionStatistics
>
list
);
int
batchInsert
(
@Param
(
"list"
)
List
<
CustomerActionStatistics
>
list
);
}
\ No newline at end of file
}
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/CustomerNetworkStatisticsMapper.java
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
.
mapper
;
import
cn.com.glsx.openplatform.model.CustomerNetworkStatistics
;
import
java.util.Date
;
import
java.util.List
;
import
cn.com.glsx.openplatform.model.CustomerNetworkStatistics
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
* <p>Description:
* <p>Description:
* <p>Project: rpc-openplatform-container
*
* @author wbh
...
...
@@ -15,6 +16,12 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public
interface
CustomerNetworkStatisticsMapper
{
List
<
CustomerNetworkStatistics
>
selectByDate
(
@Param
(
"startDate"
)
String
startDate
,
@Param
(
"endDate"
)
String
endDate
);
List
<
CustomerNetworkStatistics
>
selectFromDeviceNetworkByDate
(
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
);
int
deleteByPrimaryKey
(
Integer
id
);
int
insert
(
CustomerNetworkStatistics
record
);
...
...
@@ -36,4 +43,4 @@ public interface CustomerNetworkStatisticsMapper {
int
updateBatchSelective
(
List
<
CustomerNetworkStatistics
>
list
);
int
batchInsert
(
@Param
(
"list"
)
List
<
CustomerNetworkStatistics
>
list
);
}
\ No newline at end of file
}
rpc-openplatform-container/src/main/java/cn/com/glsx/openplatform/mapper/DeviceActionDetailMapper.java
View file @
3fe033e
...
...
@@ -17,10 +17,14 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public
interface
DeviceActionDetailMapper
{
int
countByMonth
(
@Param
(
"startMonth"
)
Date
startMonth
,
@Param
(
"endMonth"
)
Date
endMonth
);
List
<
String
>
selectDeviceType
(
);
List
<
PlatformDevice
>
selectByMonth
(
@Param
(
"startMonth"
)
Date
startMonth
,
@Param
(
"endMonth"
)
Date
endMonth
,
@Param
(
"count"
)
Integer
count
);
int
countByDate
(
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
,
@Param
(
"type"
)
String
type
);
List
<
PlatformDevice
>
selectByDate
(
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
,
@Param
(
"count"
)
Integer
count
,
@Param
(
"type"
)
String
type
);
int
deleteByPrimaryKey
(
Integer
id
);
...
...
rpc-openplatform-container/src/main/resources/META-INF/orm/ActivationDataMapper.xml
View file @
3fe033e
...
...
@@ -19,6 +19,19 @@
order by month;
</select>
<select
id=
"countByDate"
resultType=
"integer"
>
select count(1)
from t_platform_device
<where>
<if
test=
"startDate != null"
>
and create_time >= #{startDate,jdbcType=TIMESTAMP}
</if>
<if
test=
"endDate != null"
>
and create_time
<
#{endDate,jdbcType=TIMESTAMP}
</if>
</where>
</select>
<update
id=
"updateDeviceActivation"
>
update t_platform_device
set customer_id = #{data.customerId,jdbcType=INTEGER},
...
...
@@ -38,8 +51,31 @@
limit #{num,jdbcType=INTEGER}
</update>
<select
id=
"getShipmentList"
resultType=
"cn.com.glsx.openplatform.model.ShipmentData"
>
select id, goods_time goodsTime, goods_num goodsNum, type
<select
id=
"selectDeviceTypeList"
resultType=
"java.lang.String"
>
select distinct device_type
from t_shipment_data
</select>
<select
id=
"selectShipmentByType"
resultType=
"cn.com.glsx.openplatform.model.ShipmentData"
>
select id, goods_time goodsTime, goods_num goodsNum, device_type deviceType,
customer_id customerId, customer_name customerName, version
from t_shipment_data
<where>
<if
test=
"deviceType != null and deviceType != ''"
>
and device_type = #{deviceType,jdbcType=VARCHAR}
</if>
</where>
</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>
rpc-openplatform-container/src/main/resources/META-INF/orm/CustomerActionStatisticsMapper.xml
View file @
3fe033e
...
...
@@ -8,17 +8,67 @@
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"customer_id"
jdbcType=
"INTEGER"
property=
"customerId"
/>
<result
column=
"customer_name"
jdbcType=
"VARCHAR"
property=
"customerName"
/>
<result
column=
"device_type"
jdbcType=
"VARCHAR"
property=
"deviceType"
/>
<result
column=
"type"
jdbcType=
"VARCHAR"
property=
"type"
/>
<result
column=
"statistics_time"
jdbcType=
"VARCHAR"
property=
"statisticsTime"
/>
<result
column=
"active_number"
jdbcType=
"INTEGER"
property=
"activeNumber"
/>
<result
column=
"activation_growth"
jdbcType=
"INTEGER"
property=
"activationGrowth"
/>
<result
column=
"number"
jdbcType=
"INTEGER"
property=
"number"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--@mbg.generated-->
id, customer_id, customer_name,
`type`, statistics_time, active_number, activation_growth
id, customer_id, customer_name,
device_type, `type`, statistics_time, number
</sql>
<select
id=
"selectMonthList"
resultType=
"java.lang.String"
>
select distinct statistics_time
from t_customer_action_statistics
</select>
<select
id=
"selectByMonth"
resultMap=
"BaseResultMap"
>
select id, customer_id, customer_name, device_type, type, statistics_time, number
from t_customer_action_statistics
<where>
<if
test=
"month != null and month != ''"
>
and statistics_time = #{month,jdbcType=VARCHAR}
</if>
</where>
</select>
<select
id=
"selectOnlineNumber"
resultType=
"java.lang.Integer"
>
select sum(online_number)
from t_customer_device_statistics_new_doing_copy2
<where>
<if
test=
"customerId != null"
>
and customer_id = #{customerId,jdbcType=INTEGER}
</if>
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
and statistics_time = #{statisticsTime,jdbcType=VARCHAR}
</if>
</where>
group by customer_id, statistics_time
</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"
resultType=
"cn.com.glsx.openplatform.model.PlatformDevice"
>
select id, device_sn deviceSn, device_type deviceType
from t_platform_device
where customer_id = #{actionStatistics.customerId,jdbcType=INTEGER}
and device_type = #{actionStatistics.deviceType,jdbcType=VARCHAR}
and create_time
<
#{endDate,jdbcType=TIMESTAMP}
order by rand()
limit #{count,jdbcType=INTEGER}
</select>
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
<!--@mbg.generated-->
select
...
...
@@ -42,11 +92,10 @@
select LAST_INSERT_ID()
</selectKey>
insert into t_customer_action_statistics (customer_id, customer_name, `type`,
statistics_time, active_number, activation_growth
)
statistics_time, number
)
values (#{customerId,jdbcType=INTEGER}, #{customerName,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{statisticsTime,jdbcType=VARCHAR}, #{activeNumber,jdbcType=INTEGER},
#{activationGrowth,jdbcType=INTEGER})
#{type,jdbcType=VARCHAR},
#{statisticsTime,jdbcType=VARCHAR}, #{number,jdbcType=INTEGER})
</insert>
<insert
id=
"insertSelective"
keyColumn=
"id"
keyProperty=
"id"
...
...
@@ -70,11 +119,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time,
</if>
<if
test=
"activeNumber != null"
>
active_number,
</if>
<if
test=
"activationGrowth != null"
>
activation_growth,
<if
test=
"number != null"
>
number,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
...
...
@@ -90,11 +136,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
#{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
#{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
#{activationGrowth,jdbcType=INTEGER},
<if
test=
"number != null"
>
#{number,jdbcType=INTEGER},
</if>
</trim>
</insert>
...
...
@@ -116,11 +159,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
active_number = #{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
activation_growth = #{activationGrowth,jdbcType=INTEGER},
<if
test=
"number != null"
>
number = #{number,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
...
...
@@ -131,11 +171,10 @@
<!--@mbg.generated-->
update t_customer_action_statistics
set customer_id = #{customerId,jdbcType=INTEGER},
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
active_number = #{activeNumber,jdbcType=INTEGER},
activation_growth = #{activationGrowth,jdbcType=INTEGER}
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
number = #{number,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
...
...
@@ -164,15 +203,9 @@
then #{item.statisticsTime,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"
active_
number = case"
suffix=
"end,"
>
<trim
prefix=
"number = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=INTEGER} then #{item.activeNumber,jdbcType=INTEGER}
</foreach>
</trim>
<trim
prefix=
"activation_growth = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activationGrowth,jdbcType=INTEGER}
when id = #{item.id,jdbcType=INTEGER} then #{item.number,jdbcType=INTEGER}
</foreach>
</trim>
</trim>
...
...
@@ -217,19 +250,11 @@
</if>
</foreach>
</trim>
<trim
prefix=
"
active_
number = case"
suffix=
"end,"
>
<trim
prefix=
"number = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.
activeN
umber != null"
>
<if
test=
"item.
n
umber != null"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activeNumber,jdbcType=INTEGER}
</if>
</foreach>
</trim>
<trim
prefix=
"activation_growth = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.activationGrowth != null"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activationGrowth,jdbcType=INTEGER}
then #{item.number,jdbcType=INTEGER}
</if>
</foreach>
</trim>
...
...
@@ -244,14 +269,12 @@
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into t_customer_action_statistics
(customer_id, customer_name, `type`, statistics_time, active_number,
activation_growth)
(customer_id, customer_name, `type`, statistics_time, number)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.customerId,jdbcType=INTEGER}, #{item.customerName,jdbcType=VARCHAR},
#{item.type,jdbcType=VARCHAR},
#{item.statisticsTime,jdbcType=VARCHAR}, #{item.activeNumber,jdbcType=INTEGER},
#{item.activationGrowth,jdbcType=INTEGER})
#{item.type,jdbcType=VARCHAR},
#{item.statisticsTime,jdbcType=VARCHAR}, #{item.number,jdbcType=INTEGER})
</foreach>
</insert>
...
...
@@ -268,8 +291,7 @@
customer_name,
`type`,
statistics_time,
active_number,
activation_growth,
number,
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
...
...
@@ -280,8 +302,7 @@
#{customerName,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{statisticsTime,jdbcType=VARCHAR},
#{activeNumber,jdbcType=INTEGER},
#{activationGrowth,jdbcType=INTEGER},
#{number,jdbcType=INTEGER},
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
...
...
@@ -289,11 +310,10 @@
id = #{id,jdbcType=INTEGER},
</if>
customer_id = #{customerId,jdbcType=INTEGER},
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
active_number = #{activeNumber,jdbcType=INTEGER},
activation_growth = #{activationGrowth,jdbcType=INTEGER},
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
number = #{number,jdbcType=INTEGER},
</trim>
</insert>
...
...
@@ -318,11 +338,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time,
</if>
<if
test=
"activeNumber != null"
>
active_number,
</if>
<if
test=
"activationGrowth != null"
>
activation_growth,
<if
test=
"number != null"
>
number,
</if>
</trim>
values
...
...
@@ -342,11 +359,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
#{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
#{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
#{activationGrowth,jdbcType=INTEGER},
<if
test=
"number != null"
>
#{number,jdbcType=INTEGER},
</if>
</trim>
on duplicate key update
...
...
@@ -366,11 +380,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
active_number = #{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
activation_growth = #{activationGrowth,jdbcType=INTEGER},
<if
test=
"number != null"
>
number = #{number,jdbcType=INTEGER},
</if>
</trim>
</insert>
...
...
rpc-openplatform-container/src/main/resources/META-INF/orm/CustomerNetworkStatisticsMapper.xml
View file @
3fe033e
...
...
@@ -8,17 +8,49 @@
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"customer_id"
jdbcType=
"INTEGER"
property=
"customerId"
/>
<result
column=
"customer_name"
jdbcType=
"VARCHAR"
property=
"customerName"
/>
<result
column=
"type"
jdbcType=
"TINYINT"
property=
"type"
/>
<result
column=
"device_type"
jdbcType=
"VARCHAR"
property=
"deviceType"
/>
<result
column=
"type"
jdbcType=
"VARCHAR"
property=
"type"
/>
<result
column=
"statistics_time"
jdbcType=
"VARCHAR"
property=
"statisticsTime"
/>
<result
column=
"active_number"
jdbcType=
"INTEGER"
property=
"activeNumber"
/>
<result
column=
"activation_growth"
jdbcType=
"INTEGER"
property=
"activationGrowth"
/>
<result
column=
"online_number"
jdbcType=
"INTEGER"
property=
"onlineNumber"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--@mbg.generated-->
id, customer_id, customer_name,
`type`, statistics_time, active_number, activation_growth
id, customer_id, customer_name,
device_type, `type`, statistics_time, online_number
</sql>
<select
id=
"selectByDate"
resultMap=
"BaseResultMap"
>
select id, customer_id, customer_name, device_type, statistics_time, online_number
from t_customer_device_statistics_new_doing_copy2 cns
<where>
<if
test=
"startDate != null"
>
and statistics_time >= #{startDate,jdbcType=VARCHAR}
</if>
<if
test=
"endDate != null"
>
and statistics_time
<
#{endDate,jdbcType=VARCHAR}
</if>
and online_number > 0
</where>
</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
<
#{endDate,jdbcType=TIMESTAMP}
</if>
</where>
group by pd.customer_id, statisticsTime
</select>
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
<!--@mbg.generated-->
select
...
...
@@ -42,11 +74,10 @@
select LAST_INSERT_ID()
</selectKey>
insert into t_customer_network_statistics (customer_id, customer_name, `type`,
statistics_time,
active_number, activation_growth
)
statistics_time,
online_number
)
values (#{customerId,jdbcType=INTEGER}, #{customerName,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT},
#{statisticsTime,jdbcType=VARCHAR}, #{activeNumber,jdbcType=INTEGER},
#{activationGrowth,jdbcType=INTEGER})
#{statisticsTime,jdbcType=VARCHAR}, #{onlineNumber,jdbcType=INTEGER})
</insert>
<insert
id=
"insertSelective"
keyColumn=
"id"
keyProperty=
"id"
...
...
@@ -70,11 +101,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time,
</if>
<if
test=
"activeNumber != null"
>
active_number,
</if>
<if
test=
"activationGrowth != null"
>
activation_growth,
<if
test=
"onlineNumber != null"
>
online_number,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
...
...
@@ -90,11 +118,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
#{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
#{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
#{activationGrowth,jdbcType=INTEGER},
<if
test=
"onlineNumber != null"
>
#{onlineNumber,jdbcType=INTEGER},
</if>
</trim>
</insert>
...
...
@@ -116,11 +141,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
active_number = #{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
activation_growth = #{activationGrowth,jdbcType=INTEGER},
<if
test=
"onlineNumber != null"
>
online_number = #{onlineNumber,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
...
...
@@ -134,8 +156,7 @@
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=TINYINT},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
active_number = #{activeNumber,jdbcType=INTEGER},
activation_growth = #{activationGrowth,jdbcType=INTEGER}
online_number = #{onlineNumber,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
...
...
@@ -164,15 +185,9 @@
then #{item.statisticsTime,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"
activ
e_number = case"
suffix=
"end,"
>
<trim
prefix=
"
onlin
e_number = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=INTEGER} then #{item.activeNumber,jdbcType=INTEGER}
</foreach>
</trim>
<trim
prefix=
"activation_growth = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activationGrowth,jdbcType=INTEGER}
when id = #{item.id,jdbcType=INTEGER} then #{item.onlineNumber,jdbcType=INTEGER}
</foreach>
</trim>
</trim>
...
...
@@ -217,19 +232,11 @@
</if>
</foreach>
</trim>
<trim
prefix=
"
activ
e_number = case"
suffix=
"end,"
>
<trim
prefix=
"
onlin
e_number = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.
activ
eNumber != null"
>
<if
test=
"item.
onlin
eNumber != null"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activeNumber,jdbcType=INTEGER}
</if>
</foreach>
</trim>
<trim
prefix=
"activation_growth = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.activationGrowth != null"
>
when id = #{item.id,jdbcType=INTEGER}
then #{item.activationGrowth,jdbcType=INTEGER}
then #{item.onlineNumber,jdbcType=INTEGER}
</if>
</foreach>
</trim>
...
...
@@ -244,14 +251,12 @@
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into t_customer_network_statistics
(customer_id, customer_name, `type`, statistics_time, active_number,
activation_growth)
(customer_id, customer_name, `type`, statistics_time, online_number)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.customerId,jdbcType=INTEGER}, #{item.customerName,jdbcType=VARCHAR},
#{item.type,jdbcType=TINYINT},
#{item.statisticsTime,jdbcType=VARCHAR}, #{item.activeNumber,jdbcType=INTEGER},
#{item.activationGrowth,jdbcType=INTEGER})
#{item.statisticsTime,jdbcType=VARCHAR}, #{item.onlineNumber,jdbcType=INTEGER})
</foreach>
</insert>
...
...
@@ -268,8 +273,7 @@
customer_name,
`type`,
statistics_time,
active_number,
activation_growth,
online_number,
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
...
...
@@ -280,8 +284,7 @@
#{customerName,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT},
#{statisticsTime,jdbcType=VARCHAR},
#{activeNumber,jdbcType=INTEGER},
#{activationGrowth,jdbcType=INTEGER},
#{onlineNumber,jdbcType=INTEGER},
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
...
...
@@ -292,8 +295,7 @@
customer_name = #{customerName,jdbcType=VARCHAR},
`type` = #{type,jdbcType=TINYINT},
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
active_number = #{activeNumber,jdbcType=INTEGER},
activation_growth = #{activationGrowth,jdbcType=INTEGER},
online_number = #{onlineNumber,jdbcType=INTEGER},
</trim>
</insert>
...
...
@@ -318,11 +320,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time,
</if>
<if
test=
"activeNumber != null"
>
active_number,
</if>
<if
test=
"activationGrowth != null"
>
activation_growth,
<if
test=
"onlineNumber != null"
>
online_number,
</if>
</trim>
values
...
...
@@ -342,11 +341,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
#{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
#{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
#{activationGrowth,jdbcType=INTEGER},
<if
test=
"onlineNumber != null"
>
#{onlineNumber,jdbcType=INTEGER},
</if>
</trim>
on duplicate key update
...
...
@@ -366,11 +362,8 @@
<if
test=
"statisticsTime != null and statisticsTime != ''"
>
statistics_time = #{statisticsTime,jdbcType=VARCHAR},
</if>
<if
test=
"activeNumber != null"
>
active_number = #{activeNumber,jdbcType=INTEGER},
</if>
<if
test=
"activationGrowth != null"
>
activation_growth = #{activationGrowth,jdbcType=INTEGER},
<if
test=
"onlineNumber != null"
>
online_number = #{onlineNumber,jdbcType=INTEGER},
</if>
</trim>
</insert>
...
...
rpc-openplatform-container/src/main/resources/META-INF/orm/DeviceActionDetailMapper.xml
View file @
3fe033e
...
...
@@ -16,32 +16,45 @@
id, device_sn, `type`, create_time
</sql>
<select
id=
"countByMonth"
resultType=
"int"
>
<select
id=
"selectDeviceType"
resultType=
"java.lang.String"
>
select distinct device_type
from t_platform_device
where device_type != '通信模组'
</select>
<select
id=
"countByDate"
resultType=
"int"
>
select count(1)
from t_platform_device
<where>
<if
test=
"start
Month
!= null"
>
and activat_time >= #{start
Month
,jdbcType=TIMESTAMP}
<if
test=
"start
Date
!= null"
>
and activat_time >= #{start
Date
,jdbcType=TIMESTAMP}
</if>
<if
test=
"endMonth != null"
>
and activat_time
<
#{endMonth,jdbcType=TIMESTAMP}
<if
test=
"endDate != null"
>
and activat_time
<
#{endDate,jdbcType=TIMESTAMP}
</if>
<if
test=
"type != null and type != ''"
>
and device_type = #{type,jdbcType=VARCHAR}
</if>
</where>
</select>
<select
id=
"selectBy
Month
"
resultType=
"cn.com.glsx.openplatform.model.PlatformDevice"
>
<select
id=
"selectBy
Date
"
resultType=
"cn.com.glsx.openplatform.model.PlatformDevice"
>
select id, device_sn deviceSn, device_type deviceType, customer_id customerId,
user_id userId, activat_time activatTime, status, create_time createTime,
update_time updateTime, create_by createBy, update_by updateBy, remark
from t_platform_device
<where>
<if
test=
"startMonth != null"
>
and activat_time >= #{startMonth,jdbcType=TIMESTAMP}
<if
test=
"startDate != null"
>
and activat_time >= #{startDate,jdbcType=TIMESTAMP}
</if>
<if
test=
"endDate != null"
>
and activat_time
<
#{endDate,jdbcType=TIMESTAMP}
</if>
<if
test=
"
endMonth != null
"
>
and
activat_time
<
#{endMonth,jdbcType=TIMESTAMP
}
<if
test=
"
type != null and type != ''
"
>
and
device_type = #{type,jdbcType=VARCHAR
}
</if>
</where>
order by rand()
<if
test=
"count != null"
>
limit #{count,jdbcType=INTEGER}
</if>
...
...
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateCustomerActionStatistic.java
0 → 100644
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.List
;
import
cn.com.glsx.openplatform.mapper.CustomerActionStatisticsMapper
;
import
cn.com.glsx.openplatform.mapper.CustomerNetworkStatisticsMapper
;
import
cn.com.glsx.openplatform.model.CustomerNetworkStatistics
;
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-02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Main
.
class
)
public
class
GenerateCustomerActionStatistic
{
@Autowired
private
CustomerActionStatisticsMapper
customerActionStatisticsMapper
;
@Autowired
private
CustomerNetworkStatisticsMapper
customerNetworkStatisticsMapper
;
private
BufferedWriter
customerActionStatisticsWriter
;
@Test
public
void
generateData
()
{
this
.
initCustomerActionStatisticWriter
();
List
<
CustomerNetworkStatistics
>
networkStatisticsList
=
this
.
customerNetworkStatisticsMapper
.
selectByDate
(
null
,
null
);
for
(
CustomerNetworkStatistics
networkStatistics
:
networkStatisticsList
)
{
Integer
onlineNumber
=
networkStatistics
.
getOnlineNumber
();
this
.
addCustomerActionStatisticsRecord
(
networkStatistics
,
"声控调用"
,
this
.
getRandomDouble
(
onlineNumber
,
5
,
9
));
this
.
addCustomerActionStatisticsRecord
(
networkStatistics
,
"收音机使用"
,
this
.
getRandomDouble
(
onlineNumber
,
28
,
33
));
this
.
addCustomerActionStatisticsRecord
(
networkStatistics
,
"导航调用"
,
this
.
getRandomDouble
(
onlineNumber
,
3
,
6
));
this
.
addCustomerActionStatisticsRecord
(
networkStatistics
,
"音乐使用"
,
this
.
getRandomDouble
(
onlineNumber
,
13
,
18
));
this
.
addCustomerActionStatisticsRecord
(
networkStatistics
,
"联网应用使用"
,
this
.
getRandomDouble
(
onlineNumber
,
2
,
4
));
}
this
.
closeCustomerActionStatisticsWriter
();
}
private
void
initCustomerActionStatisticWriter
()
{
try
{
this
.
customerActionStatisticsWriter
=
Files
.
newBufferedWriter
(
Paths
.
get
(
"D:/Users/wbh/Desktop/customer-action-statistics.sql"
));
this
.
customerActionStatisticsWriter
.
write
(
"insert into t_customer_action_statistics "
+
"(customer_id, customer_name, device_type, type, statistics_time, number) values"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
void
closeCustomerActionStatisticsWriter
()
{
try
{
this
.
customerActionStatisticsWriter
.
flush
();
this
.
customerActionStatisticsWriter
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
int
getRandomDouble
(
int
base
,
int
min
,
int
max
)
{
return
(
int
)
(((
double
)
base
)
*
RandomUtil
.
randomDouble
(
min
,
max
));
}
private
void
addCustomerActionStatisticsRecord
(
CustomerNetworkStatistics
networkStatistics
,
String
type
,
int
count
)
{
try
{
String
s
=
String
.
format
(
",\n(%d, '%s', '%s', '%s', '%s', %d)"
,
networkStatistics
.
getCustomerId
(),
networkStatistics
.
getCustomerName
(),
networkStatistics
.
getDeviceType
(),
type
,
networkStatistics
.
getStatisticsTime
(),
count
);
this
.
customerActionStatisticsWriter
.
write
(
s
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateCustomerNetworkStatistic.java
0 → 100644
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
;
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.hutool.core.date.DateUtil
;
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-02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Main
.
class
)
public
class
GenerateCustomerNetworkStatistic
{
@Autowired
private
CustomerNetworkStatisticsMapper
customerNetworkStatisticsMapper
;
@Test
public
void
generateData
()
{
Date
startDate
=
DateUtil
.
parse
(
"2019-01-01"
,
"yyyy-MM-dd"
);
Date
endDate
=
DateUtil
.
parse
(
"2021-01-01"
,
"yyyy-MM-dd"
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
calendar
.
add
(
Calendar
.
MONTH
,
1
);
Date
currentStartDate
=
startDate
;
Date
currentEndDate
=
calendar
.
getTime
();
while
(
currentStartDate
.
before
(
endDate
))
{
List
<
CustomerNetworkStatistics
>
statisticsList
=
this
.
customerNetworkStatisticsMapper
.
selectFromDeviceNetworkByDate
(
currentStartDate
,
currentEndDate
);
if
(!
statisticsList
.
isEmpty
())
{
this
.
customerNetworkStatisticsMapper
.
batchInsert
(
statisticsList
);
}
currentStartDate
=
currentEndDate
;
calendar
.
add
(
Calendar
.
MONTH
,
1
);
currentEndDate
=
calendar
.
getTime
();
}
}
}
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateDeviceActionDetail.java
0 → 100644
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
cn.com.glsx.openplatform.mapper.DeviceActionDetailMapper
;
import
cn.com.glsx.openplatform.model.DeviceActionDetail
;
import
cn.com.glsx.openplatform.model.DeviceNetworkDetail
;
import
cn.com.glsx.openplatform.model.PlatformDevice
;
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 2021-01-02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Main
.
class
)
public
class
GenerateDeviceActionDetail
{
@Autowired
private
DeviceActionDetailMapper
deviceActionDetailMapper
;
//@Autowired
//private DeviceNetworkDetailMapper deviceNetworkDetailMapper;
private
BufferedWriter
deviceActionDataWriter
;
private
BufferedWriter
deviceNetworkDataWriter
;
@Test
public
void
generateData
()
throws
IOException
{
this
.
initDeviceActionDataWriter
();
//this.initDeviceNetworkDataWriter();
Date
startDate
=
DateUtil
.
parseDate
(
"2019-01-01"
);
Date
endDate
=
DateUtil
.
parseDate
(
"2021-01-01"
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentStartDate
=
calendar
.
getTime
();
calendar
.
add
(
Calendar
.
MONTH
,
1
);
Date
currentEndDate
=
calendar
.
getTime
();
while
(
currentStartDate
.
before
(
endDate
))
{
// 获取所有类型的设备,按照设备类型进行生成
List
<
String
>
typeList
=
this
.
deviceActionDetailMapper
.
selectDeviceType
();
for
(
String
type
:
typeList
)
{
List
<
PlatformDevice
>
deviceList
=
this
.
getNeededDeviceList
(
currentStartDate
,
currentEndDate
,
type
);
this
.
generateDeviceActionData
(
currentStartDate
,
endDate
,
deviceList
);
//this.generateDeviceNetworkData(currentStartDate, deviceList);
}
currentStartDate
=
currentEndDate
;
calendar
.
add
(
Calendar
.
MONTH
,
1
);
currentEndDate
=
calendar
.
getTime
();
}
this
.
closeDeviceActionDataWriter
();
//this.closeDeviceNetworkDataWriter();
}
private
void
initDeviceNetworkDataWriter
()
throws
IOException
{
this
.
deviceNetworkDataWriter
=
Files
.
newBufferedWriter
(
Paths
.
get
(
"D:/Users/wbh/Desktop/device-network-data.sql"
));
this
.
deviceNetworkDataWriter
.
write
(
"insert into t_device_network_detail (device_sn, create_time) values"
);
}
private
void
closeDeviceNetworkDataWriter
()
throws
IOException
{
this
.
deviceNetworkDataWriter
.
flush
();
this
.
deviceNetworkDataWriter
.
close
();
}
private
void
initDeviceActionDataWriter
()
throws
IOException
{
this
.
deviceActionDataWriter
=
Files
.
newBufferedWriter
(
Paths
.
get
(
"D:/Users/wbh/Desktop/device-action-data.sql"
));
this
.
deviceActionDataWriter
.
write
(
"insert into t_device_action_detail (device_sn, type, create_time) values"
);
}
private
void
closeDeviceActionDataWriter
()
throws
IOException
{
this
.
deviceActionDataWriter
.
flush
();
this
.
deviceActionDataWriter
.
close
();
}
private
List
<
PlatformDevice
>
getNeededDeviceList
(
Date
startDate
,
Date
endDate
,
String
type
)
{
int
count
=
this
.
deviceActionDetailMapper
.
countByDate
(
startDate
,
endDate
,
type
);
// 取所有数量的 30% 左右
int
neededCount
=
this
.
getNumPercent
(
count
,
RandomUtil
.
randomInt
(
25
,
35
));
List
<
PlatformDevice
>
deviceList
=
this
.
deviceActionDetailMapper
.
selectByDate
(
startDate
,
endDate
,
neededCount
,
type
);
return
deviceList
;
}
private
void
generateDeviceActionData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
this
.
addDeviceActionSoundControlData
(
startDate
,
endDate
,
deviceList
);
this
.
addDeviceActionFmData
(
startDate
,
endDate
,
deviceList
);
this
.
addDeviceActionNavigationData
(
startDate
,
endDate
,
deviceList
);
this
.
addDeviceActionMusicData
(
startDate
,
endDate
,
deviceList
);
this
.
addDeviceActionInternetData
(
startDate
,
endDate
,
deviceList
);
}
private
void
generateDeviceNetworkData
(
Date
startDate
,
List
<
PlatformDevice
>
deviceList
)
{
this
.
addDeviceNetworkData
(
startDate
,
deviceList
);
}
private
int
getNumPercent
(
int
num
,
int
percent
)
{
return
num
*
percent
/
100
;
}
/**
* 生成声控调用数据
*
* @param startDate 开始日期
* @param endDate 结束日期
* @param deviceList 设备数据
*/
private
void
addDeviceActionSoundControlData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总数的 40% 左右,每天生成两条数据
int
twiceCount
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
35
,
45
));
List
<
PlatformDevice
>
twiceDeviceList
=
deviceList
.
subList
(
0
,
twiceCount
);
// 取剩余量的 60% 左右,每天生成一条数据
int
onceCount
=
this
.
getNumPercent
(
neededCount
-
twiceCount
,
RandomUtil
.
randomInt
(
55
,
65
));
List
<
PlatformDevice
>
onceDeviceList
=
deviceList
.
subList
(
twiceCount
,
twiceCount
+
onceCount
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentDate
=
startDate
;
while
(
currentDate
.
before
(
endDate
))
{
// 每天需要生成两条数据的
for
(
PlatformDevice
device
:
twiceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"声控调用"
,
2
,
currentDate
);
}
// 每天生成一条数据的
for
(
PlatformDevice
device
:
onceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"声控调用"
,
1
,
currentDate
);
}
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
currentDate
=
calendar
.
getTime
();
}
}
/**
* 生成声收音机使用数据
*
* @param startDate 开始日期
* @param endDate 结束日期
* @param deviceList 设备数据
*/
private
void
addDeviceActionFmData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总数的 70% 左右,每天生成一条数据
int
onceCount
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
65
,
75
));
List
<
PlatformDevice
>
onceDeviceList
=
deviceList
.
subList
(
0
,
onceCount
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentDate
=
startDate
;
while
(
currentDate
.
before
(
endDate
))
{
// 每天生成一条数据的
for
(
PlatformDevice
device
:
onceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"收音机使用"
,
1
,
currentDate
);
}
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
currentDate
=
calendar
.
getTime
();
}
}
/**
* 生成导航调用数据
*
* @param startDate 开始日期
* @param endDate 结束日期
* @param deviceList 设备数据
*/
private
void
addDeviceActionNavigationData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总数的 50% 左右,每天生成两条数据
int
twiceCount
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
45
,
55
));
List
<
PlatformDevice
>
twiceDeviceList
=
deviceList
.
subList
(
0
,
twiceCount
);
// 取剩余量的 50% 左右,每天生成一条数据
int
onceCount
=
this
.
getNumPercent
(
neededCount
-
twiceCount
,
RandomUtil
.
randomInt
(
45
,
55
));
List
<
PlatformDevice
>
onceDeviceList
=
deviceList
.
subList
(
twiceCount
,
twiceCount
+
onceCount
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentDate
=
startDate
;
while
(
currentDate
.
before
(
endDate
))
{
// 每天需要生成两条数据的
for
(
PlatformDevice
device
:
twiceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"导航调用"
,
2
,
currentDate
);
}
// 每天生成一条数据的
for
(
PlatformDevice
device
:
onceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"导航调用"
,
1
,
currentDate
);
}
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
currentDate
=
calendar
.
getTime
();
}
}
/**
* 生成音乐使用数据
*
* @param startDate 开始日期
* @param endDate 结束日期
* @param deviceList 设备数据
*/
private
void
addDeviceActionMusicData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总数的 70% 左右,每天生成一条数据
int
onceCount
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
65
,
75
));
List
<
PlatformDevice
>
onceDeviceList
=
deviceList
.
subList
(
0
,
onceCount
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentDate
=
startDate
;
while
(
currentDate
.
before
(
endDate
))
{
// 每天生成一条数据的
for
(
PlatformDevice
device
:
onceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"音乐使用"
,
1
,
currentDate
);
}
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
currentDate
=
calendar
.
getTime
();
}
}
/**
* 生成联网应用数据
*
* @param startDate 开始日期
* @param endDate 结束日期
* @param deviceList 设备数据
*/
private
void
addDeviceActionInternetData
(
Date
startDate
,
Date
endDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总数的 40% 左右,每天生成一条数据
int
onceCount
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
35
,
45
));
List
<
PlatformDevice
>
onceDeviceList
=
deviceList
.
subList
(
0
,
onceCount
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
Date
currentDate
=
startDate
;
while
(
currentDate
.
before
(
endDate
))
{
// 每天生成一条数据的
for
(
PlatformDevice
device
:
onceDeviceList
)
{
this
.
addDeviceActionDetailRecord
(
device
,
"联网应用使用"
,
1
,
currentDate
);
}
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
currentDate
=
calendar
.
getTime
();
}
}
/**
* 按照条件生成设备行为数据
*
* @param device 设备数据
* @param type 设备行为类型
* @param count 生成数量
* @param currentDate 当前日期
*/
private
void
addDeviceActionDetailRecord
(
PlatformDevice
device
,
String
type
,
int
count
,
Date
currentDate
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
currentDate
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
// 生成每日随机时间,范围为 06:00:00 ~ 22:59:59
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
RandomUtil
.
randomInt
(
6
,
23
));
calendar
.
set
(
Calendar
.
MINUTE
,
RandomUtil
.
randomInt
(
0
,
60
));
calendar
.
set
(
Calendar
.
SECOND
,
RandomUtil
.
randomInt
(
0
,
60
));
DeviceActionDetail
deviceActionDetail
=
new
DeviceActionDetail
();
deviceActionDetail
.
setDeviceSn
(
device
.
getDeviceSn
());
deviceActionDetail
.
setType
(
type
);
deviceActionDetail
.
setCreateTime
(
calendar
.
getTime
());
try
{
String
s
=
String
.
format
(
",\n('%s', '%s', '%s')"
,
deviceActionDetail
.
getDeviceSn
(),
deviceActionDetail
.
getType
(),
DateUtil
.
formatDateTime
(
deviceActionDetail
.
getCreateTime
()));
this
.
deviceActionDataWriter
.
write
(
s
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//this.deviceActionDetailMapper.insertSelective(deviceActionDetail);
}
}
private
void
addDeviceNetworkData
(
Date
startDate
,
List
<
PlatformDevice
>
deviceList
)
{
int
neededCount
=
deviceList
.
size
();
// 取总量的 20% 左右,生成小于 10 条数据
int
lt10Count
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
18
,
25
));
List
<
PlatformDevice
>
lt20DeviceList
=
deviceList
.
subList
(
0
,
lt10Count
);
for
(
PlatformDevice
device
:
lt20DeviceList
)
{
this
.
addDeviceNetworkDetailRecord
(
device
,
RandomUtil
.
randomInt
(
5
,
10
),
startDate
);
}
// 取总量的 60% 左右,生成 20 条数据
int
from10To20Count
=
this
.
getNumPercent
(
neededCount
,
RandomUtil
.
randomInt
(
55
,
65
));
List
<
PlatformDevice
>
from10To20DeviceList
=
deviceList
.
subList
(
lt10Count
,
lt10Count
+
from10To20Count
);
for
(
PlatformDevice
device
:
from10To20DeviceList
)
{
this
.
addDeviceNetworkDetailRecord
(
device
,
RandomUtil
.
randomInt
(
12
,
21
),
startDate
);
}
// 取总量的剩余,生成大于 20 条数据
List
<
PlatformDevice
>
gt20DeviceList
=
deviceList
.
subList
(
lt10Count
+
from10To20Count
,
neededCount
);
for
(
PlatformDevice
device
:
gt20DeviceList
)
{
this
.
addDeviceNetworkDetailRecord
(
device
,
RandomUtil
.
randomInt
(
21
,
31
),
startDate
);
}
}
/**
* 按照条件生成设备联网数据
*
* @param device 设备数据
* @param count 生成数量
* @param currentDate 当前日期
*/
private
void
addDeviceNetworkDetailRecord
(
PlatformDevice
device
,
int
count
,
Date
currentDate
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
currentDate
);
int
totalDayNum
=
calendar
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
// 生成随机时间,范围为 06:00:00 ~ 22:59:59
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
RandomUtil
.
randomInt
(
1
,
totalDayNum
+
1
));
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
RandomUtil
.
randomInt
(
6
,
23
));
calendar
.
set
(
Calendar
.
MINUTE
,
RandomUtil
.
randomInt
(
0
,
60
));
calendar
.
set
(
Calendar
.
SECOND
,
RandomUtil
.
randomInt
(
0
,
60
));
DeviceNetworkDetail
deviceNetworkDetail
=
new
DeviceNetworkDetail
();
deviceNetworkDetail
.
setDeviceSn
(
device
.
getDeviceSn
());
deviceNetworkDetail
.
setCreateTime
(
calendar
.
getTime
());
try
{
String
s
=
String
.
format
(
",\n('%s', '%s')"
,
deviceNetworkDetail
.
getDeviceSn
(),
DateUtil
.
formatDateTime
(
deviceNetworkDetail
.
getCreateTime
()));
deviceNetworkDataWriter
.
write
(
s
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//this.deviceNetworkDetailMapper.insertSelective(deviceNetworkDetail);
}
}
}
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateDeviceActionDetailByCustomer.java
0 → 100644
View file @
3fe033e
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
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Main
.
class
)
public
class
GenerateDeviceActionDetailByCustomer
{
@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.selectByMonth(
// 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
();
}
}
}
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GenerateFakeData.java
deleted
100644 → 0
View file @
d4b664f
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
;
}
}
rpc-openplatform-container/src/test/java/cn/com/glsx/openplatform/GeneratePlatformDevice.java
0 → 100644
View file @
3fe033e
package
cn
.
com
.
glsx
.
openplatform
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
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.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
GeneratePlatformDevice
{
@Autowired
private
ActivationDataMapper
activationDataMapper
;
@Autowired
private
PlatformDeviceMapper
deviceMapper
;
private
BufferedWriter
platformDeviceWriter
;
private
static
final
Map
<
Byte
,
String
>
TYPE_MAP
=
new
HashMap
<>();
private
static
final
Map
<
String
,
Integer
>
DEVICE_TYPE_MAP
=
new
HashMap
<>();
static
{
TYPE_MAP
.
put
((
byte
)
1
,
"通信模组"
);
TYPE_MAP
.
put
((
byte
)
2
,
"核心板"
);
TYPE_MAP
.
put
((
byte
)
3
,
"PCBA"
);
DEVICE_TYPE_MAP
.
put
(
"通信模组"
,
10
);
DEVICE_TYPE_MAP
.
put
(
"核心板"
,
10
);
DEVICE_TYPE_MAP
.
put
(
"PCBA-4G"
,
31
);
DEVICE_TYPE_MAP
.
put
(
"PCBA-360"
,
32
);
DEVICE_TYPE_MAP
.
put
(
"PCBA-AR"
,
33
);
DEVICE_TYPE_MAP
.
put
(
"PCBA-WIFI"
,
34
);
}
//@Test
//public void generatePlatformDevice() throws IOException {
// BufferedWriter writer = Files.newBufferedWriter(
// Paths.get("D:/Users/wbh/Desktop/platform-device.sql"));
// writer.write("insert into t_platform_device (device_sn, device_type, status, create_time, update_time, create_by, update_by) values ");
//
// List<ShipmentData> shipmentList = activationDataMapper.getShipmentList();
// List<String> addedDateList = new ArrayList<>();
//
// for (ShipmentData shipmentData : shipmentList) {
// String goodsTime = shipmentData.getGoodsTime();
// int goodsNum = shipmentData.getGoodsNum();
// Byte type = shipmentData.getType();
// DateTime startDate = DateUtil.parseDate(goodsTime);
// while (goodsNum > 0) {
// String startDateStr = DateUtil.formatDate(startDate);
// // 判断当天是否已经出货,如果没有出货则添加数据,否则不添加,直接往前推一天
// if (!addedDateList.contains(startDateStr)) {
// addedDateList.add(startDateStr);
// int serialNum = 1;
// int year = startDate.getField(DateField.YEAR);
// int month = startDate.getField(DateField.MONTH) + 1;
// int day = startDate.getField(DateField.DAY_OF_MONTH);
// DateTime currentDate = startDate.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, 5001) : 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(currentDate);
// record.setUpdateTime(currentDate);
// record.setCreateBy(0);
// record.setUpdateBy(0);
// String s = String.format(",\n('%s', '%s', %d, '%s', '%s', %d, %d)",
// record.getDeviceSn(), record.getDeviceType(), record.getStatus(),
// DateUtil.formatDateTime(record.getCreateTime()),
// DateUtil.formatDateTime(record.getUpdateTime()),
// record.getCreateBy(), record.getUpdateBy());
// writer.write(s);
// //this.deviceMapper.insertSelective(record);
// serialNum++;
// }
// goodsNum -= currentNum;
// }
// startDate = startDate.offsetNew(DateField.DAY_OF_MONTH, -1);
// }
// }
//
// writer.flush();
// writer.close();
//}
@Test
public
void
generatePlatformDevice
()
throws
IOException
{
this
.
initPlatformDeviceWriter
();
List
<
String
>
deviceTypeList
=
this
.
activationDataMapper
.
selectDeviceTypeList
();
Map
<
String
,
Integer
>
serialNumMap
=
new
HashMap
<>();
for
(
String
deviceType
:
deviceTypeList
)
{
List
<
ShipmentData
>
shipmentDataList
=
this
.
activationDataMapper
.
selectShipmentByType
(
deviceType
);
for
(
ShipmentData
shipmentData
:
shipmentDataList
)
{
// 获取需要的出货量
Integer
goodsNum
=
shipmentData
.
getGoodsNum
();
// 出货日期
String
goodsTime
=
shipmentData
.
getGoodsTime
();
// 序列号中的日期
Date
serialDate
=
DateUtil
.
parseDate
(
goodsTime
);
// 用于记下每天出货量
String
serialDateStr
=
goodsTime
;
while
(
goodsNum
>
0
)
{
// 如果当天没有记录出货则初始化出货量为 0
if
(!
serialNumMap
.
containsKey
(
serialDateStr
))
{
serialNumMap
.
put
(
serialDateStr
,
0
);
}
// 获取当天已经出货的量,作为起始序列号
int
startSerialNum
=
serialNumMap
.
get
(
serialDateStr
)
+
1
;
int
endSerialNum
;
int
randCount
=
goodsNum
>
5000
?
RandomUtil
.
randomInt
(
4000
,
5000
)
:
goodsNum
;
// 计算终止序列号
endSerialNum
=
(
startSerialNum
+
randCount
>
5000
)
?
RandomUtil
.
randomInt
(
4800
,
5000
)
:
(
startSerialNum
+
randCount
);
// 如果起始序列号大于终止序列号,则说明出货量已经满了,直接往前推一天
if
(
startSerialNum
<
endSerialNum
)
{
this
.
addPlatformDevice
(
shipmentData
,
serialDate
,
startSerialNum
,
endSerialNum
);
serialNumMap
.
put
(
serialDateStr
,
endSerialNum
-
1
);
// 需要出货量减去实际出货量
goodsNum
-=
endSerialNum
-
startSerialNum
;
}
serialDate
=
DateUtil
.
offsetDay
(
serialDate
,
-
1
);
serialDateStr
=
DateUtil
.
formatDate
(
serialDate
);
}
}
}
this
.
closePlatformDeviceWriter
();
}
@Test
public
void
fillPlatformDeviceActivation
()
{
}
private
void
initPlatformDeviceWriter
()
throws
IOException
{
this
.
platformDeviceWriter
=
Files
.
newBufferedWriter
(
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"
);
}
private
void
closePlatformDeviceWriter
()
throws
IOException
{
this
.
platformDeviceWriter
.
flush
();
this
.
platformDeviceWriter
.
close
();
}
private
void
addPlatformDevice
(
ShipmentData
shipmentData
,
Date
serialDate
,
int
startSerialNum
,
int
endSerialNum
)
{
Date
createDate
=
DateUtil
.
parseDate
(
shipmentData
.
getGoodsTime
());
for
(
int
serialNum
=
startSerialNum
;
serialNum
<
endSerialNum
;
serialNum
++)
{
String
deviceSn
=
String
.
format
(
"%02d%02d%02d%02d%04d"
,
DEVICE_TYPE_MAP
.
get
(
shipmentData
.
getDeviceType
()),
DateUtil
.
year
(
serialDate
)
%
100
,
DateUtil
.
month
(
serialDate
)
+
1
,
DateUtil
.
dayOfMonth
(
serialDate
),
serialNum
);
PlatformDevice
device
=
new
PlatformDevice
();
device
.
setDeviceSn
(
deviceSn
);
device
.
setDeviceType
(
shipmentData
.
getDeviceType
());
device
.
setVersion
(
shipmentData
.
getVersion
());
device
.
setCustomerId
(
shipmentData
.
getCustomerId
());
device
.
setCustomerName
(
shipmentData
.
getCustomerName
());
device
.
setStatus
(
1
);
device
.
setCreateTime
(
createDate
);
device
.
setUpdateTime
(
createDate
);
device
.
setCreateBy
(
0
);
device
.
setUpdateBy
(
0
);
try
{
String
s
=
String
.
format
(
",\n('%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d)"
,
device
.
getDeviceSn
(),
device
.
getDeviceType
(),
device
.
getVersion
(),
device
.
getCustomerId
(),
device
.
getStatus
(),
DateUtil
.
formatDateTime
(
device
.
getCreateTime
()),
DateUtil
.
formatDateTime
(
device
.
getUpdateTime
()),
device
.
getCreateBy
(),
device
.
getUpdateBy
());
this
.
platformDeviceWriter
.
write
(
s
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
@Test
public
void
generateDeviceActivationData
()
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
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment