|
@@ -0,0 +1,214 @@
|
|
|
+package com.tzld.piaoquan.risk.control.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.annotation.JSONField;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.tzld.piaoquan.risk.control.dao.mapper.UserBaseMapper;
|
|
|
+import com.tzld.piaoquan.risk.control.dao.mapper.UserCorpMapper;
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.UserBase;
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.UserBaseExample;
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.UserCorp;
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.UserCorpExample;
|
|
|
+import com.tzld.piaoquan.risk.control.model.qywx.QwCallBackWrapperData;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class QywxUserDataService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserBaseMapper userBaseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserCorpMapper userCorpMapper;
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @NoArgsConstructor
|
|
|
+ private static class UserData {
|
|
|
+ // 企业信息
|
|
|
+ @JSONField(name = "Corpid")
|
|
|
+ private Long corpId;
|
|
|
+
|
|
|
+ @JSONField(name = "corp_id")
|
|
|
+ private Long corpId2;
|
|
|
+
|
|
|
+ @JSONField(name = "Corp_name")
|
|
|
+ private String corpName;
|
|
|
+
|
|
|
+ @JSONField(name = "Corp_full_name")
|
|
|
+ private String corpFullName;
|
|
|
+
|
|
|
+ @JSONField(name = "Corp_logo")
|
|
|
+ private String corpLogo;
|
|
|
+
|
|
|
+ @JSONField(name = "Corp_desc")
|
|
|
+ private String corpDesc;
|
|
|
+
|
|
|
+ @JSONField(name = "scorp_id")
|
|
|
+ private String sCorpId;
|
|
|
+
|
|
|
+ // 用户基础信息
|
|
|
+ @JSONField(name = "unionid")
|
|
|
+ private String unionId;
|
|
|
+
|
|
|
+ @JSONField(name = "Admin_vid")
|
|
|
+ private Long adminVid;
|
|
|
+
|
|
|
+ @JSONField(name = "acctid")
|
|
|
+ private String accountId;
|
|
|
+
|
|
|
+ @JSONField(name = "english_name")
|
|
|
+ private String englishName;
|
|
|
+
|
|
|
+ @JSONField(name = "Ownername")
|
|
|
+ private String ownerName;
|
|
|
+
|
|
|
+ @JSONField(name = "nickname")
|
|
|
+ private String nickName;
|
|
|
+
|
|
|
+ @JSONField(name = "create_time")
|
|
|
+ private Long createTime1;
|
|
|
+
|
|
|
+ @JSONField(name = "Create_time")
|
|
|
+ private Long createTime2;
|
|
|
+
|
|
|
+ @JSONField(name = "sex")
|
|
|
+ private Integer gender;
|
|
|
+
|
|
|
+ @JSONField(name = "mobile")
|
|
|
+ private String mobile;
|
|
|
+
|
|
|
+ @JSONField(name = "avatar")
|
|
|
+ private String avatarUrl;
|
|
|
+
|
|
|
+ @JSONField(name = "realname")
|
|
|
+ private String realName;
|
|
|
+
|
|
|
+ @JSONField(name = "Vid")
|
|
|
+ private Long vid;
|
|
|
+
|
|
|
+ @JSONField(name = "Mail")
|
|
|
+ private String email;
|
|
|
+
|
|
|
+ @JSONField(name = "user_id")
|
|
|
+ private Long userId;
|
|
|
+
|
|
|
+ @JSONField(name = "position")
|
|
|
+ private String jobPosition;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void processUserData(String originalJson) {
|
|
|
+ // 1. 解析外层数据
|
|
|
+ QwCallBackWrapperData wrapperData = JSON.parseObject(originalJson, QwCallBackWrapperData.class);
|
|
|
+ if (StringUtils.isEmpty(wrapperData.getJson())) {
|
|
|
+ log.warn("Empty inner json data, uuid: {}", wrapperData.getUuid());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 解析内层用户数据
|
|
|
+ UserData userData = JSON.parseObject(wrapperData.getJson(), UserData.class);
|
|
|
+
|
|
|
+ // 3. 处理用户基础信息
|
|
|
+ UserBase userBase = processBaseInfo(wrapperData, userData);
|
|
|
+
|
|
|
+ // 4. 处理企业关联信息
|
|
|
+ try {
|
|
|
+ processCorpRelation(Long.parseLong(userBase.getVid()), userData);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Error processing user data: {}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private UserBase processBaseInfo(QwCallBackWrapperData envelop, UserData data) {
|
|
|
+ UserBase userBase = new UserBase();
|
|
|
+ userBase.setUuid(envelop.getUuid());
|
|
|
+ userBase.setMobile(data.mobile);
|
|
|
+ userBase.setRealname(data.realName);
|
|
|
+ userBase.setAvatar(data.avatarUrl);
|
|
|
+ userBase.setLoginStatus(0);
|
|
|
+ userBase.setVid(data.vid.toString());
|
|
|
+ userBase.setUpdateTime(new Date());
|
|
|
+
|
|
|
+
|
|
|
+ // 时间处理(优先使用Create_time)
|
|
|
+ Long createTime = data.createTime2 != null && data.createTime2 > 0 ? data.createTime2 : data.createTime1;
|
|
|
+ if (createTime != null && createTime > 0) {
|
|
|
+ userBase.setCreateTime(new Date(createTime * 1000));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询是否已存在
|
|
|
+ UserBaseExample example = new UserBaseExample();
|
|
|
+ example.createCriteria().andUuidEqualTo(envelop.getUuid());
|
|
|
+ List<UserBase> existUsers = userBaseMapper.selectByExample(example);
|
|
|
+
|
|
|
+ if (!existUsers.isEmpty()) {
|
|
|
+ UserBase existUser = existUsers.get(0);
|
|
|
+ userBase.setId(existUser.getId());
|
|
|
+ userBase.setCreateTime(existUser.getCreateTime());
|
|
|
+ userBaseMapper.updateByPrimaryKeySelective(userBase);
|
|
|
+ } else {
|
|
|
+ userBaseMapper.insertSelective(userBase);
|
|
|
+ }
|
|
|
+ return userBase;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processCorpRelation(Long userId, UserData data) {
|
|
|
+ UserCorp userCorp = new UserCorp();
|
|
|
+ userCorp.setUserId(userId);
|
|
|
+ userCorp.setCorpId(data.corpId != null ? data.corpId : data.corpId2);
|
|
|
+// userCorp.setAdminVid(data.adminVid);
|
|
|
+ userCorp.setUnionid(data.unionId);
|
|
|
+// userCorp.setAccountId(data.accountId);
|
|
|
+ userCorp.setPosition(data.jobPosition);
|
|
|
+// userCorp.setStatus((byte) 0);
|
|
|
+ userCorp.setUpdateTime(new Date());
|
|
|
+ userCorp.setCorpName(data.corpName);
|
|
|
+// userCorp.setCorpFullName(data.corpFullName);
|
|
|
+// userCorp.setCorpLogo(data.corpLogo);
|
|
|
+// userCorp.setCorpDesc(data.corpDesc);
|
|
|
+// userCorp.setSCorpId(data.sCorpId);
|
|
|
+// userCorp.setOwnerName(data.ownerName);
|
|
|
+ userCorp.setEnglishName(data.englishName);
|
|
|
+ userCorp.setUpdateTime(new Date());
|
|
|
+// userCorp.setVid(data.vid);
|
|
|
+
|
|
|
+ UserCorpExample example = new UserCorpExample();
|
|
|
+ example.createCriteria()
|
|
|
+ .andUserIdEqualTo(userId)
|
|
|
+ .andCorpIdEqualTo(userCorp.getCorpId());
|
|
|
+
|
|
|
+ List<UserCorp> existRelations = userCorpMapper.selectByExample(example);
|
|
|
+
|
|
|
+ if (!existRelations.isEmpty()) {
|
|
|
+ UserCorp existRelation = existRelations.get(0);
|
|
|
+ userCorp.setId(existRelation.getId());
|
|
|
+ userCorpMapper.updateByPrimaryKeySelective(userCorp);
|
|
|
+ } else {
|
|
|
+ userCorpMapper.insertSelective(userCorp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据手机号查询用户
|
|
|
+ public UserBase getUserByMobile(String mobile) {
|
|
|
+ UserBaseExample example = new UserBaseExample();
|
|
|
+ example.createCriteria().andMobileEqualTo(mobile);
|
|
|
+ List<UserBase> users = userBaseMapper.selectByExample(example);
|
|
|
+ return users.isEmpty() ? null : users.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页查询用户列表
|
|
|
+ public List<UserBase> listUsers(int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ return userBaseMapper.selectByExample(new UserBaseExample());
|
|
|
+ }
|
|
|
+}
|