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.MarketVo; import com.gear.common.builder.WhereBuilder; import com.gear.common.core.redis.RedisCache; import com.gear.common.vo.Result; import com.gear.swx.domain.SwxMarketContracts; 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.SwxMarket; import com.gear.swx.service.ISwxMarketService; import com.gear.common.utils.poi.ExcelUtil; /** * 市场产品管理Controller * * @author czx * @date 2023-11-18 */ @RestController @RequestMapping("/swx/market") public class SwxMarketController extends BaseController { @Autowired private ISwxMarketService swxMarketService; @Autowired private RedisCache redisCache; /** * 查询市场产品管理列表 */ @PreAuthorize("@ss.hasPermi('swx:market:list')") @GetMapping("/list") public Result> list(SwxMarket swxMarket, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){ QueryWrapper queryWrapper = WhereBuilder.build(swxMarket); Page page = new Page(pageNo, pageSize); queryWrapper.lambda().orderByDesc(SwxMarket::getCreateTime); IPage pageList = swxMarketService.page(page, queryWrapper); List list = new ArrayList<>(); for(SwxMarket item : pageList.getRecords()){ MarketVo marketVo = new MarketVo(); BeanUtils.copyProperties(item,marketVo); marketVo.setZdf(redisCache.getCacheObject(item.getCode()+"CurrZdf") == null ? BigDecimal.ZERO : new BigDecimal(redisCache.getCacheObject(item.getCode()+"CurrZdf")+"")); marketVo.setPrice(redisCache.getCacheObject(item.getCode()+"CurrPrice") == null ? BigDecimal.ZERO : new BigDecimal(redisCache.getCacheObject(item.getCode()+"CurrPrice")+"")); marketVo.setHundred(redisCache.getCacheList(item.getCode()+"Hundred")); list.add(marketVo); } IPage result = new Page<>(); result.setRecords(list); result.setCurrent(pageList.getCurrent()); result.setPages(pageList.getPages()); result.setSize(pageList.getSize()); result.setTotal(pageList.getTotal()); return Result.OK(result); } /** * 导出市场产品管理列表 */ @PreAuthorize("@ss.hasPermi('swx:market:export')") @Log(title = "市场产品管理", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, SwxMarket swxMarket){ QueryWrapper queryWrapper = WhereBuilder.build(swxMarket); List list = swxMarketService.list(queryWrapper); ExcelUtil util = new ExcelUtil(SwxMarket.class); util.exportExcel(response, list, "市场产品管理数据"); } /** * 获取市场产品管理详细信息 */ @PreAuthorize("@ss.hasPermi('swx:market:query')") @GetMapping(value = "/{id}") public Result getInfo(@PathVariable("id") String id){ SwxMarket swxMarket = swxMarketService.getById(id); if(swxMarket==null) { return Result.error("未找到对应数据"); } return Result.OK(swxMarket); } /** * 新增市场产品管理 */ @PreAuthorize("@ss.hasPermi('swx:market:add')") @Log(title = "市场产品管理", businessType = BusinessType.INSERT) @PostMapping public Result add(@RequestBody SwxMarket swxMarket){ swxMarketService.save(swxMarket); return Result.ok("添加成功!"); } /** * 修改市场产品管理 */ @PreAuthorize("@ss.hasPermi('swx:market:edit')") @Log(title = "市场产品管理", businessType = BusinessType.UPDATE) @PutMapping public Result edit(@RequestBody SwxMarket swxMarket){ swxMarketService.updateById(swxMarket); return Result.ok("编辑成功!"); } /** * 删除市场产品管理 */ @PreAuthorize("@ss.hasPermi('swx:market:remove')") @Log(title = "市场产品管理", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public Result remove(@PathVariable List ids){ swxMarketService.removeBatchByIds(ids); return Result.ok("删除成功!"); } }