Просмотр исходного кода

//类目-1

release_toaliyun_real
xhxu 3 лет назад
Родитель
Сommit
bec9b01e91
11 измененных файлов: 281 добавлений и 15 удалений
  1. +2
    -2
      mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java
  2. +21
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java
  3. +22
    -1
      mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategory.java
  4. +10
    -0
      mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java
  5. +25
    -0
      mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java
  6. +57
    -0
      mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsCategory.java
  7. +1
    -1
      mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplyFunctionStatus.java
  8. +4
    -1
      mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java
  9. +5
    -0
      mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java
  10. +90
    -1
      mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java
  11. +44
    -9
      mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml

+ 2
- 2
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


+ 21
- 0
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();
}

}

+ 22
- 1
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<TtGoodsCategory> child;

@TableField(exist = false)
private List<Integer> categoryIds;//ids

@TableField(exist = false)
private List<Integer> parentIds;

}

+ 10
- 0
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<GoodsCategory> categoryGet(Integer category_id,Integer account_id) throws WxErrorException;

/**
* - 查询商品模板,创建商品时的属性列表需与该接口保持一致,否则无法识别
* category_id int TRUE 行业类目;详细见;商品类目表 https://bytedance.feishu.cn/docx/doxcnn02OUCTiKjpmzFR6ItdTye


+ 25
- 0
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<GoodsCategory> 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<GoodsCategory> list = GSON.fromJson(asJsonObject.getAsJsonArray("category_list"),
new TypeReference<List<GoodsCategory>>() {}.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());


+ 57
- 0
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;

}

+ 1
- 1
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, "开通完成"),
;


+ 4
- 1
mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryMapper.java Просмотреть файл

@@ -8,6 +8,9 @@ import java.util.List;

public interface TtGoodsCategoryMapper extends CommonMapper<TtGoodsCategory, String> {

List<TtGoodsCategory> findListAll();
List<TtGoodsCategory> findList(TtGoodsCategory record);

List<Integer> findIdAll(TtGoodsCategory record);

int updDelByIds(TtGoodsCategory record);
}

+ 5
- 0
mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java Просмотреть файл

@@ -33,4 +33,9 @@ public interface TtGoodsCategoryService {
* 处理系统属性和默认属性
*/
void handDefaultAttr(WxCoupon coupon,List<GoodsTemplateGet.ProductAttrs> productAttrs,List<GoodsTemplateGet.ProductAttrs> skuAttrs);

/**
* 同步抖音类目
*/
void syncGet();
}

+ 90
- 1
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<TtGoodsCategory> findTreeList() {
List<TtGoodsCategory> listAll = ttGoodsCategoryMapper.findListAll();
TtGoodsCategory record = new TtGoodsCategory();
record.setEnable(EnumYesOrNo.YES.getCode());
record.setIsDel(EnumYesOrNo.NO.getCode());
record.setSortColumns(BaseEntity.SortField.Id_ASC);
List<TtGoodsCategory> listAll = ttGoodsCategoryMapper.findList(record);
List<TtGoodsCategory> topList = new ArrayList<TtGoodsCategory>();
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<GoodsCategory> goodsCategories = ttWebService.getGoodsService().categoryGet(category_id, null);
if(goodsCategories != null){
TtGoodsCategory record = new TtGoodsCategory();
record.setParentId(category_id);
List<Integer> 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<Integer> 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<Integer> idAll = ttGoodsCategoryMapper.findIdAll(gcq);
updateDelByIds(idAll,now);
}

}

+ 44
- 9
mallinkService/src/main/resources/mapper/TtGoodsCategoryMapper.xml Просмотреть файл

@@ -3,32 +3,59 @@
<mapper namespace="com.iformall.mapper.TtGoodsCategoryMapper">
<resultMap id="BaseResultMap" type="com.iformall.domain.po.TtGoodsCategory">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="level" jdbcType="INTEGER" property="level" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="parent_id" jdbcType="INTEGER" property="parentId" />
<result column="enable" jdbcType="INTEGER" property="enable" />
<result column="is_leaf" jdbcType="INTEGER" property="is_leaf" />
<result column="service_fee" jdbcType="INTEGER" property="service_fee" />
</resultMap>
<sql id="allColumns">
`id`,`name`,`parent_id`
`id`,`level`,`name`,`parent_id`,`enable`,`is_leaf`,`service_fee`
</sql>

<sql id="dynamicWhereConditions">
where 1 = 1
where 1=1
<if test=" null != id ">
and `id` = #{id}
and `id` = #{id}
</if>

<if test=" null != isDel ">
and `is_del` = #{isDel}
</if>

<if test=" null != level ">
and `level` = #{level}
</if>
<if test=" null != name ">
and `name` like concat('%', #{name},'%')
and `name` like concat('%', #{name},'%')
</if>

<if test=" null != parentId ">
and `parent_id` = #{parentId}
</if>

<if test=" null != ids ">
<if test=" null != enable ">
and `enable` = #{enable}
</if>

<if test=" null != isLeaf ">
and `is_leaf` = #{isLeaf}
</if>

<if test=" null != parentIds ">
and parent_id in
<foreach collection="parentIds" index="index" item="idItem" open="(" separator="," close=")">
#{idItem}
</foreach>
</if>

<if test=" null != categoryIds ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
<foreach collection="categoryIds" index="index" item="idItem" open="(" separator="," close=")">
#{idItem}
</foreach>
</if>
@@ -40,9 +67,17 @@
<include refid="dynamicWhereConditions" />
</select>

<select id="findListAll" resultMap="BaseResultMap">
select <include refid="allColumns" /> from tt_goods_category
order by id
<select id="findIdAll" parameterType="com.iformall.domain.po.TtGoodsCategory" resultType="Integer">
select id from tt_goods_category
<include refid="dynamicWhereConditions" />
</select>

<update id="updDelByIds" parameterType="com.iformall.domain.po.TtGoodsCategory">
update tt_goods_category set is_del = #{isDel}, update_date = #{updateDate}
where id in
<foreach collection="categoryIds" index="index" item="idItem" open="(" separator="," close=")">
#{idItem}
</foreach>
</update>

</mapper>

Загрузка…
Отмена
Сохранить