13 files modified
2 files added
| | |
| | | @RequestParam(value = "keyWords", required = false) String keyWords) { |
| | | return stockService.getStocksByKeyWords(pageNum, pageSize, keyWords); |
| | | } |
| | | |
| | | //建仓列表页 |
| | | @PostMapping({"getPositionList.do"}) |
| | | @ResponseBody |
| | | public ServerResponse getPositionList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, |
| | | @RequestParam(value = "pageSize", defaultValue = "5") int pageSize, |
| | | @RequestParam(value = "id", required = false) Integer stockAiOrderId) { |
| | | if (stockAiOrderId == null) { |
| | | return ServerResponse.createByErrorMsg("id is null"); |
| | | } |
| | | return stockAiService.getPositionList(pageNum, pageSize, stockAiOrderId); |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.nq.pojo.StockAIOrderPosition; |
| | | import com.nq.vo.position.UserPositionVO; |
| | | import com.nq.vo.stock.ai.StockAIOrderPositionVO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | |
| | | |
| | | List<UserPositionVO> getAiPositionList(@Param("userId") Integer userId, @Param("status") Integer status); |
| | | |
| | | List<StockAIOrderPositionVO> getPositionListByOrderId(@Param("stockAiOrderId") Integer stockAiOrderId); |
| | | } |
| | |
| | | |
| | | import com.nq.pojo.StockSubscribe; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.nq.vo.subscribe.StockSubscribeVO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | |
| | | |
| | | public interface StockSubscribeMapper extends BaseMapper<StockSubscribe> { |
| | | |
| | | List<StockSubscribeVO> selectStockSubscribeVO(@Param("zt") Integer zt, |
| | | @Param("type") Integer type, |
| | | @Param("userId") Integer userId); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | ServerResponse openPosition(StockAIOrderPosition model); |
| | | |
| | | ServerResponse orderOperation(Long id, String status); |
| | | |
| | | ServerResponse getPositionList(Integer pageNum, Integer pageSize, Integer stockAiOrderId); |
| | | |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.Repository.ExchangeRateRepository; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockAiMapper; |
| | |
| | | import com.nq.enums.*; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.vo.stock.ai.StockAIOrderPositionVO; |
| | | import com.nq.vo.stock.ai.StockAiOrderTypeVO; |
| | | import com.nq.vo.stock.ai.StockAiOrderVO; |
| | | import com.nq.vo.stock.ai.StockAiVO; |
| | |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | /** |
| | | * 建仓列表 |
| | | * 建仓列表 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param stockAiOrderId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ServerResponse getPositionList(Integer pageNum, Integer pageSize, Integer stockAiOrderId) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockAIOrderPositionVO> positionVOList = stockAiOrderPositionMapper.getPositionListByOrderId(stockAiOrderId); |
| | | PageInfo<StockAIOrderPositionVO> pageInfo = new PageInfo<>(positionVOList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | log.error("StockAiService getPositionList error", e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockMapper; |
| | | import com.nq.dao.UserPositionMapper; |
| | |
| | | import com.nq.dao.StockSubscribeMapper; |
| | | import com.nq.service.IUserService; |
| | | import com.nq.vo.stock.ai.StockAiOrderTypeVO; |
| | | import com.nq.vo.subscribe.StockSubscribeVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Override |
| | | public ServerResponse listPageInfo(int pageNum, int pageSize, HttpServletRequest request) { |
| | | try { |
| | | QueryWrapper<StockSubscribe> queryWrapper = new QueryWrapper(); |
| | | /*QueryWrapper<StockSubscribe> queryWrapper = new QueryWrapper(); |
| | | //显示 0 |
| | | queryWrapper.eq("zt", 0); |
| | | queryWrapper.eq("type", 1); |
| | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockSubscribe> stockSubscribeList = this.stockSubscribeMapper.selectList(queryWrapper); |
| | | // 获取分页信息 |
| | | PageInfo<StockSubscribe> pageInfo = new PageInfo<>(stockSubscribeList); |
| | | PageInfo<StockSubscribe> pageInfo = new PageInfo<>(stockSubscribeList);*/ |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", request); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockSubscribeVO> subscribeVOs = stockSubscribeMapper.selectStockSubscribeVO(0 ,1 ,user.getId()); |
| | | PageInfo<StockSubscribeVO> pageInfo = new PageInfo<>(subscribeVOs); |
| | | |
| | | Date newDate = new Date(); |
| | | pageInfo.getList().forEach(stockSubscribe -> { |
| | |
| | | moneyLog.setAmount(amount.toString()); |
| | | moneyLog.setAccectType(userAssets.getAccectType()); |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(userAssets.getId()+""); |
| | | moneyLog.setUserId(userAssets.getUserId()+""); |
| | | moneyLog.setSymbol(EStockType.getEStockTypeByCode(userAssets.getAccectType()).getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | |
| | | } else { |
| | | //ai交易 计算收益率 收益/本金*100 |
| | | BigDecimal profitAndLose = userPositionVO.getProfitAndLose() |
| | | .divide(userPositionVO.getOrderTotalPrice()) |
| | | .divide(userPositionVO.getOrderTotalPrice(), RoundingMode.HALF_UP) |
| | | .multiply(new BigDecimal(100)) |
| | | .setScale(2, BigDecimal.ROUND_DOWN); |
| | | .setScale(2, RoundingMode.DOWN); |
| | | userPositionVO.setNow_price(String.valueOf(userPositionVO.getSellOrderPrice().setScale(2, RoundingMode.HALF_UP))); |
| | | userPositionVO.setProfitAndLoseParent(profitAndLose + "%"); |
| | | userPositionVO.setSellOrderTotalPrice(userPositionVO.getSellOrderPrice().multiply(BigDecimal.valueOf(userPositionVO.getOrderNum()))); |
| | | } |
| | | resultUserPositions.add(userPositionVO); |
| | | } |
| | |
| | | pageInfo.setList(resultUserPositions); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("IUserPositionService findMyPositionByParam {}", e.getMessage()); |
| | | } |
| | | return ServerResponse.createByError(); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception { |
| | | public ServerResponse save(UserStockSubscribe model, HttpServletRequest request){ |
| | | try { |
| | | int ret = 0; |
| | | if( model.getId() != null ){ |
| | | if (model.getStatus() == 3||model.getStatus() == 2) { |
| | |
| | | if(ret>0){ |
| | | return ServerResponse.createBySuccessMsg("Successful operation"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(),e); |
| | | } |
| | | return ServerResponse.createByErrorMsg("Operation failure"); |
| | | } |
| | | /** |
| | |
| | | import com.nq.vo.position.UserPositionVO; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | /** |
| | | * 仓位计算工具类 |
| | |
| | | * */ |
| | | public static UserPositionVO assembleUserPositionVO2(UserPositionVO userPositionVO,BigDecimal nowPrice) { |
| | | PositionProfitVO positionProfitVO = getPositionProfitVO2(userPositionVO, nowPrice); |
| | | BigDecimal ss = positionProfitVO.getProfitAndLose().divide(userPositionVO.getOrderTotalPrice(),BigDecimal.ROUND_CEILING) |
| | | BigDecimal ss = positionProfitVO.getProfitAndLose().divide(userPositionVO.getOrderTotalPrice(), RoundingMode.CEILING) |
| | | .multiply(new BigDecimal(100)); |
| | | ss = ss.setScale(2, BigDecimal.ROUND_DOWN); |
| | | ss = ss.setScale(2, RoundingMode.DOWN); |
| | | userPositionVO.setProfitAndLoseParent(ss+"%"); |
| | | userPositionVO.setProfitAndLoseParent2(ss); |
| | | userPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose()); |
| | |
| | | private Date sellOrderTime; |
| | | |
| | | private BigDecimal sellOrderPrice; |
| | | private BigDecimal sellOrderTotalPrice; |
| | | private BigDecimal profitTargetPrice; |
| | | private BigDecimal stopTargetPrice; |
| | | private String orderDirection; |
| New file |
| | |
| | | package com.nq.vo.stock.ai; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | public class StockAIOrderPositionVO { |
| | | |
| | | |
| | | private Integer id; |
| | | |
| | | //ai交易产品订单id |
| | | private Integer stockAiOrderId; |
| | | |
| | | //建仓股票id |
| | | private Integer stockId; |
| | | |
| | | /** |
| | | * 建仓股票数量 |
| | | */ |
| | | private Long stockNum; |
| | | |
| | | /** |
| | | * 建仓股票单价 |
| | | */ |
| | | private BigDecimal stockPrice; |
| | | |
| | | /** |
| | | * 建仓时间 |
| | | */ |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date creatDate; |
| | | |
| | | /** |
| | | * 平仓单价 |
| | | */ |
| | | private BigDecimal coverPrice; |
| | | |
| | | /** |
| | | * 平仓时间 |
| | | */ |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date coverDate; |
| | | |
| | | /** |
| | | * 收益 (平仓单价-建仓股票单价)*建仓股票数量 |
| | | */ |
| | | private BigDecimal earnings; |
| | | |
| | | /** |
| | | * 建仓状态 0持仓 1已平仓 |
| | | */ |
| | | private Integer status; |
| | | |
| | | //股票名称 |
| | | private String stockName; |
| | | //code |
| | | private String stockCode; |
| | | //股票名称缩写 |
| | | private String stockSpell; |
| | | //类型 |
| | | private String stockType; |
| | | } |
| New file |
| | |
| | | package com.nq.vo.subscribe; |
| | | |
| | | import com.nq.pojo.StockSubscribe; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class StockSubscribeVO extends StockSubscribe { |
| | | |
| | | //是否已购买 0未购买 1已购买 |
| | | private Integer isBuy; |
| | | |
| | | } |
| | |
| | | ORDER BY creat_date DESC |
| | | </select> |
| | | |
| | | <select id="getPositionListByOrderId" resultType="com.nq.vo.stock.ai.StockAIOrderPositionVO"> |
| | | SELECT p.*,s.stock_name,s.stock_code,s.stock_spell,s.stock_type |
| | | FROM stock_ai_order_position p |
| | | LEFT JOIN stock s ON s.id = p.stock_id |
| | | WHERE p.stock_ai_order_id = #{stockAiOrderId} |
| | | ORDER BY p.creat_date DESC |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | |
| | | |
| | | <!-- </select>--> |
| | | |
| | | |
| | | <select id="selectStockSubscribeVO" resultType="com.nq.vo.subscribe.StockSubscribeVO"> |
| | | SELECT s.*, |
| | | IF((SELECT COUNT(1) FROM user_stock_subscribe |
| | | WHERE new_stock_id = s.newlist_id AND type=#{type} AND user_id =#{userId}) > 0,1,0) isbuy |
| | | FROM stock_subscribe s |
| | | WHERE s.zt= #{zt} AND s.type=#{type} |
| | | ORDER BY s.list_date DESC |
| | | </select> |
| | | |
| | | </mapper> |