Merge branch 'api-dev' of http://139.159.177.244:3000/hurui/hai-server into api-dev
commit
40da39a651
@ -0,0 +1,225 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.PageUtil; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.entity.ApiProduct; |
||||
import com.hai.entity.ApiStarbucksProducts; |
||||
import com.hai.entity.BsProductConfig; |
||||
import com.hai.entity.OutRechargePrice; |
||||
import com.hai.model.BsProductConfigModel; |
||||
import com.hai.model.OutRechargePriceModel; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.ApiProductService; |
||||
import com.hai.service.BsConfigService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.models.auth.In; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/bsProductConfig") |
||||
@Api(value = "api产品") |
||||
public class BsProductConfigController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(BsProductConfigController.class); |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private BsConfigService bsConfigService; |
||||
|
||||
@Autowired |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/getProductConfig", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询配置产品") |
||||
public ResponseData getProductConfig(@RequestParam(value = "productName", required = false) String productName, |
||||
@RequestParam(value = "productType", required = false) Integer productType, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize, |
||||
HttpServletRequest request) { |
||||
try { |
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("companyId", String.valueOf(userInfoModel.getBsCompany().getId())); |
||||
map.put("productName", productName); |
||||
map.put("productType", productType); |
||||
|
||||
|
||||
List<BsProductConfig> productConfigs = apiProductService.getProductConfig(map); |
||||
|
||||
Map<String, Object> listMap; |
||||
|
||||
List<BsProductConfigModel> productConfigModels = new ArrayList<>(); |
||||
|
||||
for (BsProductConfig list : productConfigs) { |
||||
BsProductConfigModel bsProductConfigModel = new BsProductConfigModel(); |
||||
listMap = new HashMap<>(); |
||||
listMap.put("returnType", 2); |
||||
listMap.put("productType", "5"); |
||||
listMap.put("sourceId", list.getId()); |
||||
BeanUtils.copyProperties(list, bsProductConfigModel); |
||||
bsProductConfigModel.setIntegralDiscount(bsConfigService.getProductDiscountByMap(listMap).getDiscount()); |
||||
bsProductConfigModel.setProductPayTypeString(bsConfigService.getProductPayTypeByMap(listMap)); |
||||
bsProductConfigModel.setProductPlatformString(bsConfigService.getProductPlatformByMap(listMap)); |
||||
productConfigModels.add(bsProductConfigModel); |
||||
|
||||
} |
||||
|
||||
return ResponseMsgUtil.success(PageUtil.initPageInfoObj(pageNum,productConfigModels.size(),pageSize,new PageInfo<>(productConfigModels))); |
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/productConfig", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "新增产品配置") |
||||
public ResponseData productConfig(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (object == null || |
||||
object.getJSONArray("productIds") == null || |
||||
object.getBigDecimal("discount") == null || |
||||
object.getInteger("productType") == null || |
||||
object.getJSONArray("productPlatform") == null || |
||||
object.getJSONArray("payType") == null |
||||
) { |
||||
log.error("OutRechargePriceController -> productConfig() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
object.put("operatorId", userInfoModel.getSecUser().getId()); |
||||
object.put("operatorName", userInfoModel.getSecUser().getLoginName()); |
||||
object.put("companyId", userInfoModel.getBsCompany().getId()); |
||||
|
||||
apiProductService.ProductConfig(object); |
||||
|
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> insertPrice() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateProductConfig", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑产品配置") |
||||
public ResponseData updateProductConfig(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (object == null || |
||||
object.getLong("id") == null || |
||||
object.getJSONArray("productIds") == null || |
||||
object.getBigDecimal("discount") == null || |
||||
object.getInteger("productType") == null || |
||||
object.getJSONArray("productPlatform") == null || |
||||
object.getJSONArray("payType") == null |
||||
) { |
||||
log.error("OutRechargePriceController -> productConfig() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
object.put("operatorId", userInfoModel.getSecUser().getId()); |
||||
object.put("operatorName", userInfoModel.getSecUser().getLoginName()); |
||||
object.put("companyId", userInfoModel.getBsCompany().getId()); |
||||
|
||||
apiProductService.updateProductConfig(object); |
||||
|
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> insertPrice() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/findProductConfig", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询详情") |
||||
public ResponseData findProductConfig(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
|
||||
BsProductConfig bsProductConfig = apiProductService.findProductConfig(id); |
||||
|
||||
BsProductConfigModel bsProductConfigModel = new BsProductConfigModel(); |
||||
BeanUtils.copyProperties(bsProductConfig, bsProductConfigModel); |
||||
Map<String, Object> listMap = new HashMap<>(); |
||||
listMap.put("productType", "5"); |
||||
listMap.put("returnType", 1); |
||||
listMap.put("sourceId", bsProductConfig.getId()); |
||||
listMap.put("platformId", null); |
||||
|
||||
bsProductConfigModel.setIntegralDiscount(bsConfigService.getProductDiscountByMap(listMap).getDiscount()); |
||||
bsProductConfigModel.setProductPayTypeString(bsConfigService.getProductPayTypeByMap(listMap)); |
||||
bsProductConfigModel.setProductPlatformString(bsConfigService.getProductPlatformByMap(listMap)); |
||||
return ResponseMsgUtil.success(bsProductConfigModel); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/findStarbucksProducts", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询详情产品详情") |
||||
public ResponseData findStarbucksProducts(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
|
||||
BsProductConfig bsProductConfig = apiProductService.findProductConfig(id); |
||||
|
||||
ApiStarbucksProducts apiStarbucksProducts = apiProductService.findStarbucksProducts(bsProductConfig.getProductId()); |
||||
|
||||
apiStarbucksProducts.setSalesVentiPrice(apiStarbucksProducts.getMarketVentiPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
apiStarbucksProducts.setSalesTallPrice(apiStarbucksProducts.getMarketTallPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
apiStarbucksProducts.setSalesGrandePrice(apiStarbucksProducts.getMarketGrandePrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
|
||||
return ResponseMsgUtil.success(apiStarbucksProducts); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,281 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.cweb.config.SysConfig; |
||||
import com.cweb.config.SysConst; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.CoordCommonUtil; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.config.CommonSysConst; |
||||
import com.hai.config.QianZhuConfig; |
||||
import com.hai.entity.*; |
||||
import com.hai.enum_type.ProductImgEnum; |
||||
import com.hai.model.ApiStarbucksProductsModel; |
||||
import com.hai.model.BsProductConfigModel; |
||||
import com.hai.model.HighUserModel; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.service.ApiProductService; |
||||
import com.hai.service.BsConfigService; |
||||
import com.hai.service.HighOrderService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.w3c.dom.ls.LSException; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.math.BigDecimal; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/highThirdParty") |
||||
@Api(value = "订单接口") |
||||
public class HighThirdPartyController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(HighThirdPartyController.class); |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private BsConfigService bsConfigService; |
||||
|
||||
@Resource |
||||
private HighOrderService highOrderService; |
||||
|
||||
@Autowired |
||||
private UserCenter userCenter; |
||||
|
||||
|
||||
@RequestMapping(value = "/getAllCity", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询所有城市") |
||||
public ResponseData getAllCity(@RequestParam(name = "cityName", required = false) String cityName) { |
||||
try { |
||||
return ResponseMsgUtil.success(apiProductService.getAllCity(cityName)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighUserCardController --> oilCardRefund() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getStarbucksProducts", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询星巴克商品") |
||||
public ResponseData getStarbucksProducts(@RequestParam(name = "name", required = false) String name) { |
||||
try { |
||||
|
||||
List<String> CategoryNameList = apiProductService.getCategoryName(); |
||||
|
||||
List<ApiStarbucksProducts> starbucksProductsList = new ArrayList<>(); |
||||
int i = 9999; |
||||
for (String s : CategoryNameList) { |
||||
i++; |
||||
ApiStarbucksProducts starbucksProducts = new ApiStarbucksProducts(); |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("name" , name); |
||||
map.put("categoryName" , s); |
||||
List<ApiStarbucksProducts> list = apiProductService.getStarbucksProducts(map); |
||||
for (ApiStarbucksProducts apiStarbucksProducts : list) { |
||||
apiStarbucksProducts.setExt1(String.valueOf(i)); |
||||
starbucksProductsList.add(apiStarbucksProducts); |
||||
} |
||||
starbucksProducts.setName(s); |
||||
starbucksProducts.setExt2(SysConst.getSysConfig().getImgUrl() + ProductImgEnum.getNameByImgUrl(s)); |
||||
starbucksProducts.setId((long) i); |
||||
starbucksProductsList.add(starbucksProducts); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(starbucksProductsList); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighUserCardController --> oilCardRefund() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getStarbucksStore", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询星巴克门店") |
||||
public ResponseData getStarbucksStore(@RequestParam(name = "lat", required = true) String lat, |
||||
@RequestParam(name = "lon", required = true) String lon) { |
||||
try { |
||||
JSONObject jsonObject = QianZhuConfig.getStarbucksStore(lat , lon); |
||||
if (jsonObject.getBoolean("success")) { |
||||
return ResponseMsgUtil.success(jsonObject.getJSONArray("data")); |
||||
} else { |
||||
log.error("getRechargeProduct error!", "查询失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighUserCardController --> oilCardRefund() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/findStarbucksProducts", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询详情产品详情") |
||||
public ResponseData findStarbucksProducts(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
|
||||
BsProductConfig bsProductConfig = apiProductService.findProductConfigByGoodsId(id); |
||||
|
||||
if (bsProductConfig == null) { |
||||
log.error("findStarbucksProducts error!", "查询失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "未查询到当前商品"); |
||||
} |
||||
|
||||
ApiStarbucksProducts apiStarbucksProducts = apiProductService.findStarbucksProducts(bsProductConfig.getProductId()); |
||||
apiStarbucksProducts.setSalesVentiPrice(apiStarbucksProducts.getMarketVentiPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
apiStarbucksProducts.setSalesTallPrice(apiStarbucksProducts.getMarketTallPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
apiStarbucksProducts.setSalesGrandePrice(apiStarbucksProducts.getMarketGrandePrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); |
||||
|
||||
ApiStarbucksProductsModel starbucksProductsModel = new ApiStarbucksProductsModel(); |
||||
BeanUtils.copyProperties(apiStarbucksProducts, starbucksProductsModel); |
||||
|
||||
Map<String, Object> listMap = new HashMap<>(); |
||||
listMap.put("productType", "5"); |
||||
listMap.put("returnType", 1); |
||||
listMap.put("sourceId", bsProductConfig.getId()); |
||||
listMap.put("platformId", null); |
||||
|
||||
starbucksProductsModel.setIntegralDiscount(bsConfigService.getProductDiscountByMap(listMap).getDiscount()); |
||||
starbucksProductsModel.setProductPayTypeString(bsConfigService.getProductPayTypeByMap(listMap)); |
||||
starbucksProductsModel.setProductPlatformString(bsConfigService.getProductPlatformByMap(listMap)); |
||||
|
||||
return ResponseMsgUtil.success(starbucksProductsModel); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/addOrder", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "增加订单") |
||||
public ResponseData addOrder(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
// 用户
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
||||
|
||||
|
||||
if (StringUtils.isBlank(object.getString("customerMobile")) || |
||||
StringUtils.isBlank(object.getString("regionId")) || |
||||
StringUtils.isBlank(object.getString("productType")) || |
||||
object.getJSONArray("orderItems") == null |
||||
) { |
||||
log.error("addOrder error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
object.put("userId", userInfoModel.getHighUser().getId()); |
||||
|
||||
highOrderService.insertThirdProduct(object); |
||||
|
||||
return ResponseMsgUtil.success("下单成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController -> addOrder() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getKfcStoresList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询肯德基门店") |
||||
public ResponseData getKfcStoresList(@RequestParam(name = "storeName", required = false) String storeName, |
||||
@RequestParam(name = "cityCode", required = true) String cityCode, |
||||
@RequestParam(name = "lat", required = true) String lat, |
||||
@RequestParam(name = "lon", required = true) String lon) { |
||||
try { |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("storeName" , storeName); |
||||
map.put("cityCode" , cityCode); |
||||
|
||||
List<ApiKfcStores> list = apiProductService.getKfcStoresList(map); |
||||
|
||||
if (StringUtils.isNotBlank(lat)){ |
||||
for (ApiKfcStores stores : list) { |
||||
double distance = CoordCommonUtil.getDistance(Double.valueOf(stores.getLat()), Double.valueOf(stores.getLon()), Double.valueOf(lat), Double.valueOf(lon)); |
||||
stores.setDistance(String.valueOf(Math.round(distance/100d)/10d)); |
||||
} |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(list.stream().sorted(Comparator.comparing(ApiKfcStores::getDistance)).collect(Collectors.toList())); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighUserCardController --> oilCardRefund() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/listByStoreCode", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询肯德基门店菜单") |
||||
public ResponseData listByStoreCode(@RequestParam(name = "storeCode", required = false) String storeCode) { |
||||
try { |
||||
|
||||
JSONObject jsonObject = QianZhuConfig.listByStoreCode(storeCode); |
||||
|
||||
JSONArray array = jsonObject.getJSONArray("data"); |
||||
|
||||
Map<String, Object> listMap = new HashMap<>(); |
||||
listMap.put("productType", "2"); |
||||
listMap.put("companyId", 2); |
||||
|
||||
List<BsProductConfig> productConfigs = apiProductService.getProductConfig(listMap); |
||||
|
||||
for (Object data : array) { |
||||
JSONObject dataObject = (JSONObject) data; |
||||
if (dataObject.getJSONArray("products") != null) { |
||||
for (Object products : dataObject.getJSONArray("products")) { |
||||
JSONObject productsObject = (JSONObject) products; |
||||
BigDecimal productsPrice = productsObject.getBigDecimal("price"); |
||||
productsObject.put("salePrice" , productsPrice.add(productsPrice.multiply(productConfigs.get(0).getDiscount()).divide(new BigDecimal(100)))); |
||||
|
||||
if (productsObject.getJSONArray("specGroups") != null) { |
||||
for (Object specGroups : productsObject.getJSONArray("specGroups")) { |
||||
JSONObject specGroupsObject = (JSONObject) specGroups; |
||||
BigDecimal specGroupsPrice = specGroupsObject.getBigDecimal("price"); |
||||
specGroupsObject.put("salePrice" , specGroupsPrice.add(specGroupsPrice.multiply(productConfigs.get(0).getDiscount()).divide(new BigDecimal(100)))); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (jsonObject.getBoolean("success")) { |
||||
return ResponseMsgUtil.success(array); |
||||
} else { |
||||
log.error("getRechargeProduct error!", "查询失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighUserCardController --> oilCardRefund() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -1,7 +1,20 @@ |
||||
package com.hai.dao; |
||||
|
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface ApiStarbucksProductsMapperExt { |
||||
@Select(value = { |
||||
"<script>", |
||||
" select category_name from api_starbucks_products group by category_name ORDER BY create_time asc ;", |
||||
"</script>" |
||||
}) |
||||
List<String> getCategoryName(); |
||||
|
||||
|
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.hai.enum_type; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* 产品图片 |
||||
* @author hurui |
||||
*/ |
||||
public enum ProductImgEnum { |
||||
name0("product/茶瓦纳.png", "茶瓦纳"), |
||||
name1("product/冷萃咖啡.png", "冷萃咖啡"), |
||||
name2("product/浓缩咖啡.png", "浓缩咖啡"), |
||||
name3("product/其他.png", "其他"), |
||||
name4("product/星冰乐.png", "星冰乐"), |
||||
; |
||||
|
||||
private String name; |
||||
|
||||
private String imgUrl; |
||||
|
||||
public static String getNameByImgUrl(String name) { |
||||
for (ProductImgEnum ele : values()) { |
||||
if(Objects.equals(name,ele.getName())) return ele.getImgUrl(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
ProductImgEnum(String imgUrl, String name) { |
||||
this.imgUrl = imgUrl; |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getImgUrl() { |
||||
return imgUrl; |
||||
} |
||||
|
||||
public void setImgUrl(String imgUrl) { |
||||
this.imgUrl = imgUrl; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
package com.hai.model; |
||||
|
||||
import com.hai.entity.ApiStarbucksProducts; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
public class ApiStarbucksProductsModel extends ApiStarbucksProducts { |
||||
|
||||
// 抵扣比例
|
||||
private BigDecimal integralDiscount; |
||||
|
||||
// 产品展示平台
|
||||
private String productPlatformString; |
||||
|
||||
// 产品支付方式
|
||||
private String productPayTypeString; |
||||
|
||||
public BigDecimal getIntegralDiscount() { |
||||
return integralDiscount; |
||||
} |
||||
|
||||
public void setIntegralDiscount(BigDecimal integralDiscount) { |
||||
this.integralDiscount = integralDiscount; |
||||
} |
||||
|
||||
public String getProductPlatformString() { |
||||
return productPlatformString; |
||||
} |
||||
|
||||
public void setProductPlatformString(String productPlatformString) { |
||||
this.productPlatformString = productPlatformString; |
||||
} |
||||
|
||||
public String getProductPayTypeString() { |
||||
return productPayTypeString; |
||||
} |
||||
|
||||
public void setProductPayTypeString(String productPayTypeString) { |
||||
this.productPayTypeString = productPayTypeString; |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.hai.model; |
||||
|
||||
import com.hai.entity.BsProductConfig; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
public class BsProductConfigModel extends BsProductConfig { |
||||
|
||||
// 抵扣比例
|
||||
private BigDecimal integralDiscount; |
||||
|
||||
// 产品展示平台
|
||||
private String productPlatformString; |
||||
|
||||
// 产品支付方式
|
||||
private String productPayTypeString; |
||||
|
||||
//最低产品销售价格
|
||||
private BigDecimal minProductSalePrice; |
||||
|
||||
//最低产品市场价格
|
||||
private BigDecimal minProductMarketPrice; |
||||
|
||||
public BigDecimal getIntegralDiscount() { |
||||
return integralDiscount; |
||||
} |
||||
|
||||
public void setIntegralDiscount(BigDecimal integralDiscount) { |
||||
this.integralDiscount = integralDiscount; |
||||
} |
||||
|
||||
public String getProductPlatformString() { |
||||
return productPlatformString; |
||||
} |
||||
|
||||
public void setProductPlatformString(String productPlatformString) { |
||||
this.productPlatformString = productPlatformString; |
||||
} |
||||
|
||||
public String getProductPayTypeString() { |
||||
return productPayTypeString; |
||||
} |
||||
|
||||
public void setProductPayTypeString(String productPayTypeString) { |
||||
this.productPayTypeString = productPayTypeString; |
||||
} |
||||
|
||||
public BigDecimal getMinProductSalePrice() { |
||||
return minProductSalePrice; |
||||
} |
||||
|
||||
public void setMinProductSalePrice(BigDecimal minProductSalePrice) { |
||||
this.minProductSalePrice = minProductSalePrice; |
||||
} |
||||
|
||||
public BigDecimal getMinProductMarketPrice() { |
||||
return minProductMarketPrice; |
||||
} |
||||
|
||||
public void setMinProductMarketPrice(BigDecimal minProductMarketPrice) { |
||||
this.minProductMarketPrice = minProductMarketPrice; |
||||
} |
||||
} |
@ -0,0 +1,239 @@ |
||||
package com.v1.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.config.QianZhuConfig; |
||||
import com.hai.entity.ApiMerchants; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.service.*; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName ThirdPartyController.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 第三方产品接口
|
||||
* @createTime 14:48 2022/6/28 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/thirdParty") |
||||
@Api(value = "第三方产品接口") |
||||
public class ThirdPartyController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ThirdPartyController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@RequestMapping(value = "/getAllCities", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询所有城市") |
||||
public ResponseData getAllCities(@RequestBody JSONObject object , HttpServletRequest request ) { |
||||
try { |
||||
|
||||
String ip = ""; |
||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||
if (request.getHeader("x-forwarded-for") == null) { |
||||
ip = request.getRemoteAddr(); |
||||
} else { |
||||
ip = request.getHeader("x-forwarded-for"); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("IP_WHITE" , ip)) { |
||||
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(object.getString("apiKey")) || |
||||
StringUtils.isBlank(object.getString("merchId")) || |
||||
StringUtils.isBlank(object.getString("sign")) |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "商户号错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) { |
||||
log.error("getAllCities error!", "当前商户无权限查询!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前商户无权限查询!"); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("merchId" , object.getString("merchId")); |
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
JSONObject jsonObject = QianZhuConfig.getAllCities(); |
||||
|
||||
return ResponseMsgUtil.success(jsonObject.getString("data")); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getStarbucksStore", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询星巴克门店") |
||||
public ResponseData getStarbucksStore(@RequestBody JSONObject object , HttpServletRequest request ) { |
||||
try { |
||||
|
||||
String ip = ""; |
||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||
if (request.getHeader("x-forwarded-for") == null) { |
||||
ip = request.getRemoteAddr(); |
||||
} else { |
||||
ip = request.getHeader("x-forwarded-for"); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("IP_WHITE" , ip)) { |
||||
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(object.getString("apiKey")) || |
||||
StringUtils.isBlank(object.getString("merchId")) || |
||||
StringUtils.isBlank(object.getString("lat")) || |
||||
StringUtils.isBlank(object.getString("lon")) || |
||||
StringUtils.isBlank(object.getString("sign")) |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "商户号错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) { |
||||
log.error("getAllCities error!", "当前商户无权限查询!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前商户无权限查询!"); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("merchId" , object.getString("merchId")); |
||||
map.put("lat" , object.getString("lat")); |
||||
map.put("lon" , object.getString("lon")); |
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
JSONObject jsonObject = QianZhuConfig.getStarbucksStore(object.getString("lat") , object.getString("lon")); |
||||
|
||||
if (jsonObject.getBoolean("success")) { |
||||
return ResponseMsgUtil.success(jsonObject.getString("data")); |
||||
} else { |
||||
log.error("getRechargeProduct error!", "查询失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getStarbucksProducts", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询星巴克商品") |
||||
public ResponseData getStarbucksProducts(@RequestBody JSONObject object , HttpServletRequest request ) { |
||||
try { |
||||
|
||||
String ip = ""; |
||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||
if (request.getHeader("x-forwarded-for") == null) { |
||||
ip = request.getRemoteAddr(); |
||||
} else { |
||||
ip = request.getHeader("x-forwarded-for"); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("IP_WHITE" , ip)) { |
||||
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(object.getString("apiKey")) || |
||||
StringUtils.isBlank(object.getString("merchId")) || |
||||
StringUtils.isBlank(object.getString("pageIndex")) || |
||||
StringUtils.isBlank(object.getString("pageSize")) || |
||||
StringUtils.isBlank(object.getString("sign")) |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "商户号错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) { |
||||
log.error("getAllCities error!", "当前商户无权限查询!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前商户无权限查询!"); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("merchId" , object.getString("merchId")); |
||||
map.put("pageSize" , object.getString("pageSize")); |
||||
map.put("pageIndex" , object.getString("pageIndex")); |
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
JSONObject jsonObject = QianZhuConfig.getStarbucksProducts(object.getInteger("pageIndex") , object.getInteger("pageSize")); |
||||
|
||||
if (jsonObject.getBoolean("success")) { |
||||
return ResponseMsgUtil.success(jsonObject.getString("data")); |
||||
} else { |
||||
log.error("getRechargeProduct error!", "查询失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue