xiaoyong931011
2021-11-10 a30578866c2c85d684dd493be3795d3bf6e40a18
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.xzx.gc.pay.service;
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.utils.BusinessUtil;
import com.xzx.gc.entity.CityPartner;
import com.xzx.gc.entity.PartnerAccount;
import com.xzx.gc.entity.PartnerAccountLog;
import com.xzx.gc.model.admin.AccountLogModel;
import com.xzx.gc.model.admin.PartnerAccountLogModel;
import com.xzx.gc.model.admin.PartnerAccountModel;
import com.xzx.gc.pay.mapper.CityPartnerMapper;
import com.xzx.gc.pay.mapper.PartnerAccountLogMapper;
import com.xzx.gc.util.DoubleUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
 
@Service
@Transactional
@Slf4j
public class PartnerAccountLogService {
 
    @Autowired
    private PartnerAccountLogMapper partnerAccountLogMapper;
 
    @Autowired
    private CityPartnerMapper cityPartnerMapper;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    @Autowired
    private PartnerAccountService partnerAccountService;
 
 
    public void add(PartnerAccountLog partnerAccountLog){
        String now=DateUtil.now();
        partnerAccountLog.setCreateTime(now);
        partnerAccountLog.setDelFlag(Constants.DEL_NOT_FLAG);
        partnerAccountLog.setUpdateTime(now);
        //未审核
        partnerAccountLog.setApproverStatus("1");
 
        PartnerAccount byAccount=partnerAccountLog.getPartnerAccount();
 
        if(byAccount==null) {
 
            String accountId = partnerAccountLog.getAccountId();
            if (StrUtil.isBlank(accountId)) {
                PartnerAccount byPartnerId = partnerAccountService.findByPartnerId(partnerAccountLog.getPartnerId());
                if (byPartnerId != null) {
                    partnerAccountLog.setAccountId(byPartnerId.getAccount());
                }
            }
            if (StrUtil.isBlank(partnerAccountLog.getAccountId())) return;
 
            byAccount = partnerAccountService.findByAccount(partnerAccountLog.getAccountId());
        }
 
        if(StrUtil.isNotBlank(partnerAccountLog.getMoney())) {
            partnerAccountLog.setAccountMoney(businessUtil.changeMoney(byAccount.getHbb()));
            BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getAccountMoney()), Convert.toBigDecimal(partnerAccountLog.getMoney()));
            partnerAccountLog.setHbb(businessUtil.changeMoney(add));
        }
 
        if(StrUtil.isNotBlank(partnerAccountLog.getManageLimit())) {
            partnerAccountLog.setOldLimit(businessUtil.changeMoney(byAccount.getOverdraftLimit()));
            BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getOldLimit()), Convert.toBigDecimal(partnerAccountLog.getManageLimit()));
            partnerAccountLog.setNewLimit(businessUtil.changeMoney(add));
        }
 
 
        if(StrUtil.isNotBlank(partnerAccountLog.getManageLimitFix())) {
            partnerAccountLog.setOldLimitFix(businessUtil.changeMoney(byAccount.getFixedLimit()));
            BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getOldLimitFix()), Convert.toBigDecimal(partnerAccountLog.getManageLimitFix()));
            partnerAccountLog.setNewLimitFix(businessUtil.changeMoney(add));
        }
 
        partnerAccountLogMapper.insertSelective(partnerAccountLog);
    }
 
 
    public void insertPartnerAccountLog(PartnerAccountModel accountModel, String type, BigDecimal money, String payOrderId, String packageType) {
        //写入日志
        AccountLogModel log = new AccountLogModel();
        boolean flag = true;
        if(null!=accountModel.getAddType()&&!"".equals(accountModel.getAddType())){
            log.setNewMoney(DoubleUtil.roundTwo(new BigDecimal(accountModel.getHbb()).add(money).toString()));
 
        }else{
            flag = false;
            log.setNewMoney(DoubleUtil.roundTwo(new BigDecimal(accountModel.getHbb()).subtract(money).toString()));
 
        }
        CityPartner partner = cityPartnerMapper.queryEntityByUserIds(accountModel.getUserId());
        PartnerAccountLogModel partnerLog = new PartnerAccountLogModel();
        partnerLog.setFlowNo(payOrderId);
        partnerLog.setCreateTime(DateUtil.now());
        partnerLog.setApproverStatus("1");
        if(type.equals("14")){
            if(!flag){
                partnerLog.setMoney(DoubleUtil.roundTwo(money.multiply(new BigDecimal("-1")).toString()));
 
            }else{
                partnerLog.setMoney(DoubleUtil.roundTwo(money.toString()));
 
            }
 
        }else{
            if(!flag){
                partnerLog.setMoney(DoubleUtil.roundTwo(money.multiply(new BigDecimal("-1")).toString()));
 
            }else{
                partnerLog.setMoney(DoubleUtil.roundTwo(money.toString()));
 
            }
        }
        partnerLog.setHbb(log.getNewMoney());
        partnerLog.setDelFlag(0);
        partnerLog.setAccountId(accountModel.getAccount());
        partnerLog.setAccountMoney(DoubleUtil.roundTwo(accountModel.getHbb() + ""));
        partnerLog.setUserName(partner.getPartnerName());
        if (null != packageType) {
            partnerLog.setType(packageType);
 
        } else {
            if(type.equals("9")){
                partnerLog.setType("12");
            }else if(type.equals("8")){
                partnerLog.setType("7");
            }else{
                partnerLog.setType("1");
            }
        }
        partnerLog.setUserPhone(partner.getMobilePhone());
        partnerLog.setRoleName("城市合伙人");
        partnerAccountLogMapper.addPartnerAccountLog(partnerLog);
 
    }
}