Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
holmes
Commits
f293d702
Commit
f293d702
authored
Mar 02, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增/api/product/skuState和/api/price/getSellPrice
parent
782fe9eb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
362 additions
and
0 deletions
+362
-0
KeystoneService.java
src/main/java/cn/qg/holmes/bean/KeystoneService.java
+81
-0
ProductController.java
...qg/holmes/controller/mock/keystone/ProductController.java
+84
-0
JdSellPriceRequest.java
...cn/qg/holmes/entity/mock/keystone/JdSellPriceRequest.java
+26
-0
JdSkuStateRequest.java
.../cn/qg/holmes/entity/mock/keystone/JdSkuStateRequest.java
+17
-0
ProductItem.java
...n/java/cn/qg/holmes/entity/mock/keystone/ProductItem.java
+154
-0
No files found.
src/main/java/cn/qg/holmes/bean/KeystoneService.java
0 → 100644
View file @
f293d702
package
cn
.
qg
.
holmes
.
bean
;
import
cn.qg.holmes.entity.mock.keystone.ProductItem
;
import
cn.qg.holmes.utils.JdbcUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.math.BigDecimal
;
import
java.sql.*
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Component
public
class
KeystoneService
{
String
driver
=
"com.mysql.jdbc.Driver"
;
String
dbName
=
"keystone"
;
Connection
connection
=
null
;
PreparedStatement
preparedStatement
=
null
;
Statement
statement
=
null
;
@Value
(
"${dbsync.mysql.ip}"
)
private
String
ip
;
@Value
(
"${dbsync.mysql.port}"
)
private
String
port
;
@Value
(
"${dbsync.mysql.username}"
)
private
String
username
;
@Value
(
"${dbsync.mysql.password}"
)
private
String
password
;
@PostConstruct
public
void
createConnection
()
{
String
url
=
"jdbc:mysql://"
+
ip
+
":"
+
port
+
"/"
+
dbName
;
try
{
Class
.
forName
(
driver
);
connection
=
DriverManager
.
getConnection
(
url
,
username
,
password
);
log
.
info
(
"创建同步库keystone连接: {}"
,
connection
.
toString
());
}
catch
(
Exception
e
)
{
log
.
info
(
"同步库初始化失败."
);
e
.
printStackTrace
();
}
}
/**
* 根据id获取商品相关信息
* @param skuId
* @return
*/
public
ProductItem
getProductItemById
(
String
skuId
)
{
String
sql
=
"SELECT * FROM `product_item` WHERE id = "
+
skuId
;
log
.
info
(
"从keystone.product_item根据skuId查询商品信息:{}"
,
sql
);
ProductItem
productItem
=
new
ProductItem
();
try
{
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
List
<
Map
<
String
,
Object
>>
resultList
=
JdbcUtils
.
convertResultSetToList
(
resultSet
);
if
(
resultList
.
size
()
>
0
)
{
Map
<
String
,
Object
>
map
=
resultList
.
get
(
0
);
productItem
.
setProductId
((
Long
)
map
.
get
(
"id"
));
productItem
.
setName
((
String
)
map
.
get
(
"name"
));
productItem
.
setThirdSkuNo
((
String
)
map
.
get
(
"third_sku_no"
));
productItem
.
setProductId
((
Long
)
map
.
get
(
"product_id"
));
productItem
.
setMarketPrice
(
new
BigDecimal
(
map
.
get
(
"market_price"
).
toString
()));
productItem
.
setSalePrice
(
new
BigDecimal
(
map
.
get
(
"sale_price"
).
toString
()));
productItem
.
setSupplyPrice
(
new
BigDecimal
(
map
.
get
(
"market_price"
).
toString
()));
productItem
.
setSpecProps
(
map
.
get
(
"spec_props"
).
toString
());
productItem
.
setState
((
Integer
)
map
.
get
(
"state"
));
productItem
.
setOffSaleItemId
((
Long
)
map
.
get
(
"off_sale_item_id"
));
productItem
.
setImage
((
String
)
map
.
get
(
"image"
));
productItem
.
setPrimaryImage
((
String
)
map
.
get
(
"primary_image"
));
productItem
.
setProductStockWarning
((
Integer
)
map
.
get
(
"product_stock_warning"
));
productItem
.
setSupplierType
((
String
)
map
.
get
(
"supplier_type"
));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
productItem
;
}
}
src/main/java/cn/qg/holmes/controller/mock/keystone/ProductController.java
0 → 100644
View file @
f293d702
package
cn
.
qg
.
holmes
.
controller
.
mock
.
keystone
;
import
cn.qg.holmes.bean.KeystoneService
;
import
cn.qg.holmes.entity.mock.keystone.JdSellPriceRequest
;
import
cn.qg.holmes.entity.mock.keystone.JdSkuStateRequest
;
import
cn.qg.holmes.entity.mock.keystone.ProductItem
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.math.BigDecimal
;
/**
* 商品相关mock接口
* @author libo
*/
@Slf4j
@RestController
public
class
ProductController
{
@Autowired
KeystoneService
keystoneService
;
/**
* 4.5 查询商品上下架状态
* @param request
* @return
*/
@PostMapping
(
"/api/product/skuState"
)
public
JSONObject
getProductState
(
JdSkuStateRequest
request
)
{
JSONObject
response
=
new
JSONObject
();
String
[]
skuArray
=
request
.
getSku
().
split
(
","
);
response
.
put
(
"success"
,
true
);
response
.
put
(
"resultMessage"
,
"操作成功"
);
response
.
put
(
"resultCode"
,
"0000"
);
JSONArray
jsonArray
=
new
JSONArray
();
for
(
String
sku
:
skuArray
)
{
JSONObject
skuObject
=
new
JSONObject
();
skuObject
.
put
(
"sku"
,
Long
.
valueOf
(
sku
));
skuObject
.
put
(
"state"
,
1
);
jsonArray
.
add
(
skuObject
);
}
response
.
put
(
"result"
,
jsonArray
);
return
response
;
}
/**
* 5.1 查询商品售卖价
*/
@PostMapping
(
"/api/price/getSellPrice"
)
public
JSONObject
getSellPrice
(
JdSellPriceRequest
request
)
{
String
[]
skuArray
=
request
.
getSku
().
split
(
","
);
String
queryExts
=
request
.
getQueryExts
();
JSONObject
response
=
new
JSONObject
();
response
.
put
(
"success"
,
true
);
response
.
put
(
"resultMessage"
,
"价格为null或者小于0时,为暂无报价"
);
response
.
put
(
"resultCode"
,
"0000"
);
JSONArray
result
=
new
JSONArray
();
for
(
String
skuId:
skuArray
)
{
ProductItem
productItem
=
keystoneService
.
getProductItemById
(
skuId
);
JSONObject
productJson
=
new
JSONObject
();
productJson
.
put
(
"skuId"
,
Long
.
valueOf
(
skuId
));
productJson
.
put
(
"jdPrice"
,
productItem
.
getSupplyPrice
());
productJson
.
put
(
"price"
,
productItem
.
getSalePrice
());
if
(
queryExts
!=
null
&&
queryExts
.
contains
(
"marketPrice"
))
{
productJson
.
put
(
"marketPrice"
,
productItem
.
getMarketPrice
());
}
if
(
queryExts
!=
null
&&
queryExts
.
contains
(
"containsTax"
))
{
// 随便模拟一个税率
productJson
.
put
(
"tax"
,
16
);
productJson
.
put
(
"taxPrice"
,
productItem
.
getSalePrice
().
multiply
(
new
BigDecimal
(
"0.16"
)));
BigDecimal
nakedPrice
=
productItem
.
getSalePrice
().
divide
(
new
BigDecimal
(
"1.16"
),
BigDecimal
.
ROUND_HALF_UP
);
productJson
.
put
(
"nakedPrice"
,
nakedPrice
);
}
result
.
add
(
productJson
);
}
response
.
put
(
"result"
,
result
);
return
response
;
}
}
src/main/java/cn/qg/holmes/entity/mock/keystone/JdSellPriceRequest.java
0 → 100644
View file @
f293d702
package
cn
.
qg
.
holmes
.
entity
.
mock
.
keystone
;
import
lombok.Data
;
/**
* 5.1 查询商品售卖价
*/
@Data
public
class
JdSellPriceRequest
{
private
String
token
;
/**
* 商品编号,请以,(英文逗号)分割。例如:129408,129409(最高支持100个商品)
*/
private
String
sku
;
/**
* 为英文半角分隔的多个枚举值,枚举值不同,本接口的出参不同。枚举值如下:
* Price //大客户默认价格(根据合同类型查询价格),该字段必传。
* marketPrice //市场价。
* containsTax //税率。出参增加tax,taxPrice,nakedPrice 3个字段。
* nakedPrice//未税价。出参增加nakedPrice字段
*/
private
String
queryExts
;
}
src/main/java/cn/qg/holmes/entity/mock/keystone/JdSkuStateRequest.java
0 → 100644
View file @
f293d702
package
cn
.
qg
.
holmes
.
entity
.
mock
.
keystone
;
import
lombok.Data
;
/**
* 查询商品上下架状态
*/
@Data
public
class
JdSkuStateRequest
{
private
String
token
;
/**
* 商品编号,支持批量,以“,”(半角)分隔 (最高支持100个商品)
*/
private
String
sku
;
}
src/main/java/cn/qg/holmes/entity/mock/keystone/ProductItem.java
0 → 100644
View file @
f293d702
package
cn
.
qg
.
holmes
.
entity
.
mock
.
keystone
;
import
com.baomidou.mybatisplus.annotation.FieldFill
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.List
;
@Data
public
class
ProductItem
{
/**
* skuId
*/
@TableId
(
value
=
"id"
,
type
=
IdType
.
INPUT
)
private
Long
id
;
/**
* SKU名称
*/
private
String
name
;
/**
* SKU编码-三方渠道为起对应的skuId,自营商品手工输入
*/
private
String
thirdSkuNo
;
/**
* 商品Id
*/
private
Long
productId
;
/**
* 售价 出价
*/
private
BigDecimal
salePrice
;
/**
* 供货价 进价
*/
@TableField
(
exist
=
false
)
private
BigDecimal
supplyPrice
;
/**
* 市场价
*/
private
BigDecimal
marketPrice
;
/**
* 规格属性,存放为JSON字符串
*/
private
String
specProps
;
/**
* 规格的图片,如果没有则为null
*/
private
String
image
;
/**
* sku重量 单位:kg
*/
private
BigDecimal
weight
;
/**
* 详情图
*/
private
String
primaryImage
;
/**
* 下架原因id
*/
private
Long
offSaleItemId
;
/**
* 为了透传
*/
@TableField
(
exist
=
false
)
private
Integer
stock
;
/**
* 实际销量
*/
@TableField
(
exist
=
false
)
private
Integer
actualSales
;
/**
* 销量(含取消)
*/
@TableField
(
exist
=
false
)
private
Integer
sales
;
/**
* 5:未上架,6:上架,7:下架
*/
private
Integer
state
;
/**
* 上架时间
*/
private
LocalDateTime
pushedAt
;
/**
* 下架时间
*/
private
LocalDateTime
offlineAt
;
/**
* 创建人
*/
private
String
createdBy
;
/**
* 更新人
*/
private
String
updatedBy
;
/**
* 供应商类型
*/
private
String
supplierType
;
/**
* 创建时间
*/
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
LocalDateTime
createdAt
;
/**
* 更新时间
*/
@TableField
(
fill
=
FieldFill
.
INSERT_UPDATE
,
update
=
"now()"
)
private
LocalDateTime
updatedAt
;
/**
* 为了透传
*/
@TableField
(
exist
=
false
)
private
List
<
String
>
imageList
;
/**
* 为了透传
*/
@TableField
(
exist
=
false
)
private
String
skuLink
;
/**
* 库存预警值
*/
@TableField
(
exist
=
false
)
private
Integer
productStockWarning
;
}
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