+
+
+ UPDATE epdc_points_logs
+ SET FACE_IMG = #{faceImg},
+ USER_ID = #{newUserId}
+ WHERE
+ id = #{oldUserId}
+
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/CachingUserInfoDTO.java b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/CachingUserInfoDTO.java
index 896b623b..f5b48815 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/CachingUserInfoDTO.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/CachingUserInfoDTO.java
@@ -74,4 +74,15 @@ public class CachingUserInfoDTO {
*/
private String remark;
+ /**
+ * 积分
+ */
+ private Integer points;
+ /**
+ * 积分
+ */
+ private Integer pointsTotle;
+
+
+
}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/PointsLogsBindUnIdDTO.java b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/PointsLogsBindUnIdDTO.java
new file mode 100644
index 00000000..b8152a48
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/PointsLogsBindUnIdDTO.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+/**
+ * 修改过时积分日志
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-04-29
+ */
+@Data
+public class PointsLogsBindUnIdDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 用户ID
+ */
+ private String userId;
+
+ /**
+ * 新用户
+ */
+ private UserDTO user;
+
+}
\ No newline at end of file
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcUserRegistFormDTO.java b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcUserRegistFormDTO.java
index 97280424..0886d608 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcUserRegistFormDTO.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcUserRegistFormDTO.java
@@ -63,4 +63,10 @@ public class EpdcUserRegistFormDTO implements Serializable {
*/
@NotBlank(message = "微信code不能为空")
private String wxCode;
+
+
+ /**
+ * 小程序类型
+ */
+ private String type;
}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/UserGridRelationDao.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/UserGridRelationDao.java
index fe088b38..c78a6e76 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/UserGridRelationDao.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/UserGridRelationDao.java
@@ -21,6 +21,7 @@ import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import com.elink.esua.epdc.dto.UserGridRelationDTO;
import com.elink.esua.epdc.entity.UserGridRelationEntity;
import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -83,4 +84,20 @@ public interface UserGridRelationDao extends BaseDao {
* @return com.elink.esua.epdc.dto.UserGridRelationDTO
**/
UserGridRelationDTO getUserFirstScanGrid(String userId);
+ /**
+ * @Description 把小程序用户的userID全部替换为UidUser的ID
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [openUserId, unionUserId]
+ * @return void
+ **/
+ void maBindUnId(@Param("openUserId") String openUserId, @Param("unionUserId") String unionUserId);
+ /**
+ * @Description 查询重复的网格关系数据
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [userId]
+ * @return java.util.List
+ **/
+ List selectRepeatRelation(String userId);
}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/PointsFeignClient.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/PointsFeignClient.java
new file mode 100644
index 00000000..fecae047
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/PointsFeignClient.java
@@ -0,0 +1,32 @@
+package com.elink.esua.epdc.feign;
+
+import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
+import com.elink.esua.epdc.commons.tools.utils.Result;
+import com.elink.esua.epdc.dto.PointsLogsBindUnIdDTO;
+import com.elink.esua.epdc.feign.fallback.NewsFeignClientFallback;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * 积分管理模块
+ *
+ * @author work@yujt.net.cn
+ * @date 2019/9/18 15:37
+ */
+@FeignClient(name = ServiceConstant.EPDC_POINTS_SERVER, fallback = NewsFeignClientFallback.class)
+public interface PointsFeignClient {
+
+ /**
+ * 更新积分日志
+ *
+ * @param formDto
+ * @return com.elink.esua.epdc.commons.tools.utils.Result
+ * @author zhy
+ * @date 2020/8/12 15:55
+ */
+ @PostMapping(value = "points/pointslogs/maBindUnIdLogs", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ Result maBindUnIdLogs(@RequestBody PointsLogsBindUnIdDTO formDto);
+
+}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/fallback/PointsFeignClientFallback.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/fallback/PointsFeignClientFallback.java
new file mode 100644
index 00000000..810a32dd
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/feign/fallback/PointsFeignClientFallback.java
@@ -0,0 +1,21 @@
+package com.elink.esua.epdc.feign.fallback;
+
+import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
+import com.elink.esua.epdc.commons.tools.utils.ModuleUtils;
+import com.elink.esua.epdc.commons.tools.utils.Result;
+import com.elink.esua.epdc.dto.PointsLogsBindUnIdDTO;
+import com.elink.esua.epdc.feign.PointsFeignClient;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author work@yujt.net.cn
+ * @date 2019/9/18 15:38
+ */
+@Component
+public class PointsFeignClientFallback implements PointsFeignClient {
+
+ @Override
+ public Result maBindUnIdLogs(PointsLogsBindUnIdDTO formDto) {
+ return ModuleUtils.feignConError(ServiceConstant.EPDC_POINTS_SERVER, "maBindUnIdLogs", formDto);
+ }
+}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/UserGridRelationService.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/UserGridRelationService.java
index 92ca056e..ba6a16d5 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/UserGridRelationService.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/UserGridRelationService.java
@@ -205,4 +205,20 @@ public interface UserGridRelationService extends BaseService
+ **/
+ List selectRepeatRelation(String userId);
}
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserGridRelationServiceImpl.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserGridRelationServiceImpl.java
index 8b54239d..c98486bc 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserGridRelationServiceImpl.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserGridRelationServiceImpl.java
@@ -21,11 +21,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
+import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.redis.RedisKeys;
import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
-import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.constant.UserFieldConsant;
import com.elink.esua.epdc.dao.UserGridRelationDao;
@@ -243,6 +243,16 @@ public class UserGridRelationServiceImpl extends BaseServiceImpl selectRepeatRelation(String userId) {
+ return baseDao.selectRepeatRelation(userId);
+ }
+
/**
*
* 组织机构信息处理
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserServiceImpl.java b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserServiceImpl.java
index 3bac1324..72c7689a 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserServiceImpl.java
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/UserServiceImpl.java
@@ -38,28 +38,19 @@ import com.elink.esua.epdc.commons.tools.utils.MessageUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.constant.AuthenticatedConsant;
import com.elink.esua.epdc.constant.UserFieldConsant;
-import com.elink.esua.epdc.dao.PartyAuthenticationFailedDao;
-import com.elink.esua.epdc.dao.PartyMembersDao;
-import com.elink.esua.epdc.dao.UserAuthenticateHistoryDao;
-import com.elink.esua.epdc.dao.UserDao;
+import com.elink.esua.epdc.dao.*;
import com.elink.esua.epdc.dto.*;
-import com.elink.esua.epdc.dto.epdc.form.EpdcUserGroupInviteFormDTO;
-import com.elink.esua.epdc.dto.epdc.form.EpdcUserRegistFormDTO;
-import com.elink.esua.epdc.dto.epdc.result.*;
import com.elink.esua.epdc.dto.epdc.EpdcCompleteAppUserDTO;
import com.elink.esua.epdc.dto.epdc.EpdcGridLeaderRegisterDTO;
import com.elink.esua.epdc.dto.epdc.form.*;
-import com.elink.esua.epdc.dto.epdc.result.EpdcResidentDetailResultDTO;
-import com.elink.esua.epdc.dto.epdc.result.EpdcUserRegisterInfoResultDTO;
+import com.elink.esua.epdc.dto.epdc.result.*;
import com.elink.esua.epdc.entity.*;
-import com.elink.esua.epdc.dto.epdc.result.EpdcUserInfoResultDTO;
-import com.elink.esua.epdc.dto.epdc.result.EpdcUserRegisterAuditMsgResultDTO;
-import com.elink.esua.epdc.dto.epdc.result.EpdcWorkUserResultDTO;
import com.elink.esua.epdc.enums.AppUserAuditStateEnum;
import com.elink.esua.epdc.enums.AppUserStatesEnum;
import com.elink.esua.epdc.enums.PartyMemberRegFlagEnum;
import com.elink.esua.epdc.exception.UserModuleErrorCode;
import com.elink.esua.epdc.feign.AdminFeignClient;
+import com.elink.esua.epdc.feign.PointsFeignClient;
import com.elink.esua.epdc.rocketmq.dto.OrganizationModifyDTO;
import com.elink.esua.epdc.service.UserGridRelationService;
import com.elink.esua.epdc.service.UserInvitationRecordService;
@@ -100,6 +91,8 @@ public class UserServiceImpl extends BaseServiceImpl implem
private PartyAuthenticationFailedDao partyAuthenticationFailedDao;
@Autowired
private UserTagRelationService userTagRelationService;
+ @Autowired
+ private PointsFeignClient pointsFeignClient;
@Override
public PageData page(Map params) {
@@ -1024,16 +1017,98 @@ public class UserServiceImpl extends BaseServiceImpl implem
if (StringUtils.isBlank(formDTO.getOpenId())) {
throw new RenException("openId不能为空");
}
- CachingUserInfoDTO cachingUserInfoDTO = null;
- if (StringUtils.isNotBlank(formDTO.getUnionId())) {
- //根据unionId查询
- cachingUserInfoDTO = this.baseDao.selectCachingUserInfoDTO(null, formDTO.getUnionId());
- }
- if (null == cachingUserInfoDTO) {
- //根据openId查询
- cachingUserInfoDTO = this.baseDao.selectCachingUserInfoDTO(formDTO.getOpenId(), null);
+ //接口匹配志愿者小程序 - start
+ CachingUserInfoDTO uIdUser = this.baseDao.selectCachingUserInfoDTO(null, formDTO.getUnionId());
+ CachingUserInfoDTO oIdUser = this.baseDao.selectCachingUserInfoDTO(formDTO.getOpenId(), null);
+ if(uIdUser != null && oIdUser == null){
+ return new Result().ok(uIdUser);
+ }
+ //更新oIdUser的unionId
+ if(uIdUser == null && oIdUser != null){
+ UserEntity userEntity = new UserEntity();
+ userEntity.setId(oIdUser.getUserId());
+ userEntity.setWxUnionId(formDTO.getUnionId());
+ baseDao.updateById(userEntity);
+ return new Result().ok(oIdUser);
+ }
+ //合并用户
+ if(oIdUser != null && uIdUser != null){
+ //如果相同,则查出的用户为同一个
+ if(uIdUser.getUserId().equals(oIdUser.getUserId())){
+ return new Result().ok(oIdUser);
+ }
+ this.combineUsers(oIdUser,uIdUser,formDTO.getOpenId());
}
- return new Result().ok(cachingUserInfoDTO);
+ return new Result().ok(uIdUser);
+ }
+ /**
+ * @Description 合并用户
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [oIdUser, uIdUser]
+ * @return void
+ **/
+ private void combineUsers(CachingUserInfoDTO oIdUser, CachingUserInfoDTO uIdUser, String openId) {
+ // 处理user表积分,删除小程序用户
+ updateUserInfo(oIdUser, uIdUser,openId);
+ // 处理网格关系表
+ updateUerGridRelation(oIdUser, uIdUser);
+ // 处理积分日志
+ updatePointLogs(oIdUser, uIdUser);
+ }
+ /**
+ * @Description 处理积分日志
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [oIdUser, uIdUser]
+ * @return void
+ **/
+ private void updatePointLogs(CachingUserInfoDTO oIdUser, CachingUserInfoDTO uIdUser) {
+ // 把原有积分日志中的userid替换为新的userid,同时更新其中的用户信息
+ PointsLogsBindUnIdDTO pointsLogsBindAppDTO = new PointsLogsBindUnIdDTO();
+ UserDTO userDTO = ConvertUtils.sourceToTarget(uIdUser, UserDTO.class);
+ pointsLogsBindAppDTO.setUserId(oIdUser.getUserId());
+ pointsLogsBindAppDTO.setUser(userDTO);
+ pointsFeignClient.maBindUnIdLogs(pointsLogsBindAppDTO);
+ }
+
+ /**
+ * @Description 处理网格关系表
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [oIdUser, uIdUser]
+ * @return void
+ **/
+ private void updateUerGridRelation(CachingUserInfoDTO oIdUser, CachingUserInfoDTO uIdUser) {
+ // 把小程序用户的userID全部替换为UidUser的ID
+ userGridRelationService.maBindUnId(oIdUser.getUserId(), uIdUser.getUserId());
+ // 修改完成后查询重复的网格关系数据,把重复并且createTime比较新的数据删除
+ List repeatUser = userGridRelationService.selectRepeatRelation(uIdUser.getUserId());
+ userGridRelationService.deleteBatchIds(repeatUser);
+ }
+
+ /**
+ * @Description 处理user表积分,删除小程序用户
+ * @Author songyunpeng
+ * @Date 2021/4/8
+ * @Param [oIdUser, uIdUser]
+ * @return void
+ **/
+ private void updateUserInfo(CachingUserInfoDTO oIdUser, CachingUserInfoDTO uIdUser, String openId) {
+ // 求出两个账户的积分和
+ Integer pointSum = oIdUser.getPoints() + uIdUser.getPoints();
+ Integer pointsTotleSum = oIdUser.getPointsTotle() + uIdUser.getPointsTotle();
+
+ UserEntity updateUser = new UserEntity();
+ updateUser.setId(uIdUser.getUserId());
+ updateUser.setPoints(pointSum);
+ updateUser.setPointsTotle(pointsTotleSum);
+ updateUser.setWxOpenId(openId);
+ // 更新app账户的积分信息
+ baseDao.updateById(updateUser);
+
+ // 删除当前小程序用户
+ baseDao.deleteById(oIdUser.getUserId());
}
@Override
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserDao.xml b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserDao.xml
index 281ece22..4bccf4cf 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserDao.xml
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserDao.xml
@@ -460,6 +460,8 @@
+
+
@@ -511,6 +513,8 @@
eu.STATE,
eu.REMARK,
eu.PARTY_FLAG,
+ eu.POINTS,
+ eu.POINTS_TOTLE,
(select r.GRID_ID
from epdc_user_grid_relation r
where r.USER_ID=eu.ID
diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserGridRelationDao.xml b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserGridRelationDao.xml
index eed9ff01..100c296d 100644
--- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserGridRelationDao.xml
+++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/UserGridRelationDao.xml
@@ -32,6 +32,9 @@
UPDATE epdc_user_grid_relation SET GRID = #{newDeptName}, UPDATED_TIME = NOW() WHERE GRID_ID = #{deptId}
+
+ UPDATE epdc_user_grid_relation SET USER_ID = #{unionUserId}, UPDATED_TIME = NOW() WHERE USER_ID = #{openUserId}
+
SELECT
@@ -60,6 +63,25 @@
CREATED_TIME
LIMIT 1
+
+ SELECT
+ t.ID
+ FROM
+ (
+ SELECT
+ ID,GRID_ID,USER_ID
+ FROM
+ epdc_user_grid_relation
+ WHERE
+ USER_ID = #{userId}
+ ORDER BY
+ CREATED_TIME DESC
+ ) t
+ GROUP BY
+ t.GRID_ID
+ HAVING
+ COUNT(t.USER_ID) > 1
+