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.admin.vo.swx.MarketSmartVo;
|
import com.gear.common.builder.WhereBuilder;
|
import com.gear.common.core.redis.RedisCache;
|
import com.gear.common.vo.Result;
|
import com.gear.swx.domain.SwxMarket;
|
import com.gear.swx.domain.SwxMarketContracts;
|
import com.gear.swx.domain.SwxMarketOptions;
|
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.SwxMarketSmart;
|
import com.gear.swx.service.ISwxMarketSmartService;
|
import com.gear.common.utils.poi.ExcelUtil;
|
|
/**
|
* 智能产品管理Controller
|
*
|
* @author czx
|
* @date 2023-11-20
|
*/
|
@RestController
|
@RequestMapping("/swx/marketSmart")
|
public class SwxMarketSmartController extends BaseController
|
{
|
@Autowired
|
private ISwxMarketSmartService swxMarketSmartService;
|
|
@Autowired
|
private ISwxMarketService swxMarketService;
|
|
@Autowired
|
private RedisCache redisCache;
|
|
/**
|
* 查询智能产品管理列表
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:marketSmart:list')")
|
@GetMapping("/list")
|
public Result<IPage<MarketSmartVo>> list(MarketSmartVo swxMarketSmart,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
|
QueryWrapper<SwxMarketSmart> queryWrapper = new QueryWrapper<>();
|
if(!Strings.isEmpty(swxMarketSmart.getCode()) || !Strings.isEmpty(swxMarketSmart.getName()) || swxMarketSmart.getType() != null){
|
QueryWrapper<SwxMarket> marketQueryWrapper = new QueryWrapper<>();
|
if(!Strings.isEmpty(swxMarketSmart.getCode())){
|
marketQueryWrapper.lambda().like(SwxMarket::getCode,swxMarketSmart.getCode());
|
}
|
if(!Strings.isEmpty(swxMarketSmart.getName())){
|
marketQueryWrapper.lambda().like(SwxMarket::getName,swxMarketSmart.getName());
|
}
|
if(swxMarketSmart.getType() != null){
|
marketQueryWrapper.lambda().eq(SwxMarket::getType,swxMarketSmart.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(SwxMarketSmart::getMId,ids);
|
}
|
Page<SwxMarketSmart> page = new Page<SwxMarketSmart>(pageNo, pageSize);
|
queryWrapper.lambda().orderByDesc(SwxMarketSmart::getCreateTime);
|
IPage<SwxMarketSmart> pageList = swxMarketSmartService.page(page, queryWrapper);
|
IPage<MarketSmartVo> result = new Page<>();
|
List<MarketSmartVo> records = new ArrayList<>();
|
for(SwxMarketSmart item : pageList.getRecords()){
|
MarketSmartVo vo = new MarketSmartVo();
|
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:marketSmart:export')")
|
@Log(title = "智能产品管理", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, SwxMarketSmart swxMarketSmart){
|
QueryWrapper<SwxMarketSmart> queryWrapper = WhereBuilder.build(swxMarketSmart);
|
List<SwxMarketSmart> list = swxMarketSmartService.list(queryWrapper);
|
ExcelUtil<SwxMarketSmart> util = new ExcelUtil<SwxMarketSmart>(SwxMarketSmart.class);
|
util.exportExcel(response, list, "智能产品管理数据");
|
}
|
|
/**
|
* 获取智能产品管理详细信息
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:marketSmart:query')")
|
@GetMapping(value = "/{id}")
|
public Result<SwxMarketSmart> getInfo(@PathVariable("id") String id){
|
SwxMarketSmart swxMarketSmart = swxMarketSmartService.getById(id);
|
if(swxMarketSmart==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(swxMarketSmart);
|
}
|
|
|
/**
|
* 修改智能产品管理
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:marketSmart:edit')")
|
@Log(title = "智能产品管理", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public Result<String> edit(@RequestBody SwxMarketSmart swxMarketSmart){
|
//更新市场信息时,如果状态设置为不启用,则将market表状态修改
|
if(swxMarketSmart.getStatus() != null){
|
SwxMarketSmart old = swxMarketSmartService.getById(swxMarketSmart.getId());
|
SwxMarket swxMarket = swxMarketService.getById(old.getMId());
|
swxMarket.setCanContracts(swxMarketSmart.getStatus());
|
swxMarketService.updateById(swxMarket);
|
}
|
swxMarketSmartService.updateById(swxMarketSmart);
|
return Result.ok("编辑成功!");
|
}
|
|
}
|