diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopStoreSfSupplier.java b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopStoreSfSupplier.java new file mode 100644 index 00000000..9f0bc158 --- /dev/null +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopStoreSfSupplier.java @@ -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; +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java index 7e340d36..bce5bb23 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java @@ -388,7 +388,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService { * @param contactPhone 店铺电话 * @param longitude 经度 * @param latitude 纬度 - * @return Pair 第一个元素表示是否成功,第二个元素表示结果信息或错误信息 + * @return Pair 第一个元素表示是否成功,第二个元素表示结果信息(成功返回顺丰店铺Id)或错误信息 */ @Override public Pair createSfExpressShopInner(Integer storeId, String optSupplierId, String shopName, String cityName, diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopStoreSfSupplierMapper.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopStoreSfSupplierMapper.java new file mode 100644 index 00000000..bca60c4b --- /dev/null +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopStoreSfSupplierMapper.java @@ -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; + +/** + *

+ * 权限表 Mapper 接口 + *

+ * + * @author Xinze + * @since 2021-09-28 + */ + +@Repository +public interface ShopStoreSfSupplierMapper extends BaseMapper { + +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreSfSupplierService.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreSfSupplierService.java new file mode 100644 index 00000000..6d6bf91a --- /dev/null +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreSfSupplierService.java @@ -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 { + + + /** + * 根据区域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); + +} + diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java index d88daf4e..67e590e0 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java @@ -1582,12 +1582,12 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("parent_id", s.get("store_id")) .eq("store_is_open", CommonConstant.Enable); - Map data = getLists(queryWrapper, 1, 500); + Map data = getLists(queryWrapper, 1, 100); List branchItems = (List) data.get("items"); if (CollUtil.isNotEmpty(branchItems)) { diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreSameCityTransportBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreSameCityTransportBaseServiceImpl.java index 7c1c348c..9a018e4a 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreSameCityTransportBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreSameCityTransportBaseServiceImpl.java @@ -400,7 +400,7 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl 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 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 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 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(); + } + +}