Helius
2021-06-15 a8ecdb8fccf3805f3ba841bd493a0e6dccb0274d
modify
1 files modified
6 files added
156 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java 73 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/dao/GbzOrderDao.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/entity/GbzOrderEntity.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/GbzAddDto.java 18 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/GbzListDto.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/websocket/TradePlateSendWebSocket.java 1 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/walletCoinOrder/GbzOrderDao.xml 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java
New file
@@ -0,0 +1,73 @@
package com.xcong.excoin.modules.coin.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.coin.dao.GbzOrderDao;
import com.xcong.excoin.modules.coin.entity.GbzOrderEntity;
import com.xcong.excoin.modules.coin.parameter.dto.GbzAddDto;
import com.xcong.excoin.modules.coin.parameter.dto.GbzListDto;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
@Slf4j
@Validated
@RestController
@RequestMapping(value = "/api/gbz")
@Api(value = "GbzOrderController", tags = "gbz订单接口类")
public class GbzOrderController {
    @Autowired
    private GbzOrderDao gbzOrderDao;
    @Autowired
    private MemberWalletCoinDao memberWalletCoinDao;
    @ApiOperation(value = "新增订单", notes = "新增订单")
    @PostMapping(value = "/add")
    public Result add(@RequestBody GbzAddDto gbzAddDto) {
        MemberEntity loginUser = LoginUserUtils.getAppLoginUser();
        BigDecimal price = new BigDecimal(66);
        BigDecimal amount = BigDecimal.valueOf(gbzAddDto.getCount()).multiply(price);
        GbzOrderEntity gbzOrder = new GbzOrderEntity();
        gbzOrder.setPrice(price);
        gbzOrder.setAmount(amount);
        gbzOrder.setCnt(gbzAddDto.getCount());
        gbzOrder.setMemberId(loginUser.getId());
        gbzOrder.setSymbol(CoinTypeEnum.BZZ.name());
        gbzOrderDao.insert(gbzOrder);
        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(loginUser.getId(), CoinTypeEnum.USDT.name());
        memberWalletCoinDao.updateBlockBalance(wallet.getId(), amount.negate(), BigDecimal.ZERO, 0);
        return Result.ok("购买成功");
    }
    @ApiOperation(value = "获取订单列表")
    @PostMapping(value = "/findList")
    public Result findList(@RequestBody GbzListDto gbzListDto) {
        Page<GbzOrderEntity> page = new Page<>(gbzListDto.getPageNum(), gbzListDto.getPageSize());
        IPage<GbzOrderEntity> result = gbzOrderDao.selectInPage(page);
        return Result.ok(result.getRecords());
    }
    @ApiOperation(value = "获取最新价")
    @GetMapping(value = "/findPrice")
    public Result findPrice() {
        return Result.ok(BigDecimal.valueOf(66));
    }
}
src/main/java/com/xcong/excoin/modules/coin/dao/GbzOrderDao.java
New file
@@ -0,0 +1,11 @@
package com.xcong.excoin.modules.coin.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.modules.coin.entity.GbzOrderEntity;
public interface GbzOrderDao extends BaseMapper<GbzOrderEntity> {
    IPage<GbzOrderEntity> selectInPage(Page<GbzOrderEntity> page);
}
src/main/java/com/xcong/excoin/modules/coin/entity/GbzOrderEntity.java
New file
@@ -0,0 +1,23 @@
package com.xcong.excoin.modules.coin.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xcong.excoin.common.system.base.BaseEntity;
import lombok.Data;
import java.math.BigDecimal;
@Data
@TableName("gbz_order")
public class GbzOrderEntity extends BaseEntity {
    private BigDecimal price;
    private BigDecimal amount;
    private Integer cnt;
    private Long memberId;
    private String symbol;
}
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/GbzAddDto.java
New file
@@ -0,0 +1,18 @@
package com.xcong.excoin.modules.coin.parameter.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel(value = "GbzAddDto", description = "订单新增接口参数接受类")
public class GbzAddDto {
    @ApiModelProperty(value = "数量")
    @NotNull(message = "数量不能为空")
    private Integer count;
}
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/GbzListDto.java
New file
@@ -0,0 +1,21 @@
package com.xcong.excoin.modules.coin.parameter.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel(value = "GbzListDto", description = "订单列表接口参数类")
public class GbzListDto {
    @NotNull(message = "参数错误")
    @ApiModelProperty(value = "当前页", example = "1")
    private Integer pageNum;
    @NotNull(message = "参数错误")
    @ApiModelProperty(value = "条数", example = "10")
    private Integer pageSize;
}
src/main/java/com/xcong/excoin/websocket/TradePlateSendWebSocket.java
@@ -79,6 +79,7 @@
    public void onMessage(String message, Session session) {
        // 盘口订阅方法 {sub: 'market.btcusdt.depth.10,id: symbol}
        JSONObject jsonObject = JSON.parseObject(message);
        log.info("订阅参数:{}", jsonObject);
        // 盘口的判断
        if (jsonObject.containsKey("sub") && jsonObject.get("sub").toString().contains("depth")) {
src/main/resources/mapper/walletCoinOrder/GbzOrderDao.xml
New file
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xcong.excoin.modules.coin.dao.GbzOrderDao">
    <select id="selectInPage" resultType="com.xcong.excoin.modules.coin.entity.GbzOrderEntity">
        select * from gbz_order
        order by create_time desc
    </select>
</mapper>