fwq
2024-01-16 4133e14d7904ee2c1458e8a103de052584459efe
合并用户优化
2个文件已添加
1个文件已修改
167 ■■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/dao/mapper/UserMergeCommonMapper.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/resources/mapper/UserMergeCommonMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/user/impl/UserMergeLogServiceImpl.java 138 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/dao/mapper/UserMergeCommonMapper.java
New file
@@ -0,0 +1,13 @@
package com.hx.phip.dao.mapper;
import com.hx.mybatisTool.SqlSentence;
import java.util.List;
import java.util.Map;
public interface UserMergeCommonMapper {
    /**查询列表,返回Map的List*/
    List<Map<String,Object>> selectListMap(SqlSentence sqlSentence);
    /**更新,返回更新数量*/
    int updateWhere(SqlSentence sqlSentence);
}
phi_platform_common/src/main/resources/mapper/UserMergeCommonMapper.xml
New file
@@ -0,0 +1,16 @@
<?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">
<!-- namespace:该mapper.xml映射文件的 唯一标识 -->
<mapper namespace="com.hx.phip.dao.mapper.UserMergeCommonMapper">
    <select id="selectListMap" resultType="java.util.Map" parameterType="com.hx.mybatisTool.SqlSentence" >
            ${sqlSentence}
    </select>
    <update id="updateWhere" parameterType="com.hx.mybatisTool.SqlSentence">
        ${sqlSentence}
    </update>
</mapper>
phi_platform_user/src/main/java/com/hx/phip/service/user/impl/UserMergeLogServiceImpl.java
@@ -5,8 +5,10 @@
import com.hx.guide.model.VLatelyLog;
import com.hx.guide.model.VisitOrder;
import com.hx.guide.model.VisitRecord;
import com.hx.mybatis.aes.springbean.ConstantBean;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.OperationReasonConstants;
import com.hx.phiappt.dto.MerUserFileDto;
import com.hx.phiappt.model.*;
import com.hx.phiappt.model.aliyun.call.AliyunSecretCallRecord;
import com.hx.phiappt.model.appearancePlan.AppearanceTotal;
@@ -39,6 +41,7 @@
import com.hx.phiappt.model.user.*;
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
import com.hx.phiappt.model.wechat.gzh.GzhMsg;
import com.hx.phiappt.util.MerUserFileUtil;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.dao.mapper.*;
import com.hx.phip.dto.user.UserMergeConsumeDto;
@@ -171,6 +174,8 @@
    @Resource
    private ConsultationNeededProjectMapper consultationNeededProjectMapper;
    @Resource
    private ConsultationTreatProjectMapper consultationTreatProjectMapper;
    @Resource
    private VGuideLogMapper vGuideLogMapper;
    @Resource
    private UserStatisticsMapper userStatisticsMapper;
