Commit 45862b322fbba0b9595a8050a55cadeec19c53f2

Authored by 徐烜
1 parent 81e157d8

1、添加dubbo消费者配置

2、修改排班计划查询的服务,调用dubbo服务
... ... @@ -296,6 +296,45 @@
296 296 <artifactId>jpinyin</artifactId>
297 297 <version>1.1.8</version>
298 298 </dependency>
  299 +
  300 + <!-- dubbo 需要的jar start -->
  301 + <dependency>
  302 + <groupId>com.alibaba</groupId>
  303 + <artifactId>dubbo</artifactId>
  304 + <version>2.5.3</version>
  305 + <exclusions>
  306 + <exclusion>
  307 + <groupId>org.springframework</groupId>
  308 + <artifactId>spring</artifactId>
  309 + </exclusion>
  310 + </exclusions>
  311 + </dependency>
  312 +
  313 + <dependency>
  314 + <groupId>org.apache.zookeeper</groupId>
  315 + <artifactId>zookeeper</artifactId>
  316 + <version>3.4.5</version>
  317 + <exclusions>
  318 + <exclusion>
  319 + <groupId>org.slf4j</groupId>
  320 + <artifactId>slf4j-log4j12</artifactId>
  321 + </exclusion>
  322 + </exclusions>
  323 + </dependency>
  324 +
  325 + <dependency>
  326 + <groupId>com.101tec</groupId>
  327 + <artifactId>zkclient</artifactId>
  328 + <version>0.3</version>
  329 + </dependency>
  330 + <!-- dubbo 需要的jar end -->
  331 +
  332 + <!-- common工程依赖 -->
  333 + <dependency>
  334 + <groupId>com.bsth.control_v2</groupId>
  335 + <artifactId>plan_module-common</artifactId>
  336 + <version>1.0-SNAPSHOT</version>
  337 + </dependency>
299 338 </dependencies>
300 339  
301 340 <dependencyManagement>
... ...
src/main/java/com/bsth/controller/schedule/core/SchedulePlanController.java
... ... @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
8 8 import org.springframework.web.bind.annotation.PathVariable;
9 9 import org.springframework.web.bind.annotation.RequestMapping;
10 10 import org.springframework.web.bind.annotation.RequestMethod;
11   -import org.springframework.web.bind.annotation.RestController;
12 11  
13 12 import java.util.Date;
14 13 import java.util.HashMap;
... ... @@ -17,8 +16,8 @@ import java.util.Map;
17 16 /**
18 17 * Created by xu on 16/6/16.
19 18 */
20   -@RestController
21   -@RequestMapping("spc")
  19 +//@RestController
  20 +//@RequestMapping("spc")
22 21 public class SchedulePlanController extends BController<SchedulePlan, Long> {
23 22 @Autowired
24 23 private SchedulePlanService schedulePlanService;
... ...
src/main/java/com/bsth/controller/schedule/core/SchedulePlanController_dubbo.java 0 → 100644
  1 +package com.bsth.controller.schedule.core;
  2 +
  3 +import com.bsth.common.ResponseCode;
  4 +import com.bsth.control_v2.plan_module.common.dto.PageRequestDto;
  5 +import com.bsth.control_v2.plan_module.common.service.schedule.PlanServiceFacade;
  6 +import com.google.common.base.Splitter;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.data.domain.PageRequest;
  9 +import org.springframework.data.domain.Sort;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestMethod;
  12 +import org.springframework.web.bind.annotation.RequestParam;
  13 +import org.springframework.web.bind.annotation.RestController;
  14 +
  15 +import java.util.ArrayList;
  16 +import java.util.HashMap;
  17 +import java.util.List;
  18 +import java.util.Map;
  19 +
  20 +@RestController
  21 +@RequestMapping("spc")
  22 +public class SchedulePlanController_dubbo {
  23 + @Autowired
  24 + private PlanServiceFacade planServiceFacade;
  25 +
  26 + //---------------- CRUD 操作 ----------------//
  27 + // 分页查询操作
  28 + @RequestMapping(method = RequestMethod.GET)
  29 + public Map<String, Object> list(
  30 + @RequestParam Map<String, Object> map,
  31 + @RequestParam(defaultValue = "0") int page,
  32 + @RequestParam(defaultValue = "10") int size,
  33 + @RequestParam(defaultValue = "id") String order,
  34 + @RequestParam(defaultValue = "DESC") String direction) {
  35 +
  36 + PageRequestDto pageRequestDto = PageRequestDto.getBuilder()
  37 + .setPage(page)
  38 + .setSize(size)
  39 + .setOrder(order)
  40 + .setDirection(direction)
  41 + .build();
  42 + Map<String, Object> rtn = new HashMap<>();
  43 + rtn.put("data", planServiceFacade.list(map, pageRequestDto));
  44 + rtn.put("status", ResponseCode.SUCCESS);
  45 + return rtn;
  46 +
  47 + }
  48 +
  49 + // TODO
  50 +}
... ...
src/main/java/com/bsth/service/schedule/dubbo/DubboConfig.java 0 → 100644
  1 +package com.bsth.service.schedule.dubbo;
  2 +
  3 +import org.springframework.context.annotation.Configuration;
  4 +import org.springframework.context.annotation.ImportResource;
  5 +
  6 +/**
  7 + * Dubbo消费者配置。
  8 + */
  9 +@Configuration
  10 +@ImportResource({"classpath:dubbo/applicationContext_dubbo_consumer.xml"})
  11 +public class DubboConfig {
  12 +
  13 +}
... ...
src/main/resources/dubbo/applicationContext_dubbo_consumer.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  3 + xsi:schemaLocation="http://www.springframework.org/schema/beans
  4 + http://www.springframework.org/schema/beans/spring-beans.xsd
  5 + http://code.alibabatech.com/schema/dubbo
  6 + http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  7 +
  8 + <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
  9 + <dubbo:application name="bsth_control_v2" />
  10 +
  11 + <!-- 使用zookeeper注册中心暴露服务地址 -->
  12 + <!-- 注册中心地址 -->
  13 + <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />
  14 +
  15 + <!-- 用户服务接口 -->
  16 + <dubbo:reference interface="com.bsth.control_v2.plan_module.common.service.schedule.PlanServiceFacade" id="planServiceFacadeImpl" check="false" />
  17 +
  18 +
  19 +</beans>
0 20 \ No newline at end of file
... ...