将市商功能修改为 ‘提交申请,自动通过’

pull/1/head
luzhaofeng 5 years ago
parent 5c2f2c79d9
commit 9b48fd4479
  1. 4
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/controller/MarketApplyController.java
  2. 7
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/mapper/MarketFreezeMapper.java
  3. 14
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/MarketApplyService.java
  4. 18
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/MarketFreezeService.java
  5. 7
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/MarketUserService.java
  6. 117
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/MarketApplyServiceImpl.java
  7. 25
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/MarketFreezeServiceImpl.java
  8. 16
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/MarketUserServiceImpl.java
  9. 7
      blockchain-server/blockchain-server-otc/src/main/resources/mapper/MarketFreezeMapper.xml

@ -31,7 +31,7 @@ public class MarketApplyController {
@PostMapping("/cancelApply") @PostMapping("/cancelApply")
public ResultDTO cancelApply(HttpServletRequest request) { public ResultDTO cancelApply(HttpServletRequest request) {
String userId = getUserId(request); String userId = getUserId(request);
marketApplyService.applyMarket(userId, MarketApplyConstants.CANCEL); marketApplyService.cancelMarket(userId);
return ResultDTO.requstSuccess(); return ResultDTO.requstSuccess();
} }
@ -40,7 +40,7 @@ public class MarketApplyController {
@PostMapping("/marketApply") @PostMapping("/marketApply")
public ResultDTO marketApply(HttpServletRequest request) { public ResultDTO marketApply(HttpServletRequest request) {
String userId = getUserId(request); String userId = getUserId(request);
marketApplyService.applyMarket(userId, MarketApplyConstants.MARKET); marketApplyService.asMarket(userId);
return ResultDTO.requstSuccess(); return ResultDTO.requstSuccess();
} }

@ -20,4 +20,11 @@ public interface MarketFreezeMapper extends Mapper<MarketFreeze> {
* @return * @return
*/ */
MarketFreeze selectByUserId(@Param("userId") String userId); MarketFreeze selectByUserId(@Param("userId") String userId);
/***
* 根据用户id删除
* @param userId
* @return
*/
int deleteByUserId(@Param("userId") String userId);
} }

@ -11,6 +11,20 @@ public interface MarketApplyService {
*/ */
void applyMarket(String userId, String applyType); void applyMarket(String userId, String applyType);
/**
* 提交成为市商申请后直接成为市商
*
* @param userId
*/
void asMarket(String userId);
/**
* 提交取消申请后取消市商身份
*
* @param userId
*/
void cancelMarket(String userId);
/*** /***
* 根据用户id和申请类型查询 * 根据用户id和申请类型查询
* @param userId * @param userId

@ -2,6 +2,8 @@ package com.blockchain.server.otc.service;
import com.blockchain.server.otc.entity.MarketFreeze; import com.blockchain.server.otc.entity.MarketFreeze;
import java.math.BigDecimal;
public interface MarketFreezeService { public interface MarketFreezeService {
/*** /***
@ -10,4 +12,20 @@ public interface MarketFreezeService {
* @return * @return
*/ */
MarketFreeze getByUserId(String userId); MarketFreeze getByUserId(String userId);
/***
* 新建用户保证金信息
* @param userId
* @param amount
* @param coinName
* @return
*/
int insertMarketFreeze(String userId, BigDecimal amount, String coinName);
/***
* 删除保证金记录
* @param userId
* @return
*/
int deleteMarketFreeze(String userId);
} }

@ -30,4 +30,11 @@ public interface MarketUserService {
* @return * @return
*/ */
int updateByPrimaryKeySelective(MarketUser marketUser); int updateByPrimaryKeySelective(MarketUser marketUser);
/***
* 新建市商用户
* @param userId 用户id
* @return
*/
int insertMarketUser(String userId);
} }

