diff --git a/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java b/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java index a56a0e016..1ed71d35e 100644 --- a/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java +++ b/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java @@ -147,10 +147,10 @@ public class ShiroConfig { filterChainDefinitionMap.put("/wxDeviceScreenAd/**", "anon"); // filterChainDefinitionMap.put("/role/**", "corsFilter,token"); //商场初始化init - filterChainDefinitionMap.put("/wxProjectConfig/**", "anon"); +// filterChainDefinitionMap.put("/wxProjectConfig/**", "anon"); // filterChainDefinitionMap.put("/goodsCategory/**", "anon"); - + filterChainDefinitionMap.put("/goodsCategory/syncGet/**", "anon"); // filterChainDefinitionMap.put("/wxCoupon/goods/**", "anon"); // //test diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java index d2d73ce16..ff36d188f 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java @@ -3,11 +3,14 @@ package com.iformall.controller.basic; import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.TenantIgnore; +import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; import com.iformall.service.TtGoodsCategoryService; +import com.iformall.utils.DateUtils; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,4 +38,22 @@ public class TtGoodsCategoryController extends BaseController { return new ResultData(ttGoodsCategoryService.findTreeList()); } + @TenantIgnore + @ApiOperation("查询抖音类目") + @GetMapping("syncGet/{token}") + @ApiImplicitParams({}) + @SystemControllerLog(description = "列表") + public ResultData get(@PathVariable String token) { + logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::get"); + if(StringUtils.isBlank(token)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + String systemTime = DateUtils.getSystemTime("MMdd")+"syncgc"; + if(!systemTime.equals(token)){ + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + ttGoodsCategoryService.syncGet(); + return new ResultData(); + } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategory.java b/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategory.java index 6a790394f..16a5cdfc3 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategory.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategory.java @@ -14,7 +14,10 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) public class TtGoodsCategory extends BaseEntity { - protected Integer id; + protected Integer id;//category_id + + @io.swagger.annotations.ApiModelProperty(value="层级",name="level") + private Integer level; @io.swagger.annotations.ApiModelProperty(value="",name="name") private String name; @@ -22,12 +25,30 @@ public class TtGoodsCategory extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value="",name="parentId") private Integer parentId; + @io.swagger.annotations.ApiModelProperty(value="类目是否开放",name="enable") + private Integer enable; + + @io.swagger.annotations.ApiModelProperty(value="是否是叶子结点",name="isLeaf") + private Integer isLeaf; + @io.swagger.annotations.ApiModelProperty(value="",name="serviceFee") private Integer serviceFee; + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") + private Date createDate; + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") + private Date updateDate; + + @io.swagger.annotations.ApiModelProperty(value="",name="isDel") + private Integer isDel; @TableField(exist = false) protected List child; + @TableField(exist = false) + private List categoryIds;//ids + + @TableField(exist = false) + private List parentIds; } diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java index 794fe1e1f..ed5cafcfd 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java @@ -13,6 +13,10 @@ import java.util.List; */ public interface TtWebGoodsService { + /** + *0 查询商品品类 + */ + String CATEGORY_GET = "/life/goods/category/get/"; /** *1 查询商品模板 */ @@ -54,6 +58,12 @@ public interface TtWebGoodsService { */ String STOCK_SYNC = "/life/goods/stock/sync/"; + /** + * category_id int FALSE 行业类目ID,返回当前id下的直系子类目信息;传0或者不传,均返回所有一级行业类目 + * account_id int FALSE 服务商的入驻商户ID/代运营的商户ID,不传时默认为服务商身份 + */ + List categoryGet(Integer category_id,Integer account_id) throws WxErrorException; + /** * - 查询商品模板,创建商品时的属性列表需与该接口保持一致,否则无法识别 * category_id int TRUE 行业类目;详细见;商品类目表 https://bytedance.feishu.cn/docx/doxcnn02OUCTiKjpmzFR6ItdTye diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java index 68ddf1ffd..d3bb14ae4 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java @@ -1,8 +1,11 @@ package com.iformall.douyin.web.api.impl; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import com.iformall.douyin.web.api.*; import com.iformall.douyin.web.bean.*; import lombok.AllArgsConstructor; @@ -25,6 +28,28 @@ public class TtWebGoodsServiceImpl implements TtWebGoodsService { private TtWebService service; + @Override + public List categoryGet(Integer category_id, Integer account_id) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.CATEGORY_GET; + String param = "category_id=" + category_id; + if(account_id != null){ + param += "&account_id=" + account_id; + } + String result = this.service.execute(getExecutor, apiUrl, param); + JsonObject asJsonObject = GSON.toJsonTree(result).getAsJsonObject(); + JsonObject data = asJsonObject.getAsJsonObject("data"); + int error_code = data.get("error_code").getAsInt(); + if(error_code == 0){ + List list = GSON.fromJson(asJsonObject.getAsJsonArray("category_list"), + new TypeReference>() {}.getType()); + return list; + }else{ + String description = data.get("description").getAsString(); + throw new WxErrorException(WxError.builder().errorCode(error_code).errorMsg(description).build()); + } + } + @Override public GoodsTemplateGet templateGet(Integer category_id, Integer product_type) throws WxErrorException { TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsCategory.java b/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsCategory.java new file mode 100644 index 000000000..0a46317cd --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsCategory.java @@ -0,0 +1,57 @@ +package com.iformall.douyin.web.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 商品类目信息 + * + * @author thinsstar + */ +@Data +@NoArgsConstructor +public class GoodsCategory implements Serializable { + + private static final long serialVersionUID = -1L; + + /** + * 类目ID + */ + @SerializedName(value = "category_id") + private Integer categoryId; + + /** + * 类目名称 + */ + @SerializedName(value = "name") + private String name; + + /** + * 父类目ID + */ + @SerializedName(value = "parent_id") + private Integer parentId; + + /** + * 类目层级 + */ + @SerializedName(value = "level") + private Integer level; + + /** + * 是否叶子节点 + */ + @SerializedName(value = "is_leaf") + private Boolean isLeaf; + + /** + * 类目是否开放 + */ + @SerializedName(value = "enable") + private Boolean enable; + +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplyFunctionStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplyFunctionStatus.java index aef5c859b..787763057 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplyFunctionStatus.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplyFunctionStatus.java @@ -5,7 +5,7 @@ package com.iformall.enums; */ public enum EnumSharingReceiverApplyFunctionStatus { - wait(0, "待开通"), + wait(0, "未开通"), ing(1, "开通中"), FINISH(2, "开通完成"), ; diff --git a/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java b/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java index 4f8088b5e..f41f3925d 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java @@ -8,6 +8,9 @@ import java.util.List; public interface TtGoodsCategoryMapper extends CommonMapper { - List findListAll(); + List findList(TtGoodsCategory record); + List findIdAll(TtGoodsCategory record); + + int updDelByIds(TtGoodsCategory record); } diff --git a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java index 4366fa472..2ad17d8cc 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java @@ -33,4 +33,9 @@ public interface TtGoodsCategoryService { * 处理系统属性和默认属性 */ void handDefaultAttr(WxCoupon coupon,List productAttrs,List skuAttrs); + + /** + * 同步抖音类目 + */ + void syncGet(); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java index aed973bad..d849ba392 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java @@ -4,18 +4,27 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iformall.domain.po.TtGoodsCategory; import com.iformall.domain.po.WxCoupon; +import com.iformall.domain.po.base.BaseEntity; +import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.bean.GoodsCategory; import com.iformall.douyin.web.bean.GoodsTemplateGet; import com.iformall.enums.EnumCouponValidType; +import com.iformall.enums.EnumYesOrNo; import com.iformall.mapper.TtGoodsCategoryMapper; import com.iformall.service.TtGoodsCategoryService; +import com.iformall.service.TtMerchantPoiService; import com.iformall.utils.DateUtils; +import com.microsoft.schemas.vml.STExt; +import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Date; import java.util.List; @Service @@ -25,9 +34,16 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { @Autowired TtGoodsCategoryMapper ttGoodsCategoryMapper; + @Autowired + private TtMerchantPoiService ttMerchantPoiService; + @Override public List findTreeList() { - List listAll = ttGoodsCategoryMapper.findListAll(); + TtGoodsCategory record = new TtGoodsCategory(); + record.setEnable(EnumYesOrNo.YES.getCode()); + record.setIsDel(EnumYesOrNo.NO.getCode()); + record.setSortColumns(BaseEntity.SortField.Id_ASC); + List listAll = ttGoodsCategoryMapper.findList(record); List topList = new ArrayList(); for (TtGoodsCategory category:listAll) { if(category.getParentId().intValue() == 0){ @@ -451,4 +467,77 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { } } + @Async + @Override + public void syncGet() { + TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); + handSyncCategory(ttWebService,0,new Date()); + } + + /** + * 循环同步类目 + * @param ttWebService + * @param category_id + * @param now + */ + private void handSyncCategory(TtWebService ttWebService,Integer category_id,Date now){ + try { + List goodsCategories = ttWebService.getGoodsService().categoryGet(category_id, null); + if(goodsCategories != null){ + TtGoodsCategory record = new TtGoodsCategory(); + record.setParentId(category_id); + List listAll = ttGoodsCategoryMapper.findIdAll(record); + for (GoodsCategory gc:goodsCategories) { + TtGoodsCategory updgc = new TtGoodsCategory(); + updgc.setId(gc.getCategoryId()); + updgc.setLevel(gc.getLevel()); + updgc.setParentId(gc.getParentId()); + updgc.setEnable(gc.getEnable()?EnumYesOrNo.YES.getCode():EnumYesOrNo.NO.getCode()); + updgc.setIsLeaf(gc.getEnable()?EnumYesOrNo.YES.getCode():EnumYesOrNo.NO.getCode()); + updgc.setIsDel(EnumYesOrNo.NO.getCode()); + updgc.setUpdateDate(now); + if(listAll.contains(gc.getCategoryId())){ + ttGoodsCategoryMapper.updateById(updgc); + listAll.remove(gc.getCategoryId()); + }else{ + updgc.setCreateDate(now); + ttGoodsCategoryMapper.insert(updgc); + } + if(!gc.getIsLeaf()){ + handSyncCategory(ttWebService,gc.getCategoryId(),now); + } + } + updateDelByIds(listAll,now); + } + } catch (WxErrorException e) { + e.printStackTrace(); + logger.error("同步商品类目失败"+e.getMessage()); + } + catch (Exception e) { + e.printStackTrace(); + logger.error("同步商品类目失败"+e.getMessage()); + } + + } + + /** + * 循环删除类目 + * @param ids + * @param now + */ + private void updateDelByIds(List ids,Date now){ + if(ids == null || ids.size() <= 0){ + return; + } + TtGoodsCategory delgc = new TtGoodsCategory(); + delgc.setCategoryIds(ids); + delgc.setIsDel(EnumYesOrNo.YES.getCode()); + delgc.setUpdateDate(now); + int i = ttGoodsCategoryMapper.updDelByIds(delgc); + TtGoodsCategory gcq = new TtGoodsCategory(); + gcq.setParentIds(ids); + List idAll = ttGoodsCategoryMapper.findIdAll(gcq); + updateDelByIds(idAll,now); + } + } diff --git a/mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml b/mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml index 5e094496c..248a134bf 100644 --- a/mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml +++ b/mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml @@ -3,32 +3,59 @@ + + + + - `id`,`name`,`parent_id` + `id`,`level`,`name`,`parent_id`,`enable`,`is_leaf`,`service_fee` - where 1 = 1 + where 1=1 - and `id` = #{id} + and `id` = #{id} + + + + and `is_del` = #{isDel} + + + + and `level` = #{level} - and `name` like concat('%', #{name},'%') + and `name` like concat('%', #{name},'%') and `parent_id` = #{parentId} - + + and `enable` = #{enable} + + + + and `is_leaf` = #{isLeaf} + + + + and parent_id in + + #{idItem} + + + + and id in - + #{idItem} @@ -40,9 +67,17 @@ - + select id from tt_goods_category + + + update tt_goods_category set is_del = #{isDel}, update_date = #{updateDate} + where id in + + #{idItem} + + +