§ 本文目的

了解并掌握全局序列号组件

简介:

全局序列号是一个独立的微服务,提供了客户端jar用于流水号的获取;

全局序列号有自己的前端配置,可以配置序列号的格式,如 YP20190807-0001

§ 练习场景

配置一个序列号模板,用于生成押品信息的主键

前提:

  • 微服务应用yusp-sequence、yup-app-oca、yusp-app-common
  • 数据库

§ 操作步骤

§ 配置序列号模板

qjxlh_01

qjxlh_02

qjxlh_03

§ 引入依赖

pom.xml文件中添加封装的SDK工具的jar依赖

<dependency>
    <groupId>cn.com.yusys.yusp</groupId>
    <artifactId>yusp-sequence-client</artifactId>
          <version>2.1.1-SNAPSHOT</version>
</dependency>
1
2
3
4
5

§ JavaConfig配置

在启动类上加@EnableFeignClients注解,并指定扫描的包名,如果已存在注解,通过basePackages={"...","cn.com.yusys.yusp"}方式添加

@EnableFeignClients(basePackages = "cn.com.yusys.yusp")
1

§ Application.yml配置

sequence:
    service:
      name: yusp-sequence
      url: /api/sequenceconfig
1
2
3
4

§ 调用SDK方法

package cn.com.yusys.yusp.example.common.web.rest;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import cn.com.yusys.yusp.sequence.client.SequenceTemplateService;
/**
 * 序列号微服务客户端调用示例
 * @author wangyf10
 * @since 2019-03-27
 */
@RestController
@RequestMapping("/api/sequence")
public class SequenceDemoResource {
          
          @Autowired
          private SequenceTemplateService sequenceTemplateService;
          
          /**
           * 
           * @方法名称:generate
           * @方法描述:根据seqId生成序列号
           * @参数与返回说明:
           * @算法描述:
           */
          @GetMapping(value = "/generate")
    public  ResultDto`<String>` generate(@RequestParam("seqId") String seqId) {
          String resultDto = sequenceTemplateService.getSequenceTemplate(seqId, new HashMap<String,String>());  //调用SDK中封装的客户端接口SequenceTemplateService.java类   
        return new ResultDto`<String>`(resultDto);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

浏览器输入 ip:端口/api/sequence/generate?seqId=YPSEQ 即可返回序列号字符串

最后更新于: 5/5/2022, 6:41:08 PM