@ -1,6 +1,7 @@
package com.blockchain.server.otc.service.impl; package com.blockchain.server.otc.service.impl;
import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.otc.common.constant.BillConstants;
import com.blockchain.server.otc.common.constant.MarketApplyConstants; import com.blockchain.server.otc.common.constant.MarketApplyConstants;
import com.blockchain.server.otc.common.constant.MarketUserConstants; import com.blockchain.server.otc.common.constant.MarketUserConstants;
import com.blockchain.server.otc.common.enums.OtcEnums; import com.blockchain.server.otc.common.enums.OtcEnums;
@ -10,10 +11,8 @@ import com.blockchain.server.otc.entity.MarketFreeze;
import com.blockchain.server.otc.entity.MarketUser; import com.blockchain.server.otc.entity.MarketUser;
import com.blockchain.server.otc.feign.UserFeign; import com.blockchain.server.otc.feign.UserFeign;
import com.blockchain.server.otc.mapper.MarketApplyMapper; import com.blockchain.server.otc.mapper.MarketApplyMapper;
import com.blockchain.server.otc.service.ConfigService; import com.blockchain.server.otc.service.*;
import com.blockchain.server.otc.service.MarketApplyService; import com.codingapi.tx.annotation.TxTransaction;
import com.blockchain.server.otc.service.MarketFreezeService;
import com.blockchain.server.otc.service.MarketUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -34,8 +33,15 @@ public class MarketApplyServiceImpl implements MarketApplyService {
@Autowired @Autowired
private ConfigService configService; private ConfigService configService;
@Autowired @Autowired
private WalletService walletService;
@Autowired
private BillService billService;
@Autowired
private UserFeign userFeign; private UserFeign userFeign;
//保证金固定为CNY
private static final String UNIT_NAME = "CNY";
@Override @Override
@Transactional @Transactional
public void applyMarket(String userId, String applyType) { public void applyMarket(String userId, String applyType) {
@ -51,6 +57,88 @@ public class MarketApplyServiceImpl implements MarketApplyService {
insertMarketApply(userId, applyType); insertMarketApply(userId, applyType);
} }
@Override
@Transactional
@TxTransaction(isStart = true)
public void asMarket(String userId) {
//提交市商申请时,判断用户是否通过高级认证
checkUserHighAuth(userId, MarketUserConstants.MARKET);
//查询用户市商状态
MarketUser marketUser = marketUserService.getMarketUserByUserId(userId);
//市商用户存在
if (marketUser != null) {
//市商状态不等于未认证
if (!marketUser.getStatus().equals(MarketUserConstants.NOTMARKET)) {
throw new OtcException(OtcEnums.USER_IS_MRAKET);
}
//更新市商用户状态为市商
marketUser.setStatus(MarketUserConstants.MARKET);
marketUser.setModifyTime(new Date());
marketUserService.updateByPrimaryKeySelective(marketUser);
} else {//市商用户不存在
//新建市商
marketUserService.insertMarketUser(userId);
}
//新建市商申请
//市商申请id
String applyId = insertAgreeMarketApply(userId, MarketApplyConstants.MARKET);
//市商保证金代币
String coinName = configService.selectMarketFreezeCoin();
//市商保证金数量
BigDecimal amount = configService.selectMarketFreezeAmount();
//防止保证金代币和数量为空
if (coinName != null && amount.compareTo(BigDecimal.ZERO) > 0) {
//新建冻结记录
marketFreezeService.insertMarketFreeze(userId, amount, coinName);
//冻结余额
walletService.handleBalance(userId, applyId, coinName, UNIT_NAME, BigDecimal.ZERO, amount);
//增加余额变更记录
billService.insertBill(userId, applyId, BigDecimal.ZERO, amount, BillConstants.MARKET_USER, coinName);
}
}
@Override
@Transactional
@TxTransaction(isStart = true)
public void cancelMarket(String userId) {
//查询用户市商状态
MarketUser marketUser = marketUserService.getMarketUserByUserId(userId);
//市商用户为空
if (marketUser == null) {
throw new OtcException(OtcEnums.MARKET_USER_NULL);
}
//市商用户状态不等于市商
if (!marketUser.getStatus().equals(MarketUserConstants.MARKET)) {
throw new OtcException(OtcEnums.CANCEL_MARKET_USER_STATUS_ERROR);
}
//新建市商申请
String applyId = insertAgreeMarketApply(userId, MarketApplyConstants.CANCEL);
//更新
marketUser.setStatus(MarketUserConstants.NOTMARKET);
marketUser.setModifyTime(new Date());
marketUserService.updateByPrimaryKeySelective(marketUser);
//查询保证金记录
MarketFreeze marketFreeze = marketFreezeService.getByUserId(userId);
if (marketFreeze != null) {
//删除冻结记录
marketFreezeService.deleteMarketFreeze(userId);
//解冻资金
BigDecimal freeAmount = marketFreeze.getAmount();
BigDecimal freezeAmount = freeAmount.multiply(new BigDecimal("-1"));
//解冻的币种
String coinName = marketFreeze.getCoinName();
//解冻余额
walletService.handleBalance(userId, applyId, coinName, UNIT_NAME, freeAmount, freezeAmount);
//增加余额变更记录
billService.insertBill(userId, applyId, freeAmount, freezeAmount, BillConstants.CANCEL_MARKET_USER, coinName);
}
}
@Override @Override
public MarketApply getByUserIdAndApplyTypeAndStatus(String userId, String applyType, String status) { public MarketApply getByUserIdAndApplyTypeAndStatus(String userId, String applyType, String status) {
return marketApplyMapper.selectByUserIdAndApplyTypeAndStatus(userId, applyType, status); return marketApplyMapper.selectByUserIdAndApplyTypeAndStatus(userId, applyType, status);
@ -101,6 +189,27 @@ public class MarketApplyServiceImpl implements MarketApplyService {
} }
} }
/***
* 新建状态为'已同意'的申请记录
* @param userId
* @param applyType
* @return
*/
private String insertAgreeMarketApply(String userId, String applyType) {
MarketApply marketApply = new MarketApply();
Date now = new Date();
String applyId = UUID.randomUUID().toString();
marketApply.setId(applyId);
marketApply.setUserId(userId);
marketApply.setApplyType(applyType);
marketApply.setCreateTime(now);
marketApply.setModifyTime(now);
marketApply.setStatus(MarketApplyConstants.AGREE);
marketApplyMapper.insertSelective(marketApply);
return applyId;
}
/*** /***
* 新增市商申请 * 新增市商申请
* @param userId * @param userId

@ -5,6 +5,11 @@ import com.blockchain.server.otc.mapper.MarketFreezeMapper;
import com.blockchain.server.otc.service.MarketFreezeService; import com.blockchain.server.otc.service.MarketFreezeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;
@Service @Service
public class MarketFreezeServiceImpl implements MarketFreezeService { public class MarketFreezeServiceImpl implements MarketFreezeService {
@ -16,4 +21,24 @@ public class MarketFreezeServiceImpl implements MarketFreezeService {
public MarketFreeze getByUserId(String userId) { public MarketFreeze getByUserId(String userId) {
return marketFreezeMapper.selectByUserId(userId); return marketFreezeMapper.selectByUserId(userId);
} }
@Override
@Transactional
public int insertMarketFreeze(String userId, BigDecimal amount, String coinName) {
MarketFreeze marketFreeze = new MarketFreeze();
marketFreeze.setId(UUID.randomUUID().toString());
marketFreeze.setUserId(userId);
marketFreeze.setCoinName(coinName);
marketFreeze.setAmount(amount);
marketFreeze.setMarketApplyId(null);
marketFreeze.setCreateTime(new Date());
return marketFreezeMapper.insertSelective(marketFreeze);
}
@Override
@Transactional
public int deleteMarketFreeze(String userId) {
return marketFreezeMapper.deleteByUserId(userId);
}
} }

@ -10,6 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.UUID;
@Service @Service
public class MarketUserServiceImpl implements MarketUserService { public class MarketUserServiceImpl implements MarketUserService {
@ -44,4 +47,17 @@ public class MarketUserServiceImpl implements MarketUserService {
public int updateByPrimaryKeySelective(MarketUser marketUser) { public int updateByPrimaryKeySelective(MarketUser marketUser) {
return marketUserMapper.updateByPrimaryKeySelective(marketUser); return marketUserMapper.updateByPrimaryKeySelective(marketUser);
} }
@Override
@Transactional
public int insertMarketUser(String userId) {
MarketUser marketUser = new MarketUser();
Date date = new Date();
marketUser.setId(UUID.randomUUID().toString());
marketUser.setUserId(userId);
marketUser.setStatus(MarketUserConstants.MARKET);
marketUser.setModifyTime(date);
marketUser.setCreateTime(date);
return marketUserMapper.insertSelective(marketUser);
}
} }

@ -22,4 +22,11 @@
user_id = #{userId} user_id = #{userId}
</select> </select>
<delete id="deleteByUserId">
DELETE FROM
<include refid="table"/>
WHERE
user_id = #{userId}
</delete>
</mapper> </mapper>
Loading…
Cancel
Save