|
@@ -5,11 +5,14 @@ import com.vcarecity.publish.api.ApiResult;
|
5
|
5
|
import com.vcarecity.publish.api.ApiStatus;
|
6
|
6
|
import com.vcarecity.publish.constants.ElasticConstant;
|
7
|
7
|
import com.vcarecity.publish.elastic.service.ElasticLoadDataService;
|
|
8
|
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
|
|
9
|
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
|
8
|
10
|
import com.vcarecity.publish.pojo.dto.TotalResultDTO;
|
9
|
11
|
import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
|
10
|
12
|
import com.vcarecity.publish.pojo.dto.UnitIdDTO;
|
11
|
13
|
import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
|
12
|
14
|
import com.vcarecity.publish.service.LoadDataStatusService;
|
|
15
|
+import com.vcarecity.publish.sql.service.AgencyService;
|
13
|
16
|
import com.vcarecity.publish.sql.service.UnitService;
|
14
|
17
|
import lombok.extern.slf4j.Slf4j;
|
15
|
18
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -17,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
17
|
20
|
|
18
|
21
|
import javax.validation.Valid;
|
19
|
22
|
import java.io.IOException;
|
|
23
|
+import java.util.ArrayList;
|
20
|
24
|
import java.util.List;
|
21
|
25
|
|
22
|
26
|
/**
|
|
@@ -29,16 +33,20 @@ public class MainController implements PrepareController {
|
29
|
33
|
|
30
|
34
|
|
31
|
35
|
private final UnitService unitService;
|
|
36
|
+ private final AgencyService agencyService;
|
32
|
37
|
private final ElasticLoadDataService elasticLoadDataService;
|
|
38
|
+ private final ElasticUpdateService elasticUpdateService;
|
33
|
39
|
private final LoadDataStatusService loadDataStatusService;
|
34
|
40
|
|
35
|
41
|
public MainController(UnitService unitService,
|
36
|
42
|
ElasticLoadDataService elasticLoadDataService,
|
37
|
43
|
LoadDataStatusService loadDataStatusService,
|
38
|
|
- @Value("${app.index.reload}") Boolean reloadData) {
|
|
44
|
+ @Value("${app.index.reload}") Boolean reloadData, AgencyService agencyService, ElasticUpdateService elasticUpdateService) {
|
39
|
45
|
this.unitService = unitService;
|
40
|
46
|
this.elasticLoadDataService = elasticLoadDataService;
|
41
|
47
|
this.loadDataStatusService = loadDataStatusService;
|
|
48
|
+ this.agencyService = agencyService;
|
|
49
|
+ this.elasticUpdateService = elasticUpdateService;
|
42
|
50
|
|
43
|
51
|
if (!reloadData) {
|
44
|
52
|
// 不重新加载
|
|
@@ -49,7 +57,7 @@ public class MainController implements PrepareController {
|
49
|
57
|
|
50
|
58
|
@SkipMethod
|
51
|
59
|
@ResponseBody
|
52
|
|
- @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
|
|
60
|
+ @RequestMapping(value = "/set-load", method = {RequestMethod.GET, RequestMethod.POST})
|
53
|
61
|
public ApiResult setLoaded() {
|
54
|
62
|
loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADED);
|
55
|
63
|
return ApiResult.builder().status(20000).message("already load data success!").build();
|
|
@@ -82,6 +90,32 @@ public class MainController implements PrepareController {
|
82
|
90
|
}
|
83
|
91
|
|
84
|
92
|
|
|
93
|
+ @ResponseBody
|
|
94
|
+ @RequestMapping(value = "/loadByAgencyIds", method = {RequestMethod.POST, RequestMethod.GET})
|
|
95
|
+ public ApiResult loadByAgencyIds(@RequestParam("agencyIds") String agencyIds) {
|
|
96
|
+ String[] split = agencyIds.split(",");
|
|
97
|
+ List<Long> ids = new ArrayList<>(split.length);
|
|
98
|
+ for (String s : split) {
|
|
99
|
+ try {
|
|
100
|
+ ids.add(Long.parseLong(s));
|
|
101
|
+ } catch (RuntimeException e) {
|
|
102
|
+ e.printStackTrace();
|
|
103
|
+ }
|
|
104
|
+ }
|
|
105
|
+ List<UnitAgencyMergeEntity> result = agencyService.loadByAgencyIds(ids);
|
|
106
|
+ if (result == null) {
|
|
107
|
+ return ApiResult.builder().status(ApiStatus.FAILED_CODE).build();
|
|
108
|
+ }
|
|
109
|
+ try {
|
|
110
|
+ elasticUpdateService.handlerDataChange("unitId", result);
|
|
111
|
+ return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).build();
|
|
112
|
+ } catch (IOException e) {
|
|
113
|
+ e.printStackTrace();
|
|
114
|
+ return ApiResult.builder().status(40000).message(e.getMessage()).build();
|
|
115
|
+ }
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+
|
85
|
119
|
@PostMapping("/query-unit-agency")
|
86
|
120
|
public ApiResult queryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
|
87
|
121
|
|