Skip to content

Commit 809af2e

Browse files
author
wuxw7
committed
评论模型设计完成
1 parent 8d34f35 commit 809af2e

18 files changed

Lines changed: 2239 additions & 0 deletions

CommentService/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>MicroCommunity</artifactId>
7+
<groupId>com.java110</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>CommentService</artifactId>
13+
14+
<name>CommentService</name>
15+
<!-- FIXME change it to the project's website -->
16+
<url>http://www.example.com</url>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.java110</groupId>
25+
<artifactId>java110-service</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.java110</groupId>
29+
<artifactId>java110-event</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<finalName>CommentService</finalName>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-dependency-plugin</artifactId>
39+
<version>2.10</version>
40+
<executions>
41+
<execution>
42+
<id>unpack</id>
43+
<phase>generate-resources</phase>
44+
<goals>
45+
<goal>unpack</goal>
46+
</goals>
47+
<configuration>
48+
<artifactItems>
49+
<artifactItem>
50+
<groupId>com.java110</groupId>
51+
<artifactId>java110-config</artifactId>
52+
<version>${microcommunity.version}</version>
53+
<type>jar</type>
54+
<overWrite>true</overWrite>
55+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
56+
</artifactItem>
57+
</artifactItems>
58+
</configuration>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-maven-plugin</artifactId>
65+
<configuration>
66+
<mainClass>com.java110.comment.CommentServiceApplicationStart</mainClass>
67+
</configuration>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.java110.comment;
2+
3+
import com.java110.core.annotation.Java110ListenerDiscovery;
4+
import com.java110.event.service.BusinessServiceDataFlowEventPublishing;
5+
import com.java110.service.init.ServiceStartInit;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.boot.web.client.RestTemplateBuilder;
9+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10+
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
11+
import org.springframework.context.ApplicationContext;
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.http.converter.StringHttpMessageConverter;
14+
import org.springframework.web.client.RestTemplate;
15+
16+
import java.nio.charset.Charset;
17+
18+
19+
/**
20+
* spring boot 初始化启动类
21+
*
22+
* @version v0.1
23+
* @auther com.java110.wuxw
24+
* @mail 928255095@qq.com
25+
* @date 2016年8月6日
26+
* @tag
27+
*/
28+
@SpringBootApplication(scanBasePackages={"com.java110.service","com.java110.comment","com.java110.core","com.java110.cache"})
29+
@EnableDiscoveryClient
30+
@Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class,
31+
basePackages = {"com.java110.comment.listener"})
32+
public class CommentServiceApplicationStart {
33+
34+
35+
/**
36+
* 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
37+
* @return restTemplate
38+
*/
39+
@Bean
40+
@LoadBalanced
41+
public RestTemplate restTemplate() {
42+
StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
43+
RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
44+
return restTemplate;
45+
}
46+
47+
public static void main(String[] args) throws Exception{
48+
ApplicationContext context = SpringApplication.run(CommentServiceApplicationStart.class, args);
49+
ServiceStartInit.initSystemConfig(context);
50+
}
51+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.java110.comment.api;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.java110.comment.smo.ICommentServiceSMO;
5+
import com.java110.common.constant.ResponseConstant;
6+
import com.java110.common.exception.InitConfigDataException;
7+
import com.java110.common.exception.InitDataFlowContextException;
8+
import com.java110.core.base.controller.BaseController;
9+
import com.java110.core.context.BusinessServiceDataFlow;
10+
import com.java110.core.factory.DataTransactionFactory;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.web.bind.annotation.RequestBody;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RequestMethod;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
import javax.servlet.http.HttpServletRequest;
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
21+
/**
22+
* 用户服务类
23+
* Created by wuxw on 2018/5/14.
24+
*/
25+
@RestController
26+
public class CommentApi extends BaseController {
27+
28+
@Autowired
29+
ICommentServiceSMO commentServiceSMOImpl;
30+
31+
@RequestMapping(path = "/commentApi/service",method= RequestMethod.GET)
32+
public String serviceGet(HttpServletRequest request) {
33+
return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,"不支持Get方法请求").toJSONString();
34+
}
35+
36+
/**
37+
* 用户服务统一处理接口
38+
* @param orderInfo
39+
* @param request
40+
* @return
41+
*/
42+
@RequestMapping(path = "/commentApi/service",method= RequestMethod.POST)
43+
public String servicePost(@RequestBody String orderInfo, HttpServletRequest request) {
44+
BusinessServiceDataFlow businessServiceDataFlow = null;
45+
JSONObject responseJson = null;
46+
try {
47+
Map<String, String> headers = new HashMap<String, String>();
48+
getRequestInfo(request, headers);
49+
//预校验
50+
preValiateOrderInfo(orderInfo);
51+
businessServiceDataFlow = this.writeDataToDataFlowContext(orderInfo, headers);
52+
responseJson = commentServiceSMOImpl.service(businessServiceDataFlow);
53+
}catch (InitDataFlowContextException e){
54+
logger.error("请求报文错误,初始化 BusinessServiceDataFlow失败"+orderInfo,e);
55+
responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo,ResponseConstant.RESULT_PARAM_ERROR,e.getMessage(),null);
56+
}catch (InitConfigDataException e){
57+
logger.error("请求报文错误,加载配置信息失败"+orderInfo,e);
58+
responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo,ResponseConstant.RESULT_PARAM_ERROR,e.getMessage(),null);
59+
}catch (Exception e){
60+
logger.error("请求订单异常",e);
61+
responseJson = DataTransactionFactory.createBusinessResponseJson(businessServiceDataFlow,ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e,
62+
null);
63+
}finally {
64+
return responseJson.toJSONString();
65+
}
66+
}
67+
68+
/**
69+
* 这里预校验,请求报文中不能有 dataFlowId
70+
* @param orderInfo
71+
*/
72+
private void preValiateOrderInfo(String orderInfo) {
73+
/* if(JSONObject.parseObject(orderInfo).getJSONObject("orders").containsKey("dataFlowId")){
74+
throw new BusinessException(ResponseConstant.RESULT_CODE_ERROR,"报文中不能存在dataFlowId节点");
75+
}*/
76+
}
77+
78+
/**
79+
* 获取请求信息
80+
* @param request
81+
* @param headers
82+
* @throws RuntimeException
83+
*/
84+
private void getRequestInfo(HttpServletRequest request,Map headers) throws Exception{
85+
try{
86+
super.initHeadParam(request,headers);
87+
super.initUrlParam(request,headers);
88+
}catch (Exception e){
89+
logger.error("加载头信息失败",e);
90+
throw new InitConfigDataException(ResponseConstant.RESULT_PARAM_ERROR,"加载头信息失败");
91+
}
92+
}
93+
94+
public ICommentServiceSMO getCommentServiceSMOImpl() {
95+
return commentServiceSMOImpl;
96+
}
97+
98+
public void setCommentServiceSMOImpl(ICommentServiceSMO commentServiceSMOImpl) {
99+
this.commentServiceSMOImpl = commentServiceSMOImpl;
100+
}
101+
}

0 commit comments

Comments
 (0)