package com.ruoyi.project.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.project.domain.GiApi; import com.ruoyi.project.domain.dto.ApiDTO; import com.ruoyi.project.mapper.ApiMapper; import com.ruoyi.project.service.IApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; import java.util.Map; @Service public class ApiServiceImpl extends ServiceImpl implements IApiService { @Autowired ApiMapper mapper; /** * 主键查询详细 * @param code * @return */ public GiApi getCode(String code){ QueryWrapper wrapper=new QueryWrapper<>(); wrapper.eq("api_Code",code); return mapper.selectOne(wrapper); } public String buildSql(HttpServletRequest request, String sql) { // JSONArray requestParams = JSON.parseArray(config.getParams()); // for (int i = 0; i < requestParams.size(); i++) { // JSONObject jo = requestParams.getJSONObject(i); // String name = jo.getString("name"); // String type = jo.getString("type"); // String old = '$' + name; // // String value = request.getParameter(name); // // //不是数字类型的值要加单引号 // if (!"number".equals(type)) { // value = String.format("'%s'", value); // } // // sql = sql.replace(old, value); // } return sql; } /** * 查询数据列表 * @param DTO * @return */ public List> getListSql(String sql, ApiDTO DTO) { if(DTO.getParams()!=null) { for (String key : DTO.getParams().keySet()) { sql = sql.replace("@" + key, DTO.getParams().get(key) + ""); } } return mapper.executeSql(sql); } /** * 查询数据列表 * @param DTO * @return */ public String getStringSql(String sql, ApiDTO DTO) { if(DTO.getParams()!=null) { for (String key : DTO.getParams().keySet()) { sql = sql.replace("@" + key, DTO.getParams().get(key) + ""); } } return mapper.getClob(sql); } }