|
@@ -1,43 +1,27 @@
|
|
|
package com.ydd.module.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ydd.common.core.domain.entity.SysUser;
|
|
|
-import com.ydd.common.core.page.PageResult;
|
|
|
-import com.ydd.common.enums.DeliveryTypeEnums;
|
|
|
import com.ydd.common.enums.UserTypeEnums;
|
|
|
-import com.ydd.common.exception.CustomException;
|
|
|
-import com.ydd.common.utils.SnCodeUtils;
|
|
|
-import com.ydd.ecloud.core.utils.JsonMapper;
|
|
|
import com.ydd.module.domain.*;
|
|
|
-import com.ydd.module.dto.*;
|
|
|
-import com.ydd.module.enums.*;
|
|
|
-import com.ydd.module.expection.CustomAppException;
|
|
|
+import com.ydd.module.dto.DeliveryDto;
|
|
|
+import com.ydd.module.dto.ShopDto;
|
|
|
+import com.ydd.module.enums.MemberTypeEnum;
|
|
|
+import com.ydd.module.enums.PackageCityConfigPackageTypeEnum;
|
|
|
import com.ydd.module.expection.CustomWebException;
|
|
|
import com.ydd.module.mapper.ShopMapper;
|
|
|
import com.ydd.module.request.ShopBindRulePackageRequest;
|
|
|
import com.ydd.module.service.*;
|
|
|
-import com.ydd.third.common.utils.AddressLngLatExchanger;
|
|
|
-import com.ydd.third.common.vo.ResObject;
|
|
|
-import com.ydd.third.delivery.Client;
|
|
|
-import com.ydd.third.delivery.vo.shop.ShopResultVo;
|
|
|
-import com.ydd.third.delivery.vo.shop.ShopVo;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.compress.utils.Lists;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 商家门店Service业务层处理
|
|
@@ -46,7 +30,6 @@ import java.util.stream.Collectors;
|
|
|
* @date 2021-02-01
|
|
|
*/
|
|
|
@Service
|
|
|
-@Slf4j
|
|
|
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IShopService {
|
|
|
|
|
|
@Resource
|
|
@@ -70,21 +53,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
|
|
|
@Resource
|
|
|
private IPackageCommissionService iPackageCommissionService;
|
|
|
|
|
|
- @Resource
|
|
|
- private IPackageFreightService iPackageFreightService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private IShopThirdService iShopThirdService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private IShopDeliveryService iShopDeliveryService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private IDspDeliveryService iDspDeliveryService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private Client deliveryClient;
|
|
|
-
|
|
|
@Override
|
|
|
public List<Shop> queryList(Shop shop) {
|
|
|
LambdaQueryWrapper<Shop> lqw = Wrappers.lambdaQuery();
|
|
@@ -188,8 +156,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ShopDto> findList(Long merchantId,Long shopId) {
|
|
|
- return baseMapper.findList(merchantId,shopId);
|
|
|
+ public List<ShopDto> findList(Long merchantId) {
|
|
|
+ return baseMapper.findList(merchantId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -219,11 +187,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Long> findShopIdByMerchantId(List<Long> merchantIds) {
|
|
|
- return baseMapper.findShopIdByMerchantId(merchantIds);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public List<Integer> findByMerchantId(Integer merchantId) {
|
|
|
return baseMapper.findByMerchantId(merchantId);
|
|
|
}
|
|
@@ -335,475 +298,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ShopBindDto> findListByMerchantId(Long merchantId) {
|
|
|
- return baseMapper.findListByMerchantId(merchantId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<ShopBindDto> findListById(Long shopId) {
|
|
|
- return baseMapper.findListById(shopId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Long> getIdListByFreightPackageId(Long freightPackageId) {
|
|
|
- List<Long> merchantIds = baseMapper.getIdListByFreightPackageId(freightPackageId);
|
|
|
- return CollectionUtils.isNotEmpty(merchantIds) ? merchantIds : Lists.newArrayList();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<DadaDspMerchantShopInfoDto> queryShopListByMerchantId(DadaDspMerchantShopListQuery shopListQuery) {
|
|
|
- return baseMapper.queryShopListByMerchantId(shopListQuery);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PageResult queryDadaShopList(DadaShopListQuery listQuery, SysUser user) {
|
|
|
- if (UserTypeEnums.DADA_DELIVERY_RAP.getCode().equals(user.getType())
|
|
|
- || UserTypeEnums.DADA_DELIVERY.getCode().equals(user.getType())) {
|
|
|
- listQuery.setDadaDspId(user.getDadaDspId());
|
|
|
- }
|
|
|
- if (UserTypeEnums.DADA_MERCHANT.getCode().equals(user.getType())) {
|
|
|
- Merchant merchant = iMerchantService.findByMobile(user.getPhonenumber());
|
|
|
- listQuery.setMerchantId(merchant != null ? merchant.getId() : null);
|
|
|
- }
|
|
|
- if (listQuery.getFreightPackageId() != null) {
|
|
|
- PackageFreight packageFreight = iPackageFreightService.getById(listQuery.getFreightPackageId());
|
|
|
- if (packageFreight != null) {
|
|
|
- listQuery.setDimension(packageFreight.getDimension());
|
|
|
- }
|
|
|
- }
|
|
|
- Page<DadaShopListDto> page = baseMapper.queryDadaShopList(listQuery, new Page<>(listQuery.getPageNum(), listQuery.getPageSize()));
|
|
|
- List<DadaShopListDto> list = page.getRecords();
|
|
|
- for (DadaShopListDto shopListDto : list) {
|
|
|
- // 门店运费包
|
|
|
- PackageFreight packageFreight = iPackageFreightService.getById(shopListDto.getFreightPackageId());
|
|
|
- int dimension = 2;
|
|
|
- if (packageFreight == null) {
|
|
|
- // 商户运费包
|
|
|
- packageFreight = iPackageFreightService.getById(shopListDto.getMerchantFreightPackageId());
|
|
|
- dimension = 1;
|
|
|
- }
|
|
|
- if (packageFreight == null) {
|
|
|
- // 全国运费包
|
|
|
- Optional<PackageFreight> first = iPackageFreightService.list(new QueryWrapper<PackageFreight>()
|
|
|
- .eq("dimension", PackageFreightDimensionEnum.NORMAL.getType())
|
|
|
- .eq("dada_dsp_id", user.getDadaDspId())
|
|
|
- .eq("deleted", 0)
|
|
|
- .orderByDesc("id")).stream().findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- packageFreight = first.get();
|
|
|
- dimension = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- shopListDto.setFreightPackageName(packageFreight == null ? "" : packageFreight.getName());
|
|
|
- shopListDto.setDimensionName(packageFreight != null ? PackageFreightDimensionEnum.getNameByType(dimension) : "");
|
|
|
- }
|
|
|
- return new PageResult(page);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Merchant> queryDadaMerchantList(Long dadaDspId) {
|
|
|
- LambdaQueryWrapper<Merchant> lqw = Wrappers.lambdaQuery();
|
|
|
- if (dadaDspId != null && dadaDspId != 0){
|
|
|
- lqw.eq(Merchant::getDadaDspId ,dadaDspId);
|
|
|
- }
|
|
|
- lqw.orderByDesc(Merchant::getId);
|
|
|
- return iMerchantService.list(lqw);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean bindFreightPackage(DadaDspBindFreightQuery bindFreightQuery) {
|
|
|
- int result = baseMapper.update(null,
|
|
|
- new UpdateWrapper<Shop>()
|
|
|
- .set("freight_package_id", bindFreightQuery.getPackageId())
|
|
|
- .eq("id", bindFreightQuery.getShopId()));
|
|
|
- return result == 1;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public boolean saveDadaShop(DadaShopAddQuery shopReq, SysUser user) {
|
|
|
- if (StringUtils.isBlank(shopReq.getProvinceName())
|
|
|
- || StringUtils.isBlank(shopReq.getCityName())
|
|
|
- || StringUtils.isBlank(shopReq.getDistrictName())
|
|
|
- || StringUtils.isBlank(shopReq.getAddress())
|
|
|
- || StringUtils.isBlank(shopReq.getStreet())) {
|
|
|
- throw new CustomWebException("省市区详细地址、门牌号不可为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getName())){
|
|
|
- throw new CustomWebException("门店名称不能为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getContactName())){
|
|
|
- throw new CustomWebException("联系人名称不能为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getMobile()) || shopReq.getMobile().length() != 11) {
|
|
|
- throw new CustomException("联系电话不可为空, 且长度为11位!");
|
|
|
- }
|
|
|
- Merchant merchant = iMerchantService.getById(shopReq.getMerchantId());
|
|
|
- if (merchant == null) {
|
|
|
- throw new CustomAppException("商家不存在!");
|
|
|
- }
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
- throw new CustomAppException("该商家已禁用!");
|
|
|
- }
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
- throw new CustomAppException("请等待商家通过认证!");
|
|
|
- }
|
|
|
- Long categoryId = merchant.getCategoryId();
|
|
|
- if (null != shopReq.getCategoryId()){
|
|
|
- categoryId = shopReq.getCategoryId();
|
|
|
- }
|
|
|
- // 根据详细地址获取经纬度等信息
|
|
|
- String address = shopReq.getProvinceName() + shopReq.getCityName() + shopReq.getDistrictName() + shopReq.getAddress() + shopReq.getStreet();
|
|
|
- Map<String, Object> lngLanMap = AddressLngLatExchanger.addressToLngAndLag(address);
|
|
|
- if (lngLanMap == null || lngLanMap.get("lat") == null || lngLanMap.get("lng") == null) {
|
|
|
- throw new CustomWebException("解析地址经纬度失败!");
|
|
|
- }
|
|
|
- shopReq.setLat(String.valueOf(lngLanMap.get("lat")));
|
|
|
- shopReq.setLng(String.valueOf(lngLanMap.get("lng")));
|
|
|
- shopReq.setCityCode(String.valueOf(lngLanMap.get("cityCode")));
|
|
|
-
|
|
|
- Shop shop = this.saveOrUpdateShop(shopReq, null, categoryId, merchant.getId());
|
|
|
-
|
|
|
- Member member = iMemberService.findOne(merchant.getId());
|
|
|
- // 默认第一次创建的门店设为商家默认门店
|
|
|
- if (member != null && member.getShopId() == null) {
|
|
|
- member.setShopId(shop.getId());
|
|
|
- boolean memberUpdate = iMemberService.updateById(member);
|
|
|
- if (!memberUpdate) {
|
|
|
- throw new CustomAppException("用户默认门店变更失败!");
|
|
|
- }
|
|
|
- }
|
|
|
- MerchantCategory category = iMerchantCategoryService.getById(categoryId);
|
|
|
- if (category == null){
|
|
|
- throw new CustomAppException("门店分类不存在!");
|
|
|
- }
|
|
|
- // 创建三方门店,如果通过自动绑定该运力
|
|
|
- ShopVo shopVo = this.createShopVo(shop, category.getDadaProductType());
|
|
|
- log.info("门店信息:{}", JsonMapper.nonEmptyMapper().toJson(shopVo));
|
|
|
- ResObject<ShopResultVo> res = deliveryClient.createShop(shopVo);
|
|
|
- log.info("创建三方门店返回结果: {}", JsonMapper.nonEmptyMapper().toJson(res));
|
|
|
-
|
|
|
- DspDelivery dspDelivery = iDspDeliveryService.findOne(DeliveryTypeEnums.DADA.getType());
|
|
|
- ShopDelivery delivery = new ShopDelivery();
|
|
|
- delivery.setDeliveryId(dspDelivery.getId());
|
|
|
- delivery.setMerchantId(shop.getMerchantId());
|
|
|
- delivery.setShopId(shop.getId());
|
|
|
- if (res.getCode() == 0) {
|
|
|
- ShopResultVo shopResultVo = res.getData();
|
|
|
- String shopId = shopResultVo.getShopId();
|
|
|
- delivery.setBindStatus(BindStatusEnum.BIND.getStatus());
|
|
|
- delivery.setThirdShopId(shopId);
|
|
|
- } else {
|
|
|
- delivery.setAuthMsg(res.getMsg());
|
|
|
- }
|
|
|
- boolean result2 = iShopDeliveryService.save(delivery);
|
|
|
- if (!result2) {
|
|
|
- throw new CustomWebException("保存门店对应第三方运力信息失败!");
|
|
|
- }
|
|
|
-
|
|
|
- this.saveShopThird(shopReq, delivery.getDeliveryId(), shop.getId());
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private void saveShopThird(DadaShopAddQuery shopReq, Long deliveryId, Long shopId) {
|
|
|
- // 存lb_shop_third表中
|
|
|
- ShopThird shopThird = new ShopThird();
|
|
|
- shopThird.setShopId(shopReq.getId());
|
|
|
- shopThird.setAddress(shopReq.getAddress());
|
|
|
- shopThird.setContactName(shopReq.getContactName());
|
|
|
- shopThird.setLat(shopReq.getLat());
|
|
|
- shopThird.setLng(shopReq.getLng());
|
|
|
- shopThird.setCityCode(shopReq.getCityCode());
|
|
|
- shopThird.setMobile(shopReq.getMobile());
|
|
|
- shopThird.setName(shopReq.getName());
|
|
|
- shopThird.setStreet(shopReq.getStreet());
|
|
|
- shopThird.setDeliveryId(deliveryId);
|
|
|
- shopThird.setShopId(shopId);
|
|
|
- shopThird.setProvinceName(shopReq.getProvinceName());
|
|
|
- shopThird.setCityName(shopReq.getCityName());
|
|
|
- shopThird.setDistrictName(shopReq.getDistrictName());
|
|
|
- boolean result = iShopThirdService.saveOrUpdate(shopThird);
|
|
|
- if (!result) {
|
|
|
- throw new CustomWebException("保存门店对应第三方门店信息失败!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private Shop saveOrUpdateShop(DadaShopAddQuery shopReq, Shop shop, Long categoryId, Long merchantId) {
|
|
|
- if (shop == null) {
|
|
|
- shop = new Shop();
|
|
|
- }
|
|
|
- if (shop.getId() == null) {
|
|
|
- shop.setCode(SnCodeUtils.createShopSn());
|
|
|
- }
|
|
|
- shop.setAddress(shopReq.getAddress());
|
|
|
- shop.setStreet(shopReq.getStreet());
|
|
|
- shop.setCategoryId(categoryId);
|
|
|
- shop.setContactName(shopReq.getContactName());
|
|
|
- shop.setLat(shopReq.getLat());
|
|
|
- shop.setLng(shopReq.getLng());
|
|
|
- shop.setMerchantId(merchantId);
|
|
|
- shop.setMobile(shopReq.getMobile());
|
|
|
- shop.setName(shopReq.getName());
|
|
|
- shop.setStreet(shopReq.getStreet());
|
|
|
- shop.setProvinceName(shopReq.getProvinceName());
|
|
|
- shop.setCityName(shopReq.getCityName());
|
|
|
- shop.setDistrictName(shopReq.getDistrictName());
|
|
|
- shop.setCityCode(shopReq.getCityCode());
|
|
|
- shop.setProvinceId(shopReq.getProvinceId());
|
|
|
- shop.setCityId(shopReq.getCityId());
|
|
|
- shop.setDistrictId(shopReq.getDistrictId());
|
|
|
- boolean result1 = this.saveOrUpdate(shop);
|
|
|
- if (!result1) {
|
|
|
- throw new CustomWebException("保存门店信息失败!");
|
|
|
- }
|
|
|
- return shop;
|
|
|
- }
|
|
|
-
|
|
|
- private ShopVo createShopVo(Shop shop, Integer dadaCategory) {
|
|
|
- ShopVo shopVo = new ShopVo();
|
|
|
- shopVo.setLbClient(DeliveryTypeEnums.DADA.getName());
|
|
|
- /**
|
|
|
- * 门店名称
|
|
|
- * 达达:station_name,门店名称,必传
|
|
|
- * */
|
|
|
- shopVo.setShopName(shop.getName());
|
|
|
- /**
|
|
|
- * 业务类型
|
|
|
- * 达达:business,必传,业务类型
|
|
|
- * (食品小吃-1,饮料-2,鲜花-3,文印票务-8,便利店-9,水果生鲜-13,同城电商-19, 医药-20,蛋糕-21,酒品-24,小商品市场-25,服装-26,汽修零配-27,
|
|
|
- * 数码-28,小龙虾-29,火锅-51,其他-5)
|
|
|
- */
|
|
|
- shopVo.setBusiness(dadaCategory);
|
|
|
- /**
|
|
|
- * 城市名称
|
|
|
- * 达达:city_name 必传,城市名称(如,上海)
|
|
|
- */
|
|
|
- shopVo.setCityName(shop.getCityName());
|
|
|
- /**
|
|
|
- * 区域名称
|
|
|
- * 达达:area_name 必传, 区域名称(如,浦东新区)
|
|
|
- */
|
|
|
- shopVo.setAreaName(shop.getDistrictName());
|
|
|
- /**
|
|
|
- * 门店地址
|
|
|
- * 达达:station_address 必传,门店地址
|
|
|
- */
|
|
|
- shopVo.setShopAddress(shop.getAddress()+shop.getStreet());
|
|
|
- /**
|
|
|
- *门店经度
|
|
|
- * 达达:lng 必传,门店经度,店铺经度
|
|
|
- */
|
|
|
- shopVo.setShopLng(new BigDecimal(shop.getLng()));
|
|
|
- /**
|
|
|
- * 门店纬度
|
|
|
- * 达达:lat 必传,门店纬度
|
|
|
- */
|
|
|
- shopVo.setShopLat(new BigDecimal(shop.getLat()));
|
|
|
- /**
|
|
|
- * 联系人姓名
|
|
|
- * 达达:contact_name 必传 联系人姓名
|
|
|
- */
|
|
|
- shopVo.setContactName(shop.getContactName());
|
|
|
- /**
|
|
|
- * 联系人电话
|
|
|
- * 达达:phone 必传,联系人电话
|
|
|
- */
|
|
|
- shopVo.setContactPhone(shop.getMobile());
|
|
|
- return shopVo;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Shop> getDadaShopOption(SysUser user) {
|
|
|
- List<Merchant> merchantList = iMerchantService.list(new QueryWrapper<Merchant>()
|
|
|
- .eq(user.getDadaDspId() != null, "dada_dsp_id", user.getDadaDspId())
|
|
|
- .isNotNull(user.getDadaDspId() == null, "dada_dsp_id")
|
|
|
- .eq("deleted", 0));
|
|
|
- List<Shop> shopList = Lists.newArrayList();
|
|
|
- if (CollectionUtils.isNotEmpty(merchantList)) {
|
|
|
- List<Long> merchantIds = merchantList.stream().map(Merchant::getId).collect(Collectors.toList());
|
|
|
- shopList = this.list(new QueryWrapper<Shop>()
|
|
|
- .in("merchant_id", merchantIds)
|
|
|
- .eq("deleted", 0));
|
|
|
-
|
|
|
- }
|
|
|
- return shopList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean editDadaShop(DadaShopAddQuery shopReq, SysUser user) {
|
|
|
- Shop shop = this.getById(shopReq.getId());
|
|
|
- if (shop == null) {
|
|
|
- throw new CustomWebException("门店不存在!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getProvinceName())
|
|
|
- || StringUtils.isBlank(shopReq.getCityName())
|
|
|
- || StringUtils.isBlank(shopReq.getDistrictName())
|
|
|
- || StringUtils.isBlank(shopReq.getAddress())
|
|
|
- || StringUtils.isBlank(shopReq.getStreet())) {
|
|
|
- throw new CustomWebException("省市区详细地址、门牌号不可为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getName())){
|
|
|
- throw new CustomWebException("门店名称不能为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getContactName())){
|
|
|
- throw new CustomWebException("联系人名称不能为空!");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(shopReq.getMobile()) || shopReq.getMobile().length() != 11) {
|
|
|
- throw new CustomException("联系电话不可为空, 且长度为11位!");
|
|
|
- }
|
|
|
- Merchant merchant = iMerchantService.getById(shopReq.getMerchantId());
|
|
|
- if (merchant == null) {
|
|
|
- throw new CustomAppException("商家不存在!");
|
|
|
- }
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
- throw new CustomAppException("该商家已禁用!");
|
|
|
- }
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
- throw new CustomAppException("请等待商家通过认证!");
|
|
|
- }
|
|
|
- Long categoryId = merchant.getCategoryId();
|
|
|
- if (null != shopReq.getCategoryId()){
|
|
|
- categoryId = shopReq.getCategoryId();
|
|
|
- }
|
|
|
- MerchantCategory category = iMerchantCategoryService.getById(categoryId);
|
|
|
- if (category == null){
|
|
|
- throw new CustomAppException("门店分类不存在!");
|
|
|
- }
|
|
|
- // 根据详细地址获取经纬度等信息
|
|
|
- String address = shopReq.getProvinceName() + shopReq.getCityName() + shopReq.getDistrictName() + shopReq.getAddress();
|
|
|
- Map<String, Object> lngLanMap = AddressLngLatExchanger.addressToLngAndLag(address);
|
|
|
- if (lngLanMap == null || lngLanMap.get("lat") == null || lngLanMap.get("lng") == null) {
|
|
|
- throw new CustomWebException("解析地址经纬度失败!");
|
|
|
- }
|
|
|
- shopReq.setLat(String.valueOf(lngLanMap.get("lat")));
|
|
|
- shopReq.setLng(String.valueOf(lngLanMap.get("lng")));
|
|
|
- shopReq.setCityCode(String.valueOf(lngLanMap.get("cityCode")));
|
|
|
-
|
|
|
- // 修改门店信息
|
|
|
- shop = this.saveOrUpdateShop(shopReq, shop, categoryId, merchant.getId());
|
|
|
-
|
|
|
- DspDelivery dspDelivery = iDspDeliveryService.findOne(DeliveryTypeEnums.DADA.getType());
|
|
|
- // 修改三方门店信息
|
|
|
- ShopDelivery delivery = iShopDeliveryService.findOne(shop.getId(), dspDelivery.getId());
|
|
|
- if (delivery.getThirdShopId() != null) {
|
|
|
- // 更新
|
|
|
- ShopVo shopVo = this.editShopVo(shop, category.getDadaProductType(), delivery.getThirdShopId());
|
|
|
- log.info("门店信息:{}", JsonMapper.nonEmptyMapper().toJson(shopVo));
|
|
|
- ResObject<ShopResultVo> res = deliveryClient.updateShop(shopVo);
|
|
|
- log.info("变更三方门店返回结果: {}", JsonMapper.nonEmptyMapper().toJson(res));
|
|
|
- if (res.getCode() == 0) {//操作成功
|
|
|
- ShopResultVo shopResultVo = res.getData();
|
|
|
- String shopId = shopResultVo.getShopId();
|
|
|
- delivery.setBindStatus(BindStatusEnum.BIND.getStatus());
|
|
|
- delivery.setThirdShopId(shopId);
|
|
|
- } else {
|
|
|
- delivery.setAuthMsg(res.getMsg());
|
|
|
- }
|
|
|
- boolean result2 = iShopDeliveryService.updateById(delivery);
|
|
|
- if (!result2) {
|
|
|
- throw new CustomWebException("保存门店对应第三方运力信息失败!");
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 新增
|
|
|
- Shop shop1 = new Shop();
|
|
|
- BeanUtils.copyProperties(shopReq, shop1);
|
|
|
- ShopVo shopVo = this.createShopVo(shop1, category.getDadaProductType());
|
|
|
- log.info("门店信息:{}", JsonMapper.nonEmptyMapper().toJson(shopVo));
|
|
|
- ResObject<ShopResultVo> res = deliveryClient.createShop(shopVo);
|
|
|
- log.info("创建三方门店返回结果: {}", JsonMapper.nonEmptyMapper().toJson(res));
|
|
|
- delivery.setBindStatus(BindStatusEnum.UNBIND.getStatus());
|
|
|
- if (res.getCode() == 0) {//操作成功
|
|
|
- ShopResultVo shopResultVo = res.getData();
|
|
|
- String shopId = shopResultVo.getShopId();//返回的门店id,作保存以作后用
|
|
|
- delivery.setBindStatus(BindStatusEnum.BIND.getStatus());
|
|
|
- delivery.setThirdShopId(shopId);
|
|
|
- } else {
|
|
|
- delivery.setAuthMsg(res.getMsg());
|
|
|
- }
|
|
|
- boolean result2 = iShopDeliveryService.updateById(delivery);
|
|
|
- if (!result2) {
|
|
|
- throw new CustomWebException("保存门店对应第三方运力信息失败!");
|
|
|
- }
|
|
|
- }
|
|
|
- this.saveShopThird(shopReq, delivery.getDeliveryId(), shop.getId());
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private ShopVo editShopVo(Shop shop, Integer dadaCategory, String thirdShopId) {
|
|
|
- ShopVo shopVo = new ShopVo();
|
|
|
- shopVo.setLbClient(DeliveryTypeEnums.DADA.getName());
|
|
|
- /**
|
|
|
- * 门店编码
|
|
|
- * 达达:origin_shop_id,门店编码, 必传
|
|
|
- *
|
|
|
- */
|
|
|
- shopVo.setShopId(thirdShopId);
|
|
|
-
|
|
|
- /**
|
|
|
- * 门店名称
|
|
|
- * 达达:station_name,门店名称,需要修改时传入否则为空
|
|
|
- * */
|
|
|
- shopVo.setShopName(shop.getName());
|
|
|
- /**
|
|
|
- * 业务类型
|
|
|
- * 达达:business,业务类型,需要修改时传入否则为空
|
|
|
- * (食品小吃-1,饮料-2,鲜花-3,文印票务-8,便利店-9,水果生鲜-13,同城电商-19, 医药-20,蛋糕-21,酒品-24,小商品市场-25,服装-26,汽修零配-27,
|
|
|
- * 数码-28,小龙虾-29,火锅-51,其他-5)
|
|
|
- */
|
|
|
- shopVo.setBusiness(dadaCategory);
|
|
|
- /**
|
|
|
- * 城市名称
|
|
|
- * 达达:city_name 城市名称(如,上海),需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setCityName(shop.getCityName());
|
|
|
- /**
|
|
|
- * 区域名称
|
|
|
- * 达达:area_name 区域名称(如,浦东新区),需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setAreaName(shop.getDistrictName());
|
|
|
- /**
|
|
|
- * 门店地址
|
|
|
- * 达达:station_address 门店地址,需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setShopAddress(shop.getAddress());
|
|
|
- /**
|
|
|
- *门店经度
|
|
|
- * 达达:lng 门店经度 需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setShopLng(new BigDecimal(shop.getLng()));
|
|
|
- /**
|
|
|
- * 门店纬度
|
|
|
- * 达达:lat 门店纬度,需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setShopLat(new BigDecimal(shop.getLat()));
|
|
|
- /**
|
|
|
- * 联系人姓名
|
|
|
- * 达达:contact_name 联系人姓名,需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setContactName(shop.getContactName());
|
|
|
- /**
|
|
|
- * 联系人电话
|
|
|
- * 达达:phone 联系人电话,需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setContactPhone(shop.getMobile());
|
|
|
-
|
|
|
- /**
|
|
|
- * 门店状态
|
|
|
- * 达达
|
|
|
- * 达达:status,门店状态(1-门店激活,0-门店下线),需要修改时传入否则为空
|
|
|
- */
|
|
|
- shopVo.setShopStatus(1);
|
|
|
- return shopVo;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<ShopDiscountPackageStatisticsDto> getDiscountPackageList(Page page, DiscountPackageStatisticsQuery query) {
|
|
|
- return baseMapper.getDiscountPackageList(page, query);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Shop> getShopByMerchantIds(List<Long> merchantIds) {
|
|
|
- return baseMapper.getShopByMerchantIds(merchantIds);
|
|
|
+ public List<Shop> getShopByName(String name, Long id) {
|
|
|
+ return baseMapper.getShopByName(name, id);
|
|
|
}
|
|
|
|
|
|
}
|