| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package top.lvzhiqiang.controller;
- import com.alibaba.fastjson.JSONObject;
- import org.springframework.web.bind.annotation.*;
- import top.lvzhiqiang.dto.R;
- import top.lvzhiqiang.entity.CoinApiConfig;
- import top.lvzhiqiang.entity.CoinWatchlist;
- import top.lvzhiqiang.enumeration.ResultCodeEnum;
- import top.lvzhiqiang.exception.BusinessException;
- import top.lvzhiqiang.exception.ParameterException;
- import top.lvzhiqiang.mapper.CoinMapper;
- import top.lvzhiqiang.service.CoinApiConfigService;
- import top.lvzhiqiang.service.CoinService;
- import top.lvzhiqiang.service.impl.CoinServiceImpl;
- import top.lvzhiqiang.util.DateUtils;
- import top.lvzhiqiang.util.StringUtils;
- import javax.annotation.Resource;
- import java.time.LocalDate;
- import java.util.List;
- /**
- * Coin Controller
- *
- * @author lvzhiqiang
- * 2023/9/5 15:23
- */
- @RestController
- @RequestMapping("/coin")
- public class CoinController {
- @Resource
- private CoinService coinService;
- @Resource
- private CoinApiConfigService coinApiConfigService;
- @Resource
- private CoinMapper coinMapper;
- /**
- * 获取API配置信息
- *
- * @author lvzhiqiang
- * 2023/9/5 15:23
- */
- @PostMapping("/findApiConfig")
- public List<CoinApiConfig> findApiConfig(String userName) {
- if (userName == null) {
- throw new ParameterException("用户名为空!");
- }
- List<CoinApiConfig> all = coinApiConfigService.findByParams(null, null, null, null, 1, userName);
- return all;
- }
- /**
- * 主查询
- *
- * @author lvzhiqiang
- * 2023/9/5 15:23
- */
- @PostMapping("/mainSearch")
- public Object mainSearch(@RequestBody JSONObject params) throws Exception {
- if (!params.containsKey("nameEn")) {
- throw new ParameterException("参数错误!");
- }
- return coinService.mainSearch(params);
- }
- @PostMapping("/getCurrentHoldingTotalAmout")
- public Object getCurrentHoldingTotalAmout(@RequestBody JSONObject params) throws Exception {
- if (!params.containsKey("nameEn")) {
- throw new ParameterException("参数错误!");
- }
- return coinService.getCurrentHoldingTotalAmout(params);
- }
- @GetMapping("/orderDetail/{trackingNo}")
- public String orderDetail(@PathVariable String trackingNo) {
- if (StringUtils.isEmpty(trackingNo)) {
- return "跟单号为空!";
- }
- return coinService.orderDetail(trackingNo);
- }
- @GetMapping("/orderDetail2/{orderId}/{symbol}")
- public String orderDetail2(@PathVariable String orderId, @PathVariable String symbol) {
- if (StringUtils.isEmpty(orderId) || StringUtils.isEmpty(symbol)) {
- return "订单ID何币对名称为空!";
- }
- return coinService.orderDetail2(orderId, symbol);
- }
- @GetMapping("/watchlistDetail/{symbol}/{operationType}")
- public Object watchlistDetail(@PathVariable String symbol, @PathVariable String operationType) {
- if (StringUtils.isEmpty(symbol)) {
- throw new ParameterException("symbol不能为空!");
- }
- if (StringUtils.isEmpty(operationType)) {
- throw new ParameterException("operationType不能为空!");
- }
- return R.ok().data(coinService.watchlistDetail(symbol, operationType));
- }
- @PostMapping("/watchlistUpdate")
- public Object watchlistUpdate(String symbol, String remark, String score) {
- if (StringUtils.isEmpty(symbol)) {
- throw new ParameterException("symbol不能为空!");
- }
- if (StringUtils.isEmpty(remark) && StringUtils.isEmpty(score)) {
- throw new ParameterException("remark和score不能同时为空!");
- }
- return R.ok().data(coinService.watchlistUpdate(symbol, remark, score));
- }
- @GetMapping("/mainSearchDetail/{nameEn}/{id}")
- public Object mainSearchDetail(@PathVariable String nameEn, @PathVariable String id) {
- return coinService.mainSearchDetail(nameEn, id);
- }
- /**
- * insertOrUpdateWatchlist
- *
- * @author lvzhiqiang
- * 2024/1/20 15:42
- */
- @RequestMapping("/insertOrUpdateWatchlist")
- @ResponseBody
- public R insertOrUpdateWatchlist(String symbol, String trackCategory, String trackCategory2, String issuingDate, Long cmcId, String coingeckoId, String coingeckoUrl, String feixiaohaoUrl, Integer filterFlag, String crudType, String userName) {
- if (StringUtils.isEmpty(crudType)) {
- throw new ParameterException("crudType为空!");
- }
- if (StringUtils.isEmpty(userName)) {
- throw new ParameterException("userName为空!");
- } else {
- JSONObject coinUser = coinMapper.findUserByUsername(userName);
- if (coinUser == null) {
- throw new ParameterException("用户不存在!");
- }
- }
- if (StringUtils.isEmpty(symbol)) {
- throw new ParameterException("symbol为空!");
- }
- if ("1".equals(crudType)) {
- // 新增
- if (StringUtils.isEmpty(issuingDate) || null == cmcId || StringUtils.isEmpty(coingeckoId) || null == filterFlag) {
- throw new ParameterException("参数为空!");
- }
- CoinWatchlist coinWatchlist = new CoinWatchlist();
- coinWatchlist.setSymbol(symbol.trim());
- coinWatchlist.setTrackCategory(StringUtils.isEmpty(trackCategory) ? "" : trackCategory);
- coinWatchlist.setTrackCategory2(StringUtils.isEmpty(trackCategory2) ? "" : trackCategory2);
- coinWatchlist.setIssuingDate(LocalDate.parse(issuingDate, DateUtils.dateFormatter));
- coinWatchlist.setCmcId(cmcId);
- coinWatchlist.setCoingeckoId(coingeckoId);
- coinWatchlist.setCoingeckoUrl(coingeckoUrl);
- coinWatchlist.setFeixiaohaoUrl(feixiaohaoUrl);
- coinWatchlist.setFilterFlag(filterFlag);
- coinMapper.insertOrUpdateWatchlist(coinWatchlist);
- // init data
- coinService.initWatchlist(coinWatchlist);
- } else if ("2".equals(crudType)) {
- // 修改
- CoinWatchlist coinWatchlist = coinMapper.findWatchlistBySymbol(symbol);
- if (coinWatchlist == null) {
- throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "symbol 不存在!");
- }
- if (StringUtils.isNotEmpty(trackCategory)) {
- coinWatchlist.setTrackCategory(trackCategory);
- }
- if (StringUtils.isNotEmpty(trackCategory2)) {
- coinWatchlist.setTrackCategory2(trackCategory2);
- }
- if (StringUtils.isNotEmpty(issuingDate)) {
- coinWatchlist.setIssuingDate(LocalDate.parse(issuingDate, DateUtils.dateFormatter));
- }
- if (null != cmcId) {
- coinWatchlist.setCmcId(cmcId);
- }
- if (StringUtils.isNotEmpty(coingeckoId)) {
- coinWatchlist.setCoingeckoId(coingeckoId);
- }
- if (StringUtils.isNotEmpty(coingeckoUrl)) {
- coinWatchlist.setCoingeckoUrl(coingeckoUrl);
- }
- if (StringUtils.isNotEmpty(feixiaohaoUrl)) {
- coinWatchlist.setFeixiaohaoUrl(feixiaohaoUrl);
- }
- if (null != filterFlag) {
- coinWatchlist.setFilterFlag(filterFlag);
- }
- coinMapper.insertOrUpdateWatchlist(coinWatchlist);
- }
- return R.ok().data("success");
- }
- @PostMapping("/serverMonitorAlarm")
- public void serverMonitorAlarm(@RequestBody JSONObject params) {
- StringBuffer sb = new StringBuffer();
- params.forEach((k, v) -> {
- sb.append(k).append(":").append(v).append("\n");
- });
- if (sb.length() <= 0) {
- return;
- }
- sb.insert(0, "服务器监控告警\n");
- coinService.monitorAlarm(sb.delete(sb.length() - 1, sb.length()).toString(), CoinServiceImpl.JOB_ALARM_MODE_CHAT_BOT);
- }
- @PostMapping("/login")
- public Object login(String username, String password) {
- if (StringUtils.isEmpty(username)) {
- throw new ParameterException("用户名不能为空!");
- }
- if (StringUtils.isEmpty(password)) {
- throw new ParameterException("密码不能为空");
- }
- return coinService.login(username, password);
- }
- }
|