Showing
13 changed files
with
638 additions
and
47 deletions
@@ -20,6 +20,8 @@ import com.ash.util.UUIDGenerator; | @@ -20,6 +20,8 @@ import com.ash.util.UUIDGenerator; | ||
20 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 20 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | import org.apache.commons.collections.CollectionUtils; | 22 | import org.apache.commons.collections.CollectionUtils; |
23 | +import org.apache.commons.lang3.StringUtils; | ||
24 | +import org.apache.ibatis.annotations.Param; | ||
23 | import org.springframework.beans.BeanUtils; | 25 | import org.springframework.beans.BeanUtils; |
24 | import org.springframework.web.bind.annotation.*; | 26 | import org.springframework.web.bind.annotation.*; |
25 | import org.springframework.web.multipart.MultipartFile; | 27 | import org.springframework.web.multipart.MultipartFile; |
@@ -30,10 +32,9 @@ import javax.servlet.http.HttpServletResponse; | @@ -30,10 +32,9 @@ import javax.servlet.http.HttpServletResponse; | ||
30 | import java.io.IOException; | 32 | import java.io.IOException; |
31 | import java.net.URLEncoder; | 33 | import java.net.URLEncoder; |
32 | import java.nio.charset.StandardCharsets; | 34 | import java.nio.charset.StandardCharsets; |
33 | -import java.util.ArrayList; | ||
34 | -import java.util.List; | ||
35 | -import java.util.Map; | ||
36 | -import java.util.Optional; | 35 | +import java.util.*; |
36 | +import java.util.concurrent.ExecutorService; | ||
37 | +import java.util.concurrent.Executors; | ||
37 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; |
38 | 39 | ||
39 | @RestController | 40 | @RestController |
@@ -50,6 +51,8 @@ public class CaseController extends BaseController { | @@ -50,6 +51,8 @@ public class CaseController extends BaseController { | ||
50 | @Resource | 51 | @Resource |
51 | private CaseAnalysisService caseAnalysisService; | 52 | private CaseAnalysisService caseAnalysisService; |
52 | 53 | ||
54 | + private final ExecutorService executorService = Executors.newFixedThreadPool(10); | ||
55 | + | ||
53 | 56 | ||
54 | @PostMapping("/save") | 57 | @PostMapping("/save") |
55 | public JsonResult save(@RequestBody Case data) { | 58 | public JsonResult save(@RequestBody Case data) { |
@@ -184,8 +187,22 @@ public class CaseController extends BaseController { | @@ -184,8 +187,22 @@ public class CaseController extends BaseController { | ||
184 | } | 187 | } |
185 | 188 | ||
186 | @GetMapping(value = "/reAnalysis") | 189 | @GetMapping(value = "/reAnalysis") |
187 | - public JsonResult reAnalysis() throws IOException { | ||
188 | - return JsonResult.ok(); | 190 | + public JsonResult reAnalysis(@RequestParam(value = "id", required = false) String id) throws IOException { |
191 | + executorService.execute(() -> { | ||
192 | + try { | ||
193 | + if (StringUtils.isNotBlank(id)) { | ||
194 | + caseService.analysisByIds(Collections.singletonList(id)); | ||
195 | + } else { | ||
196 | + List<Case> dataList = caseService.listUnAnalysis(); | ||
197 | + caseService.analysis(dataList); | ||
198 | + } | ||
199 | + | ||
200 | + } catch (Exception ex) { | ||
201 | + log.error(ex.getMessage()); | ||
202 | + } | ||
203 | + }); | ||
204 | + return JsonResult.ok("重新解析开始"); | ||
205 | + | ||
189 | } | 206 | } |
190 | 207 | ||
191 | @PostMapping("/saveAnalysis") | 208 | @PostMapping("/saveAnalysis") |
@@ -6,6 +6,7 @@ import com.ash.base.BaseController; | @@ -6,6 +6,7 @@ import com.ash.base.BaseController; | ||
6 | import com.ash.base.JsonResult; | 6 | import com.ash.base.JsonResult; |
7 | import com.ash.base.OptionStatus; | 7 | import com.ash.base.OptionStatus; |
8 | import com.ash.base.excelOpt.ExcelErrorMessage; | 8 | import com.ash.base.excelOpt.ExcelErrorMessage; |
9 | +import com.ash.entity.Case; | ||
9 | import com.ash.entity.FileData; | 10 | import com.ash.entity.FileData; |
10 | import com.ash.entity.WarningInstance; | 11 | import com.ash.entity.WarningInstance; |
11 | import com.ash.entity.WarningInstanceAnalysis; | 12 | import com.ash.entity.WarningInstanceAnalysis; |
@@ -20,6 +21,7 @@ import com.ash.util.UUIDGenerator; | @@ -20,6 +21,7 @@ import com.ash.util.UUIDGenerator; | ||
20 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 21 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
21 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
22 | import org.apache.commons.collections.CollectionUtils; | 23 | import org.apache.commons.collections.CollectionUtils; |
24 | +import org.apache.commons.lang3.StringUtils; | ||
23 | import org.springframework.beans.BeanUtils; | 25 | import org.springframework.beans.BeanUtils; |
24 | import org.springframework.web.bind.annotation.*; | 26 | import org.springframework.web.bind.annotation.*; |
25 | import org.springframework.web.multipart.MultipartFile; | 27 | import org.springframework.web.multipart.MultipartFile; |
@@ -30,10 +32,9 @@ import javax.servlet.http.HttpServletResponse; | @@ -30,10 +32,9 @@ import javax.servlet.http.HttpServletResponse; | ||
30 | import java.io.IOException; | 32 | import java.io.IOException; |
31 | import java.net.URLEncoder; | 33 | import java.net.URLEncoder; |
32 | import java.nio.charset.StandardCharsets; | 34 | import java.nio.charset.StandardCharsets; |
33 | -import java.util.ArrayList; | ||
34 | -import java.util.List; | ||
35 | -import java.util.Map; | ||
36 | -import java.util.Optional; | 35 | +import java.util.*; |
36 | +import java.util.concurrent.ExecutorService; | ||
37 | +import java.util.concurrent.Executors; | ||
37 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; |
38 | 39 | ||
39 | @RestController | 40 | @RestController |
@@ -49,6 +50,8 @@ public class WarningInstanceController extends BaseController { | @@ -49,6 +50,8 @@ public class WarningInstanceController extends BaseController { | ||
49 | @Resource | 50 | @Resource |
50 | private FileDataService fileDataService; | 51 | private FileDataService fileDataService; |
51 | 52 | ||
53 | + private ExecutorService executorService = Executors.newFixedThreadPool(10); | ||
54 | + | ||
52 | @PostMapping(value = "/list") | 55 | @PostMapping(value = "/list") |
53 | public JsonResult list(@RequestBody WarningInstance warningInstance) { | 56 | public JsonResult list(@RequestBody WarningInstance warningInstance) { |
54 | try { | 57 | try { |
@@ -195,8 +198,23 @@ public class WarningInstanceController extends BaseController { | @@ -195,8 +198,23 @@ public class WarningInstanceController extends BaseController { | ||
195 | 198 | ||
196 | 199 | ||
197 | @GetMapping(value = "/reAnalysis") | 200 | @GetMapping(value = "/reAnalysis") |
198 | - public JsonResult reAnalysis() throws IOException { | ||
199 | - return JsonResult.ok(); | 201 | + public JsonResult reAnalysis(@RequestParam(value = "id", required = false) String id) throws IOException { |
202 | + executorService.execute(() -> { | ||
203 | + try { | ||
204 | + if (StringUtils.isNotBlank(id)) { | ||
205 | + warningInstanceService.analysisByIds(Collections.singletonList(id)); | ||
206 | + } else { | ||
207 | + List<WarningInstance> dataList = warningInstanceService.listUnAnalysis(); | ||
208 | + warningInstanceService.analysis(dataList); | ||
209 | + } | ||
210 | + | ||
211 | + } catch (Exception ex) { | ||
212 | + log.error(ex.getMessage()); | ||
213 | + | ||
214 | + } | ||
215 | + }); | ||
216 | + return JsonResult.ok("重新解析开始"); | ||
217 | + | ||
200 | } | 218 | } |
201 | 219 | ||
202 | @PostMapping("/saveAnalysis") | 220 | @PostMapping("/saveAnalysis") |
@@ -84,7 +84,7 @@ public class CaseAnalysis extends BaseModel { | @@ -84,7 +84,7 @@ public class CaseAnalysis extends BaseModel { | ||
84 | private String rainageMethod; | 84 | private String rainageMethod; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | - * 引流方式 | 87 | + * 引流方式详情 |
88 | */ | 88 | */ |
89 | @TableField(value = "rainage_method_detail") | 89 | @TableField(value = "rainage_method_detail") |
90 | private String rainageMethodDetail; | 90 | private String rainageMethodDetail; |
@@ -35,7 +35,7 @@ public class WarningInstanceExcelData implements Serializable { | @@ -35,7 +35,7 @@ public class WarningInstanceExcelData implements Serializable { | ||
35 | @ColumnWidth(25) | 35 | @ColumnWidth(25) |
36 | private Date alarmDate; | 36 | private Date alarmDate; |
37 | 37 | ||
38 | - @ExcelCheck(canEmpty = false, dateFormatValid = "yyyy-MM-dd HH:mm:ss") | 38 | + @ExcelCheck(canEmpty = false) |
39 | @ExcelProperty(value = "报警电话", index = 2) | 39 | @ExcelProperty(value = "报警电话", index = 2) |
40 | @ContentStyle(dataFormat = 49) | 40 | @ContentStyle(dataFormat = 49) |
41 | @ColumnWidth(25) | 41 | @ColumnWidth(25) |
@@ -16,11 +16,13 @@ import com.ash.base.excelOpt.ExcelErrorMessage; | @@ -16,11 +16,13 @@ import com.ash.base.excelOpt.ExcelErrorMessage; | ||
16 | import com.ash.base.excelOpt.ValidateAnnotation; | 16 | import com.ash.base.excelOpt.ValidateAnnotation; |
17 | import com.ash.entity.dao.CaseMapper; | 17 | import com.ash.entity.dao.CaseMapper; |
18 | import com.ash.excelData.CaseExcelData; | 18 | import com.ash.excelData.CaseExcelData; |
19 | +import com.ash.service.CaseService; | ||
19 | import lombok.Getter; | 20 | import lombok.Getter; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.collections.CollectionUtils; | 22 | import org.apache.commons.collections.CollectionUtils; |
22 | import org.apache.commons.lang3.StringUtils; | 23 | import org.apache.commons.lang3.StringUtils; |
23 | 24 | ||
25 | +import javax.annotation.Resource; | ||
24 | import java.lang.reflect.Field; | 26 | import java.lang.reflect.Field; |
25 | import java.text.ParseException; | 27 | import java.text.ParseException; |
26 | import java.text.SimpleDateFormat; | 28 | import java.text.SimpleDateFormat; |
@@ -147,7 +149,8 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | @@ -147,7 +149,8 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | ||
147 | endPosition = (i + 1) * singleThreadDealcount; | 149 | endPosition = (i + 1) * singleThreadDealcount; |
148 | } | 150 | } |
149 | CaseMapper caseMapper = SpringJobBeanFactory.getBean(CaseMapper.class); | 151 | CaseMapper caseMapper = SpringJobBeanFactory.getBean(CaseMapper.class); |
150 | - CaseThread thread = new CaseThread(count, caseMapper, list, startPosition, endPosition); | 152 | + CaseService caseService= SpringJobBeanFactory.getBean(CaseService.class); |
153 | + CaseThread thread = new CaseThread(count, caseMapper, caseService, list, startPosition, endPosition); | ||
151 | executor.execute(thread); | 154 | executor.execute(thread); |
152 | } | 155 | } |
153 | 156 | ||
@@ -203,7 +206,7 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | @@ -203,7 +206,7 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | ||
203 | try { | 206 | try { |
204 | SimpleDateFormat format = new SimpleDateFormat(excelCheck.dateFormatValid()); | 207 | SimpleDateFormat format = new SimpleDateFormat(excelCheck.dateFormatValid()); |
205 | format.setLenient(false); | 208 | format.setLenient(false); |
206 | - format.parse(format.format(value.toString())); | 209 | + format.parse(format.format(value)); |
207 | 210 | ||
208 | } catch (Exception e) { | 211 | } catch (Exception e) { |
209 | addError(rowIndex + 1, annotation.getHeadName() + "时间格式错误!"); | 212 | addError(rowIndex + 1, annotation.getHeadName() + "时间格式错误!"); |
1 | package com.ash.listener; | 1 | package com.ash.listener; |
2 | 2 | ||
3 | import com.ash.entity.Case; | 3 | import com.ash.entity.Case; |
4 | +import com.ash.entity.WarningInstance; | ||
4 | import com.ash.entity.dao.CaseMapper; | 5 | import com.ash.entity.dao.CaseMapper; |
5 | import com.ash.enums.AnalysisStatusEnum; | 6 | import com.ash.enums.AnalysisStatusEnum; |
6 | import com.ash.enums.ReviewStatusEnum; | 7 | import com.ash.enums.ReviewStatusEnum; |
7 | import com.ash.excelData.CaseExcelData; | 8 | import com.ash.excelData.CaseExcelData; |
9 | +import com.ash.service.CaseService; | ||
10 | +import com.ash.util.UUIDGenerator; | ||
8 | import org.springframework.beans.BeanUtils; | 11 | import org.springframework.beans.BeanUtils; |
9 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
10 | 13 | ||
14 | +import javax.annotation.Resource; | ||
11 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
12 | import java.util.Collections; | 16 | import java.util.Collections; |
13 | import java.util.List; | 17 | import java.util.List; |
14 | import java.util.concurrent.CountDownLatch; | 18 | import java.util.concurrent.CountDownLatch; |
19 | +import java.util.stream.Collectors; | ||
15 | 20 | ||
16 | @Component | 21 | @Component |
17 | public class CaseThread implements Runnable { | 22 | public class CaseThread implements Runnable { |
@@ -23,17 +28,19 @@ public class CaseThread implements Runnable { | @@ -23,17 +28,19 @@ public class CaseThread implements Runnable { | ||
23 | private List<CaseExcelData> list = Collections.synchronizedList(new ArrayList<>()); | 28 | private List<CaseExcelData> list = Collections.synchronizedList(new ArrayList<>()); |
24 | private CountDownLatch count; | 29 | private CountDownLatch count; |
25 | private CaseMapper caseMapper; | 30 | private CaseMapper caseMapper; |
31 | + private CaseService caseService; | ||
26 | 32 | ||
27 | public CaseThread() { | 33 | public CaseThread() { |
28 | } | 34 | } |
29 | 35 | ||
30 | - public CaseThread(CountDownLatch count, CaseMapper mapper, | ||
31 | - List<CaseExcelData> list, int startPosition, int endPosition) { | 36 | + public CaseThread(CountDownLatch count, CaseMapper mapper, CaseService caseService, |
37 | + List<CaseExcelData> list, int startPosition, int endPosition) { | ||
32 | this.count = count; | 38 | this.count = count; |
33 | this.list = list; | 39 | this.list = list; |
34 | this.startPosition = startPosition; | 40 | this.startPosition = startPosition; |
35 | this.endPosition = endPosition; | 41 | this.endPosition = endPosition; |
36 | this.caseMapper = mapper; | 42 | this.caseMapper = mapper; |
43 | + this.caseService = caseService; | ||
37 | } | 44 | } |
38 | 45 | ||
39 | @Override | 46 | @Override |
@@ -44,11 +51,15 @@ public class CaseThread implements Runnable { | @@ -44,11 +51,15 @@ public class CaseThread implements Runnable { | ||
44 | for (CaseExcelData data : subList) { | 51 | for (CaseExcelData data : subList) { |
45 | Case dbData = new Case(); | 52 | Case dbData = new Case(); |
46 | BeanUtils.copyProperties(data, dbData); | 53 | BeanUtils.copyProperties(data, dbData); |
47 | - dbData.setAnalysisStatus(AnalysisStatusEnum.unanalysis); | 54 | + dbData.setAnalysisStatus(AnalysisStatusEnum.analysis); |
48 | dbData.setReviewStatus(ReviewStatusEnum.UNAUDITED); | 55 | dbData.setReviewStatus(ReviewStatusEnum.UNAUDITED); |
56 | + String uuid = UUIDGenerator.uuid(); | ||
57 | + dbData.setId(uuid); | ||
49 | dataList.add(dbData); | 58 | dataList.add(dbData); |
50 | } | 59 | } |
60 | + List<String> ids = dataList.stream().map(Case::getId).collect(Collectors.toList()); | ||
51 | caseMapper.insertBatchSomeColumn(dataList); | 61 | caseMapper.insertBatchSomeColumn(dataList); |
62 | + caseService.analysisByIds(ids); | ||
52 | } catch (Exception ex) { | 63 | } catch (Exception ex) { |
53 | ex.printStackTrace(); | 64 | ex.printStackTrace(); |
54 | } finally { | 65 | } finally { |
@@ -16,6 +16,7 @@ import com.ash.base.excelOpt.ExcelErrorMessage; | @@ -16,6 +16,7 @@ import com.ash.base.excelOpt.ExcelErrorMessage; | ||
16 | import com.ash.base.excelOpt.ValidateAnnotation; | 16 | import com.ash.base.excelOpt.ValidateAnnotation; |
17 | import com.ash.entity.dao.WarningInstanceMapper; | 17 | import com.ash.entity.dao.WarningInstanceMapper; |
18 | import com.ash.excelData.WarningInstanceExcelData; | 18 | import com.ash.excelData.WarningInstanceExcelData; |
19 | +import com.ash.service.WarningInstanceService; | ||
19 | import lombok.Getter; | 20 | import lombok.Getter; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.collections.CollectionUtils; | 22 | import org.apache.commons.collections.CollectionUtils; |
@@ -150,7 +151,8 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | @@ -150,7 +151,8 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | ||
150 | endPosition = (i + 1) * singleThreadDealcount; | 151 | endPosition = (i + 1) * singleThreadDealcount; |
151 | } | 152 | } |
152 | WarningInstanceMapper deadManMapper = SpringJobBeanFactory.getBean(WarningInstanceMapper.class); | 153 | WarningInstanceMapper deadManMapper = SpringJobBeanFactory.getBean(WarningInstanceMapper.class); |
153 | - WarningInstanceThread thread = new WarningInstanceThread(count, deadManMapper, list, startPosition, endPosition); | 154 | + WarningInstanceService warningInstanceService = SpringJobBeanFactory.getBean(WarningInstanceService.class); |
155 | + WarningInstanceThread thread = new WarningInstanceThread(count, deadManMapper, warningInstanceService, list, startPosition, endPosition); | ||
154 | executor.execute(thread); | 156 | executor.execute(thread); |
155 | } | 157 | } |
156 | 158 | ||
@@ -207,7 +209,7 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | @@ -207,7 +209,7 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | ||
207 | try { | 209 | try { |
208 | SimpleDateFormat format = new SimpleDateFormat(excelCheck.dateFormatValid()); | 210 | SimpleDateFormat format = new SimpleDateFormat(excelCheck.dateFormatValid()); |
209 | format.setLenient(false); | 211 | format.setLenient(false); |
210 | - format.parse(format.format(value.toString())); | 212 | + format.parse(format.format(value)); |
211 | 213 | ||
212 | } catch (Exception e) { | 214 | } catch (Exception e) { |
213 | addError(rowIndex + 1, annotation.getHeadName() + "时间格式错误!"); | 215 | addError(rowIndex + 1, annotation.getHeadName() + "时间格式错误!"); |
@@ -5,13 +5,17 @@ import com.ash.entity.dao.WarningInstanceMapper; | @@ -5,13 +5,17 @@ import com.ash.entity.dao.WarningInstanceMapper; | ||
5 | import com.ash.enums.AnalysisStatusEnum; | 5 | import com.ash.enums.AnalysisStatusEnum; |
6 | import com.ash.enums.ReviewStatusEnum; | 6 | import com.ash.enums.ReviewStatusEnum; |
7 | import com.ash.excelData.WarningInstanceExcelData; | 7 | import com.ash.excelData.WarningInstanceExcelData; |
8 | +import com.ash.service.WarningInstanceService; | ||
9 | +import com.ash.util.UUIDGenerator; | ||
8 | import org.springframework.beans.BeanUtils; | 10 | import org.springframework.beans.BeanUtils; |
9 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
10 | 12 | ||
13 | +import javax.annotation.Resource; | ||
11 | import java.util.ArrayList; | 14 | import java.util.ArrayList; |
12 | import java.util.Collections; | 15 | import java.util.Collections; |
13 | import java.util.List; | 16 | import java.util.List; |
14 | import java.util.concurrent.CountDownLatch; | 17 | import java.util.concurrent.CountDownLatch; |
18 | +import java.util.stream.Collectors; | ||
15 | 19 | ||
16 | @Component | 20 | @Component |
17 | public class WarningInstanceThread implements Runnable { | 21 | public class WarningInstanceThread implements Runnable { |
@@ -23,17 +27,19 @@ public class WarningInstanceThread implements Runnable { | @@ -23,17 +27,19 @@ public class WarningInstanceThread implements Runnable { | ||
23 | private List<WarningInstanceExcelData> list = Collections.synchronizedList(new ArrayList<>()); | 27 | private List<WarningInstanceExcelData> list = Collections.synchronizedList(new ArrayList<>()); |
24 | private CountDownLatch count; | 28 | private CountDownLatch count; |
25 | private WarningInstanceMapper warningInstanceMapper; | 29 | private WarningInstanceMapper warningInstanceMapper; |
30 | + private WarningInstanceService warningInstanceService; | ||
26 | 31 | ||
27 | public WarningInstanceThread() { | 32 | public WarningInstanceThread() { |
28 | } | 33 | } |
29 | 34 | ||
30 | - public WarningInstanceThread(CountDownLatch count, WarningInstanceMapper mapper, | 35 | + public WarningInstanceThread(CountDownLatch count, WarningInstanceMapper mapper, WarningInstanceService warningInstanceService, |
31 | List<WarningInstanceExcelData> list, int startPosition, int endPosition) { | 36 | List<WarningInstanceExcelData> list, int startPosition, int endPosition) { |
32 | this.count = count; | 37 | this.count = count; |
33 | this.list = list; | 38 | this.list = list; |
34 | this.startPosition = startPosition; | 39 | this.startPosition = startPosition; |
35 | this.endPosition = endPosition; | 40 | this.endPosition = endPosition; |
36 | this.warningInstanceMapper = mapper; | 41 | this.warningInstanceMapper = mapper; |
42 | + this.warningInstanceService = warningInstanceService; | ||
37 | } | 43 | } |
38 | 44 | ||
39 | 45 | ||
@@ -45,11 +51,15 @@ public class WarningInstanceThread implements Runnable { | @@ -45,11 +51,15 @@ public class WarningInstanceThread implements Runnable { | ||
45 | for (WarningInstanceExcelData data : subList) { | 51 | for (WarningInstanceExcelData data : subList) { |
46 | WarningInstance dbData = new WarningInstance(); | 52 | WarningInstance dbData = new WarningInstance(); |
47 | BeanUtils.copyProperties(data, dbData); | 53 | BeanUtils.copyProperties(data, dbData); |
48 | - dbData.setAnalysisStatus(AnalysisStatusEnum.unanalysis); | 54 | + dbData.setAnalysisStatus(AnalysisStatusEnum.analysis); |
49 | dbData.setReviewStatus(ReviewStatusEnum.UNAUDITED); | 55 | dbData.setReviewStatus(ReviewStatusEnum.UNAUDITED); |
56 | + String uuid = UUIDGenerator.uuid(); | ||
57 | + dbData.setId(uuid); | ||
50 | dataList.add(dbData); | 58 | dataList.add(dbData); |
51 | } | 59 | } |
60 | + List<String> ids = dataList.stream().map(WarningInstance::getId).collect(Collectors.toList()); | ||
52 | warningInstanceMapper.insertBatchSomeColumn(dataList); | 61 | warningInstanceMapper.insertBatchSomeColumn(dataList); |
62 | + warningInstanceService.analysisByIds(ids); | ||
53 | } catch (Exception ex) { | 63 | } catch (Exception ex) { |
54 | ex.printStackTrace(); | 64 | ex.printStackTrace(); |
55 | } finally { | 65 | } finally { |
@@ -3,22 +3,26 @@ package com.ash.service; | @@ -3,22 +3,26 @@ package com.ash.service; | ||
3 | import com.alibaba.excel.EasyExcel; | 3 | import com.alibaba.excel.EasyExcel; |
4 | import com.alibaba.excel.exception.ExcelAnalysisException; | 4 | import com.alibaba.excel.exception.ExcelAnalysisException; |
5 | import com.alibaba.excel.exception.ExcelDataConvertException; | 5 | import com.alibaba.excel.exception.ExcelDataConvertException; |
6 | +import com.alibaba.fastjson.JSONObject; | ||
6 | import com.ash.base.*; | 7 | import com.ash.base.*; |
7 | import com.ash.base.excelOpt.ExcelErrorMessage; | 8 | import com.ash.base.excelOpt.ExcelErrorMessage; |
8 | import com.ash.entity.Case; | 9 | import com.ash.entity.Case; |
10 | +import com.ash.entity.CaseAnalysis; | ||
9 | import com.ash.entity.dao.CaseMapper; | 11 | import com.ash.entity.dao.CaseMapper; |
12 | +import com.ash.enums.AnalysisStatusEnum; | ||
13 | +import com.ash.enums.ConformStatusEnum; | ||
10 | import com.ash.excelData.CaseExcelData; | 14 | import com.ash.excelData.CaseExcelData; |
11 | import com.ash.listener.CaseExcelListener; | 15 | import com.ash.listener.CaseExcelListener; |
12 | -import com.ash.util.DateUtils; | ||
13 | -import com.ash.util.MultipartFileToFileUtils; | ||
14 | -import com.ash.util.ObjectValueOption; | ||
15 | -import com.ash.util.UUIDGenerator; | 16 | +import com.ash.util.*; |
16 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 17 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
17 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 18 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
18 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 19 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
19 | import com.github.yulichang.query.MPJQueryWrapper; | 20 | import com.github.yulichang.query.MPJQueryWrapper; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
23 | +import org.apache.http.entity.ContentType; | ||
24 | +import org.apache.http.entity.StringEntity; | ||
25 | +import org.springframework.beans.factory.annotation.Value; | ||
22 | import org.springframework.stereotype.Service; | 26 | import org.springframework.stereotype.Service; |
23 | import org.springframework.util.CollectionUtils; | 27 | import org.springframework.util.CollectionUtils; |
24 | import org.springframework.web.multipart.MultipartFile; | 28 | import org.springframework.web.multipart.MultipartFile; |
@@ -26,20 +30,25 @@ import org.springframework.web.multipart.MultipartFile; | @@ -26,20 +30,25 @@ import org.springframework.web.multipart.MultipartFile; | ||
26 | import javax.annotation.Resource; | 30 | import javax.annotation.Resource; |
27 | import java.text.ParseException; | 31 | import java.text.ParseException; |
28 | import java.text.SimpleDateFormat; | 32 | import java.text.SimpleDateFormat; |
29 | -import java.util.ArrayList; | ||
30 | -import java.util.Date; | ||
31 | -import java.util.List; | ||
32 | -import java.util.Map; | 33 | +import java.util.*; |
33 | import java.util.concurrent.atomic.AtomicReference; | 34 | import java.util.concurrent.atomic.AtomicReference; |
35 | +import java.util.function.Function; | ||
34 | import java.util.stream.Collectors; | 36 | import java.util.stream.Collectors; |
35 | 37 | ||
36 | @Slf4j | 38 | @Slf4j |
37 | @Service | 39 | @Service |
38 | public class CaseService { | 40 | public class CaseService { |
39 | 41 | ||
42 | + @Value("${ash.caseAnalysisUrl}") | ||
43 | + public String caseAnalysisUrl; | ||
44 | + | ||
45 | + | ||
40 | @Resource | 46 | @Resource |
41 | private CaseMapper caseMapper; | 47 | private CaseMapper caseMapper; |
42 | 48 | ||
49 | + @Resource | ||
50 | + private CaseAnalysisService caseAnalysisService; | ||
51 | + | ||
43 | public Boolean save(Case data) { | 52 | public Boolean save(Case data) { |
44 | String uuid = UUIDGenerator.uuid(); | 53 | String uuid = UUIDGenerator.uuid(); |
45 | data.setId(uuid); | 54 | data.setId(uuid); |
@@ -105,6 +114,13 @@ public class CaseService { | @@ -105,6 +114,13 @@ public class CaseService { | ||
105 | return caseMapper.selectList(queryWrapper); | 114 | return caseMapper.selectList(queryWrapper); |
106 | } | 115 | } |
107 | 116 | ||
117 | + public List<Case> listUnAnalysis() { | ||
118 | + QueryWrapper<Case> queryWrapper = new QueryWrapper<>(); | ||
119 | + LambdaQueryWrapper<Case> lambda = queryWrapper.lambda(); | ||
120 | + lambda.ne(Case::getAnalysisStatus, AnalysisStatusEnum.success); | ||
121 | + return caseMapper.selectList(queryWrapper); | ||
122 | + } | ||
123 | + | ||
108 | public Page<Case> pageByCondition(Case params, Page<Case> page) { | 124 | public Page<Case> pageByCondition(Case params, Page<Case> page) { |
109 | QueryWrapper<Case> queryWrapper = getCondition(params); | 125 | QueryWrapper<Case> queryWrapper = getCondition(params); |
110 | return caseMapper.selectPage(page, queryWrapper); | 126 | return caseMapper.selectPage(page, queryWrapper); |
@@ -389,4 +405,60 @@ public class CaseService { | @@ -389,4 +405,60 @@ public class CaseService { | ||
389 | return null; | 405 | return null; |
390 | } | 406 | } |
391 | 407 | ||
408 | + public void analysisByIds(List<String> ids) { | ||
409 | + List<Case> dataList = caseMapper.selectBatchIds(ids); | ||
410 | + analysis(dataList); | ||
411 | + | ||
412 | + } | ||
413 | + | ||
414 | + public void analysis(List<Case> dataList) { | ||
415 | + if (CollectionUtils.isEmpty(dataList)) { | ||
416 | + return; | ||
417 | + } | ||
418 | + Map<String, Case> dataMap = dataList.stream().collect(Collectors.toMap(Case::getId, Function.identity())); | ||
419 | + for (String id : dataMap.keySet()) { | ||
420 | + Case cd = dataMap.get(id); | ||
421 | + JSONObject analysisResult = invokeAnalysis(cd); | ||
422 | + if (analysisResult == null) { | ||
423 | + cd.setAnalysisStatus(AnalysisStatusEnum.fail); | ||
424 | + update(cd); | ||
425 | + } else { | ||
426 | + CaseAnalysis wa = new CaseAnalysis(); | ||
427 | + wa.setCaseId(cd.getId()); | ||
428 | + wa.setCounty(analysisResult.getString("area")); | ||
429 | + wa.setAmount(analysisResult.getDouble("value")); | ||
430 | + wa.setTotalAmount(analysisResult.getDouble("value")); | ||
431 | + wa.setSex(analysisResult.getString("gender")); | ||
432 | + wa.setAge(analysisResult.getInteger("age")); | ||
433 | + wa.setCareer(analysisResult.getString("occupation")); | ||
434 | + wa.setIdCard(analysisResult.getString("idCard")); | ||
435 | + wa.setFraudType(analysisResult.getString("fraudType")); | ||
436 | + wa.setRainageMethod(analysisResult.getString("diversionMethod")); | ||
437 | + wa.setPayMethod(analysisResult.getString("paymentMethod")); | ||
438 | + wa.setConformStatus(ConformStatusEnum.UNCONFIRMED); | ||
439 | + caseAnalysisService.save(wa); | ||
440 | + cd.setAnalysisStatus(AnalysisStatusEnum.success); | ||
441 | + update(cd); | ||
442 | + } | ||
443 | + } | ||
444 | + } | ||
445 | + | ||
446 | + private JSONObject invokeAnalysis(Case cd) { | ||
447 | + try { | ||
448 | + Map<String, String> header = new HashMap<>(); | ||
449 | + Map<String, Object> paramsMap = new HashMap<>(); | ||
450 | + paramsMap.put("summary", cd.getCaseDetail()); | ||
451 | + paramsMap.put("unit", cd.getFilingUnit()); | ||
452 | + String toJson = JSONObject.toJSONString(paramsMap); | ||
453 | + StringEntity myEntity = new StringEntity(toJson, ContentType.APPLICATION_JSON); | ||
454 | + String sResult = HttpClientUtils.doPostRequest(caseAnalysisUrl, header, null, myEntity); | ||
455 | + return JSONObject.parseObject(sResult); | ||
456 | + } catch (Exception ex) { | ||
457 | + ex.printStackTrace(); | ||
458 | + } | ||
459 | + | ||
460 | + return null; | ||
461 | + | ||
462 | + } | ||
463 | + | ||
392 | } | 464 | } |
@@ -3,22 +3,26 @@ package com.ash.service; | @@ -3,22 +3,26 @@ package com.ash.service; | ||
3 | import com.alibaba.excel.EasyExcel; | 3 | import com.alibaba.excel.EasyExcel; |
4 | import com.alibaba.excel.exception.ExcelAnalysisException; | 4 | import com.alibaba.excel.exception.ExcelAnalysisException; |
5 | import com.alibaba.excel.exception.ExcelDataConvertException; | 5 | import com.alibaba.excel.exception.ExcelDataConvertException; |
6 | +import com.alibaba.fastjson.JSONObject; | ||
6 | import com.ash.base.*; | 7 | import com.ash.base.*; |
7 | import com.ash.base.excelOpt.ExcelErrorMessage; | 8 | import com.ash.base.excelOpt.ExcelErrorMessage; |
8 | import com.ash.entity.WarningInstance; | 9 | import com.ash.entity.WarningInstance; |
10 | +import com.ash.entity.WarningInstanceAnalysis; | ||
9 | import com.ash.entity.dao.WarningInstanceMapper; | 11 | import com.ash.entity.dao.WarningInstanceMapper; |
12 | +import com.ash.enums.AnalysisStatusEnum; | ||
13 | +import com.ash.enums.ConformStatusEnum; | ||
10 | import com.ash.excelData.WarningInstanceExcelData; | 14 | import com.ash.excelData.WarningInstanceExcelData; |
11 | import com.ash.listener.WarningInstanceExcelListener; | 15 | import com.ash.listener.WarningInstanceExcelListener; |
12 | -import com.ash.util.DateUtils; | ||
13 | -import com.ash.util.MultipartFileToFileUtils; | ||
14 | -import com.ash.util.ObjectValueOption; | ||
15 | -import com.ash.util.UUIDGenerator; | 16 | +import com.ash.util.*; |
16 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 17 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
17 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 18 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
18 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 19 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
19 | import com.github.yulichang.query.MPJQueryWrapper; | 20 | import com.github.yulichang.query.MPJQueryWrapper; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
23 | +import org.apache.http.entity.ContentType; | ||
24 | +import org.apache.http.entity.StringEntity; | ||
25 | +import org.springframework.beans.factory.annotation.Value; | ||
22 | import org.springframework.stereotype.Service; | 26 | import org.springframework.stereotype.Service; |
23 | import org.springframework.util.CollectionUtils; | 27 | import org.springframework.util.CollectionUtils; |
24 | import org.springframework.web.multipart.MultipartFile; | 28 | import org.springframework.web.multipart.MultipartFile; |
@@ -26,19 +30,25 @@ import org.springframework.web.multipart.MultipartFile; | @@ -26,19 +30,25 @@ import org.springframework.web.multipart.MultipartFile; | ||
26 | import javax.annotation.Resource; | 30 | import javax.annotation.Resource; |
27 | import java.text.ParseException; | 31 | import java.text.ParseException; |
28 | import java.text.SimpleDateFormat; | 32 | import java.text.SimpleDateFormat; |
29 | -import java.util.ArrayList; | ||
30 | -import java.util.Date; | ||
31 | -import java.util.List; | ||
32 | -import java.util.Map; | 33 | +import java.util.*; |
33 | import java.util.concurrent.atomic.AtomicReference; | 34 | import java.util.concurrent.atomic.AtomicReference; |
35 | +import java.util.function.Function; | ||
34 | import java.util.stream.Collectors; | 36 | import java.util.stream.Collectors; |
35 | 37 | ||
36 | @Slf4j | 38 | @Slf4j |
37 | @Service | 39 | @Service |
38 | public class WarningInstanceService { | 40 | public class WarningInstanceService { |
41 | + | ||
42 | + | ||
43 | + @Value("${ash.wiAnalysisUrl}") | ||
44 | + public String wiAnalysisUrl; | ||
45 | + | ||
39 | @Resource | 46 | @Resource |
40 | private WarningInstanceMapper warningInstanceMapper; | 47 | private WarningInstanceMapper warningInstanceMapper; |
41 | 48 | ||
49 | + @Resource | ||
50 | + private WarningInstanceAnalysisService warningInstanceAnalysisService; | ||
51 | + | ||
42 | public Boolean save(WarningInstance data) { | 52 | public Boolean save(WarningInstance data) { |
43 | String uuid = UUIDGenerator.uuid(); | 53 | String uuid = UUIDGenerator.uuid(); |
44 | data.setId(uuid); | 54 | data.setId(uuid); |
@@ -103,6 +113,15 @@ public class WarningInstanceService { | @@ -103,6 +113,15 @@ public class WarningInstanceService { | ||
103 | return warningInstanceMapper.selectList(queryWrapper); | 113 | return warningInstanceMapper.selectList(queryWrapper); |
104 | } | 114 | } |
105 | 115 | ||
116 | + public List<WarningInstance> listUnAnalysis() { | ||
117 | + QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>(); | ||
118 | + LambdaQueryWrapper<WarningInstance> lambda = queryWrapper.lambda(); | ||
119 | + lambda.ne(WarningInstance::getAnalysisStatus,AnalysisStatusEnum.success); | ||
120 | + return warningInstanceMapper.selectList(queryWrapper); | ||
121 | + } | ||
122 | + | ||
123 | + | ||
124 | + | ||
106 | public Page<WarningInstance> pageByCondition(WarningInstance params, Page<WarningInstance> page) { | 125 | public Page<WarningInstance> pageByCondition(WarningInstance params, Page<WarningInstance> page) { |
107 | QueryWrapper<WarningInstance> queryWrapper = getCondition(params); | 126 | QueryWrapper<WarningInstance> queryWrapper = getCondition(params); |
108 | return warningInstanceMapper.selectPage(page, queryWrapper); | 127 | return warningInstanceMapper.selectPage(page, queryWrapper); |
@@ -281,4 +300,56 @@ public class WarningInstanceService { | @@ -281,4 +300,56 @@ public class WarningInstanceService { | ||
281 | 300 | ||
282 | return null; | 301 | return null; |
283 | } | 302 | } |
303 | + | ||
304 | + public void analysisByIds(List<String> ids) { | ||
305 | + List<WarningInstance> dataList = warningInstanceMapper.selectBatchIds(ids); | ||
306 | + analysis(dataList); | ||
307 | + | ||
308 | + } | ||
309 | + | ||
310 | + public void analysis(List<WarningInstance> dataList) { | ||
311 | + if (CollectionUtils.isEmpty(dataList)) { | ||
312 | + return; | ||
313 | + } | ||
314 | + Map<String, WarningInstance> dataMap = dataList.stream().collect(Collectors.toMap(WarningInstance::getId, Function.identity())); | ||
315 | + for (String id : dataMap.keySet()) { | ||
316 | + WarningInstance cd = dataMap.get(id); | ||
317 | + JSONObject analysisResult = invokeAnalysis(cd); | ||
318 | + if (analysisResult == null) { | ||
319 | + cd.setAnalysisStatus(AnalysisStatusEnum.fail); | ||
320 | + update(cd); | ||
321 | + } else { | ||
322 | + WarningInstanceAnalysis wa = new WarningInstanceAnalysis(); | ||
323 | + wa.setWiId(cd.getId()); | ||
324 | + wa.setArea(cd.getMunicipalPolice().replaceAll("公安局", "")); | ||
325 | + wa.setAmount(analysisResult.getDouble("value")); | ||
326 | + wa.setSex(analysisResult.getString("gender")); | ||
327 | + wa.setCareer(analysisResult.getString("occupation")); | ||
328 | + wa.setRainageMethod(analysisResult.getString("diversionMethod")); | ||
329 | + wa.setPayMethod(analysisResult.getString("paymentMethod")); | ||
330 | + wa.setConformStatus(ConformStatusEnum.UNCONFIRMED); | ||
331 | + warningInstanceAnalysisService.save(wa); | ||
332 | + cd.setAnalysisStatus(AnalysisStatusEnum.success); | ||
333 | + update(cd); | ||
334 | + } | ||
335 | + } | ||
336 | + } | ||
337 | + | ||
338 | + private JSONObject invokeAnalysis(WarningInstance cd) { | ||
339 | + try { | ||
340 | + Map<String, String> header = new HashMap<>(); | ||
341 | + Map<String, Object> paramsMap = new HashMap<>(); | ||
342 | + paramsMap.put("content", cd.getContent()); | ||
343 | + paramsMap.put("feedback", cd.getFeedbackContent()); | ||
344 | + String toJson = JSONObject.toJSONString(paramsMap); | ||
345 | + StringEntity myEntity = new StringEntity(toJson, ContentType.APPLICATION_JSON); | ||
346 | + String sResult = HttpClientUtils.doPostRequest(wiAnalysisUrl, header, null, myEntity); | ||
347 | + return JSONObject.parseObject(sResult); | ||
348 | + } catch (Exception ex) { | ||
349 | + ex.printStackTrace(); | ||
350 | + } | ||
351 | + | ||
352 | + return null; | ||
353 | + | ||
354 | + } | ||
284 | } | 355 | } |
1 | +package com.ash.util; | ||
2 | + | ||
3 | +import lombok.extern.slf4j.Slf4j; | ||
4 | +import org.apache.commons.collections.MapUtils; | ||
5 | +import org.apache.commons.lang3.StringUtils; | ||
6 | +import org.apache.http.*; | ||
7 | +import org.apache.http.client.ClientProtocolException; | ||
8 | +import org.apache.http.client.config.RequestConfig; | ||
9 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | ||
10 | +import org.apache.http.client.methods.CloseableHttpResponse; | ||
11 | +import org.apache.http.client.methods.HttpGet; | ||
12 | +import org.apache.http.client.methods.HttpPost; | ||
13 | +import org.apache.http.client.methods.HttpPut; | ||
14 | +import org.apache.http.entity.StringEntity; | ||
15 | +import org.apache.http.impl.client.CloseableHttpClient; | ||
16 | +import org.apache.http.message.BasicNameValuePair; | ||
17 | +import org.apache.http.util.EntityUtils; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | +import java.util.ArrayList; | ||
21 | +import java.util.List; | ||
22 | +import java.util.Map; | ||
23 | + | ||
24 | +@Slf4j | ||
25 | +public class HttpClientUtils { | ||
26 | + | ||
27 | + | ||
28 | + /** | ||
29 | + * 发送post请求 | ||
30 | + * | ||
31 | + * @param url:请求地址 | ||
32 | + * @param header:请求头参数 | ||
33 | + * @param params:表单参数 form提交 | ||
34 | + * @param httpEntity json/xml参数 | ||
35 | + * @return | ||
36 | + */ | ||
37 | + public static String doPostRequest(String url, Map<String, String> header, Map<String, String> params, HttpEntity httpEntity) { | ||
38 | + String resultStr = ""; | ||
39 | + if (StringUtils.isEmpty(url)) { | ||
40 | + return resultStr; | ||
41 | + } | ||
42 | + CloseableHttpClient httpClient = null; | ||
43 | + CloseableHttpResponse httpResponse = null; | ||
44 | + try { | ||
45 | + httpClient = SSLClientCustom.getHttpClinet(); | ||
46 | + HttpPost httpPost = new HttpPost(url); | ||
47 | + //请求头header信息 | ||
48 | + if (MapUtils.isNotEmpty(header)) { | ||
49 | + for (Map.Entry<String, String> stringStringEntry : header.entrySet()) { | ||
50 | + httpPost.setHeader(stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
51 | + log.info("请求header信息,key:{},value:{}", stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
52 | + } | ||
53 | + } | ||
54 | + //请求参数信息 | ||
55 | + if (MapUtils.isNotEmpty(params)) { | ||
56 | + List<NameValuePair> paramList = new ArrayList<NameValuePair>(); | ||
57 | + for (Map.Entry<String, String> stringStringEntry : params.entrySet()) { | ||
58 | + paramList.add(new BasicNameValuePair(stringStringEntry.getKey(), stringStringEntry.getValue())); | ||
59 | + log.info("请求参数信息,key:{},value:{}", stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
60 | + } | ||
61 | + UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(paramList, Consts.UTF_8); | ||
62 | + httpPost.setEntity(urlEncodedFormEntity); | ||
63 | + } | ||
64 | + //实体设置 | ||
65 | + if (httpEntity != null) { | ||
66 | + String json = EntityUtils.toString(httpEntity); | ||
67 | + log.info("请求参数信息{}", json); | ||
68 | + httpPost.setEntity(httpEntity); | ||
69 | + } | ||
70 | + //httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); | ||
71 | + //发起请求 | ||
72 | + httpResponse = httpClient.execute(httpPost); | ||
73 | + int statusCode = httpResponse.getStatusLine().getStatusCode(); | ||
74 | + if (statusCode == HttpStatus.SC_OK||statusCode == HttpStatus.SC_UNAUTHORIZED) { | ||
75 | + HttpEntity httpResponseEntity = httpResponse.getEntity(); | ||
76 | + resultStr = EntityUtils.toString(httpResponseEntity); | ||
77 | + //log.info("请求正常,请求地址:{},响应结果:{}", url, statusCode+";"+resultStr); | ||
78 | + } else { | ||
79 | + StringBuffer stringBuffer = new StringBuffer(); | ||
80 | + HeaderIterator headerIterator = httpResponse.headerIterator(); | ||
81 | + while (headerIterator.hasNext()) { | ||
82 | + stringBuffer.append("\t" + headerIterator.next()); | ||
83 | + } | ||
84 | + log.info("异常信息:请求地址:{},响应状态和结果:{}",url,statusCode+";"+stringBuffer); | ||
85 | + } | ||
86 | + | ||
87 | + } catch (Exception e) { | ||
88 | + log.info("请求地址:{}", url); | ||
89 | + e.printStackTrace(); | ||
90 | + } finally { | ||
91 | + HttpClientUtils.closeConnection(httpClient, httpResponse); | ||
92 | + } | ||
93 | + return resultStr; | ||
94 | + } | ||
95 | + | ||
96 | + public static String doGetRequest(String url, Map<String, String> header, Map<String, Object> params) { | ||
97 | + String resultStr = ""; | ||
98 | + if (StringUtils.isEmpty(url)) { | ||
99 | + return resultStr; | ||
100 | + } | ||
101 | + CloseableHttpClient httpClient = null; | ||
102 | + CloseableHttpResponse httpResponse = null; | ||
103 | + try { | ||
104 | + httpClient = SSLClientCustom.getHttpClinet(); | ||
105 | + //请求参数信息 | ||
106 | + if (MapUtils.isNotEmpty(params)) { | ||
107 | + url = url + buildUrl(params); | ||
108 | + } | ||
109 | + HttpGet httpGet = new HttpGet(url); | ||
110 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000)//连接超时 | ||
111 | + .setConnectionRequestTimeout(25000)//请求超时 | ||
112 | + .setSocketTimeout(25000)//套接字连接超时 | ||
113 | + .setRedirectsEnabled(true).build();//允许重定向 | ||
114 | + httpGet.setConfig(requestConfig); | ||
115 | + if (MapUtils.isNotEmpty(header)) { | ||
116 | + for (Map.Entry<String, String> stringStringEntry : header.entrySet()) { | ||
117 | + httpGet.setHeader(stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
118 | + } | ||
119 | + } | ||
120 | + //发起请求 | ||
121 | + httpResponse = httpClient.execute(httpGet); | ||
122 | + int statusCode = httpResponse.getStatusLine().getStatusCode(); | ||
123 | + if (statusCode == HttpStatus.SC_OK) { | ||
124 | + resultStr = EntityUtils.toString(httpResponse.getEntity(), Consts.UTF_8); | ||
125 | + log.info("请求地址:{},响应结果:{}", url, resultStr); | ||
126 | + } else { | ||
127 | + StringBuffer stringBuffer = new StringBuffer(); | ||
128 | + HeaderIterator headerIterator = httpResponse.headerIterator(); | ||
129 | + while (headerIterator.hasNext()) { | ||
130 | + stringBuffer.append("\t" + headerIterator.next()); | ||
131 | + } | ||
132 | + resultStr = EntityUtils.toString(httpResponse.getEntity(), Consts.UTF_8); | ||
133 | + log.info("异常信息请求地址:{}", url, resultStr); | ||
134 | + log.info("异常信息:请求响应状态:{},请求返回结果:{}", httpResponse.getStatusLine().getStatusCode(),StringUtils.isBlank(resultStr)?stringBuffer:resultStr); | ||
135 | + } | ||
136 | + | ||
137 | + } catch (Exception e) { | ||
138 | + log.info("请求地址:{}", url); | ||
139 | + e.printStackTrace(); | ||
140 | + | ||
141 | + } finally { | ||
142 | + HttpClientUtils.closeConnection(httpClient, httpResponse); | ||
143 | + } | ||
144 | + return resultStr; | ||
145 | + } | ||
146 | + | ||
147 | + public static String doGetRequest(String url, Map<String, String> header, Map<String, Object> params,StringBuffer tracecode) { | ||
148 | + String resultStr = ""; | ||
149 | + if (StringUtils.isEmpty(url)) { | ||
150 | + return resultStr; | ||
151 | + } | ||
152 | + CloseableHttpClient httpClient = null; | ||
153 | + CloseableHttpResponse httpResponse = null; | ||
154 | + try { | ||
155 | + httpClient = SSLClientCustom.getHttpClinet(); | ||
156 | + //请求参数信息 | ||
157 | + if (MapUtils.isNotEmpty(params)) { | ||
158 | + url = url + buildUrl(params); | ||
159 | + } | ||
160 | + HttpGet httpGet = new HttpGet(url); | ||
161 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000)//连接超时 | ||
162 | + .setConnectionRequestTimeout(30000)//请求超时 | ||
163 | + .setSocketTimeout(30000)//套接字连接超时 | ||
164 | + .setRedirectsEnabled(true).build();//允许重定向 | ||
165 | + httpGet.setConfig(requestConfig); | ||
166 | + if (MapUtils.isNotEmpty(header)) { | ||
167 | + for (Map.Entry<String, String> stringStringEntry : header.entrySet()) { | ||
168 | + httpGet.setHeader(stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
169 | + } | ||
170 | + } | ||
171 | + //发起请求 | ||
172 | + httpResponse = httpClient.execute(httpGet); | ||
173 | + int statusCode = httpResponse.getStatusLine().getStatusCode(); | ||
174 | + if (statusCode == HttpStatus.SC_OK) { | ||
175 | + Header[] tracecodes = httpResponse.getHeaders("Tracecode"); | ||
176 | + tracecode.append(tracecodes[0].getValue()); | ||
177 | + resultStr = EntityUtils.toString(httpResponse.getEntity(), Consts.UTF_8); | ||
178 | + log.info("请求地址:{},响应结果:{}", url, resultStr); | ||
179 | + } else { | ||
180 | + StringBuffer stringBuffer = new StringBuffer(); | ||
181 | + HeaderIterator headerIterator = httpResponse.headerIterator(); | ||
182 | + while (headerIterator.hasNext()) { | ||
183 | + stringBuffer.append("\t" + headerIterator.next()); | ||
184 | + } | ||
185 | + log.info("异常信息:请求地址:{},请求响应状态:{},请求返回结果:{}",url,httpResponse.getStatusLine().getStatusCode(), stringBuffer); | ||
186 | + } | ||
187 | + | ||
188 | + } catch (Exception e) { | ||
189 | + e.printStackTrace(); | ||
190 | + } finally { | ||
191 | + HttpClientUtils.closeConnection(httpClient, httpResponse); | ||
192 | + } | ||
193 | + return resultStr; | ||
194 | + } | ||
195 | + | ||
196 | + | ||
197 | + public static String doPutRequest(String url, Map<String, String> header,StringEntity entity) { | ||
198 | + | ||
199 | + CloseableHttpClient closeableHttpClient = null; | ||
200 | + CloseableHttpResponse closeableHttpResponse=null; | ||
201 | + try { | ||
202 | + closeableHttpClient = SSLClientCustom.getHttpClinet(); | ||
203 | + } catch (Exception e) { | ||
204 | + e.printStackTrace(); | ||
205 | + } | ||
206 | + | ||
207 | + | ||
208 | + RequestConfig requestConfig = RequestConfig.custom() | ||
209 | + .setConnectTimeout(5000) | ||
210 | + .setConnectionRequestTimeout(5000) | ||
211 | + .setRedirectsEnabled(true) | ||
212 | + .build(); | ||
213 | + | ||
214 | + HttpPut httpPost = new HttpPut(url); | ||
215 | + | ||
216 | + httpPost.setConfig(requestConfig); | ||
217 | + httpPost.setHeader("Content-Type", "application/json"); | ||
218 | + | ||
219 | + if (MapUtils.isNotEmpty(header)) { | ||
220 | + for (Map.Entry<String, String> stringStringEntry : header.entrySet()) { | ||
221 | + httpPost.setHeader(stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
222 | + log.info("请求header信息,key:{},value:{}", stringStringEntry.getKey(), stringStringEntry.getValue()); | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | + String strRequest = ""; | ||
227 | + try { | ||
228 | +// StringEntity entity = new StringEntity(jsonObject.toString(), "utf-8"); | ||
229 | + entity.setContentEncoding("utf-8"); | ||
230 | + entity.setContentType("application/json"); | ||
231 | + httpPost.setEntity(entity); | ||
232 | + | ||
233 | + | ||
234 | + closeableHttpResponse = closeableHttpClient.execute(httpPost); | ||
235 | + | ||
236 | + if (null != closeableHttpResponse && !"".equals(closeableHttpResponse)) { | ||
237 | + int statusCode = closeableHttpResponse.getStatusLine().getStatusCode(); | ||
238 | + if (closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | ||
239 | + HttpEntity httpEntity = closeableHttpResponse.getEntity(); | ||
240 | + strRequest = EntityUtils.toString(httpEntity); | ||
241 | + log.info("请求正常,请求地址:{},响应结果:{}", url, statusCode+";"+strRequest); | ||
242 | + } else { | ||
243 | + StringBuffer stringBuffer = new StringBuffer(); | ||
244 | + HeaderIterator headerIterator = closeableHttpResponse.headerIterator(); | ||
245 | + while (headerIterator.hasNext()) { | ||
246 | + stringBuffer.append("\t" + headerIterator.next()); | ||
247 | + } | ||
248 | + strRequest = "Error Response" + statusCode; | ||
249 | + log.info("异常信息:请求地址:{},响应状态和结果:{}",url,strRequest+";"+stringBuffer); | ||
250 | + } | ||
251 | + } | ||
252 | + | ||
253 | + } catch (ClientProtocolException e) { | ||
254 | + e.printStackTrace(); | ||
255 | + } catch (ParseException e) { | ||
256 | + e.printStackTrace(); | ||
257 | + } catch (IOException e) { | ||
258 | + e.printStackTrace(); | ||
259 | + } finally { | ||
260 | + try { | ||
261 | + if (closeableHttpClient != null) { | ||
262 | + closeableHttpClient.close(); | ||
263 | + } | ||
264 | + | ||
265 | + if(closeableHttpResponse!=null){ | ||
266 | + closeableHttpResponse.close(); | ||
267 | + } | ||
268 | + } catch (IOException e) { | ||
269 | + e.printStackTrace(); | ||
270 | + } | ||
271 | + } | ||
272 | + | ||
273 | + return strRequest; | ||
274 | + } | ||
275 | + | ||
276 | + | ||
277 | + | ||
278 | + /** | ||
279 | + * 关掉连接释放资源 | ||
280 | + */ | ||
281 | + private static void closeConnection(CloseableHttpClient httpClient, CloseableHttpResponse httpResponse) { | ||
282 | + if (httpClient != null) { | ||
283 | + try { | ||
284 | + httpClient.close(); | ||
285 | + } catch (IOException e) { | ||
286 | + e.printStackTrace(); | ||
287 | + } | ||
288 | + } | ||
289 | + if (httpResponse != null) { | ||
290 | + try { | ||
291 | + httpResponse.close(); | ||
292 | + } catch (IOException e) { | ||
293 | + e.printStackTrace(); | ||
294 | + } | ||
295 | + } | ||
296 | + | ||
297 | + } | ||
298 | + | ||
299 | + /** | ||
300 | + * 构造get请求的参数 | ||
301 | + * | ||
302 | + * @return | ||
303 | + */ | ||
304 | + private static String buildUrl(Map<String, Object> map) { | ||
305 | + if (MapUtils.isEmpty(map)) { | ||
306 | + return ""; | ||
307 | + } | ||
308 | + StringBuffer stringBuffer = new StringBuffer("?"); | ||
309 | + for (Map.Entry<String, Object> stringStringEntry : map.entrySet()) { | ||
310 | + stringBuffer.append(stringStringEntry.getKey()).append("=").append(stringStringEntry.getValue()).append("&"); | ||
311 | + } | ||
312 | + String result = stringBuffer.toString(); | ||
313 | + if (StringUtils.isNotEmpty(result)) { | ||
314 | + result = result.substring(0, result.length() - 1);//去掉结尾的&连接符 | ||
315 | + } | ||
316 | + return result; | ||
317 | + } | ||
318 | + | ||
319 | +} |
1 | +package com.ash.util; | ||
2 | + | ||
3 | +import org.apache.http.config.Registry; | ||
4 | +import org.apache.http.config.RegistryBuilder; | ||
5 | +import org.apache.http.conn.socket.ConnectionSocketFactory; | ||
6 | +import org.apache.http.conn.socket.PlainConnectionSocketFactory; | ||
7 | +import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
8 | +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
9 | +import org.apache.http.conn.ssl.TrustStrategy; | ||
10 | +import org.apache.http.impl.client.CloseableHttpClient; | ||
11 | +import org.apache.http.impl.client.HttpClients; | ||
12 | +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
13 | +import org.apache.http.ssl.SSLContextBuilder; | ||
14 | + | ||
15 | +import java.security.KeyManagementException; | ||
16 | +import java.security.KeyStoreException; | ||
17 | +import java.security.NoSuchAlgorithmException; | ||
18 | +import java.security.cert.CertificateException; | ||
19 | +import java.security.cert.X509Certificate; | ||
20 | + | ||
21 | +public class SSLClientCustom { | ||
22 | + private static final String HTTP = "http"; | ||
23 | + private static final String HTTPS = "https"; | ||
24 | + private static SSLConnectionSocketFactory sslConnectionSocketFactory = null; | ||
25 | + private static PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = null;//连接池管理类 | ||
26 | + private static SSLContextBuilder sslContextBuilder = null;//管理Https连接的上下文类 | ||
27 | + | ||
28 | + static { | ||
29 | + try { | ||
30 | + sslContextBuilder = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { | ||
31 | + @Override | ||
32 | + public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | ||
33 | +// 信任所有站点 直接返回true | ||
34 | + return true; | ||
35 | + } | ||
36 | + }); | ||
37 | + sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(), new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE); | ||
38 | + Registry<ConnectionSocketFactory> registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create() | ||
39 | + .register(HTTP, new PlainConnectionSocketFactory()) | ||
40 | + .register(HTTPS, sslConnectionSocketFactory) | ||
41 | + .build(); | ||
42 | + poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registryBuilder); | ||
43 | + poolingHttpClientConnectionManager.setMaxTotal(200); | ||
44 | + } catch (NoSuchAlgorithmException e) { | ||
45 | + e.printStackTrace(); | ||
46 | + } catch (KeyStoreException e) { | ||
47 | + e.printStackTrace(); | ||
48 | + } catch (KeyManagementException e) { | ||
49 | + e.printStackTrace(); | ||
50 | + } | ||
51 | + | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * 获取连接 | ||
56 | + * | ||
57 | + * @return | ||
58 | + * @throws Exception | ||
59 | + */ | ||
60 | + public static CloseableHttpClient getHttpClinet() throws Exception { | ||
61 | + CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory) | ||
62 | + .setConnectionManager(poolingHttpClientConnectionManager) | ||
63 | + .setConnectionManagerShared(true) | ||
64 | + .build(); | ||
65 | + return httpClient; | ||
66 | + } | ||
67 | +} |
@@ -5,13 +5,14 @@ spring: | @@ -5,13 +5,14 @@ spring: | ||
5 | name: ash | 5 | name: ash |
6 | main: | 6 | main: |
7 | allow-bean-definition-overriding: true | 7 | allow-bean-definition-overriding: true |
8 | + allow-circular-references: true | ||
8 | profiles: | 9 | profiles: |
9 | active: default | 10 | active: default |
10 | datasource: | 11 | datasource: |
11 | - url: jdbc:mysql://53.1.236.89:3306/ash?useSSL=false&autoReconnect=true&characterEncoding=utf8 | 12 | + url: jdbc:mysql://10.9.1.252:3306/ash?useSSL=false&autoReconnect=true&characterEncoding=utf8 |
12 | driver-class-name: com.mysql.cj.jdbc.Driver | 13 | driver-class-name: com.mysql.cj.jdbc.Driver |
13 | - username: root | ||
14 | - password: zaq1,lp- | 14 | + username: qixiao |
15 | + password: qixiao123!@# | ||
15 | type: com.alibaba.druid.pool.DruidDataSource | 16 | type: com.alibaba.druid.pool.DruidDataSource |
16 | druid: | 17 | druid: |
17 | initial-size: 5 | 18 | initial-size: 5 |
@@ -25,11 +26,9 @@ spring: | @@ -25,11 +26,9 @@ spring: | ||
25 | test-on-return: true | 26 | test-on-return: true |
26 | test-while-idle: true | 27 | test-while-idle: true |
27 | redis: | 28 | redis: |
28 | - # cluster: | ||
29 | - # nodes: 10.9.1.252:16380 | ||
30 | - password: zaq1,lp- | ||
31 | - host: 53.1.236.89 | ||
32 | - port: 36379 | 29 | + cluster: |
30 | + nodes: 10.9.1.252:16380 | ||
31 | + password: qixiao@123.com | ||
33 | timeout: 3000 | 32 | timeout: 3000 |
34 | servlet: | 33 | servlet: |
35 | multipart: | 34 | multipart: |
@@ -52,6 +51,8 @@ logging: | @@ -52,6 +51,8 @@ logging: | ||
52 | ash: | 51 | ash: |
53 | # errorFilePath: D:/data/errorData | 52 | # errorFilePath: D:/data/errorData |
54 | errorFilePath: /web/errorData | 53 | errorFilePath: /web/errorData |
54 | + wiAnalysisUrl: http://10.124.9.44:9098/review/infoAnalyse | ||
55 | + caseAnalysisUrl: http://10.124.9.44:9098/review/caseAnalyse | ||
55 | auth: | 56 | auth: |
56 | enable: false | 57 | enable: false |
57 | white: | 58 | white: |