5 files modified
6 files added
| New file |
| | |
| | | package com.nq.Repository; |
| | | |
| | | import com.nq.pojo.ExchangeRate; |
| | | import org.springframework.data.jpa.repository.JpaRepository; |
| | | |
| | | import java.util.Optional; |
| | | |
| | | public interface ExchangeRateRepository extends JpaRepository<ExchangeRate, Long> { |
| | | |
| | | Optional<ExchangeRate> findExchangeRateByCurrencyAndConversionCurrency(String currency, String conversionCurrency); |
| | | |
| | | } |
| New file |
| | |
| | | package com.nq.controller; |
| | | |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.pojo.ExchangeRate; |
| | | import com.nq.service.ExchangeRateService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * 汇率管理 |
| | | */ |
| | | @Controller |
| | | @RequestMapping({"/stock/rate"}) |
| | | public class ExchangeRateController { |
| | | |
| | | @Autowired |
| | | ExchangeRateService exchangeRateService; |
| | | |
| | | //查询汇率列表 |
| | | @RequestMapping({"getInfo.do"}) |
| | | @ResponseBody |
| | | public ServerResponse getInfo(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, |
| | | @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) { |
| | | return exchangeRateService.getInfo(pageNum, pageSize); |
| | | } |
| | | |
| | | //修改汇率 |
| | | @RequestMapping({"updateRate.do"}) |
| | | @ResponseBody |
| | | public ServerResponse updateRate(ExchangeRate model, HttpServletRequest request) { |
| | | return exchangeRateService.updateRate(model, request); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MX", user.getId()); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MEX", user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| New file |
| | |
| | | package com.nq.dao; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.nq.pojo.ExchangeRate; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @Mapper |
| | | public interface ExchangeRateMapper extends BaseMapper<ExchangeRate>{ |
| | | } |
| | |
| | | // MAS("MAS","马来西亚股票","42",PropertiesUtil.getProperty("MAS_HTTP_API"),PropertiesUtil.getProperty("MAS_KEY"),"MYR","RM"), |
| | | // |
| | | // IN("IN","印度股票","14", PropertiesUtil.getProperty("JS_IN_HTTP_URL"),PropertiesUtil.getProperty("JS_IN_KEY"),"INR","₹"), |
| | | MX("MX","墨西哥股票","7",PropertiesUtil.getProperty("MX_HTTP_API"),PropertiesUtil.getProperty("MX_KEY"),"MXN","MXN$"); |
| | | MX("MEX","墨西哥股票","7",PropertiesUtil.getProperty("MX_HTTP_API"),PropertiesUtil.getProperty("MX_KEY"),"MXN","MXN$"); |
| | | |
| | | // TH("TH","泰国股票","41",PropertiesUtil.getProperty("TH_HTTP_API"),PropertiesUtil.getProperty("TH_KEY")), |
| | | // HG("HG","韩国股票","11",PropertiesUtil.getProperty("HG_HTTP_API"),PropertiesUtil.getProperty("HG_KEY")), |
| New file |
| | |
| | | package com.nq.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 汇率表 |
| | | */ |
| | | @Data |
| | | @TableName("exchange_rate") |
| | | @Entity |
| | | public class ExchangeRate{ |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | /** |
| | | * 汇率 |
| | | */ |
| | | private BigDecimal rata; |
| | | /** |
| | | * 原始货币 |
| | | */ |
| | | private String currency; |
| | | |
| | | /** |
| | | * 转换货币 |
| | | */ |
| | | private String conversionCurrency; |
| | | |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date updateTime; |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.nq.service; |
| | | |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.pojo.ExchangeRate; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | public interface ExchangeRateService { |
| | | |
| | | /** |
| | | * 获取列表 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | ServerResponse getInfo(Integer pageNum, Integer pageSize); |
| | | |
| | | /** |
| | | * 新增或编辑 |
| | | * @param model |
| | | * @param request |
| | | * @return |
| | | */ |
| | | ServerResponse updateRate(ExchangeRate model, HttpServletRequest request); |
| | | } |
| New file |
| | |
| | | package com.nq.service.impl; |
| | | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.Repository.ExchangeRateRepository; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.ExchangeRateMapper; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.ExchangeRate; |
| | | import com.nq.service.ExchangeRateService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class ExchangeRateServiceImpl implements ExchangeRateService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(ExchangeRateServiceImpl.class); |
| | | |
| | | @Autowired |
| | | ExchangeRateRepository exchangeRateRepository; |
| | | |
| | | @Autowired |
| | | ExchangeRateMapper exchangeRateMapper; |
| | | |
| | | @Override |
| | | public ServerResponse getInfo(Integer pageNum, Integer pageSize) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<ExchangeRate> exchangeRateList = exchangeRateMapper.selectList(null); |
| | | // 获取分页信息 |
| | | PageInfo<ExchangeRate> pageInfo = new PageInfo<>(exchangeRateList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse updateRate(ExchangeRate model, HttpServletRequest request) { |
| | | try { |
| | | if (model == null) { |
| | | return ServerResponse.createByErrorMsg("model is null"); |
| | | } |
| | | if (model.getRata() == null || model.getCurrency().isEmpty() || model.getConversionCurrency().isEmpty()) { |
| | | return ServerResponse.createByErrorMsg("请输入货币和汇率参数不能为空"); |
| | | } |
| | | if (model.getCurrency().equals(model.getConversionCurrency())) { |
| | | return ServerResponse.createByErrorMsg("原始货币和转换货币不能相同"); |
| | | } |
| | | //货币只能为US或MX |
| | | if (!model.getCurrency().equals(EStockType.US.getSymbol()) && !model.getCurrency().equals(EStockType.MX.getSymbol())) { |
| | | return ServerResponse.createByErrorMsg("货币只能为:" + EStockType.US.getSymbol() + " 或 " + EStockType.MX.getSymbol()); |
| | | } |
| | | if (!model.getConversionCurrency().equals(EStockType.US.getSymbol()) && !model.getConversionCurrency().equals(EStockType.MX.getSymbol())) { |
| | | return ServerResponse.createByErrorMsg("转换货币只能为:" + EStockType.US.getSymbol() + " 或 " + EStockType.MX.getSymbol()); |
| | | } |
| | | //新增 |
| | | if (model.getId() == null) { |
| | | //查询该货币汇率是否存在 |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency(model.getCurrency(), |
| | | model.getConversionCurrency()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | return ServerResponse.createByErrorMsg("当前货币转换已存在"); |
| | | } |
| | | model.setUpdateTime(new Date()); |
| | | model = exchangeRateRepository.saveAndFlush(model); |
| | | } else { //修改 |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findById(model.getId()).orElse(null); |
| | | if (exchangeRate == null) { |
| | | return ServerResponse.createByErrorMsg("修改失败,记录不存在!"); |
| | | } |
| | | //只能修改汇率 |
| | | exchangeRate.setRata(model.getRata()); |
| | | exchangeRate.setUpdateTime(new Date()); |
| | | model = exchangeRateRepository.saveAndFlush(exchangeRate); |
| | | } |
| | | model = exchangeRateRepository.saveAndFlush(model); |
| | | return ServerResponse.createBySuccess("操作成功", model); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | } |
| | |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | if (stockType.equals("99")) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "MX", Integer.valueOf(0))); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "MEX", Integer.valueOf(0))); |
| | | } else if (stockType.equals("100")) { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | |
| | | import com.nq.dao.UserPositionMapper; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.ExchangeRateService; |
| | | import com.nq.service.IMandatoryLiquidationService; |
| | | import com.nq.service.IStockService; |
| | | import com.nq.service.IUserPositionService; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | @Autowired |
| | | private StockServiceImpl iStockService; |
| | | @Autowired |
| | | private ExchangeRateService exchangeRateService; |
| | | |
| | | /** |
| | | * test |
| | |
| | | //@Scheduled(cron = "0 0/1 * * * ?") |
| | | @Scheduled(cron = "*/5 * * * * *") |
| | | public void test() { |
| | | /*ExchangeRate model = new ExchangeRate(); |
| | | model.setCurrency("MXN"); |
| | | model.setConversionCurrency("USD"); |
| | | model.setRata(BigDecimal.valueOf(0.0520)); |
| | | exchangeRateService.updateRate(model,null);*/ |
| | | |
| | | //iStockService.getStockByType(1, 20, "desc","st" , "US", null); |
| | | //istockService.getIndicesList("US"); |
| | | //istockService.getIndicesAndKData("15882", "US"); |
| | |
| | | @Override |
| | | public void onMessage(String message) { |
| | | if (message.contains("身份验证成功") || message.contains("pong") || message.contains("身份验证失败") || message.contains("ws连接点只能有一个")) { |
| | | System.out.println("mx" + message); |
| | | System.out.println("mex" + message); |
| | | return; |
| | | } |
| | | System.out.println("mx2" + message); |
| | | System.out.println("mex2" + message); |
| | | Map<String, String> stringObjectMap = jsonToMap(message); |
| | | StockRealTimeBean stockRealTimeBean = new StockRealTimeBean(); |
| | | stockRealTimeBean.setPid(stringObjectMap.get("Id").toString()); |