controller类:
/**
* 获取店铺信息
* 根据城市编码查询当前城市下 根据定位的经纬度获取最近的一个门店信息
*
@param
cityCode
当前城市编码
*
@return
返回符合门店配送条件的门店配送信息 没有匹配到会返回null
*/
@RequestMapping
(
value =
[
"/sellershop/list"
])
@ApiMethod
(
id =
"getSellerShopAddress"
,
summary =
"getSellerShopAddress"
,
description =
"获取店铺信息"
)
fun
getSellerShopAddress(
@ApiQueryParam
(
name =
"cityCode"
,
description =
"当前定位的城市编码"
,
required =
false
)
@RequestParam
(
value =
"cityCode"
,
required =
false
)
cityCode: String?): ResponseEntity<YTXResponse> {
val
result = YTXResponse.success()
val
sellerDistributtionVoList: MutableList<SellerDistributtionVo> = ArrayList()
if
(!(cityCode.
equals
(
""
) || cityCode ==
null
)) {
//根据cityCode获取当前城市下的门店及配送范围信息
val
distributionScopeList =
distributionScopeManager
.findBycityCode(cityCode)
//循环门店配送信息 添加门店经纬度 门店名字 及门店所在地城市code name
if
(distributionScopeList.
isNotEmpty
()) {
for
(distributionScope
in
distributionScopeList) {
val
sellerDistributtionVo = SellerDistributtionVo()
//配送区域
sellerDistributtionVo.
areas
= distributionScope.
areas
//门店id
sellerDistributtionVo.
sellerAccountId
= distributionScope.
sellerAccountId
val
sellerAddress =
sellerManager
.findStoreAddressByAccountId(distributionScope.
sellerAccountId
)
if
(sellerAddress !=
null
) {
//经纬度
sellerDistributtionVo.
latitude
= sellerAddress.
latitude
sellerDistributtionVo.
longitude
= sellerAddress.
longitude
if
(sellerAddress.
cityCode
!=
null
) {
val
region =
regionManager
.findByCode(sellerAddress.
cityCode
)
//城市name
if
(region !=
null
) {
//城市code
sellerDistributtionVo.
cityCode
= region.
cityCode
sellerDistributtionVo.
cityName
= region.
name
}
}
}
//门店名字
val
seller =
sellerManager
.findByAccountId(distributionScope.
sellerAccountId
)
if
(seller !=
null
) sellerDistributtionVo.
sellerAccountName
=
seller
.
sellerShop
.
name
sellerDistributtionVoList.add(sellerDistributtionVo)
}
}
}
//找到所有有门店的城市 的code
val
allCitiesHavingStores =
sellerManager
.findAllCitiesHavingStores()
val
regionList: MutableList<Region> = ArrayList()
//添加城市名称
allCitiesHavingStores.
mapTo
(regionList)
{
regionManager
.findByCode(
it
)
}
val
simplePropertyPreFilter = SimplePropertyPreFilter(Region::
class
.
java
,
"cityCode"
,
"name"
)
result.addData(
"regionList"
, JSON.toJSONString(regionList, simplePropertyPreFilter))
result.addData(
"distributionScopeList"
, sellerDistributtionVoList)
return
ResponseEntity(result, HttpStatus.
OK
)
}
YTXResponse
类:
import
java.util.LinkedHashMap;
import
java.util.Map;
/**
* 与客户端交互的返回结果
*/
public class
YTXResponse
implements
YTXMessage, YTXData {
/**
* 操作成功与否 由后台返回前台
*/
private
String
success
= SuccessFlag.
TRUE
.toString();
/**
* 处理信息代码
*/
private
String
code
=
"Y00-000200"
;
/**
* 信息
*/
private
String
message
=
"SUCCESS"
;
/**
* 返回客户端所带的数据
*/
private
Map<String, Object>
data
=
new
LinkedHashMap<>();
public static
YTXResponse success() {
YTXResponse response =
new
YTXResponse();
response.
success
= SuccessFlag.
TRUE
.toString();
response.
message
=
"SUCCESS"
;
return
response;
}
@Override
public
String getSuccess() {
return
success
;
}
public void
setSuccessFalse() {
this
.
success
= SuccessFlag.
FALSE
.
value
;
}
public void
setSuccessTrue() {
this
.
success
= SuccessFlag.
TRUE
.
value
;
}
/**
* 操作是不是成功
*
@return
true:成功, false:未成功
*/
public
Boolean isSucceed() {
return
SuccessFlag.
TRUE
.toString().equals(
success
);
}
/**
* 操作是不是失败
*
@return
true:失败, false:无误
*/
public
Boolean isFailed() {
return
!SuccessFlag.
TRUE
.toString().equals(
success
);
}
@Override
public void
setSuccess(String success) {
this
.
success
= success;
}
@Override
public
String getCode() {
return
code
;
}
@Override
public void
setCode(String code) {
this
.
code
= code;
}
@Override
public
String getMessage() {
return
message
;
}
@Override
public void
setMessage(String message) {
this
.
message
= message;
}
/**
* Return the underlying {
@code
data} instance (never {
@code
null}).
*/
@Override
public
Map<String, Object> getData() {
if
(
this
.
data
==
null
) {
this
.
data
=
new
LinkedHashMap<>();
}
return this
.
data
;
}
@Override
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
getData(String dataName) {
if
(
this
.
data
==
null
) {
this
.
data
=
new
LinkedHashMap<>();
}
return
(
T
)
this
.
data
.get(dataName);
}
@Override
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
addData(String dataName,
T
dataValue) {
if
(
this
.
data
==
null
) {
this
.
data
=
new
LinkedHashMap<>();
}
if
(dataName ==
null
) {
throw new
IllegalArgumentException(
"Model attribute name must not be null"
);
}
this
.
data
.put(dataName, dataValue);
return
dataValue;
}
public enum
SuccessFlag {
TRUE
(
"TRUE"
),
FALSE
(
"FALSE"
);
String
value
;
SuccessFlag(String value) {
this
.
value
= value;
}
public
String getValue() {
return
value
;
}
}
public
YTXResponse() {
}
public
YTXResponse(String code, String message) {
this
.
code
= code;
this
.
message
= message;
}
public
YTXResponse(String code, String message, Map<String, Object> data) {
this
.
code
= code;
this
.
message
= message;
this
.
data
= data;
}
private
YTXResponse(String success, String code, String message, Map<String, Object> data) {
this
.
success
= success;
this
.
code
= code;
this
.
message
= message;
this
.
data
= data;
}
public static
Builder builder() {
return new
Builder();
}
public static class
Builder {
/**
* 操作成功与否 由后台返回前台
*/
private
String
success
= SuccessFlag.
TRUE
.toString();
/**
* 处理信息代码
*/
private
String
code
=
"Y00-000200"
;
/**
* 信息
*/
private
String
message
=
"SUCCESS"
;
/**
* 返回客户端所带的数据
*/
private
Map<String, Object>
data
=
new
LinkedHashMap<>();
private
Builder() {
}
public
Builder success(String success) {
this
.
success
= success;
return this
;
}
public
Builder code(String code) {
this
.
code
= code;
return this
;
}
public
Builder message(String message) {
this
.
message
= message;
return this
;
}
public
Builder data(Map<String, Object> data) {
this
.
data
= data;
return this
;
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
> Builder addData(String dataName,
T
dataValue) {
if
(
this
.
data
==
null
) {
this
.
data
=
new
LinkedHashMap<>();
}
if
(dataName ==
null
) {
throw new
IllegalArgumentException(
"Model attribute name must not be null"
);
}
this
.
data
.put(dataName, dataValue);
return this
;
}
@Override
public
String toString() {
return
"Builder{"
+
"success='"
+
success
+
'
\'
'
+
", code='"
+
code
+
'
\'
'
+
", message='"
+
message
+
'
\'
'
+
", data="
+
data
+
'}'
;
}
public
YTXResponse build() {
return new
YTXResponse(
success
,
code
,
message
,
data
);
}
}
}
YTXMessage类:
import
java.util.List;
/**
* 与客户端交互时,返回的信息
*/
public interface
YTXMessage {
/**
* 返回处理成功与否
*
@return
"true" or "false"
*/
String getSuccess();
/**
* 设置成功与否
*
@param
success
成功与否
*/
void
setSuccess(String success);
/**
* 返回信息的统一代码
*
@return
code 统一代码
*/
String getCode();
/**
* 设置信息的统一代码
*
@param
code
信息的统一代码
*/
void
setCode(String code);
/**
* 返回具体处理信息
*
@return
具体处理信息
*/
String getMessage();
/**
* 设置具体信息
*
@param
message
具体处理信息
*/
void
setMessage(String message);
}
YTXData类:
import
java.util.Map;
public interface
YTXData {
Map<String, Object> getData();
<
T
>
T
getData(String dataName);
<
T
>
T
addData(String dataName,
T
dataValue);
}