| | |
| | | import com.nq.enums.*; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.vo.stock.StockAiVO; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public ServerResponse getStockAiList(Integer pageNum, Integer pageSize) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockAI> stockAiList = stockAiMapper.selectList(new QueryWrapper<StockAI>().eq("status", EStockAIStatus.online.getValue())); |
| | | List<StockAI> stockAiList = stockAiMapper.selectList(new QueryWrapper<StockAI>() |
| | | .eq("status", EStockAIStatus.online.getValue())); |
| | | // 获取分页信息 |
| | | PageInfo<StockAI> pageInfo = new PageInfo<>(stockAiList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getAdminStockAiList(Integer pageNum, Integer pageSize, String stockType, String status, String name) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockAiVO> stockAiList = stockAiMapper.getStockAiList(stockType, status, name); |
| | | // 获取分页信息 |
| | | PageInfo<StockAiVO> pageInfo = new PageInfo<>(stockAiList); |
| | | |
| | | if (!pageInfo.getList().isEmpty()) { |
| | | List<StockAiVO> newStockAiList = pageInfo.getList(); |
| | | newStockAiList.forEach(stockAiVO -> { |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockAiVO.getStockType()); |
| | | stockAiVO.setStockTypeName(eStockType.getSymbol1()); |
| | | stockAiVO.setSymbol(stockType); |
| | | }); |
| | | pageInfo.setList(newStockAiList); |
| | | } |
| | | |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception ex) { |
| | | log.error("StockAiService getAdminStockAiList error", ex); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | * @param model |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ServerResponse editStockAi(StockAI model) { |
| | | try { |
| | | if (model == null) { |
| | | return ServerResponse.createByErrorMsg("editStockAi model is null"); |
| | | } |
| | | if (model.getStockType().isEmpty() || model.getStockName().isEmpty() || model.getMinPrice() == null |
| | | || model.getSuccessRate() == null || model.getExpectedEarning() == null || model.getStatus().isEmpty()) { |
| | | return ServerResponse.createByErrorMsg("请完善必填信息"); |
| | | } |
| | | if (!model.getStockType().equals(EStockType.US.getCode()) && !model.getStockType().equals(EStockType.MX.getCode())) { |
| | | return ServerResponse.createByErrorMsg("只能选择美股或墨西哥股"); |
| | | } |
| | | //新增 |
| | | if (model.getId() == null) { |
| | | //查询是否存在 |
| | | StockAI stockAI = stockAiMapper.selectOne(new QueryWrapper<StockAI>().eq("stock_name", model.getStockName())); |
| | | if (stockAI != null) { |
| | | return ServerResponse.createByErrorMsg("当前股票已添加"); |
| | | } |
| | | model.setCreateDate(new Date()); |
| | | stockAiMapper.insert(model); |
| | | } else { //修改 |
| | | stockAiMapper.updateById(model); |
| | | } |
| | | return ServerResponse.createBySuccess("操作成功"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | } |