From 4245b7efa66ffac5fef7e4a3578d297b84104279 Mon Sep 17 00:00:00 2001 From: xhxu Date: Fri, 6 May 2022 16:32:38 +0800 Subject: [PATCH] //update poi --- .../controller/WxCouponChannelController.java | 10 +++ .../controller/WxCouponOrderController.java | 45 ++++++++++- .../schedule/TtMerchantPoiSchedule.java | 71 ++++++++++------ .../domain/po/TtCouponChannelPoi.java | 43 ++++++++++ .../com/iformall/enums/EnumSpuSyncStatus.java | 40 +++++++++ .../mapper/TtCouponChannelPoiMapper.java | 14 ++++ .../service/WxCouponChannelService.java | 3 +- .../impl/TtMerchantPoiServiceImpl.java | 81 ++++++++++++++++++- .../impl/WxCouponChannelServiceImpl.java | 13 +++ .../service/impl/WxPayOrderServiceImpl.java | 2 +- .../mapper/TtCouponChannelPoiMapper.xml | 80 ++++++++++++++++++ 11 files changed, 370 insertions(+), 32 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumSpuSyncStatus.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/TtCouponChannelPoiMapper.java create mode 100644 mallinkService/src/main/resources/mapper/TtCouponChannelPoiMapper.xml diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java index 0d7d9e4c0..318baff3b 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java @@ -218,4 +218,14 @@ public class WxCouponChannelController extends BaseController { } + @ApiOperation("获取poi数据") + @GetMapping("getChannelPoi") + public ResultData getChannelPoi(Long id) { + if (null == id){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + return wxCouponChannelService.getCouponChannelPoi(getTenantInfo(),id); + } + + } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java index 4a9f2df42..d50c6bdbb 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java @@ -14,10 +14,7 @@ import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxCouponOrderCVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; -import com.iformall.service.MemCouponFromDspService; -import com.iformall.service.SysConfigService; -import com.iformall.service.WxCouponOrderService; -import com.iformall.service.WxCouponService; +import com.iformall.service.*; import com.iformall.utils.Constant; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -61,6 +58,9 @@ public class WxCouponOrderController extends BaseController { @Autowired SysConfigService sysConfigService; + @Autowired + private WxPayOrderService wxPayOrderService; + //@RedisCache(expireTime = 100) @ApiOperation("券包分页列表接口") @GetMapping("list") @@ -522,4 +522,41 @@ public class WxCouponOrderController extends BaseController { return new ResultData(couponOrder); } + + @ApiOperation("获取支付订单") + @GetMapping("getChannelPoi") + public ResultData getChannelPoi(Long id) { + if (null == id){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + WxCUserBasicInfo member; + try { + member = getCacheMember(); + } catch (Exception e) { + return new ResultData(Result.ERROR,e.getMessage()); + } + + WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(id,getTenantInfo().getTenantId()); + if (wxCouponOrder == null) { + logger.error("券ID不存在:" + id); + return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); + } + if(!member.getId().equals(wxCouponOrder.getCUserId())){ + logger.error("此券不属于此人:" + member.getId()); + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); + } + try{ + WxPayOrder payOrderQ = new WxPayOrder(); + payOrderQ.updateTenantInfo(getTenantInfo()); + payOrderQ.setCUserId(member.getId()); + payOrderQ.setOrderId(wxCouponOrder.getComposeOrderId()); + payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); + WxPayOrder payOrder = wxPayOrderService.getByObj(payOrderQ); + return new ResultData(payOrder); + }catch(MallinkException e) { + return new ResultData(e.getErrorCode(),e.getMessage()); + } + + } + } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java index aa30f3ba9..af09e3eb8 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java @@ -1,26 +1,30 @@ -//package com.iformall.schedule; -// -//import com.iformall.domain.po.*; -//import com.iformall.enums.EnumSupplierMathStatus; -//import com.iformall.enums.EnumSupplierSyncStatus; -//import com.iformall.service.TtMerchantPoiService; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.scheduling.annotation.Async; -//import org.springframework.scheduling.annotation.Scheduled; -//import org.springframework.stereotype.Component; -// -//import java.util.List; -// -//@Component -//public class TtMerchantPoiSchedule { -// -// private final Logger logger = LoggerFactory.getLogger(this.getClass()); -// -// @Autowired -// private TtMerchantPoiService ttMerchantPoiService; -// +package com.iformall.schedule; + +import com.iformall.domain.po.*; +import com.iformall.enums.EnumSpuSyncStatus; +import com.iformall.enums.EnumSupplierMathStatus; +import com.iformall.mapper.TtCouponChannelPoiMapper; +import com.iformall.service.TtMerchantPoiService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class TtMerchantPoiSchedule { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private TtMerchantPoiService ttMerchantPoiService; + + @Autowired + private TtCouponChannelPoiMapper ttCouponChannelPoiMapper; + // @Async // @Scheduled(cron = "0 0 */1 * * *?") // 每小时检查一次 // public void supplierQueryTaskSchedule() { @@ -54,5 +58,22 @@ // } // } // } -// -//} \ No newline at end of file + + @Async + @Scheduled(cron = "0 0 */1 * * *?") // 每小时检查一次 + public void supplierQueryTaskSchedule() { + TtCouponChannelPoi ttCouponChannelPoi = new TtCouponChannelPoi(); + ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + List list = ttCouponChannelPoiMapper.findList(ttCouponChannelPoi); + if(list != null && list.size() > 0){ + for (TtCouponChannelPoi poi:list) { + try{ + ttMerchantPoiService.spuGet(poi,poi.getId()); + }catch(Exception e){ + logger.error("查询商品同步任务失败"); + } + } + } + } + +} \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java b/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java new file mode 100644 index 000000000..cdd8c0eba --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java @@ -0,0 +1,43 @@ +package com.iformall.domain.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.google.gson.JsonObject; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.utils.Constant; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.math.BigDecimal; +import java.util.Date; + +@TableName(value = "tt_coupon_channel_poi") +@Data +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class TtCouponChannelPoi extends TenantEntity { + + protected Long id;//coupon_channel_id + + @io.swagger.annotations.ApiModelProperty(value="spuId",name="spuId") + private String spuId; + + @io.swagger.annotations.ApiModelProperty(value="状态:0-审核中,1-上架,2-下架,3-审核拒绝 4-审核通过",name="status") + private Integer status; + + @io.swagger.annotations.ApiModelProperty(value="描述",name="statusDesc") + private String statusDesc; + + @io.swagger.annotations.ApiModelProperty(value="状态:0-审核中,1-上架,2-下架,3-审核拒绝 4-审核通过",name="lastStatus") + private Integer lastStatus; + + @io.swagger.annotations.ApiModelProperty(value="描述",name="lastStatusDesc") + private String lastStatusDesc; + + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") + private Date createDate; + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") + private Date updateDate; + + +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumSpuSyncStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumSpuSyncStatus.java new file mode 100644 index 000000000..537553ae3 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumSpuSyncStatus.java @@ -0,0 +1,40 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumSpuSyncStatus { + // 状态:0-审核中,1-上架,2-下架,3-审核拒绝 4-审核通过 +// sync_update(-1, "等待重新同步"), + sync_auditing(0, "审核中"), + sync_put_on(1, "上架"), + sync_pull_off(2, "下架"), + sync_audit_rejection(3, "审核拒绝"), + sync_audit_pass(4, "审核通过"), + ; + + public static EnumSpuSyncStatus getEnum(Integer code) { + for (EnumSpuSyncStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumSpuSyncStatus(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/TtCouponChannelPoiMapper.java b/mallinkService/src/main/java/com/iformall/mapper/TtCouponChannelPoiMapper.java new file mode 100644 index 000000000..8e46fb873 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/TtCouponChannelPoiMapper.java @@ -0,0 +1,14 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.TtCouponChannelPoi; + +import java.util.List; + +public interface TtCouponChannelPoiMapper extends CommonMapper { + + List findList(TtCouponChannelPoi record); + + List findIdList(TtCouponChannelPoi record); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java index 9560f7eed..e347da8db 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java @@ -67,5 +67,6 @@ public interface WxCouponChannelService { void setChannelStock(WxCouponChannel record,Integer number); void releaseChannelStock(WxCouponChannel record); void setChannelPrice(WxCouponChannel record); - + + ResultData getCouponChannelPoi(TenantEntity tenantInfo, Long id); } 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 1dcedb3d0..9cdf8e20d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.iformall.common.ErrorCode; @@ -55,6 +54,9 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { @Autowired WxCouponChannelMapper wxCouponChannelMapper; + @Autowired + TtCouponChannelPoiMapper ttCouponChannelPoiMapper; + @Autowired WxCouponMapper wxCouponMapper; @@ -605,9 +607,31 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { ccUpd.setTtSpuId(spuId); ccUpd.setUpdateDate(new Date()); wxCouponChannelMapper.updateById(ccUpd); + + syncCouponChannelPoi(ccUpd); return new ResultData(); } + private void syncCouponChannelPoi(WxCouponChannel ccUpd){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(ccUpd.getId()); + if(ttCouponChannelPoi != null){ + ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatusDesc(""); + ttCouponChannelPoi.setUpdateDate(ccUpd.getUpdateDate()); + ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); + }else{ + ttCouponChannelPoi = new TtCouponChannelPoi(); + ttCouponChannelPoi.setId(ccUpd.getId()); + ttCouponChannelPoi.updateTenantInfo(ccUpd); + ttCouponChannelPoi.setSpuId(ccUpd.getTtSpuId()); + ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setCreateDate(ccUpd.getUpdateDate()); + ttCouponChannelPoi.setUpdateDate(ccUpd.getUpdateDate()); + ttCouponChannelPoiMapper.insert(ttCouponChannelPoi); + } + } + private String spuSync(WxCoupon coupon,WxCouponChannel couponChannel, List merchantIds){ TtSpuSync spuSync = new TtSpuSync(); spuSync.setEntryInfo(getEntryInfo(couponChannel)); @@ -759,6 +783,7 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { spuGet.setSpuDraftcount(3); try { TtSpuGetResult spuGetResult = getTtWebService(tenantInfo).getProductService().spuGet(spuGet); + handSyncCouponChannelPoi(tenantInfo,spuGetResult); //处理一下数据 Map map = new HashMap<>(); if(spuGetResult.getSpuDetail() != null){//线上数据 @@ -776,6 +801,60 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { } } + private void handSyncCouponChannelPoi(TenantEntity tenantInfo,TtSpuGetResult spuGetResult){ + Date now = new Date(); + TtSpuSync spuDetail = spuGetResult.getSpuDetail(); + if(spuDetail != null && StringUtils.isNotBlank(spuDetail.getSpuId()) && StringUtils.isNotBlank(spuDetail.getSpuExtId()) + && spuDetail.getStatus() != null){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(Long.parseLong(spuDetail.getSpuExtId())); + if(ttCouponChannelPoi != null && !spuDetail.getStatus().equals(ttCouponChannelPoi.getStatus())){ + TtCouponChannelPoi ccPoi = new TtCouponChannelPoi(); + ccPoi.setId(ttCouponChannelPoi.getId()); + ccPoi.setStatus(spuDetail.getStatus()); + ccPoi.setStatusDesc(spuDetail.getStatusDesc()); + ccPoi.setUpdateDate(now); + ttCouponChannelPoiMapper.updateById(ccPoi); + }else if(ttCouponChannelPoi == null){ + ttCouponChannelPoi = new TtCouponChannelPoi(); + ttCouponChannelPoi.setId(Long.parseLong(spuDetail.getSpuExtId())); + ttCouponChannelPoi.updateTenantInfo(tenantInfo); + ttCouponChannelPoi.setSpuId(spuDetail.getSpuId()); + ttCouponChannelPoi.setStatus(spuDetail.getStatus()); + ttCouponChannelPoi.setStatusDesc(spuDetail.getStatusDesc()); + ttCouponChannelPoi.setCreateDate(now); + ttCouponChannelPoi.setUpdateDate(now); + ttCouponChannelPoiMapper.insert(ttCouponChannelPoi); + } + } + List spuDraftList = spuGetResult.getSpuDraft(); + if(spuDraftList != null && spuDraftList.size() > 0){ + TtSpuSync spuDraft = spuDraftList.get(0); + if(spuDraft != null && StringUtils.isNotBlank(spuDraft.getSpuId()) && StringUtils.isNotBlank(spuDraft.getSpuExtId()) + && spuDraft.getStatus() != null){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(Long.parseLong(spuDraft.getSpuExtId())); + if(ttCouponChannelPoi != null && !spuDraft.getStatus().equals(ttCouponChannelPoi.getStatus())){ + TtCouponChannelPoi ccPoi = new TtCouponChannelPoi(); + ccPoi.setId(ttCouponChannelPoi.getId()); + ccPoi.setLastStatus(spuDraft.getStatus()); + ccPoi.setLastStatusDesc(spuDraft.getStatusDesc()); + ccPoi.setUpdateDate(now); + ttCouponChannelPoiMapper.updateById(ccPoi); + }else if(ttCouponChannelPoi == null){ + ttCouponChannelPoi = new TtCouponChannelPoi(); + ttCouponChannelPoi.setId(Long.parseLong(spuDetail.getSpuExtId())); + ttCouponChannelPoi.updateTenantInfo(tenantInfo); + ttCouponChannelPoi.setSpuId(spuDraft.getSpuId()); + ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatus(spuDraft.getStatus()); + ttCouponChannelPoi.setLastStatusDesc(spuDraft.getStatusDesc()); + ttCouponChannelPoi.setCreateDate(now); + ttCouponChannelPoi.setUpdateDate(now); + ttCouponChannelPoiMapper.insert(ttCouponChannelPoi); + } + } + } + } + private Map handSpuSync(TtSpuSync spuSync){ Map map = new HashMap<>(); map.put("id",spuSync.getSpuExtId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java index 739633047..e6f7a4d9c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java @@ -6,6 +6,7 @@ import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.Result; import com.iformall.common.ResultData; +import com.iformall.domain.po.TtCouponChannelPoi; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponChannel; @@ -56,6 +57,9 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { WxMerchantMapper wxMerchantMapper; @Autowired WxCouponMerchantMapper wxCouponMerchantMapper; + + @Autowired + TtCouponChannelPoiMapper ttCouponChannelPoiMapper; @Lazy @Autowired @@ -727,5 +731,14 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { wxCouponChannelMapper.setChannelPrice(record.getId(), record.getTenantId(), record.getChannelPrice()); } + @Override + public ResultData getCouponChannelPoi(TenantEntity tenantInfo, Long id) { + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(id); + if(ttCouponChannelPoi != null && ttCouponChannelPoi.getStatus() != null && ttCouponChannelPoi.getStatus().intValue() > 0){ + return new ResultData(ttCouponChannelPoi); + } + return new ResultData(ErrorCode.SYS_NULLPOINTER_ERROR.getCode(),"未找到可用的数据"); + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 18035f5ef..2ab52adb7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -1326,7 +1326,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { }else if(list != null && list.size() > 1){ throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); } - return null; + throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); } @Override diff --git a/mallinkService/src/main/resources/mapper/TtCouponChannelPoiMapper.xml b/mallinkService/src/main/resources/mapper/TtCouponChannelPoiMapper.xml new file mode 100644 index 000000000..bb819e7eb --- /dev/null +++ b/mallinkService/src/main/resources/mapper/TtCouponChannelPoiMapper.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`parent_tenant_id`,`spu_id`, + `status`,`status_desc`,`last_status`,`last_status_desc`, + `create_date`,`update_date` + + + + where is_del = 0 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + + and `spu_id` = #{spuId} + + + + and `status` = #{status} + + + + and `last_status` = #{lastStatus} + + + + and `id` in + + #{idItem} + + + + order by ${sortColumns} + + + + + + + + update tt_coupon_channel_poi set is_del = 1 + where id = #{id} + + +