|
|
@ -34,12 +34,15 @@ import com.epmet.dto.PaCustomerDTO; |
|
|
|
import com.epmet.dto.PaUserDTO; |
|
|
|
import com.epmet.dto.PaUserVisitedDTO; |
|
|
|
import com.epmet.dto.PaUserWechatDTO; |
|
|
|
import com.epmet.dto.form.SaveUserVisitedFormDTO; |
|
|
|
import com.epmet.dto.form.WxCodeToTokenFormDTO; |
|
|
|
import com.epmet.dto.result.CustomerUserResultDTO; |
|
|
|
import com.epmet.dto.result.SaveUserResultDTO; |
|
|
|
import com.epmet.entity.PaUserEntity; |
|
|
|
import com.epmet.entity.PaUserWechatEntity; |
|
|
|
import com.epmet.redis.PaUserRedis; |
|
|
|
import com.epmet.service.PaUserService; |
|
|
|
import com.epmet.service.PaUserVisitedService; |
|
|
|
import com.epmet.service.PaUserWechatService; |
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -72,6 +75,8 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity> |
|
|
|
private PaUserWechatDao paUserWechatDao; |
|
|
|
@Autowired |
|
|
|
private PaUserVisitedDao paUserVisitedDao; |
|
|
|
@Autowired |
|
|
|
private PaUserVisitedService paUserVisitedService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<PaUserDTO> page(Map<String, Object> params) { |
|
|
@ -126,22 +131,24 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity> |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param wxMpUser |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 根据openId新增或更新用户信息 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public SaveUserResultDTO saveUser(WxMpUser wxMpUser) { |
|
|
|
public SaveUserResultDTO saveUser(WxCodeToTokenFormDTO formDTO) { |
|
|
|
WxMpUser wxMpUser = formDTO.getWxMpUser(); |
|
|
|
SaveUserResultDTO resultDTO = new SaveUserResultDTO(); |
|
|
|
//1.根据openId查询user_wechat表是否存在用户信息(user表和user_wechat表数据时多对多关系)
|
|
|
|
List<PaUserWechatDTO> wechatDTO = paUserWechatService.getWechatByOpenId(wxMpUser.getOpenId()); |
|
|
|
//1.根据openId查询user_wechat表是否存在用户信息(user表和user_wechat表数据是多对多关系)
|
|
|
|
List<PaUserWechatDTO> wechatDTO = paUserWechatService.getWechatByOpenId(wxMpUser.getOpenId(), formDTO.getSource()); |
|
|
|
|
|
|
|
//2.不存在则新增用户信息,存在则更新user_wechat表信息
|
|
|
|
if (null == wechatDTO || wechatDTO.size() < NumConstant.ONE) { |
|
|
|
//2.1、user表新增数据
|
|
|
|
PaUserEntity userEntity = new PaUserEntity(); |
|
|
|
userEntity.setSource(formDTO.getSource()); |
|
|
|
baseDao.insert(userEntity); |
|
|
|
//2.2、user_wechat表新增数据
|
|
|
|
PaUserWechatEntity wechatEntity = new PaUserWechatEntity(); |
|
|
@ -157,9 +164,16 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity> |
|
|
|
wechatEntity.setLanguage(null == wxMpUser.getLanguage() ? "" : wxMpUser.getLanguage()); |
|
|
|
paUserWechatService.insert(wechatEntity); |
|
|
|
|
|
|
|
//2.3、pa_user_visited表新增访问记录数据
|
|
|
|
SaveUserVisitedFormDTO visited = new SaveUserVisitedFormDTO(); |
|
|
|
visited.setUserId(userEntity.getId()); |
|
|
|
visited.setLogonUserId(userEntity.getId()); |
|
|
|
visited.setSource(formDTO.getSource()); |
|
|
|
paUserVisitedService.saveUserVisited(visited); |
|
|
|
|
|
|
|
resultDTO.setUserId(userEntity.getId()); |
|
|
|
} else { |
|
|
|
//2.3、批量更新user_wechat表数据
|
|
|
|
//2.4、批量更新user_wechat表数据
|
|
|
|
List<PaUserWechatEntity> wechatEntity = ConvertUtils.sourceToTarget(wechatDTO, PaUserWechatEntity.class); |
|
|
|
for(PaUserWechatEntity entity : wechatEntity){ |
|
|
|
entity.setGender(wxMpUser.getSex().toString()); |
|
|
@ -172,8 +186,8 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity> |
|
|
|
} |
|
|
|
paUserWechatService.updateBatchById(wechatEntity); |
|
|
|
|
|
|
|
//2.4、根据openid查询用户登陆访问记录表数据,按登陆时间倒序
|
|
|
|
PaUserVisitedDTO visitedDTO = paUserVisitedDao.selectByOpenId(wxMpUser.getOpenId()); |
|
|
|
//2.5、根据openid查询用户登陆访问记录表数据,按登陆时间倒序
|
|
|
|
PaUserVisitedDTO visitedDTO = paUserVisitedDao.selectByOpenId(wxMpUser.getOpenId(), formDTO.getSource()); |
|
|
|
if (null == visitedDTO || "".equals(visitedDTO.getUserId())) { |
|
|
|
logger.error("根据openid查询用户访问记录表数据失败,openid->"+wxMpUser.getOpenId()); |
|
|
|
throw new RenException(PaConstant.SELECT_VISITED_EXCEPTION); |
|
|
|