File tree 8 files changed +112
-4
lines changed
8 files changed +112
-4
lines changed Original file line number Diff line number Diff line change 67
67
<artifactId >jakarta.xml.bind-api</artifactId >
68
68
<version >2.3.3</version >
69
69
</dependency >
70
+ <dependency >
71
+ <groupId >org.springframework.boot</groupId >
72
+ <artifactId >spring-boot-starter-data-elasticsearch</artifactId >
73
+ </dependency >
70
74
</dependencies >
71
75
72
76
Original file line number Diff line number Diff line change
1
+ package com .serve .api .configuration ;
2
+
3
+ import org .elasticsearch .client .RestHighLevelClient ;
4
+ import org .springframework .beans .factory .annotation .Value ;
5
+ import org .springframework .context .annotation .Bean ;
6
+ import org .springframework .context .annotation .ComponentScan ;
7
+ import org .springframework .context .annotation .Configuration ;
8
+ import org .springframework .data .elasticsearch .client .ClientConfiguration ;
9
+ import org .springframework .data .elasticsearch .client .RestClients ;
10
+ import org .springframework .data .elasticsearch .config .AbstractElasticsearchConfiguration ;
11
+ import org .springframework .data .elasticsearch .repository .config .EnableElasticsearchRepositories ;
12
+
13
+ @ Configuration
14
+ @ EnableElasticsearchRepositories (basePackages = "com.serve.api.repository" )
15
+ @ ComponentScan (basePackages = "com.serve.api" )
16
+ public class Config extends AbstractElasticsearchConfiguration {
17
+
18
+ @ Value ("${elasticsearch.url}" )
19
+ public String elasticsearchUrl ;
20
+
21
+ @ Bean
22
+ @ Override
23
+ public RestHighLevelClient elasticsearchClient () {
24
+
25
+ final ClientConfiguration config = ClientConfiguration .builder ()
26
+ .connectedTo (elasticsearchUrl )
27
+ .build ();
28
+
29
+ return RestClients .create (config ).rest ();
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ package com .serve .api .model .document ;
2
+
3
+ import org .springframework .data .annotation .Id ;
4
+ import org .springframework .data .elasticsearch .annotations .Document ;
5
+ import org .springframework .data .elasticsearch .annotations .Field ;
6
+ import org .springframework .data .elasticsearch .annotations .FieldType ;
7
+ import org .springframework .data .elasticsearch .annotations .Setting ;
8
+
9
+ @ Document (indexName = "staff" )
10
+ @ Setting (settingPath = "static/es-settings.json" )
11
+ public class Staff {
12
+
13
+ @ Id
14
+ @ Field (type = FieldType .Keyword )
15
+ public Long id ;
16
+
17
+ @ Field (type = FieldType .Text )
18
+ public String name ;
19
+
20
+ public Long getId () {
21
+ return id ;
22
+ }
23
+
24
+ public void setId (Long id ) {
25
+ this .id = id ;
26
+ }
27
+
28
+ public String getName () {
29
+ return name ;
30
+ }
31
+
32
+ public void setName (String name ) {
33
+ this .name = name ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ package com .serve .api .repository ;
2
+
3
+ import com .serve .api .model .document .Staff ;
4
+ import org .springframework .data .elasticsearch .repository .ElasticsearchRepository ;
5
+ import org .springframework .stereotype .Repository ;
6
+
7
+ @ Repository
8
+ public interface StaffRepository extends ElasticsearchRepository <Staff , Long > {
9
+ }
Original file line number Diff line number Diff line change 3
3
import com .serve .api .dto .ArriveDto ;
4
4
import com .serve .api .mapper .ArriveMapper ;
5
5
import com .serve .api .model .entity .Arrive ;
6
- import com .serve .api .model .entity .Worker ;
7
6
import com .serve .api .model .enumeration .Type ;
8
7
import com .serve .api .repository .ArriveRepository ;
9
8
import com .serve .api .repository .CompanyRepository ;
13
12
import lombok .experimental .FieldDefaults ;
14
13
import org .slf4j .Logger ;
15
14
import org .slf4j .LoggerFactory ;
16
- import org .springframework .security .core .context .SecurityContextHolder ;
17
- import org .springframework .security .core .userdetails .UserDetails ;
15
+
18
16
import org .springframework .stereotype .Service ;
19
17
20
- import java .time .Duration ;
21
18
import java .time .Period ;
22
19
import java .util .Date ;
23
20
import java .util .List ;
Original file line number Diff line number Diff line change
1
+ package com .serve .api .service ;
2
+
3
+ import com .serve .api .model .document .Staff ;
4
+ import com .serve .api .repository .StaffRepository ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .stereotype .Service ;
7
+
8
+ @ Service
9
+ public class StaffService {
10
+
11
+ private final StaffRepository repository ;
12
+
13
+ @ Autowired
14
+ public StaffService (StaffRepository repository ) {
15
+ this .repository = repository ;
16
+ }
17
+
18
+ public void save (final Staff staff ){
19
+ repository .save (staff );
20
+ }
21
+
22
+ public Staff findById (final Long id ){
23
+ return repository .findById (id ).orElse (null );
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -7,3 +7,5 @@ spring.datasource.password=apiuser
7
7
spring.jpa.hibernate.ddl-auto =update
8
8
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
9
9
spring.liquibase.change-log =db/changelog/db/changelog/db.changelog-master.xml
10
+
11
+ elasticsearch.url = localhost:9200
Original file line number Diff line number Diff line change
1
+ {
2
+ "index" : {
3
+
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments