KKSU
2025-02-07 62fc17e246f99c73f162f243490a811e540c0043
fix: 修改文件名大小写
5 files modified
917 ■■■■ changed files
src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/model/RefundStatus.java 3 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/util/FiuuRefundUtil.java 43 ●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 4 ●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/AgentTest.java 864 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java
@@ -172,7 +172,8 @@
        // 计算 skey 验证
        String preSkey = DigestUtils.md5Hex(tranID + orderId + status + domain + amount + currency);
        String calculatedSkey = DigestUtils.md5Hex(paydate + domain + preSkey + secretKey);
        MallOrderInfo mallOrderInfo = ValidateEntityUtils.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在");
        MallOrderInfo mallOrderInfo = ValidateEntityUtils
                .ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在");
        log.info("callback payResult: {}", mallOrderInfo.getPayResult());
        if("1".equals(mallOrderInfo.getPayResult())){
            return new FebsResponse().success().data("/pages/order/pay/paySuccess?amount="+ amount +"&type=3");
src/main/java/cc/mrbird/febs/pay/model/RefundStatus.java
@@ -1,8 +1,10 @@
package cc.mrbird.febs.pay.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class RefundStatus {
    private String TxnID;
    private String RefID;
@@ -10,5 +12,4 @@
    private String Status;
    private String LastUpdate;
    private String ReasonMsg;
    private String FPXTxnID;
}
src/main/java/cc/mrbird/febs/pay/util/FiuuRefundUtil.java
@@ -1,7 +1,9 @@
package cc.mrbird.febs.pay.util;
import cc.mrbird.febs.pay.model.RefundStatus;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
@@ -9,17 +11,13 @@
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.*;
@Slf4j
@Service(value="FiuuRefundUtil")
public class FiuuRefundUtil {
    private static final String API_BASE_URL = "https://api.fiuu.com/RMS/API/refundAPI/";
    private static final String MERCHANT_ID = "e2umart01";
    private static final String VERIFY_KEY = "4e3a4ed58e62ddbfacf41f6d5ec56bf2";
    private static final int MAX_RETRIES = 3;
    private static final int POLL_INTERVAL = 1000; // 5秒
    private static final int TIMEOUT = 60000; // 60秒超时
    private final ObjectMapper objectMapper = new ObjectMapper();
@@ -47,41 +45,16 @@
        HttpGet request = new HttpGet(url);
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            String response = EntityUtils.toString(client.execute(request).getEntity());
            List<RefundStatus> refundStatusList = objectMapper.readValue(
                    response,
                    objectMapper.getTypeFactory().constructCollectionType(List.class, RefundStatus.class));
            log.info("Response: " + response);
            List<RefundStatus> refundStatusList = JSONUtil.toList(JSONUtil.parseArray(response), RefundStatus.class);
            return refundStatusList.get(0);
        }
    }
    // 异步轮询退款状态
    public RefundStatus pollRefundStatus(String txnId) throws Exception {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<RefundStatus> future = executor.submit(() -> {
            int retryCount = 0;
            while (retryCount < MAX_RETRIES) {
                try {
                    RefundStatus status = queryByTxnId(txnId);
                    if (!"pending".equals(status.getStatus())) {
                        return status;
                    }
                    Thread.sleep(POLL_INTERVAL);
                    retryCount++;
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new RuntimeException("Polling interrupted", e);
                }
            }
            throw new TimeoutException("Max retries reached");
        });
        try {
            return future.get(TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            future.cancel(true);
            throw new RuntimeException("Refund status check timeout");
        } finally {
            executor.shutdown();
        }
        RefundStatus status = queryByTxnId(txnId);
        return status;
    }
}
src/main/resources/application-test.yml
@@ -2,7 +2,7 @@
  datasource:
    dynamic:
      # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗
      p6spy: true
      p6spy: false
      hikari:
        connection-timeout: 30000
        max-lifetime: 1800000
@@ -18,7 +18,7 @@
          username: db_e2
          password: db_e20806123!@#
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://120.27.238.55:3406/db_e2?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
          url: jdbc:mysql://47.250.124.232:3306/db_e2?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
  redis:
    # Redis数据库索引(默认为 0)
src/test/java/cc/mrbird/febs/AgentTest.java
@@ -1,737 +1,127 @@
//package cc.mrbird.febs;
//
//import cc.mrbird.febs.vip.service.IVipCommonService;
//import lombok.extern.slf4j.Slf4j;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//
///**
// * @author wzy
// * @date 2021-09-25
// **/
//@Slf4j
//@SpringBootTest
//public class AgentTest {
//    @Autowired
//    private IVipCommonService vipCommonService;
//    @Test
//    public void getCouponAmountMap(){
//        vipCommonService.getScore(283L);
//
//    }
//
//
////    @Autowired
////    private RedisUtils redisUtils;
////    @Resource
////    RestTemplate restTemplate;
////
////    public static final String API_KEY = "MPHXcBxkGLIDOmoaahS9pIB7";
////    public static final String SECRET_KEY = "f5ueNY65fE9C6FzFTVKc6Imo8NdZSWMw";
////
////    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
////    @Test
////    public void getAccessToken(){
////        ApiIdentifyAddressDto apiIdentifyAddressDto = new ApiIdentifyAddressDto();
////        apiIdentifyAddressDto.setText("上海市浦东新区纳贤路701号百度上海研发中心 F4A000 张三");
////        MediaType mediaType = MediaType.parse("application/json");
////        RequestBody body = RequestBody.create(mediaType, JSONUtil.toJsonStr(apiIdentifyAddressDto));
////        Request request = new Request.Builder()
////                .url("https://aip.baidubce.com/rpc/2.0/nlp/v1/address?access_token=" + redisUtils.get(WechatConfigure.BAIDU_ACCESS_TOKEN_REDIS_KEY).toString())
////                .method("POST", body)
////                .addHeader("Content-Type", "application/json")
////                .addHeader("Accept", "application/json")
////                .build();
////        try {
////            Response response = HTTP_CLIENT.newCall(request).execute();
////            String responseStr = response.body().string();
////            System.out.println(responseStr);
////            if (responseStr.contains("error_code")) {
////                System.out.println("获取access_token失败");
////                JSONObject jsonObject = JSONUtil.parseObj(responseStr);
////                System.out.print(jsonObject.get("error_code").toString());
////            }
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////    }
////    @Test
////    public void getAccessToken2(){
////        // 官网获取的 API Key 更新为你注册的
////        String clientId = "MPHXcBxkGLIDOmoaahS9pIB7";
////        // 官网获取的 Secret Key 更新为你注册的
////        String clientSecret = "f5ueNY65fE9C6FzFTVKc6Imo8NdZSWMw";
////        String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
////        String getAccessTokenUrl = authHost
////                // 1. grant_type为固定参数
////                + "grant_type=client_credentials"
////                // 2. 官网获取的 API Key
////                + "&client_id=" + clientId
////                // 3. 官网获取的 Secret Key
////                + "&client_secret=" + clientSecret;
////        String jsonStr = restTemplate.getForObject(getAccessTokenUrl, String.class);
////
////        /**
////         * 返回结果
////         * {"access_token":"ACCESS_TOKEN","expires_in":7200}
////         */
////        if (!jsonStr.contains("access_token")) {
////            System.out.println("获取access_token失败");
////        }
////        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(jsonStr);
////        String accessToken = jsonObject.getString("access_token");
////
////        String accessTokenKey = WechatConfigure.BAIDU_ACCESS_TOKEN_REDIS_KEY;
////        if (StrUtil.isEmpty(accessToken)) {
////            log.error("获取baidu access_token失败: {}" , jsonObject.getString("errmsg"));
////            throw new ApiException("获取access token失败");
////        } else {
////            log.info("baidu access_token : {}",accessToken);
////            System.out.println(accessToken);
////            redisUtils.set(accessTokenKey,accessToken);
////        }
////    }
////    @Test
////    public void goodsDetails(){
////        Long id = 68L;
////        MallGoods mallGoods = mallGoodsMapper.selectGoodsDetailById(id);
////        if (mallGoods == null) {
////            throw new FebsException("商品不存在");
////        }
////        List<String> images = goodsImagesMapper.selectGoodsImagesByGoodsId(mallGoods.getId());
////        MallGoodsDetailsVo mallGoodsDetailsVo = MallGoodsConversion.INSTANCE.entityToDetailsVo(mallGoods);
////
////        List<GoodsDetailsStyleVo> styles = mallGoodsDetailsVo.getStyles();
////        if(ObjectUtil.isNotEmpty(styles)){
////            for(GoodsDetailsStyleVo goodsDetailsStyleVo : styles){
////                List<GoodsDetailsSkuVo> skus = goodsDetailsStyleVo.getSkus();
////                if(CollUtil.isNotEmpty(skus) ){
////                    for(GoodsDetailsSkuVo goodsDetailsSkuVo : skus){
////                        if(StrUtil.isNotEmpty(goodsDetailsSkuVo.getSample())){
////                            goodsDetailsSkuVo.setSampleFlag(true);
////                        }else{
////                            goodsDetailsSkuVo.setSampleFlag(false);
////                        }
////                    }
////                }
////            }
////        }
////
////        if (CollUtil.isNotEmpty(mallGoods.getStyles())) {
////            Map<String, BigDecimal> stockAndVolume = mallGoodsMapper.selectGoodsStockAndVolume(id);
////            mallGoodsDetailsVo.setStock(stockAndVolume.get("stock").intValue());
////            mallGoodsDetailsVo.setVolume(stockAndVolume.get("volume").intValue());
////        }
////        mallGoodsDetailsVo.setImages(images);
////
////    }
////
////    @Test
////    public void levelTest(){
////        ApiCreateOrderVerifyDto apiCreateOrderVerifyDto = new ApiCreateOrderVerifyDto();
////        List<AddOrderItemDto> addOrderItemDtos = new ArrayList<>();
////        AddOrderItemDto addOrderItemDto = new AddOrderItemDto();
////        addOrderItemDto.setCnt(1);
////        addOrderItemDto.setSkuId(243L);
////        addOrderItemDtos.add(addOrderItemDto);
////        apiCreateOrderVerifyDto.setItems(addOrderItemDtos);
////        MallMember member = mallMemberMapper.selectById(401L);
////        List<AddOrderItemDto> items = apiCreateOrderVerifyDto.getItems();
////        if(CollUtil.isEmpty(items)){
////            System.out.println("请先挑选商品");
////        }
////        for (AddOrderItemDto item : apiCreateOrderVerifyDto.getItems()) {
////            MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
////            if (sku == null) {
////                System.out.println("购买商品或sku不存在");
////            }
////            if("样品".equals(sku.getSample())){
////                List<MallOrderItem> mallOrderItems = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId());
////                if (CollUtil.isNotEmpty(mallOrderItems)) {
////                    System.out.println("样品只能购买一次");
////                }
////                Integer cnt = item.getCnt();
////                if(1 < cnt){
////                    System.out.println("样品只能购买一件");
////                }
////            }else{
////                //验证用户的等级
////                if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){
////                    System.out.println(sku.getSkuName() + "请先申请成为合伙人");
////                }
////            }
////
////            if (sku.getStock() < item.getCnt()) {
////                System.out.println(sku.getSkuName() + "库存不足");
////            }
////
////            MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
////            if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
////                System.out.println(mallGoods.getGoodsName() + "已下架");
////            }
////        }
////    }
//////    @Test
//////    public void skusTest() {
//////        ApiMallAwardDetailsVo apiMallAwardDetailsVo = new ApiMallAwardDetailsVo();
//////        Long memberId = 4L;
//////        Long actId = 1L;
//////        MallMember mallMember = mallMemberMapper.selectById(memberId);
//////        if(ObjectUtil.isEmpty(mallMember)){
//////            throw new FebsException("用户不存在");
//////        }
//////
//////        MallActSet mallActSet = mallActSetMapper.selectById(actId);
//////        if(ObjectUtil.isEmpty(mallActSet)){
//////            throw new FebsException("活动不存在");
//////        }
//////        Integer actStatus = mallActSet.getActStatus();
//////        if(MallActSet.ACT_STATUS_DISABLED == actStatus){
//////            throw new FebsException("活动还没开始");
//////        }
//////        /**
//////         * 获取用户积分数,判断能不能抽奖
//////         * 减少对应的积分数量
//////         * 较少奖品的已抽奖
//////         * 生成一条抽奖记录
//////         */
//////
//////        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
//////        if(ObjectUtil.isEmpty(wallet)){
//////            throw new FebsException("账户不存在");
//////        }
//////        BigDecimal commission = wallet.getCommission();
//////        BigDecimal prizeScore = wallet.getPrizeScore();
//////        Integer actScoreCnt = mallActSet.getActScoreCnt();
//////        if(prizeScore.compareTo(new BigDecimal(actScoreCnt))<0){
//////            throw new FebsException("竞猜积分不足");
//////        }
//////        /**
//////         * 中奖概率 20%
//////         * 每次抽奖产生一个随机数要大于8,则中奖
//////         * 历史10条抽奖记录有中奖过,中奖记录少于两条,则中奖
//////         */
//////        //获取中奖概率
//////        DataDictionaryCustom scoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//////                DataDictionaryEnum.WIN_SCORE.getType(),
//////                DataDictionaryEnum.WIN_SCORE.getCode());
//////        DataDictionaryCustom cashDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//////                DataDictionaryEnum.WIN_CASH.getType(),
//////                DataDictionaryEnum.WIN_CASH.getCode());
//////        String scoreDicValue = scoreDic.getValue();
//////        String cashDicValue = cashDic.getValue();
//////        BigDecimal totalProbability = new BigDecimal(scoreDicValue).add(new BigDecimal(cashDicValue));
//////        //获取那个更大一点的几率
//////        BigDecimal maxProbability = BigDecimal.ZERO;
//////        BigDecimal minProbability = BigDecimal.ZERO;
//////        Integer maxAwardType = 0;
//////        Integer minAwardType = 0;
//////        if(new BigDecimal(scoreDicValue).compareTo(new BigDecimal(cashDicValue)) < 0){
//////            maxProbability = new BigDecimal(cashDicValue);
//////            minProbability = new BigDecimal(scoreDicValue);
//////            maxAwardType = MallActAwardSet.AWARD_TYPE_YJ;
//////            minAwardType = MallActAwardSet.AWARD_TYPE_JF;
//////        }else{
//////            maxProbability = new BigDecimal(scoreDicValue);
//////            minProbability = new BigDecimal(cashDicValue);
//////            maxAwardType = MallActAwardSet.AWARD_TYPE_JF;
//////            minAwardType = MallActAwardSet.AWARD_TYPE_YJ;
//////        }
//////
//////        BigDecimal multiply = totalProbability.multiply(new BigDecimal(100));
//////        BigDecimal failureScope = new BigDecimal(100).subtract(multiply);
//////        int randomInt = 90;
//////        //小于failureScope这个数字,则没中奖
//////        if(new BigDecimal(randomInt).compareTo(failureScope) <= 0){
//////            //抽奖记录
//////            MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////            mallActLuckdrawRecord.setActId(actId);
//////            mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////            mallActLuckdrawRecord.setMemberId(memberId);
//////            mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////            mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////            mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////            List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////            if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////            }else{
//////                apiMallAwardDetailsVo.setAwardName("未中奖");
//////            }
//////        }else if(new BigDecimal(randomInt).compareTo(failureScope) > 0
//////                && new BigDecimal(randomInt).compareTo(failureScope.add(maxProbability.multiply(new BigDecimal(100)))) <= 0){
//////            //大于failureScope.add(maxProbability.multiply(new BigDecimal(100)))这个数字,则中奖
//////            //获取最新的十条抽奖记录
//////            List<MallActLuckdrawRecord> records = mallActLuckdrawRecordMapper.selectRecordByMemberIdAndActId(memberId,actId);
//////            if(CollUtil.isNotEmpty(records)){
//////                //中奖次数
//////                Integer count = 0;
//////                for(MallActLuckdrawRecord mallActLuckdrawRecord : records){
//////                    Integer status = mallActLuckdrawRecord.getStatus();
//////                    if(MallActLuckdrawRecord.STATUS_ENABLE == status){
//////                        count = count + 1;
//////                    }
//////                }
//////                if(new BigDecimal(count).compareTo(maxProbability.multiply(new BigDecimal(10))) < 0){
//////                    //获取活动下该类别的奖品
//////                    List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,maxAwardType);
//////                    if(CollUtil.isEmpty(mallActAwardSets)){
//////                        //抽奖记录
//////                        MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                        mallActLuckdrawRecord.setActId(actId);
//////                        mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                        mallActLuckdrawRecord.setMemberId(memberId);
//////                        mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                        mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                        mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                        List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                        if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                            apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                            apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                        }else{
//////                            apiMallAwardDetailsVo.setAwardName("未中奖");
//////                        }
//////                    }else{
//////                        List<MallActAwardSet> idList = new ArrayList();
//////                        for(MallActAwardSet mallActAwardSet : mallActAwardSets){
//////                            Integer awardTotal = mallActAwardSet.getAwardTotal();
//////                            Integer awardCnt = mallActAwardSet.getAwardCnt();
//////                            if(awardCnt < awardTotal){
//////                                idList.add(mallActAwardSet);
//////                            }
//////                        }
//////                        MallActAwardSet mallActAwardSet = new MallActAwardSet();
//////                        if(idList.size() <= 1){
//////                            mallActAwardSet = idList.get(0);
//////                        }else{
//////                            int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1);
//////                            mallActAwardSet = idList.get(randomIdIndex);
//////                        }
//////                        mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1);
//////                        mallActAwardSetMapper.updateById(mallActAwardSet);
//////
//////                        MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                        mallActLuckdrawRecord.setActId(actId);
//////                        mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                        mallActLuckdrawRecord.setMemberId(memberId);
//////                        mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                        mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE);
//////                        mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                        MallActWinRecord mallActWinRecord = new MallActWinRecord();
//////                        mallActWinRecord.setMemberId(memberId);
//////                        mallActWinRecord.setActId(actId);
//////                        mallActWinRecord.setActName(mallActSet.getActName());
//////                        mallActWinRecord.setAwardId(mallActAwardSet.getId());
//////                        mallActWinRecord.setAwardName(mallActAwardSet.getAwardName());
//////                        mallActWinRecord.setAwardType(mallActAwardSet.getAwardType());
//////                        mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue());
//////                        mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId());
//////                        mallActWinRecordMapper.insert(mallActWinRecord);
//////
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName());
//////                        apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType());
//////                        apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue());
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage());
//////
//////                        if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){
//////                            prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                        }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){
//////                            commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                        }
//////                    }
//////                }else{
//////                    //抽奖记录
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                    if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                    }else{
//////                        apiMallAwardDetailsVo.setAwardName("未中奖");
//////                    }
//////                }
//////            }else{
//////                //获取活动下该类别的奖品
//////                List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,maxAwardType);
//////                if(CollUtil.isEmpty(mallActAwardSets)){
//////                    //抽奖记录
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                    if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                    }else{
//////                        apiMallAwardDetailsVo.setAwardName("未中奖");
//////                    }
//////                }else{
//////                    List<MallActAwardSet> idList = new ArrayList();
//////                    for(MallActAwardSet mallActAwardSet : mallActAwardSets){
//////                        Integer awardTotal = mallActAwardSet.getAwardTotal();
//////                        Integer awardCnt = mallActAwardSet.getAwardCnt();
//////                        if(awardCnt < awardTotal){
//////                            idList.add(mallActAwardSet);
//////                        }
//////                    }
//////                    MallActAwardSet mallActAwardSet = new MallActAwardSet();
//////                    if(idList.size() <= 1){
//////                        mallActAwardSet = idList.get(0);
//////                    }else{
//////                        int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1);
//////                        mallActAwardSet = idList.get(randomIdIndex);
//////                    }
//////                    mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1);
//////                    mallActAwardSetMapper.updateById(mallActAwardSet);
//////
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    MallActWinRecord mallActWinRecord = new MallActWinRecord();
//////                    mallActWinRecord.setMemberId(memberId);
//////                    mallActWinRecord.setActId(actId);
//////                    mallActWinRecord.setActName(mallActSet.getActName());
//////                    mallActWinRecord.setAwardId(mallActAwardSet.getId());
//////                    mallActWinRecord.setAwardName(mallActAwardSet.getAwardName());
//////                    mallActWinRecord.setAwardType(mallActAwardSet.getAwardType());
//////                    mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue());
//////                    mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId());
//////                    mallActWinRecordMapper.insert(mallActWinRecord);
//////
//////                    apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName());
//////                    apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType());
//////                    apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue());
//////                    apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage());
//////
//////                    if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){
//////                        prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                    }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){
//////                        commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                    }
//////                }
//////            }
//////        }else{
//////            //中奖
//////            //获取最新的十条抽奖记录
//////            List<MallActLuckdrawRecord> records = mallActLuckdrawRecordMapper.selectRecordByMemberIdAndActId(memberId,actId);
//////            if(CollUtil.isNotEmpty(records)){
//////                //中奖次数
//////                Integer count = 0;
//////                for(MallActLuckdrawRecord mallActLuckdrawRecord : records){
//////                    Integer status = mallActLuckdrawRecord.getStatus();
//////                    if(MallActLuckdrawRecord.STATUS_ENABLE == status){
//////                        count = count + 1;
//////                    }
//////                }
//////                if(new BigDecimal(count).compareTo(minProbability.multiply(new BigDecimal(10))) < 0){
//////                    //获取活动下该类别的奖品
//////                    List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,minAwardType);
//////                    if(CollUtil.isEmpty(mallActAwardSets)){
//////                        //抽奖记录
//////                        MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                        mallActLuckdrawRecord.setActId(actId);
//////                        mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                        mallActLuckdrawRecord.setMemberId(memberId);
//////                        mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                        mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                        mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                        List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                        if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                            apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                            apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                        }else{
//////                            apiMallAwardDetailsVo.setAwardName("未中奖");
//////                        }
//////                    }else{
//////                        List<MallActAwardSet> idList = new ArrayList();
//////                        for(MallActAwardSet mallActAwardSet : mallActAwardSets){
//////                            Integer awardTotal = mallActAwardSet.getAwardTotal();
//////                            Integer awardCnt = mallActAwardSet.getAwardCnt();
//////                            if(awardCnt < awardTotal){
//////                                idList.add(mallActAwardSet);
//////                            }
//////                        }
//////                        MallActAwardSet mallActAwardSet = new MallActAwardSet();
//////                        if(idList.size() <= 1){
//////                            mallActAwardSet = idList.get(0);
//////                        }else{
//////                            int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1);
//////                            mallActAwardSet = idList.get(randomIdIndex);
//////                        }
//////                        mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1);
//////                        mallActAwardSetMapper.updateById(mallActAwardSet);
//////
//////                        MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                        mallActLuckdrawRecord.setActId(actId);
//////                        mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                        mallActLuckdrawRecord.setMemberId(memberId);
//////                        mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                        mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE);
//////                        mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                        MallActWinRecord mallActWinRecord = new MallActWinRecord();
//////                        mallActWinRecord.setMemberId(memberId);
//////                        mallActWinRecord.setActId(actId);
//////                        mallActWinRecord.setActName(mallActSet.getActName());
//////                        mallActWinRecord.setAwardId(mallActAwardSet.getId());
//////                        mallActWinRecord.setAwardName(mallActAwardSet.getAwardName());
//////                        mallActWinRecord.setAwardType(mallActAwardSet.getAwardType());
//////                        mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue());
//////                        mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId());
//////                        mallActWinRecordMapper.insert(mallActWinRecord);
//////
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName());
//////                        apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType());
//////                        apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue());
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage());
//////
//////                        if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){
//////                            prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                        }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){
//////                            commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                        }
//////                    }
//////                }else{
//////                    //抽奖记录
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                    if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                    }else{
//////                        apiMallAwardDetailsVo.setAwardName("未中奖");
//////                    }
//////                }
//////            }else{
//////                //获取活动下该类别的奖品
//////                List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,minAwardType);
//////                if(CollUtil.isEmpty(mallActAwardSets)){
//////                    //抽奖记录
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY);
//////                    if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){
//////                        apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage());
//////                        apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName());
//////                    }else{
//////                        apiMallAwardDetailsVo.setAwardName("未中奖");
//////                    }
//////                }else{
//////                    List<MallActAwardSet> idList = new ArrayList();
//////                    for(MallActAwardSet mallActAwardSet : mallActAwardSets){
//////                        Integer awardTotal = mallActAwardSet.getAwardTotal();
//////                        Integer awardCnt = mallActAwardSet.getAwardCnt();
//////                        if(awardCnt < awardTotal){
//////                            idList.add(mallActAwardSet);
//////                        }
//////                    }
//////                    MallActAwardSet mallActAwardSet = new MallActAwardSet();
//////                    if(idList.size() <= 1){
//////                        mallActAwardSet = idList.get(0);
//////                    }else{
//////                        int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1);
//////                        mallActAwardSet = idList.get(randomIdIndex);
//////                    }
//////                    mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1);
//////                    mallActAwardSetMapper.updateById(mallActAwardSet);
//////
//////                    MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord();
//////                    mallActLuckdrawRecord.setActId(actId);
//////                    mallActLuckdrawRecord.setActName(mallActSet.getActName());
//////                    mallActLuckdrawRecord.setMemberId(memberId);
//////                    mallActLuckdrawRecord.setActScoreCnt(actScoreCnt);
//////                    mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE);
//////                    mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord);
//////
//////                    MallActWinRecord mallActWinRecord = new MallActWinRecord();
//////                    mallActWinRecord.setMemberId(memberId);
//////                    mallActWinRecord.setActId(actId);
//////                    mallActWinRecord.setActName(mallActSet.getActName());
//////                    mallActWinRecord.setAwardId(mallActAwardSet.getId());
//////                    mallActWinRecord.setAwardName(mallActAwardSet.getAwardName());
//////                    mallActWinRecord.setAwardType(mallActAwardSet.getAwardType());
//////                    mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue());
//////                    mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId());
//////                    mallActWinRecordMapper.insert(mallActWinRecord);
//////
//////                    apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName());
//////                    apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType());
//////                    apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue());
//////                    apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage());
//////
//////                    if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){
//////                        prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                    }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){
//////                        commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue()));
//////                    }
//////                }
//////            }
//////        }
//////
//////        //扣竞猜积分
//////        prizeScore = prizeScore.subtract(new BigDecimal(actScoreCnt));
//////        wallet.setPrizeScore(prizeScore);
//////        wallet.setCommission(commission);
//////        mallMemberWalletMapper.updateAmountWithVersion(wallet);
//////
//////        System.out.println(apiMallAwardDetailsVo);
//////    }
//////
//////    @Test
//////    public void agentTest() {
////////        agentProducer.sendDelayMsg(1L, 10000L);
//////
//////        ApiMallActWinDetailsDto apiMallActWinDetailsDto = new ApiMallActWinDetailsDto();
//////        apiMallActWinDetailsDto.setActId(1L);
//////        apiMallActWinDetailsDto.setPageNow(1);
//////        apiMallActWinDetailsDto.setPageSize(10);
//////        Long memberId = 4L;
//////        MallMember mallMember = mallMemberMapper.selectById(memberId);
//////        if(ObjectUtil.isEmpty(mallMember)){
//////            throw new FebsException("用户不存在");
//////        }
//////        apiMallActWinDetailsDto.setMemberId(memberId);
//////
//////        Long actId = apiMallActWinDetailsDto.getActId();
//////        MallActSet mallActSet = mallActSetMapper.selectById(actId);
//////        if(ObjectUtil.isEmpty(mallActSet)){
//////            throw new FebsException("活动不存在");
//////        }
//////        Page<ApiMallActWinDetailsVo> page = new Page<>(apiMallActWinDetailsDto.getPageNow(), apiMallActWinDetailsDto.getPageSize());
//////        IPage<ApiMallActWinDetailsVo> apiMallActWinDetailsVoIPage = mallActWinRecordMapper.selectApiMallActWinDetailsListInPage(apiMallActWinDetailsDto, page);
//////        System.out.println(apiMallActWinDetailsVoIPage);
//////    }
//////
//////    @Test
//////    public void insertAgentTest() {
////////        AgentInfo agentInfo = new AgentInfo();
////////        agentInfo.setOrderType(2);
////////        agentInfo.setOrderCnt(2000);
////////        agentInfo.setLastCnt(3);
////////        agentInfo.setDirectIncome(BigDecimal.valueOf(50));
////////        agentInfo.setTeamIncome(BigDecimal.valueOf(15));
////////        agentInfo.setTeamIncomeType(2);
////////
////////        DataDictionaryCustom data = new DataDictionaryCustom();
////////        data.setType("AGENT_LEVEL_REQUIRE");
////////        data.setCode(AgentLevelEnum.FOUR_LEVEL.name());
////////        data.setValue(JSONObject.toJSONString(agentInfo));
////////        dataDictionaryCustomMapper.insert(data);
//////    }
//////
//////    @Test
//////    public void insertData() {
//////        int i = 1;
//////        for (AgentLevelEnum value : AgentLevelEnum.values()) {
//////            DataDictionaryCustom data = new DataDictionaryCustom();
//////            data.setType("AGENT_LEVEL");
//////            data.setDescription(value.getName());
//////            data.setCode(value.name());
//////            data.setValue(String.valueOf(i));
//////            dataDictionaryCustomMapper.insert(data);
//////        }
//////
//////    }
//////
//////    public static void main(String[] args) {
//////        getJson();
//////    }
//////
//////    public static void getJson(){
//////        AgentLevelUpdateDto adminAgentLevelUpdateInfoVo = new AgentLevelUpdateDto();
//////        String jsonStr = "{\"directIncome\":50,\"lastCnt\":3,\"orderCnt\":2000,\"orderType\":2,\"teamIncome\":15,\"teamIncomeType\":2}";
//////        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
//////        adminAgentLevelUpdateInfoVo.setDirectIncome(new BigDecimal((jsonObject.get("directIncome")==null?0:jsonObject.get("directIncome")).toString()));
//////        adminAgentLevelUpdateInfoVo.setLastCnt(Integer.parseInt((jsonObject.get("lastCnt")==null?0:jsonObject.get("lastCnt")).toString()));
//////        adminAgentLevelUpdateInfoVo.setOrderCnt(Integer.parseInt((jsonObject.get("orderCnt")==null?0:jsonObject.get("orderCnt")).toString()));
//////        adminAgentLevelUpdateInfoVo.setOrderType(Integer.parseInt(jsonObject.get("orderType").toString()));
//////        adminAgentLevelUpdateInfoVo.setTeamIncome(new BigDecimal((jsonObject.get("teamIncome")==null?0:jsonObject.get("teamIncome")).toString()));
//////        adminAgentLevelUpdateInfoVo.setTeamIncomeType(Integer.parseInt(jsonObject.get("orderType").toString()));
//////        adminAgentLevelUpdateInfoVo.setId(14L);
//////        AgentLevelUpdateDto agentLevelUpdateDtoJson = new AgentLevelUpdateDto();
//////        agentLevelUpdateDtoJson.setDirectIncome(adminAgentLevelUpdateInfoVo.getDirectIncome());
//////        agentLevelUpdateDtoJson.setLastCnt(adminAgentLevelUpdateInfoVo.getLastCnt());
//////        agentLevelUpdateDtoJson.setOrderCnt(adminAgentLevelUpdateInfoVo.getOrderCnt());
//////        agentLevelUpdateDtoJson.setTeamIncome(adminAgentLevelUpdateInfoVo.getTeamIncome());
//////        agentLevelUpdateDtoJson.setOrderType(adminAgentLevelUpdateInfoVo.getOrderType());
//////        agentLevelUpdateDtoJson.setTeamIncomeType(adminAgentLevelUpdateInfoVo.getTeamIncomeType());
//////        JSONObject jsonObjectA = (JSONObject)JSONObject.toJSON(agentLevelUpdateDtoJson);
//////        System.out.println(jsonObjectA.toJSONString());
//////    }
//////
//////    @Test
//////    public void autoLevelUp() {
//////        // agentService.autoUpAgentLevel(3L);
////////        agentProducer.sendAutoLevelUpMsg(5L);
//////
//////        agentProducer.sendReturnMoneyMsg(2L);
//////    }
//////
//////    @Test
//////    public void returnMoney() {
//////        // agentService.autoUpAgentLevel(3L);
////////        agentProducer.sendAutoLevelUpMsg(5L);
////////        agentProducer.sendReturnMoneyMsg(52L);
//////        agentService.returnMoneyToAgent(52L);
//////    }
//////
//////    @Test
//////    public void bigdecimalTest() {
//////        BigDecimal aa = new BigDecimal("1.345");
//////
//////        System.out.println(aa.setScale(2, RoundingMode.DOWN));
//////        System.out.println(aa.setScale(2, RoundingMode.UP));
//////    }
//////
//////    @Autowired
//////    private ProfitJob profitJob;
//////
//////    @Test
//////    public void profitJobTest() {
//////        profitJob.profitJob();
//////    }
//////
//////
////    @Autowired
////    private AgentConsumer agentConsumer;
////
////    @Test
////    public void orderReturnTest() {
////        agentConsumer.getScoreMsg(215L);
////    }
//}
package cc.mrbird.febs;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.pay.model.RefundStatus;
import cc.mrbird.febs.pay.util.FiuuRefundUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@Slf4j
@SpringBootTest
public class AgentTest {
    @Autowired
    private MallActivityMapper mallActivityMapper;
    @Autowired
    private MallRefundMapper mallRefundMapper;
    @Autowired
    private MallOrderInfoMapper mallOrderInfoMapper;
    @Autowired
    private MallOrderItemMapper mallOrderItemMapper;
    @Autowired
    private MallGoodsSkuMapper mallGoodsSkuMapper;
    @Autowired
    private MallGoodsMapper mallGoodsMapper;
    @Autowired
    private FiuuRefundUtil fiuuRefundUtil;
    @Autowired
    private IMallMoneyFlowService mallMoneyFlowService;
    @Test
    public void refundJob() {
        LambdaQueryWrapper<MallRefundEntity> mallOrderRefundLambdaQueryWrapper = new LambdaQueryWrapper<>();
        mallOrderRefundLambdaQueryWrapper.eq(MallRefundEntity::getState, 3);
        mallOrderRefundLambdaQueryWrapper.eq(MallRefundEntity::getType, 1);
        List<MallRefundEntity> mallRefundEntities = mallRefundMapper.selectList(mallOrderRefundLambdaQueryWrapper);
        if(CollUtil.isEmpty(mallRefundEntities)){
            return;
        }
        mallRefundEntities.forEach(mallRefundEntity -> {
            processRefund(mallRefundEntity);
        });
    }
    private void processRefund(MallRefundEntity mallRefundEntity) {
        try {
            MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectById(mallRefundEntity.getOrderId());
            MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(mallRefundEntity.getItemId());
            MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(mallOrderItem.getSkuId());
            String txnId = mallOrderInfo.getPayOrderNo();
            RefundStatus status = fiuuRefundUtil.pollRefundStatus(txnId);
            switch (status.getStatus()) {
                case "success":
                    updateOnSuccess(mallRefundEntity, mallOrderInfo, mallOrderItem, mallGoodsSku);
                    break;
                case "rejected":
                    updateOnRejected(mallRefundEntity, mallOrderItem);
                    break;
                default:
                    log.warn("未知状态:{}", status.getStatus());
            }
        } catch (Exception e) {
            log.error("处理退款失败: {}", e.getMessage(), e);
        }
    }
    private void updateOnSuccess(MallRefundEntity mallRefundEntity, MallOrderInfo mallOrderInfo, MallOrderItem mallOrderItem, MallGoodsSku mallGoodsSku) {
        mallOrderItem.setState(3);
        mallOrderItemMapper.updateById(mallOrderItem);
        MallGoods mallGoods = mallGoodsMapper.selectById(mallOrderItem.getGoodsId());
        mallGoods.setStock(mallGoods.getStock() + mallOrderItem.getCnt());
        mallGoods.setVolume(mallGoods.getVolume() - mallOrderItem.getCnt());
        mallGoodsMapper.updateById(mallGoods);
        mallGoodsSku.setStock(mallGoodsSku.getStock() + mallOrderItem.getCnt());
        mallGoodsSku.setSkuVolume(mallGoodsSku.getSkuVolume() - mallOrderItem.getCnt());
        mallGoodsSkuMapper.updateById(mallGoodsSku);
        mallRefundEntity.setState(1);
        mallRefundEntity.setUpdatedTime(DateUtil.date());
        mallRefundMapper.updateById(mallRefundEntity);
        mallMoneyFlowService.addMoneyFlow(
                mallOrderInfo.getMemberId(),
                mallRefundEntity.getAmount(),
                MoneyFlowTypeEnum.WECHAT_REFUND.getValue(),
                mallOrderInfo.getOrderNo(),
                FlowTypeEnum.WECHAT.getValue(),
                "FIUU退款",
                2);
        List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByNotInStateAndOrderId(3, mallRefundEntity.getOrderId());
        if (CollUtil.isEmpty(mallOrderItemList)) {
            MallOrderInfo mallOrderRefund = mallOrderInfoMapper.selectById(mallRefundEntity.getOrderId());
            mallOrderRefund.setStatus(6);
            mallOrderInfoMapper.updateById(mallOrderRefund);
        }
    }
    private void updateOnRejected(MallRefundEntity mallRefundEntity, MallOrderItem mallOrderItem) {
        mallOrderItem.setState(1);
        mallOrderItemMapper.updateById(mallOrderItem);
        mallRefundEntity.setState(2);
        mallRefundMapper.updateById(mallRefundEntity);
    }
}