zyy
2025-12-29 645f40f5f61f8fa217ef01b5b2aaaf687b173577
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
package com.yami.trading.admin.controller.syspara;
 
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.domain.Result;
 
import javax.validation.Valid;
 
import com.google.common.collect.Lists;
import com.yami.trading.common.query.QueryWrapperGenerator;
 
import com.yami.trading.service.item.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.bean.syspara.domain.OpenClose;
 
import com.yami.trading.bean.syspara.dto.OpenCloseDTO;
import com.yami.trading.bean.syspara.mapstruct.OpenCloseWrapper;
import com.yami.trading.service.syspara.OpenCloseService;
import com.yami.trading.bean.syspara.query.OpenCloseQuery;
 
import java.util.List;
import java.util.stream.Stream;
 
 
/**
 * 开盘停盘时间设置Controller
 *
 * @author lucas
 * @version 2023-05-20
 */
 
@Api(tags = "开盘停盘时间设置")
@RestController
@CrossOrigin
@RequestMapping(value = "/syspara/openClose")
public class OpenCloseController {
 
    @Autowired
    private OpenCloseService openCloseService;
 
    @Autowired
    private OpenCloseWrapper openCloseWrapper;
    @Autowired
    private ItemService itemService;
 
    /**
     * 开盘停盘时间设置列表数据
     */
    @ApiOperation(value = "查询开盘停盘时间设置列表数据")
    @GetMapping("list")
    public Result<IPage<OpenClose>> list(OpenCloseQuery openCloseQuery, Page<OpenClose> page) throws Exception {
        QueryWrapper queryWrapper = QueryWrapperGenerator.buildQueryCondition(openCloseQuery, OpenCloseQuery.class);
        IPage<OpenClose> result = openCloseService.page(page, queryWrapper);
        List<OpenClose> records = result.getRecords();
        for(OpenClose record: records){
            Item bySymbol = itemService.findBySymbol(record.getSymbol());
            if(bySymbol != null){
                record.setSymbolName(bySymbol.getName());
            }
        }
        return Result.ok(result);
    }
 
 
    /**
     * 根据Id获取开盘停盘时间设置数据
     */
    @ApiOperation(value = "根据Id获取开盘停盘时间设置数据")
    @GetMapping("queryById")
    public Result<OpenCloseDTO> queryById(String id) {
        return Result.ok(openCloseWrapper.toDTO(openCloseService.getById(id)));
    }
 
    /**
     * 保存开盘停盘时间设置
     */
    @ApiOperation(value = "保存开盘停盘时间设置")
    @PostMapping("save")
    public Result<String> save(@Valid @RequestBody OpenCloseDTO openCloseDTO) {
        //新增或编辑表单保存
        OpenClose entity = openCloseWrapper.toEntity(openCloseDTO);
        entity.setCloseTs( openCloseDTO.getCloseBjDate().getTime());
        entity.setOpenTs(openCloseDTO.getOpenBjDate().getTime());
        try {
            openCloseService.saveOrUpdate(entity);
        }catch (DuplicateKeyException e){
            return Result.failed("当前币对所在时段已经配置过开盘时间了");
 
        }
        return Result.ok("保存开盘停盘时间设置成功");
    }
 
 
    /**
     * 删除开盘停盘时间设置
     */
    @ApiOperation(value = "删除开盘停盘时间设置")
    @DeleteMapping("delete")
    public Result<String> delete(String ids) {
        String idArray[] = ids.split(",");
        openCloseService.removeByIds(Lists.newArrayList(idArray));
        return Result.ok("删除开盘停盘时间设置成功");
    }
 
}