顺丰手动创建店铺,相关代码

This commit is contained in:
Jack 2026-01-14 10:09:39 +08:00
parent d819216b4a
commit 0597b03f8d
7 changed files with 333 additions and 4 deletions

View File

@ -0,0 +1,73 @@
package com.suisung.mall.common.modules.store;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("shop_store_sf_supplier")
@ApiModel(value = "顺丰地区提供商商家ID表", description = "顺丰地区提供商商家ID表")
public class ShopStoreSfSupplier {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "自增ID")
@TableId(value = "id", type = IdType.AUTO)
@JsonProperty("id")
private Long id;
@ApiModelProperty(value = "商家Id")
@JsonProperty("supplier_id")
private String supplier_id;
@ApiModelProperty(value = "省份Id")
@JsonProperty("province_id")
private String province_id;
@ApiModelProperty(value = "省份名称")
@JsonProperty("province_name")
private String province_name;
@ApiModelProperty(value = "城市Id")
@JsonProperty("city_id")
private String city_id;
@ApiModelProperty(value = "城市名称")
@JsonProperty("city_name")
private String city_name;
@ApiModelProperty(value = "区域Id")
@JsonProperty("district_id")
private String district_id;
@ApiModelProperty(value = "区域名称")
@JsonProperty("district_name")
private String district_name;
@ApiModelProperty(value = "状态1-有效2-无效;")
@JsonProperty("status")
private Integer status;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonProperty("created_at")
@ApiModelProperty(value = "新建时间")
private Date created_at;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间")
@JsonProperty("updated_at")
private Date updated_at;
}

View File

