xiaoyong931011
2022-08-12 565726c9559ebc047fa0833c16a39f1824187bbb
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package cc.mrbird.febs;
 
import cc.mrbird.febs.mall.dto.ApiLeaderOrderConfirmDto;
import cc.mrbird.febs.mall.entity.MallOrderInfo;
import cc.mrbird.febs.mall.entity.MallOrderItem;
import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper;
import cc.mrbird.febs.mall.mapper.MallOrderItemMapper;
import cc.mrbird.febs.mall.service.IAgentService;
import cc.mrbird.febs.mall.service.IApiMallTeamLeaderService;
import cc.mrbird.febs.mall.service.IMallAchieveService;
import cc.mrbird.febs.mall.service.IMemberProfitService;
import cc.mrbird.febs.rabbit.consumer.AgentConsumer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.client.RestTemplate;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2022-06-02
 **/
@SpringBootTest
public class ProfitTest {
 
    @Autowired
    private AgentConsumer agentConsumer;
 
    @Autowired
    private IAgentService agentService;
 
    @Autowired
    private IMemberProfitService memberProfitService;
 
    @Test
    public void dynamicProfit() {
        memberProfitService.dynamicProfit(21L);
    }
    @Test
    public void agentProfit() {
        memberProfitService.agentProfit(null);
    }
 
 
    @Test
    public void staticProfit() {
        memberProfitService.staticProfit(new Date());
    }
 
    @Test
    public void thankfulProfit() {
        memberProfitService.thankfulProfit(new Date());
    }
 
    @Test
    public void rankProfit() {
        memberProfitService.rankProfit();
    }
 
    @Autowired
    private MallOrderInfoMapper mallOrderInfoMapper;
 
    @Test
    public void directorProfitTest() {
        memberProfitService.storeAndDirectorProfit(new Date());
    }
 
    @Autowired
    private MallOrderItemMapper mallOrderItemMapper;
 
    @Autowired
    private IMallAchieveService mallAchieveService;
 
    @Test
    public void achieveTest() {
        List<MallOrderItem> items = mallOrderItemMapper.selectList(null);
        for (MallOrderItem item : items) {
            mallAchieveService.add(item.getId());
        }
    }
 
    @Test
    public void paramTest() {
        Map<String, Integer> map = new HashMap<>();
        BigDecimal amount = new BigDecimal("100");
        map.put("amount", 1);
        changeAmount(map);
        System.out.println(map.get("amount"));
    }
 
    public void changeAmount(Map<String, Integer> amount) {
        amount.put("amount", 2);
    }
 
    @Resource
    RestTemplate restTemplate;
 
    @Test
    public void getWeChatAccessToken() {
 
        String appId = "wx5cc58f796224af61";
        String appSecret = "71403646f666f9b9dca308d4f357765c";
        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
        String jsonStr = restTemplate.getForObject(url, String.class);
 
        /**
         * 返回结果
         * {"access_token":"ACCESS_TOKEN","expires_in":7200}
         */
        if (!jsonStr.contains("access_token")) {
            System.out.println("获取微信access_token失败");
        }
 
        JSONObject jsonObject = JSON.parseObject(jsonStr);
        System.out.println(jsonObject.get("access_token").toString());
    }
    @Resource
    IApiMallTeamLeaderService iApiMallTeamLeaderService;
 
    @Test
    public void confirm(){
//        ApiLeaderOrderConfirmDto apiLeaderOrderConfirmDto = new ApiLeaderOrderConfirmDto();
//        apiLeaderOrderConfirmDto.setIds("90");
//        iApiMallTeamLeaderService.leaderOrderConfirm(apiLeaderOrderConfirmDto);
        String productNames = getProductNames(35L, 106L);
        System.out.println(productNames);
    }
 
    /**
     * 根据用户ID和订单ID获取所购买商品名称
     * @return 所含商品名称(多个以","隔开)
     */
    public String getProductNames(Long memberId, Long orderId) {
        MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectOrderByMemberIdAndId(memberId, orderId);
        List<MallOrderItem> details = mallOrderInfo.getItems();
        if (CollectionUtils.isEmpty(details)) {
            return "";
        }
        StringBuffer productNameBuffer = new StringBuffer();
        Integer maxLength = 30;
        for (int i = 0; i< details.size(); i++) {
            MallOrderItem mallOrderItem = details.get(i);
            String goodsName = mallOrderItem.getGoodsName();
            if (goodsName == null) {
                continue;
            }
            if (i == 0 && goodsName.length() > maxLength) {
                productNameBuffer.append(goodsName.substring(0, maxLength) + "...");
                break;
            }
            if ((productNameBuffer.length() + goodsName.length()) > maxLength) {
                productNameBuffer.append("等");
                break;
            }
            productNameBuffer.append(goodsName + ",");
        }
        String productNames = productNameBuffer.toString();
        if (productNames.endsWith(",")) {
            productNames = productNames.substring(0, productNames.length() - 1);
        }
        if (productNames.endsWith(",等")) {
            productNames = productNames.substring(0, productNames.length() - 2) + "等";
        }
        return productNames;
    }
}