jiangqs
2023-09-28 bdd9af51204d2108e2eaf4202310d2c24edea8b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.ruoyi.shop.service.impl.shop;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult;
import com.google.common.base.Joiner;
import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication;
import com.ruoyi.shop.enums.WxApplyMentSignStateEnum;
import com.ruoyi.shop.enums.WxApplyMentStateEnum;
import com.ruoyi.shop.enums.dict.IDict;
import com.ruoyi.shop.mapper.shop.ShopAuthenticationMapper;
import com.ruoyi.shop.service.shop.ShopAuthenticationService;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 商户信息 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-06-02
 */
@Service
public class ShopAuthenticationServiceImpl extends ServiceImpl<ShopAuthenticationMapper, ShopAuthentication> implements ShopAuthenticationService {
 
    @Override
    public List<ShopAuthentication> getShopAuthNeedUpdateStatus() {
        List<Integer> auditStatusList = Arrays.asList(1, 2, 3, 5);
        LambdaQueryWrapper<ShopAuthentication> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(ShopAuthentication::getAuditStatus, auditStatusList);
        queryWrapper.isNotNull(ShopAuthentication::getApplymentId);
        return this.list(queryWrapper);
    }
 
    @Override
    public void updateAuditStatusByApplymentId(String applymentId, ApplymentsStatusResult result) {
        // WxApplyMentStateEnum
        String applymentState = result.getApplymentState();
        Integer auditStatus = IDict.getCodeByText(WxApplyMentStateEnum.class, applymentState);
 
        Integer signState = IDict.getCodeByText(WxApplyMentSignStateEnum.class, result.getSignState());
 
        LambdaUpdateWrapper<ShopAuthentication> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(ShopAuthentication::getApplymentId, applymentId)
                .set(ShopAuthentication::getAuditStatus, auditStatus)
                .set(ShopAuthentication::getSignState, signState);
 
        if(WxApplyMentStateEnum.ACCOUNT_NEED_VERIFY.getCode().equals(auditStatus)){
            // ACCOUNT_NEED_VERIFY 待账户验证
            updateWrapper.set(ShopAuthentication::getLegalValidationUrl, result.getLegalValidationUrl());
            ApplymentsStatusResult.AccountValidation accountValidation = result.getAccountValidation();
            if(null != accountValidation) {
                updateWrapper.set(ShopAuthentication::getAvAccountName, accountValidation.getAccountName())
                    .set(ShopAuthentication::getAvAccountNo, accountValidation.getAccountNo())
                    .set(ShopAuthentication::getAvPayAmount, accountValidation.getPayAmount())
                    .set(ShopAuthentication::getDaNumber, accountValidation.getDestinationAccountNumber())
                    .set(ShopAuthentication::getDaName, accountValidation.getDestinationAccountName())
                    .set(ShopAuthentication::getDaBank, accountValidation.getDestinationAccountBank())
                    .set(ShopAuthentication::getDaCity, accountValidation.getCity())
                    .set(ShopAuthentication::getDaRemark, accountValidation.getRemark())
                    .set(ShopAuthentication::getDaDeadline, accountValidation.getDeadline());
            }
        } else if(WxApplyMentStateEnum.NEED_SIGN.getCode().equals(auditStatus)){
            // NEED_SIGN 待签约
            updateWrapper.set(ShopAuthentication::getSignUrl, result.getSignUrl());
            updateWrapper.set(ShopAuthentication::getSubMchid, result.getSubMchid());
 
        } else if(WxApplyMentStateEnum.FINISH.getCode().equals(auditStatus)){
            // FINISH 完成
            updateWrapper.set(ShopAuthentication::getSubMchid, result.getSubMchid());
 
        } else if(WxApplyMentStateEnum.REJECTED.getCode().equals(auditStatus)
                || WxApplyMentStateEnum.FROZEN.getCode().equals(auditStatus)){
            List<ApplymentsStatusResult.AuditDetail> auditDetail = result.getAuditDetail();
            if(null != auditDetail && !auditDetail.isEmpty()){
                List<String> paramNameList = auditDetail.stream().map(ApplymentsStatusResult.AuditDetail::getParamName).collect(Collectors.toList());
                List<String> rejectReason = auditDetail.stream().map(ApplymentsStatusResult.AuditDetail::getRejectReason).collect(Collectors.toList());
                updateWrapper.set(ShopAuthentication::getAdParamName, Joiner.on(";").join(paramNameList))
                        .set(ShopAuthentication::getAdRejectReason, Joiner.on(";").join(rejectReason));
            }
 
        }
        if("UNSIGNED".equals(result.getSignState())&&StringUtils.isNotBlank(result.getSignUrl())){
            updateWrapper.set(ShopAuthentication::getSignUrl, result.getSignUrl());
        }
        this.update(updateWrapper);
    }
 
    @Override
    public ShopAuthentication getByShopId(Long shopId) {
        LambdaQueryWrapper<ShopAuthentication> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(ShopAuthentication::getShopId, shopId)
                .last(" limit 1 ");
        return this.getOne(queryWrapper);
    }
}