@ -388,7 +388,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
* @param contactPhone 店铺电话 * @param contactPhone 店铺电话
* @param longitude 经度 * @param longitude 经度
* @param latitude 纬度 * @param latitude 纬度
* @return Pair<Boolean, String> 第一个元素表示是否成功第二个元素表示结果信息或错误信息 * @return Pair<Boolean, String> 第一个元素表示是否成功第二个元素表示结果信息成功返回顺丰店铺Id或错误信息
*/ */
@Override @Override
public Pair<Boolean, String> createSfExpressShopInner(Integer storeId, String optSupplierId, String shopName, String cityName, public Pair<Boolean, String> createSfExpressShopInner(Integer storeId, String optSupplierId, String shopName, String cityName,

View File

@ -0,0 +1,19 @@
package com.suisung.mall.shop.store.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.suisung.mall.common.modules.store.ShopStoreSfSupplier;
import org.springframework.stereotype.Repository;
/**
* <p>
* 权限表 Mapper 接口
* </p>
*
* @author Xinze
* @since 2021-09-28
*/
@Repository
public interface ShopStoreSfSupplierMapper extends BaseMapper<ShopStoreSfSupplier> {
}

View File

@ -0,0 +1,44 @@
package com.suisung.mall.shop.store.service;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.store.ShopStoreSfSupplier;
import com.suisung.mall.core.web.service.IBaseService;
public interface ShopStoreSfSupplierService extends IBaseService<ShopStoreSfSupplier> {
/**
* 根据区域ID查询
*
* @param districtId
* @return
*/
ShopStoreSfSupplier getByDistrictId(String districtId);
/**
* 添加或更新
*
* @param shopStoreSfSupplier
* @return
*/
Boolean addOrUpdate(ShopStoreSfSupplier shopStoreSfSupplier);
/**
* 检测是否可重新生成sf店铺ID
*
* @param storeId 店铺ID
* @return
*/
CommonResult checkReCreateSfShopId(Integer storeId);
/**
* 重新生成sf店铺ID
*
* @param storeId 店铺ID
* @param sfSupplierId 顺丰平台商家Id
* @return
*/
CommonResult reCreateSfShopId(Integer storeId, String sfSupplierId);
}

View File

@ -1582,12 +1582,12 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
// 处理分店信息限制递归深度以避免栈溢出 // 处理分店信息限制递归深度以避免栈溢出
Integer parentId = Convert.toInt(s.get("parent_id")); Integer parentId = Convert.toInt(s.get("parent_id"));
if (parentId != null && parentId == 0) { if (parentId != null && parentId <= 0) {
QueryWrapper<ShopStoreBase> queryWrapper = new QueryWrapper<>(); QueryWrapper<ShopStoreBase> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("parent_id", s.get("store_id")) queryWrapper.eq("parent_id", s.get("store_id"))
.eq("store_is_open", CommonConstant.Enable); .eq("store_is_open", CommonConstant.Enable);
Map data = getLists(queryWrapper, 1, 500); Map data = getLists(queryWrapper, 1, 100);
List<Map> branchItems = (List<Map>) data.get("items"); List<Map> branchItems = (List<Map>) data.get("items");
if (CollUtil.isNotEmpty(branchItems)) { if (CollUtil.isNotEmpty(branchItems)) {

View File

@ -400,7 +400,7 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
queryWrapper.eq("is_platform", isPlatform); queryWrapper.eq("is_platform", isPlatform);
queryWrapper.eq("status", CommonConstant.Enable); queryWrapper.eq("status", CommonConstant.Enable);
return getOne(queryWrapper); return getOne(queryWrapper, false);
} }
/** /**

View File

@ -0,0 +1,193 @@
package com.suisung.mall.shop.store.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.modules.store.ShopMchEntry;
import com.suisung.mall.common.modules.store.ShopStoreSameCityTransportBase;
import com.suisung.mall.common.modules.store.ShopStoreSfSupplier;
import com.suisung.mall.common.pojo.to.AddressParseResultTO;
import com.suisung.mall.common.utils.AddressUtil;
import com.suisung.mall.common.utils.CheckUtil;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.sfexpress.service.SFExpressApiService;
import com.suisung.mall.shop.store.mapper.ShopStoreSameCityTransportBaseMapper;
import com.suisung.mall.shop.store.mapper.ShopStoreSfSupplierMapper;
import com.suisung.mall.shop.store.service.ShopMchEntryService;
import com.suisung.mall.shop.store.service.ShopStoreSameCityTransportBaseService;
import com.suisung.mall.shop.store.service.ShopStoreSfSupplierService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
public class ShopStoreSfSupplierServiceImpl extends BaseServiceImpl<ShopStoreSfSupplierMapper, ShopStoreSfSupplier> implements ShopStoreSfSupplierService {
private static final Logger logger = LoggerFactory.getLogger(ShopStoreSfSupplierServiceImpl.class);
@Lazy
@Resource
private ShopStoreSameCityTransportBaseService shopStoreSameCityTransportBaseService;
@Lazy
@Resource
private ShopStoreSameCityTransportBaseMapper shopStoreSameCityTransportBaseMapper;
@Lazy
@Resource
private SFExpressApiService sFExpressApiService;
@Lazy
@Resource
private ShopMchEntryService shopMchEntryService;
/**
* 根据区域ID查询顺丰供应商信息
*
* @param districtId 区域ID
* @return 顺丰供应商信息
*/
@Override
public ShopStoreSfSupplier getByDistrictId(String districtId) {
if (StrUtil.isBlank(districtId)) {
logger.debug("区域ID为空返回null");
return null;
}
LambdaQueryWrapper<ShopStoreSfSupplier> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopStoreSfSupplier::getDistrict_id, districtId)
.eq(ShopStoreSfSupplier::getStatus, CommonConstant.Enable)
.orderByDesc(ShopStoreSfSupplier::getId);
return getOne(wrapper, false);
}
/**
* 根据供应商ID添加或更新顺丰供应商信息
*
* @param shopStoreSfSupplier 顺丰供应商信息
* @return 操作结果
*/
@Override
public Boolean addOrUpdate(ShopStoreSfSupplier shopStoreSfSupplier) {
if (shopStoreSfSupplier == null) {
logger.warn("参数对象为空");
return false;
}
String supplierId = shopStoreSfSupplier.getSupplier_id();
if (StrUtil.isBlank(supplierId)) {
logger.warn("供应商ID为空无法执行操作");
return false;
}
LambdaQueryWrapper<ShopStoreSfSupplier> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopStoreSfSupplier::getSupplier_id, supplierId);
ShopStoreSfSupplier existingRecord = getOne(wrapper, false);
boolean result;
if (existingRecord != null) {
// 更新现有记录
shopStoreSfSupplier.setId(existingRecord.getId());
result = updateById(shopStoreSfSupplier);
logger.info("更新顺丰地区提供商商家记录: supplier_id={}, result={}", supplierId, result);
} else {
// 新增记录
result = save(shopStoreSfSupplier);
logger.info("新增顺丰地区提供商商家记录: supplier_id={}, result={}", supplierId, result);
}
return result;
}
/**
* 检测是否可重新生成sf店铺ID
*
* @param storeId 店铺ID
* @return
*/
@Override
public CommonResult checkReCreateSfShopId(Integer storeId) {
return null;
}
/**
* 重新生成sf店铺ID
*
* @param storeId 店铺ID
* @param sfSupplierId 顺丰平台商家Id
* @return
*/
@Transactional
@Override
public CommonResult reCreateSfShopId(Integer storeId, String sfSupplierId) {
if (CheckUtil.isEmpty(storeId) || StrUtil.isBlank(sfSupplierId)) {
return CommonResult.failed("缺少必要参数");
}
ShopStoreSameCityTransportBase sameCityTransportBase = shopStoreSameCityTransportBaseService.getShopStoreSameCityTransportBaseById(Convert.toLong(storeId), 2);
if (sameCityTransportBase == null) {
return CommonResult.failed("请配置店铺配送设置,再重试");
}
ShopMchEntry shopMchEntry = shopMchEntryService.getShopMerchEntryByStoreId(storeId);
if (shopMchEntry == null) {
return CommonResult.failed("为找到商家入驻信息,请检查");
}
// 省市区名称
String storeArea = shopMchEntry.getStore_area();
// 省市区Id
String storeDistrict = shopMchEntry.getStore_district();
AddressParseResultTO addressParseResultTO = AddressUtil.parseAddress(shopMchEntry.getStore_address());
String cityName = "桂平市";
String shopAddress = addressParseResultTO != null ? addressParseResultTO.getDetailAddress() : "";
String[] areaNames;
if (StrUtil.isNotBlank(shopMchEntry.getStore_area())) {
areaNames = shopMchEntry.getStore_area().split("/");
cityName = areaNames.length >= 3 ? areaNames[2] :
areaNames.length > 0 ? areaNames[areaNames.length - 1] : cityName;
} else if (addressParseResultTO != null && StrUtil.isNotBlank(addressParseResultTO.getCity())) {
cityName = addressParseResultTO.getCity();
}
if (StrUtil.isBlank(cityName)) {
cityName = "桂平市";
logger.warn("[顺丰] 城市名为空,使用默认城市: {}", cityName);
} else {
logger.debug("[顺丰] 解析得到城市名: {}", cityName);
}
Pair<Boolean, String> result = sFExpressApiService.createSfExpressShopInner(storeId, sfSupplierId, shopMchEntry.getStore_name(),
cityName, shopAddress, shopMchEntry.getContact_name(), shopMchEntry.getLogin_mobile(),
shopMchEntry.getStore_longitude(), shopMchEntry.getStore_latitude());
if (Boolean.FALSE.equals(result.getFirst())) {
return CommonResult.failed(result.getSecond());
}
// 更改店铺sf店铺ID
sameCityTransportBase.setSupplier_id(sfSupplierId);
sameCityTransportBase.setShop_id(result.getSecond());
shopStoreSameCityTransportBaseMapper.updateById(sameCityTransportBase);
ShopStoreSfSupplier record = new ShopStoreSfSupplier();
record.setSupplier_id(sfSupplierId);
addOrUpdate(record);
return CommonResult.success();
}
}