Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 41a5fb7f
authored
Nov 22, 2021
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加不在店统计任务执行逻辑
1 parent
73a2338c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
209 additions
and
5 deletions
src/main/java/cn/com/glsx/stdinterface/modules/controller/StatisticsInStoreController.java
src/main/java/cn/com/glsx/stdinterface/modules/mapper/StatisticsInStoreMapper.java
src/main/java/cn/com/glsx/stdinterface/modules/model/StatisticsDrive.java
src/main/java/cn/com/glsx/stdinterface/modules/model/StatisticsInstore.java
src/main/java/cn/com/glsx/stdinterface/modules/service/StatisticsDriveService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/StatisticsInStoreService.java
src/main/resources/mapper/StatisticsInstoreMapper.xml
src/test/java/cn/com/glsx/stdinterface/modules/service/StatisticsInStoreServiceTest.java
src/main/java/cn/com/glsx/stdinterface/modules/controller/StatisticsInStoreController.java
0 → 100644
View file @
41a5fb7
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
controller
;
import
cn.com.glsx.stdinterface.modules.service.StatisticsInStoreService
;
import
com.glsx.plat.common.annotation.SysLog
;
import
com.glsx.plat.common.enums.OperateType
;
import
com.glsx.plat.core.web.R
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 试驾统计 Controller
*/
@Slf4j
@RestController
@RequestMapping
(
value
=
"/statisticsinstore"
)
@Api
(
value
=
"不在店统计数据"
,
tags
=
{
"不在店统计数据"
})
public
class
StatisticsInStoreController
{
private
final
static
String
MODULE
=
"不在店统计数据"
;
@Autowired
private
StatisticsInStoreService
statisticsInStoreService
;
@GetMapping
(
value
=
"/statisticsandinsertinstoredatalist"
)
@SysLog
(
module
=
MODULE
,
value
=
"查询并插入在店统计数据"
,
action
=
OperateType
.
QUERY
)
@ApiOperation
(
value
=
"查询并插入在店统计数据"
)
public
R
<
Integer
>
statisticsAndInsertDriveDataEveryDay
()
{
log
.
info
(
"开始查询不在店统计数据并插入到统计表中==="
);
Integer
num
=
statisticsInStoreService
.
statisticsAndInsertInStoreDataEveryDay
();
return
R
.
ok
().
data
(
num
);
}
}
src/main/java/cn/com/glsx/stdinterface/modules/mapper/StatisticsInStoreMapper.java
0 → 100644
View file @
41a5fb7
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
mapper
;
import
cn.com.glsx.stdinterface.modules.model.StatisticsInstore
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
* 试驾统计 mapper
*/
@Mapper
public
interface
StatisticsInStoreMapper
extends
CommonBaseMapper
<
StatisticsInstore
>
{
/**
* 统计并插入每一天的数据总和
*
* @param yesterDayFormat 昨天的日期
*/
Integer
statisticsAndInsertInStoreDataEveryDay
(
@Param
(
"yesterDayFormat"
)
String
yesterDayFormat
);
}
src/main/java/cn/com/glsx/stdinterface/modules/model/StatisticsDrive.java
View file @
41a5fb7
...
@@ -2,9 +2,7 @@ package cn.com.glsx.stdinterface.modules.model;
...
@@ -2,9 +2,7 @@ package cn.com.glsx.stdinterface.modules.model;
import
lombok.Data
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.*
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -21,6 +19,8 @@ public class StatisticsDrive implements Serializable {
...
@@ -21,6 +19,8 @@ public class StatisticsDrive implements Serializable {
*
*
*/
*/
@Id
@Id
@Column
(
name
=
"id"
,
unique
=
true
,
nullable
=
false
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
,
generator
=
"SELECT LAST_INSERT_ID()"
)
private
Integer
id
;
private
Integer
id
;
/**
/**
* 设备号
* 设备号
...
...
src/main/java/cn/com/glsx/stdinterface/modules/model/StatisticsInstore.java
0 → 100644
View file @
41a5fb7
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
model
;
import
lombok.Data
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 在店数据统计实体类
* 作者: Yanglinlong
* 日期: 2021/11/22
*/
@Table
(
name
=
"t_statistics_instore_drive"
)
@Data
public
class
StatisticsInstore
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Column
(
name
=
"id"
,
unique
=
true
,
nullable
=
false
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
,
generator
=
"SELECT LAST_INSERT_ID()"
)
private
Integer
id
;
/**
* 设备号
*/
private
String
sn
;
/**
* 当天是否在店数据
*/
@Column
(
name
=
"instore_num"
)
private
Integer
instoreNum
;
/**
* 在店日期
*/
@Column
(
name
=
"instore_time"
)
private
String
instoreTime
;
/**
* 车辆设备关系表id
*/
@Column
(
name
=
"vd_id"
)
private
Integer
vdId
;
/**
* 创建时间
*/
@Column
(
name
=
"created_time"
)
private
Date
createdTime
;
/**
* 更新时间
*/
@Column
(
name
=
"updated_time"
)
private
Date
updatedTime
;
}
src/main/java/cn/com/glsx/stdinterface/modules/service/StatisticsDriveService.java
View file @
41a5fb7
...
@@ -59,9 +59,9 @@ public class StatisticsDriveService {
...
@@ -59,9 +59,9 @@ public class StatisticsDriveService {
Calendar
cal
=
Calendar
.
getInstance
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
add
(
Calendar
.
DATE
,
-
1
);
cal
.
add
(
Calendar
.
DATE
,
-
1
);
String
yesterDayFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
cal
.
getTime
());
String
yesterDayFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
cal
.
getTime
());
log
.
info
(
"数据统计的天数==="
+
yesterDayFormat
);
log
.
info
(
"
[试驾统计]
数据统计的天数==="
+
yesterDayFormat
);
Integer
num
=
statisticsDriveMapper
.
statisticsAndInsertDriveDataEveryDay
(
yesterDayFormat
);
Integer
num
=
statisticsDriveMapper
.
statisticsAndInsertDriveDataEveryDay
(
yesterDayFormat
);
log
.
info
(
"插入到统计表的数据行数==="
+
num
);
log
.
info
(
"
[试驾统计]
插入到统计表的数据行数==="
+
num
);
return
num
;
return
num
;
}
}
}
}
src/main/java/cn/com/glsx/stdinterface/modules/service/StatisticsInStoreService.java
0 → 100644
View file @
41a5fb7
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.stdinterface.modules.mapper.StatisticsInStoreMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
/**
* 项目名:ne-shield-standard-interfaces
* 包名: cn.com.glsx.stdinterface.modules.service
* 作者: Yanglinlong
* 日期: 2021/8/25 14:27
*/
@Slf4j
@Service
public
class
StatisticsInStoreService
{
@Autowired
private
StatisticsInStoreMapper
statisticsInStoreMapper
;
/**
* 统计每天的数据并插入
*
* @return 成功插入的行数
*/
public
Integer
statisticsAndInsertInStoreDataEveryDay
()
{
// 获取昨天的日期
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
add
(
Calendar
.
DATE
,
-
1
);
String
yesterDayFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
cal
.
getTime
());
log
.
info
(
"[不在店统计]数据统计的天数==="
+
yesterDayFormat
);
Integer
num
=
statisticsInStoreMapper
.
statisticsAndInsertInStoreDataEveryDay
(
yesterDayFormat
);
log
.
info
(
"[不在店统计]插入到统计表的数据行数==="
+
num
);
return
num
;
}
}
src/main/resources/mapper/StatisticsInstoreMapper.xml
0 → 100644
View file @
41a5fb7
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"cn.com.glsx.stdinterface.modules.mapper.StatisticsInStoreMapper"
>
<resultMap
id=
"BaseMap"
type=
"cn.com.glsx.stdinterface.modules.model.StatisticsInstore"
>
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"sn"
property=
"sn"
jdbcType=
"VARCHAR"
/>
<result
column=
"instore_num"
property=
"instoreNum"
jdbcType=
"INTEGER"
/>
<result
column=
"instore_time"
property=
"instoreTime"
jdbcType=
"VARCHAR"
/>
<result
column=
"vd_id"
property=
"vdId"
jdbcType=
"INTEGER"
/>
<result
column=
"created_time"
property=
"createdTime"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"updated_time"
property=
"updatedTime"
jdbcType=
"TIMESTAMP"
/>
</resultMap>
<sql
id=
"BaseColumns"
>
a.id, a.sn, a.instore_num, a.instore_time, a.vd_id, a.created_time, a.updated_time
</sql>
<insert
id=
"statisticsAndInsertInStoreDataEveryDay"
>
INSERT t_statistics_instore_drive (instore_num ,instore_time ,vd_id ,created_time)
select
case when sum(case when gps_state = 2 then 1 else 0 end) = count(1) then 1 else 0 end as instore_num ,
left(gps_time,10) as instore_time ,
vd_id ,
NOW()
from t_electric_instore_drive
where left(gps_time,10) = #{yesterDayFormat}
GROUP BY vd_id;
</insert>
</mapper>
\ No newline at end of file
\ No newline at end of file
src/test/java/cn/com/glsx/stdinterface/modules/service/StatisticsInStoreServiceTest.java
0 → 100644
View file @
41a5fb7
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.Application
;
import
lombok.extern.slf4j.Slf4j
;
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.SpringRunner
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
StatisticsInStoreServiceTest
{
@Autowired
private
StatisticsInStoreService
statisticsInStoreService
;
@Test
public
void
statisticsAndInsertDriveDataEveryDay
()
{
Integer
num
=
statisticsInStoreService
.
statisticsAndInsertInStoreDataEveryDay
();
System
.
out
.
println
(
"statisticsAndInsertDriveDataEveryDay = "
+
num
);
}
}
\ No newline at end of file
\ No newline at end of file
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