提交 ad2d92ec 编写于 作者: chenzhehao's avatar chenzhehao

微信消息处理流程修改

上级 cb6342c6
...@@ -7,4 +7,10 @@ import java.util.Map; ...@@ -7,4 +7,10 @@ import java.util.Map;
public interface PWechatUserMapper { public interface PWechatUserMapper {
PWechatUser queryByOpenId(Map map); PWechatUser queryByOpenId(Map map);
int insert(PWechatUser user);
int updateById(PWechatUser user);
int updateSubscribeById(PWechatUser user);
} }
\ No newline at end of file
...@@ -14,9 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,9 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author: zhehao.chen * @author: zhehao.chen
...@@ -73,27 +71,17 @@ public class CoreServiceImpl implements CoreService { ...@@ -73,27 +71,17 @@ public class CoreServiceImpl implements CoreService {
// 事件类型 // 事件类型
String eventType = requestMap.get("Event"); String eventType = requestMap.get("Event");
logger.info("eventType:" + eventType); logger.info("eventType:" + eventType);
//关注流程处理 //关注、取消关注流程处理
if (eventType.equals(Constants.EVENT_TYPE_SUBSCRIBE)) { if (eventType.equals(Constants.EVENT_TYPE_SUBSCRIBE) || eventType.equals(Constants.EVENT_TYPE_UNSUBSCRIBE)) {
//获得openId
String openId = fromUserName;
//调用微信的接口,获取微信用户的详细信息
Map map = userServiceClient.users(Constants.WECHAT_NAME_YQYL, openId);
logger.info(map.toString());
//1.首先处理p_wechat_user表,存在信息就补全,不存在就新增
// insertOrUpdataWechatDoctor(requestMap, map, userGet);
}
// 取消订阅
else if (eventType.equals(Constants.EVENT_TYPE_UNSUBSCRIBE)) {
String openId = fromUserName;//获得openId String openId = fromUserName;//获得openId
Map mapIn = new HashMap(); Map mapIn = new HashMap();
mapIn.put("type", 1);//1云鹊医联 mapIn.put("type", 1);//1云鹊医联
mapIn.put("openId", openId); mapIn.put("openId", openId);
PWechatUser userGet = wechatUserMapper.queryByOpenId(mapIn);//从wechat表中获取数据 PWechatUser userGet = wechatUserMapper.queryByOpenId(mapIn);//从wechat表中获取数据
Map map = userServiceClient.users(Constants.WECHAT_NAME_YQYL, openId); //调用微信的接口,获取微信用户的详细信息 Map map = userServiceClient.users(Constants.WECHAT_NAME_YQYL, openId); //调用微信的接口,获取微信用户的详细信息
logger.info(map.toString()); logger.info("调用微信接口获取用户信息:" + map.toString());
//1.首先处理p_wechat_user表,存在信息就补全,不存在就新增 //1.首先处理p_wechat_user表,存在信息就补全,不存在就新增
// insertOrUpdataWechatDoctor(requestMap, map, userGet); insertOrUpdataWechatUser(requestMap, (HashMap) map.get("data"), userGet);
} }
// 自定义菜单点击事件 // 自定义菜单点击事件
else if (eventType.equals(Constants.EVENT_TYPE_CLICK)) { else if (eventType.equals(Constants.EVENT_TYPE_CLICK)) {
...@@ -121,8 +109,55 @@ public class CoreServiceImpl implements CoreService { ...@@ -121,8 +109,55 @@ public class CoreServiceImpl implements CoreService {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("微信消息处理流程异常", e);
} }
return respMessage; return respMessage;
} }
private void insertOrUpdataWechatUser(Map<String, String> requestMap, Map map, PWechatUser wechatUser) {
String eventType = requestMap.get("Event");
if (eventType.equals(Constants.EVENT_TYPE_SUBSCRIBE)) {//关注
boolean newFlag = false;
if (StringUtil.isNull(wechatUser)) {//新增
wechatUser = new PWechatUser();
newFlag = true;
}
wechatUser.setOpenid((String) map.get("openid"));
wechatUser.setType(1);//1、云鹊医联
wechatUser.setSex((Integer) map.get("sex"));
wechatUser.setNickname((String) map.get("nickname"));
wechatUser.setProvince((String) map.get("province"));
wechatUser.setCity((String) map.get("city"));
wechatUser.setCountry((String) map.get("country"));
wechatUser.setHeadimgurl((String) map.get("headimgurl"));
wechatUser.setPrivilege((String) map.get("privilege"));
wechatUser.setUnionid((String) map.get("unionid"));
wechatUser.setSubscribe((Integer) map.get("subscribe"));
wechatUser.setLanguage((String) map.get("language"));
Integer subscribe_time = (Integer) map.get("subscribe_time");
logger.info(subscribe_time.toString());
wechatUser.setSubscribeTime(StringUtil.isNull(subscribe_time) ? new Date() : new Date(subscribe_time));
wechatUser.setRemark((String) map.get("remark"));
wechatUser.setGroupid(String.valueOf(map.get("groupid")));
List tagid_list = (ArrayList) map.get("tagid_list");
logger.info(StringUtil.isNull(tagid_list) ? "" : tagid_list.toString());
wechatUser.setTagidList(StringUtil.isNull(tagid_list) ? "" : tagid_list.toString());
wechatUser.setDeleteFlag(1);
wechatUser.setCreatId(0);
wechatUser.setModifyId(0);
if (newFlag) {//新增
wechatUserMapper.insert(wechatUser);
} else {//更新
wechatUserMapper.updateById(wechatUser);
}
} else if (eventType.equals(Constants.EVENT_TYPE_UNSUBSCRIBE)) {//取消关注
if (StringUtil.isNull(wechatUser)) {//新增
}
wechatUser.setSubscribe(0);
wechatUserMapper.updateSubscribeById(wechatUser);
}
}
} }
<?xml version="1.0" encoding="UTF-8" ?> <?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" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.pica.cloud.wechat.yunqueyilian.server.mapper.PWechatUserMapper" > <mapper namespace="com.pica.cloud.wechat.yunqueyilian.server.mapper.PWechatUserMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser" > <resultMap id="BaseResultMap" type="com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser">
<id column="id" property="id" jdbcType="INTEGER" /> <id column="id" property="id" jdbcType="INTEGER"/>
<result column="openid" property="openid" jdbcType="VARCHAR" /> <result column="openid" property="openid" jdbcType="VARCHAR"/>
<result column="patient_id" property="patientId" jdbcType="INTEGER" /> <result column="patient_id" property="patientId" jdbcType="INTEGER"/>
<result column="type" property="type" jdbcType="INTEGER" /> <result column="type" property="type" jdbcType="INTEGER"/>
<result column="sex" property="sex" jdbcType="INTEGER" /> <result column="sex" property="sex" jdbcType="INTEGER"/>
<result column="nickname" property="nickname" jdbcType="VARCHAR" /> <result column="nickname" property="nickname" jdbcType="VARCHAR"/>
<result column="province" property="province" jdbcType="VARCHAR" /> <result column="province" property="province" jdbcType="VARCHAR"/>
<result column="city" property="city" jdbcType="VARCHAR" /> <result column="city" property="city" jdbcType="VARCHAR"/>
<result column="country" property="country" jdbcType="VARCHAR" /> <result column="country" property="country" jdbcType="VARCHAR"/>
<result column="headimgurl" property="headimgurl" jdbcType="VARCHAR" /> <result column="headimgurl" property="headimgurl" jdbcType="VARCHAR"/>
<result column="privilege" property="privilege" jdbcType="VARCHAR" /> <result column="privilege" property="privilege" jdbcType="VARCHAR"/>
<result column="unionid" property="unionid" jdbcType="VARCHAR" /> <result column="unionid" property="unionid" jdbcType="VARCHAR"/>
<result column="subscribe" property="subscribe" jdbcType="INTEGER" /> <result column="subscribe" property="subscribe" jdbcType="INTEGER"/>
<result column="language" property="language" jdbcType="VARCHAR" /> <result column="language" property="language" jdbcType="VARCHAR"/>
<result column="subscribe_time" property="subscribeTime" jdbcType="TIMESTAMP" /> <result column="subscribe_time" property="subscribeTime" jdbcType="TIMESTAMP"/>
<result column="remark" property="remark" jdbcType="VARCHAR" /> <result column="remark" property="remark" jdbcType="VARCHAR"/>
<result column="groupid" property="groupid" jdbcType="VARCHAR" /> <result column="groupid" property="groupid" jdbcType="VARCHAR"/>
<result column="tagid_list" property="tagidList" jdbcType="VARCHAR" /> <result column="tagid_list" property="tagidList" jdbcType="VARCHAR"/>
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" /> <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
<result column="creat_id" property="creatId" jdbcType="INTEGER" /> <result column="creat_id" property="creatId" jdbcType="INTEGER"/>
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" /> <result column="creat_time" property="creatTime" jdbcType="TIMESTAMP"/>
<result column="modify_id" property="modifyId" jdbcType="INTEGER" /> <result column="modify_id" property="modifyId" jdbcType="INTEGER"/>
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" /> <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List">
id, openid, patient_id, type, sex, nickname, province, city, country, headimgurl, id, openid, patient_id, type, sex, nickname, province, city, country, headimgurl,
privilege, unionid, subscribe, language, subscribe_time, remark, groupid, tagid_list, privilege, unionid, subscribe, language, subscribe_time, remark, groupid, tagid_list,
delete_flag, creat_id, creat_time, modify_id, modify_time delete_flag, creat_id, creat_time, modify_id, modify_time
</sql> </sql>
<select id="queryByOpenId" resultMap="BaseResultMap" parameterMap="java.util.Map" > <insert id="insert" parameterType="com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser">
insert into p_wechat_user (openid, patient_id,
type, sex, nickname,
province, city, country,
headimgurl, privilege, unionid,
subscribe, language, subscribe_time,
remark, groupid, tagid_list,
delete_flag, creat_id, creat_time,
modify_id, modify_time)
values (#{openid,jdbcType=VARCHAR}, #{patientId,jdbcType=INTEGER},
#{type,jdbcType=INTEGER}, #{sex,jdbcType=INTEGER}, #{nickname,jdbcType=VARCHAR},
#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR},
#{headimgurl,jdbcType=VARCHAR}, #{privilege,jdbcType=VARCHAR}, #{unionid,jdbcType=VARCHAR},
#{subscribe,jdbcType=INTEGER}, #{language,jdbcType=VARCHAR}, #{subscribeTime,jdbcType=TIMESTAMP},
#{remark,jdbcType=VARCHAR}, #{groupid,jdbcType=VARCHAR}, #{tagidList,jdbcType=VARCHAR},
#{deleteFlag,jdbcType=INTEGER}, #{creatId,jdbcType=INTEGER}, SYSDATE(),
#{modifyId,jdbcType=INTEGER}, SYSDATE())
</insert>
<update id="updateById" parameterType="com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser">
update p_wechat_user
<set>
<if test="openid != null">
openid = #{openid,jdbcType=VARCHAR},
</if>
<if test="patientId != null">
patient_id = #{patientId,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="sex != null">
sex = #{sex,jdbcType=INTEGER},
</if>
<if test="nickname != null">
nickname = #{nickname,jdbcType=VARCHAR},
</if>
<if test="province != null">
province = #{province,jdbcType=VARCHAR},
</if>
<if test="city != null">
city = #{city,jdbcType=VARCHAR},
</if>
<if test="country != null">
country = #{country,jdbcType=VARCHAR},
</if>
<if test="headimgurl != null">
headimgurl = #{headimgurl,jdbcType=VARCHAR},
</if>
<if test="privilege != null">
privilege = #{privilege,jdbcType=VARCHAR},
</if>
<if test="unionid != null">
unionid = #{unionid,jdbcType=VARCHAR},
</if>
<if test="subscribe != null">
subscribe = #{subscribe,jdbcType=INTEGER},
</if>
<if test="language != null">
language = #{language,jdbcType=VARCHAR},
</if>
<if test="subscribeTime != null">
subscribe_time = #{subscribeTime,jdbcType=TIMESTAMP},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="groupid != null">
groupid = #{groupid,jdbcType=VARCHAR},
</if>
<if test="tagidList != null">
tagid_list = #{tagidList,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null">
delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if>
<if test="creatId != null">
creat_id = #{creatId,jdbcType=INTEGER},
</if>
<if test="creatTime != null">
creat_time = #{creatTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyId != null">
modify_id = #{modifyId,jdbcType=INTEGER},
</if>
<if test="modifyTime != null">
modify_time = #{modifyTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="queryByOpenId" resultMap="BaseResultMap" parameterType="java.util.Map">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from p_wechat_user from p_wechat_user
where type = #{type} and openid = #{openId} where type = #{type} and openid = #{openId}
</select> </select>
<update id="updateSubscribeById" parameterType="com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser">
update p_wechat_user set subscribe = #{subscribe} where id = #{id,jdbcType=INTEGER}
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册