From 6107e978c64bc7ca9b3a238444e899932434e21d Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 21 Aug 2020 15:13:33 +0800
Subject: [PATCH] Merge branch 'whole' of https://gitee.com/chonggaoxiao/new_excoin into whole

---
 src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java |   27 ++++++
 src/main/resources/i18n/messages_zh_CN.properties                                    |    1 
 src/main/resources/mapper/member/MemberWalletContractDao.xml                         |    6 +
 src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java           |   26 ++++++
 src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java       |    4 +
 src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java        |  114 ++++++++++++++++++++++++++++
 src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java                 |    4 +
 src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ContractSymbolListVo.java   |   14 +++
 src/main/resources/i18n/messages_en_US.properties                                    |    1 
 9 files changed, 197 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java b/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
index deb78e0..7166929 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -6,6 +6,7 @@
 import javax.validation.Valid;
 
 import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
+import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberAgentIntoInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
@@ -21,6 +22,7 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.coin.parameter.dto.ContractInTransferDto;
 import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
 import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceDto;
 import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceFromAgentDto;
@@ -211,6 +213,19 @@
 	}
 	
 	/**
+	 * 合约账户内部划转(合约多账户)
+	 * @return
+	 */
+	@ApiOperation(value="合约账户内部划转(合约多账户)", notes="合约账户内部划转(合约多账户)")
+	@PostMapping(value="/contractInTransfer")
+	public Result contractInTransfer(@RequestBody @Valid ContractInTransferDto contractInTransferDto) {
+		BigDecimal balance = contractInTransferDto.getBalance();
+		String symbolIn = contractInTransferDto.getSymbolIn();
+		String symbolOut = contractInTransferDto.getSymbolOut();
+		return coinService.contractInTransfer(balance,symbolIn,symbolOut);
+	}
+	
+	/**
 	 * 代理账户划转到USDT账户
 	 * @return
 	 */
@@ -235,5 +250,16 @@
 		return coinService.agentTransferToWalletCoins(balance,transfertype,symbol);
 	}
 	
+	/**
+	 * 合约账户列表
+	 * @return
+	 */
+	@ApiOperation(value="合约账户列表", notes="合约账户列表")
+	@ApiResponses({@ApiResponse( code = 200, message = "success", response = ContractSymbolListVo.class)})
+	@GetMapping(value="/getContractSymbolList")
+	public Result  getContractSymbolList() {
+		return coinService.getContractSymbolList();
+	}
+	
 
 }
diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java
new file mode 100644
index 0000000..4ac829c
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java
@@ -0,0 +1,27 @@
+package com.xcong.excoin.modules.coin.parameter.dto;
+
+import java.math.BigDecimal;
+
+import javax.validation.constraints.NotNull;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "ContractInTransferDto", description = "参数接收类")
+public class ContractInTransferDto {
+	
+	@NotNull(message = "划转金额不能为空")
+    @ApiModelProperty(value = "划转金额", example = "100")
+    private BigDecimal balance;
+
+	@NotNull(message = "币种不能为空")
+    @ApiModelProperty(value = "转入币种", example = "USDT")
+    private String symbolIn;
+	
+	@NotNull(message = "币种不能为空")
+	@ApiModelProperty(value = "转出币种", example = "BTC")
+	private String symbolOut;
+
+}
diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ContractSymbolListVo.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ContractSymbolListVo.java
new file mode 100644
index 0000000..989afaf
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ContractSymbolListVo.java
@@ -0,0 +1,14 @@
+package com.xcong.excoin.modules.coin.parameter.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "ContractSymbolListVo", description = "信息返回")
+public class ContractSymbolListVo {
+	
+	@ApiModelProperty(value = "账户类型")
+	private String walletCode;
+
+}
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java b/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
index 9ff63ff..6bac866 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -45,4 +45,8 @@
 
 	public Result agentTransferToWalletCoins(BigDecimal balance, Integer transfertype, String symbol);
 
+	public Result getContractSymbolList();
+
+	public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut);
+
 }
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
index 23915c1..1ce5f47 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -22,6 +22,7 @@
 import com.xcong.excoin.modules.coin.mapper.MemberAccountMoneyChangeMapper;
 import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
 import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
+import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinInfoVo;
@@ -797,4 +798,117 @@
         return Result.ok(allWalletCoinVo);
 	}
 
