From 4c9d69c8c07c7fcd9411f8d662983666f4720948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Tue, 28 Mar 2023 10:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4lettuce-core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-service/ticket/pom.xml | 32 ++++++++++++++++ .../controller/StandardWorkTicketController.java | 26 +++++++++++-- .../strategy/abstracts/TicketAbstractService.java | 38 +++++++++++++++++++ .../standardTicket/strategy/entity/Ticket.java | 30 +++++++++++++++ .../strategy/service/TicketService.java | 29 +++++++++++++++ .../serviceimpl/OperatorTicketServiceImpl.java | 40 ++++++++++++++++++++ .../serviceimpl/SignatureTicketServiceImpl.java | 43 ++++++++++++++++++++++ .../utils/StandardTicketIdWorker.java | 8 ++-- 8 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java diff --git a/hzims-service/ticket/pom.xml b/hzims-service/ticket/pom.xml index a63fc17..eb24db8 100644 --- a/hzims-service/ticket/pom.xml +++ b/hzims-service/ticket/pom.xml @@ -102,7 +102,39 @@ org.springblade blade-core-boot + + + org.springblade + blade-starter-redis + + + + + + org.springblade + blade-starter-redis + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + io.lettuce + lettuce-core + + + + + org.springblade blade-core-cloud diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardWorkTicketController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardWorkTicketController.java index a34f050..dab4f94 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardWorkTicketController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardWorkTicketController.java @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.hnac.hzims.ticket.response.WorkTicketMessageResponse; import com.hnac.hzims.ticket.standardTicket.service.StandardWorkTicketService; +import com.hnac.hzims.ticket.standardTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.standardTicket.strategy.service.TicketService; import com.hnac.hzims.ticket.standardTicket.utils.StandardTicketIdWorker; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -12,10 +14,10 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; /** * 工作票管理 @@ -42,6 +44,10 @@ public class StandardWorkTicketController { @Autowired private StandardTicketIdWorker standardTicketIdWorker; + + @Autowired + List ticketService; + @ApiOperation("测试开票") @PostMapping("/createTicket") public R createTicket() { @@ -63,4 +69,16 @@ public class StandardWorkTicketController { return R.data(ticketCode); } + + @ApiOperation("测试") + @GetMapping("/hello/{type}") + public R hello(@PathVariable int type) { + + TicketService service = ticketService.stream().filter(item -> item.isCurrentTicket(type)) + .findFirst().orElse(null); + String calculate = service.calculate(new Ticket()); + return R.data(calculate); + } + + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java new file mode 100644 index 0000000..d080162 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.ticket.standardTicket.strategy.abstracts; + +import com.hnac.hzims.ticket.standardTicket.strategy.service.TicketService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 9:02 + */ +@Slf4j +public abstract class TicketAbstractService implements TicketService { + + + @Autowired + private RedisTemplate redisTemplate; + + /** + * 查询所有的方法 + * + * @return + */ + public List getTicketList() { + System.out.println("实例化:" +redisTemplate); + List list = new ArrayList<>(); + list.add(1); + list.add(2); + return list; + } + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java new file mode 100644 index 0000000..681a321 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.ticket.standardTicket.strategy.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:49 + */ +@Data +@Accessors(chain = true) +public class Ticket { + + /** + * 实例Id + */ + private String flowId; + + + /** + * 实例Id说明 + */ + private String segment; + + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java new file mode 100644 index 0000000..a8541d7 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.ticket.standardTicket.strategy.service; + +import com.hnac.hzims.ticket.standardTicket.strategy.entity.Ticket; + +import java.util.List; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:39 + */ +public interface TicketService { + + /** + * 设置执行那种实现类 + * @param type + * @return + */ + Boolean isCurrentTicket(int type); + + + /** + * 两票管理业务方法 + * @param ticket + */ + String calculate(Ticket ticket); + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java new file mode 100644 index 0000000..55a164a --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.ticket.standardTicket.strategy.serviceimpl; + +import com.hnac.hzims.ticket.standardTicket.strategy.abstracts.TicketAbstractService; +import com.hnac.hzims.ticket.standardTicket.strategy.entity.Ticket; +import org.springframework.stereotype.Service; +import java.util.List; + +/** + * 运行人接收 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 8:47 + */ +@Service +public class OperatorTicketServiceImpl extends TicketAbstractService { + /** + * 设置执行那种实现类 + * + * @param type + * @return + */ + @Override + public Boolean isCurrentTicket(int type) { + List ticketList = this.getTicketList(); + return type == ticketList.get(1); + } + + /** + * 两票管理业务方法 + * + * @param ticket + */ + @Override + public String calculate(Ticket ticket) { + System.out.println("OperatorTicketServiceImpl"); + return "运行人接收"; + + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java new file mode 100644 index 0000000..ff612a7 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java @@ -0,0 +1,43 @@ +package com.hnac.hzims.ticket.standardTicket.strategy.serviceimpl; + +import com.hnac.hzims.ticket.standardTicket.strategy.abstracts.TicketAbstractService; +import com.hnac.hzims.ticket.standardTicket.strategy.entity.Ticket; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 签发人签发 + * + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:40 + */ +@Service +public class SignatureTicketServiceImpl extends TicketAbstractService { + + + /** + * 设置执行那种实现类 + * + * @param type + * @return + */ + @Override + public Boolean isCurrentTicket(int type) { + List ticketList = this.getTicketList(); + return type == ticketList.get(0); + } + + /** + * 两票管理业务方法 + * + * @param ticket + */ + @Override + public String calculate(Ticket ticket) { + System.out.println("SignatureTicketServiceImpl"); + return "签发人签发"; + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java index c74ab25..5d99934 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java @@ -8,9 +8,12 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Component; +import org.xnio.sasl.SaslQop; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -55,13 +58,13 @@ public class StandardTicketIdWorker { AtomicInteger atomicInteger = new AtomicInteger(1); String key = staff + ":" + typeInstrument + ":" + YearMonth; // TicketCode ticketCode1 = cacheMap.get(key); - TicketCode ticketCode = JSON.parseObject(operations.get(key),TicketCode.class); + TicketCode ticketCode = JSON.parseObject(operations.get(key), TicketCode.class); if (ticketCode == null) { ticketCode = new TicketCode(); ticketCode.setYearMonth(YearMonth); ticketCode.setSequencing(atomicInteger); // cacheMap.put(key, ticketCode); - operations.set(key,JSON.toJSONString(ticketCode)); + operations.set(key, JSON.toJSONString(ticketCode)); String result = getTicketCode(staff, typeInstrument, YearMonth, atomicInteger.get()); return result; } @@ -192,7 +195,6 @@ public class StandardTicketIdWorker { // // String format = numberFormatter.format(2); // System.out.println(format); - }