Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smalltools
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王家辉
smalltools
Commits
85c5c37a
Commit
85c5c37a
authored
Feb 12, 2019
by
wjh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置swagger
parent
ae8a63f6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
224 deletions
+77
-224
src/main/java/com/freemud/Controller/OrdersController.java
+10
-16
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
+4
-0
src/main/java/com/freemud/SmalltoolsApplication.java
+16
-0
src/main/java/com/freemud/config/Swagger2Config.java
+40
-0
src/main/java/com/freemud/dto/OrderProductDTO.java
+7
-5
src/main/java/com/freemud/utils/FileOperationUtils.java
+0
-203
No files found.
src/main/java/com/freemud/Controller/OrdersController.java
View file @
85c5c37a
...
...
@@ -15,6 +15,8 @@ package com.freemud.Controller;
import
com.alibaba.fastjson.JSON
;
import
com.freemud.Service.OrdersService
;
import
com.freemud.dto.OrderProductDTO
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -22,25 +24,22 @@ import org.springframework.web.bind.annotation.*;
import
java.util.List
;
@Controller
@Api
(
"订单sku Controller"
)
public
class
OrdersController
{
@Autowired
private
OrdersService
ordersService
;
@RequestMapping
(
"index"
)
public
String
index
(){
return
"index"
;
}
@PostMapping
(
"/getOrder/{orderId}"
)
@ApiOperation
(
"获取订单的商品信息"
)
@PostMapping
(
"/getOrder"
)
@ResponseBody
public
String
getOrder
(
@
PathVariable
(
"orderId"
)
String
orderId
){
List
<
OrderProductDTO
>
list
=
ordersService
.
getOrderProductDTOByOrderId
(
orderId
);
return
JSON
.
toJSONString
(
list
);
public
String
getOrder
(
@
RequestParam
(
"orderId"
)
String
orderId
){
List
<
OrderProductDTO
>
list
=
ordersService
.
getOrderProductDTOByOrderId
(
orderId
);
return
JSON
.
toJSONString
(
list
);
}
@ApiOperation
(
"根据正确的sku进行补推"
)
@PostMapping
(
"/getRightSkuAndOrderPush"
)
@ResponseBody
public
String
getRightSkuAndOrderPush
(
@RequestBody
OrderProductDTO
orderProductDTO
){
...
...
@@ -54,9 +53,4 @@ public class OrdersController {
}
@GetMapping
(
"/RepairByRightSkuAndOrderPush"
)
public
Object
RepairByRightSkuAndOrderPush
(
@RequestParam
(
"rightSku"
)
String
rightSku
){
return
null
;
}
}
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
View file @
85c5c37a
...
...
@@ -38,11 +38,15 @@ public class OrdersServiceImpl implements OrdersService {
@Override
public
void
RepairByRightSku
(
Long
id
,
String
sku
)
{
// 请求修复接口
// String url = "10.50.1.40:9929/order/repairByRightSku";
// restTemplate.getForObject(url,String.class);
}
@Override
public
void
OrderPush
(
String
channel
,
String
orderId
)
{
// 补推订单
}
...
...
src/main/java/com/freemud/SmalltoolsApplication.java
View file @
85c5c37a
package
com
.
freemud
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.client.RestTemplate
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@EnableSwagger2
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
@MapperScan
(
basePackages
=
"com.freemud.Mapper"
)
public
class
SmalltoolsApplication
{
@Autowired
private
RestTemplateBuilder
builder
;
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SmalltoolsApplication
.
class
,
args
);
}
@Bean
public
RestTemplate
restTemplate
(){
return
builder
.
build
();
}
}
src/main/java/com/freemud/config/Swagger2Config.java
0 → 100644
View file @
85c5c37a
package
com
.
freemud
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.Contact
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
/**
* @program: smalltools
* @description: ${description}
* @author: Mr.Wang
* @create: 2019-02-12 11:18
**/
@Configuration
public
class
Swagger2Config
{
@Bean
public
Docket
createRestApi
(){
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.freemud.Controller"
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
public
ApiInfo
apiInfo
(){
return
new
ApiInfoBuilder
()
.
title
(
"修复sku小工具"
)
.
description
(
"提供后台查询商品sku和修复并补单功能"
)
.
contact
(
new
Contact
(
"jiahui.wang"
,
"local"
,
"jiahui.wang@freemud.cn"
))
.
version
(
"1.0"
)
.
build
();
}
}
src/main/java/com/freemud/dto/OrderProductDTO.java
View file @
85c5c37a
...
...
@@ -12,26 +12,28 @@
*/
package
com
.
freemud
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
OrderProductDTO
{
// 商品编号
@ApiModelProperty
(
value
=
"商品编号"
,
required
=
true
)
private
Long
id
;
// 订单主键
@ApiModelProperty
(
value
=
"订单主键"
,
required
=
true
)
private
String
orderId
;
@ApiModelProperty
(
value
=
"渠道"
,
required
=
true
)
private
String
channel
;
// 订单号
@ApiModelProperty
(
value
=
"订单号"
,
required
=
true
)
private
String
orderCode
;
// 商品名称
@ApiModelProperty
(
value
=
"商品名称"
,
required
=
true
)
private
String
name
;
// 商品 sku
@ApiModelProperty
(
value
=
"商品 sku"
,
required
=
true
)
private
String
sku
;
}
src/main/java/com/freemud/utils/FileOperationUtils.java
deleted
100644 → 0
View file @
ae8a63f6
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: FileOperationUtils
* @Package com.freemud.apps.promotion.util
* @Description: 文件上传下载工具类
* @author: jiahui.wang
* @date: 2019/1/29 10:50
* @version V1.0
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
package
com
.
freemud
.
utils
;
import
com.freemud.exception.HandleExcelException
;
import
com.github.pagehelper.util.StringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.beanutils.BeanUtils
;
import
org.apache.commons.beanutils.BeanUtilsBean
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.beans.PropertyDescriptor
;
import
java.io.IOException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
public
class
FileOperationUtils
{
private
static
final
String
SUFFIX_2007
=
".xlsx"
;
private
static
final
String
SUFFIX_2003
=
".xls"
;
// 日期的格式
private
static
final
String
DateFormate
=
"yyyy-MM-dd"
;
/**
* 读取 Excel 并解析对象工具类
* @param file
* @param aimClass
* @param map key-value key表示excel内字段,value表示我们的bean类字段
* @param <T>
* @return
*/
public
static
<
T
>
List
<
T
>
ReadExcelToObj
(
MultipartFile
file
,
Class
<
T
>
aimClass
,
Map
<
String
,
String
>
map
)
{
List
<
T
>
result
=
new
ArrayList
<>();
List
<
List
<
String
>>
rows
=
readExcel
(
file
,
0
);
try
{
for
(
int
k
=
1
;
k
<
rows
.
size
();
k
++)
{
T
t
=
aimClass
.
newInstance
();
for
(
int
num
=
0
;
num
<
rows
.
get
(
0
).
size
();
num
++)
{
//循环bean字段(等同循环表头)
for
(
String
header
:
map
.
keySet
())
{
if
(
rows
.
get
(
0
).
get
(
num
).
equals
(
header
))
{
PropertyDescriptor
propertyDescriptor
=
BeanUtilsBean
.
getInstance
()
.
getPropertyUtils
().
getPropertyDescriptor
(
t
,
map
.
get
(
header
).
toString
());
if
(
propertyDescriptor
!=
null
)
{
BeanUtils
.
setProperty
(
t
,
map
.
get
(
header
).
toString
(),
changeType
(
rows
.
get
(
k
).
get
(
num
),
propertyDescriptor
.
getPropertyType
()));
break
;
}
}
}
}
result
.
add
(
t
);
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
private
static
Object
changeType
(
String
s
,
Class
<?>
propertyType
)
{
System
.
out
.
println
(
propertyType
.
getTypeName
());
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.String"
)){
return
s
;
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Long"
)){
return
Long
.
parseLong
(
s
);
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Float"
)){
return
Float
.
parseFloat
(
s
);
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Short"
)){
return
Short
.
parseShort
(
s
);
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Byte"
)){
return
Byte
.
parseByte
(
s
);
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Integer"
)){
return
Integer
.
parseInt
(
s
);
}
else
if
(
propertyType
.
getTypeName
().
equals
(
"java.lang.Double"
)){
return
Double
.
parseDouble
(
s
);
}
else
{
return
null
;
}
}
private
static
List
<
List
<
String
>>
readExcel
(
MultipartFile
file
,
int
i
)
{
// 创建二位数组保存所有读取到的行列数据,外层存行数据,内存存单元格数据
List
<
List
<
String
>>
dataList
=
new
ArrayList
<
List
<
String
>>();
try
{
Workbook
workbook
=
getWorkbook
(
file
);
int
sheetNum
=
workbook
.
getNumberOfSheets
();
for
(
int
index
=
0
;
index
<
sheetNum
;
index
++){
Sheet
sheet
=
workbook
.
getSheetAt
(
index
);
if
(
sheet
==
null
){
continue
;
}
log
.
info
(
"表单行数:{}"
,
sheet
.
getLastRowNum
());
for
(
int
rowIndex
=
0
;
rowIndex
<=
sheet
.
getLastRowNum
()
;
rowIndex
++){
Row
row
=
sheet
.
getRow
(
rowIndex
);
if
(
row
==
null
){
continue
;
}
// 遍历每一行的第一列,第三层遍历所有的单元格
List
<
String
>
cellList
=
new
ArrayList
<>();
for
(
int
cellIndex
=
0
;
cellIndex
<
row
.
getLastCellNum
();
cellIndex
++){
Cell
cell
=
row
.
getCell
(
cellIndex
);
String
CellValue
=
getCellValue
(
cell
);
if
(
CellValue
==
null
){
continue
;
}
cellList
.
add
(
CellValue
);
}
if
(
cellList
.
size
()
!=
0
){
dataList
.
add
(
cellList
);
}
}
}
}
catch
(
HandleExcelException
e
)
{
log
.
error
(
"输入的文件不是excel文件,请确认文件是否正确"
);
}
return
dataList
;
}
/**
* 获取cell中的值
* @param cell
* @return
*/
private
static
String
getCellValue
(
Cell
cell
)
{
CellType
cellType
=
cell
.
getCellTypeEnum
();
String
cellValue
=
""
;
if
(
cell
==
null
||
cell
.
toString
().
trim
().
equals
(
""
)){
return
null
;
}
if
(
cellType
==
CellType
.
STRING
){
cellValue
=
cell
.
getStringCellValue
().
trim
();
return
cellValue
=
StringUtil
.
isEmpty
(
cellValue
)?
""
:
cellValue
;
}
if
(
cellType
==
CellType
.
NUMERIC
){
if
(
HSSFDateUtil
.
isCellDateFormatted
(
cell
))
{
//判断日期类型
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DateFormate
);
cellValue
=
sdf
.
format
(
cell
.
getDateCellValue
().
getTime
());
}
else
{
// DecimalFormat 对数字进行格式化
// # 整数 #.## 取两位小数 #.##% 百分号计数取2位小数 todo 处理数值类型数据
cellValue
=
new
DecimalFormat
(
"#.##"
).
format
(
cell
.
getNumericCellValue
());
}
return
cellValue
;
}
if
(
cellType
==
CellType
.
BOOLEAN
){
cellValue
=
String
.
valueOf
(
cell
.
getBooleanCellValue
());
return
cellValue
;
}
return
null
;
}
/**
* 通过判断文件结尾封装 Workbook 类
* @param file
* @return
* @throws HandleExcelException
*/
private
static
Workbook
getWorkbook
(
MultipartFile
file
)
throws
HandleExcelException
{
Workbook
wb
=
null
;
try
{
if
(
file
.
getOriginalFilename
().
endsWith
(
SUFFIX_2007
)){
wb
=
new
XSSFWorkbook
(
file
.
getInputStream
());
}
else
if
(
file
.
getOriginalFilename
().
endsWith
(
SUFFIX_2003
)){
wb
=
new
HSSFWorkbook
(
file
.
getInputStream
());
}
else
{
throw
new
HandleExcelException
(
"输入的文件不是excel文件,请确认文件是否正确"
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"读取Excel 异常,请确认文件是否正确"
);
}
return
wb
;
}
}
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