| | |
| | | package com.yami.trading.admin.controller.ico; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.google.common.collect.Lists; |
| | | import com.yami.trading.bean.ico.domain.Ico; |
| | | import com.yami.trading.bean.ico.domain.UserSubscription; |
| | | import com.yami.trading.bean.ico.dto.UserSubscriptionDTO; |
| | | import com.yami.trading.bean.ico.query.IcoQuery; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.bean.item.query.ItemQuery; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.query.QueryWrapperGenerator; |
| | | import com.yami.trading.security.common.util.SecurityUtils; |
| | | import com.yami.trading.service.ico.IcoService; |
| | | import com.yami.trading.service.ico.UserSubscriptionService; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.time.Instant; |
| | | import java.util.Date; |
| | | |
| | | |
| | | @Api(tags ="新币管理") |
| | |
| | | |
| | | @Autowired |
| | | private UserSubscriptionService userSubscriptionService; |
| | | |
| | | @Autowired |
| | | ItemService itemService; |
| | | |
| | | /** |
| | | * 产品列表数据 |
| | |
| | | @ApiOperation(value = "保存新币") |
| | | @PostMapping("save") |
| | | public Result <String> save(@Valid @RequestBody Ico ico) { |
| | | long count; |
| | | if (ico.getId() == null) { //新增校验 |
| | | count = icoService.count(new LambdaQueryWrapper<Ico>() |
| | | .eq(Ico::getSymbol, ico.getSymbol()).or().eq(Ico::getSymbolData, ico.getSymbolData())); |
| | | |
| | | } else { |
| | | Ico model = icoService.getById(ico.getId()); |
| | | if (model == null) { |
| | | throw new YamiShopBindException("数据不存在"); |
| | | } |
| | | Date now = Date.from(Instant.now()); |
| | | if (model.getMarketDate() != null && model.getMarketDate().before(now)){ |
| | | throw new YamiShopBindException("已上市不能修改"); |
| | | } |
| | | |
| | | if (!model.getSymbol().equalsIgnoreCase(ico.getSymbol()) || |
| | | !model.getSymbolData().equalsIgnoreCase(ico.getSymbolData())) { |
| | | //修改编码判断是否有人购买 |
| | | QueryWrapper<UserSubscription> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("ico_project_id", ico.getId()); |
| | | long uCount = userSubscriptionService.count(queryWrapper); |
| | | if (uCount > 0) { |
| | | throw new YamiShopBindException("已有申购,禁止修改代币符号,数据源编码"); |
| | | } |
| | | } |
| | | count = icoService.count(new LambdaQueryWrapper<Ico>() |
| | | .ne(Ico::getId, ico.getId()) |
| | | .and(wrapper -> wrapper |
| | | .eq(Ico::getSymbol, ico.getSymbol()) |
| | | .or() |
| | | .eq(Ico::getSymbolData, ico.getSymbolData()))); |
| | | } |
| | | if(count > 0){ |
| | | throw new YamiShopBindException("代币符号或数据源编码已存在"); |
| | | } |
| | | //产品表 |
| | | long iCount = itemService.count(new LambdaQueryWrapper<Item>() |
| | | .eq(Item::getSymbol, ico.getSymbol()).or().eq(Item::getSymbolData, ico.getSymbolData())); |
| | | if(iCount > 0){ |
| | | throw new YamiShopBindException("产品表已存在数据"); |
| | | } |
| | | //新增或编辑表单保存 |
| | | icoService.saveOrUpdate(ico); |
| | | return Result.ok ( "保存产品成功" ); |
| | |
| | | @ApiOperation(value = "删除新币") |
| | | @DeleteMapping("delete") |
| | | public Result <String> delete(Integer id) { |
| | | icoService.removeById(id); |
| | | return Result.ok("删除产品成功"); |
| | | if (id == null) { |
| | | throw new YamiShopBindException("id is null"); |
| | | } |
| | | QueryWrapper<UserSubscription> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("ico_project_id", id); |
| | | long count = userSubscriptionService.count(queryWrapper); |
| | | if (count > 0) { |
| | | throw new YamiShopBindException("已有申购记录,删除失败"); |
| | | } |
| | | if (icoService.removeById(id)) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.ok("删除失败"); |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新币申购记录列表") |
| | | @GetMapping("recordList") |
| | | public Result<Page<UserSubscription>> recordList(IcoQuery icoQuery, Page<UserSubscription> page) throws Exception { |
| | | public Result<Page<UserSubscriptionDTO>> recordList(IcoQuery icoQuery, Page<UserSubscriptionDTO> page) throws Exception { |
| | | QueryWrapper queryWrapper = QueryWrapperGenerator.buildQueryCondition (icoQuery, IcoQuery.class); |
| | | Page<UserSubscription> result = userSubscriptionService.page(page, queryWrapper); |
| | | queryWrapper.eq("u.del_flag", "0"); |
| | | Page<UserSubscriptionDTO> result = userSubscriptionService.findPage(page, queryWrapper); |
| | | return Result.ok(result); |
| | | } |
| | | |