From 62fc17e246f99c73f162f243490a811e540c0043 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Fri, 07 Feb 2025 14:34:00 +0800 Subject: [PATCH] fix: 修改文件名大小写 --- src/test/java/cc/mrbird/febs/AgentTest.java | 181 ++++++++++++++++++++++++--------------------- 1 files changed, 97 insertions(+), 84 deletions(-) diff --git a/src/test/java/cc/mrbird/febs/AgentTest.java b/src/test/java/cc/mrbird/febs/AgentTest.java index 5b62509..b3cf218 100644 --- a/src/test/java/cc/mrbird/febs/AgentTest.java +++ b/src/test/java/cc/mrbird/febs/AgentTest.java @@ -1,114 +1,127 @@ package cc.mrbird.febs; -import cc.mrbird.febs.common.enumerates.AgentLevelEnum; -import cc.mrbird.febs.mall.dto.AgentLevelUpdateDto; -import cc.mrbird.febs.mall.entity.AgentInfo; -import cc.mrbird.febs.mall.entity.DataDictionaryCustom; -import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper; -import cc.mrbird.febs.mall.service.IAgentService; -import cc.mrbird.febs.rabbit.producter.AgentProducer; -import com.alibaba.fastjson.JSONObject; +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.aspectj.weaver.loadtime.Agent; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import java.math.BigDecimal; -import java.math.RoundingMode; +import java.util.List; -/** - * @author wzy - * @date 2021-09-25 - **/ @Slf4j @SpringBootTest public class AgentTest { @Autowired - private AgentProducer agentProducer; + private MallActivityMapper mallActivityMapper; @Autowired - private DataDictionaryCustomMapper dataDictionaryCustomMapper; + private MallRefundMapper mallRefundMapper; @Autowired - private IAgentService agentService; + 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 agentTest() { -// agentProducer.sendDelayMsg(1L, 10000L); - } - - @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 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); + }); } - public static void main(String[] args) { - getJson(); + 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); + } } - 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()); + 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); + } } - @Test - public void autoLevelUp() { - // agentService.autoUpAgentLevel(3L); - agentProducer.sendAutoLevelUpMsg(9L); + private void updateOnRejected(MallRefundEntity mallRefundEntity, MallOrderItem mallOrderItem) { + mallOrderItem.setState(1); + mallOrderItemMapper.updateById(mallOrderItem); -// agentProducer.sendReturnMoneyMsg(24L); + mallRefundEntity.setState(2); + mallRefundMapper.updateById(mallRefundEntity); } - @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)); - } } -- Gitblit v1.9.1