package com.nq.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.nq.common.ServerResponse; import com.nq.dao.StockConfigMapper; import com.nq.pojo.StockConfig; import com.nq.service.IStockConfigServices; import org.apache.http.util.TextUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class StockConfigServicesImpl implements IStockConfigServices { @Resource StockConfigMapper stockConfigMapper; @Override public ServerResponse updateStockConfig(StockConfig stockConfig) { int ref = stockConfigMapper.updateById(stockConfig); if(ref>0){ return ServerResponse.createBySuccess(); } return ServerResponse.createByErrorMsg("设置失败"); } @Override public ServerResponse queryAll(String desc) { if(TextUtils.isEmpty(desc)){ return ServerResponse.createBySuccess(stockConfigMapper.selectList(new QueryWrapper<>())); } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.like("c_desc",desc); return ServerResponse.createBySuccess(stockConfigMapper.selectList(queryWrapper)); } @Override public StockConfig queryByKey(String key) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("c_key",key); return stockConfigMapper.selectOne(queryWrapper); } @Override public Map queryByKeys(List keys) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.in("c_key", keys); List stockConfigs = stockConfigMapper.selectList(queryWrapper); // 构建结果的 Map Map resultMap = new HashMap<>(); for (StockConfig config : stockConfigs) { resultMap.put(config.getCKey(), config); } return resultMap; } }