Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-trialdrive-admin
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 cecaa57b
authored
Jun 08, 2021
by
黄小葱
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
批量导入试驾车辆优化
1 parent
6e10c9e5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
13 deletions
src/main/java/cn/com/glsx/admin/common/enums/ResultEnum.java
src/main/java/cn/com/glsx/admin/modules/controller/VehicleController.java
src/main/java/cn/com/glsx/admin/modules/model/imports/TrialDriveVehicleImport.java
src/main/java/cn/com/glsx/admin/modules/model/imports/TrialDriveVehicleImportListener.java
src/main/java/cn/com/glsx/admin/modules/service/DictService.java
src/main/java/cn/com/glsx/admin/modules/service/UserApiService.java
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
src/main/java/cn/com/glsx/admin/common/enums/ResultEnum.java
View file @
cecaa57
...
...
@@ -32,7 +32,8 @@ public enum ResultEnum {
EXIST_VEHICLE
(
12120006
,
"该车辆已存在:vin %s"
),
IMPORT_SIZE_TIP
(
12120007
,
"每次只能导入 %s 条。"
),
IMPORT_EMPTY
(
12120008
,
"导入的数据为空。"
),
PARSE_EXCEL_ERROR
(
12120002
,
"解析excel文件异常"
),
PARSE_EXCEL_ERROR
(
12120009
,
"解析excel文件异常"
),
IMPORT_FIAL_ERROR
(
12120010
,
"导入数据异常"
),
/**
* 拆除报警
...
...
src/main/java/cn/com/glsx/admin/modules/controller/VehicleController.java
View file @
cecaa57
...
...
@@ -108,7 +108,7 @@ public class VehicleController {
@ApiOperation
(
value
=
"导入试驾车辆数据"
)
@PostMapping
(
value
=
"/drivevehicle/import"
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
public
R
importDriveVehicle
(
@RequestPar
t
(
"file"
)
MultipartFile
file
)
throws
IOException
{
public
R
importDriveVehicle
(
@RequestPar
am
(
"file"
)
MultipartFile
file
)
throws
IOException
{
TrialDriveVehicleImportListener
listener
=
new
TrialDriveVehicleImportListener
(
vehicleService
,
deviceService
);
EasyExcel
.
read
(
file
.
getInputStream
(),
TrialDriveVehicleImport
.
class
,
listener
)
.
head
(
TrialDriveVehicleImport
.
class
)
...
...
src/main/java/cn/com/glsx/admin/modules/model/imports/TrialDriveVehicleImport.java
View file @
cecaa57
package
cn
.
com
.
glsx
.
admin
.
modules
.
model
.
imports
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
lombok.Data
;
import
scala.Int
;
import
java.io.Serializable
;
...
...
@@ -11,6 +13,8 @@ import java.io.Serializable;
@Data
public
class
TrialDriveVehicleImport
implements
Serializable
{
@ExcelIgnore
private
Long
userId
;
/**
* 特约店名称
*/
...
...
@@ -32,11 +36,21 @@ public class TrialDriveVehicleImport implements Serializable {
@ExcelProperty
(
value
=
"*车型"
,
index
=
3
)
private
String
modelName
;
/**
* 车型id
*/
@ExcelIgnore
private
Integer
modelId
;
/**
* 配置
*/
@ExcelProperty
(
value
=
"*配置"
,
index
=
4
)
private
String
configDesc
;
/**
* 配置id
*/
@ExcelIgnore
private
Integer
configId
;
/**
* 车牌
*/
@ExcelProperty
(
value
=
"车牌"
,
index
=
5
)
...
...
src/main/java/cn/com/glsx/admin/modules/model/imports/TrialDriveVehicleImportListener.java
View file @
cecaa57
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/glsx/admin/modules/service/DictService.java
View file @
cecaa57
...
...
@@ -38,6 +38,19 @@ public class DictService {
return
dictDataList
.
get
(
0
);
}
/**
* 根据车型查找对应数据
* @param type
* @return
*/
public
List
<
SysDictDataResponse
>
listDictDataByType
(
String
type
)
{
FindDictDataRequest
request
=
new
FindDictDataRequest
();
request
.
setDictType
(
type
);
R
<
List
<
SysDictDataResponse
>>
listR
=
dictDataService
.
findByDict
(
request
);
List
<
SysDictDataResponse
>
dictDataList
=
listR
.
getDataList
(
new
TypeToken
<
List
<
SysDictDataResponse
>>(){}.
getType
());
return
dictDataList
;
}
}
src/main/java/cn/com/glsx/admin/modules/service/UserApiService.java
View file @
cecaa57
...
...
@@ -76,4 +76,18 @@ public class UserApiService {
}
return
userId
;
}
/**
* 查找所有用户信息
* @return
*/
public
List
<
User
>
findAllUser
()
{
R
<
List
<
User
>>
listR
=
userService
.
findAll
();
if
(
listR
==
null
||
!
listR
.
isSuccess
())
{
return
null
;
}
List
<
User
>
userList
=
listR
.
getDataList
(
new
TypeToken
<
List
<
User
>>()
{
}.
getType
());
return
userList
;
}
}
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
View file @
cecaa57
...
...
@@ -34,6 +34,7 @@ import com.google.errorprone.annotations.FormatString;
import
com.google.gson.reflect.TypeToken
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -44,6 +45,7 @@ import java.io.FileNotFoundException;
import
java.io.InputStream
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
* @Desc:试驾车辆service
...
...
@@ -439,23 +441,13 @@ public class VehicleService {
//保存车辆
Vehicle
vehicle
=
new
Vehicle
();
BeanUtils
.
copyProperties
(
vi
,
vehicle
);
//匹配车辆配置和车型
SysDictDataResponse
modelDict
=
dictService
.
getDictDataByLabelAndType
(
vehicle
.
getModelName
(),
Constants
.
TRIALDRIVE_VEHICLE_MODEL
);
if
(
modelDict
!=
null
)
{
vehicle
.
setModelId
(
Math
.
toIntExact
(
modelDict
.
getId
()));
}
modelDict
=
dictService
.
getDictDataByLabelAndType
(
vehicle
.
getConfigDesc
(),
Constants
.
TRIALDRIVE_VEHICLE_CONFIG
);
if
(
modelDict
!=
null
)
{
vehicle
.
setConfigId
(
Math
.
toIntExact
(
modelDict
.
getId
()));
}
String
serveType
=
vi
.
getServeTypeStr
();
if
(
ConstantsVehicle
.
VEHICLE_TYPE_PLATE_STR
.
equals
(
serveType
.
trim
()))
{
vehicle
.
setServeType
(
ConstantsVehicle
.
VEHICLE_TYPE_PLATE
);
}
else
{
vehicle
.
setServeType
(
ConstantsVehicle
.
UN_VEHICLE_TYPE_PLATE
);
}
List
<
User
>
userList
=
findByNameAndCode
(
vi
.
getShopName
(),
vi
.
getShopCode
());
vehicle
.
setCreatedBy
(
userList
.
get
(
0
).
getId
());
vehicle
.
setCreatedBy
(
vi
.
getUserId
());
vehicle
.
setCreatedDate
(
new
Date
());
vehicle
.
setVehicleType
(
ConstantsVehicle
.
TRIAL_DRIVE_TYPE
);
vehicle
.
setServeType
(
ConstantsVehicle
.
UN_VEHICLE_TYPE_PLATE
);
...
...
@@ -494,4 +486,44 @@ public class VehicleService {
userRequest
.
setAccount
(
shopCode
);
return
userApiService
.
findByUser
(
userRequest
);
}
/**
* 批量插入数据
* @param driveList
*/
public
void
insertVehicleAndSnList
(
List
<
TrialDriveVehicleImport
>
driveList
)
{
for
(
TrialDriveVehicleImport
trialDrive
:
driveList
)
{
this
.
insertVehicleAndSn
(
trialDrive
);
}
}
/**
* 根据类型封装字典 key:id, value:DictLabel
* @param type
* @return
*/
public
Map
<
String
,
Integer
>
getDictDataByType
(
String
type
)
{
List
<
SysDictDataResponse
>
sysDictDataResponses
=
dictService
.
listDictDataByType
(
type
);
Map
<
String
,
Integer
>
dictMap
=
new
HashedMap
();
for
(
SysDictDataResponse
dictData
:
sysDictDataResponses
)
{
dictMap
.
put
(
dictData
.
getDictLabel
(),
Math
.
toIntExact
(
dictData
.
getId
()));
}
return
dictMap
;
}
/**
* 封装用户信息 key:门店编码 value:id
* @return
*/
public
Map
<
String
,
Long
>
findUserIdMapByAccount
()
{
Map
<
String
,
Long
>
userMap
=
new
HashedMap
();
List
<
User
>
userList
=
userApiService
.
findAllUser
();
if
(
userList
==
null
)
{
return
userMap
;
}
for
(
User
user
:
userList
)
{
userMap
.
put
(
user
.
getAccount
(),
user
.
getId
());
}
return
userMap
;
}
}
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