@@ -218,6 +223,10 @@
    private KoapOrderTotalMapper koapOrderTotalMapper;
    @Resource
    private UserMoneyLogMapper userMoneyLogMapper;
    @Resource
    private ConstantBean constantBean;
    @Resource
    private UserMergeCommonMapper userMergeCommonMapper;
    /**
     * 合并账号
@@ -400,9 +409,89 @@
        //处理消费摘要
        timeConsumeHandler(user, delUser, userMergeLog, sqlSentence, sqlMap);
        //处理含注解的
        annotationHandler(user,delUser,userMergeLog, sqlSentence, sqlMap);
        //修改状态
        otherService.logStatusUpdate(userMergeLog.getId(),1);
        logger.info("------------------------------------结束处理账号合并-------------------------------------");
    }
    /**
     * 处理含注解的表
     * */
    private void annotationHandler(User user, User delUser, UserMergeLog userMergeLog, SqlSentence sqlSentence, Map<String, Object> sqlMap) {
        logger.info("<-扫描含注解的表合并开始->");
        List<MerUserFileDto> merUserFileUtilList = null;
        try {
            merUserFileUtilList = MerUserFileUtil.getMerUserFileUtilList(constantBean);
        }catch (Exception e){
            logger.error("合并账号扫描含注解的表错误,保留{},作废{}"+user.getId(),delUser.getId());
        }
        if (merUserFileUtilList == null || merUserFileUtilList.size() < 1){
            logger.info("<-扫描含注解的表无所属,结束->");
            return;
        }
        StringBuilder sql = new StringBuilder();
        List<Map<String, Object>> delUserDataList = null;
        UserMergeLogItem dUserLog = null;
        for (MerUserFileDto merUserFileDto : merUserFileUtilList) {
            logger.info("扫描注解处理,表{},字段{}",merUserFileDto.getTableName(),merUserFileDto.getFileName());
            //获取旧用户数据
            if (sql.length() > 0){
                sql.delete(0,sql.length());
            }
            sql.append(" SELECT * FROM ").append(merUserFileDto.getTableName()).append(" WHERE isDel = #{m.isDel} ");
            sql.append(" AND ").append(merUserFileDto.getFileName()).append(" = #{m.delUserId} ");
            sqlSentence.sqlSentence(sql.toString(), sqlMap);
            delUserDataList = userMergeCommonMapper.selectListMap(sqlSentence);
            if (delUserDataList == null || delUserDataList.size() < 1){
                continue;
            }
            int sortNum = 0;
            dUserLog = new UserMergeLogItem();
            dUserLog.setMergeLogId(userMergeLog.getId());
            dUserLog.setMergeLogNo(userMergeLog.getMergeNo());
            dUserLog.setPersistUserId(userMergeLog.getPersistUserId());
            dUserLog.setRepealUserId(userMergeLog.getRepealUserId());
            dUserLog.setIsHaveOther(0);
            dUserLog.setOpManType(UserMergeLogItem.OP_MAN_TYPE_DEL);
            dUserLog.setOpType(UserMergeLogItem.OP_TYPE_UPDATE);
            dUserLog.setType(UserMergeLogItem.TYPE_USER_ADDRESS);
            dUserLog.setTableName(merUserFileDto.getTableName());
            dUserLog.setFieldId(merUserFileDto.getFileName());
            dUserLog.setFieldName("用户标识");
            dUserLog.setBeforeValue(delUser.getId());
            dUserLog.setAfterValue(user.getId());
            for (Map<String, Object> map : delUserDataList) {
                logger.info("当前处理,表{},字段{},记录标识{}",merUserFileDto.getTableName(),merUserFileDto.getFileName(),map.get("id"));
                dUserLog.setSortNum(sortNum);
                dUserLog.setOpContent(JSON.toJSONString(map));
                sqlMap.put("id", map.get("id"));
                if (sql.length() > 0){
                    sql.delete(0,sql.length());
                }
                sql.append(" UPDATE ").append(merUserFileDto.getTableName()).append(" SET ");
                sql.append(merUserFileDto.getFileName()).append(" = #{m.userId} WHERE id = #{m.id} ");
                sqlSentence.sqlUpdate(sql.toString(), sqlMap);
                if (userMergeCommonMapper.updateWhere(sqlSentence) != 1) {
                    logger.info("合并失败,当前处理,表{},字段{},记录标识{}",merUserFileDto.getTableName(),merUserFileDto.getFileName(),map.get("id"));
                    dUserLog.setStatus(0);
                    otherService.logAdd(dUserLog);
                    otherService.logStatusUpdate(userMergeLog.getId(),0);
                    throw new PlatTipsException(PlatformCode.ERROR_TIPS, "合并失败!");
                }
                dUserLog.setStatus(1);
                otherService.logAdd(dUserLog);
                sortNum = sortNum + 1;
            }
        }
        logger.info("<-扫描含注解的表合并结束->");
    }
    /**
@@ -2423,7 +2512,7 @@
                sqlMap.put("id", record.getId());
                sqlSentence.sqlUpdate(" userId = #{m.userId} WHERE id = #{m.id} ", sqlMap);
                if (consultationPotentialProjectMapper.updateWhere(sqlSentence) != 1) {
                    logger.error("合并用户咨询记录-关注活动记录失败" + JSON.toJSONString(record));
                    logger.error("合并用户咨询记录-潜在项目记录失败" + JSON.toJSONString(record));
                    dUserLog.setStatus(0);
                    otherService.logAdd(dUserLog);
                    otherService.logStatusUpdate(userMergeLog.getId(),0);
@@ -2479,6 +2568,53 @@
            }
        }
        logger.info("<-合并用户咨询记录-推荐项目记录结束->");
        //治疗项目consultation_treat_project
        logger.info("<-合并用户咨询记录-治疗项目记录开始->");
        //要作废账号的咨询记录-治疗项目列表
        sqlSentence.sqlSentence("SELECT * FROM consultation_treat_project WHERE userId = #{m.delUserId} AND isDel = #{m.isDel}", sqlMap);
        List<ConsultationTreatProject> consultationTreatProjectList = consultationTreatProjectMapper.selectList(sqlSentence);
        if (consultationTreatProjectList != null && consultationTreatProjectList.size() > 0) {
            logger.info("<-当前作废账号存在咨询记录-治疗项目记录->");
            UserMergeLogItem dUserLog = new UserMergeLogItem();
            dUserLog.setMergeLogId(userMergeLog.getId());
            dUserLog.setMergeLogNo(userMergeLog.getMergeNo());
            dUserLog.setPersistUserId(userMergeLog.getPersistUserId());
            dUserLog.setRepealUserId(userMergeLog.getRepealUserId());
            dUserLog.setIsHaveOther(0);
            dUserLog.setOpManType(UserMergeLogItem.OP_MAN_TYPE_DEL);
            dUserLog.setOpType(UserMergeLogItem.OP_TYPE_UPDATE);
            dUserLog.setType(UserMergeLogItem.TYPE_CONSULT);
            dUserLog.setTableName("consultation_treat_project");
            dUserLog.setFieldId("userId");
            dUserLog.setFieldName("用户标识");
            dUserLog.setBeforeValue(delUser.getId());
            dUserLog.setAfterValue(user.getId());
            for (ConsultationTreatProject record : consultationTreatProjectList) {
                logger.info("当前处理咨询记录-治疗项目记录,标识" + record.getId());
                dUserLog.setSortNum(sortNum);
                dUserLog.setOpContent(JSON.toJSONString(record));
                sqlMap.put("id", record.getId());
                sqlSentence.sqlUpdate(" userId = #{m.userId} WHERE id = #{m.id} ", sqlMap);
                if (consultationTreatProjectMapper.updateWhere(sqlSentence) != 1) {
                    logger.error("合并用户咨询记录-治疗项目记录失败" + JSON.toJSONString(record));
                    dUserLog.setStatus(0);
                    otherService.logAdd(dUserLog);
                    otherService.logStatusUpdate(userMergeLog.getId(),0);
                    throw new PlatTipsException(PlatformCode.ERROR_TIPS, "合并用户咨询记录-治疗项目记录失败!");
                }
                dUserLog.setStatus(1);
                otherService.logAdd(dUserLog);
                sortNum = sortNum + 1;
            }
        }
        logger.info("<-合并用户咨询记录-治疗项目记录结束->");
    }
    /**