1
zyy
2 days ago a6c07a0526befbbd8194c97eb8f64b84b1a477a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.yami.trading.admin.controller.purchasing;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.controller.purchasing.dto.ProjectBreedDto;
import com.yami.trading.admin.controller.purchasing.dto.RealtimeDto;
import com.yami.trading.admin.controller.purchasing.model.*;
import com.yami.trading.admin.model.IdModel;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.log.dto.LogDto;
import com.yami.trading.bean.purchasing.ProjectBreed;
import com.yami.trading.bean.purchasing.ProjectVariety;
import com.yami.trading.bean.purchasing.dto.RelatedStockDto;
import com.yami.trading.common.domain.PageRequest;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.purchasing.ProjectBreedService;
import com.yami.trading.service.purchasing.ProjectVarietyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@RestController
@CrossOrigin
@RequestMapping("projectVariety")
@Api(tags = "ETF品种管理")
@Slf4j
public class ProjectVarietyController {
    @Autowired
    ProjectVarietyService projectVarietyService;
    @Autowired
    ProjectBreedService projectBreedService;
    @Autowired
    DataService dataService;
 
    @Autowired
    ItemService itemService;
    @ApiOperation(value = "列表")
    @PostMapping("list")
    public Result<Page<ProjectVariety>> list(@RequestBody @Valid PageRequest request) {
        QueryWrapper<ProjectBreed> projectBreedQueryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(request.getProjectName())){
           projectBreedQueryWrapper.like("project_name", request.getProjectName());
        }
        List<ProjectBreed> list = projectBreedService.list(projectBreedQueryWrapper);
        List<String> projectBreedIds = list.stream().map(ProjectBreed::getUuid).collect(Collectors.toList());
        QueryWrapper<ProjectVariety> queryWrapper = new QueryWrapper<>();
        if(CollectionUtil.isNotEmpty(projectBreedIds)){
            queryWrapper.in("project_breed_id", projectBreedIds);
        }
        queryWrapper.orderByDesc("update_time");
 
        Page<ProjectVariety> page = new Page(request.getCurrent(), request.getSize());
        projectVarietyService.page(page, queryWrapper);
        for (ProjectVariety projectVariety : page.getRecords()) {
            List<Realtime> realtimes = dataService.realtime(projectVariety.getRelatedStockSymbol());
            if(CollectionUtil.isEmpty(realtimes)){
                log.error("ETF品种管理 获取实时价格为空 {}", projectVariety.getRelatedStockSymbol());
                continue;
            }
            Realtime realtime = realtimes.get(0);
            projectVariety.setRealtime(realtime);
            Item item= itemService.findBySymbol(projectVariety.getRelatedStockSymbol());
            if (item!=null){
                projectVariety.setDataType(item.getFake().equals("1")?1:2);
                projectVariety.setRelatedStockName(item.getName());
                projectVariety.setItemId(item.getUuid());
            }
        }
        return Result.ok(page);
    }
 
    @ApiOperation(value = "新增")
    @PostMapping("add")
    public Result add(@RequestBody @Valid ProjectVarietyAddModel addModel) {
        ProjectVariety projectBreed = new ProjectVariety();
        BeanUtils.copyProperties(addModel, projectBreed);
        List<RelatedStockDto> relatedStockDtos = new ArrayList<>();
        StringBuffer sb=new StringBuffer();
//        for (String str : addModel.getRelatedStockVarieties()) {
//            List<Realtime> list = dataService.realtime(str);
//            Item item= itemService.findBySymbol(str);
//            if (!CollectionUtil.isEmpty(list)) {
//                Realtime realtime = list.get(0);
//                RelatedStockDto dto = new RelatedStockDto();
//                dto.setSymbol(realtime.getSymbol());
//                dto.setName(realtime.getName());
//                relatedStockDtos.add(dto);
//                sb.append(realtime.getName()+",");
//            }
//        }
//        if (sb.length()==0){
//            projectBreed.setRelatedStockVarieties("");
//        }else {
//            projectBreed.setRelatedStockVarieties(sb.substring(0,sb.length()-1));
//        }
//        projectVarietyService.saveProjectBreed(projectBreed, relatedStockDtos);
        projectVarietyService.save(projectBreed);
        return Result.ok(null);
    }
 
    @ApiOperation(value = "更新")
    @PostMapping("update")
    public Result<Page<LogDto>> update(@RequestBody @Valid ProjectVarietyUpdateModel updateModel) {
        ProjectVariety projectBreed = projectVarietyService.getById(updateModel.getId());
        if (projectBreed == null) {
            throw new YamiShopBindException("参数错误!");
        }
        BeanUtils.copyProperties(updateModel, projectBreed);
        projectVarietyService.updateById(projectBreed);
        return Result.succeed();
    }
 
    @ApiOperation(value = "获取详情")
    @PostMapping("getDesc")
    public Result<ProjectBreedDto> getDesc(@RequestBody @Valid IdModel idModel) {
        ProjectVariety projectBreed = projectVarietyService.getById(idModel.getId());
        if (projectBreed == null) {
            throw new YamiShopBindException("参数错误!");
        }
        List<Realtime> list = dataService.realtime(projectBreed.getTransactionPairsSymbol());
        ProjectBreedDto dto = new ProjectBreedDto();
        BeanUtils.copyProperties(projectBreed, dto);
        if (!CollectionUtil.isEmpty(list)) {
            Realtime realtime = list.get(0);
            RealtimeDto realtimeDto = new RealtimeDto();
            realtimeDto.setAmount(realtime.getAmount());
            realtimeDto.setClose(realtime.getClose());
            realtimeDto.setLow(realtime.getLow());
            realtimeDto.setHigh(realtime.getHigh());
            realtimeDto.setOpenInterest(realtime.getVolume());
            realtimeDto.setDailyIncrement(realtime.getAmount());
            dto.setRealtimeDto(realtimeDto);
            Item item= itemService.findBySymbol(projectBreed.getRelatedStockSymbol());
            if (item!=null){
                projectBreed.setDataType(item.getFake().equals("1")?1:2);
                projectBreed.setRelatedStockName(item.getName());
                projectBreed.setItemId(item.getUuid());
            }
        }
        return Result.ok(dto);
    }
 
    @ApiOperation(value = "删除")
    @PostMapping("delete")
    public Result delete(@RequestBody @Valid IdModel idModel) {
//        projectVarietyService.deleteProjectBreed(idModel.getId());
        projectVarietyService.deleteByProjectBreedId(idModel.getId());
        return Result.succeed();
    }
 
}