Commit 32adb64937d60051c8aa0c55b29b8feecad89b13
1 parent
ca84efa9
编写读取文件 审核关键字 通过者导出文件
Showing
2 changed files
with
84 additions
and
0 deletions
src/main/java/com/cnlive/shenhe/job/TextJob.java
0 → 100644
| 1 | +package com.cnlive.shenhe.job; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; | |
| 5 | +import lombok.extern.slf4j.Slf4j; | |
| 6 | +import org.springframework.stereotype.Component; | |
| 7 | + | |
| 8 | +import java.io.*; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @Author: yan-zhao-wang | |
| 12 | + * @DateTime: 2022-06-27 10:30 | |
| 13 | + */ | |
| 14 | +@Slf4j | |
| 15 | +@Component | |
| 16 | +public class TextJob { | |
| 17 | + | |
| 18 | + | |
| 19 | + //@Scheduled(cron = "0 0/2 * * * ? ") | |
| 20 | + public String TestFilter() { | |
| 21 | + BufferedReader bufferedReader = null; | |
| 22 | + BufferedWriter bufferedWriter = null; | |
| 23 | + String type = null; | |
| 24 | + String desc = null; | |
| 25 | + Integer action; | |
| 26 | + try { | |
| 27 | + bufferedReader = new BufferedReader(new FileReader(new File("C:\\Users\\Administrator\\Desktop\\123.txt"))); | |
| 28 | + bufferedWriter = new BufferedWriter(new BufferedWriter(new FileWriter(new File("C:\\Users\\Administrator\\Desktop\\通过数据.txt")))); | |
| 29 | + boolean falg = true; | |
| 30 | + while (falg) { | |
| 31 | + if (falg = (bufferedReader.read()) != -1 ? true : false) { | |
| 32 | + String txt = bufferedReader.readLine(); | |
| 33 | + String[] split = txt.split(","); | |
| 34 | + JSONObject textFilter = null; | |
| 35 | + for (String s : split) { | |
| 36 | + textFilter = YiDunAntiFraudUtil.getTextFilter(s); | |
| 37 | + type = textFilter.getString("type"); | |
| 38 | + desc = textFilter.getString("desc"); | |
| 39 | + action = textFilter.getInteger("action"); | |
| 40 | + | |
| 41 | + if (action == 0) { | |
| 42 | + String hint = textFilter.getString("hint"); | |
| 43 | + bufferedWriter.write(hint); | |
| 44 | + bufferedWriter.newLine(); | |
| 45 | + | |
| 46 | + } | |
| 47 | + log.info("type:{}" + type); | |
| 48 | + log.info("desc:{}" + desc); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 53 | + } catch (IOException e) { | |
| 54 | + e.printStackTrace(); | |
| 55 | + } finally { | |
| 56 | + if (bufferedReader != null) { | |
| 57 | + try { | |
| 58 | + bufferedReader.close(); | |
| 59 | + } catch (IOException e) { | |
| 60 | + e.printStackTrace(); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + if (bufferedWriter != null) { | |
| 64 | + try { | |
| 65 | + bufferedWriter.close(); | |
| 66 | + } catch (IOException e) { | |
| 67 | + e.printStackTrace(); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + } | |
| 71 | + return "type:{}" + type + "desc:{}" + desc; | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | ... | ... |
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
| ... | ... | @@ -161,6 +161,7 @@ public class YiDunAntiFraudUtil { |
| 161 | 161 | int action = resultJsonObject.getIntValue("action"); |
| 162 | 162 | String taskId = resultJsonObject.getString("taskId"); |
| 163 | 163 | String labelMsg = ""; |
| 164 | + String hint = ""; | |
| 164 | 165 | if (action != 0) { |
| 165 | 166 | JSONArray labels = resultJsonObject.getJSONArray("labels"); |
| 166 | 167 | labelMsg = "("; |
| ... | ... | @@ -168,6 +169,9 @@ public class YiDunAntiFraudUtil { |
| 168 | 169 | for (Object obj : labels) { |
| 169 | 170 | JSONObject jsonObjectone = (JSONObject) obj; |
| 170 | 171 | Integer label = jsonObjectone.getInteger("label"); |
| 172 | + JSONObject details = jsonObjectone.getJSONObject("details"); | |
| 173 | + hint = details.getString("hint"); | |
| 174 | + | |
| 171 | 175 | String name = TextLabels.getName(label); |
| 172 | 176 | labelMsg = labelMsg + name; |
| 173 | 177 | |
| ... | ... | @@ -178,14 +182,20 @@ public class YiDunAntiFraudUtil { |
| 178 | 182 | if (action == 0) { |
| 179 | 183 | jsonObj.put("type", "PASS"); |
| 180 | 184 | jsonObj.put("desc", "易盾文本审核通过"); |
| 185 | + jsonObj.put("action", 0); | |
| 186 | + jsonObj.put("hint", hint); | |
| 181 | 187 | } |
| 182 | 188 | if (action == 1) { |
| 183 | 189 | jsonObj.put("type", "REJECT"); |
| 184 | 190 | jsonObj.put("desc", "易盾文本审核文本嫌疑" + labelMsg + ")"); |
| 191 | + jsonObj.put("hint", hint); | |
| 192 | + jsonObj.put("action", 1); | |
| 185 | 193 | } |
| 186 | 194 | if (action == 2) { |
| 187 | 195 | jsonObj.put("type", "REJECT"); |
| 188 | 196 | jsonObj.put("desc", "易盾文本审核文本违规" + labelMsg + ")"); |
| 197 | + jsonObj.put("hint", hint); | |
| 198 | + jsonObj.put("action", 2); | |
| 189 | 199 | } |
| 190 | 200 | jsonObj.put("taskId", taskId); |
| 191 | 201 | logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | ... | ... |