| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.EChoMapper; |
| | | import com.nq.dao.OrderEchoMapper; |
| | | import com.nq.dao.UserAssetsMapper; |
| | | import com.nq.dao.UserPositionMapper; |
| | | import com.nq.enums.EStockAIStatus; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.pojo.reponse.OrderEChoReponse; |
| | | import com.nq.service.IEchoServices; |
| | | import com.nq.service.IUserService; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.vo.subscribe.UserStockSubscribeVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | IUserService iUserService; |
| | | |
| | | @Autowired |
| | | private UserAssetsServices serAssetsServices; |
| | | private UserAssetsMapper userAssetsMapper; |
| | | |
| | | @Autowired |
| | | private UserAssetsMapper userAssetsMapper; |
| | | private UserPositionMapper userPositionMapper; |
| | | |
| | | @Override |
| | | public List<EChoBean> queryList() { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean buyECho(String eId, BigDecimal money, HttpServletRequest request) { |
| | | public ServerResponse queryListPage(int pageNum, int pageSize) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<EChoBean> eChoBeans = eChoMapper.selectList(null); |
| | | PageInfo<EChoBean> pageInfo = new PageInfo<>(eChoBeans); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception ex) { |
| | | log.error("echoService queryListPage error", ex); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean buyECho(String eId, BigDecimal money, String accectType, HttpServletRequest request) { |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | |
| | |
| | | |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, orderEchoBean.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, accectType) |
| | | ); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().subtract(money)); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(money)); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse queryOrderEchoPage(int pageNum, int pageSize, HttpServletRequest request) { |
| | | try { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<OrderEchoOut> orderEchoOutList = orderEchoMapper.queryByUserId(user.getId()); |
| | | PageInfo<OrderEchoOut> pageInfo = new PageInfo<>(orderEchoOutList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception ex) { |
| | | log.error("echoService queryOrderEchoPage error", ex); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public List<OrderEChoReponse> queryALLOrderEcho() { |
| | | return orderEchoMapper.queryAll(); |
| | | } |
| | | |
| | | @Override |
| | | public void sendMoney() { |
| | | // 创建固定大小的线程池,根据需求调整线程数量 |
| | | ExecutorService executor = Executors.newFixedThreadPool(2); |
| | | try { |
| | | executor.submit(() -> sendMoney(EStockType.getDefault().getCode())); |
| | | } finally { |
| | | // 关闭线程池 |
| | | executor.shutdown(); |
| | | } |
| | | } |
| | | |
| | | private void sendMoney(String stockType) { |
| | | try { |
| | | QueryWrapper<OrderEchoBean> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("state", 1); |
| | |
| | | BigDecimal aml = incomeAmount.add(money); |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, orderEchoBean.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, stockType) |
| | | ); |
| | | if (userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0) { |
| | | continue; |
| | |
| | | } else { |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(aml)); |
| | | } |
| | | /*UserPosition userPosition = userPositionMapper.selectOne(new LambdaQueryWrapper<UserPosition>().gt(UserPosition::getAmountToBeCovered, BigDecimal.ZERO).eq(UserPosition::getUserId,userAssets.getUserId())); |
| | | if(null != userPosition){ |
| | | userPosition.setAmountToBeCovered(userAssets.getAmountToBeCovered()); |
| | | userPositionMapper.updateById(userPosition); |
| | | }*/ |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(money)); |
| | | userAssetsMapper.updateById(userAssets); |
| | | orderEchoBean.setState("2"); |
| | |
| | | log.error("基金定时任务---失败: ", ex); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int insertEcho(EChoBean eChoBean) { |