正在显示
9 个修改的文件
包含
499 行增加
和
3 行删除
| 1 | +package com.ruoyi.system.domain.log; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +@ApiModel("水产舆情") | ||
| 7 | +public class LogExcelSub { | ||
| 8 | + @ApiModelProperty(value="主键") | ||
| 9 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 10 | + @ApiModelProperty(value="记录id") | ||
| 11 | + private String log_id; // | ||
| 12 | + @ApiModelProperty(value="平台类型(1:飞书,2:wps)") | ||
| 13 | + private Integer system_type; // int NOT NULL COMMENT '平台类型(1:飞书,2:wps)', | ||
| 14 | + @ApiModelProperty(value="创建时间") | ||
| 15 | + private String create_time; // datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 16 | + @ApiModelProperty(value="表格唯一主键") | ||
| 17 | + private String excel_id; // varchar(50) DEFAULT NULL COMMENT '表格唯一主键', | ||
| 18 | + @ApiModelProperty(value="sheet唯一主键") | ||
| 19 | + private String sheet_id; // varchar(50) DEFAULT NULL COMMENT 'sheet唯一主键', | ||
| 20 | + @ApiModelProperty(value="提交的数据") | ||
| 21 | + private String sub_data; // json DEFAULT NULL, | ||
| 22 | + | ||
| 23 | + public String getLog_id() { | ||
| 24 | + return log_id; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setLog_id(String log_id) { | ||
| 28 | + this.log_id = log_id; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public Integer getId() { | ||
| 32 | + return id; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setId(Integer id) { | ||
| 36 | + this.id = id; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public Integer getSystem_type() { | ||
| 40 | + return system_type; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setSystem_type(Integer system_type) { | ||
| 44 | + this.system_type = system_type; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getCreate_time() { | ||
| 48 | + return create_time; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setCreate_time(String create_time) { | ||
| 52 | + this.create_time = create_time; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getExcel_id() { | ||
| 56 | + return excel_id; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setExcel_id(String excel_id) { | ||
| 60 | + this.excel_id = excel_id; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getSheet_id() { | ||
| 64 | + return sheet_id; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setSheet_id(String sheet_id) { | ||
| 68 | + this.sheet_id = sheet_id; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public String getSub_data() { | ||
| 72 | + return sub_data; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setSub_data(String sub_data) { | ||
| 76 | + this.sub_data = sub_data; | ||
| 77 | + } | ||
| 78 | +} |
| 1 | package com.zhonglai.luhui.dao.dto; | 1 | package com.zhonglai.luhui.dao.dto; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.dao.dto.SqlResult; | ||
| 4 | + | ||
| 3 | import com.ruoyi.common.annotation.PublicSQLConfig; | 5 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import org.apache.commons.lang3.StringUtils; | 6 | import org.apache.commons.lang3.StringUtils; |
| 5 | 7 | ||
| @@ -782,4 +784,26 @@ public class PublicSQL { | @@ -782,4 +784,26 @@ public class PublicSQL { | ||
| 782 | } | 784 | } |
| 783 | return select; | 785 | return select; |
| 784 | } | 786 | } |
| 787 | + | ||
| 788 | + public String buildSql(Map<String, Object> para) { | ||
| 789 | + | ||
| 790 | + SqlResult sqlResult = (SqlResult) para.get("sqlResult"); | ||
| 791 | + String sql = sqlResult.getSql(); | ||
| 792 | + | ||
| 793 | + // 参数列表 | ||
| 794 | + List<Object> params = sqlResult.getParams(); | ||
| 795 | + | ||
| 796 | + // 将 “?” 替换为 #{param1}, #{param2}…… | ||
| 797 | + if (params != null) { | ||
| 798 | + for (int i = 0; i < params.size(); i++) { | ||
| 799 | + para.put("param" + (i + 1), params.get(i)); | ||
| 800 | + | ||
| 801 | + // 用第一个 '?' 替换为 #{paramX} | ||
| 802 | + sql = sql.replaceFirst("\\?", "#{param" + (i + 1) + "}"); | ||
| 803 | + } | ||
| 804 | + } | ||
| 805 | + | ||
| 806 | + return sql; | ||
| 807 | + } | ||
| 808 | + | ||
| 785 | } | 809 | } |
| 1 | +package com.zhonglai.luhui.dao.dto; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +public class SqlResult { | ||
| 6 | + private String sql; | ||
| 7 | + private List<Object> params; | ||
| 8 | + | ||
| 9 | + public String getSql() { | ||
| 10 | + return sql; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public void setSql(String sql) { | ||
| 14 | + this.sql = sql; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public List<Object> getParams() { | ||
| 18 | + return params; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setParams(List<Object> params) { | ||
| 22 | + this.params = params; | ||
| 23 | + } | ||
| 24 | +} |
| 1 | package com.zhonglai.luhui.dao.mapper; | 1 | package com.zhonglai.luhui.dao.mapper; |
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.dao.dto.PublicSQL; | 3 | import com.zhonglai.luhui.dao.dto.PublicSQL; |
| 4 | +import com.zhonglai.luhui.dao.dto.SqlResult; | ||
| 4 | import org.apache.ibatis.annotations.*; | 5 | import org.apache.ibatis.annotations.*; |
| 5 | import org.springframework.stereotype.Component; | 6 | import org.springframework.stereotype.Component; |
| 6 | 7 | ||
| @@ -153,4 +154,7 @@ public interface PublicMapper { | @@ -153,4 +154,7 @@ public interface PublicMapper { | ||
| 153 | @Options(useGeneratedKeys = false) | 154 | @Options(useGeneratedKeys = false) |
| 154 | @InsertProvider(type = PublicSQL.class, method = "updateBySql") | 155 | @InsertProvider(type = PublicSQL.class, method = "updateBySql") |
| 155 | int insertIntoBySql(@Param("sql") String sql); | 156 | int insertIntoBySql(@Param("sql") String sql); |
| 157 | + | ||
| 158 | + @SelectProvider(type = PublicSQL.class, method = "buildSql") | ||
| 159 | + List<Map<String, Object>> getDynamicList(@Param("sqlResult") SqlResult sqlResult); | ||
| 156 | } | 160 | } |
| 1 | package com.zhonglai.luhui.dao.service; | 1 | package com.zhonglai.luhui.dao.service; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.dao.dto.SqlResult; | ||
| 4 | + | ||
| 3 | import java.util.List; | 5 | import java.util.List; |
| 4 | import java.util.Map; | 6 | import java.util.Map; |
| 5 | 7 | ||
| @@ -127,4 +129,6 @@ public interface PublicService { | @@ -127,4 +129,6 @@ public interface PublicService { | ||
| 127 | int insertIntoBySql(String sql); | 129 | int insertIntoBySql(String sql); |
| 128 | 130 | ||
| 129 | public Long selectCountBySql(String sql); | 131 | public Long selectCountBySql(String sql); |
| 132 | + public List<Map<String,Object>> getDynamicList(SqlResult sqlResult); | ||
| 133 | + | ||
| 130 | } | 134 | } |
| 1 | package com.zhonglai.luhui.dao.service.impl; | 1 | package com.zhonglai.luhui.dao.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.dao.dto.SqlResult; | ||
| 4 | import com.zhonglai.luhui.dao.mapper.PublicMapper; | 5 | import com.zhonglai.luhui.dao.mapper.PublicMapper; |
| 5 | import com.zhonglai.luhui.dao.service.PublicService; | 6 | import com.zhonglai.luhui.dao.service.PublicService; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -220,4 +221,9 @@ public class PublicServiceImpl implements PublicService { | @@ -220,4 +221,9 @@ public class PublicServiceImpl implements PublicService { | ||
| 220 | { | 221 | { |
| 221 | return publicMapper.insertIntoBySql(sql); | 222 | return publicMapper.insertIntoBySql(sql); |
| 222 | } | 223 | } |
| 224 | + | ||
| 225 | + public List<Map<String,Object>> getDynamicList(SqlResult sqlResult) | ||
| 226 | + { | ||
| 227 | + return publicMapper.getDynamicList(sqlResult); | ||
| 228 | + } | ||
| 223 | } | 229 | } |
| 1 | +package com.ruoyi.common.utils; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.html.HttpUtils; | ||
| 4 | +import okhttp3.Response; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | + | ||
| 8 | +import javax.crypto.Mac; | ||
| 9 | +import javax.crypto.spec.SecretKeySpec; | ||
| 10 | +import java.io.IOException; | ||
| 11 | +import java.nio.charset.StandardCharsets; | ||
| 12 | +import java.security.InvalidKeyException; | ||
| 13 | +import java.security.MessageDigest; | ||
| 14 | +import java.security.NoSuchAlgorithmException; | ||
| 15 | +import java.time.ZoneId; | ||
| 16 | +import java.time.ZonedDateTime; | ||
| 17 | +import java.time.format.DateTimeFormatter; | ||
| 18 | +import java.util.Date; | ||
| 19 | +import java.util.Locale; | ||
| 20 | +import java.util.Map; | ||
| 21 | + | ||
| 22 | +public class WpsUtil { | ||
| 23 | + private static final Logger logger = LoggerFactory.getLogger(WpsUtil.class); | ||
| 24 | + | ||
| 25 | + private static final String accessKey = "AK123456"; | ||
| 26 | + private static final String secretKey = "sk098765"; | ||
| 27 | + public static final class Out { | ||
| 28 | + private final String date; // X-Kso-Date | ||
| 29 | + private final String authorization; // X-Kso-Authorization | ||
| 30 | + | ||
| 31 | + public Out(String date, String authorization) { | ||
| 32 | + this.date = date; | ||
| 33 | + this.authorization = authorization; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public String getDate() { | ||
| 37 | + return date; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public String getAuthorization() { | ||
| 41 | + return authorization; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public static Out kso1Sign(String method, String uri, String contentType, String ksoDate, byte[] requestBody) throws NoSuchAlgorithmException, InvalidKeyException { | ||
| 46 | + String ksoSignature = getKso1Signature(method, uri, contentType, ksoDate, requestBody); | ||
| 47 | + String authorization = String.format("KSO-1 %s:%s", accessKey, ksoSignature); | ||
| 48 | + return new Out(ksoDate, authorization); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + private static String getKso1Signature(String method, String uri, String contentType, String ksoDate, byte[] requestBody) throws NoSuchAlgorithmException, InvalidKeyException { | ||
| 52 | + String sha256Hex = ""; | ||
| 53 | + if (requestBody != null && requestBody.length > 0) { | ||
| 54 | + MessageDigest digest = MessageDigest.getInstance("SHA-256"); | ||
| 55 | + byte[] hash = digest.digest(requestBody); | ||
| 56 | + sha256Hex = bytesToHex(hash); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + System.out.println("sha256: " + sha256Hex); | ||
| 60 | + | ||
| 61 | + String dataToSign = "KSO-1" + method + uri + contentType + ksoDate + sha256Hex; | ||
| 62 | + Mac mac = Mac.getInstance("HmacSHA256"); | ||
| 63 | + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256"); | ||
| 64 | + mac.init(secretKeySpec); | ||
| 65 | + byte[] macBytes = mac.doFinal(dataToSign.getBytes(StandardCharsets.UTF_8)); | ||
| 66 | + return bytesToHex(macBytes); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + private static String bytesToHex(byte[] bytes) { | ||
| 70 | + StringBuilder result = new StringBuilder(); | ||
| 71 | + for (byte b : bytes) { | ||
| 72 | + result.append(String.format("%02x", b)); | ||
| 73 | + } | ||
| 74 | + return result.toString(); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public static String getFeishuTable(String authorization, String date, String file_id, Map<String,Object> body) | ||
| 78 | + { | ||
| 79 | + String url = "https://openapi.wps.cn/v7/coop/dbsheet/"+file_id+"/sheets/{sheet_id}/records/search"; | ||
| 80 | + try { | ||
| 81 | + | ||
| 82 | + Response response = HttpUtils.postJsonBody(url, builder -> { | ||
| 83 | + builder.addHeader("Content-Type", "application/json"); | ||
| 84 | +// builder.addHeader("Authorization", "Bearer " + tenant_access_token); | ||
| 85 | + }, jsonObject -> { | ||
| 86 | + if(null != body && body.size() > 0) | ||
| 87 | + { | ||
| 88 | + for(String key : body.keySet()) | ||
| 89 | + { | ||
| 90 | + jsonObject.put(key,body.get(key)); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + }); | ||
| 94 | + String str = response.body().string(); | ||
| 95 | + return str; | ||
| 96 | + } catch (IOException e) { | ||
| 97 | + logger.error("查询飞书表数据异常",e); | ||
| 98 | + } | ||
| 99 | + return null; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public static void main(String[] args) throws Exception { | ||
| 103 | + final String method = "POST"; | ||
| 104 | + final String uri = "/v7/test/body"; | ||
| 105 | + final String contentType = "application/json"; | ||
| 106 | + final String contentDate = ZonedDateTime.now(ZoneId.of("GMT")).format(DateTimeFormatter | ||
| 107 | + .ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH)); | ||
| 108 | + final byte[] requestBody = "{\"key\": \"value\"}".getBytes(StandardCharsets.UTF_8); | ||
| 109 | + | ||
| 110 | + Out out = kso1Sign(method, uri, contentType, contentDate, requestBody); | ||
| 111 | + System.out.println(out.getDate()); | ||
| 112 | + System.out.println(out.getAuthorization()); | ||
| 113 | + } | ||
| 114 | +} |
| @@ -6,7 +6,11 @@ import com.google.gson.JsonObject; | @@ -6,7 +6,11 @@ import com.google.gson.JsonObject; | ||
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | import com.ruoyi.common.utils.FeishuUtil; | 7 | import com.ruoyi.common.utils.FeishuUtil; |
| 8 | import com.ruoyi.common.utils.GsonConstructor; | 8 | import com.ruoyi.common.utils.GsonConstructor; |
| 9 | +import com.ruoyi.system.domain.log.LogExcelSub; | ||
| 9 | import com.zhonglai.luhui.api.controller.test.dto.ClueData; | 10 | import com.zhonglai.luhui.api.controller.test.dto.ClueData; |
| 11 | +import com.zhonglai.luhui.api.controller.test.dto.FindExcelDataDto; | ||
| 12 | +import com.zhonglai.luhui.dao.dto.SqlResult; | ||
| 13 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 10 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 11 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 12 | import org.apache.batik.transcoder.Transcoder; | 16 | import org.apache.batik.transcoder.Transcoder; |
| @@ -15,6 +19,7 @@ import org.apache.batik.transcoder.TranscoderInput; | @@ -15,6 +19,7 @@ import org.apache.batik.transcoder.TranscoderInput; | ||
| 15 | import org.apache.batik.transcoder.TranscoderOutput; | 19 | import org.apache.batik.transcoder.TranscoderOutput; |
| 16 | import org.apache.batik.transcoder.image.JPEGTranscoder; | 20 | import org.apache.batik.transcoder.image.JPEGTranscoder; |
| 17 | import org.apache.batik.transcoder.image.PNGTranscoder; | 21 | import org.apache.batik.transcoder.image.PNGTranscoder; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 18 | import org.springframework.util.StreamUtils; | 23 | import org.springframework.util.StreamUtils; |
| 19 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 20 | 25 | ||
| @@ -24,14 +29,14 @@ import javax.servlet.http.HttpServletResponse; | @@ -24,14 +29,14 @@ import javax.servlet.http.HttpServletResponse; | ||
| 24 | import java.io.IOException; | 29 | import java.io.IOException; |
| 25 | import java.io.OutputStreamWriter; | 30 | import java.io.OutputStreamWriter; |
| 26 | import java.io.StringReader; | 31 | import java.io.StringReader; |
| 27 | -import java.util.Enumeration; | ||
| 28 | -import java.util.HashMap; | ||
| 29 | -import java.util.Map; | 32 | +import java.util.*; |
| 30 | 33 | ||
| 31 | @Api(tags = "测试") | 34 | @Api(tags = "测试") |
| 32 | @RestController | 35 | @RestController |
| 33 | @RequestMapping("/test") | 36 | @RequestMapping("/test") |
| 34 | public class TestController { | 37 | public class TestController { |
| 38 | + @Autowired | ||
| 39 | + private PublicService publicService; | ||
| 35 | @ApiOperation("账号密码登陆") | 40 | @ApiOperation("账号密码登陆") |
| 36 | @GetMapping("/t1") | 41 | @GetMapping("/t1") |
| 37 | public AjaxResult t1() | 42 | public AjaxResult t1() |
| @@ -109,6 +114,43 @@ public class TestController { | @@ -109,6 +114,43 @@ public class TestController { | ||
| 109 | return str; | 114 | return str; |
| 110 | } | 115 | } |
| 111 | 116 | ||
| 117 | + @ApiOperation("新增多维表格数据") | ||
| 118 | + @RequestMapping(value = "addExcelData") | ||
| 119 | + public AjaxResult addExcelData(Integer system_type,String log_id,String excel_id,String sheet_id,@RequestBody String sub_data) throws IOException { | ||
| 120 | + LogExcelSub logExcelSub = new LogExcelSub(); | ||
| 121 | + logExcelSub.setExcel_id(excel_id); | ||
| 122 | + logExcelSub.setSheet_id(sheet_id); | ||
| 123 | + logExcelSub.setSub_data(sub_data); | ||
| 124 | + logExcelSub.setSystem_type(system_type); | ||
| 125 | + logExcelSub.setLog_id(log_id); | ||
| 126 | + return AjaxResult.success(publicService.insert(logExcelSub)); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @ApiOperation("修改多维表格数据") | ||
| 130 | + @RequestMapping(value = "upExcelData") | ||
| 131 | + public AjaxResult upExcelData(Integer system_type,String log_id,String excel_id,String sheet_id,@RequestBody String sub_data) throws IOException { | ||
| 132 | + LogExcelSub logExcelSub = new LogExcelSub(); | ||
| 133 | + logExcelSub.setExcel_id(excel_id); | ||
| 134 | + logExcelSub.setSheet_id(sheet_id); | ||
| 135 | + logExcelSub.setSystem_type(system_type); | ||
| 136 | + logExcelSub.setLog_id(log_id); | ||
| 137 | + Long nub = publicService.getObjectListTotle(logExcelSub,null); | ||
| 138 | + | ||
| 139 | + logExcelSub.setSub_data(sub_data); | ||
| 140 | + if(0==nub) | ||
| 141 | + { | ||
| 142 | + return AjaxResult.success(publicService.insert(logExcelSub)); | ||
| 143 | + } | ||
| 144 | + return AjaxResult.success(publicService.updateObject(logExcelSub,"system_type,excel_id,sheet_id,log_id")); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @ApiOperation("查询多维表格数据") | ||
| 148 | + @RequestMapping(value = "findExcelData") | ||
| 149 | + public AjaxResult findExcelData(@RequestBody FindExcelDataDto findExcelDataDto) throws IOException { | ||
| 150 | + List<Map<String,Object>> list =publicService.getDynamicList(buildDynamicSqlSecure(findExcelDataDto.getSelectFields(),findExcelDataDto.getEqualConditions(),findExcelDataDto.getRangeConditions(),findExcelDataDto.getSystemType(),findExcelDataDto.getExcelId(),findExcelDataDto.getSheetId(),findExcelDataDto.getOrderFields(),findExcelDataDto.getOrderDirections())); | ||
| 151 | + return AjaxResult.success(list); | ||
| 152 | + } | ||
| 153 | + | ||
| 112 | @ApiOperation("重写Highcharts导出") | 154 | @ApiOperation("重写Highcharts导出") |
| 113 | @RequestMapping(value = "getFeishuTable") | 155 | @RequestMapping(value = "getFeishuTable") |
| 114 | public void getFeishuTable(HttpServletRequest request, HttpServletResponse response) throws IOException { | 156 | public void getFeishuTable(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| @@ -202,4 +244,113 @@ public class TestController { | @@ -202,4 +244,113 @@ public class TestController { | ||
| 202 | FeishuUtil.subFeishuTables(FeishuUtil.gettenant_access_token("cli_a77e560b9475100c","7E80HFwgkmHjngFWDNsz6Pe1aqtKLC3m"),"YY58bkeMjahX5Uskh4WcnYOCnZc","tbldo1VjlU9jY51Y",field); | 244 | FeishuUtil.subFeishuTables(FeishuUtil.gettenant_access_token("cli_a77e560b9475100c","7E80HFwgkmHjngFWDNsz6Pe1aqtKLC3m"),"YY58bkeMjahX5Uskh4WcnYOCnZc","tbldo1VjlU9jY51Y",field); |
| 203 | } | 245 | } |
| 204 | 246 | ||
| 247 | + public SqlResult buildDynamicSqlSecure( | ||
| 248 | + List<String> selectFields, // 需要返回的字段 | ||
| 249 | + Map<String, Object> equalConditions, // JSON 等值条件 | ||
| 250 | + Map<String, Object[]> rangeConditions, // JSON 范围条件 [start, end] | ||
| 251 | + Integer systemType, // system_type | ||
| 252 | + String excel_id, | ||
| 253 | + String sheetId, // sheet_id | ||
| 254 | + List<String> orderFields, // 排序字段 | ||
| 255 | + List<String> orderDirections // 排序方向 ASC/DESC | ||
| 256 | + ) { | ||
| 257 | + SqlResult result = new SqlResult(); | ||
| 258 | + StringBuilder sql = new StringBuilder(); | ||
| 259 | + List<Object> params = new ArrayList<>(); | ||
| 260 | + | ||
| 261 | + sql.append("SELECT id, log_id, "); | ||
| 262 | + | ||
| 263 | + // SELECT JSON 字段 | ||
| 264 | + for (int i = 0; i < selectFields.size(); i++) { | ||
| 265 | + String field = selectFields.get(i); | ||
| 266 | + sql.append("JSON_UNQUOTE(JSON_EXTRACT(sub_data, '$.\"") | ||
| 267 | + .append(field) | ||
| 268 | + .append("\"')) AS `") | ||
| 269 | + .append(field) | ||
| 270 | + .append("`"); | ||
| 271 | + if (i < selectFields.size() - 1) sql.append(", "); | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + sql.append(" FROM log_excel_sub WHERE 1=1 "); | ||
| 275 | + | ||
| 276 | + // system_type | ||
| 277 | + if (systemType != null) { | ||
| 278 | + sql.append(" AND system_type = ? "); | ||
| 279 | + params.add(systemType); | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + | ||
| 283 | + // sheet_id | ||
| 284 | + if (excel_id != null) { | ||
| 285 | + sql.append(" AND excel_id = ? "); | ||
| 286 | + params.add(excel_id); | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + // sheet_id | ||
| 290 | + if (sheetId != null) { | ||
| 291 | + sql.append(" AND sheet_id = ? "); | ||
| 292 | + params.add(sheetId); | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + // 等值查询 | ||
| 296 | + if (equalConditions != null) { | ||
| 297 | + for (Map.Entry<String, Object> entry : equalConditions.entrySet()) { | ||
| 298 | + sql.append(" AND JSON_UNQUOTE(JSON_EXTRACT(sub_data, '$.\"") | ||
| 299 | + .append(entry.getKey()) | ||
| 300 | + .append("\"')) = ? "); | ||
| 301 | + params.add(entry.getValue()); | ||
| 302 | + } | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + // 范围查询 | ||
| 306 | + if (rangeConditions != null) { | ||
| 307 | + for (Map.Entry<String, Object[]> entry : rangeConditions.entrySet()) { | ||
| 308 | + String field = entry.getKey(); | ||
| 309 | + Object[] range = entry.getValue(); | ||
| 310 | + | ||
| 311 | + sql.append(" AND STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(sub_data, '$.\"") | ||
| 312 | + .append(field) | ||
| 313 | + .append("\"')), '%Y/%m/%d %H:%i:%s') "); | ||
| 314 | + | ||
| 315 | + if (range[0] != null && range[1] != null) { | ||
| 316 | + sql.append("BETWEEN ? AND ? "); | ||
| 317 | + params.add(range[0]); | ||
| 318 | + params.add(range[1]); | ||
| 319 | + } else if (range[0] != null) { | ||
| 320 | + sql.append(">= ? "); | ||
| 321 | + params.add(range[0]); | ||
| 322 | + } else if (range[1] != null) { | ||
| 323 | + sql.append("<= ? "); | ||
| 324 | + params.add(range[1]); | ||
| 325 | + } | ||
| 326 | + } | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + // 排序 | ||
| 330 | + if (orderFields != null && !orderFields.isEmpty()) { | ||
| 331 | + sql.append(" ORDER BY "); | ||
| 332 | + | ||
| 333 | + for (int i = 0; i < orderFields.size(); i++) { | ||
| 334 | + String field = orderFields.get(i); | ||
| 335 | + String direction = (orderDirections != null && orderDirections.size() > i) | ||
| 336 | + ? orderDirections.get(i) | ||
| 337 | + : "ASC"; | ||
| 338 | + | ||
| 339 | + sql.append("JSON_UNQUOTE(JSON_EXTRACT(sub_data, '$.\"") | ||
| 340 | + .append(field) | ||
| 341 | + .append("\"')) ") | ||
| 342 | + .append(direction); | ||
| 343 | + | ||
| 344 | + if (i < orderFields.size() - 1) { | ||
| 345 | + sql.append(", "); | ||
| 346 | + } | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + result.setSql(sql.toString()); | ||
| 351 | + result.setParams(params); | ||
| 352 | + return result; | ||
| 353 | + } | ||
| 354 | + | ||
| 355 | + | ||
| 205 | } | 356 | } |
lh-modules/lh-api/src/main/java/com/zhonglai/luhui/api/controller/test/dto/FindExcelDataDto.java
0 → 100644
| 1 | +package com.zhonglai.luhui.api.controller.test.dto; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +@ApiModel("查询多维表格数据参数") | ||
| 10 | +public class FindExcelDataDto { | ||
| 11 | + @ApiModelProperty("需要返回的字段") | ||
| 12 | + private List<String> selectFields; // // 需要返回的字段 | ||
| 13 | + @ApiModelProperty("JSON 等值条件") | ||
| 14 | + private Map<String, Object> equalConditions; // // JSON 等值条件 | ||
| 15 | + @ApiModelProperty("JSON 范围条件 [start, end]") | ||
| 16 | + private Map<String, Object[]> rangeConditions; // // JSON 范围条件 [start, end] | ||
| 17 | + @ApiModelProperty("系统平台类型") | ||
| 18 | + private Integer systemType; // // system_type | ||
| 19 | + @ApiModelProperty("多维表id") | ||
| 20 | + private String excelId; // // sheet_id | ||
| 21 | + @ApiModelProperty("sheet表id") | ||
| 22 | + private String sheetId; // // sheet_id | ||
| 23 | + @ApiModelProperty("排序字段") | ||
| 24 | + private List<String> orderFields; // // 排序字段 | ||
| 25 | + @ApiModelProperty("排序方向 ASC/DESC") | ||
| 26 | + private List<String> orderDirections; // 排序方向 ASC/DESC | ||
| 27 | + | ||
| 28 | + public String getExcelId() { | ||
| 29 | + return excelId; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setExcelId(String excelId) { | ||
| 33 | + this.excelId = excelId; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public List<String> getSelectFields() { | ||
| 37 | + return selectFields; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setSelectFields(List<String> selectFields) { | ||
| 41 | + this.selectFields = selectFields; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public Map<String, Object> getEqualConditions() { | ||
| 45 | + return equalConditions; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setEqualConditions(Map<String, Object> equalConditions) { | ||
| 49 | + this.equalConditions = equalConditions; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public Map<String, Object[]> getRangeConditions() { | ||
| 53 | + return rangeConditions; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setRangeConditions(Map<String, Object[]> rangeConditions) { | ||
| 57 | + this.rangeConditions = rangeConditions; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public Integer getSystemType() { | ||
| 61 | + return systemType; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setSystemType(Integer systemType) { | ||
| 65 | + this.systemType = systemType; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public String getSheetId() { | ||
| 69 | + return sheetId; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setSheetId(String sheetId) { | ||
| 73 | + this.sheetId = sheetId; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public List<String> getOrderFields() { | ||
| 77 | + return orderFields; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setOrderFields(List<String> orderFields) { | ||
| 81 | + this.orderFields = orderFields; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public List<String> getOrderDirections() { | ||
| 85 | + return orderDirections; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setOrderDirections(List<String> orderDirections) { | ||
| 89 | + this.orderDirections = orderDirections; | ||
| 90 | + } | ||
| 91 | +} |
-
请 注册 或 登录 后发表评论