fwq
2024-01-24 260f9557ee555bb96b74a0850982b875e260d1a0
金额领取配置优化
1个文件已修改
261 ■■■■ 已修改文件
phi_platform_user/src/main/java/com/hx/phip/service/userMoney/impl/UserMoneyUnclaimedServiceImpl.java 261 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/userMoney/impl/UserMoneyUnclaimedServiceImpl.java
@@ -347,79 +347,34 @@
                    throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "资金类型错误,类型不存在");
            }
        }
        //获取金额配置
        MoneyRule moneyRule = getMoneyRule(userMoneyUnclaimed.getMoneyRuleId());
        if (moneyRule != null){
            logger.info("操作资金-moneyRule规则数据:"+JSON.toJSONString(moneyRule));
            //增值金校验
            if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_ADDED_FUND)
                    && !userMoneyUnclaimed.getFundType().equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND)){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型匹配!");
            }
            //积分校验
            if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_INTEGRAL)
                    && !userMoneyUnclaimed.getFundType().equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型匹配!");
            }
            userMoneyUnclaimed.setMoneyRuleId(moneyRule.getId());
            userMoneyUnclaimed.setIsNeedReceive(moneyRule.getIsNeedReceive());
            userMoneyUnclaimed.setIsUserReceive(moneyRule.getIsUserReceive());
            userMoneyUnclaimed.setWaitReceiveLimit(moneyRule.getWaitReceiveLimit());
            userMoneyUnclaimed.setWaitReceiveLimitDay(moneyRule.getWaitReceiveLimitDay());
            userMoneyUnclaimed.setIsReceiveLimit(moneyRule.getIsReceiveLimit());
            userMoneyUnclaimed.setReceiveLimitType(moneyRule.getReceiveLimitType());
            userMoneyUnclaimed.setReceiveLimitData(moneyRule.getReceiveLimitData());
            userMoneyUnclaimed.setReceiveMoneyLimit(moneyRule.getReceiveMoneyLimit());
            userMoneyUnclaimed.setReceiveMoneyLimitDay(moneyRule.getReceiveMoneyLimitDay());
        }
        // 来源渠道
        if (StringUtils.isEmpty(userMoneyUnclaimed.getOriginChannel())) {
            // 默认来源渠道为 预约后台
            userMoneyUnclaimed.setOriginChannel(OriginChannelConstants.ORIGIN_CHANNEL_PHIS);
            // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "来源渠道不能为空");
        }
        /* else {
            if (checkConstantNotHaveValue(OriginChannelConstants.class, userMoneyUnclaimed.getOriginChannel())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "来源渠道错误,渠道不存在");
            }
        }*/
        // 操作原因
        if (StringUtils.isEmpty(userMoneyUnclaimed.getOperationReason())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因不能为空");
        } else {
            if (checkConstantNotHaveValue(OperationReasonConstants.class, userMoneyUnclaimed.getOperationReason())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因错误,原因不存在");
            }
        }
        if (checkConstantNotHaveValue(OperationReasonConstants.class, userMoneyUnclaimed.getOperationReason())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因错误,原因不存在");
        }
        //操作类型,默认为系统处理
        if (userMoneyUnclaimed.getOpType() == null) {
        // 获取金额配置,(有传标识则拿对应的配置,否则拿默认配置)
        MoneyRule moneyRule = getMoneyRule(userMoneyUnclaimed.getMoneyRuleId(),userMoneyUnclaimed.getFundType());
        logger.info("操作资金-moneyRule规则数据:"+JSON.toJSONString(moneyRule));
        //负数默认系统处理
        if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) > 0) {
            userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
        }else {
            // 操作类型,默认为系统处理
            if (userMoneyUnclaimed.getOpType() == null) {
                userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
            }
            // 判断是否是支持的类型
            if (UserMoneyUnclaimed.OP_TYPE_SYSTEM != userMoneyUnclaimed.getOpType() && UserMoneyUnclaimed.OP_TYPE_RECEIVE != userMoneyUnclaimed.getOpType()) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作类型错误");
            }
            //增值金默认需要领取
            if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) {
                if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) < 0) {
                    userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_RECEIVE);
                }else {
                    //负数不用用户领取和判断是否需要发送短信提醒领取
                    userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
                }
            }else {
                //其他金额类型默认不需要领取
                userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
            }
        }
        // 是否发送短信
        if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()) {
            boolean flag = true;
            //规则不需要校验用户勾选
            // 有规则,且规则不需要校验用户勾选
            if (moneyRule != null && moneyRule.getIsUserReceive().equals(BaseEntity.NO)){
                // 校验基础规则中是否需要领取
                if (moneyRule.getIsNeedReceive().equals(BaseEntity.YES)){
                    logger.info("操作用户资金(待领取记录)-不校验用户设置是否需要领取状态-但是需要用户领取");
                    //需要领取
@@ -427,25 +382,23 @@
                }else if (moneyRule.getIsNeedReceive().equals(BaseEntity.NO)){
                    logger.info("操作用户资金(待领取记录)-不校验用户设置是否需要领取状态-并且不需要用户领取");
                    //不需要领取
                    flag = false;
                    userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
                }
            }else {
                // 查询用户设置是否领取状态
                UserInfo userInfo = userInfoMapper.selectOneByUserId(userMoneyUnclaimed.getUserId());
                if (userInfo != null) {
                    // 不需要领取处理数据
                    if (userInfo.getIsReceiveValueAddedFund() != null && BaseEntity.NO.equals(userInfo.getIsReceiveValueAddedFund())) {
                        // 用户设置了不用再领取增值金
                        flag = false;
                //增值金需要判断用户是否勾选
                if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()){
                    // 没有规则,或者需要用户勾选校验 查询用户设置是否领取状态
                    UserInfo userInfo = userInfoMapper.selectOneByUserId(userMoneyUnclaimed.getUserId());
                    if (userInfo != null && userInfo.getIsReceiveValueAddedFund() != null
                            && BaseEntity.NO.equals(userInfo.getIsReceiveValueAddedFund())){
                        logger.info("操作用户资金(待领取记录)-用户设置增值金是否需要领取状态:{}", userInfo.getIsReceiveValueAddedFund());
                        // 用户设置了不用再领取
                        userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
                        logger.info("操作用户资金(待领取记录)-用户设置是否需要领取状态:{}", userInfo.getIsReceiveValueAddedFund());
                    }
                }else {
                    //非增值金默认系统处理
                    userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
                }
            }
            // 校验是否要发送短信
            if (flag) {
                checkIsNeedSentSMS(userMoneyUnclaimed);
            }
        }
        // 判断操作数量或金额
@@ -577,9 +530,10 @@
                }
            }
        }*/
        //设置待领取的有效时间
        if (moneyRule != null){
            if (moneyRule.getWaitReceiveLimit().equals(BaseEntity.YES)){
                userMoneyUnclaimed.setIsLimitTime(BaseEntity.YES);
                // 获取有效期时间配置 待领取默认30天领取
                int validityPeriod = moneyRule.getWaitReceiveLimitDay();
                // 获取时间
@@ -594,6 +548,8 @@
                userMoneyUnclaimed.setLimitEndTime(limitEndTime);
            }
        }else {
            // 走原本默认的设置
            userMoneyUnclaimed.setIsLimitTime(BaseEntity.YES);
            // 获取有效期时间配置 待领取默认30天领取
            int validityPeriod = UserMoneyTool.getUnclaimedValidityTime(commonService);
            // 获取时间
@@ -601,25 +557,76 @@
            // 设置有效期时间
            userMoneyUnclaimed.setLimitEndTime(limitEndTime);
        }
        // 默认来源渠道为 预约后台
        if (StringUtils.isEmpty(userMoneyUnclaimed.getOriginChannel())) {
            userMoneyUnclaimed.setOriginChannel(OriginChannelConstants.ORIGIN_CHANNEL_PHIS);
        }
        // 填充金额规则数据
        if (moneyRule != null){
            userMoneyUnclaimed.setMoneyRuleId(moneyRule.getId());
            userMoneyUnclaimed.setIsNeedReceive(moneyRule.getIsNeedReceive());
            userMoneyUnclaimed.setIsUserReceive(moneyRule.getIsUserReceive());
            userMoneyUnclaimed.setWaitReceiveLimit(moneyRule.getWaitReceiveLimit());
            userMoneyUnclaimed.setWaitReceiveLimitDay(moneyRule.getWaitReceiveLimitDay());
            userMoneyUnclaimed.setIsReceiveLimit(moneyRule.getIsReceiveLimit());
            userMoneyUnclaimed.setReceiveLimitType(moneyRule.getReceiveLimitType());
            userMoneyUnclaimed.setReceiveLimitData(moneyRule.getReceiveLimitData());
            userMoneyUnclaimed.setReceiveMoneyLimit(moneyRule.getReceiveMoneyLimit());
            userMoneyUnclaimed.setReceiveMoneyLimitDay(moneyRule.getReceiveMoneyLimitDay());
        }
        //要领取的资金填充发送短信信息
        if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()){
            //暂时默认增值金会发送短信
            if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) {
                checkIsNeedSentSMS(userMoneyUnclaimed);
            }
            //其他处理
        }
    }
    /**获取金额规则信息*/
    private MoneyRule getMoneyRule(String moneyRuleId) {
    /**
     * 获取金额规则信息
     * @param moneyRuleId 金额规则
     * @param fundType 操作的金额类型
     * */
    private MoneyRule getMoneyRule(String moneyRuleId,Integer fundType) {
        MoneyRule moneyRule = null;
        if (StringUtils.noNull(moneyRuleId)){
            moneyRule = moneyRuleMapper.selectOneByKey(moneyRuleId);
            if (moneyRule == null){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "资金规则信息不存在");
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "标识错误,金额规则信息查询失败");
            }
            if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_ADDED_FUND)){
                //增值金校验
                if (!fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND)){
                    throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型不匹配,当前操作【增值金】");
                }
            }else if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_INTEGRAL)){
                //积分校验
                if (!fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
                    throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型不匹配,当前操作【积分】");
                }
            }
        }else {
            SqlSentence sqlSentence = new SqlSentence();
            Map<String,Object> sqlMap = new HashMap<>();
            sqlMap.put("isDel",BaseEntity.NO);
            sqlMap.put("isUp",BaseEntity.YES);
            sqlMap.put("isDefault",BaseEntity.YES);
            sqlSentence.sqlSentence("SELECT * FROM money_rule WHERE isDle = #{m.isDel} " +
                    " AND isUp = #{m.isUp} AND isDefault = #{m.isDefault} ",sqlMap);
            moneyRule = moneyRuleMapper.selectOne(sqlSentence);
            //查找增值金/积分默认配置信息
            if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND) || fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
                SqlSentence sqlSentence = new SqlSentence();
                Map<String,Object> sqlMap = new HashMap<>();
                sqlMap.put("isDel",BaseEntity.NO);
                sqlMap.put("isUp",BaseEntity.YES);
                sqlMap.put("isDefault",BaseEntity.YES);
                if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND)){
                    //增值金
                    sqlMap.put("moneyType",MoneyRule.MONEY_TYPE_ADDED_FUND);
                }else if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
                    //积分
                    sqlMap.put("moneyType",MoneyRule.MONEY_TYPE_INTEGRAL);
                }
                sqlSentence.sqlSentence("SELECT * FROM money_rule WHERE isDle = #{m.isDel} " +
                        " AND isUp = #{m.isUp} AND isDefault = #{m.isDefault} AND moneyType = #{m.moneyType} ",sqlMap);
                moneyRule = moneyRuleMapper.selectOne(sqlSentence);
            }
        }
        return moneyRule;
    }
