mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
format code
This commit is contained in:
parent
67c559853a
commit
655f752e12
@ -35,29 +35,5 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<pluginManagement>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</pluginManagement>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
|
||||||
<inherited>false</inherited>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
<check/>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
@ -51,7 +51,8 @@ public class DatabaseConfiguration {
|
|||||||
String password = env.getProperty("mysql.user.password");
|
String password = env.getProperty("mysql.user.password");
|
||||||
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
DruidDataSource druidDataSource = new DruidDataSource();
|
||||||
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
druidDataSource.setUrl(
|
||||||
|
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||||
druidDataSource.setUsername(userName);
|
druidDataSource.setUsername(userName);
|
||||||
druidDataSource.setPassword(password);
|
druidDataSource.setPassword(password);
|
||||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
@ -46,86 +46,86 @@ import java.util.Random;
|
|||||||
@RestController
|
@RestController
|
||||||
public class OrderController {
|
public class OrderController {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
||||||
private static final String SUCCESS = "SUCCESS";
|
private static final String SUCCESS = "SUCCESS";
|
||||||
private static final String FAIL = "FAIL";
|
private static final String FAIL = "FAIL";
|
||||||
private static final String USER_ID = "U100001";
|
private static final String USER_ID = "U100001";
|
||||||
private static final String COMMODITY_CODE = "C00321";
|
private static final String COMMODITY_CODE = "C00321";
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) {
|
public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/order", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "/order", method = RequestMethod.POST, produces = "application/json")
|
||||||
public String order(String userId, String commodityCode, int orderCount) {
|
public String order(String userId, String commodityCode, int orderCount) {
|
||||||
LOGGER.info("Order Service Begin ... xid: " + RootContext.getXID());
|
LOGGER.info("Order Service Begin ... xid: " + RootContext.getXID());
|
||||||
|
|
||||||
int orderMoney = calculate(commodityCode, orderCount);
|
int orderMoney = calculate(commodityCode, orderCount);
|
||||||
|
|
||||||
invokerAccountService(orderMoney);
|
invokerAccountService(orderMoney);
|
||||||
|
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.userId = userId;
|
order.userId = userId;
|
||||||
order.commodityCode = commodityCode;
|
order.commodityCode = commodityCode;
|
||||||
order.count = orderCount;
|
order.count = orderCount;
|
||||||
order.money = orderMoney;
|
order.money = orderMoney;
|
||||||
|
|
||||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||||
|
|
||||||
int result = jdbcTemplate.update(new PreparedStatementCreator() {
|
int result = jdbcTemplate.update(new PreparedStatementCreator() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement createPreparedStatement(Connection con)
|
public PreparedStatement createPreparedStatement(Connection con)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
PreparedStatement pst = con.prepareStatement(
|
PreparedStatement pst = con.prepareStatement(
|
||||||
"insert into order_tbl (user_id, commodity_code, count, money) values (?, ?, ?, ?)",
|
"insert into order_tbl (user_id, commodity_code, count, money) values (?, ?, ?, ?)",
|
||||||
PreparedStatement.RETURN_GENERATED_KEYS);
|
PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
pst.setObject(1, order.userId);
|
pst.setObject(1, order.userId);
|
||||||
pst.setObject(2, order.commodityCode);
|
pst.setObject(2, order.commodityCode);
|
||||||
pst.setObject(3, order.count);
|
pst.setObject(3, order.count);
|
||||||
pst.setObject(4, order.money);
|
pst.setObject(4, order.money);
|
||||||
return pst;
|
return pst;
|
||||||
}
|
}
|
||||||
}, keyHolder);
|
}, keyHolder);
|
||||||
|
|
||||||
order.id = keyHolder.getKey().longValue();
|
order.id = keyHolder.getKey().longValue();
|
||||||
|
|
||||||
// if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
// throw new RuntimeException("this is a mock Exception");
|
throw new RuntimeException("this is a mock Exception");
|
||||||
// }
|
}
|
||||||
|
|
||||||
LOGGER.info("Order Service End ... Created " + order);
|
LOGGER.info("Order Service End ... Created " + order);
|
||||||
|
|
||||||
if (result == 1) {
|
if (result == 1) {
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculate(String commodityId, int orderCount) {
|
private int calculate(String commodityId, int orderCount) {
|
||||||
return 2 * orderCount;
|
return 2 * orderCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokerAccountService(int orderMoney) {
|
private void invokerAccountService(int orderMoney) {
|
||||||
String url = "http://127.0.0.1:18084/account";
|
String url = "http://127.0.0.1:18084/account";
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
|
||||||
map.add("userId", USER_ID);
|
map.add("userId", USER_ID);
|
||||||
map.add("money", orderMoney + "");
|
map.add("money", orderMoney + "");
|
||||||
|
|
||||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
|
||||||
map, headers);
|
map, headers);
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
|
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
|
||||||
String.class);
|
String.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package org.springframework.cloud.alicloud.acm.bootstrap;
|
|||||||
|
|
||||||
import com.alibaba.edas.acm.ConfigService;
|
import com.alibaba.edas.acm.ConfigService;
|
||||||
import com.alibaba.edas.acm.exception.ConfigException;
|
import com.alibaba.edas.acm.exception.ConfigException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.springframework.cloud.alicloud.acm.endpoint;
|
package org.springframework.cloud.alicloud.acm.endpoint;
|
||||||
|
|
||||||
import com.alibaba.edas.acm.ConfigService;
|
import com.alibaba.edas.acm.ConfigService;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.Health;
|
import org.springframework.boot.actuate.health.Health;
|
||||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user