Commit ae6b9b6c by fudahua

Merge branch 'developer-hua-5-21' into developer

# Conflicts:
#	haoban-manage3-service/src/main/resources/mapper/WxEnterpriseRelatedMapper.xml
#	haoban-manage3-service/src/test/java/ServiceTest.java
parents 651080b2 df6107b5
......@@ -127,6 +127,17 @@
<artifactId>haoban-app-customer-api</artifactId>
<version>${haoban-app-customer-api}</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-binlog-base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
package com.gic.haoban.manage.service.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.binlog.base.entity.GicRecord;
import com.gic.clerk.api.dto.ClerkListDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.communicate.api.dto.SyncJsonColumnDTO;
import com.gic.haoban.communicate.api.dto.SyncJsonDTO;
import com.gic.haoban.contacts.api.dto.EmployeeClerkAddDTO;
import com.gic.haoban.contacts.api.service.EmployeeClerkService;
import com.gic.haoban.contacts.manage.api.dto.DepartmentStoreGroupDTO;
import com.gic.haoban.contacts.manage.api.service.DepartmentStoreGroupService;
import com.gic.haoban.contacts.manage.api.service.StoreService;
import com.gic.haoban.manage.api.service.StaffApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.listener.MessageListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created 2019/4/10.
*
* @author hua
*/
public class KafkaMessageServiceImpl implements MessageListener<String, GicRecord> {
private final static Logger logger = LoggerFactory.getLogger(KafkaMessageServiceImpl.class);
private final String STORE = "tab_gic_store";
private final String CLERK = "tab_gic_clerk";
private final String DEPARTMENT = "tab_gic_store_group";
private final String STORE_IMAGE = "tab_gic_store_photo";
@Autowired
private StoreService storeService;
@Autowired
private ClerkService clerkService;
@Autowired
private StaffApiService staffApiService;
@Override
public void onMessage(ConsumerRecord<String, GicRecord> record) {
logger.info("message:{}", JSONObject.toJSONString(record.value()));
String message = JSONObject.toJSONString(record.value());
if(StringUtils.isBlank(message)){
return;
}
// SyncJsonDTO syncJsonDTO = JSON.toJavaObject((JSONObject)JSON.parse(message),SyncJsonDTO.class);
// String fieldListString = syncJsonDTO.getFieldList();
// String tableName = syncJsonDTO.getTableName();
if(tableName.equals(STORE)){
logger.info("【同步门店】");
String haobanClerkListString = setClerkList(fieldListString);
logger.info("【同步门店】haobanClerkListString={}",haobanClerkListString);
storeService.syncGicStore(fieldListString,haobanClerkListString);
}else if (tableName.equals(CLERK)){
logger.info("【同步店员】");
try {
employeeClerkService.syncGicClerk(fieldListString);
} catch (Exception e) {
logger.info("【同步店员】同步失败={}",e.toString());
}
staffApiService.syncGicClerk(fieldListString);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:apollo="http://www.ctrip.com/schema/apollo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.ctrip.com/schema/apollo
http://www.ctrip.com/schema/apollo.xsd">
<apollo:config/>
<bean id="consumerProperties" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="bootstrap.servers" value="${kafka.service}"/>
<entry key="group.id" value="haoban-3-sync"/>
<entry key="key.deserializer"
value="org.apache.kafka.common.serialization.StringDeserializer"/>
<entry key="value.deserializer"
value="com.gic.binlog.base.serializer.KafkaGicRecordSerializer"/>
</map>
</constructor-arg>
</bean>
<!-- 2.创建consumerFactory bean -->
<bean id="consumerFactory"
class="org.springframework.kafka.core.DefaultKafkaConsumerFactory">
<constructor-arg>
<ref bean="consumerProperties"/>
</constructor-arg>
</bean>
<!-- 3.定义消费实现类 -->
<bean id="kafkaConsumerService" class="com.gic.haoban.manage.service.task.KafkaMessageServiceImpl"/>
<!-- 4.消费者容器配置信息 -->
<bean id="containerProperties" class="org.springframework.kafka.listener.config.ContainerProperties">
<!-- topic -->
<constructor-arg name="topics">
<list>
<value>haoban_gic_clerk</value>
<value>haoban_gic_store</value>
</list>
</constructor-arg>
<property name="messageListener" ref="kafkaConsumerService"/>
</bean>
<!-- 5.消费者并发消息监听容器,执行doStart()方法 -->
<bean id="messageListenerContainer" class="org.springframework.kafka.listener.ConcurrentMessageListenerContainer"
init-method="doStart">
<constructor-arg ref="consumerFactory"/>
<constructor-arg ref="containerProperties"/>
<property name="concurrency" value="3"/>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper" >
<resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
<id column="wx_enterprise_related_id" property="wxEnterpriseRelatedId" jdbcType="VARCHAR" />
<result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR" />
<result column="enterprise_id" property="enterpriseId" jdbcType="VARCHAR" />
<result column="version" property="version" jdbcType="VARCHAR" />
<result column="status_flag" property="statusFlag" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
wx_enterprise_related_id, wx_enterprise_id, enterprise_id, version, status_flag,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
insert into tab_haoban_wx_enterprise_related (wx_enterprise_related_id, wx_enterprise_id,
enterprise_id, version, status_flag,
create_time, update_time)
values (#{wxEnterpriseRelatedId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
#{enterpriseId,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
insert into tab_haoban_wx_enterprise_related
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="wxEnterpriseRelatedId != null" >
wx_enterprise_related_id,
</if>
<if test="wxEnterpriseId != null" >
wx_enterprise_id,
</if>
<if test="enterpriseId != null" >
enterprise_id,
</if>
<if test="version != null" >
version,
</if>
<if test="statusFlag != null" >
status_flag,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="wxEnterpriseRelatedId != null" >
#{wxEnterpriseRelatedId,jdbcType=VARCHAR},
</if>
<if test="wxEnterpriseId != null" >
#{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null" >
#{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="version != null" >
#{version,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
#{statusFlag,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
update tab_haoban_wx_enterprise_related
<set >
<if test="wxEnterpriseId != null" >
wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null" >
enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="version != null" >
version = #{version,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
status_flag = #{statusFlag,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
update tab_haoban_wx_enterprise_related
set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
version = #{version,jdbcType=VARCHAR},
status_flag = #{statusFlag,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</update>
<select id="listByWxenterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and status_flag = 1
</select>
<select id="findOneByEnterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
and status_flag = 1
</select>
<select id="queryAllHasGicEnterpriseId" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
</select>
<select id="listEnterpriseByEnterpriseIds" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
<if test="enterpriseIds != null and enterpriseIds.size() > 0">
and enterprise_id IN
<foreach collection="enterpriseIds" item="id" index="index" open="(" close=")" separator=",">
#{id,jdbcType=VARCHAR}
</foreach>
</if>
</select>
<select id="listEnterpriseByTime" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
AND AND DATE_FORMAT(update_time,'%Y-%m-%d') = #{time}
</select>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper" >
<resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
<id column="wx_enterprise_related_id" property="wxEnterpriseRelatedId" jdbcType="VARCHAR" />
<result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR" />
<result column="enterprise_id" property="enterpriseId" jdbcType="VARCHAR" />
<result column="version" property="version" jdbcType="VARCHAR" />
<result column="status_flag" property="statusFlag" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
wx_enterprise_related_id, wx_enterprise_id, enterprise_id, version, status_flag,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from tab_haoban_wx_enterprise_related
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
insert into tab_haoban_wx_enterprise_related (wx_enterprise_related_id, wx_enterprise_id,
enterprise_id, version, status_flag,
create_time, update_time)
values (#{wxEnterpriseRelatedId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
#{enterpriseId,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
insert into tab_haoban_wx_enterprise_related
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="wxEnterpriseRelatedId != null" >
wx_enterprise_related_id,
</if>
<if test="wxEnterpriseId != null" >
wx_enterprise_id,
</if>
<if test="enterpriseId != null" >
enterprise_id,
</if>
<if test="version != null" >
version,
</if>
<if test="statusFlag != null" >
status_flag,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="wxEnterpriseRelatedId != null" >
#{wxEnterpriseRelatedId,jdbcType=VARCHAR},
</if>
<if test="wxEnterpriseId != null" >
#{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null" >
#{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="version != null" >
#{version,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
#{statusFlag,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
update tab_haoban_wx_enterprise_related
<set >
<if test="wxEnterpriseId != null" >
wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null" >
enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="version != null" >
version = #{version,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
status_flag = #{statusFlag,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated" >
update tab_haoban_wx_enterprise_related
set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
version = #{version,jdbcType=VARCHAR},
status_flag = #{statusFlag,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
</update>
<select id="listByWxenterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and status_flag = 1
</select>
<select id="findOneByEnterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
and status_flag = 1
</select>
<select id="queryAllHasGicEnterpriseId" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
</select>
<select id="listEnterpriseByEnterpriseIds" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
<if test="enterpriseIds != null and enterpriseIds.size() > 0">
and enterprise_id IN
<foreach collection="enterpriseIds" item="id" index="index" open="(" close=")" separator=",">
#{id,jdbcType=VARCHAR}
</foreach>
</if>
</select>
<select id="listEnterpriseByTime" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise_related
where status_flag = 1
AND AND DATE_FORMAT(update_time,'%Y-%m-%d') = #{time}
</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