Merge branch 'wx-dev' into dev

# Conflicts:
#	src/main/java/com/rymcu/vertical/wx/mp/controller/WxMenuController.java
#	src/main/java/com/rymcu/vertical/wx/mp/controller/WxoAuthController.java
This commit is contained in:
ronger 2020-06-08 11:32:51 +08:00
commit 913f884cbc
5 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package com.rymcu.vertical.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author ronger
*/
@Data
@Table(name = "vertical_wx_user")
public class WxUser {
@Id
@Column(name = "id")
@GeneratedValue(generator = "JDBC")
private Integer idWxUser;
private Boolean subscribe;
private String openId;
private String nickname;
private String sexDesc;
private Integer sex;
private String language;
private String city;
private String province;
private String country;
private String headImgUrl;
private Long subscribeTime;
private String unionId;
private String appId;
private String actToken;
}

View File

@ -0,0 +1,10 @@
package com.rymcu.vertical.mapper;
import com.rymcu.vertical.core.mapper.Mapper;
import com.rymcu.vertical.entity.WxUser;
/**
* @author ronger
*/
public interface WxUserMapper extends Mapper<WxUser> {
}

View File

@ -0,0 +1,14 @@
package com.rymcu.vertical.service;
import com.rymcu.vertical.core.service.Service;
import com.rymcu.vertical.entity.WxUser;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
/**
* @author ronger
*/
public interface WxUserService extends Service<WxUser> {
WxUser saveUser(WxMpUser wxMpUser, String appId);
}

View File

@ -0,0 +1,62 @@
package com.rymcu.vertical.service.impl;
import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.entity.WxUser;
import com.rymcu.vertical.mapper.WxUserMapper;
import com.rymcu.vertical.service.WxUserService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author ronger
*/
@Service
public class WxUserServiceImpl extends AbstractService<WxUser> implements WxUserService {
@Resource
private WxUserMapper wxUserMapper;
@Override
public WxUser saveUser(WxMpUser wxMpUser, String appId) {
WxUser searchWxUser = new WxUser();
if (StringUtils.isBlank(wxMpUser.getUnionId())) {
searchWxUser.setUnionId(wxMpUser.getUnionId());
} else {
searchWxUser.setAppId(appId);
searchWxUser.setOpenId(searchWxUser.getOpenId());
}
List<WxUser> wxUsers = wxUserMapper.select(searchWxUser);
WxUser wxUser;
if (wxUsers.isEmpty()) {
wxUser = new WxUser();
wxUser.setAppId(appId);
wxUser = copyWxUser(wxMpUser,wxUser);
wxUserMapper.insertSelective(wxUser);
} else {
wxUser = wxUsers.get(0);
wxUser = copyWxUser(wxMpUser,wxUser);
wxUserMapper.updateByPrimaryKeySelective(wxUser);
}
return wxUser;
}
private WxUser copyWxUser(WxMpUser wxMpUser, WxUser wxUser) {
wxUser.setNickname(wxMpUser.getNickname());
wxUser.setHeadImgUrl(wxMpUser.getHeadImgUrl());
wxUser.setCountry(wxMpUser.getCountry());
wxUser.setProvince(wxMpUser.getProvince());
wxUser.setCity(wxMpUser.getCity());
wxUser.setSex(wxMpUser.getSex());
wxUser.setSubscribe(wxMpUser.getSubscribe());
wxUser.setSubscribeTime(wxMpUser.getSubscribeTime());
wxUser.setUnionId(wxMpUser.getUnionId());
wxUser.setOpenId(wxMpUser.getOpenId());
wxUser.setLanguage(wxMpUser.getLanguage());
wxUser.setSexDesc(wxMpUser.getSexDesc());
return wxUser;
}
}

View File

@ -0,0 +1,21 @@
<?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.rymcu.vertical.mapper.WxUserMapper">
<resultMap id="BaseResultMap" type="com.rymcu.vertical.entity.WxUser">
<id column="id" property="idWxUser"></id>
<result column="nickname" property="nickname"></result>
<result column="nickname" property="unionId"></result>
<result column="nickname" property="appId"></result>
<result column="nickname" property="openId"></result>
<result column="nickname" property="sex"></result>
<result column="nickname" property="sexDesc"></result>
<result column="nickname" property="headImgUrl"></result>
<result column="nickname" property="country"></result>
<result column="nickname" property="province"></result>
<result column="nickname" property="city"></result>
<result column="nickname" property="actToken"></result>
<result column="nickname" property="subscribe"></result>
<result column="nickname" property="subscribeTime"></result>
<result column="nickname" property="language"></result>
</resultMap>
</mapper>