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
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<ApiMapper, GiApi> implements IApiService {
    @Autowired
      ApiMapper mapper;
    /**
     * 主键查询详细
     * @param code
     * @return
     */
    public GiApi getCode(String code){
        QueryWrapper <GiApi> 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<Map<String,Object>> 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);
    }
}