Merge pull request #14 from linzb0123/houserush-sample
Add the two of 6 micro-services: login and gateway
diff --git a/houserush/README.md b/houserush/README.md
index 2ccff7f..a167254 100644
--- a/houserush/README.md
+++ b/houserush/README.md
@@ -17,4 +17,4 @@
4. check & change the src/main/resources/microservice.yaml and src/main/resources/application.yaml configuration file.
-5. run each microservice process <code>by mvn spring-boot:run. </code>
\ No newline at end of file
+5. run each microservice process by <code>mvn spring-boot:run. </code>
\ No newline at end of file
diff --git a/houserush/customer-manage/pom.xml b/houserush/customer-manage/pom.xml
index fae8da0..696d99b 100644
--- a/houserush/customer-manage/pom.xml
+++ b/houserush/customer-manage/pom.xml
@@ -25,7 +25,6 @@
</parent>
<modelVersion>4.0.0</modelVersion>
-
<artifactId>houserush-customer-manage</artifactId>
<name>Java Chassis::Samples::Practice::HouseRush-Customer-Manage</name>
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageApplication.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageApplication.java
new file mode 100644
index 0000000..17947d0
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageApplication.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage;
+
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+@SpringBootApplication
+@EnableServiceComb
+@EnableJpaAuditing
+public class CustomerManageApplication {
+
+ public static void main(String[] args) {
+ configBeforeBoot();
+ SpringApplication.run(CustomerManageApplication.class, args);
+ }
+
+ private static void configBeforeBoot() {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+ RestObjectMapperFactory.getRestObjectMapper().setDateFormat(simpleDateFormat);
+ }
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageConfig.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageConfig.java
new file mode 100644
index 0000000..7432139
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/CustomerManageConfig.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Configuration
+@EnableJpaRepositories(basePackages = "org.apache.servicecomb.samples.practise.houserush")
+public class CustomerManageConfig {
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Customer.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Customer.java
new file mode 100644
index 0000000..0494245
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Customer.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.Where;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+@Entity
+@Table(name = "customers")
+@SQLDelete(sql = "update customers set = now() where id = ?")
+@Where(clause = "deleted_at is null")
+@EntityListeners(AuditingEntityListener.class)
+public class Customer {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+
+ private String phone;
+
+ private String realName;
+
+ private String address;
+
+ @OneToMany(mappedBy = "customer", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
+ private List<Qualification> qualifications = new ArrayList<>();
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date updatedAt;
+}
\ No newline at end of file
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Qualification.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Qualification.java
new file mode 100644
index 0000000..ac5878b
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/Qualification.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Data
+@Entity
+@Table(name = "qualifications")
+@EntityListeners(AuditingEntityListener.class)
+public class Qualification {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "customer_id")
+ private Customer customer;
+
+ private Integer saleId;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date UpdatedAt;
+}
\ No newline at end of file
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/User.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/User.java
new file mode 100644
index 0000000..77e7898
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/aggregate/User.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Data
+public class User {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+
+ private String username;
+
+ @Transient
+ private String password;
+
+ @JsonIgnore
+ private String hashedPassword;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updatedAt;
+
+ @Transient
+ private String token;
+
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApi.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApi.java
new file mode 100644
index 0000000..0ce9a4f
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApi.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.api;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Customer;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Qualification;
+
+import java.util.List;
+
+public interface CustomerManageApi {
+ Customer createCustomer(Customer customer);
+
+ Customer findCustomer(int id);
+
+ Customer updateCustomer(int id, Customer customer);
+
+ void removeCustomer(int id);
+
+ List<Customer> indexCustomers();
+
+ Customer updateCustomerQualifications(int id, List<Qualification> qualifications);
+
+ int getQualificationsCount(int customerId, int saleId);
+}
\ No newline at end of file
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApiRestImpl.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApiRestImpl.java
new file mode 100644
index 0000000..ddf925e
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/api/CustomerManageApiRestImpl.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.api;
+
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.User;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.rpc.UserApi;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.service.CustomerManageService;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Customer;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Qualification;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestSchema(schemaId = "customerManageApiRest")
+@RequestMapping("/")
+public class CustomerManageApiRestImpl implements CustomerManageApi {
+
+ @RpcReference(microserviceName = "login", schemaId = "userApiRest")
+ private UserApi userApi;
+
+ @Autowired
+ private CustomerManageService customerManageService;
+
+ @PostMapping("customers")
+ public Customer createCustomer(@RequestBody Customer customer) {
+ User user = new User();
+ user.setUsername(customer.getRealName());
+ user.setPassword("123456");
+ userApi.createUser(user);
+ return customerManageService.createCustomer(customer);
+ }
+
+ @GetMapping("customers/{id}")
+ public Customer findCustomer(@PathVariable int id) {
+ return customerManageService.findCustomer(id);
+ }
+
+ @PutMapping("customers/{id}")
+ public Customer updateCustomer(@PathVariable int id, @RequestBody Customer customer) {
+ customer.setId(id);
+ return customerManageService.updateCustomer(customer);
+ }
+
+ @DeleteMapping("customers/{id}")
+ public void removeCustomer(@PathVariable int id) {
+ customerManageService.removeCustomer(id);
+ }
+
+ @GetMapping("customers")
+ public List<Customer> indexCustomers() {
+ return customerManageService.indexCustomers();
+ }
+
+ @PutMapping(value = "customers/{id}/update_qualifications")
+ public Customer updateCustomerQualifications(@PathVariable int id, @RequestBody List<Qualification> qualifications) {
+ Customer customer = customerManageService.findCustomer(id);
+ customerManageService.updateCustomerQualifications(customer, qualifications);
+ // refresh customer
+ customer = customerManageService.findCustomer(id);
+ return customer;
+ }
+
+ @GetMapping("customers/{customerId}/sales/{saleId}/qulification_count")
+ public int getQualificationsCount(@PathVariable int customerId, @PathVariable int saleId) {
+ return customerManageService.getQualificationsCount(customerId, saleId);
+
+ }
+}
\ No newline at end of file
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/CustomerDao.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/CustomerDao.java
new file mode 100644
index 0000000..c77a85c
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/CustomerDao.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Customer;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface CustomerDao extends JpaRepository<Customer, Integer> {
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/QualificationDao.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/QualificationDao.java
new file mode 100644
index 0000000..5227cae
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/dao/QualificationDao.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Qualification;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface QualificationDao extends JpaRepository<Qualification, Integer> {
+ int countByCustomerIdAndSaleId(int customerId, int saleId);
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/rpc/UserApi.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/rpc/UserApi.java
new file mode 100644
index 0000000..6a0c155
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/rpc/UserApi.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.rpc;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.User;
+
+public interface UserApi {
+ User createUser(User user);
+
+ User findUser(int id);
+
+ void removeUser(int id);
+
+ User signin(User user);
+
+ User verifyToken(String token);
+}
\ No newline at end of file
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageService.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageService.java
new file mode 100644
index 0000000..cc0c535
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageService.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.service;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Customer;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Qualification;
+
+import java.util.List;
+
+public interface CustomerManageService {
+ Customer createCustomer(Customer customer);
+
+ Customer findCustomer(int id);
+
+ Customer updateCustomer(Customer customer);
+
+ void removeCustomer(int id);
+
+ List<Customer> indexCustomers();
+
+ boolean updateCustomerQualifications(Customer customer, List<Qualification> qualifications);
+
+ int getQualificationsCount(int customerId, int saleId);
+
+}
diff --git a/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageServiceImpl.java b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageServiceImpl.java
new file mode 100644
index 0000000..2881054
--- /dev/null
+++ b/houserush/customer-manage/src/main/java/org/apache/servicecomb/samples/practise/houserush/customer/manage/service/CustomerManageServiceImpl.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.customer.manage.service;
+
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Customer;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.aggregate.Qualification;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.dao.CustomerDao;
+import org.apache.servicecomb.samples.practise.houserush.customer.manage.dao.QualificationDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CustomerManageServiceImpl implements CustomerManageService {
+
+ @Autowired
+ private CustomerDao customerDao;
+
+ @Autowired
+ private QualificationDao qualificationDao;
+
+ @Override
+ public Customer createCustomer(Customer customer) {
+ return customerDao.save(customer);
+ }
+
+ @Override
+ public Customer updateCustomer(Customer customer) {
+ int id = customer.getId();
+ if (customerDao.exists(id)) {
+ return customerDao.save(customer);
+ } else {
+ throw new DataRetrievalFailureException("cannot update the non-existed customer");
+ }
+ }
+
+ @Override
+ public Customer findCustomer(int id) {
+ return customerDao.findOne(id);
+ }
+
+ @Override
+ public void removeCustomer(int id) {
+ customerDao.delete(id);
+ }
+
+ @Override
+ public List<Customer> indexCustomers() {
+ return customerDao.findAll();
+ }
+
+ @Override
+ public boolean updateCustomerQualifications(Customer customer, List<Qualification> qualifications) {
+ customer.setQualifications(qualifications);
+ qualifications.forEach(qualification -> qualification.setCustomer(customer));
+ customerDao.saveAndFlush(customer);
+ return true;
+ }
+
+ @Override
+ public int getQualificationsCount(int customerId, int saleId) {
+ return qualificationDao.countByCustomerIdAndSaleId(customerId, saleId);
+ }
+}
diff --git a/houserush/customer-manage/src/main/resources/microservice.yaml b/houserush/customer-manage/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..7fa9d94
--- /dev/null
+++ b/houserush/customer-manage/src/main/resources/microservice.yaml
@@ -0,0 +1,44 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# all interconnected microservices must belong to an application wth the same ID
+APPLICATION_ID: houserush
+service_description:
+# name of the declaring microservice
+ name: customer-manage
+ version: 0.0.20
+servicecomb:
+ service:
+ registry:
+ address: http://192.168.229.134:30100
+ rest:
+ address: 0.0.0.0:7779
+ handler:
+ chain:
+ Provider:
+ default: bizkeeper-provider
+spring:
+ datasource:
+ url: jdbc:mysql://172.17.0.128:3306/customer?characterEncoding=utf8&useSSL=false
+ driver-class-name: com.mysql.jdbc.Driver
+ username: root
+ password: 123456
+ jpa:
+ properties:
+ hibernate:
+ enable_lazy_load_no_trans: true
\ No newline at end of file
diff --git a/houserush/house-order/README.md b/houserush/house-order/README.md
new file mode 100644
index 0000000..1ed80b0
--- /dev/null
+++ b/houserush/house-order/README.md
@@ -0,0 +1,95 @@
+## 微服务 House-Order
+
+### 主要职责
+该微服务主要有4个职责
+1. 管理员用作开售活动的管理。
+2. 普通用户"**抢购**"房产。
+3. 管理员获取抢购活动的结果。
+4. 普通用户查询自己的抢购结果。
+
+### 主要设计考量
+1. 简单,抢购的核心接口只有1,2个,因为这部分后续需要优化性能,所以越简单,后续优化越容易。
+2. 第一版利用同步调用的方式,尽量不引入冗余数据,减少数据一致性的考量。
+
+### 后续改进的关注点 TODO list:
+1. 需要减少对其他微服务的同步调用,考虑引入异步的事务消息更新机制。提高抢购的性能。
+2. 可能会引入缓存系统,初步定为redis。
+3. 需要跨微服务事务机制,保证数据库的一致性。
+
+### 数据表设计
+
+主要有2张表:
+1. house_orders表,这张表既表示了待抢房源,也表示了抢购订单(抢购结果),差别在与customer_id列是否为null和state列的值。
+在开始抢购之前,customer_id为空,state为new, 记录这次开售活动有哪些房源参与销售。开售中和开售后记录抢购结果。
+即谁抢购到了该房产。
+2. sales表,表示开售活动,主要记录了开售活动的起止时间。sale has_many house_orders。表示这次开售
+活动有哪些房产可售。
+
+sales表:
+
+| column name | type | brief | description |
+| -------------- | ------------ | ------- | -------------- |
+| id | int | 主键 | |
+| state | varchar(20) | 订单状态 | new->published-> ongoing -> finished |
+| begin_at | timestamp | 开售活动开始时间 | |
+| end_at | timestamp | 开售活动结束时间 | |
+| realestate_id | int | 楼盘id | 一次开售活动只能针对同属一个楼盘的部分房源 |
+| deleted_at | timestamp | 开售活动删除时间 | 一次开售活动只有在未发布前可以进行删除或编辑,软删除方案 |
+
+
+house_orders表:
+
+| column name | type | 简介 | 更多说明 |
+| -------------- | ------------ | ------- | -------------- |
+| id | int | 主键 | |
+| sale_id | int | 外键:开售活动id | |
+| customer_id | int | 客户id | 记录了谁抢到了该房源,开售前为空 |
+| state | varchar(20) | 订单状态 | new 是待抢,confirmed是已抢 |
+| ordered_at | timestamp | 抢购时间 | state变为confirmed的时间 |
+
+### 接口设计
+
+
+##### 管理开售活动相关
+```java
+ @PostMapping("sales")
+ Sale createSale(@RequestBody Sale sale);
+
+ @GetMapping("sales/{saleId}")
+ Sale findSale(@PathVariable int saleId);
+ //获取开售活动详情。
+
+ @PutMapping("sales/{saleId}")
+ Sale Sale updateSale(@PathVariable int saleId, @RequestBody Sale sale);
+ //开售活动发布是通过该接口,一旦发布,不能再修改了,也不能删除。
+
+ @DeleteMapping("sales/{saleId}")
+ void removeSale(@PathVariable int saleId);
+
+ @GetMapping("sales")
+ List<Sale> indexSales();
+ //对客户列出客户有抢购资格的还未开始的开售活动,已开始时间排序;对管理员,列出所有的开售活动。
+
+ @PostMapping("sales/{saleId}/house_orders")
+ createHouseOrders(@PathVariable int saleId, @RequestBody List<Integer> houseIds);
+ //为开售活动创建房源,创建时需要检查这些房源是否已被其他开售活动锁定或售出。
+ //需要先对这些房源加锁后再添加到当前开售活动中,要注意事务的应用。
+
+```
+
+##### 执行抢购相关
+```java
+ @PutMapping("house_orders/{houseOrderId}")
+ HouseOrder placeHouseOrder(@RequestHeader int customerId, @PathVariable int houseOrderId)
+ //修改house_orders的customer_id列,抢购前需要检查该房源是否已被占用,
+ // select for update加锁,注意事务应用。
+ //
+```
+
+### 依赖其他微服务。
+1. find 和 index Sale的时候,需要调用realestate微服务的相关接口获取
+Sale关联楼盘的详细信息。
+2. createHouseOrders接口需要依赖realestate微服务查询房源状态和加锁,见接口说明。
+3. 依赖CustomerManage微服务,查询当前抢购的客户是否还有抢购的资格。
+
+
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderApplication.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderApplication.java
new file mode 100644
index 0000000..63a6875
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderApplication.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale;
+
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+@SpringBootApplication
+@EnableServiceComb
+@EnableJpaAuditing
+public class HouseOrderApplication {
+ public static void main(String[] args) {
+ configBeforeBoot();
+ SpringApplication.run(HouseOrderApplication.class, args);
+ }
+
+ private static void configBeforeBoot() {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+ RestObjectMapperFactory.getRestObjectMapper().setDateFormat(simpleDateFormat);
+ }
+}
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderConfig.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderConfig.java
new file mode 100644
index 0000000..f681976
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/HouseOrderConfig.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Configuration
+@EnableJpaRepositories(basePackages = "org.apache.servicecomb.samples.practise.houserush")
+public class HouseOrderConfig {
+}
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/HouseOrder.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/HouseOrder.java
new file mode 100644
index 0000000..3b8b863
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/HouseOrder.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Data
+@Entity
+@Table(name = "house_orders")
+@EntityListeners(AuditingEntityListener.class)
+public class HouseOrder {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "sale_id")
+ private Sale sale;
+
+ private Integer customerId;
+
+ private String state = "new";
+
+ private Integer houseId;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date orderedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date CreatedAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date UpdatedAt;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/Sale.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/Sale.java
new file mode 100644
index 0000000..a0ea966
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/aggregate/Sale.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.Where;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+@Entity
+@Table(name = "sales")
+@SQLDelete(sql = "update sales set deleted_at = now() where id = ?")
+@Where(clause = "deleted_at is null")
+@EntityListeners(AuditingEntityListener.class)
+public class Sale {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+
+ private String state = "new";
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date beginAt;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date endAt;
+
+ @JsonIgnore
+ @OneToMany(mappedBy = "sale")
+ private List<HouseOrder> houseOrders = new ArrayList<>();
+
+ private Integer realestateId;
+
+ @Transient
+ private String realestateName;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updatedAt;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApi.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApi.java
new file mode 100644
index 0000000..13207d9
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApi.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.api;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.HouseOrder;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.Sale;
+
+import java.util.List;
+
+public interface HouseOrderApi {
+ List<HouseOrder> createHouseOrders(int saleId, List<Integer> houseIds);
+
+ HouseOrder placeHouseOrder(int customerId, int houseOrderId);
+
+ Sale createSale(Sale sale);
+
+ Sale findSale(int saleId);
+
+ Sale updateSale(int saleId, Sale sale);
+
+ void removeSale(int saleId);
+
+ List<Sale> indexSales();
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApiRestImpl.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApiRestImpl.java
new file mode 100644
index 0000000..2a74fc5
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/api/HouseOrderApiRestImpl.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.api;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.HouseOrder;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.Sale;
+import org.apache.servicecomb.samples.practise.houserush.sale.service.HouseOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestSchema(schemaId = "houseOrderApiRest")
+@RequestMapping("/")
+public class HouseOrderApiRestImpl implements HouseOrderApi {
+ @Autowired
+ HouseOrderService houseOrderService;
+
+ @PostMapping("sales/{saleId}/house_orders")
+ public List<HouseOrder> createHouseOrders(@PathVariable int saleId, @RequestBody List<Integer> houseIds) {
+ return houseOrderService.createHouseOrders(saleId, houseIds);
+ }
+
+ @PutMapping("house_orders/{houseOrderId}")
+ public HouseOrder placeHouseOrder(@RequestHeader int customerId, @PathVariable int houseOrderId) {
+ return houseOrderService.placeHouseOrder(customerId, houseOrderId);
+ }
+
+ @Override
+ @PostMapping("sales")
+ public Sale createSale(@RequestBody Sale sale) {
+ return houseOrderService.createSale(sale);
+ }
+
+ @Override
+ @GetMapping("sales/{saleId}")
+ public Sale findSale(@PathVariable int saleId) {
+ return houseOrderService.findSale(saleId);
+ }
+
+ @Override
+ @PutMapping("sales/{saleId}")
+ public Sale updateSale(@PathVariable int saleId, @RequestBody Sale sale) {
+ sale.setId(saleId);
+ return houseOrderService.updateSale(sale);
+ }
+
+ @Override
+ @DeleteMapping("sales/{saleId}")
+ public void removeSale(@PathVariable int saleId) {
+ houseOrderService.removeSale(saleId);
+ }
+
+ @Override
+ @GetMapping("sales")
+ public List<Sale> indexSales() {
+ return houseOrderService.indexSales();
+ }
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/HouseOrderDao.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/HouseOrderDao.java
new file mode 100644
index 0000000..3e4bc2f
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/HouseOrderDao.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.HouseOrder;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.persistence.LockModeType;
+import java.util.List;
+
+public interface HouseOrderDao extends JpaRepository<HouseOrder, Integer> {
+ @Lock(LockModeType.PESSIMISTIC_WRITE)
+ @Query("SELECT ho FROM HouseOrder ho WHERE ho.sale.id = ?1 and ho.houseId in (?2)")
+ List<HouseOrder> findAllBySaleIdAndHouseIdInForUpdate(int saleId, List<Integer> ids);
+
+ @Lock(LockModeType.PESSIMISTIC_WRITE)
+ @Query("SELECT ho FROM HouseOrder ho WHERE ho.id = ?1")
+ HouseOrder findOneForUpdate(int id);
+
+ int countByCustomerIdAndSaleId(int customerId, int saleId);
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/SaleDao.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/SaleDao.java
new file mode 100644
index 0000000..99795ec
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/dao/SaleDao.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.Sale;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface SaleDao extends JpaRepository<Sale, Integer> {
+}
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/CustomerManageApi.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/CustomerManageApi.java
new file mode 100644
index 0000000..0b30523
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/CustomerManageApi.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.Customer;
+
+public interface CustomerManageApi {
+ Customer findCustomer(int customerId);
+
+ int getQualificationsCount(int customerId, int saleId);
+}
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/RealestateApi.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/RealestateApi.java
new file mode 100644
index 0000000..0ca5393
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/RealestateApi.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.House;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.Realestate;
+
+import java.util.List;
+
+public interface RealestateApi {
+ Realestate findRealestate(int id);
+
+ List<House> lockHousesForSale(List<Integer> ids);
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Customer.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Customer.java
new file mode 100644
index 0000000..d458315
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Customer.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc.po;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class Customer {
+ private int id;
+
+ private String phone;
+
+ private List<Qualification> qualifications;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/House.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/House.java
new file mode 100644
index 0000000..c122ef4
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/House.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc.po;
+
+import lombok.Data;
+
+@Data
+public class House {
+ private Integer id;
+
+ private String name;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Qualification.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Qualification.java
new file mode 100644
index 0000000..027ca72
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Qualification.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc.po;
+
+import lombok.Data;
+
+@Data
+public class Qualification {
+ private int id;
+
+ private Integer saleId;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Realestate.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Realestate.java
new file mode 100644
index 0000000..d7d3324
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/rpc/po/Realestate.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.rpc.po;
+
+import lombok.Data;
+
+@Data
+public class Realestate {
+ private int id;
+
+ private String name;
+}
\ No newline at end of file
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderService.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderService.java
new file mode 100644
index 0000000..3333de3
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.service;
+
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.HouseOrder;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.Sale;
+
+import java.util.List;
+
+public interface HouseOrderService {
+ List<HouseOrder> createHouseOrders(int saleId, List<Integer> houseIds);
+
+ HouseOrder placeHouseOrder(int customerId, int houseOrderId);
+
+ Sale createSale(Sale sale);
+
+ Sale findSale(int saleId);
+
+ Sale updateSale(Sale sale);
+
+ void removeSale(int saleId);
+
+ List<Sale> indexSales();
+}
diff --git a/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderServiceImpl.java b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderServiceImpl.java
new file mode 100644
index 0000000..e2dfd3c
--- /dev/null
+++ b/houserush/house-order/src/main/java/org/apache/servicecomb/samples/practise/houserush/sale/service/HouseOrderServiceImpl.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.sale.service;
+
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.HouseOrder;
+import org.apache.servicecomb.samples.practise.houserush.sale.aggregate.Sale;
+import org.apache.servicecomb.samples.practise.houserush.sale.dao.HouseOrderDao;
+import org.apache.servicecomb.samples.practise.houserush.sale.dao.SaleDao;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.CustomerManageApi;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.RealestateApi;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.Customer;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.House;
+import org.apache.servicecomb.samples.practise.houserush.sale.rpc.po.Realestate;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class HouseOrderServiceImpl implements HouseOrderService {
+ @Autowired
+ HouseOrderDao houseOrderDao;
+
+ @Autowired
+ SaleDao saleDao;
+
+ @RpcReference(microserviceName = "realestate", schemaId = "realestateApiRest")
+ private RealestateApi realestateApi;
+
+ @RpcReference(microserviceName = "customer-manage", schemaId = "customerManageApiRest")
+ private CustomerManageApi customerManageApi;
+
+ @Override
+ @Transactional
+ public List<HouseOrder> createHouseOrders(int saleId, List<Integer> houseIds) {
+ Sale sale = saleDao.findOne(saleId);
+ if (null == sale) {
+ throw new DataRetrievalFailureException("cannot create house for the non-existed sale.");
+ }
+
+ List<HouseOrder> houseOrders = houseOrderDao.findAllBySaleIdAndHouseIdInForUpdate(saleId, houseIds);
+ if (!houseOrders.isEmpty()) {
+ throw new InvocationException(400, "", "some house is already in this sale.");
+ }
+
+ List<House> houses = realestateApi.lockHousesForSale(houseIds);
+ List<HouseOrder> resHouseOrders = new ArrayList<>();
+ houses.forEach(house -> {
+ HouseOrder houseOrder = new HouseOrder();
+ houseOrder.setHouseId(house.getId());
+ houseOrder.setSale(sale);
+ houseOrderDao.save(houseOrder);
+ resHouseOrders.add(houseOrder);
+
+ });
+ return resHouseOrders;
+ }
+
+ @Override
+ @Transactional
+ public HouseOrder placeHouseOrder(int customerId, int houseOrderId) {
+ HouseOrder houseOrder = houseOrderDao.findOneForUpdate(houseOrderId);
+ Sale sale = houseOrder.getSale();
+
+ if (null != houseOrder) {
+ if (null == houseOrder.getCustomerId()) {
+ int qualificationsCount = customerManageApi.getQualificationsCount(customerId, sale.getId());
+
+ int ordersCount = houseOrderDao.countByCustomerIdAndSaleId(customerId, sale.getId());
+
+ if (qualificationsCount <= ordersCount) {
+ throw new InvocationException(400, "", "do not have the enough qualification to buy houses in this sale, " +
+ "the qualifications count is " + qualificationsCount + " , the order count is " + ordersCount);
+ }
+
+ houseOrder.setCustomerId(customerId);
+ houseOrder.setState("confirmed");
+ houseOrderDao.save(houseOrder);
+ return houseOrder;
+ } else {
+ throw new InvocationException(400, "", "this house have been occupied first by other customer, please choose another house or try it later.");
+ }
+ } else {
+ throw new InvocationException(400, "", "this house which you chose does not belong to the current sale.");
+ }
+ }
+
+ @Override
+ public Sale createSale(Sale sale) {
+ return saleDao.save(sale);
+ }
+
+ @Override
+ public Sale findSale(int saleId) {
+ Sale sale = saleDao.findOne(saleId);
+ Realestate realestate = realestateApi.findRealestate(sale.getRealestateId());
+ sale.setRealestateName(realestate.getName());
+ return sale;
+ }
+
+ @Override
+ @Transactional
+ public Sale updateSale(Sale sale) {
+ int id = sale.getId();
+ if (saleDao.exists(id)) {
+ return saleDao.save(sale);
+ } else {
+ throw new DataRetrievalFailureException("cannot update the none-existed sale");
+ }
+ }
+
+ @Override
+ public void removeSale(int saleId) {
+ saleDao.delete(saleId);
+ }
+
+ @Override
+ public List<Sale> indexSales() {
+ return saleDao.findAll();
+ }
+}
diff --git a/houserush/house-order/src/main/resources/microservice.yaml b/houserush/house-order/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..5aa426a
--- /dev/null
+++ b/houserush/house-order/src/main/resources/microservice.yaml
@@ -0,0 +1,48 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# all interconnected microservices must belong to an application wth the same ID
+APPLICATION_ID: houserush
+service_description:
+ # name of the declaring microservice
+ name: house-order
+ version: 0.0.6
+servicecomb:
+ service:
+ registry:
+ address: http://127.0.0.1:30100
+ instance:
+ watch: true
+ healthCheck:
+ interval: 5
+
+ rest:
+ address: 0.0.0.0:6788
+ handler:
+ chain:
+ Provider:
+ default: bizkeeper-provider
+spring:
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/house_order?characterEncoding=utf8&useSSL=false
+ username: root
+ password: root
+ jpa:
+ properties:
+ hibernate:
+ enable_lazy_load_no_trans: true
\ No newline at end of file
diff --git a/houserush/realestate/README.md b/houserush/realestate/README.md
new file mode 100644
index 0000000..18835e5
--- /dev/null
+++ b/houserush/realestate/README.md
@@ -0,0 +1,245 @@
+## 微服务 realestate
+
+该微服务用于楼盘及房源管理
+
+###快速开始
+
+1、参考[ServiceComb快速入门](http://servicecomb.apache.org/cn/docs/quick-start/)安装开发环境:
+
+- 安装git,详情可参考[git安装教程](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)。
+- 安装JDK 1.8,详情可参考[JDK安装教程](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html)。
+- 安装Maven 3.x, 详情可参考[Maven安装教程](https://maven.apache.org/install.html)。
+
+2、运行 Service Center
+
+- 安装Docker,详情可参考[Docker安装教程](https://www.docker.com/get-started)。
+- 命令行或终端输入<code>$ docker pull servicecomb/service-center</code>拉取最新版servicecomb/service-center。
+- 命令行或终端输入<code>$ docker run -d -p 30100:30100 servicecomb/service-center:latest</code>在30100端口运行service-center。
+
+3、参考下文的[数据表设计](#dbDisign)创建数据库表。
+
+4、配置realestate的数据库、服务中心地址以及启动端口
+
+- 修改src/main/resources/microservice.yaml文件:
+```yaml
+#...
+servicecomb:
+ service:
+ registry:
+ address: http://127.0.0.1:30100 #service-center地址
+ rest:
+ address: 0.0.0.0:7771 #微服务启动端口
+ #...
+spring:
+ #数据库url、用户名、密码配置
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/realestate?characterEncoding=utf8&useSSL=false
+ username: houserush
+ password: password
+ #...
+```
+5、启动微服务
+- 该微服务基于spring-boot开发,所以启动微服务只需要在微服务根目录下打开命令行或终端输入<code>$ mvn spring-boot:run</code>,或通过IDE启动spring-boot程序。
+
+### 主要功能
+
+- 楼盘的增删改查
+
+- 建筑楼的增删改查
+
+- 房源的增删改查
+
+- 锁定已售房源
+
+### 设计原理
+
+一个楼盘可能含多栋建筑楼,一栋建筑楼可能含多个房源
+
+### 数据表设计
+<span id = "dbDisign" />
+
+- realestates
+
+| 字段 | 类型 | 描述 |
+| :-------------- | ------------ | --------|
+| id | int | 主键id |
+| name | varchar(255) | 楼盘名称 |
+| description | varchar(2048)| 描述 |
+| deleted_at | timestamp | 删除时间 |
+| created_at | timestamp | 创建时间 |
+| update_at | timestamp | 更新时间 |
+
+- buildings
+
+| 字段 | 类型 | 描述 |
+| :--------------------- | ------------ | --------- |
+| id | int | 主键id |
+| realestate_id | int | 所在楼盘id |
+| name | varchar(255) | 建筑楼名称 |
+| sequence_in_realestate | tinyint | 栋 |
+| deleted_at | timestamp | 删除时间 |
+| created_at | timestamp | 创建时间 |
+| update_at | timestamp | 更新时间 |
+
+- houses
+
+| 字段 | 类型 | 描述 |
+| :---------------- | ------------ | --------- |
+| id | int | 主键id |
+| building_id | int | 所在建筑楼id |
+| name | varchar(255) | 房源名称 |
+| layer | int | 房源所在楼层 |
+| state | varchar(255) | 房源状态 |
+| sequence_in_layer | tinyint | 房间号 |
+| price | decimal | 价格 |
+| deleted_at | timestamp | 删除时间 |
+| created_at | timestamp | 创建时间 |
+| update_at | timestamp | 更新时间 |
+
+
+### 接口设计
+
+```java
+package org.apache.servicecomb.samples.practise.houserush.realestate.api;
+
+public interface RealestateApi {
+ /**
+ * 新增楼盘
+ * @param realestate 楼盘信息
+ * @return Realestate 添加成功后的楼盘信息
+ */
+ Realestate createRealestate(Realestate realestate);
+
+ /**
+ * 查询楼盘
+ * @param id 楼盘id
+ * @return Realestate 楼盘信息
+ */
+ Realestate findRealestate(int id);
+
+ /**
+ * 修改楼盘信息
+ * @param id 楼盘id
+ * @param realestate 楼盘信息
+ * @return Realestate 修改成功后的楼盘信息
+ */
+ Realestate updateRealestate(int id, Realestate realestate);
+
+ /**
+ * 删除楼盘
+ * @param id 楼盘id
+ */
+ void removeRealestate(int id);
+
+ /**
+ * 查询所有楼盘
+ * @return List<Realestate> 所有楼盘列表
+ */
+ List<Realestate> indexRealestates();
+
+ /**
+ * 新增建筑楼
+ * @param realestateId 楼盘id
+ * @param building 建筑楼信息
+ * @return Building 添加成功后的建筑楼信息
+ */
+ Building createBuilding(int realestateId, Building building);
+
+ /**
+ * 查询建筑楼
+ * @param id 建筑楼id
+ * @return Building 建筑楼信息
+ */
+ Building findBuilding(int id);
+
+ /**
+ * 更改建筑楼信息
+ * @param id 建筑楼id
+ * @param building 建筑楼信息
+ * @return Building 更改成功后的建筑楼信息
+ */
+ Building updateBuilding(int id, Building building);
+
+ /**
+ * 删除建筑楼
+ * @param id 建筑楼id
+ */
+ void removeBuilding(int id);
+
+ /**
+ * 查询某一楼盘下的所有建筑楼
+ * @param realestateId 楼盘id
+ * @return List<Building> 建筑楼列表
+ */
+ List<Building> indexBuildings(int realestateId);
+
+ /**
+ * 新增房源信息
+ * @param buidingId 建筑楼id
+ * @param house 房源信息
+ * @return House 添加成功后的房源信息
+ */
+ House createHouse(int buidingId, House house);
+
+ /**
+ * 查询房源信息
+ * @param id 房源id
+ * @return House 房源信息
+ */
+ House findHouse(int id);
+
+ /**
+ * 更改房源信息
+ * @param id 房源id
+ * @param house 房源信息
+ * @return House 更改成功后的房源信息
+ */
+ House updateHouse(int id, House house);
+
+ /**
+ * 删除房源信息
+ * @param id 房源id
+ */
+ void removeHouse(int id);
+
+ /**
+ * 查询某一建筑楼下的所有房源
+ * @param buildingId 建筑楼id
+ * @return List<House> 所有房源列表
+ */
+ List<House> indexHouses(int buildingId);
+
+ /**
+ * 锁定已售房源
+ * @param ids 已售房源id列表
+ * @return List<House> 锁定的房源列表
+ */
+ List<House> lockHousesForSale(List<Integer> ids);
+}
+```
+
+### Rest API调用示例
+点击[houserush-realestate Rest API文档](https://documenter.getpostman.com/view/5023270/SVYkwMZd?version=latest)查看Rest API调用示例。
+
+- 注意:示例中是通过Gateway网关服务调用的Realestate服务,所以示例调用接口较org.apache.servicecomb.samples.practise.houserush.realestate.api.RealestateApiRestImpl中声明的接口多含一个前缀/realestate.
+- 鉴权操作、获取用户Token操作请移步[houserush-gateway服务文档](https://github.com/apache/servicecomb-samples/tree/master/houserush/gateway)
+
+### 源码文件解析
+
+```yaml
+src/main:
+ /java: java源码文件所在目录
+ org.apache.servicecomb.samples.practise.houserush.realestate:
+ .aggregate: 项目实体类所在包,其中Building、House、Realestate类为JPA实体
+ .api: Rest接口定义及实现包
+ .RealestateApi: 接口定义
+ .RealestateApiRestImpl: 接口实现
+ .dao: 数据访问对象所在包,其中数据库操作都是Spring-Data-JPA实现
+ .service: 各种增删改查具体逻辑实现
+ .RealestateConfig: 微服务配置类
+ .RealestateApplication: 微服务启动类
+ /resources: 项目资源文件所在目录
+ /microservice.yaml: 微服务配置文件,其中关键内容在上文"快速开始"中已经提及。
+pom.xml: maven配置文件
+
+```
\ No newline at end of file
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateApplication.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateApplication.java
new file mode 100644
index 0000000..0cfb114
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateApplication.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate;
+
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+@SpringBootApplication
+@EnableServiceComb
+public class RealestateApplication {
+
+ public static void main(String[] args) {
+ configBeforeBoot();
+ SpringApplication.run(RealestateApplication.class, args);
+ }
+
+ private static void configBeforeBoot() {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+ RestObjectMapperFactory.getRestObjectMapper().setDateFormat(simpleDateFormat);
+ }
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateConfig.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateConfig.java
new file mode 100644
index 0000000..b4136ae
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/RealestateConfig.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Configuration
+@EnableJpaRepositories(basePackages = "org.apache.servicecomb.samples.practise.houserush")
+public class RealestateConfig {
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Building.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Building.java
new file mode 100644
index 0000000..1c0a0c9
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Building.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.Where;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+@Entity
+@Table(name = "buildings")
+@SQLDelete(sql = "update buildings set deleted_at = now() where id = ?")
+@Where(clause = "deleted_at is null")
+public class Building {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "realestate_id")
+ private Realestate realestate;
+
+ @JsonIgnore
+ @OneToMany(mappedBy = "building")
+ private List<House> houses = new ArrayList<>();
+
+ private String name;
+
+ private Integer sequenceInRealestate;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updatedAt;
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/House.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/House.java
new file mode 100644
index 0000000..3c47904
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/House.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.aggregate;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.Where;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import javax.persistence.*;
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@Entity
+@Table(name = "houses")
+@SQLDelete(sql = "update houses set deleted_at = now() where id = ?")
+@Where(clause = "deleted_at is null")
+public class House {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "building_id")
+ private Building building;
+
+ private String name;
+
+ private Integer layer;
+
+ private String state;
+
+ private Integer sequenceInLayer;
+
+ private BigDecimal price;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updatedAt;
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Realestate.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Realestate.java
new file mode 100644
index 0000000..f936ade
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/aggregate/Realestate.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.aggregate;
+
+import lombok.Data;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.Where;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+@Entity
+@Table(name = "realestates")
+@SQLDelete(sql = "update realestates set deleted_at = now() where id = ?")
+@Where(clause = "deleted_at is null")
+public class Realestate {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @OneToMany(mappedBy = "realestate")
+ private List<Building> buildings = new ArrayList<>();
+
+ private String name;
+
+ private String description;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date deletedAt;
+
+ @CreatedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date createdAt;
+
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updatedAt;
+
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApi.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApi.java
new file mode 100644
index 0000000..ccef9c9
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApi.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.api;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Building;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.House;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Realestate;
+
+import java.util.List;
+
+public interface RealestateApi {
+ /**
+ * 新增楼盘
+ *
+ * @param realestate 楼盘信息
+ * @return Realestate 添加成功后的楼盘信息
+ */
+ Realestate createRealestate(Realestate realestate);
+
+ /**
+ * 查询楼盘
+ *
+ * @param id 楼盘id
+ * @return Realestate 楼盘信息
+ */
+ Realestate findRealestate(int id);
+
+ /**
+ * 修改楼盘信息
+ *
+ * @param id 楼盘id
+ * @param realestate 楼盘信息
+ * @return Realestate 修改成功后的楼盘信息
+ */
+ Realestate updateRealestate(int id, Realestate realestate);
+
+ /**
+ * 删除楼盘
+ *
+ * @param id 楼盘id
+ */
+ void removeRealestate(int id);
+
+ /**
+ * 查询所有楼盘
+ *
+ * @return List<Realestate> 所有楼盘列表
+ */
+ List<Realestate> indexRealestates();
+
+ /**
+ * 新增建筑楼
+ *
+ * @param realestateId 楼盘id
+ * @param building 建筑楼信息
+ * @return Building 添加成功后的建筑楼信息
+ */
+ Building createBuilding(int realestateId, Building building);
+
+ /**
+ * 查询建筑楼
+ *
+ * @param id 建筑楼id
+ * @return Building 建筑楼信息
+ */
+ Building findBuilding(int id);
+
+ /**
+ * 更改建筑楼信息
+ *
+ * @param id 建筑楼id
+ * @param building 建筑楼信息
+ * @return Building 更改成功后的建筑楼信息
+ */
+ Building updateBuilding(int id, Building building);
+
+ /**
+ * 删除建筑楼
+ *
+ * @param id 建筑楼id
+ */
+ void removeBuilding(int id);
+
+ /**
+ * 查询某一楼盘下的所有建筑楼
+ *
+ * @param realestateId 楼盘id
+ * @return List<Building> 建筑楼列表
+ */
+ List<Building> indexBuildings(int realestateId);
+
+ /**
+ * 新增房源信息
+ *
+ * @param buidingId 建筑楼id
+ * @param house 房源信息
+ * @return House 添加成功后的房源信息
+ */
+ House createHouse(int buidingId, House house);
+
+ /**
+ * 查询房源信息
+ *
+ * @param id 房源id
+ * @return House 房源信息
+ */
+ House findHouse(int id);
+
+ /**
+ * 更改房源信息
+ *
+ * @param id 房源id
+ * @param house 房源信息
+ * @return House 更改成功后的房源信息
+ */
+ House updateHouse(int id, House house);
+
+ /**
+ * 删除房源信息
+ *
+ * @param id 房源id
+ */
+ void removeHouse(int id);
+
+ /**
+ * 查询某一建筑楼下的所有房源
+ *
+ * @param buildingId 建筑楼id
+ * @return List<House> 所有房源列表
+ */
+ List<House> indexHouses(int buildingId);
+
+ /**
+ * 锁定已售房源
+ *
+ * @param ids 已售房源id列表
+ * @return List<House> 锁定的房源列表
+ */
+ List<House> lockHousesForSale(List<Integer> ids);
+}
\ No newline at end of file
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApiRestImpl.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApiRestImpl.java
new file mode 100644
index 0000000..482ead8
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/api/RealestateApiRestImpl.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.api;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Building;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.House;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Realestate;
+import org.apache.servicecomb.samples.practise.houserush.realestate.service.RealestateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestSchema(schemaId = "realestateApiRest")
+@RequestMapping("/")
+public class RealestateApiRestImpl implements RealestateApi {
+
+ @Autowired
+ private RealestateService realestateService;
+
+
+ @PostMapping("/realestates")
+ public Realestate createRealestate(@RequestBody Realestate realestate) {
+ return realestateService.createRealesate(realestate);
+ }
+
+ @GetMapping("/realestates/{id}")
+ public Realestate findRealestate(@PathVariable("id") int id) {
+ return realestateService.findRealestate(id);
+ }
+
+ @PutMapping("realestates/{id}")
+ public Realestate updateRealestate(@PathVariable("id") int id, @RequestBody Realestate realestate) {
+ realestate.setId(id);
+ return realestateService.updateRealestate(realestate);
+ }
+
+ @DeleteMapping("realestates/{id}")
+ public void removeRealestate(@PathVariable("id") int id) {
+ realestateService.removeRealestate(id);
+ }
+
+ @GetMapping("realestates")
+ public List<Realestate> indexRealestates() {
+ return realestateService.indexRealestates();
+ }
+
+ @PostMapping("realestates/{realestateId}/buildings")
+ public Building createBuilding(@PathVariable("realestateId") int realestateId, Building building) {
+ return realestateService.createBuilding(realestateId, building);
+ }
+
+ @GetMapping("buildings/{id}")
+ public Building findBuilding(@PathVariable("id") int id) {
+ return realestateService.findBuilding(id);
+ }
+
+ @PutMapping("buildings/{id}")
+ public Building updateBuilding(@PathVariable("id") int id, @RequestBody Building building) {
+ building.setId(id);
+ return realestateService.updateBuilding(building);
+ }
+
+ @DeleteMapping("buildings/{id}")
+ public void removeBuilding(@PathVariable("id") int id) {
+ realestateService.removeBuilding(id);
+ }
+
+ @GetMapping("realestates/{realestateId}/buildings")
+ public List<Building> indexBuildings(@PathVariable("realestateId") int realestateId) {
+ return realestateService.indexBuildings(realestateId);
+ }
+
+ @PostMapping("buildings/{buildingId}/houses")
+ public House createHouse(@PathVariable("buildingId") int buildingId, House house) {
+ return realestateService.createHouse(buildingId, house);
+ }
+
+ @GetMapping("houses/{id}")
+ public House findHouse(@PathVariable("id") int id) {
+ return realestateService.findHouse(id);
+ }
+
+ @PutMapping("houses/{id}")
+ public House updateHouse(@PathVariable("id") int id, House house) {
+ house.setId(id);
+ return realestateService.updateHouse(house);
+ }
+
+ @DeleteMapping("houses/{id}")
+ public void removeHouse(@PathVariable("id") int id) {
+ realestateService.removeHouse(id);
+ }
+
+ @GetMapping("buildings/{buildingId}/houses")
+ public List<House> indexHouses(@PathVariable("buildingId") int buildingId) {
+ return realestateService.indexHouses(buildingId);
+ }
+
+ @PutMapping("houses/lock_houses_for_sale")
+ public List<House> lockHousesForSale(@RequestBody List<Integer> ids) {
+ return realestateService.lockHousesForSale(ids);
+ }
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/BuildingDao.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/BuildingDao.java
new file mode 100644
index 0000000..f728fdc
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/BuildingDao.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Building;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface BuildingDao extends JpaRepository<Building, Integer> {
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDao.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDao.java
new file mode 100644
index 0000000..93b6940
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDao.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.House;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.persistence.LockModeType;
+import java.util.List;
+
+public interface HouseDao extends JpaRepository<House, Integer>, HouseDaoMore {
+ @Lock(LockModeType.PESSIMISTIC_WRITE)
+ @Query("SELECT h FROM House h WHERE h.id in (?1)")
+ List<House> findAllByIdInForUpdate(List<Integer> ids);
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoImpl.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoImpl.java
new file mode 100644
index 0000000..aec75b3
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoImpl.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.dao;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.util.List;
+
+public class HouseDaoImpl implements HouseDaoMore {
+ @PersistenceContext
+ private EntityManager em;
+
+ @Override
+ public int updateLockingStatesForHouses(List<Integer> ids) {
+ return em.createQuery("UPDATE House h set h.state = 'locking' where h.id in (?1)").setParameter(1, ids).executeUpdate();
+ }
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoMore.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoMore.java
new file mode 100644
index 0000000..6b82347
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/HouseDaoMore.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.dao;
+
+import java.util.List;
+
+public interface HouseDaoMore {
+ int updateLockingStatesForHouses(List<Integer> ids);
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/RealestateDao.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/RealestateDao.java
new file mode 100644
index 0000000..2df74e3
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/dao/RealestateDao.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.dao;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Realestate;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface RealestateDao extends JpaRepository<Realestate, Integer> {
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateService.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateService.java
new file mode 100644
index 0000000..525a797
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateService.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.service;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Building;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.House;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Realestate;
+
+import java.util.List;
+
+public interface RealestateService {
+ Realestate createRealesate(Realestate realestate);
+
+ Realestate findRealestate(Integer id);
+
+ Realestate updateRealestate(Realestate realestate);
+
+ void removeRealestate(Integer id);
+
+ List<Realestate> indexRealestates();
+
+ Building createBuilding(Integer realestateId, Building building);
+
+ Building findBuilding(Integer id);
+
+ Building updateBuilding(Building building);
+
+ void removeBuilding(Integer id);
+
+ List<Building> indexBuildings(Integer realestateId);
+
+ House createHouse(Integer buildingId, House house);
+
+ House findHouse(Integer id);
+
+ House updateHouse(House house);
+
+ void removeHouse(Integer id);
+
+ List<House> indexHouses(Integer buildingId);
+
+ List<House> lockHousesForSale(List<Integer> houseIds);
+
+}
diff --git a/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateServiceImpl.java b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateServiceImpl.java
new file mode 100644
index 0000000..85e5ccf
--- /dev/null
+++ b/houserush/realestate/src/main/java/org/apache/servicecomb/samples/practise/houserush/realestate/service/RealestateServiceImpl.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.realestate.service;
+
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Building;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.House;
+import org.apache.servicecomb.samples.practise.houserush.realestate.aggregate.Realestate;
+import org.apache.servicecomb.samples.practise.houserush.realestate.dao.BuildingDao;
+import org.apache.servicecomb.samples.practise.houserush.realestate.dao.HouseDao;
+import org.apache.servicecomb.samples.practise.houserush.realestate.dao.RealestateDao;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+public class RealestateServiceImpl implements RealestateService {
+ @Autowired
+ private RealestateDao realestateDao;
+
+ @Autowired
+ private BuildingDao buildingDao;
+
+ @Autowired
+ private HouseDao houseDao;
+
+ @Override
+ public Realestate createRealesate(Realestate realestate) {
+ return realestateDao.save(realestate);
+ }
+
+ @Override
+ public Realestate findRealestate(Integer id) {
+ return realestateDao.findOne(id);
+ }
+
+ @Override
+ @Transactional
+ public Realestate updateRealestate(Realestate realestate) {
+ int id = realestate.getId();
+ if (realestateDao.exists(id)) {
+ return realestateDao.save(realestate);
+ } else {
+ throw new DataRetrievalFailureException("cannot update the non-existed realestate");
+ }
+ }
+
+ @Override
+ public void removeRealestate(Integer id) {
+ realestateDao.delete(id);
+ }
+
+ @Override
+ public List<Realestate> indexRealestates() {
+ return realestateDao.findAll();
+ }
+
+ @Override
+ public Building createBuilding(Integer realestateId, Building building) {
+ Realestate realestate = realestateDao.findOne(realestateId);
+ if (null == realestate) {
+ throw new DataRetrievalFailureException("cannot create buildings for" +
+ " the not-existed realestate");
+ } else {
+ building.setRealestate(realestate);
+ return buildingDao.save(building);
+ }
+ }
+
+ @Override
+ public Building findBuilding(Integer id) {
+ return buildingDao.findOne(id);
+ }
+
+ @Override
+ @Transactional
+ public Building updateBuilding(Building building) {
+ int id = building.getId();
+ if (buildingDao.exists(id)) {
+ return buildingDao.save(building);
+ } else {
+ throw new DataRetrievalFailureException("cannot update the non-existed building");
+ }
+ }
+
+ @Override
+ @Transactional
+ public void removeBuilding(Integer id) {
+ buildingDao.delete(id);
+ }
+
+ @Override
+ public List<Building> indexBuildings(Integer realestateId) {
+ Realestate realestate = realestateDao.findOne(realestateId);
+ return realestate.getBuildings();
+ }
+
+ @Override
+ public House createHouse(Integer buildingId, House house) {
+ Building building = buildingDao.findOne(buildingId);
+ if (building != null) {
+ house.setBuilding(building);
+ return houseDao.save(house);
+ } else {
+ throw new DataRetrievalFailureException("cannot create house for the non-existed building");
+ }
+ }
+
+ @Override
+ public House findHouse(Integer id) {
+ return houseDao.findOne(id);
+ }
+
+ @Override
+ public House updateHouse(House house) {
+ int id = house.getId();
+ if (houseDao.exists(id)) {
+ return houseDao.save(house);
+ } else {
+ throw new DataRetrievalFailureException("cannot update the non-existed house");
+ }
+ }
+
+ @Override
+ public void removeHouse(Integer id) {
+ houseDao.delete(id);
+ }
+
+ @Override
+ public List<House> indexHouses(Integer buildingId) {
+ Building building = buildingDao.findOne(buildingId);
+ if (building != null) {
+ return building.getHouses();
+ } else {
+ throw new DataRetrievalFailureException("cannot index the houses for the non-existed building");
+ }
+ }
+
+ @Override
+ @Transactional
+ public List<House> lockHousesForSale(List<Integer> houseIds) {
+ List<House> houses = houseDao.findAllByIdInForUpdate(houseIds);
+ houses.forEach(house -> {
+ if (!"in_stock".equals(house.getState())) {
+ throw new InvocationException(400, "", "house " + house.getId() + " is not in_stock.");
+ }
+ });
+ houseDao.updateLockingStatesForHouses(houseIds);
+ return houses;
+ }
+}
diff --git a/houserush/realestate/src/main/resources/microservice.yaml b/houserush/realestate/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..5b20894
--- /dev/null
+++ b/houserush/realestate/src/main/resources/microservice.yaml
@@ -0,0 +1,43 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# all interconnected microservices must belong to an application wth the same ID
+APPLICATION_ID: houserush
+service_description:
+ # name of the declaring microservice
+ name: realestate
+ version: 0.0.11
+servicecomb:
+ service:
+ registry:
+ address: http://127.0.0.1:30100
+ rest:
+ address: 0.0.0.0:7771
+ handler:
+ chain:
+ Provider:
+ default: bizkeeper-provider
+spring:
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/realestate?characterEncoding=utf8&useSSL=false
+ username: root
+ password: root
+ jpa:
+ properties:
+ hibernate:
+ enable_lazy_load_no_trans: true
\ No newline at end of file
diff --git a/houserush/user-center/pom.xml b/houserush/user-center/pom.xml
index 52dc4f6..016e5be 100644
--- a/houserush/user-center/pom.xml
+++ b/houserush/user-center/pom.xml
@@ -17,12 +17,14 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
<parent>
<artifactId>houserush</artifactId>
<groupId>org.apache.servicecomb.samples.practice</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
+
<modelVersion>4.0.0</modelVersion>
<artifactId>houserush-user-center</artifactId>
@@ -59,5 +61,4 @@
</plugin>
</plugins>
</build>
-
</project>
diff --git a/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterApplication.java b/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterApplication.java
new file mode 100644
index 0000000..edff407
--- /dev/null
+++ b/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterApplication.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.user.center;
+
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+@SpringBootApplication
+@EnableServiceComb
+public class UserCenterApplication {
+
+ public static void main(String[] args) {
+ configBeforeBoot();
+ SpringApplication.run(UserCenterApplication.class, args);
+ }
+
+ private static void configBeforeBoot() {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+ RestObjectMapperFactory.getRestObjectMapper().setDateFormat(simpleDateFormat);
+ }
+}
diff --git a/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterConfig.java b/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterConfig.java
new file mode 100644
index 0000000..e9ae84c
--- /dev/null
+++ b/houserush/user-center/src/main/java/org/apache/servicecomb/samples/practise/houserush/user/center/UserCenterConfig.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.samples.practise.houserush.user.center;
+
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class UserCenterConfig {
+}
diff --git a/houserush/user-center/src/main/resources/microservice.yaml b/houserush/user-center/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..e568ad2
--- /dev/null
+++ b/houserush/user-center/src/main/resources/microservice.yaml
@@ -0,0 +1,34 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# all interconnected microservices must belong to an application wth the same ID
+APPLICATION_ID: houserush
+service_description:
+# name of the declaring microservice
+ name: user-center
+ version: 0.0.2
+servicecomb:
+ service:
+ registry:
+ address: http://192.168.229.134:30100
+ rest:
+ address: 0.0.0.0:6877
+ handler:
+ chain:
+ Provider:
+ default: bizkeeper-provider
\ No newline at end of file