+	@Override
+	public Result getContractSymbolList() {
+		//获取用户ID
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+        List<ContractSymbolListVo> list = memberWalletContractDao.findContractSymbolListBymemberId(memberId);
+        if(CollUtil.isNotEmpty(list)) {
+        	for(ContractSymbolListVo contractSymbolListVo : list) {
+        		String walletCode = contractSymbolListVo.getWalletCode();
+        		walletCode = walletCode+"/USDT";
+        		contractSymbolListVo.setWalletCode(walletCode);
+        	}
+        }
+		return Result.ok(list);
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut) {
+		//获取用户ID
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+        //转入转出不能是同一账户
+        if(symbolIn.equals(symbolOut)) {
+        	return Result.fail(MessageSourceUtils.getString("member_service_0098"));
+        }
+        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0004"));
+    	}
+        
+        MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolOut);
+    	BigDecimal availableBalance = walletContract.getAvailableBalance();
+    	// 扣币
+    	BigDecimal availableSubtract = availableBalance.subtract(balance);
+    	if (availableSubtract.compareTo(BigDecimal.ZERO) < 0) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0007"));
+    	}
+    	BigDecimal totalBalance = walletContract.getTotalBalance();
+    	BigDecimal totalSubtract = totalBalance.subtract(balance);
+    	
+    	walletContract.setAvailableBalance(availableSubtract);
+    	walletContract.setTotalBalance(totalSubtract);
+    	int updateWalletCoinById = memberWalletContractDao.updateById(walletContract);
+    	if (updateWalletCoinById < 1) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+    	}
+    	
+    	//更新合约全仓模式下的订单权益
+        MemberEntity memberEntity = memberDao.selectById(memberId);
+        String symbols = symbolOut+"/USDT";
+        ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
+        
+        // 加币
+        // 查询合约账户
+        MemberWalletContractEntity walletContractIn = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolIn);
+        BigDecimal availableBalanceIn = walletContractIn.getAvailableBalance();
+        BigDecimal addIn = availableBalanceIn.add(balance);
+        walletContractIn.setAvailableBalance(addIn);
+        BigDecimal totalBalanceIn = walletContractIn.getTotalBalance();
+        BigDecimal totalBigDecimalIn = totalBalanceIn.add(balance);
+        walletContractIn.setTotalBalance(totalBigDecimalIn);
+        int updateWalletContractById = memberWalletContractDao.updateById(walletContractIn);
+        if (updateWalletContractById < 1) {
+            return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+        }
+        
+        //更新合约全仓模式下的订单权益
+        String symbolIns = symbolIn+"/USDT";
+        ThreadPoolUtils.sendWholeForceClosingPrice(symbolIns, memberEntity);
+        
+        //添加币币资金划转历史记录
+        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
+        memberAccountRecord.setContent("转出至合约"+symbolIn+"账户");
+        memberAccountRecord.setMemberId(memberId);
+        memberAccountRecord.setAmount(balance.negate());
+        memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
+        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
+        memberAccountMoneyChangeDao.insert(memberAccountRecord);
+
+        //添加合约资金划转历史记录
+        memberAccountRecord.setContent("由合约"+symbolOut+"账户转入至合约"+symbolIn+"账户");
+        memberAccountRecord.setAmount(balance);
+        memberAccountMoneyChangeDao.insert(memberAccountRecord);
+        
+        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
+	}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
 }
diff --git a/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java b/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java
index e12db7e..dbd1942 100644
--- a/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java
+++ b/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java
@@ -3,9 +3,11 @@
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
 import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 public interface MemberWalletContractDao extends BaseMapper<MemberWalletContractEntity> {
 	
@@ -19,4 +21,6 @@
 	 * @param id
 	 */
 	void increaseWalletContractBalanceById(@Param("availableBalance") BigDecimal availableBalance,@Param("totalBalance") BigDecimal totalBalance,@Param("frozenBalance") BigDecimal frozenBalance,@Param("id") Long id);
+
+	List<ContractSymbolListVo> findContractSymbolListBymemberId(@Param("memberId")Long memberId);
 }
diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties
index dc42e05..300eeb3 100644
--- a/src/main/resources/i18n/messages_en_US.properties
+++ b/src/main/resources/i18n/messages_en_US.properties
@@ -139,6 +139,7 @@
 member_service_0095=Insufficient available balance of agent usdt account
 member_service_0096=Transfer fail
 member_service_0097=Payment method already exists
+member_service_0098=Please select another account
 
 order_service_0001=Wrong parameter value
 order_service_0002=Not logged in
diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties
index 01c4b5a..335a593 100644
--- a/src/main/resources/i18n/messages_zh_CN.properties
+++ b/src/main/resources/i18n/messages_zh_CN.properties
@@ -139,6 +139,7 @@
 member_service_0095=代理USDT账户可用余额不足
 member_service_0096=划转失败
 member_service_0097=支付方式已存在
+member_service_0098=请选择其他账户
 
 order_service_0001=参值有误
 order_service_0002=未登录
diff --git a/src/main/resources/mapper/member/MemberWalletContractDao.xml b/src/main/resources/mapper/member/MemberWalletContractDao.xml
index 878b221..c9b2ece 100644
--- a/src/main/resources/mapper/member/MemberWalletContractDao.xml
+++ b/src/main/resources/mapper/member/MemberWalletContractDao.xml
@@ -9,6 +9,12 @@
 				and wallet_code = #{symbol}
 			</if>
 	</select>
+	
+	<select id="findContractSymbolListBymemberId" resultType="com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo">
+			select wallet_code 
+			from member_wallet_contract 
+			where member_id = #{memberId} 
+	</select>
 
 	<update id="increaseWalletContractBalanceById" parameterType="map" >
 		update member_wallet_contract

--
Gitblit v1.9.1