diff --git a/mallinkService/src/main/java/com/iformall/domain/po/TtMerchantPoi.java b/mallinkService/src/main/java/com/iformall/domain/po/TtMerchantPoi.java index 263109225..eb6445515 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/TtMerchantPoi.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/TtMerchantPoi.java @@ -19,17 +19,17 @@ public class TtMerchantPoi extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value=" merchant_id",name="supplierExtId") private String supplierExtId; - @io.swagger.annotations.ApiModelProperty(value="poi名称 商户名",name="poiName") - private String poiName; + @io.swagger.annotations.ApiModelProperty(value="商户名",name="merchantName") + private String merchantName; - @io.swagger.annotations.ApiModelProperty(value="省",name="province") - private String province; + @io.swagger.annotations.ApiModelProperty(value="商户省",name="merchantProvince") + private String merchantProvince; - @io.swagger.annotations.ApiModelProperty(value="市",name="city") - private String city; + @io.swagger.annotations.ApiModelProperty(value="商户市",name="merchantCity") + private String merchantCity; - @io.swagger.annotations.ApiModelProperty(value="地址",name="address") - private String address; + @io.swagger.annotations.ApiModelProperty(value="商户地址",name="merchantAddr") + private String merchantAddr; @io.swagger.annotations.ApiModelProperty(value="经度",name="longitude") private Float longitude; @@ -46,10 +46,22 @@ public class TtMerchantPoi extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="高德POI ID/抖音POIID",name="poiId") private String poiId; + @io.swagger.annotations.ApiModelProperty(value="poi名称 ",name="poiName") + private String poiName; + + @io.swagger.annotations.ApiModelProperty(value="省",name="province") + private String province; + + @io.swagger.annotations.ApiModelProperty(value="市",name="city") + private String city; + + @io.swagger.annotations.ApiModelProperty(value="地址",name="address") + private String address; + @io.swagger.annotations.ApiModelProperty(value="抖音平台任务ID",name="taskId") private String taskId; - @io.swagger.annotations.ApiModelProperty(value="匹配状态,0-等待匹配,1-正在匹配,2-匹配成功,3-匹配失败",name="matchStatus") + @io.swagger.annotations.ApiModelProperty(value="EnumSupplierMathStatus 匹配状态,0-等待匹配,1-正在匹配,2-匹配成功,3-匹配失败",name="matchStatus") private Integer matchStatus; @io.swagger.annotations.ApiModelProperty(value="匹配状态描述",name="mismatchStatusDesc") @@ -60,4 +72,13 @@ public class TtMerchantPoi extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") private Date updateDate; + @io.swagger.annotations.ApiModelProperty(value="抖音平台商户ID",name="supplierId") + private String supplierId; + + @io.swagger.annotations.ApiModelProperty(value="EnumSupplierSyncStatus 最近一次同步状态, 0 - 未处理; 1 - 通过; 2 - 未通过",name="lastSyncStatus") + private Integer lastSyncStatus; + + @io.swagger.annotations.ApiModelProperty(value="同步失败原因,抖音风控政策问题,该字段无法提供太多信息,目前审核不通过联系抖音运营做进一步处理",name="failReason") + private String failReason; + } diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/bean/TtSupplierSync.java b/mallinkService/src/main/java/com/iformall/douyin/web/bean/TtSupplierSync.java index b92c5b8aa..c2bc80f5f 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/bean/TtSupplierSync.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/bean/TtSupplierSync.java @@ -82,7 +82,7 @@ public class TtSupplierSync implements Serializable { * 1101 JsonArray 酒店服务 * ************* */ - private JsonObject attributes;//店铺属性字段,编号规则:垂直行业 1xxx-酒店民宿 2xxx-餐饮 3xxx-景区 通用属性-9yxxx + private JsonObject attributes = new JsonObject();//店铺属性字段,编号规则:垂直行业 1xxx-酒店民宿 2xxx-餐饮 3xxx-景区 通用属性-9yxxx private String longitude;//经度 private List openTime;//营业时间, 从周一到周日,list长度为7,不营业则为空字符串 diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java index 32980e2d1..9aa17e122 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java @@ -7,20 +7,22 @@ import java.util.Map; * Created by Stormeye on 2018/08/09. */ public enum EnumBusiness { + //抖音poi同步店铺类型 + //店铺类型 1 - 酒店民宿 2 - 餐饮 3 - 景区 4 - 电商 5 - 教育 6 - 丽人 7 - 爱车 8 - 亲子 9 - 宠物 10 - 家装 11 - 娱乐场所 12 - 图文快印 // 0:无, 1:餐饮, 2:娱乐, 3:服饰, 4:亲子, 5:超市, 6:其他 - BUSINESS_NULL(0, "无"), - BUSINESS_ID1(1, "餐饮"), - BUSINESS_ID2(2, "娱乐"), - BUSINESS_ID3(3, "服饰"), - BUSINESS_ID4(4, "亲子"), - BUSINESS_ID5(5, "超市"), - BUSINESS_ID6(6, "其它"), - BUSINESS_ID7(7, "美妆"), - BUSINESS_ID8(8, "珠宝"), - BUSINESS_ID9(9, "服务"), - BUSINESS_ID10(10, "家居"), - BUSINESS_ID11(11, "数码家电"), + BUSINESS_NULL(0, "无", null), + BUSINESS_ID1(1, "餐饮", 2), + BUSINESS_ID2(2, "娱乐", 11), + BUSINESS_ID3(3, "服饰", 6), + BUSINESS_ID4(4, "亲子", 8), + BUSINESS_ID5(5, "超市", null), + BUSINESS_ID6(6, "其它", null), + BUSINESS_ID7(7, "美妆",6), + BUSINESS_ID8(8, "珠宝",null), + BUSINESS_ID9(9, "服务",11), + BUSINESS_ID10(10, "家居",10), + BUSINESS_ID11(11, "数码家电",null), ; private static Map map = new HashMap(); @@ -44,11 +46,13 @@ public enum EnumBusiness { private Integer code; private String message; + private Integer ttType; - EnumBusiness(Integer code, String message) { + EnumBusiness(Integer code, String message,Integer ttType) { this.code = code; this.message = message; + this.ttType = ttType; } public Integer getCode() { @@ -58,4 +62,8 @@ public enum EnumBusiness { public String getMessage() { return message; } + + public Integer getTtType() { + return ttType; + } } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java new file mode 100644 index 000000000..327447c23 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java @@ -0,0 +1,38 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumSupplierSyncStatus { + // 最近一次同步状态, 0 - 未处理; 1 - 通过; 2 - 未通过 +// match_update(-1, "等待重新同步"), + match_wait(0, " 未处理"), + match_success(1, "通过"), + match_fail(2, "未通过"), + ; + + public static EnumSupplierSyncStatus getEnum(Integer code) { + for (EnumSupplierSyncStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumSupplierSyncStatus(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java index 117116993..902d6f6fa 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -3,16 +3,19 @@ package com.iformall.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.iformall.common.ErrorCode; +import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; import com.iformall.douyin.web.api.TtWebService; import com.iformall.douyin.web.bean.TtSupplierMatch; import com.iformall.douyin.web.bean.TtSupplierMatchList; -import com.iformall.enums.EnumAppPlat; -import com.iformall.enums.EnumAppType; -import com.iformall.enums.EnumSupplierMathStatus; +import com.iformall.douyin.web.bean.TtSupplierSync; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.*; import com.iformall.utils.Constant; @@ -93,10 +96,10 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { poi.setId(merchant.getId()); poi.updateTenantInfo(mall); poi.setSupplierExtId(merchant.getId().toString()); - poi.setPoiName(merchant.getName()); - poi.setProvince(mall.getProvince()); - poi.setCity(mall.getCity()); - poi.setAddress(mall.getAddr()); + poi.setMerchantName(merchant.getName()); + poi.setMerchantProvince(mall.getProvince()); + poi.setMerchantCity(mall.getCity()); + poi.setMerchantAddr(mall.getAddr()); poi.setLongitude(mall.getLongitude() == null?null:mall.getLongitude().floatValue()); poi.setLatitude(mall.getLatitude() == null?null:mall.getLatitude().floatValue()); poi.setMatchStatus(EnumSupplierMathStatus.match_update.getCode()); @@ -189,20 +192,69 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { if(!EnumSupplierMathStatus.match_success.getCode().equals(merchantPoi.getMatchStatus())){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"该店铺未匹配成功,暂不能同步"); } + WxMerchant merchant = wxMerchantMapper.selectById(id); + String supplierId = supplierSync(tenantInfo, merchantPoi, merchant); + if(StringUtils.isBlank(supplierId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"同步失败"); + } + TtMerchantPoi updPoi = new TtMerchantPoi(); + updPoi.setId(id); + updPoi.setSupplierId(supplierId); + updPoi.setLastSyncStatus(EnumSupplierSyncStatus.match_wait.getCode()); + updPoi.setUpdateDate(new Date()); + ttMerchantPoiMapper.updateById(merchantPoi); + return new ResultData(); + } + private String supplierSync(TenantEntity tenantInfo,TtMerchantPoi merchantPoi,WxMerchant merchant){ + TtSupplierSync supplierSync = new TtSupplierSync(); + supplierSync.setContactPhone(merchant.getLinkPhone()); + List images = new ArrayList<>(); + images.add(merchant.getImgUrl()); + supplierSync.setImages(images); +// supplierSync.setMerchantUid();//如果开启分账并且已进件 +// supplierSync.setServiceProvider();//营业执照等 + supplierSync.setSupplierExtId(merchant.getId().toString()); + supplierSync.setStatus(EnumMerchantStatus.VALID.getCode().equals(merchant.getStatus())?1:2); + supplierSync.setAddress(merchantPoi.getAddress()); +// supplierSync.setAvgCost();//人均消费(单位分) +// supplierSync.setCustomerInfo();//商家资质 + supplierSync.setDescription(merchant.getIntroduction()); + supplierSync.setName(merchant.getName()); +// supplierSync.setRecommends();//推荐 + supplierSync.setServices(getServices()); +// supplierSync.setLongitude();//经度 +// supplierSync.setLatitude();//纬度 +// supplierSync.setOpenTime();// 营业时间, 从周一到周日,list长度为7, + supplierSync.setPoiId(merchantPoi.getPoiId()); - return null; + //如果抖音没有这个类型怎么办 + Integer ttType = EnumBusiness.getEnum(merchant.getBusinessId()).getTtType(); + if(ttType == null){ + logger.error("未找到对应的店铺类型"); + throw new MallinkException(ErrorCode.MSG_METHOD_REQUEST_ERROR.getCode(),"未找到对应的店铺类型"); + } + supplierSync.setType(ttType); + + String supplierId = null; + try { + supplierId = getTtWebService(tenantInfo).getProductService().supplierSync(supplierSync); + } catch (WxErrorException e) { + logger.error("发起店铺同步error"+e.getMessage()); + throw new MallinkException(ErrorCode.MSG_METHOD_REQUEST_ERROR.getCode(),e.getMessage()); + } + return supplierId; } - private String supplierMatch(TenantEntity tenantInfo, List merchantPoiList){ + private String supplierMatch(TenantEntity tenantInfo, List merchantPoiList) throws MallinkException{ TtSupplierMatchList matchList = new TtSupplierMatchList(); for (TtMerchantPoi poi:merchantPoiList) { TtSupplierMatch match = new TtSupplierMatch(); match.setSupplierExtId(poi.getSupplierExtId()); - match.setPoiName(poi.getPoiName()); - match.setProvince(poi.getProvince()); - match.setCity(poi.getCity()); - match.setAddress(poi.getAddress()); + match.setPoiName(poi.getMerchantName()); + match.setProvince(poi.getMerchantProvince()); + match.setCity(poi.getMerchantCity()); + match.setAddress(poi.getMerchantAddr()); match.setLongitude(poi.getLongitude()); match.setLatitude(poi.getLatitude()); match.setAmapId(poi.getAmapId()); @@ -214,6 +266,7 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { taskId = getTtWebService(tenantInfo).getShopMatchService().supplierMatch(matchList); } catch (WxErrorException e) { logger.error("发起店铺匹配POI同步任务error"+e.getMessage()); + throw new MallinkException(ErrorCode.MSG_METHOD_REQUEST_ERROR.getCode(),e.getMessage()); } return taskId; } @@ -261,4 +314,15 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { } } + //__________________________________店铺同步_______________________________________________ + //团购券类型 services 中的 service_type 必须包含 9101,门票类型 services 中的 service_type 必须包含 9001 + private JsonArray getServices(){ + JsonArray jsonArray = new JsonArray(); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("enable",1); + jsonObject.addProperty("service_type",9101); + jsonArray.add(jsonObject); + return jsonArray; + } + } diff --git a/mallinkService/src/main/resources/mapper/TtMerchantPoiMapper.xml b/mallinkService/src/main/resources/mapper/TtMerchantPoiMapper.xml index 2cfabf2ed..c96676b37 100644 --- a/mallinkService/src/main/resources/mapper/TtMerchantPoiMapper.xml +++ b/mallinkService/src/main/resources/mapper/TtMerchantPoiMapper.xml @@ -6,26 +6,43 @@ - - - - + + + + + + + + + + + + + + + + + - `id`,`tenant_id`,`parent_tenant_id`,`supplier_ext_id`,`poi_name`,`province`,`city`,`address`, - `longitude`,`latitude`,`amap_id`,`extra`,`poi_id`,`task_id`,`match_status`,`mismatch_status_desc`, - `create_date`,`update_date` + `id`,`tenant_id`,`parent_tenant_id`,`supplier_ext_id`, + `merchant_name`,`merchant_province`,`merchant_city`,`merchant_addr`,`longitude`,`latitude`, + `amap_id`,`extra`, + `poi_id`,`poi_name`,`province`,`city`,`address`, + `task_id`,`match_status`,`mismatch_status_desc`, + `create_date`,`update_date`, + `supplier_id`,`last_sync_status`,`fail_reason` @@ -50,8 +67,8 @@ and `poi_id` = #{poiId} - - and `poi_name` like concat('%', #{poiName},'%') + + and `merchant_name` like concat('%', #{merchantName},'%') @@ -62,6 +79,14 @@ and `match_status` = #{matchStatus} + + and `supplier_id` = #{supplierId} + + + + and `last_sync_status` = #{lastSynStatus} + + and `id` in