| @@ -6,6 +6,7 @@ import com.iformall.annotation.TenantIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.TtGoodsCategory; | |||
| import com.iformall.service.TtGoodsCategoryService; | |||
| import com.iformall.utils.DateUtils; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -52,20 +53,45 @@ public class TtGoodsCategoryController extends BaseController { | |||
| } | |||
| @TenantIgnore | |||
| @ApiOperation("查询抖音类目") | |||
| @GetMapping("syncGet/{token}") | |||
| @ApiOperation("同步抖音类目") | |||
| @GetMapping("syncGetTt") | |||
| @ApiImplicitParams({}) | |||
| @SystemControllerLog(description = "列表") | |||
| public ResultData syncGet(@PathVariable String token) { | |||
| logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::get"); | |||
| if(StringUtils.isBlank(token)){ | |||
| @SystemControllerLog(description = "同步") | |||
| public ResultData syncGetTt() { | |||
| logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::syncGetTt"); | |||
| ttGoodsCategoryService.syncGet(); | |||
| return new ResultData(); | |||
| } | |||
| @TenantIgnore | |||
| @ApiOperation("设置抖音软件服务费率") | |||
| @PostMapping("setServiceFee") | |||
| @ApiImplicitParams({}) | |||
| @SystemControllerLog(description = "修改") | |||
| public ResultData setServiceFee(@RequestBody TtGoodsCategory record) { | |||
| logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::setServiceFee"); | |||
| if(record.getId() == null || record.getServiceFee() == null){ | |||
| 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); | |||
| record.setSoftwareFee(null); | |||
| ttGoodsCategoryService.updateFee(record); | |||
| return new ResultData(); | |||
| } | |||
| @TenantIgnore | |||
| @ApiOperation("设置软件服务费") | |||
| @PostMapping("setSoftwareFee") | |||
| @ApiImplicitParams({}) | |||
| @SystemControllerLog(description = "修改") | |||
| public ResultData setSoftwareFee(@RequestBody TtGoodsCategory record) { | |||
| logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::setSoftwareFee"); | |||
| if(record.getId() == null || record.getSoftwareFee() == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| ttGoodsCategoryService.syncGet(); | |||
| record.setServiceFee(null); | |||
| ttGoodsCategoryService.updateFee(record); | |||
| return new ResultData(); | |||
| } | |||
| @@ -0,0 +1,4 @@ | |||
| ALTER TABLE `mallink`.`tt_goods_category` | |||
| MODIFY COLUMN `service_fee` int(11) DEFAULT NULL COMMENT ''抖音软件服务费率(万分之)'' AFTER `is_leaf`, | |||
| ADD COLUMN `software_fee` int(11) COMMENT ''软件服务费率(万分位)'' AFTER `service_fee`; | |||
| @@ -34,6 +34,9 @@ public class TtGoodsCategory extends BaseEntity { | |||
| @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") | |||
| @@ -13,4 +13,6 @@ public interface TtGoodsCategoryMapper extends CommonMapper<TtGoodsCategory, Str | |||
| List<Integer> findIdAll(TtGoodsCategory record); | |||
| int updDelByIds(TtGoodsCategory record); | |||
| int updateByFreeIds(TtGoodsCategory updgc); | |||
| } | |||
| @@ -1,6 +1,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.WxCoupon; | |||
| import com.iformall.douyin.web.bean.GoodsCategory; | |||
| @@ -44,4 +45,5 @@ public interface TtGoodsCategoryService { | |||
| List<GoodsCategory> categoryGet(Integer categoryId); | |||
| void updateFee(TtGoodsCategory record); | |||
| } | |||
| @@ -3,6 +3,8 @@ package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| 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.WxCoupon; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| @@ -477,11 +479,11 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| } | |||
| } | |||
| @Async | |||
| // @Async | |||
| @Override | |||
| public void syncGet() { | |||
| TtWebService ttWebService = ttMerchantPoiService.getTtWebService(null); | |||
| handSyncCategory(ttWebService,0,null,new Date()); | |||
| handSyncCategory(ttWebService,0,new Date()); | |||
| } | |||
| @Override | |||
| @@ -504,13 +506,24 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| } | |||
| } | |||
| @Override | |||
| public void updateFee(TtGoodsCategory record) { | |||
| List<Integer> ids = new ArrayList<>(); | |||
| if(record.getId() != null){ | |||
| ids.add(record.getId()); | |||
| } | |||
| if(!ids.isEmpty()){ | |||
| updateFeeByIds(ids,record.getServiceFee(),record.getSoftwareFee(),new Date()); | |||
| } | |||
| } | |||
| /** | |||
| * 循环同步类目 | |||
| * @param ttWebService | |||
| * @param category_id | |||
| * @param now | |||
| */ | |||
| private void handSyncCategory(TtWebService ttWebService,Integer category_id,EnumGoodsCategoryRate categoryRate,Date now){ | |||
| private void handSyncCategory(TtWebService ttWebService,Integer category_id,Date now){ | |||
| try { | |||
| List<GoodsCategory> goodsCategories = ttWebService.getGoodsService().categoryGet(category_id, null); | |||
| if(goodsCategories != null){ | |||
| @@ -518,12 +531,6 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| record.setParentId(category_id); | |||
| List<Integer> listAll = ttGoodsCategoryMapper.findIdAll(record); | |||
| for (GoodsCategory gc:goodsCategories) { | |||
| if(category_id.intValue() == 0){ | |||
| categoryRate = EnumGoodsCategoryRate.getEnum(gc.getCategoryId()); | |||
| if(categoryRate == null){ | |||
| categoryRate = EnumGoodsCategoryRate.OTHER; | |||
| } | |||
| } | |||
| TtGoodsCategory updgc = new TtGoodsCategory(); | |||
| updgc.setId(gc.getCategoryId()); | |||
| @@ -532,7 +539,6 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| 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.setServiceFee(categoryRate.getRate()); | |||
| updgc.setIsDel(EnumYesOrNo.NO.getCode()); | |||
| updgc.setUpdateDate(now); | |||
| if(listAll.contains(gc.getCategoryId())){ | |||
| @@ -543,7 +549,7 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| ttGoodsCategoryMapper.insert(updgc); | |||
| } | |||
| if(!gc.getIsLeaf()){ | |||
| handSyncCategory(ttWebService,gc.getCategoryId(),categoryRate,now); | |||
| handSyncCategory(ttWebService,gc.getCategoryId(),now); | |||
| } | |||
| } | |||
| updateDelByIds(listAll,now); | |||
| @@ -551,10 +557,12 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| } 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); | |||
| } | |||
| } | |||
| @@ -573,10 +581,33 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { | |||
| 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); | |||
| if(i > 0){ | |||
| TtGoodsCategory gcq = new TtGoodsCategory(); | |||
| gcq.setParentIds(ids); | |||
| List<Integer> idAll = ttGoodsCategoryMapper.findIdAll(gcq); | |||
| updateDelByIds(idAll,now); | |||
| } | |||
| } | |||
| /** | |||
| * 循环修改费率 | |||
| */ | |||
| private void updateFeeByIds(List<Integer> ids,Integer serviceFee,Integer softwareFee,Date now){ | |||
| if(ids == null || ids.size() <= 0){ | |||
| return; | |||
| } | |||
| TtGoodsCategory updgc = new TtGoodsCategory(); | |||
| updgc.setCategoryIds(ids); | |||
| updgc.setServiceFee(serviceFee); | |||
| updgc.setSoftwareFee(softwareFee); | |||
| updgc.setUpdateDate(now); | |||
| int i = ttGoodsCategoryMapper.updateByFreeIds(updgc); | |||
| if(i > 0){ | |||
| TtGoodsCategory gcq = new TtGoodsCategory(); | |||
| gcq.setParentIds(ids); | |||
| List<Integer> idAll = ttGoodsCategoryMapper.findIdAll(gcq); | |||
| updateFeeByIds(idAll,serviceFee,softwareFee,now); | |||
| } | |||
| } | |||
| } | |||
| @@ -9,10 +9,11 @@ | |||
| <result column="enable" jdbcType="INTEGER" property="enable" /> | |||
| <result column="is_leaf" jdbcType="INTEGER" property="isLeaf" /> | |||
| <result column="service_fee" jdbcType="INTEGER" property="serviceFee" /> | |||
| <result column="software_fee" jdbcType="INTEGER" property="softwareFee" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`level`,`name`,`parent_id`,`enable`,`is_leaf`,`service_fee` | |||
| `id`,`level`,`name`,`parent_id`,`enable`,`is_leaf`,`service_fee`,`software_fee` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -80,4 +81,14 @@ | |||
| </foreach> | |||
| </update> | |||
| <update id="updateByFreeIds" parameterType="com.iformall.domain.po.TtGoodsCategory"> | |||
| update tt_goods_category set update_date = #{updateDate} | |||
| <if test=" null != serviceFee ">,`service_fee` = #{serviceFee}</if> | |||
| <if test=" null != softwareFee ">,`software_fee` = #{softwareFee}</if> | |||
| where id in | |||
| <foreach collection="categoryIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </update> | |||
| </mapper> | |||