Commit 308dc8b2 by yinyong

数据中心--crm退款新增是否平台订单+发货、订单状态实时更新

parent 10a71313
......@@ -2,6 +2,7 @@ package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.CrmRefundSyncJob;
import com.bailuntec.job.CrmStatusSyncJob;
import com.bailuntec.job.RefundLinkOrderJob;
import com.bailuntec.listener.CrmRefundSyncJobListener;
import com.bailuntec.listener.RefundLinkJobListener;
......@@ -29,6 +30,7 @@ public class Application {
public static void main(String[] args) {
new JobScheduler(createRegistryCenter(), createJobConfiguration(),createJobEventConfiguration(), new CrmRefundSyncJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration1(),createJobEventConfiguration(), new RefundLinkJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
......@@ -50,6 +52,13 @@ public class Application {
return simpleJobRootConfig;
}
private static LiteJobConfiguration createJobConfiguration2() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_STATUS_NAME"), propertiesUtil.getPropertyAsString("JOB_STATUS_CRON"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, CrmStatusSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
return jobEventRdbConfig;
......
......@@ -57,4 +57,6 @@ public class RefundItem {
private String orderStatus;
@JSONField(name = "shipping_status")
private String shippingStatus;
@JSONField(name = "refund_type")
private Integer refundType;
}
package com.bailuntec.job;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcBaseCrmRefund;
import com.bailuntec.domain.entity.DcBaseOmsOrder;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseCrmRefundExample;
import com.bailuntec.domain.example.DcBaseOmsOrderExample;
import com.bailuntec.domain.pojo.RefundDetails;
import com.bailuntec.domain.pojo.RefundItem;
import com.bailuntec.mapper.DcBaseCrmRefundMapper;
import com.bailuntec.mapper.DcBaseOmsOrderMapper;
import com.bailuntec.support.PointJob;
import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.PropertiesUtil;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
@Slf4j
public class CrmStatusSyncJob extends PointJob {
private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
private OkHttpClient client = OkHttpUtil.getInstance();
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
LocalDate localDate = LocalDate.now();
long count = count(localDate);
long totalPage = count % jobPointLog.getPageSize() == 0 ? count/jobPointLog.getPageSize() : count/jobPointLog.getPageSize() + 1 ;
do{
DcBaseCrmRefundMapper dcBaseCrmRefundMapper = SessionUtil.getSession().getMapper(DcBaseCrmRefundMapper.class);
List<DcBaseCrmRefund> dcBaseCrmRefundList = dcBaseCrmRefundMapper.selectByRefundDate(localDate, jobPointLog.getPageIndex()*jobPointLog.getPageSize(), jobPointLog.getPageSize());
try {
for (DcBaseCrmRefund dcBaseCrmRefund : dcBaseCrmRefundList) {
DcBaseOmsOrderMapper omsOrderMapper = SessionUtil.getSession().getMapper(DcBaseOmsOrderMapper.class);
DcBaseOmsOrder dcBaseOmsOrder = null;
if(dcBaseCrmRefund.getPlatformType() != null) {
switch (dcBaseCrmRefund.getPlatformType().toUpperCase()) {
case "EBAY":
dcBaseOmsOrder = omsOrderMapper.selectOneByExample(DcBaseOmsOrderExample.newAndCreateCriteria().andBailunAccountIdEqualTo(dcBaseCrmRefund.getBailunAccountId()).andTransactionIdEqualTo(dcBaseCrmRefund.getOriginOrderId()).example());
break;
default:
dcBaseOmsOrder = omsOrderMapper.selectOneByExample(DcBaseOmsOrderExample.newAndCreateCriteria().andBailunAccountIdEqualTo(dcBaseCrmRefund.getBailunAccountId()).andOriginOrderIdEqualTo(dcBaseCrmRefund.getOriginOrderId()).example());
}
if(dcBaseOmsOrder != null) {
if("MERGED".equals(dcBaseOmsOrder.getBailunMergeStatus().toUpperCase())) {
dcBaseOmsOrder = omsOrderMapper.selectOneByExample(DcBaseOmsOrderExample.newAndCreateCriteria().andBailunAccountIdEqualTo(dcBaseCrmRefund.getBailunAccountId()).andOriginOrderIdEqualTo(dcBaseOmsOrder.getAftermergedBailunOrderNo()).example());
}
if(dcBaseOmsOrder != null) {
dcBaseCrmRefund.setOrderStatus(dcBaseOmsOrder.getBailunOrderStatus());
dcBaseCrmRefund.setShippingStatus(dcBaseOmsOrder.getBailunShippingStatus());
if("FBA".equals(dcBaseCrmRefund.getPlatformType().toUpperCase())) {
dcBaseCrmRefund.setShippingStatus("TotalShipping");
}
}
}
}
DcBaseCrmRefundMapper mapper = SessionUtil.getSession().getMapper(DcBaseCrmRefundMapper.class);
int i = mapper.updateByExampleSelective(dcBaseCrmRefund, DcBaseCrmRefundExample.newAndCreateCriteria().andCrmIdEqualTo(dcBaseCrmRefund.getCrmId()).example());
if (i == 0) {
mapper.insertSelective(dcBaseCrmRefund);
}
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1);
} catch (Exception e) {
throw new RuntimeException("MYBATIS操作DB异常", e);
} finally {
SessionUtil.closeSession();
}
}while (jobPointLog.getPageIndex() < totalPage);
jobPointLog.setPageIndex(1);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()));
}
public long count(LocalDate localDate) {
long count = 0;
try{
DcBaseCrmRefundMapper dcBaseCrmRefundMapper = SessionUtil.getSession().getMapper(DcBaseCrmRefundMapper.class);
count = dcBaseCrmRefundMapper.countByDate(localDate);
}catch (Exception e){
throw new RuntimeException("MYBATIS操作DB异常", e);
}finally {
SessionUtil.closeSession();
}
return count;
}
}
......@@ -13,4 +13,6 @@ JOB_NAME=base-sync-crm-refund
JOB_CRON=0 0 0/1 * * ? *
JOB_LINK_NAME=base-link-crm-refund
JOB_LINK_CRON=0 0 0/2 * * ? *
JOB_STATUS_NAME=base-status-crm-refund
JOB_STATUS_CRON=0 0 0/2 * * ? *
SHARDING_TOTAL_COUNT=1
\ No newline at end of file
......@@ -251,6 +251,15 @@ public class DcBaseCrmRefund {
private String shippingStatus;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_crm_refund.refund_type
*
* @mbg.generated
*/
private Integer refundType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_crm_refund
*
......@@ -289,6 +298,7 @@ public class DcBaseCrmRefund {
sb.append(", isFreeze=").append(isFreeze);
sb.append(", orderStatus=").append(orderStatus);
sb.append(", shippingStatus=").append(shippingStatus);
sb.append(", refundType=").append(refundType);
sb.append("]");
return sb.toString();
}
......@@ -337,7 +347,8 @@ public class DcBaseCrmRefund {
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()))
&& (this.getIsFreeze() == null ? other.getIsFreeze() == null : this.getIsFreeze().equals(other.getIsFreeze()))
&& (this.getOrderStatus() == null ? other.getOrderStatus() == null : this.getOrderStatus().equals(other.getOrderStatus()))
&& (this.getShippingStatus() == null ? other.getShippingStatus() == null : this.getShippingStatus().equals(other.getShippingStatus()));
&& (this.getShippingStatus() == null ? other.getShippingStatus() == null : this.getShippingStatus().equals(other.getShippingStatus()))
&& (this.getRefundType() == null ? other.getRefundType() == null : this.getRefundType().equals(other.getRefundType()));
}
/**
......@@ -377,6 +388,7 @@ public class DcBaseCrmRefund {
result = prime * result + ((getIsFreeze() == null) ? 0 : getIsFreeze().hashCode());
result = prime * result + ((getOrderStatus() == null) ? 0 : getOrderStatus().hashCode());
result = prime * result + ((getShippingStatus() == null) ? 0 : getShippingStatus().hashCode());
result = prime * result + ((getRefundType() == null) ? 0 : getRefundType().hashCode());
return result;
}
}
\ No newline at end of file
......@@ -2080,6 +2080,66 @@ public class DcBaseCrmRefundExample {
addCriterion("shipping_status not between", value1, value2, "shippingStatus");
return (Criteria) this;
}
public Criteria andRefundTypeIsNull() {
addCriterion("refund_type is null");
return (Criteria) this;
}
public Criteria andRefundTypeIsNotNull() {
addCriterion("refund_type is not null");
return (Criteria) this;
}
public Criteria andRefundTypeEqualTo(Integer value) {
addCriterion("refund_type =", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeNotEqualTo(Integer value) {
addCriterion("refund_type <>", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeGreaterThan(Integer value) {
addCriterion("refund_type >", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeGreaterThanOrEqualTo(Integer value) {
addCriterion("refund_type >=", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeLessThan(Integer value) {
addCriterion("refund_type <", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeLessThanOrEqualTo(Integer value) {
addCriterion("refund_type <=", value, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeIn(List<Integer> values) {
addCriterion("refund_type in", values, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeNotIn(List<Integer> values) {
addCriterion("refund_type not in", values, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeBetween(Integer value1, Integer value2) {
addCriterion("refund_type between", value1, value2, "refundType");
return (Criteria) this;
}
public Criteria andRefundTypeNotBetween(Integer value1, Integer value2) {
addCriterion("refund_type not between", value1, value2, "refundType");
return (Criteria) this;
}
}
/**
......
......@@ -4,6 +4,7 @@ import com.bailuntec.domain.entity.DcBaseCrmRefund;
import com.bailuntec.domain.example.DcBaseCrmRefundExample;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.util.List;
public interface DcBaseCrmRefundMapper {
......@@ -121,4 +122,8 @@ public interface DcBaseCrmRefundMapper {
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseCrmRefund record);
List<DcBaseCrmRefund> selectByRefundDate(@Param("localDate") LocalDate localDate, @Param("v1") Integer v1, @Param("v2") Integer v2);
long countByDate(@Param("localDate") LocalDate localDate);
}
\ No newline at end of file
......@@ -33,6 +33,7 @@
<result column="is_freeze" jdbcType="BIT" property="isFreeze" />
<result column="order_status" jdbcType="VARCHAR" property="orderStatus" />
<result column="shipping_status" jdbcType="VARCHAR" property="shippingStatus" />
<result column="refund_type" jdbcType="INTEGER" property="refundType" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
......@@ -109,7 +110,7 @@
platform_sku, amount_refund, order_currency, refund_time, bailun_sku_quantity_refund,
bailun_sku_unit_price, gmt_create, gmt_modified, linked, amount_refund_rmb, crm_id,
amount_refund_usd, company_id, order_total_amount, usd_order_total_amount, product_sale_amount,
is_deleted, is_freeze, order_status, shipping_status
is_deleted, is_freeze, order_status, shipping_status, refund_type
</sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseCrmRefundExample" resultMap="BaseResultMap">
<!--
......@@ -136,10 +137,7 @@
limit ${rows}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
......@@ -182,7 +180,7 @@
amount_refund_usd, company_id, order_total_amount,
usd_order_total_amount, product_sale_amount,
is_deleted, is_freeze, order_status,
shipping_status)
shipping_status, refund_type)
values (#{id,jdbcType=INTEGER}, #{platformType,jdbcType=VARCHAR}, #{bailunAccount,jdbcType=VARCHAR},
#{bailunAccountId,jdbcType=INTEGER}, #{website,jdbcType=VARCHAR}, #{originOrderId,jdbcType=VARCHAR},
#{bailunSku,jdbcType=VARCHAR}, #{platformSku,jdbcType=VARCHAR}, #{amountRefund,jdbcType=DECIMAL},
......@@ -192,7 +190,7 @@
#{amountRefundUsd,jdbcType=DECIMAL}, #{companyId,jdbcType=INTEGER}, #{orderTotalAmount,jdbcType=DECIMAL},
#{usdOrderTotalAmount,jdbcType=DECIMAL}, #{productSaleAmount,jdbcType=DECIMAL},
#{isDeleted,jdbcType=BIT}, #{isFreeze,jdbcType=BIT}, #{orderStatus,jdbcType=VARCHAR},
#{shippingStatus,jdbcType=VARCHAR})
#{shippingStatus,jdbcType=VARCHAR}, #{refundType,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcBaseCrmRefund">
<!--
......@@ -282,6 +280,9 @@
<if test="shippingStatus != null">
shipping_status,
</if>
<if test="refundType != null">
refund_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
......@@ -365,6 +366,9 @@
<if test="shippingStatus != null">
#{shippingStatus,jdbcType=VARCHAR},
</if>
<if test="refundType != null">
#{refundType,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseCrmRefundExample" resultType="java.lang.Long">
......@@ -465,6 +469,9 @@
<if test="record.shippingStatus != null">
shipping_status = #{record.shippingStatus,jdbcType=VARCHAR},
</if>
<if test="record.refundType != null">
refund_type = #{record.refundType,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -502,7 +509,8 @@
is_deleted = #{record.isDeleted,jdbcType=BIT},
is_freeze = #{record.isFreeze,jdbcType=BIT},
order_status = #{record.orderStatus,jdbcType=VARCHAR},
shipping_status = #{record.shippingStatus,jdbcType=VARCHAR}
shipping_status = #{record.shippingStatus,jdbcType=VARCHAR},
refund_type = #{record.refundType,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
......@@ -592,6 +600,9 @@
<if test="shippingStatus != null">
shipping_status = #{shippingStatus,jdbcType=VARCHAR},
</if>
<if test="refundType != null">
refund_type = #{refundType,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
......@@ -626,7 +637,8 @@
is_deleted = #{isDeleted,jdbcType=BIT},
is_freeze = #{isFreeze,jdbcType=BIT},
order_status = #{orderStatus,jdbcType=VARCHAR},
shipping_status = #{shippingStatus,jdbcType=VARCHAR}
shipping_status = #{shippingStatus,jdbcType=VARCHAR},
refund_type = #{refundType,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcBaseCrmRefund">
......@@ -718,6 +730,9 @@
<if test="shippingStatus != null">
shipping_status,
</if>
<if test="refundType != null">
refund_type,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
......@@ -802,6 +817,9 @@
<if test="shippingStatus != null">
#{shippingStatus,jdbcType=VARCHAR},
</if>
<if test="refundType != null">
#{refundType,jdbcType=INTEGER},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
......@@ -886,6 +904,9 @@
<if test="shippingStatus != null">
shipping_status = #{shippingStatus,jdbcType=VARCHAR},
</if>
<if test="refundType != null">
refund_type = #{refundType,jdbcType=INTEGER},
</if>
</trim>
</insert>
<insert id="upsert" parameterType="com.bailuntec.domain.entity.DcBaseCrmRefund">
......@@ -899,7 +920,7 @@
bailun_sku, platform_sku, amount_refund, order_currency, refund_time, bailun_sku_quantity_refund,
bailun_sku_unit_price, gmt_create, gmt_modified, linked, amount_refund_rmb, crm_id,
amount_refund_usd, company_id, order_total_amount, usd_order_total_amount, product_sale_amount,
is_deleted, is_freeze, order_status, shipping_status)
is_deleted, is_freeze, order_status, shipping_status, refund_type)
values
(#{id,jdbcType=INTEGER}, #{platformType,jdbcType=VARCHAR}, #{bailunAccount,jdbcType=VARCHAR},
#{bailunAccountId,jdbcType=INTEGER}, #{website,jdbcType=VARCHAR}, #{originOrderId,jdbcType=VARCHAR},
......@@ -910,7 +931,7 @@
#{amountRefundUsd,jdbcType=DECIMAL}, #{companyId,jdbcType=INTEGER}, #{orderTotalAmount,jdbcType=DECIMAL},
#{usdOrderTotalAmount,jdbcType=DECIMAL}, #{productSaleAmount,jdbcType=DECIMAL},
#{isDeleted,jdbcType=BIT}, #{isFreeze,jdbcType=BIT}, #{orderStatus,jdbcType=VARCHAR},
#{shippingStatus,jdbcType=VARCHAR})
#{shippingStatus,jdbcType=VARCHAR}, #{refundType,jdbcType=INTEGER})
on duplicate key update
id = #{id,jdbcType=INTEGER},
platform_type = #{platformType,jdbcType=VARCHAR},
......@@ -938,7 +959,8 @@
is_deleted = #{isDeleted,jdbcType=BIT},
is_freeze = #{isFreeze,jdbcType=BIT},
order_status = #{orderStatus,jdbcType=VARCHAR},
shipping_status = #{shippingStatus,jdbcType=VARCHAR}
shipping_status = #{shippingStatus,jdbcType=VARCHAR},
refund_type = #{refundType,jdbcType=INTEGER}
</insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseCrmRefundExample" resultMap="BaseResultMap">
<!--
......@@ -957,4 +979,19 @@
</if>
limit 1
</select>
<select id="selectByRefundDate" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from dc_base_crm_refund
where date_format(refund_time, '%Y-%m') = date_format(#{localDate}, '%Y-%m')
limit #{v1}, #{v2}
</select>
<select id="countByDate" resultType="java.lang.Long">
select
count(*)
from dc_base_crm_refund
where date_format(refund_time, '%Y-%m') = date_format(#{localDate}, '%Y-%m')
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment