xiaoyong931011
2021-09-25 f6b8f3b4e6419e5675bf400e005b8ba115fb1dc1
Merge branch 'master' of http://120.27.238.55:7000/r/xc-mall
8 files added
9 files modified
294 ■■■■■ changed files
pom.xml 17 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java 50 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/entity/AgentInfo.java 44 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/vo/MallMemberVo.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/constants/ExchangeConstants.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/constants/RouteKeyConstants.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java 47 ●●●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 8 ●●●● patch | view | raw | blame | history
src/main/resources/application-prod.yml 8 ●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 8 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/MallMemberPaymentMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/MallMoneyFlowMapper.xml 4 ●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/AgentTest.java 24 ●●●●● patch | view | raw | blame | history
pom.xml
@@ -267,6 +267,23 @@
            <artifactId>mapstruct</artifactId>
            <version>${mapstruct.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
New file
@@ -0,0 +1,50 @@
package cc.mrbird.febs.common.configure;
import cc.mrbird.febs.rabbit.constants.ExchangeConstants;
import cc.mrbird.febs.rabbit.constants.QueueConstants;
import cc.mrbird.febs.rabbit.constants.RouteKeyConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Configuration
public class RabbitConfigure {
    @Resource
    private ConnectionFactory connectionFactory;
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }
    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(ExchangeConstants.EXCHANGE_DEFAULT);
    }
    @Bean
    public Queue defaultQueue() {
        return new Queue(QueueConstants.QUEUE_DEFAULT);
    }
    @Bean
    public Binding defaultBind() {
        return BindingBuilder.bind(defaultQueue()).to(defaultExchange()).with(RouteKeyConstants.ROUTE_KEY_DEFAULT);
    }
}
src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java
@@ -60,7 +60,7 @@
    @ApiOperation(value = "修改用户信息")
    @PostMapping(value = "/modifyInfo")
    public FebsResponse modifyInfo(ModifyMemberInfoDto modifyMemberInfoDto) {
    public FebsResponse modifyInfo(@RequestBody ModifyMemberInfoDto modifyMemberInfoDto) {
        return memberService.modifyMemberInfo(modifyMemberInfoDto);
    }
src/main/java/cc/mrbird/febs/mall/entity/AgentInfo.java
New file
@@ -0,0 +1,44 @@
package cc.mrbird.febs.mall.entity;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Data
public class AgentInfo {
    /**
     * 下单数量要求 1-直推 2-团队
     */
    private Integer orderType;
    /**
     * 下单数量
     */
    private Integer orderCnt;
    /**
     * 需要上一级的数量
     */
    private Integer lastCnt;
    /**
     * 直推收益
     */
    private BigDecimal directIncome;
    /**
     * 团队收益
     */
    private BigDecimal TeamIncome;
    /**
     * 团队收益 1-指定金额 2-比例
     */
    private BigDecimal teamIncomeType;
}
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -211,6 +211,15 @@
            mallMemberVo.setReferrerName(referMember.getName());
        }
        if (StrUtil.isNotBlank(mallMember.getTradePassword())) {
            mallMemberVo.setHasTradePwd(1);
        }
        MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(id);
        if (payment != null) {
            mallMemberVo.setHasPayment(1);
        }
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(mallMemberVo.getId());
        mallMemberVo.setBalance(wallet.getBalance());
        return new FebsResponse().success().data(mallMemberVo);
@@ -329,6 +338,10 @@
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember loginMember = this.baseMapper.selectById(memberId);
        if (StrUtil.isBlank(loginMember.getTradePassword())) {
            throw new FebsException("未设置支付密码");
        }
        if (!loginMember.getTradePassword().equals(SecureUtil.md5(transferDto.getTradePwd()))) {
            throw new FebsException("支付密码错误");
        }
@@ -345,6 +358,10 @@
    public void withdrawal(WithdrawalDto withdrawalDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = this.baseMapper.selectById(memberId);
        if (StrUtil.isBlank(mallMember.getTradePassword())) {
            throw new FebsException("未设置支付密码");
        }
        if (!mallMember.getTradePassword().equals(SecureUtil.md5(withdrawalDto.getTradePwd()))) {
            throw new FebsException("支付密码错误");
        }
@@ -353,6 +370,11 @@
            throw new FebsException("最小提现金额为100");
        }
        MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(memberId);
        if (payment == null) {
            throw new FebsException("未设置收款方式");
        }
        walletService.reduceBalance(withdrawalDto.getAmount(), memberId);
        String orderNo = MallUtils.getOrderNum("W");
        this.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1);
src/main/java/cc/mrbird/febs/mall/vo/MallMemberVo.java
@@ -54,4 +54,10 @@
    public static final int ACCOUNTSTATUS_Y = 1;
    public static final int ACCOUNTSTATUS_N = 2;
    @ApiModelProperty(value = "是否设置收款方式", example = "1是2否")
    private Integer hasPayment = 2;
    @ApiModelProperty(value = "是否设置交易密码", example = "1是2否")
    private Integer hasTradePwd = 2;
}
src/main/java/cc/mrbird/febs/rabbit/constants/ExchangeConstants.java
New file
@@ -0,0 +1,10 @@
package cc.mrbird.febs.rabbit.constants;
/**
 * @author wzy
 * @date 2021-09-25
 **/
public class ExchangeConstants {
    public static final String EXCHANGE_DEFAULT = "exchange_default";
}
src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
New file
@@ -0,0 +1,10 @@
package cc.mrbird.febs.rabbit.constants;
/**
 * @author wzy
 * @date 2021-09-25
 **/
public class QueueConstants {
    public static final String QUEUE_DEFAULT = "queue_default";
}
src/main/java/cc/mrbird/febs/rabbit/constants/RouteKeyConstants.java
New file
@@ -0,0 +1,10 @@
package cc.mrbird.febs.rabbit.constants;
/**
 * @author wzy
 * @date 2021-09-25
 **/
public class RouteKeyConstants {
    public static final String ROUTE_KEY_DEFAULT = "route_key_default";
}
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
New file
@@ -0,0 +1,22 @@
package cc.mrbird.febs.rabbit.consumer;
import cc.mrbird.febs.rabbit.constants.QueueConstants;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Slf4j
@Component
public class AgentConsumer {
    @RabbitListener(queues = QueueConstants.QUEUE_DEFAULT)
    public void agentReturn(Message message, Channel channel) {
        log.info("消费者:{}", new String(message.getBody()));
    }
}
src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
New file
@@ -0,0 +1,47 @@
package cc.mrbird.febs.rabbit.producter;
import cc.mrbird.febs.rabbit.constants.ExchangeConstants;
import cc.mrbird.febs.rabbit.constants.RouteKeyConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Slf4j
@Component
public class AgentProducer implements RabbitTemplate.ConfirmCallback {
    /**
     * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
     */
    private RabbitTemplate rabbitTemplate;
    /**
     * 在构造方法上注入RabbitTemplate
     *
     * @param
     */
    @Autowired
    public AgentProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    }
    public void sendOrderReturn(Long id) {
        log.info("发送消息:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(ExchangeConstants.EXCHANGE_DEFAULT, RouteKeyConstants.ROUTE_KEY_DEFAULT, id, correlationData);
    }
}
src/main/resources/application-dev.yml
@@ -40,4 +40,10 @@
        # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: 10000
    # 连接超时时间(毫秒)
    timeout: 5000
    timeout: 5000
  rabbitmq:
    host: 120.27.238.55
    port: 5672
    username: ct_rabbit
    password: 123456
    publisher-confirm-type: correlated
src/main/resources/application-prod.yml
@@ -46,4 +46,10 @@
        # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: 10000
    # 连接超时时间(毫秒)
    timeout: 5000
    timeout: 5000
  rabbitmq:
    host: 120.27.238.55
    port: 5672
    username: ct_rabbit
    password: 123456
    publisher-confirm-type: correlated
src/main/resources/application-test.yml
@@ -40,4 +40,10 @@
        # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: 10000
    # 连接超时时间(毫秒)
    timeout: 5000
    timeout: 5000
  rabbitmq:
    host: 120.27.238.55
    port: 5672
    username: ct_rabbit
    password: 123456
    publisher-confirm-type: correlated
src/main/resources/mapper/modules/MallMemberPaymentMapper.xml
@@ -3,7 +3,7 @@
<mapper namespace="cc.mrbird.febs.mall.mapper.MallMemberPaymentMapper">
    <select id="selectByMemberId" resultType="cc.mrbird.febs.mall.entity.MallMemberPayment">
        select * from mall_member_payment where member_id=#{id}
        select * from mall_member_payment where member_id=#{memberId}
    </select>
    <select id="getMallMemberPaymentInfoByMemberId" resultType="cc.mrbird.febs.mall.vo.AdminMallMemberPaymentVo">
src/main/resources/mapper/modules/MallMoneyFlowMapper.xml
@@ -14,10 +14,10 @@
        from mall_money_flow a
            inner join mall_member b on a.member_id=b.id
        <where>
            <if test="record.type == 2">
            <if test="record.type == 3">
                and a.amount > 0
            </if>
            <if test="record.type == 3">
            <if test="record.type == 2">
                and 0 > a.amount
            </if>
            <if test="record.memberId != null">
src/test/java/cc/mrbird/febs/AgentTest.java
New file
@@ -0,0 +1,24 @@
package cc.mrbird.febs;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
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 AgentProducer agentProducer;
    @Test
    public void agentTest() {
        agentProducer.sendOrderReturn(1L);
    }
}