Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王衍超
cloud-fb
Commits
f74dedff
Commit
f74dedff
authored
Nov 12, 2021
by
高晓磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传并压缩
parent
ecc8ad25
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
212 additions
and
43 deletions
+212
-43
WeighbridgeSyncController.java
...m/xyst/dinas/transport/web/WeighbridgeSyncController.java
+212
-43
No files found.
backend/xyst.dinas.transport/src/main/java/com/xyst/dinas/transport/web/WeighbridgeSyncController.java
View file @
f74dedff
package
com
.
xyst
.
dinas
.
transport
.
web
;
import
com.beecode.bap.attachment.AttachmentConstants
;
import
com.beecode.bap.attachment.AttachmentInfo
;
import
com.beecode.bap.attachment.common.Utils
;
import
com.beecode.bap.attachment.exception.AttachmentDataUploadException
;
import
com.beecode.bap.attachment.service.AttachmentService
;
import
com.beecode.bcp.type.KObject
;
import
com.beecode.inz.basis.team.pojo.ResponseObj
;
import
com.xyst.dinas.biz.service.StationService
;
...
...
@@ -9,18 +14,21 @@ import com.xyst.dinas.sales.service.SalesPlanService;
import
com.xyst.dinas.sales.service.SalesRecordService
;
import
com.xyst.dinas.sales.web.info.SalesRecordInfo
;
import
com.xyst.dinas.transport.service.VehicleDispatchService
;
import
net.coobird.thumbnailator.Thumbnails
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItemFactory
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.math.BigDecimal
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.*
;
@RestController
/**
...
...
@@ -42,7 +50,8 @@ public class WeighbridgeSyncController {
private
VehicleDispatchService
vehicleDispatchService
;
@Autowired
private
InventoryService
inventoryService
;
@Autowired
private
AttachmentService
attachmentService
;
/**
...
...
@@ -52,94 +61,254 @@ public class WeighbridgeSyncController {
* @return
*/
@PostMapping
(
value
=
"/weighbridgeSync/saveSalesRecord"
,
consumes
=
"application/json"
)
public
Object
saveSalesRecord
(
@RequestParam
String
weighbridgeCode
,
@RequestBody
SalesRecordInfo
salesRecordList
)
{
public
Object
saveSalesRecord
(
@RequestParam
String
weighbridgeCode
,
@RequestBody
SalesRecordInfo
salesRecordList
)
{
//根据地磅id查询场站
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
}
KObject
station
=
stationService
.
getStationByWeighbridge
(
weighbridgeCode
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
}
if
(
salesRecordList
==
null
)
{
if
(
salesRecordList
==
null
)
{
return
ResponseObj
.
error
(
"传递的销售台账数据条数为0!请确认!"
);
}
else
{
return
ResponseObj
.
success
(
"新增成功"
,
salesRecordService
.
saveSalesRecordService
(
salesRecordList
,
station
));
return
ResponseObj
.
success
(
"新增成功"
,
salesRecordService
.
saveSalesRecordService
(
salesRecordList
,
station
));
}
}
/**
* 根据车牌号和地磅唯一编码获取本场站下本车辆今日销售计划和临时销售计划
*
* @param
* @return
*/
@PostMapping
(
"/weighbridgeSync/getSalePlanDetail"
)
public
Object
approveSalesPlan
(
@RequestParam
String
weighbridgeCode
,
@RequestParam
String
carNum
)
{
public
Object
approveSalesPlan
(
@RequestParam
String
weighbridgeCode
,
@RequestParam
String
carNum
)
{
//根据地磅id查询场站
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
}
KObject
station
=
stationService
.
getStationByWeighbridge
(
weighbridgeCode
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
}
if
(
StringUtils
.
isBlank
(
carNum
))
{
return
ResponseObj
.
error
(
500
,
"车牌号不能为空"
);
if
(
StringUtils
.
isBlank
(
carNum
))
{
return
ResponseObj
.
error
(
500
,
"车牌号不能为空"
);
}
//根据车牌查询所属合同和销售计划
List
<
Map
<
String
,
Object
>>
salesPlan
=
salesPlanService
.
querySalesPlanByCarNum
(
station
,
carNum
);
List
<
Map
<
String
,
Object
>>
salesPlan
=
salesPlanService
.
querySalesPlanByCarNum
(
station
,
carNum
);
Collection
<?
extends
Map
<
String
,
Object
>>
maps
=
vehicleDispatchService
.
vehicleDispatchService
(
station
,
carNum
);
if
(
maps
!=
null
)
{
if
(
maps
!=
null
)
{
salesPlan
.
addAll
(
maps
);
}
return
ResponseObj
.
success
(
"查询成功"
,
salesPlan
);
return
ResponseObj
.
success
(
"查询成功"
,
salesPlan
);
}
/**
* 根据车牌号和地磅唯一编码获取本场站下本车辆今日销售计划和临时销售计划
*
* @param
* @return
*/
@PostMapping
(
"/weighbridgeSync/getDinasTypePrice"
)
public
Object
getDinasTypePrice
(
@RequestParam
String
weighbridgeCode
,
@RequestParam
String
carNum
,
@RequestParam
String
dinasTypeId
)
{
@PostMapping
(
"/weighbridgeSync/uploadFile"
)
public
Object
getDinasTypePrice
(
@RequestParam
String
weighbridgeCode
,
@RequestParam
String
recordId
,
@RequestParam
(
"files"
)
MultipartFile
[]
file
)
{
if
(
null
==
file
||
file
.
length
<
1
)
{
return
ResponseObj
.
error
(
500
,
"文件不能为空"
);
}
//根据地磅id查询场站
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
}
KObject
station
=
stationService
.
getStationByWeighbridge
(
weighbridgeCode
);
if
(
station
==
null
){
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
}
if
(
StringUtils
.
isBlank
(
carNum
)){
return
ResponseObj
.
error
(
500
,
"车牌号不能为空"
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
}
if
(
StringUtils
.
isBlank
(
dinasTypeId
)){
return
ResponseObj
.
error
(
500
,
"砂石类型不能为空"
);
//根据查询地磅id
if
(
StringUtils
.
isBlank
(
recordId
))
{
return
ResponseObj
.
error
(
500
,
"地磅记录不能为空"
);
}
KObject
itemByStationIdAndDinasTypeId
=
inventoryService
.
getItemByStationIdAndDinasTypeId
(
station
.
getUuid
(
"id"
),
UUID
.
fromString
(
"dinasTypeId"
));
BigDecimal
price
=
itemByStationIdAndDinasTypeId
.
getBigDecimal
(
"price"
);
return
ResponseObj
.
success
(
"查询成功"
,
price
);
return
ResponseObj
.
success
(
"查询成功"
,
price
);
}
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
POST
)
public
ResponseObj
<
UUID
>
upload
(
@RequestParam
(
name
=
"belongId"
,
required
=
false
)
UUID
belongId
,
@RequestParam
(
"files"
)
MultipartFile
[]
files
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
if
(
belongId
==
null
)
{
belongId
=
UUID
.
randomUUID
();
}
checkFileUpload
(
files
);
try
{
for
(
MultipartFile
file
:
files
)
{
File
file1
=
new
File
(
""
);
Thumbnails
.
of
(
file
.
getInputStream
())
.
scale
(
0.9f
)
.
toFile
(
file1
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
file1
);
AttachmentInfo
info
=
generateInfo
(
belongId
,
"saleRecord"
,
true
,
userAgent
,
file
.
getOriginalFilename
(),
file1
.
length
());
return
ResponseObj
.
response
(
200
,
"保存成功"
,
attachmentService
.
insert
(
info
,
fileInputStream
));
}
}
catch
(
IOException
e
)
{
throw
new
AttachmentDataUploadException
(
"文件上传失败,"
+
e
.
getMessage
(),
e
);
}
return
ResponseObj
.
response
(
500
,
"保存失败"
,
null
);
}
/**
* FileItem类对象创建
*
* @param inputStream inputStream
* @param fileName fileName
* @return FileItem
*/
private
FileItem
createFileItem
(
InputStream
inputStream
,
String
fileName
)
{
FileItemFactory
factory
=
new
DiskFileItemFactory
(
16
,
null
);
String
textFieldName
=
"file"
;
FileItem
item
=
factory
.
createItem
(
textFieldName
,
MediaType
.
MULTIPART_FORM_DATA_VALUE
,
true
,
fileName
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
//使用输出流输出输入流的字节
try
(
OutputStream
os
=
item
.
getOutputStream
())
{
while
((
bytesRead
=
inputStream
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
inputStream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
IllegalArgumentException
(
"文件上传失败"
);
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
}
return
item
;
}
public
static
File
byte2File
(
byte
[]
buf
,
String
filePath
,
String
fileName
)
{
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
File
file
=
null
;
try
{
File
dir
=
new
File
(
filePath
);
if
(!
dir
.
exists
()
&&
dir
.
isDirectory
())
{
dir
.
mkdirs
();
}
file
=
new
File
(
filePath
+
File
.
separator
+
fileName
);
fos
=
new
FileOutputStream
(
file
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
buf
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
file
;
}
// outputStream转inputStream
public
ByteArrayInputStream
parse
(
OutputStream
out
)
throws
Exception
{
ByteArrayOutputStream
baos
;
baos
=
(
ByteArrayOutputStream
)
out
;
return
new
ByteArrayInputStream
(
baos
.
toByteArray
());
}
private
String
getFileNameByIE
(
String
fileName
)
{
String
[]
fileNameArray
=
fileName
.
split
(
"\\\\"
);
return
fileNameArray
[
fileNameArray
.
length
-
1
];
}
private
boolean
isIE
(
String
userAgent
)
{
if
(
userAgent
!=
null
)
{
userAgent
=
userAgent
.
toLowerCase
();
return
userAgent
.
contains
(
"msie"
)
||
userAgent
.
contains
(
"trident"
)
||
userAgent
.
contains
(
"edge"
);
}
return
false
;
}
private
AttachmentInfo
generateInfo
(
UUID
belongId
,
String
category
,
boolean
anonymous
,
String
userAgent
,
String
fileName
,
Long
fileSize
)
{
AttachmentInfo
attachmentInfo
=
new
AttachmentInfo
();
attachmentInfo
.
setBelongId
(
belongId
);
if
(
category
!=
null
&&
!
""
.
equals
(
category
))
{
attachmentInfo
.
setCategory
(
category
);
}
if
(
anonymous
)
{
attachmentInfo
.
setFileName
(
UUID
.
randomUUID
()
+
"."
+
Utils
.
getFileType
(
Objects
.
requireNonNull
(
fileName
)));
}
else
if
(
isIE
(
userAgent
))
{
// macOS系统存在含‘\’文件名的文件所以分开写
attachmentInfo
.
setFileName
(
getFileNameByIE
(
Objects
.
requireNonNull
(
fileName
)));
}
else
{
attachmentInfo
.
setFileName
(
fileName
);
}
attachmentInfo
.
setFileType
(
Utils
.
getFileType
(
Objects
.
requireNonNull
(
fileName
)));
attachmentInfo
.
setSize
(
fileSize
);
return
attachmentInfo
;
}
private
void
checkFileUpload
(
MultipartFile
[]
files
)
{
Assert
.
isTrue
(
files
.
length
<
AttachmentConstants
.
FileCheck
.
MAXTOTAL
,
"文件数量不能超过30!"
);
for
(
MultipartFile
file
:
files
)
{
checkFileUpload
(
file
);
}
}
private
void
checkFileUpload
(
MultipartFile
file
)
{
Assert
.
isTrue
(!
AttachmentConstants
.
FileCheck
.
NOTSUPPORTFILETYPE
.
contains
(
Utils
.
getFileType
(
file
.
getOriginalFilename
())),
"不支持的文件类型"
);
Assert
.
isTrue
(
file
.
getSize
()
<
AttachmentConstants
.
FileCheck
.
MAXLENGTH
,
"单个文件大小不能超过30m!"
);
}
/**
* 查询全部售卖的砂石类型和价格
*
* @param
* @return
*/
@PostMapping
(
"/weighbridgeSync/getAllDinasType"
)
public
Object
getAllDinasType
(
@RequestParam
String
weighbridgeCode
)
{
//根据地磅id查询场站
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
if
(
StringUtils
.
isBlank
(
weighbridgeCode
))
{
return
ResponseObj
.
error
(
500
,
"地磅唯一编码不能为空"
);
}
KObject
station
=
stationService
.
getStationByWeighbridge
(
weighbridgeCode
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
if
(
station
==
null
)
{
return
ResponseObj
.
error
(
500
,
"没有查询到地磅匹配的场站"
);
}
List
<
StationDinasTypeRelation
>
allDinasTypes
=
inventoryService
.
getItemListByStationId
(
station
.
getUuid
(
"id"
));
return
ResponseObj
.
success
(
"查询成功"
,
allDinasTypes
);
return
ResponseObj
.
success
(
"查询成功"
,
allDinasTypes
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment