zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
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
package com.gear.admin.controller.swx;;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.gear.admin.vo.swx.MarketCantractsVo;
import com.gear.common.builder.WhereBuilder;
import com.gear.common.constant.SwxConstons;
import com.gear.common.core.redis.RedisCache;
import com.gear.common.vo.Result;
import com.gear.swx.domain.SwxLoanSettings;
import com.gear.swx.domain.SwxMarket;
import com.gear.swx.domain.SwxMarketSmart;
import com.gear.swx.service.ISwxMarketService;
import io.jsonwebtoken.lang.Collections;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gear.common.annotation.Log;
import com.gear.common.core.controller.BaseController;
import com.gear.common.enums.BusinessType;
import com.gear.swx.domain.SwxMarketContracts;
import com.gear.swx.service.ISwxMarketContractsService;
import com.gear.common.utils.poi.ExcelUtil;
 
/**
 * 合约产品管理Controller
 * 
 * @author czx
 * @date 2023-11-20
 */
@RestController
@RequestMapping("/swx/marketContracts")
public class SwxMarketContractsController extends BaseController
{
    @Autowired
    private ISwxMarketContractsService swxMarketContractsService;
 
    @Autowired
    private ISwxMarketService swxMarketService;
 
    @Autowired
    private RedisCache redisCache;
    /**
     * 查询合约产品管理列表
     */
    @PreAuthorize("@ss.hasPermi('swx:marketContracts:list')")
    @GetMapping("/list")
    public Result<IPage<MarketCantractsVo>> list(MarketCantractsVo swxMarketContracts,
                                                 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        QueryWrapper<SwxMarketContracts> queryWrapper = new QueryWrapper<>();
        if(!Strings.isEmpty(swxMarketContracts.getCode()) || !Strings.isEmpty(swxMarketContracts.getName()) || swxMarketContracts.getType() != null){
            QueryWrapper<SwxMarket> marketQueryWrapper = new QueryWrapper<>();
            if(!Strings.isEmpty(swxMarketContracts.getCode())){
                marketQueryWrapper.lambda().like(SwxMarket::getCode,swxMarketContracts.getCode());
            }
            if(!Strings.isEmpty(swxMarketContracts.getName())){
                marketQueryWrapper.lambda().like(SwxMarket::getName,swxMarketContracts.getName());
            }
            if(swxMarketContracts.getType() != null){
                marketQueryWrapper.lambda().eq(SwxMarket::getType,swxMarketContracts.getType());
            }
            List<SwxMarket> list = swxMarketService.list(marketQueryWrapper);
            List<String> ids = new ArrayList<>();
            if(!Collections.isEmpty(list)){
                for (SwxMarket item : list){
                    ids.add(item.getId());
                }
            }else{
                ids.add("");
            }
            queryWrapper.lambda().in(SwxMarketContracts::getMId,ids);
        }
        Page<SwxMarketContracts> page = new Page<SwxMarketContracts>(pageNo, pageSize);
        queryWrapper.lambda().orderByDesc(SwxMarketContracts::getCreateTime);
        IPage<SwxMarketContracts> pageList = swxMarketContractsService.page(page, queryWrapper);
        IPage<MarketCantractsVo> result = new Page<>();
        List<MarketCantractsVo> records = new ArrayList<>();
        for(SwxMarketContracts item : pageList.getRecords()){
            MarketCantractsVo vo = new MarketCantractsVo();
            BeanUtils.copyProperties(item,vo);
            SwxMarket swxMarket = swxMarketService.getById(item.getMId());
            if(swxMarket != null){
                vo.setName(swxMarket.getName());
                vo.setCode(swxMarket.getCode());
                vo.setType(swxMarket.getType());
                vo.setZdf(redisCache.getCacheObject(swxMarket.getCode()+"CurrZdf") == null ? BigDecimal.ZERO : new BigDecimal(redisCache.getCacheObject(swxMarket.getCode()+"CurrZdf")+""));
                vo.setPrice(redisCache.getCacheObject(swxMarket.getCode()+"CurrPrice") == null ? BigDecimal.ZERO : new BigDecimal(redisCache.getCacheObject(swxMarket.getCode()+"CurrPrice")+""));
                vo.setHundred(redisCache.getCacheList(swxMarket.getCode()+"Hundred"));
            }
            records.add(vo);
        }
        result.setRecords(records);
        result.setCurrent(pageList.getCurrent());
        result.setPages(pageList.getPages());
        result.setSize(pageList.getSize());
        result.setTotal(pageList.getTotal());
        return Result.OK(result);
    }
 
    /**
     * 导出合约产品管理列表
     */
    @PreAuthorize("@ss.hasPermi('swx:marketContracts:export')")
    @Log(title = "合约产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwxMarketContracts swxMarketContracts){
        QueryWrapper<SwxMarketContracts> queryWrapper = WhereBuilder.build(swxMarketContracts);
        List<SwxMarketContracts> list = swxMarketContractsService.list(queryWrapper);
        ExcelUtil<SwxMarketContracts> util = new ExcelUtil<SwxMarketContracts>(SwxMarketContracts.class);
        util.exportExcel(response, list, "合约产品管理数据");
    }
 
    /**
     * 获取合约产品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('swx:marketContracts:query')")
    @GetMapping(value = "/{id}")
    public Result<SwxMarketContracts>  getInfo(@PathVariable("id") String id){
        SwxMarketContracts swxMarketContracts = swxMarketContractsService.getById(id);
        if(swxMarketContracts==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(swxMarketContracts);
    }
 
 
    /**
     * 修改合约产品管理
     */
    @PreAuthorize("@ss.hasPermi('swx:marketContracts:edit')")
    @Log(title = "合约产品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public  Result<String> edit(@RequestBody SwxMarketContracts swxMarketContracts){
        //更新市场信息时,如果状态设置为不启用,则将market表状态修改
        if(swxMarketContracts.getStatus() != null){
            SwxMarketContracts old = swxMarketContractsService.getById(swxMarketContracts.getId());
            SwxMarket swxMarket =  swxMarketService.getById(old.getMId());
            swxMarket.setCanContracts(swxMarketContracts.getStatus());
            swxMarketService.updateById(swxMarket);
        }
        swxMarketContractsService.updateById(swxMarketContracts);
        return Result.ok("编辑成功!");
    }
 
}