| | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | |
| | | return ServerResponse.createBySuccess(mapper.selectList(queryWrapper)); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getWeeklyProfit(HttpServletRequest request) { |
| | | Integer userId = getCurrentUser(request).getId(); |
| | | if(ObjectUtil.isEmpty(userId)){ |
| | | return ServerResponse.createBySuccess(BigDecimal.ZERO); |
| | | } |
| | | List<UserPosition> userPositions = userPositionMapper.selectList( |
| | | new QueryWrapper<UserPosition>() |
| | | .eq("user_id", userId) |
| | | .apply("(sell_order_id IS NOT NULL AND sell_order_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)) " + |
| | | "OR (sell_order_id IS NULL AND buy_order_time >= DATE_SUB(NOW(), INTERVAL 7 DAY))") |
| | | ); |
| | | BigDecimal weeklyProfit = BigDecimal.ZERO; |
| | | if (userPositions.size() > 0) { |
| | | |
| | | for (UserPosition position : userPositions) { |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | if(null == position.getSellOrderId()){ |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | }else{ |
| | | nowPrice = position.getSellOrderPrice(); |
| | | } |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,nowPrice); |
| | | |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>() |
| | | .eq(StockSubscribe::getCode, userPositionVO.getStockCode())); |
| | | if(position.getSellOrderId() == null){ |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | userPositionVO.setProfitAndLose(BigDecimal.ZERO); |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | weeklyProfit = weeklyProfit.add(userPositionVO.getProfitAndLose()); |
| | | } |
| | | } |
| | | return ServerResponse.createBySuccess(weeklyProfit); |
| | | } |
| | | } |
| | | |