添加ec标签同步完整代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.cool.store.mapper;
|
package com.cool.store.mapper;
|
||||||
|
|
||||||
import com.cool.store.entity.HyPartnerBaseInfoDO;
|
import com.cool.store.entity.HyPartnerBaseInfoDO;
|
||||||
|
import com.cool.store.entity.SyncEcCustomerLabelDO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -63,4 +64,10 @@ public interface HyPartnerBaseInfoMapper {
|
|||||||
@Param("idCardPhotoBlack") String idCardPhotoBlack,
|
@Param("idCardPhotoBlack") String idCardPhotoBlack,
|
||||||
@Param("partnerLineId") Long partnerLineId);
|
@Param("partnerLineId") Long partnerLineId);
|
||||||
|
|
||||||
|
int selectAllList();
|
||||||
|
|
||||||
|
List<SyncEcCustomerLabelDO> selectListByLimit(@Param("limit1") Integer limit1, @Param("limit2") Integer limit2);
|
||||||
|
|
||||||
|
void updateByMobile(HyPartnerBaseInfoDO record);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -296,6 +296,12 @@
|
|||||||
left join hy_partner_line_info b on a.partner_line_id = b.id
|
left join hy_partner_line_info b on a.partner_line_id = b.id
|
||||||
where a.id_card = #{idCard} and ( b.line_status != 3 and b.deleted = 0 )
|
where a.id_card = #{idCard} and ( b.line_status != 3 and b.deleted = 0 )
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectAllList" resultType="java.lang.Integer">
|
||||||
|
SELECT count(*) FROM hy_partner_base_info where mobile is not null and user_portrait is null
|
||||||
|
</select>
|
||||||
|
<select id="selectListByLimit" resultType="com.cool.store.entity.SyncEcCustomerLabelDO">
|
||||||
|
SELECT id,mobile,user_portrait as userPortrait FROM hy_partner_base_info where mobile is not null and user_portrait is null LIMIT #{limit1},#{limit2}
|
||||||
|
</select>
|
||||||
|
|
||||||
<update id="cleanIdCardInfoByPartnerLineId">
|
<update id="cleanIdCardInfoByPartnerLineId">
|
||||||
update hy_partner_base_info
|
update hy_partner_base_info
|
||||||
@@ -305,5 +311,15 @@
|
|||||||
id_card_photo_black = #{idCardPhotoBlack}
|
id_card_photo_black = #{idCardPhotoBlack}
|
||||||
where partner_line_id = #{partnerLineId}
|
where partner_line_id = #{partnerLineId}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateByMobile">
|
||||||
|
update hy_partner_base_info
|
||||||
|
<set>
|
||||||
|
update_time=now(),
|
||||||
|
<if test="userPortrait != null and userPortrait!=''">
|
||||||
|
user_portrait = #{userPortrait},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where mobile = #{mobile}
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.cool.store.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class SyncEcCustomerLabelDO {
|
||||||
|
|
||||||
|
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
private String userPortrait;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.cool.store.job;
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import com.cool.store.utils.StringUtil;
|
|
||||||
import com.xxl.job.core.context.XxlJobHelper;
|
|
||||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hxd
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class EcSyncLabelJob {
|
|
||||||
|
|
||||||
@Value("${ec.baseUrl:null}")
|
|
||||||
private String baseUrl;
|
|
||||||
|
|
||||||
@XxlJob("SyncAppletToEcJob")
|
|
||||||
public void syncAppletToEcJob() {
|
|
||||||
XxlJobHelper.log("-------------------------------定时同步小程序数据到ec开始-------------------------------");
|
|
||||||
syncEcLabelExecute();
|
|
||||||
XxlJobHelper.log("-------------------------------定时同步小程序数据到ec结束-------------------------------");
|
|
||||||
XxlJobHelper.handleSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//定时同步小程序数据到ec
|
|
||||||
private void syncEcLabelExecute() {
|
|
||||||
// 获取参数
|
|
||||||
String param = XxlJobHelper.getJobParam();
|
|
||||||
String startTime = "";
|
|
||||||
if (StringUtil.isNotEmpty(param)) {
|
|
||||||
XxlJobHelper.log("输入参数为:" + param);
|
|
||||||
startTime = param;
|
|
||||||
}
|
|
||||||
String endTime = DateUtil.now();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.cool.store.job;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.cool.store.entity.HyPartnerBaseInfoDO;
|
||||||
|
import com.cool.store.entity.SyncEcCustomerDO;
|
||||||
|
import com.cool.store.entity.SyncEcCustomerLabelDO;
|
||||||
|
import com.cool.store.mapper.HyPartnerBaseInfoMapper;
|
||||||
|
import com.cool.store.sdk.ec.EcClient;
|
||||||
|
import com.cool.store.sdk.ec.request.SyncEcCustomerLabelRequest;
|
||||||
|
import com.cool.store.sdk.ec.request.SyncEcCustomerRequest;
|
||||||
|
import com.cool.store.sdk.ec.response.SyncEcCustomerLabelResponse;
|
||||||
|
import com.cool.store.service.HyPartnerBaseInfoService;
|
||||||
|
import com.cool.store.utils.MybatisBatchUtils;
|
||||||
|
import com.cool.store.utils.StringUtil;
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hxd
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class SyncEcCustomerLabelJob {
|
||||||
|
|
||||||
|
@Value("${ec.baseUrl:null}")
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private HyPartnerBaseInfoMapper hyPartnerBaseInfoMapper;
|
||||||
|
|
||||||
|
@XxlJob("SyncEcCustomerLabelJob")
|
||||||
|
public void execute() {
|
||||||
|
XxlJobHelper.log("-------------------------------同步ec客户标签数据到小程序开始-------------------------------");
|
||||||
|
syncEcLabelExecute();
|
||||||
|
XxlJobHelper.log("-------------------------------同步ec标签数据到小程序结束-------------------------------");
|
||||||
|
XxlJobHelper.handleSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MybatisBatchUtils mybatisBatchUtils;
|
||||||
|
|
||||||
|
private final Integer count = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步ec标签到招商数据库中
|
||||||
|
*/
|
||||||
|
private void syncEcLabelExecute() {
|
||||||
|
//获取总数
|
||||||
|
int size = hyPartnerBaseInfoMapper.selectAllList();
|
||||||
|
//执行数
|
||||||
|
int counts = size / count;
|
||||||
|
//取余,如果大于1,就再加一
|
||||||
|
int yu = size % count;
|
||||||
|
if (yu > 0) {
|
||||||
|
counts += 1;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= counts; i++) {
|
||||||
|
XxlJobHelper.log("执行limit1:" + count * (i - 1) + ",执行limit2:" + count);
|
||||||
|
List<SyncEcCustomerLabelDO> list = hyPartnerBaseInfoMapper.selectListByLimit(count * (i - 1), count);
|
||||||
|
SyncEcCustomerLabelRequest syncEcCustomerLabelRequest = new SyncEcCustomerLabelRequest();
|
||||||
|
syncEcCustomerLabelRequest.setParameter(list);
|
||||||
|
EcClient ecClient = new EcClient();
|
||||||
|
SyncEcCustomerLabelResponse exec = ecClient.exec(baseUrl, syncEcCustomerLabelRequest);
|
||||||
|
if (ObjectUtil.isNull(exec)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<SyncEcCustomerLabelDO> execList = exec.getData();
|
||||||
|
if (CollectionUtils.isEmpty(execList)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<HyPartnerBaseInfoDO> collect = execList.stream().map((item) -> {
|
||||||
|
HyPartnerBaseInfoDO hyPartnerBaseInfoDO = new HyPartnerBaseInfoDO();
|
||||||
|
BeanUtil.copyProperties(item, hyPartnerBaseInfoDO);
|
||||||
|
return hyPartnerBaseInfoDO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
mybatisBatchUtils.batchInsertOrUpdate(collect, HyPartnerBaseInfoMapper.class, (record, mapper) -> mapper.updateByMobile(record));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.cool.store.sdk.ec.request;
|
||||||
|
|
||||||
|
import com.cool.store.sdk.ec.core.EcRequest;
|
||||||
|
import com.cool.store.sdk.ec.response.SyncEcCustomerLabelResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hxd
|
||||||
|
*/
|
||||||
|
public class SyncEcCustomerLabelRequest extends EcRequest<SyncEcCustomerLabelResponse> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getApiUrl() {
|
||||||
|
return "/ec/appletToEcLabel";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<SyncEcCustomerLabelResponse> getResponseClass() {
|
||||||
|
return SyncEcCustomerLabelResponse.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.cool.store.sdk.ec.response;
|
||||||
|
|
||||||
|
|
||||||
|
import com.cool.store.entity.SyncEcCustomerLabelDO;
|
||||||
|
import com.cool.store.sdk.ec.core.EcResponse;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hxd
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class SyncEcCustomerLabelResponse extends EcResponse {
|
||||||
|
|
||||||
|
private List<SyncEcCustomerLabelDO> data;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -111,7 +111,8 @@ public class LabelServiceImpl implements LabelService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addEcLabel(HyPartnerLabelDO hyPartnerLabelDO) {
|
public void addEcLabel(HyPartnerLabelDO hyPartnerLabelDO) {
|
||||||
hyPartnerLabelDO.setEditDate(new Date()).setCreateTime(new Date()).setEditUserId(createUserId).setCreateUserId(createUserId);
|
hyPartnerLabelDO.setEditDate(new Date()).setCreateTime(new Date()).setEditUserId(createUserId).setCreateUserId(createUserId)
|
||||||
|
.setUpdateUserId(createUserId);
|
||||||
labelMapper.insertSelective(hyPartnerLabelDO);
|
labelMapper.insertSelective(hyPartnerLabelDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.cool.store.utils;
|
||||||
|
|
||||||
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||||
|
public class MybatisBatchUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每次处理500条
|
||||||
|
*/
|
||||||
|
private static final int BATCH_SIZE = 500;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量处理修改或者插入
|
||||||
|
*
|
||||||
|
* @param data 需要被处理的数据
|
||||||
|
* @param mapperClass Mybatis的Mapper类
|
||||||
|
* @param consumer 自定义处理逻辑
|
||||||
|
* @return int 影响的总行数
|
||||||
|
* @author renwd
|
||||||
|
*/
|
||||||
|
public <T, U> int batchInsertOrUpdate(List<T> data, Class<U> mapperClass, BiConsumer<T, U> consumer) {
|
||||||
|
int i = 1;
|
||||||
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
|
try {
|
||||||
|
U mapper = sqlSession.getMapper(mapperClass);
|
||||||
|
int size = data.size();
|
||||||
|
for (T element : data) {
|
||||||
|
consumer.accept(element, mapper);
|
||||||
|
if ((i % BATCH_SIZE == 0) || i == size) {
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
sqlSession.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
sqlSession.close();
|
||||||
|
}
|
||||||
|
return i - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,7 @@ public class TokenValidateFilter implements Filter {
|
|||||||
//TODO 800回调地址暂时不做验证
|
//TODO 800回调地址暂时不做验证
|
||||||
"/partner/pc/flow/qualificationReview/callback",
|
"/partner/pc/flow/qualificationReview/callback",
|
||||||
"/**/ecSync/ecToApplet/**",
|
"/**/ecSync/ecToApplet/**",
|
||||||
|
"/**/ecSync/labelInfo/**",
|
||||||
"/partner/pc/websocket/**",
|
"/partner/pc/websocket/**",
|
||||||
"/partner/pc/call/**");
|
"/partner/pc/call/**");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user