@@ -754,48 +761,23 @@
                    logger.info("待领取资产处理跳过,数据id:{},原因:数据已失效无法领取", userMoneyUnclaimed.getId());
                    return;
                }
                //有领取限制
                if (userMoneyUnclaimed.getIsReceiveLimit() != null && userMoneyUnclaimed.getIsReceiveLimit().equals(BaseEntity.YES)){
                    List<MoneyRuleValueDto> moneyRuleValueDtoList = JSONArray.parseArray(userMoneyUnclaimed.getReceiveLimitData(), MoneyRuleValueDto.class);
                    logger.info("待领取资产限制数据{},数据id:{}",JSON.toJSONString(moneyRuleValueDtoList),userMoneyUnclaimed.getId());
                    boolean isPass = false;
                    if (moneyRuleValueDtoList != null && moneyRuleValueDtoList.size() > 0){
                        if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.YES)){
                            //满足其一
                            for (MoneyRuleValueDto moneyRuleValueDto : moneyRuleValueDtoList) {
                                if (SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode(),userMoneyUnclaimed.getUserId())){
                                    isPass = true;
                                    break;
                                }
                            }
                        }else if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.NO)){
                            //都要满足
                            for (MoneyRuleValueDto moneyRuleValueDto : moneyRuleValueDtoList) {
                                if (!SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode(),userMoneyUnclaimed.getUserId())){
                                    break;
                                }
                            }
                        }
                    }
                    if (!isPass){
                        logger.info("待领取资产处理跳过,数据id:{},原因:用户不满足金额的领取限制", userMoneyUnclaimed.getId());
                        return;
                //要领取的资金判断是否满足条件
                if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()){
                    if (checkCanNotReceive(userMoneyUnclaimed)){
                        throw new PlatTipsException(PlatformCode.ERROR_TIPS,"领取失败,未满足领取条件");
                    }
                }
                // 添加用户日志
                if (BaseEntity.NO.equals(isReceive)) {
                    addUserLog(userMoneyUnclaimed, BaseEntity.YES);
                }
                //计算有效结束时间
                //计算有效结束时间,操作资金处理用到结束时间
                Date limitEndTime = null;
                Map<String, Object> sqlValue = new HashMap<>();
                //有限制规则
                //有限制时间规则
                if (StringUtils.noNull(userMoneyUnclaimed.getMoneyRuleId())){
                    if (userMoneyUnclaimed.getReceiveMoneyLimit() != null && userMoneyUnclaimed.getReceiveMoneyLimit().equals(BaseEntity.YES)){
                        //有限制,限制结束时间计算
                        logger.info("待领取资产关联规则的限制天数{},数据id:{}",userMoneyUnclaimed.getWaitReceiveLimitDay(),userMoneyUnclaimed.getId());
                        logger.info("待领取资产处理,数据id:{},关联规则限制天数{}",userMoneyUnclaimed.getId(),userMoneyUnclaimed.getWaitReceiveLimitDay());
                        limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(),userMoneyUnclaimed.getWaitReceiveLimitDay());
                    }else {
                        //无限制,默认100年
@@ -807,9 +789,8 @@
                    // 获取时间
                    limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(), validityPeriod);
                }
                // 传进去资金处理
                // 传进去下面的资金处理
                userMoneyUnclaimed.setLimitEndTime(limitEndTime);
                // 操作资金处理
                switch (userMoneyUnclaimed.getFundType()) {
                    case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND:
@@ -826,20 +807,56 @@
                        userIntegralRecordService.handleData(userMoneyUnclaimed);
                        break;
                }
                // 更新状态成已处理
                SqlSentence sqlSentence = new SqlSentence();
                String sql = " status=#{m.status},receiveTime=#{m.nowTime},limitEndTime=#{m.limitEndTime},editTime=#{m.nowTime} WHERE id=#{m.id}";
                Map<String, Object> sqlValue = new HashMap<>();
                sqlValue.put("limitEndTime", limitEndTime);
                sqlValue.put("status", UserMoneyUnclaimed.STATUS_SUCCEED);
                sqlValue.put("nowTime", new Date());
                sqlValue.put("limitEndTime", limitEndTime);
                sqlValue.put("id", userMoneyUnclaimed.getId());
                sqlSentence.sqlSentence(sql, sqlValue);
                commonService.updateWhere(UserMoneyUnclaimedMapper.class, sqlSentence);
                if (commonService.updateWhere(UserMoneyUnclaimedMapper.class, sqlSentence) != 1){
                    logger.error("领取金额状态修改失败,sql{},map{}",sqlSentence.getSqlSentence(),JSON.toJSONString(sqlValue));
                    throw new TipsException("金额领取处理失败,错误代码[01]");
                }
            }
        }
    }
    /**判断是否可以领取*/
    private boolean checkCanNotReceive(UserMoneyUnclaimed userMoneyUnclaimed) {
        //有领取限制
        if (userMoneyUnclaimed.getIsReceiveLimit() != null && userMoneyUnclaimed.getIsReceiveLimit().equals(BaseEntity.YES)){
            List<MoneyRuleValueDto> limitList = JSONArray.parseArray(userMoneyUnclaimed.getReceiveLimitData(), MoneyRuleValueDto.class);
            logger.info("待领取资产处理,数据id:{},限制数据{},解析的数据{}"
                    ,userMoneyUnclaimed.getId(),userMoneyUnclaimed.getReceiveLimitData(),JSON.toJSONString(limitList));
            if (limitList != null && limitList.size() > 0){
                //满足其一
                if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.YES)){
                    for (MoneyRuleValueDto moneyRuleValueDto : limitList) {
                        //满足一个则设为通过,退出循环
                        if (SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode()
                                ,userMoneyUnclaimed.getUserId(),userMoneyUnclaimed.getOrderId())){
                            return false;
                        }
                    }
                }
                //都要满足
                else if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.NO)){
                    for (MoneyRuleValueDto moneyRuleValueDto : limitList) {
                        //存在一个不满足则退出循环
                        if (!SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode()
                                ,userMoneyUnclaimed.getUserId(),userMoneyUnclaimed.getOrderId())){
                            return true;
                        }
                    }
                }
            }
        }
        return true;
    }
    /**转赠*/
    @Override
    public void turn(UserTurnDto userTurnDto) {