| | |
| | | package com.xcong.excoin.modules.otc.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.excoin.common.LoginUserUtils; |
| | | import com.xcong.excoin.common.exception.GlobalException; |
| | |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao; |
| | | import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao; |
| | | import com.xcong.excoin.modules.otc.dao.OtcOrderDao; |
| | | import com.xcong.excoin.modules.otc.dao.OtcSettingDao; |
| | | import com.xcong.excoin.modules.otc.dto.MbAddDto; |
| | | import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder; |
| | | import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness; |
| | | import com.xcong.excoin.modules.otc.entity.OtcOrder; |
| | | import com.xcong.excoin.modules.otc.entity.OtcSetting; |
| | | import com.xcong.excoin.modules.otc.mapper.OtcEntrustOrderMapper; |
| | | import com.xcong.excoin.modules.otc.mapper.OtcMarketBussinessMapper; |
| | | import com.xcong.excoin.modules.otc.service.OtcMarketBussinessService; |
| | | import com.xcong.excoin.modules.otc.vo.ApplyConditionsVo; |
| | | import com.xcong.excoin.modules.otc.vo.EntrustListInfoVo; |
| | | import com.xcong.excoin.modules.otc.vo.MarketBussinessInfoVo; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | |
| | | private final OtcEntrustOrderDao otcEntrustOrderDao; |
| | | private final MemberDao memberDao; |
| | | private final OtcSettingDao otcSettingDao; |
| | | private final OtcOrderDao otcOrderDao; |
| | | |
| | | @Override |
| | | public void add() { |
| | | MemberEntity member = LoginUserUtils.getAppLoginUser(); |
| | | member = memberDao.selectById(member.getId()); |
| | | // long memberId = 444L; |
| | | // MemberEntity member = memberDao.selectById(memberId); |
| | | |
| | | if (MemberEntity.IS_TRADER_Y.equals(member.getIsTrader())) { |
| | | throw new GlobalException("已经是市商"); |
| | | } |
| | | OtcSetting setting = otcSettingDao.selectById(1L); |
| | | // 所有已完成订单 |
| | | List<OtcOrder> finishOrders = otcOrderDao.selectOrderListForUser(member.getId(), 3); |
| | | if (CollUtil.isEmpty(finishOrders) || setting.getOrderNum() > finishOrders.size()) { |
| | | throw new GlobalException("条件未达标"); |
| | | } |
| | | |
| | | List<OtcOrder> allOrders = otcOrderDao.selectOrderListForUser(member.getId(), null); |
| | | if (CollUtil.isNotEmpty(allOrders)) { |
| | | BigDecimal finishRatio = BigDecimal.valueOf(finishOrders.size()).divide(BigDecimal.valueOf(allOrders.size()), 4, BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)); |
| | | if (setting.getCompletionRate().compareTo(finishRatio) > 0) { |
| | | throw new GlobalException("条件未达标"); |
| | | } |
| | | } |
| | | |
| | | BigDecimal totalAmount = otcOrderDao.selectOrderTotalAmount(member.getId()); |
| | | if (setting.getTotalAmount().compareTo(totalAmount) > 0) { |
| | | throw new GlobalException("条件未达标"); |
| | | } |
| | | |
| | | OtcMarketBussiness mb = this.baseMapper.selectMarketBussinessByMemberId(member.getId()); |
| | |
| | | } |
| | | |
| | | MarketBussinessInfoVo mbVo = OtcMarketBussinessMapper.INSTANCE.entityToVo(mb); |
| | | |
| | | mbVo.setTotalOrderCnt(mb.getTotalOrderCnt() + mb.getSaleTotalCnt()); |
| | | mbVo.setFinishRatio(mb.getFinishRatio().add(mb.getSaleFinishRatio()).divide(BigDecimal.valueOf(2), 4, BigDecimal.ROUND_DOWN)); |
| | | MemberEntity member = memberDao.selectById(mb.getMemberId()); |
| | | OtcEntrustOrder query = new OtcEntrustOrder(); |
| | | query.setMemberId(mb.getMemberId()); |
| | | query.setIsDefualt(1); |
| | | query.setOrderType(OtcEntrustOrder.ORDER_TYPE_B); |
| | | query.setStatus(OtcEntrustOrder.LINE_UP); |
| | | List<OtcEntrustOrder> buysEntity = otcEntrustOrderDao.selectEntrustOrderByOrderType(query); |
| | |
| | | mbVo.setNikename(member.getName()); |
| | | return Result.ok(mbVo); |
| | | } |
| | | |
| | | @Override |
| | | public Result applyConditions() { |
| | | MemberEntity member = LoginUserUtils.getAppLoginUser(); |
| | | member = memberDao.selectById(member.getId()); |
| | | // long memberId = 444L; |
| | | // MemberEntity member = memberDao.selectById(memberId); |
| | | ApplyConditionsVo applyConditionsVo = new ApplyConditionsVo(); |
| | | |
| | | OtcSetting setting = otcSettingDao.selectById(1L); |
| | | applyConditionsVo.setOrderNum(setting.getOrderNum()); |
| | | applyConditionsVo.setTotalAmount(setting.getTotalAmount()); |
| | | applyConditionsVo.setCompletionRate(setting.getCompletionRate()); |
| | | applyConditionsVo.setCancellNum(setting.getCancellNum()); |
| | | // 所有已完成订单 |
| | | List<OtcOrder> finishOrders = otcOrderDao.selectOrderListForUser(member.getId(), 3); |
| | | if (CollUtil.isEmpty(finishOrders) || setting.getOrderNum() > finishOrders.size()) { |
| | | applyConditionsVo.setOrderNumStatus(2); |
| | | }else{ |
| | | applyConditionsVo.setOrderNumStatus(1); |
| | | } |
| | | |
| | | List<OtcOrder> allOrders = otcOrderDao.selectOrderListForUser(member.getId(), null); |
| | | if (CollUtil.isNotEmpty(allOrders)) { |
| | | BigDecimal finishRatio = BigDecimal.valueOf(finishOrders.size()).divide(BigDecimal.valueOf(allOrders.size()), 4, BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)); |
| | | if (setting.getCompletionRate().compareTo(finishRatio) > 0) { |
| | | applyConditionsVo.setCompletionRateStatus(2); |
| | | }else{ |
| | | applyConditionsVo.setCompletionRateStatus(1); |
| | | } |
| | | } |
| | | |
| | | BigDecimal totalAmount = otcOrderDao.selectOrderTotalAmount(member.getId()); |
| | | totalAmount = totalAmount == null ? BigDecimal.ZERO : totalAmount; |
| | | if (setting.getTotalAmount().compareTo(totalAmount) > 0) { |
| | | applyConditionsVo.setTotalAmountStatus(2); |
| | | }else{ |
| | | applyConditionsVo.setTotalAmountStatus(1); |
| | | } |
| | | |
| | | Integer certifyStatus = member.getCertifyStatus(); |
| | | if(MemberEntity.CERTIFY_STATUS_Y == certifyStatus){ |
| | | applyConditionsVo.setMemberAuthStatus(1); |
| | | }else{ |
| | | applyConditionsVo.setMemberAuthStatus(2); |
| | | } |
| | | |
| | | return Result.ok(applyConditionsVo); |
| | | } |
| | | } |