diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/base/DouyinBaseController.java b/mallinkAdmin/src/main/java/com/iformall/controller/base/DouyinBaseController.java new file mode 100644 index 000000000..d436c20ec --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/base/DouyinBaseController.java @@ -0,0 +1,40 @@ +package com.iformall.controller.base; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; +import com.iformall.common.ErrorCode; +import com.iformall.domain.po.WxMallVersion; +import com.iformall.enums.EnumDouyinApplicationVersion; +import com.iformall.exception.MallinkException; +import com.iformall.service.WxMallService; + +@RestController +public class DouyinBaseController extends BaseController{ + + @Autowired + private WxMallService wxMallService; + + private Integer getCurrentApplicationVersion() { + WxMallVersion mallVersion = wxMallService.getMallVersion(getTenantInfo()); + if (null == mallVersion) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"mallVersion未查询到配置"); + } + Integer v = mallVersion.getDouyinApplicationVersion() ; + if (v == null) { + return 0; + } + return v; + } + + public boolean isGoodLifeSaas() throws Exception{ + Integer _e = getCurrentApplicationVersion(); + if (_e.intValue() == EnumDouyinApplicationVersion.GOODLIFE_SAAS.getCode().intValue()) { + return true; + }else if (_e.intValue() == EnumDouyinApplicationVersion.WEB.getCode().intValue()) { + return false; + }else { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"mallVersion[douyinApplicationVersion]配置错误"); + } + } + +} 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 06d48e792..540fede52 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtGoodsCategoryController.java @@ -4,13 +4,22 @@ package com.iformall.controller.basic; import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.TenantIgnore; import com.iformall.common.ErrorCode; +import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; +import com.iformall.controller.base.DouyinBaseController; import com.iformall.domain.po.TtGoodsCategory; +import com.iformall.domain.po.TtGoodsCategoryNew; +import com.iformall.enums.EnumDouyinApplicationVersion; +import com.iformall.exception.MallinkException; import com.iformall.service.TtGoodsCategoryService; import com.iformall.utils.DateUtils; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +32,7 @@ import org.springframework.web.bind.annotation.*; */ @RestController @RequestMapping("goodsCategory") -public class TtGoodsCategoryController extends BaseController { +public class TtGoodsCategoryController extends DouyinBaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired @@ -36,7 +45,18 @@ public class TtGoodsCategoryController extends BaseController { @SystemControllerLog(description = "列表") public ResultData treeList() { logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::treeList"); - return new ResultData(ttGoodsCategoryService.findTreeList()); + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + return new ResultData(ttGoodsCategoryService.findTreeList()); + }else { + return new ResultData(ttGoodsCategoryService.findTreeListForNew()); + } + } catch (Exception e) { + logger.error("treeList error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } + } @TenantIgnore @@ -49,7 +69,17 @@ public class TtGoodsCategoryController extends BaseController { if(categoryId == null){ categoryId = 0; } - return new ResultData(ttGoodsCategoryService.categoryGet(categoryId)); + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + return new ResultData(ttGoodsCategoryService.categoryGet(categoryId,false)); + }else { + return new ResultData(ttGoodsCategoryService.categoryGet(categoryId,true)); + } + } catch (Exception e) { + logger.error("categoryGet error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } } @TenantIgnore @@ -59,7 +89,17 @@ public class TtGoodsCategoryController extends BaseController { @SystemControllerLog(description = "同步") public ResultData syncGetTt() { logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::syncGetTt"); - ttGoodsCategoryService.syncGet(); + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + ttGoodsCategoryService.syncGet(false); + }else { + ttGoodsCategoryService.syncGet(true); + } + } catch (Exception e) { + logger.error("syncGetTt error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } return new ResultData(); } @@ -70,7 +110,18 @@ public class TtGoodsCategoryController extends BaseController { @SystemControllerLog(description = "列表") public ResultData allTreeList() { logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::allTreeList"); - return new ResultData(ttGoodsCategoryService.findAllTreeList()); + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + return new ResultData(ttGoodsCategoryService.findAllTreeList()); + }else { + return new ResultData(ttGoodsCategoryService.findAllTreeListForNew()); + } + } catch (Exception e) { + logger.error("allTreeList error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } + } @TenantIgnore @@ -84,8 +135,27 @@ public class TtGoodsCategoryController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } record.setSoftwareFee(null); - - ttGoodsCategoryService.updateFee(record); + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + ttGoodsCategoryService.updateFee(record); + }else { + try { + TtGoodsCategoryNew gn = new TtGoodsCategoryNew(); + BeanUtils.copyProperties(gn, record); + ttGoodsCategoryService.updateFeeForNew(gn); + } catch (IllegalAccessException e) { + logger.error("setServiceFee error",e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getMessage()); + } catch (InvocationTargetException e) { + logger.error("setServiceFee error",e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getMessage()); + } + } + } catch (Exception e) { + logger.error("setServiceFee error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } return new ResultData(); } @@ -100,8 +170,28 @@ public class TtGoodsCategoryController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } record.setServiceFee(null); - - ttGoodsCategoryService.updateFee(record); + + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + ttGoodsCategoryService.updateFee(record); + }else { + try { + TtGoodsCategoryNew gn = new TtGoodsCategoryNew(); + BeanUtils.copyProperties(gn, record); + ttGoodsCategoryService.updateFeeForNew(gn); + } catch (IllegalAccessException e) { + logger.error("setServiceFee error",e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getMessage()); + } catch (InvocationTargetException e) { + logger.error("setServiceFee error",e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getMessage()); + } + } + } catch (Exception e) { + logger.error("setSoftwareFee error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } return new ResultData(); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java index b8c5b3899..5e528986f 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java @@ -7,6 +7,7 @@ import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; +import com.iformall.controller.base.DouyinBaseController; import com.iformall.controller.mem.AsyncTask; import com.iformall.domain.po.*; import com.iformall.domain.po.base.BaseEntity; @@ -44,7 +45,7 @@ import javax.servlet.http.HttpServletResponse; */ @RestController @RequestMapping("merchantPoi") -public class TtMerchantPoiController extends BaseController { +public class TtMerchantPoiController extends DouyinBaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired @@ -53,9 +54,6 @@ public class TtMerchantPoiController extends BaseController { @Autowired private TtMerchantPoiService ttMerchantPoiService; - @Autowired - private WxMallService wxMallService; - @Autowired StringRedisTemplate stringRedisTemplate; @@ -234,43 +232,37 @@ public class TtMerchantPoiController extends BaseController { // return ttMerchantPoiService.spuStockSync(getTenantInfo(),couponChannelId); // } - private Integer getCurrentApplicationVersion() { - WxMallVersion mallVersion = wxMallService.getMallVersion(getTenantInfo()); - if (null == mallVersion) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"mallVersion未查询到配置"); - } - Integer v = mallVersion.getDouyinApplicationVersion() ; - if (v == null) { - return 0; - } - return v; - } - @TenantIgnore @RequestMapping("/exportTemplate") public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { - Integer _e = getCurrentApplicationVersion(); - if (_e.intValue() == EnumDouyinApplicationVersion.WEB.getCode().intValue()) { - ttMerchantPoiService.exportTemplate(request, response,false); - }else if (_e.intValue() == EnumDouyinApplicationVersion.MINIAPP.getCode().intValue()) { - ttMerchantPoiService.exportTemplate(request, response,true); - }else { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"mallVersion[douyinApplicationVersion]配置错误"); - } + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + ttMerchantPoiService.exportTemplate(request, response,false); + }else { + ttMerchantPoiService.exportTemplate(request, response,true); + } + } catch (Exception e) { + logger.error("allTreeList error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } } @TenantIgnore @PostMapping(value = "/importPoi", consumes = "multipart/*") @SystemControllerLog(description = "poi-导入数据") public ResultData importPoi(@RequestParam("file") MultipartFile mFile) { - Integer _e = getCurrentApplicationVersion(); - if (_e.intValue() == EnumDouyinApplicationVersion.WEB.getCode().intValue()) { - return processImport(mFile,false); - }else if (_e.intValue() == EnumDouyinApplicationVersion.MINIAPP.getCode().intValue()) { - return processImport(mFile,true); - }else { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"mallVersion[douyinApplicationVersion]配置错误"); - } + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + return processImport(mFile,false); + }else { + return processImport(mFile,true); + } + } catch (Exception e) { + logger.error("allTreeList error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } } private ResultData processImport(MultipartFile mFile,boolean isNew) { diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/TtCouponGoodsController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/TtCouponGoodsController.java index 4b35ca3e5..0a65df784 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/TtCouponGoodsController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/TtCouponGoodsController.java @@ -3,8 +3,10 @@ package com.iformall.controller.market; import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.TenantIgnore; import com.iformall.common.ErrorCode; +import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; +import com.iformall.controller.base.DouyinBaseController; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.vo.TtCouponChannelVo; @@ -27,7 +29,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("ttgoods") @Api(description = "抖音商品库") -public class TtCouponGoodsController extends BaseController { +public class TtCouponGoodsController extends DouyinBaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired @@ -107,17 +109,23 @@ public class TtCouponGoodsController extends BaseController { if(coupon == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } - try { - GoodsTemplateGet goodsTemplateGet = ttMerchantPoiService.getTtWebService(getTenantInfo()).getGoodsService().templateGet(categoryId, productType); - ttGoodsCategoryService.adminIsShow(goodsTemplateGet); - ttGoodsCategoryService.handTemplate(goodsTemplateGet,coupon); - return new ResultData(goodsTemplateGet); - } catch (WxErrorException e) { - e.printStackTrace(); - return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); - } - + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + GoodsTemplateGet goodsTemplateGet = ttMerchantPoiService.getTtWebService(getTenantInfo()).getGoodsService().templateGet(categoryId, productType); + ttGoodsCategoryService.adminIsShow(goodsTemplateGet); + ttGoodsCategoryService.handTemplate(goodsTemplateGet,coupon); + return new ResultData(goodsTemplateGet); + }else { + GoodsTemplateGet goodsTemplateGet = ttMerchantPoiService.getTtGoodLifeSassService(getTenantInfo()).getGoodLifeSaasGoodsService().templateGet(categoryId, productType); + ttGoodsCategoryService.adminIsShow(goodsTemplateGet); + ttGoodsCategoryService.handTemplate(goodsTemplateGet,coupon); + return new ResultData(goodsTemplateGet); + } + } catch (Exception e) { + logger.error("allTreeList error.",e); + return new ResultData(Result.ERROR,e.getMessage()); + } } @TenantIgnore diff --git a/mallinkAdmin/src/main/resources/db/migration/V2023053000001_douyin.sql b/mallinkAdmin/src/main/resources/db/migration/V2023053000001_douyin.sql index 9fe2b87bf..d7587487a 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V2023053000001_douyin.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V2023053000001_douyin.sql @@ -5,3 +5,6 @@ CREATE TABLE `wx_mall_version` ( `douyin_application_version` int(3) NOT NULL COMMENT '抖音应用版本', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='商场'; + + +create table tt_goods_category_new like tt_goods_category; \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategoryNew.java b/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategoryNew.java new file mode 100644 index 000000000..7d15632f4 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/TtGoodsCategoryNew.java @@ -0,0 +1,57 @@ +package com.iformall.domain.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.iformall.domain.po.base.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; +import java.util.List; + +@TableName(value = "tt_goods_category_new") +@Data +@EqualsAndHashCode(callSuper = true) +public class TtGoodsCategoryNew extends BaseEntity { + + 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; + + @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="softwareFee") + private Integer softwareFee; + + @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/TtWebService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicService.java similarity index 84% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebService.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicService.java index 7791d9504..81adb4934 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicService.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.basic; import cn.binarywang.wx.miniapp.config.WxMaConfig; import com.iformall.douyin.web.config.TtWebConfig; @@ -10,7 +10,7 @@ import me.chanjar.weixin.common.util.http.RequestHttp; /** * */ -public interface TtWebService { +public interface TtBasicService { /** * 获取access_token. @@ -96,22 +96,4 @@ public interface TtWebService { */ RequestHttp getRequestHttp(); - /** - * 返回用户相关接口方法的实现类对象,以方便调用其各个接口. - * - * @return TtMaUserService - */ - TtWebShopMatchService getShopMatchService(); - - /** - * 返回用户相关接口方法的实现类对象,以方便调用其各个接口. - * - * @return TtMaUserService - */ - TtWebProductService getProductService(); - - TtWebGoodsService getGoodsService(); - - TtWebPoiPlanService getPoiPlanService(); - } diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicServiceImpl.java similarity index 89% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebServiceImpl.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicServiceImpl.java index 160590bb5..b1dbf2ac0 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/basic/TtBasicServiceImpl.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api.impl; +package com.iformall.douyin.web.api.basic; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -34,19 +34,13 @@ import static com.iformall.douyin.web.config.TtWebConstants.ErrorCode.*; * @author */ @Slf4j -public class TtWebServiceImpl implements TtWebService, RequestHttp { - private static final JsonParser JSON_PARSER = new JsonParser(); - private CloseableHttpClient httpClient; - private HttpHost httpProxy; - private TtWebConfig ttWebConfig; - - private TtWebShopMatchService shopMatchService = new TtWebShopMatchServiceImpl(this); - private TtWebProductService productService = new TtWebProductServiceImpl(this); - private TtWebGoodsService goodService = new TtWebGoodsServiceImpl(this); - private TtWebPoiPlanService poiPlanService = new TtWebPoiPlanServiceImpl(this); - - private int retrySleepMillis = 1000; - private int maxRetryTimes = 5; +public class TtBasicServiceImpl implements TtBasicService, RequestHttp { + protected static final JsonParser JSON_PARSER = new JsonParser(); + protected CloseableHttpClient httpClient; + protected HttpHost httpProxy; + protected TtWebConfig ttWebConfig; + protected int retrySleepMillis = 1000; + protected int maxRetryTimes = 5; protected static final Gson GSON = new Gson(); @@ -274,25 +268,4 @@ public class TtWebServiceImpl implements TtWebService, RequestHttp categoryGet(Integer category_id,Integer account_id) throws WxErrorException; + + /** + * - 查询商品模板,创建商品时的属性列表需与该接口保持一致,否则无法识别 + * category_id int TRUE 行业类目;详细见;商品类目表 https://bytedance.feishu.cn/docx/doxcnn02OUCTiKjpmzFR6ItdTye + * product_type int TRUE 商品类型 商品类型 1-团购 11-代金券 + */ + GoodsTemplateGet templateGet(Integer category_id,Integer product_type) throws WxErrorException; + + /** + * - 使用商品ID或外部商品ID查询商品草稿 + * - 处于新建审核中、修改审核中、或审核成功、失败的数据可以通过该接口查询到 + * - 一次最多查询10个草稿数据 + * product_ids string TRUE 商品ID列表(逗号分隔) + * out_ids string TRUE 外部商品ID列表(逗号分隔) + */ + List productDraftGet(String product_ids, String out_ids) throws WxErrorException ; + + /** + * - 查询本client_key(或绑定的账号)对应的商品草稿列表 + * - 处于审核中、或审核成功、失败的数据可以通过该接口查询到 + * cursor string FALSE 第一页不传,之后用前一次返回的next_cursor传入进行翻页 + * count int FALSE 分页数量,不传默认为5 + * status int FALSE 过滤草稿状态,10-审核中 12-审核失败 1-审核通过 + * + */ + ProductPage productDraftListGet(String cursor,Integer count,Integer status) throws WxErrorException ; + + /** + * - - 使用商品ID或外部商品ID查询商品线上数据 + * - 线上数据是指:通过审核后可以被用户看到的数据,包括在线、下线状态的数据 + * product_ids string TRUE 商品ID列表(逗号分隔) + * out_ids string TRUE 外部商品ID列表(逗号分隔) + */ + List productOnlineGet(String product_ids, String out_ids) throws WxErrorException ; + + /** + * - 查询本client_key(或绑定的账号)对应的商品线上列表 + * - 处于在线、下线、封禁状态的数据可以通过该接口查询到 + * cursor string FALSE 第一页不传,之后用前一次返回的next_cursor传入进行翻页 + * count int FALSE 分页数量,不传默认为5 + * status int FALSE 过滤在线状态 1-在线 2-下线 3-封禁 + * + */ + ProductPage productOnlineListGet(String cursor,Integer count,Integer status) throws WxErrorException ; + + /** + * - 创建或更新商品 + * - 对于同一服务商,相同的out_id会被认为是同一商品,重复创建会被覆盖 + * - 商品和SKU属性,需要通过模板获取 + * return - product_id 创建/更新商品成功后产生,与老接口spu_id一致 + */ + String productSave(Product product) throws WxErrorException ; + + /** + * - 免审修改团购活动 + * product_id string TRUE 商品id (商品id或商品外部id 选其一) + * out_id string TRUE 商品外部id (商品id或商品外部id 选其一) + * sold_end_time int64 FALSE 售卖结束时间 + * stock_qty int64 FALSE 总库存 + */ + boolean productFreeAudit(String productId,String outId,Long soldEndTime,Integer stockQty) throws WxErrorException ; + + /** + * 创建/更新多SKU商品的SKU列表(团购/代金券不用对接这个接口) + * + * @return + */ + boolean skuBatchSave(ProductSku sku) throws WxErrorException ; + + /** + * 上下架商品 + * product_id string TRUE 商品id(若有第三方id可不传) + * out_id string TRUE 商品第三方id + * op_type int64 TRUE 1-上线 2-下线 + * @return + */ + boolean productOperate(String product_id,String out_id,Integer op_type) throws WxErrorException ; + + /** + * 同步库存 + * product_id string TRUE 商品id(若有第三方id可不传) + * out_id string TRUE 商品第三方id + * stock StockStruct TRUE 库存信息 + * - limit_type int TRUE 库存上限类型,为2时stock_qty和avail_qty字段无意义 1-有限库存 2-无限库存 + * - stock_qty int TRUE 总库存,limit_type=2时无意义 + */ + boolean stockSync(String product_id,String out_id,Integer stock) throws WxErrorException ; + +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/TtGoodLifeSaasService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/TtGoodLifeSaasService.java new file mode 100644 index 000000000..73832ac38 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/TtGoodLifeSaasService.java @@ -0,0 +1,14 @@ +package com.iformall.douyin.web.api.goodlifesaas; + +import com.iformall.douyin.web.api.basic.TtBasicService; +import com.iformall.douyin.web.api.web.TtWebGoodsService; +import com.iformall.douyin.web.api.web.TtWebPoiPlanService; +import com.iformall.douyin.web.api.web.TtWebProductService; +import com.iformall.douyin.web.api.web.TtWebShopMatchService; +/** + * + */ +public interface TtGoodLifeSaasService extends TtBasicService{ + + TtGoodLifeSaasGoodsService getGoodLifeSaasGoodsService(); +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasGoodsServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasGoodsServiceImpl.java new file mode 100644 index 000000000..602d00ddb --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasGoodsServiceImpl.java @@ -0,0 +1,273 @@ +package com.iformall.douyin.web.api.goodlifesaas.impl; + +import com.alibaba.fastjson.TypeReference; +import com.google.gson.*; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasGoodsService; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; +import com.iformall.douyin.web.api.web.TtWebGoodsCategoryGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebGoodsGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebGoodsPostRequestExecutor; +import com.iformall.douyin.web.bean.*; +import lombok.AllArgsConstructor; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.lang3.StringUtils; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + */ +@AllArgsConstructor +public class TtGoodLifeSaasGoodsServiceImpl implements TtGoodLifeSaasGoodsService { + + private static final Gson GSON = new GsonBuilder().create(); + + private TtGoodLifeSaasService service; + + + @Override + public List categoryGet(Integer category_id, Integer account_id) throws WxErrorException { + TtWebGoodsCategoryGetRequestExecutor getExecutor = new TtWebGoodsCategoryGetRequestExecutor(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 jsonObject = GSON.fromJson(result, JsonObject.class); +// JsonElement jsonElement = GSON.toJsonTree(result); +// JsonObject asJsonObject = null; +// if(jsonElement.isJsonPrimitive()){ +// asJsonObject = jsonElement.getAsJsonPrimitive().getAsJsonObject(); +// }else{ +// asJsonObject = jsonElement.getAsJsonObject(); +// } + + JsonArray category_list = jsonObject.getAsJsonArray("category_list"); + List list = GSON.fromJson(category_list, + new TypeReference>() {}.getType()); + return list; + } + + @Override + public GoodsTemplateGet templateGet(Integer category_id, Integer product_type) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.TEMPLATE_GET; + String param = "category_id=" + category_id + + "&product_type=" + product_type; + String result = this.service.execute(getExecutor, apiUrl, param); + BaseGoodsResult baseResult = GSON.fromJson(result, + new TypeReference>(){}.getType()); + if(baseResult.isSuccess()){ + return baseResult.getData(); + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public List productDraftGet(String product_ids, String out_ids) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_DRAFT_GET; + String param = "" ; + if(StringUtils.isNotBlank(product_ids)){ + param = "product_ids=" + product_ids; + }else if(StringUtils.isNotBlank(out_ids)){ + param = "out_ids=" + out_ids; + } + String result = this.service.execute(getExecutor, apiUrl, param); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + Map map = (Map) baseResult.getData(); + if(map != null){ + Object product_draft_list = map.get("product_draft_list"); + List list = GSON.fromJson(GSON.toJson(product_draft_list), + new TypeReference>() {}.getType()); + return list; + } + return null; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public ProductPage productDraftListGet(String cursor, Integer count, Integer status) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_DRAFT_LIST; + String param = "" ; + if(count == null){ + param = "count=" + 5; + }else{ + param = "count=" + count; + } + if(StringUtils.isNotBlank(cursor)){ + param += "&cursor=" + cursor; + } + if(status != null){ + param += "&status=" + status; + } + String result = this.service.execute(getExecutor, apiUrl, param); + BaseGoodsResult baseResult = GSON.fromJson(result, + new TypeReference>() {}.getType()); + if(baseResult.isSuccess()){ + return baseResult.getData(); + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public List productOnlineGet(String product_ids, String out_ids) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_ONLINE_GET; + String param = "" ; + if(StringUtils.isNotBlank(product_ids)){ + param = "product_ids=" + product_ids; + }else if(StringUtils.isNotBlank(out_ids)){ + param = "out_ids=" + out_ids; + } + String result = this.service.execute(getExecutor, apiUrl, param); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + Map map = (Map) baseResult.getData(); + if(map != null){ + Object product_online_list = map.get("product_online_list"); + List list = GSON.fromJson(GSON.toJson(product_online_list), + new TypeReference>() {}.getType()); + return list; + } + return null; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public ProductPage productOnlineListGet(String cursor, Integer count, Integer status) throws WxErrorException { + TtWebGoodsGetRequestExecutor getExecutor = new TtWebGoodsGetRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_ONLINE_LIST; + String param = "" ; + if(count == null){ + param = "count=" + 5; + }else{ + param = "count=" + count; + } + if(StringUtils.isNotBlank(cursor)){ + param += "&cursor=" + cursor; + } + if(status != null){ + param += "&status=" + status; + } + String result = this.service.execute(getExecutor, apiUrl, param); + BaseGoodsResult baseResult = GSON.fromJson(result, + new TypeReference>() {}.getType()); + if(baseResult.isSuccess()){ + return baseResult.getData(); + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public String productSave(Product product) throws WxErrorException { + TtWebGoodsPostRequestExecutor postExecutor = new TtWebGoodsPostRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_SAVE; + String result = this.service.execute(postExecutor, apiUrl, GSON.toJson(product)); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + Map map = (Map) baseResult.getData(); + return map.get("product_id").toString(); + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public boolean productFreeAudit(String productId, String outId, Long soldEndTime, Integer stockQty) throws WxErrorException { + TtWebGoodsPostRequestExecutor postExecutor = new TtWebGoodsPostRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_FREE_AUDIT; + Map map = new HashMap<>(); + if(StringUtils.isNotBlank(productId)){ + map.put("product_id",productId); + }else if(StringUtils.isNotBlank(outId)){ + map.put("out_id",outId); + } + if(soldEndTime != null){ + map.put("sold_end_time",soldEndTime); + } + if(stockQty != null){ + map.put("stock_qty",stockQty); + } + String result = this.service.execute(postExecutor, apiUrl, GSON.toJson(map)); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + return true; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public boolean skuBatchSave(ProductSku sku) throws WxErrorException { + TtWebGoodsPostRequestExecutor postExecutor = new TtWebGoodsPostRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.SKU_BATCH_SAVE; + String result = this.service.execute(postExecutor, apiUrl, GSON.toJson(sku)); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + return true; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public boolean productOperate(String product_id, String out_id, Integer op_type) throws WxErrorException { + TtWebGoodsPostRequestExecutor postExecutor = new TtWebGoodsPostRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.PRODUCT_OPERATE; + Map map = new HashMap<>(); + if(StringUtils.isNotBlank(product_id)){ + map.put("product_id",product_id); + }else if(StringUtils.isNotBlank(out_id)){ + map.put("out_id",out_id); + } + map.put("op_type",op_type); + String result = this.service.execute(postExecutor, apiUrl, GSON.toJson(map)); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + return true; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + + @Override + public boolean stockSync(String product_id, String out_id, Integer stock) throws WxErrorException { + TtWebGoodsPostRequestExecutor postExecutor = new TtWebGoodsPostRequestExecutor(this.service.getRequestHttp()); + String apiUrl = this.service.getTtWebConfig().getApiBegin().getPrefix() + this.STOCK_SYNC; + Map map = new HashMap<>(); + if(StringUtils.isNotBlank(product_id)){ + map.put("product_id",product_id); + }else if(StringUtils.isNotBlank(out_id)){ + map.put("out_id",out_id); + } + Map stockStruct = new HashMap<>(); + if(stock == null || stock < 0){ + stockStruct.put("limit_type",2); + }else{ + stockStruct.put("limit_type",1); + stockStruct.put("stock_qty",stock); + } + map.put("stock",stockStruct); + String result = this.service.execute(postExecutor, apiUrl, GSON.toJson(map)); + BaseGoodsResult baseResult = GSON.fromJson(result, BaseGoodsResult.class); + if(baseResult.isSuccess()){ + return true; + }else{ + throw new WxErrorException(WxError.builder().errorCode(baseResult.getErrCode()).errorMsg(baseResult.getErrMsg()).build()); + } + } + +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasServiceImpl.java new file mode 100644 index 000000000..5c4348504 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/goodlifesaas/impl/TtGoodLifeSaasServiceImpl.java @@ -0,0 +1,22 @@ +package com.iformall.douyin.web.api.goodlifesaas.impl; + +import com.iformall.douyin.web.api.basic.TtBasicServiceImpl; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasGoodsService; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; +import lombok.extern.slf4j.Slf4j; + +/** + * @author + */ +@Slf4j +public class TtGoodLifeSaasServiceImpl extends TtBasicServiceImpl implements TtGoodLifeSaasService { + private TtGoodLifeSaasGoodsService shopMatchService = new TtGoodLifeSaasGoodsServiceImpl(this); + + @Override + public TtGoodLifeSaasGoodsService getGoodLifeSaasGoodsService() { + return this.shopMatchService; + } + + + +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGetRequestExecutor.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGetRequestExecutor.java similarity index 98% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGetRequestExecutor.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGetRequestExecutor.java index 5090de1dc..aa24c76e6 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGetRequestExecutor.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGetRequestExecutor.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsCategoryGetRequestExecutor.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsCategoryGetRequestExecutor.java similarity index 98% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsCategoryGetRequestExecutor.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsCategoryGetRequestExecutor.java index 7607a4051..1c1bbfc70 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsCategoryGetRequestExecutor.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsCategoryGetRequestExecutor.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsGetRequestExecutor.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsGetRequestExecutor.java similarity index 98% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsGetRequestExecutor.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsGetRequestExecutor.java index b529f8837..db24510f9 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsGetRequestExecutor.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsGetRequestExecutor.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsPostRequestExecutor.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsPostRequestExecutor.java similarity index 99% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsPostRequestExecutor.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsPostRequestExecutor.java index 59c08f36f..56a3e35bf 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsPostRequestExecutor.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsPostRequestExecutor.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsService.java similarity index 99% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsService.java index ed5cafcfd..6ace07a9b 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebGoodsService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebGoodsService.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.iformall.douyin.web.bean.*; @@ -63,7 +63,7 @@ public interface TtWebGoodsService { * 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/TtWebPoiPlanService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPoiPlanService.java similarity index 99% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebPoiPlanService.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPoiPlanService.java index 10306b853..164a20de5 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebPoiPlanService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPoiPlanService.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.iformall.douyin.web.bean.*; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebPostRequestExecutor.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPostRequestExecutor.java similarity index 99% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebPostRequestExecutor.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPostRequestExecutor.java index e978087b8..58680c279 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebPostRequestExecutor.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebPostRequestExecutor.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebProductService.java similarity index 98% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebProductService.java index 6907962fd..5780bf8ec 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebProductService.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.iformall.douyin.web.bean.*; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebService.java new file mode 100644 index 000000000..6020602b5 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebService.java @@ -0,0 +1,27 @@ +package com.iformall.douyin.web.api.web; + +import com.iformall.douyin.web.api.basic.TtBasicService; +/** + * + */ +public interface TtWebService extends TtBasicService{ + + /** + * 返回用户相关接口方法的实现类对象,以方便调用其各个接口. + * + * @return TtMaUserService + */ + TtWebShopMatchService getShopMatchService(); + + /** + * 返回用户相关接口方法的实现类对象,以方便调用其各个接口. + * + * @return TtMaUserService + */ + TtWebProductService getProductService(); + + TtWebGoodsService getGoodsService(); + + TtWebPoiPlanService getPoiPlanService(); + +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebShopMatchService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebShopMatchService.java similarity index 98% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebShopMatchService.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebShopMatchService.java index 3c943bd9c..1f532fd06 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebShopMatchService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/TtWebShopMatchService.java @@ -1,4 +1,4 @@ -package com.iformall.douyin.web.api; +package com.iformall.douyin.web.api.web; import com.iformall.douyin.web.bean.TtSupplierMatchList; import me.chanjar.weixin.common.error.WxErrorException; 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/web/impl/TtWebGoodsServiceImpl.java similarity index 96% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebGoodsServiceImpl.java index 00a966c23..609875963 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebGoodsServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebGoodsServiceImpl.java @@ -1,10 +1,15 @@ -package com.iformall.douyin.web.api.impl; +package com.iformall.douyin.web.api.web.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.google.gson.*; import com.iformall.douyin.web.api.*; +import com.iformall.douyin.web.api.web.TtWebGoodsCategoryGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebGoodsGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebGoodsPostRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebGoodsService; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.*; import lombok.AllArgsConstructor; import me.chanjar.weixin.common.error.WxError; @@ -49,7 +54,7 @@ public class TtWebGoodsServiceImpl implements TtWebGoodsService { new TypeReference>() {}.getType()); return list; } - + @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/api/impl/TtWebPoiPlanServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebPoiPlanServiceImpl.java similarity index 97% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebPoiPlanServiceImpl.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebPoiPlanServiceImpl.java index a7e43298e..5894f01ce 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebPoiPlanServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebPoiPlanServiceImpl.java @@ -1,10 +1,13 @@ -package com.iformall.douyin.web.api.impl; +package com.iformall.douyin.web.api.web.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.iformall.douyin.web.api.*; +import com.iformall.douyin.web.api.web.TtWebPoiPlanService; +import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.*; import lombok.AllArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebProductServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebProductServiceImpl.java similarity index 93% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebProductServiceImpl.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebProductServiceImpl.java index 925f79660..be8d3f6d4 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebProductServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebProductServiceImpl.java @@ -1,11 +1,11 @@ -package com.iformall.douyin.web.api.impl; +package com.iformall.douyin.web.api.web.impl; import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonObject; -import com.iformall.douyin.web.api.TtWebGetRequestExecutor; -import com.iformall.douyin.web.api.TtWebPostRequestExecutor; -import com.iformall.douyin.web.api.TtWebProductService; -import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.api.web.TtWebGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebProductService; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.*; import lombok.AllArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebServiceImpl.java new file mode 100644 index 000000000..0dd77448f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebServiceImpl.java @@ -0,0 +1,71 @@ +package com.iformall.douyin.web.api.web.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.google.gson.JsonParser; +import com.iformall.douyin.web.api.*; +import com.iformall.douyin.web.api.basic.TtBasicServiceImpl; +import com.iformall.douyin.web.api.web.TtWebGoodsService; +import com.iformall.douyin.web.api.web.TtWebPoiPlanService; +import com.iformall.douyin.web.api.web.TtWebProductService; +import com.iformall.douyin.web.api.web.TtWebService; +import com.iformall.douyin.web.api.web.TtWebShopMatchService; +import com.iformall.douyin.web.config.TtWebConfig; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.DataUtils; +import me.chanjar.weixin.common.util.http.*; +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; +import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.locks.Lock; + +import static com.iformall.douyin.web.config.TtWebConstants.ErrorCode.*; + + +/** + * @author + */ +@Slf4j +public class TtWebServiceImpl extends TtBasicServiceImpl implements TtWebService { + private TtWebShopMatchService shopMatchService = new TtWebShopMatchServiceImpl(this); + private TtWebProductService productService = new TtWebProductServiceImpl(this); + private TtWebGoodsService goodService = new TtWebGoodsServiceImpl(this); + private TtWebPoiPlanService poiPlanService = new TtWebPoiPlanServiceImpl(this); + + @Override + public TtWebShopMatchService getShopMatchService() { + return this.shopMatchService; + } + + @Override + public TtWebProductService getProductService() { + return this.productService; + } + + @Override + public TtWebGoodsService getGoodsService() { + return this.goodService; + } + + @Override + public TtWebPoiPlanService getPoiPlanService() { + return this.poiPlanService; + } + + + +} diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebShopMatchServiceImpl.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebShopMatchServiceImpl.java similarity index 87% rename from mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebShopMatchServiceImpl.java rename to mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebShopMatchServiceImpl.java index 3ba8ccfed..fb139ba44 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/impl/TtWebShopMatchServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/web/impl/TtWebShopMatchServiceImpl.java @@ -1,10 +1,10 @@ -package com.iformall.douyin.web.api.impl; +package com.iformall.douyin.web.api.web.impl; import com.google.gson.JsonObject; -import com.iformall.douyin.web.api.TtWebGetRequestExecutor; -import com.iformall.douyin.web.api.TtWebPostRequestExecutor; -import com.iformall.douyin.web.api.TtWebService; -import com.iformall.douyin.web.api.TtWebShopMatchService; +import com.iformall.douyin.web.api.web.TtWebGetRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; +import com.iformall.douyin.web.api.web.TtWebService; +import com.iformall.douyin.web.api.web.TtWebShopMatchService; import com.iformall.douyin.web.bean.TtSupplierMatch; import com.iformall.douyin.web.bean.TtSupplierMatchList; import lombok.AllArgsConstructor; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumDouyinApplicationVersion.java b/mallinkService/src/main/java/com/iformall/enums/EnumDouyinApplicationVersion.java index f7a3011e2..43949b7f5 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumDouyinApplicationVersion.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumDouyinApplicationVersion.java @@ -7,7 +7,7 @@ package com.iformall.enums; public enum EnumDouyinApplicationVersion { WEB(1, "网站应用"), - MINIAPP(2, "小程序应用"); + GOODLIFE_SAAS(2, "本地生活SAAS应用"); public static EnumDouyinApplicationVersion getEnum(Integer code) { for (EnumDouyinApplicationVersion value : values()) { diff --git a/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryNewMapper.java b/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryNewMapper.java new file mode 100644 index 000000000..68a029524 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/TtGoodsCategoryNewMapper.java @@ -0,0 +1,20 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.TtGoodsCategoryNew; + +import java.util.List; + +public interface TtGoodsCategoryNewMapper extends CommonMapper { + + List findList(TtGoodsCategoryNew record); + + List findMinList(TtGoodsCategoryNew record); + + List findIdAll(TtGoodsCategoryNew record); + + int updDelByIds(TtGoodsCategoryNew record); + + int updateFeeByIds(TtGoodsCategoryNew updgc); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java index 77607eb8d..9309c2649 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java @@ -3,6 +3,7 @@ package com.iformall.service; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.TtGoodsCategory; +import com.iformall.domain.po.TtGoodsCategoryNew; import com.iformall.domain.po.WxCoupon; import com.iformall.douyin.web.bean.GoodsCategory; import com.iformall.douyin.web.bean.GoodsTemplateGet; @@ -18,16 +19,16 @@ public interface TtGoodsCategoryService { * @return */ List findTreeList(); + List findTreeListForNew(); List findAllTreeList(); - + List findAllTreeListForNew(); /** * A端是否显示处理 */ void adminIsShow(GoodsTemplateGet temp); - /** * 处理回显 * @param temp @@ -42,13 +43,14 @@ public interface TtGoodsCategoryService { /** * 同步抖音类目 */ - void syncGet(); + void syncGet(boolean isNew); - List categoryGet(Integer categoryId); + List categoryGet(Integer categoryId,boolean isNew); void updateFee(TtGoodsCategory record); + void updateFeeForNew(TtGoodsCategoryNew record); - int getTtServiceFee(Integer categoryId); + int getTtServiceFee(Integer categoryId,boolean isNew); } diff --git a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java index 418036e12..8306a4f7a 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java @@ -7,7 +7,8 @@ import com.iformall.domain.po.TtMerchantPoi; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.MerchantPoiT; import com.iformall.domain.vo.MerchantPoiTNew; -import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; +import com.iformall.douyin.web.api.web.TtWebService; import java.util.List; @@ -48,6 +49,8 @@ public interface TtMerchantPoiService { ResultData supplierQuery(TenantEntity tenantInfo,Long id); TtWebService getTtWebService(TenantEntity tenantInfo); + + TtGoodLifeSaasService getTtGoodLifeSassService(TenantEntity tenantInfo); // ResultData findPoi(TenantEntity tenantInfo, Long couponChannelId); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java index 5384ac1c9..a12d894a1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java @@ -12,8 +12,8 @@ import com.iformall.domain.po.*; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.*; -import com.iformall.douyin.web.api.TtWebPoiPlanService; -import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.api.web.TtWebPoiPlanService; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.*; import com.iformall.enums.*; import com.iformall.exception.MallinkException; 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 27a2b3782..c92222d2c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java @@ -6,9 +6,11 @@ import com.github.binarywang.wxpay.bean.bank.BankingResult; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.TtGoodsCategory; +import com.iformall.domain.po.TtGoodsCategoryNew; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.base.BaseEntity; -import com.iformall.douyin.web.api.TtWebService; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.GoodsCategory; import com.iformall.douyin.web.bean.GoodsTemplateGet; import com.iformall.enums.EnumCouponValidType; @@ -17,6 +19,7 @@ import com.iformall.enums.EnumMerchantStatus; import com.iformall.enums.EnumYesOrNo; import com.iformall.exception.MallinkException; import com.iformall.mapper.TtGoodsCategoryMapper; +import com.iformall.mapper.TtGoodsCategoryNewMapper; import com.iformall.service.TtGoodsCategoryService; import com.iformall.service.TtMerchantPoiService; import com.iformall.utils.DateUtils; @@ -44,6 +47,9 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { @Autowired TtGoodsCategoryMapper ttGoodsCategoryMapper; + + @Autowired + TtGoodsCategoryNewMapper ttGoodsCategoryNewMapper; @Autowired private TtMerchantPoiService ttMerchantPoiService; @@ -71,6 +77,26 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { } return topList; } + + @Override + public List findTreeListForNew() { + TtGoodsCategoryNew record = new TtGoodsCategoryNew(); + record.setEnable(EnumYesOrNo.YES.getCode()); + record.setIsDel(EnumYesOrNo.NO.getCode()); + record.setSortColumns(BaseEntity.SortField.Id_ASC); + List listAll = ttGoodsCategoryNewMapper.findMinList(record); + if(listAll == null || listAll.isEmpty()){ + return new ArrayList<>(); + } + List topList = listAll.stream().filter(gc -> gc.getParentId().intValue() == 0).collect(Collectors.toList()); + if(topList != null && !topList.isEmpty()){ + listAll.removeAll(topList); + for (TtGoodsCategoryNew category:topList) { + category.setChild(getChildForNew(listAll,category.getId())); + } + } + return topList; + } @Override public List findAllTreeList() { @@ -91,6 +117,26 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { } return topList; } + + @Override + public List findAllTreeListForNew() { + TtGoodsCategoryNew record = new TtGoodsCategoryNew(); +// record.setEnable(EnumYesOrNo.YES.getCode()); + record.setIsDel(EnumYesOrNo.NO.getCode()); + record.setSortColumns(BaseEntity.SortField.Id_ASC); + List listAll = ttGoodsCategoryNewMapper.findList(record); + if(listAll == null || listAll.isEmpty()){ + return new ArrayList<>(); + } + List topList = listAll.stream().filter(gc -> gc.getParentId().intValue() == 0).collect(Collectors.toList()); + if(topList != null && !topList.isEmpty()){ + listAll.removeAll(topList); + for (TtGoodsCategoryNew category:topList) { + category.setChild(getChildForNew(listAll,category.getId())); + } + } + return topList; + } private List getChild(List listAll,Integer parentId){ @@ -112,6 +158,26 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { return childList; } + + private List getChildForNew(List listAll,Integer parentId){ + List childList = new ArrayList(); + if(listAll == null || listAll.isEmpty()){ + return childList; + } + for(TtGoodsCategoryNew category : listAll){ + if(parentId.equals(category.getParentId())){ + childList.add(category); + } + } + if(!childList.isEmpty()){ + listAll.removeAll(childList); + for (TtGoodsCategoryNew category:childList) { + category.setChild(getChildForNew(listAll,category.getId())); + } + } + + return childList; + } private List getProductAdminIsNotShowKey(){ List keyList = new ArrayList<>(); @@ -515,21 +581,36 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { // @Async @Transactional(rollbackFor = {Exception.class}) @Override - public void syncGet() { - TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); - handSyncCategory(ttWebService,0,new Date()); + public void syncGet(boolean isNew) { + if(!isNew) { + TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); + handSyncCategory(ttWebService,0,new Date()); + }else { + TenantEntity defaultEntity = new TenantEntity(); + defaultEntity.setTenantId("789"); + TtWebService ttWebService = ttMerchantPoiService.getTtMiniAppService(defaultEntity); + handSyncCategoryForNew(ttWebService,0,new Date()); + } } @Override - public List categoryGet(Integer categoryId) { + public List categoryGet(Integer categoryId,boolean isNew) { String key = "goods_category:"+categoryId; List cacheListObject = RedisCacheUtils.getCacheListObject(categoryRedisTemplate, key, GoodsCategory.class); if(cacheListObject != null && cacheListObject.size() > 0){ return cacheListObject; } try { - TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); - List goodsCategories = ttWebService.getGoodsService().categoryGet(categoryId, null); + List goodsCategories = null; + if (isNew) { + TenantEntity defaultEntity = new TenantEntity(); + defaultEntity.setTenantId("789"); + TtWebService ttWebService = ttMerchantPoiService.getTtMiniAppService(defaultEntity); + goodsCategories = ttWebService.getGoodLifeSaasGoodsService().categoryGet(categoryId, null); + }else { + TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); + goodsCategories = ttWebService.getGoodsService().categoryGet(categoryId, null); + } if(goodsCategories != null && goodsCategories.size() > 0){ RedisCacheUtils.cache(categoryRedisTemplate,key,goodsCategories,24*3600); } @@ -551,14 +632,34 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { updateFeeByIds(ids,record.getServiceFee(),record.getSoftwareFee(),new Date()); } } - + + @Transactional(rollbackFor = {Exception.class}) @Override - public int getTtServiceFee(Integer categoryId) { - TtGoodsCategory goodsCategory = ttGoodsCategoryMapper.selectById(categoryId); - if(goodsCategory != null && goodsCategory.getServiceFee() != null){ - return goodsCategory.getServiceFee(); + public void updateFeeForNew(TtGoodsCategoryNew record) { + List ids = new ArrayList<>(); + if(record.getId() != null){ + ids.add(record.getId()); } - return 0; + if(!ids.isEmpty()){ + updateFeeByIdsForNew(ids,record.getServiceFee(),record.getSoftwareFee(),new Date()); + } + } + + @Override + public int getTtServiceFee(Integer categoryId,boolean isNew) { + if (!isNew) { + TtGoodsCategory goodsCategory = ttGoodsCategoryMapper.selectById(categoryId); + if(goodsCategory != null && goodsCategory.getServiceFee() != null){ + return goodsCategory.getServiceFee(); + } + return 0; + }else { + TtGoodsCategoryNew goodsCategory = ttGoodsCategoryNewMapper.selectById(categoryId); + if(goodsCategory != null && goodsCategory.getServiceFee() != null){ + return goodsCategory.getServiceFee(); + } + return 0; + } } /** @@ -610,6 +711,50 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { } } + + private void handSyncCategoryForNew(TtWebService ttWebService,Integer category_id,Date now){ + try { + List goodsCategories = ttWebService.getGoodLifeSaasGoodsService().categoryGet(category_id, null); + if(goodsCategories != null){ + TtGoodsCategoryNew record = new TtGoodsCategoryNew(); + record.setParentId(category_id); + List listAll = ttGoodsCategoryNewMapper.findIdAll(record); + for (GoodsCategory gc:goodsCategories) { + + TtGoodsCategoryNew updgc = new TtGoodsCategoryNew(); + updgc.setId(gc.getCategoryId()); + updgc.setLevel(gc.getLevel()); + updgc.setName(gc.getName()); + 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())){ + ttGoodsCategoryNewMapper.updateById(updgc); + listAll.remove(gc.getCategoryId()); + }else{ + updgc.setCreateDate(now); + ttGoodsCategoryNewMapper.insert(updgc); + } + if(!gc.getIsLeaf()){ + handSyncCategoryForNew(ttWebService,gc.getCategoryId(),now); + } + } + updateDelByIdsForNew(listAll,now); + } + } catch (WxErrorException e) { + e.printStackTrace(); + logger.error("同步商品类目失败"+e.getMessage()); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); + } + catch (Exception e) { + e.printStackTrace(); + logger.error("同步商品类目失败"+e.getMessage()); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); + } + + } /** * 循环删除类目 @@ -632,6 +777,23 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { updateDelByIds(idAll,now); } } + + private void updateDelByIdsForNew(List ids,Date now){ + if(ids == null || ids.size() <= 0){ + return; + } + TtGoodsCategoryNew delgc = new TtGoodsCategoryNew(); + delgc.setCategoryIds(ids); + delgc.setIsDel(EnumYesOrNo.YES.getCode()); + delgc.setUpdateDate(now); + int i = ttGoodsCategoryNewMapper.updDelByIds(delgc); + if(i > 0){ + TtGoodsCategoryNew gcq = new TtGoodsCategoryNew(); + gcq.setParentIds(ids); + List idAll = ttGoodsCategoryNewMapper.findIdAll(gcq); + updateDelByIdsForNew(idAll,now); + } + } /** * 循环修改费率 @@ -653,5 +815,23 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { updateFeeByIds(idAll,serviceFee,softwareFee,now); } } + + private void updateFeeByIdsForNew(List ids,Integer serviceFee,Integer softwareFee,Date now){ + if(ids == null || ids.size() <= 0){ + return; + } + TtGoodsCategoryNew updgc = new TtGoodsCategoryNew(); + updgc.setCategoryIds(ids); + updgc.setServiceFee(serviceFee); + updgc.setSoftwareFee(softwareFee); + updgc.setUpdateDate(now); + int i = ttGoodsCategoryNewMapper.updateFeeByIds(updgc); + if(i > 0){ + TtGoodsCategoryNew gcq = new TtGoodsCategoryNew(); + gcq.setParentIds(ids); + List idAll = ttGoodsCategoryNewMapper.findIdAll(gcq); + updateFeeByIdsForNew(idAll,serviceFee,softwareFee,now); + } + } } 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 8245c7bb8..d3291f728 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -13,7 +13,9 @@ import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.MerchantPoiT; import com.iformall.domain.vo.MerchantPoiTNew; import com.iformall.domain.vo.WxCardPriceTemplate; -import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.api.basic.TtBasicService; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; +import com.iformall.douyin.web.api.web.TtWebService; import com.iformall.douyin.web.bean.*; import com.iformall.enums.*; import com.iformall.exception.MallinkException; @@ -515,6 +517,27 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { } return ttWebService; } + + @Override + public TtGoodLifeSaasService getTtGoodLifeSassService(TenantEntity tenantInfo){ + WxAppinfo appinfoQ = new WxAppinfo(); + appinfoQ.updateTenantInfo(tenantInfo); + appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); + appinfoQ.setType(EnumAppType.C.getCode()); + WxAppinfo appinfo = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ)); + TtGoodLifeSaasService ttWebService = maUtil.getTtGoodLifeSassService(appinfo); + if (StringUtils.isBlank(appinfo.getAccessToken())) { + // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 + updateWebAccessToken(appinfo, ttWebService); + } else { + // 检查token是否已过期, 1小时就重新获取 + Date curDate = new Date(); + if (curDate.getTime() > appinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { + updateWebAccessToken(appinfo, ttWebService); + } + } + return ttWebService; + } @Override public void exportTemplate(HttpServletRequest request, HttpServletResponse response, boolean isNew) { @@ -665,9 +688,9 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { // // } - private void updateWebAccessToken(WxAppinfo appinfo, TtWebService ttWebService) { + private void updateWebAccessToken(WxAppinfo appinfo, TtBasicService ttbasicService) { try { - String accessToken = ttWebService.getAccessToken(true); + String accessToken = ttbasicService.getAccessToken(true); WxAppinfo updateApp = new WxAppinfo(); updateApp.setAppId(appinfo.getAppId()); updateApp.setAccessToken(accessToken); diff --git a/mallinkService/src/main/java/com/iformall/utils/MaUtil.java b/mallinkService/src/main/java/com/iformall/utils/MaUtil.java index 599e1b1ec..2598f1b67 100644 --- a/mallinkService/src/main/java/com/iformall/utils/MaUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/MaUtil.java @@ -19,8 +19,10 @@ import java.util.concurrent.ConcurrentHashMap; import com.iformall.douyin.pay.TtPayService; import com.iformall.douyin.pay.impl.TtPayServiceImpl; import com.iformall.douyin.payv2.config.TtPayConfig; -import com.iformall.douyin.web.api.TtWebService; -import com.iformall.douyin.web.api.impl.TtWebServiceImpl; +import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; +import com.iformall.douyin.web.api.goodlifesaas.impl.TtGoodLifeSaasServiceImpl; +import com.iformall.douyin.web.api.web.TtWebService; +import com.iformall.douyin.web.api.web.impl.TtWebServiceImpl; import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; import com.iformall.douyin.web.enums.TtWebApiBeginEnum; import com.iformall.mapper.WxAppinfoMapper; @@ -56,6 +58,9 @@ public class MaUtil { private static Map webServiceMap = new ConcurrentHashMap(); private static Map webServiceKeyMap = new ConcurrentHashMap(); + + private static Map goodLifeSaasServiceMap = new ConcurrentHashMap(); + private static Map goodLifeSaasServiceKeyMap = new ConcurrentHashMap(); public WxMaService getWeappService(WxAppinfo appinfo) { WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); @@ -290,4 +295,45 @@ public class MaUtil { } return service; } + + public TtGoodLifeSaasService getTtGoodLifeSassService(WxAppinfo appinfo) { + TtWebDefaultConfigImpl config = new TtWebDefaultConfigImpl(); + config.setAppid(appinfo.getAppId()); + config.setSecret(appinfo.getSecret()); + config.setToken(appinfo.getToken()); + config.setAesKey(appinfo.getAesKey()); + config.setMsgDataFormat(appinfo.getMsgDataFormat()); + if (StringUtils.isNotBlank(appinfo.getAccessToken())) { + config.setAccessToken(appinfo.getAccessToken()); + config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000); + } + config.setApacheHttpClientBuilder(FmHttpClientBuilder.get()); + + //默认抖音 + config.setApiBegin(TtWebApiBeginEnum.DY); + + String key = appinfo.getAppId()+String.valueOf(config.getExpiresTime()); + TtGoodLifeSaasService service = goodLifeSaasServiceMap.get(key); + if ( null == service ) { + synchronized("getTtGoodLifeSaasServiceBlock"+appinfo.getAppId()) { + service = goodLifeSaasServiceMap.get(key); + if (null == service) { + //删除掉之前的 + String appServiceKey = goodLifeSaasServiceKeyMap.get(appinfo.getAppId()); + if (!StringUtils.isBlank(appServiceKey)) { + if (goodLifeSaasServiceMap.containsKey(appServiceKey)) { + goodLifeSaasServiceMap.remove(appServiceKey); + } + goodLifeSaasServiceKeyMap.remove(appinfo.getAppId()); + } + + service = new TtGoodLifeSaasServiceImpl(); + service.setTtWebConfig(config); + goodLifeSaasServiceMap.put(key, service); + goodLifeSaasServiceKeyMap.put(appinfo.getAppId(),key); + } + } + } + return service; + } } diff --git a/mallinkService/src/main/resources/mapper/TtGoodsCategoryNewMapper.xml b/mallinkService/src/main/resources/mapper/TtGoodsCategoryNewMapper.xml new file mode 100644 index 000000000..bbeabcba0 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/TtGoodsCategoryNewMapper.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + `id`,`level`,`name`,`parent_id`,`enable`,`is_leaf`,`service_fee`,`software_fee` + + + + where 1=1 + + + and `id` = #{id} + + + + and `is_del` = #{isDel} + + + + and `level` = #{level} + + + + 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} + + + order by ${sortColumns} + + + + + + + + + + update tt_goods_category_new set is_del = #{isDel}, update_date = #{updateDate} + where id in + + #{idItem} + + + + + update tt_goods_category_new set update_date = #{updateDate} + ,`service_fee` = #{serviceFee} + ,`software_fee` = #{softwareFee} + where id in + + #{idItem} + + + +