From 6b21f9ac1fca83e2484475856b5437a60ba7334b 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 16:01:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=96=E7=95=A5=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-service/ticket/pom.xml | 21 ++- .../consumer/StandardWorkTicketConsumer.java | 25 --- .../controller/StandardWorkTicketController.java | 34 +++- .../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 | 201 --------------------- .../consumer/StandardWorkTicketConsumer.java | 54 ++++++ .../twoTicket/properties/TicketProperties.java | 30 +++ .../twoTicket/properties/WorkTicketProperties.java | 22 +++ .../strategy/abstracts/TicketAbstractService.java | 37 ++++ .../twoTicket/strategy/core/TicketIdWorker.java | 197 ++++++++++++++++++++ .../ticket/twoTicket/strategy/entity/Ticket.java | 23 +++ .../twoTicket/strategy/service/TicketService.java | 28 +++ .../serviceimpl/MakeTicketServiceImpl.java | 53 ++++++ .../serviceimpl/OperatorTicketServiceImpl.java | 53 ++++++ .../serviceimpl/SignatureTicketServiceImpl.java | 54 ++++++ .../ticket/src/main/resources/application.yml | 45 +++++ .../ticket/src/main/resources/bootstrap.yml | 12 ++ .../ticket/src/test/resources/application.yml | 4 + 22 files changed, 657 insertions(+), 416 deletions(-) delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/consumer/StandardWorkTicketConsumer.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java delete mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/consumer/StandardWorkTicketConsumer.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/TicketProperties.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/WorkTicketProperties.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/abstracts/TicketAbstractService.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/core/TicketIdWorker.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/entity/Ticket.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/service/TicketService.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/MakeTicketServiceImpl.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java diff --git a/hzims-service/ticket/pom.xml b/hzims-service/ticket/pom.xml index eb24db8..d24c137 100644 --- a/hzims-service/ticket/pom.xml +++ b/hzims-service/ticket/pom.xml @@ -134,6 +134,12 @@ + + org.springframework.boot + spring-boot-configuration-processor + true + + org.springblade @@ -250,7 +256,20 @@ equipment-api - + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.nacos + nacos-spring-context + 0.2.3-RC1 + diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/consumer/StandardWorkTicketConsumer.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/consumer/StandardWorkTicketConsumer.java deleted file mode 100644 index 119a874..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/consumer/StandardWorkTicketConsumer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.hnac.hzims.ticket.standardTicket.consumer; - -import lombok.extern.slf4j.Slf4j; -import org.springblade.queue.annotation.RedisQueue; -import org.springblade.queue.consume.IQueueConsume; -import org.springframework.stereotype.Service; - -/** - * 监听数据的 - * @Author WL - * @Version v1.0 - * @Serial 1.0 - * @Date 2023/3/24 9:46 - */ -@Service -@RedisQueue(topicName = "blade:queue:flow") -@Slf4j -public class StandardWorkTicketConsumer implements IQueueConsume { - - - @Override - public void handlerMessage(String message) { - log.info("监听到数据:{}", message); - } -} 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 dab4f94..8335ca8 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,9 +4,12 @@ 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 com.hnac.hzims.ticket.twoTicket.properties.TicketProperties; +import com.hnac.hzims.ticket.twoTicket.properties.WorkTicketProperties; +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.twoTicket.strategy.service.TicketService; +import com.hnac.hzims.ticket.twoTicket.strategy.core.TicketIdWorker; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -16,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; /** @@ -42,12 +44,16 @@ public class StandardWorkTicketController { @Autowired - private StandardTicketIdWorker standardTicketIdWorker; + private TicketIdWorker standardTicketIdWorker; @Autowired List ticketService; + + @Autowired + private TicketProperties ticketProperties; + @ApiOperation("测试开票") @PostMapping("/createTicket") public R createTicket() { @@ -72,13 +78,23 @@ public class StandardWorkTicketController { @ApiOperation("测试") @GetMapping("/hello/{type}") - public R hello(@PathVariable int type) { - - TicketService service = ticketService.stream().filter(item -> item.isCurrentTicket(type)) + public R hello(@PathVariable String type) { + Ticket ticket = new Ticket(); + ticket.setDeploymentId(type); + TicketService service = ticketService.stream().filter(item -> item.isWorkflowTicket(ticket)) .findFirst().orElse(null); - String calculate = service.calculate(new Ticket()); + String calculate = service.calculate(new WorkTicketInfoDto()); return R.data(calculate); } + @ApiOperation("测试1") + @GetMapping("/hello1") + public R hello1() { + List workTickets = ticketProperties.getWorkTickets(); + System.out.println("workTickets = " + workTickets); + return R.data(workTickets); + } + + } 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 deleted file mode 100644 index d080162..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/abstracts/TicketAbstractService.java +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index 681a321..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/entity/Ticket.java +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index a8541d7..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/service/TicketService.java +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 55a164a..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index ff612a7..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 5d99934..0000000 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/utils/StandardTicketIdWorker.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.hnac.hzims.ticket.standardTicket.utils; - -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; -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; - - -/** - * 生成票据编码工具类 - * - * @Author WL - * @Version v1.0 - * @Serial 1.0 - * @Date 2023/3/27 10:11 - */ -@Component -public class StandardTicketIdWorker { - - private static Map cacheMap = new HashMap<>(); - - - @Autowired - private StringRedisTemplate redisTemplate; - - private static NumberFormat numberFormatter; - - - static { - //初始化 - numberFormatter = NumberFormat.getInstance(); - numberFormatter.setGroupingUsed(false); - numberFormatter.setMinimumIntegerDigits(3); - numberFormatter.setMaximumFractionDigits(3); - } - - /** - * 按规则生成票据编码:票据编码:AA-BB-CCCC-DDD格式 - * - * @param staff AA在建站之初由接站人员填写要求唯一 - * @param typeInstrument 票据种类,第一种票,第二种票 - * @param YearMonth 开票时间年月 - */ - public String getTicketCode(String staff, String typeInstrument, String YearMonth) { - ValueOperations operations = redisTemplate.opsForValue(); - AtomicInteger atomicInteger = new AtomicInteger(1); - String key = staff + ":" + typeInstrument + ":" + YearMonth; - // TicketCode ticketCode1 = cacheMap.get(key); - 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)); - String result = getTicketCode(staff, typeInstrument, YearMonth, atomicInteger.get()); - return result; - } - - String originalYearMonth = ticketCode.getYearMonth(); - - AtomicInteger sequencing = ticketCode.getSequencing(); - - //生成 票据排序 格式 001 010 111 - int code = getYearMonthCode(originalYearMonth, YearMonth, key, sequencing); - - String result = getTicketCode(staff, typeInstrument, YearMonth, code); - return result; - } - - - /** - * 生成的票据 编号 - */ - public String getTicketCode(String staff, String typeInstrument, String YearMonth, int sequencing) { - return staff.concat("-").concat(typeInstrument).concat("-").concat(YearMonth).concat("-").concat(numberFormatter.format(sequencing)); - } - - - /** - * 返回票据排序 - * - * @param - * @param originalYearMonth 上次的年月 年的后2位 + 月 - * @param nextYearMonth 现在的年月 年的后2位 + 月 - * @param key - * @param sequencing - * @return - */ - private int getYearMonthCode(String originalYearMonth, String nextYearMonth, String key, AtomicInteger sequencing) { - ValueOperations operations = redisTemplate.opsForValue(); - //1. 累计票据 - sequencing.incrementAndGet(); - //3. 判断年是否为空 - if (StringUtils.isEmpty(originalYearMonth) && StringUtils.isEmpty(nextYearMonth)) { - return sequencing.get(); - } - //4. 验证年 最后一位数 - String year1 = getSubstring(originalYearMonth, 1); - String year2 = getSubstring(nextYearMonth, 1); - if (!year1.equals(year2)) { - sequencing.compareAndSet(sequencing.get(), 1); - return sequencing.get(); - } - - //4. 验证倒数第二位数 - year1 = getSubstring(originalYearMonth, 2); - year2 = getSubstring(nextYearMonth, 2); - if (!year1.equals(year2)) { - sequencing.compareAndSet(sequencing.get(), 1); - return sequencing.get(); - } - - //4. 验证倒数第三位数 - year1 = getSubstring(originalYearMonth, 3); - year2 = getSubstring(nextYearMonth, 3); - if (!year1.equals(year2)) { - sequencing.compareAndSet(sequencing.get(), 1); - return sequencing.get(); - } - - - //6. sequencing 大于等于1000 的话,从头开始 - if (sequencing.get() >= 1000) { - sequencing.compareAndSet(sequencing.get(), 1); - System.out.println("sequencing >= 1000 被执行呢"); - redisTemplate.delete(key); - // cacheMap.remove(key); - return sequencing.get(); - } - - TicketCode ticketCode = new TicketCode(); - ticketCode.setYearMonth(nextYearMonth); - ticketCode.setSequencing(sequencing); - operations.set(key, JSON.toJSONString(ticketCode)); - //cacheMap.put(key, ticketCode); - - return sequencing.get(); - } - - /** - * 截取字符串 - * - * @param originalYearMonth - * @param digit 位数 - * @return - */ - private static String getSubstring(String originalYearMonth, int digit) { - return originalYearMonth.substring(originalYearMonth.length() - digit); - } - - - @Data - public static class TicketCode { - - /** - * 月份 - */ - private String yearMonth; - /** - * 记录数 - */ - private AtomicInteger sequencing = new AtomicInteger(1); - } - - public static void main(String[] args) { - - StandardTicketIdWorker standardTicketIdWorker = new StandardTicketIdWorker(); - int count = 1; - while (count <= 1000) { - - System.out.println("1 ===> " + standardTicketIdWorker.getTicketCode("aa", "bb", "2304")); - System.out.println("================================="); - //System.out.println("2 ===》" + standardTicketIdWorker.getTicketCode("aa", "bb", "2204")); - count++; - - } - - // NumberFormat numberFormatter = NumberFormat.getInstance(); - // numberFormatter.setGroupingUsed(false); - // numberFormatter.setMinimumIntegerDigits(3); - // numberFormatter.setMaximumFractionDigits(3); - // - // String format = numberFormatter.format(2); - // System.out.println(format); - } - - -} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/consumer/StandardWorkTicketConsumer.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/consumer/StandardWorkTicketConsumer.java new file mode 100644 index 0000000..a42aeff --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/consumer/StandardWorkTicketConsumer.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.ticket.twoTicket.consumer; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.ticket.response.WorkTicketMessageResponse; +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.twoTicket.strategy.service.TicketService; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; +import lombok.extern.slf4j.Slf4j; +import org.springblade.queue.annotation.RedisQueue; +import org.springblade.queue.consume.IQueueConsume; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 监听数据的 + * + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/24 9:46 + */ +@Service +@RedisQueue(topicName = "blade:queue:flow") +@Slf4j +public class StandardWorkTicketConsumer implements IQueueConsume { + + @Autowired + private List ticketServiceList; + + @Override + public void handlerMessage(String message) { + log.info("监听到数据:{}", message); + WorkTicketMessageResponse response = JSONObject.parseObject(message, WorkTicketMessageResponse.class); + String taskDefinitionKey = response.getTaskDefinitionKey(); + Ticket ticker = new Ticket(); + ticker.setDeploymentId(taskDefinitionKey); + //判断执行具体的实现类 + TicketService ticketService = ticketServiceList.stream().filter(item -> item.isWorkflowTicket(ticker)) + .findFirst().orElse(null); + if (ObjectUtils.isNotEmpty(ticketService)){ + Object formData = response.getFormData(); + String jsonString = JSON.toJSONString(formData); + WorkTicketInfoDto workTicketInfoDto = JSON.parseObject(jsonString, WorkTicketInfoDto.class); + //执行业务方法 + ticketService.calculate(workTicketInfoDto); + } + + + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/TicketProperties.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/TicketProperties.java new file mode 100644 index 0000000..3dfc491 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/TicketProperties.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.ticket.twoTicket.properties; + +import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties; +import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 读取nacos 开票的数据 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 12:06 + */ +@Data +@Accessors(chain = true) +@Component +@NacosPropertySource(dataId = "hzims-ticket-dev.yaml", autoRefreshed = true) +@ConfigurationProperties(prefix = "ticket") +@RefreshScope +public class TicketProperties { + + private List workTickets; +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/WorkTicketProperties.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/WorkTicketProperties.java new file mode 100644 index 0000000..92027e9 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/properties/WorkTicketProperties.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.ticket.twoTicket.properties; + +import lombok.Data; +import lombok.Getter; +import lombok.experimental.Accessors; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 12:09 + */ +@Data +@Accessors(chain = true) +public class WorkTicketProperties { + + private Integer status; + + private String flowId; + + private String segment; +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/abstracts/TicketAbstractService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/abstracts/TicketAbstractService.java new file mode 100644 index 0000000..7867189 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/abstracts/TicketAbstractService.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.abstracts; + +import com.hnac.hzims.ticket.twoTicket.properties.TicketProperties; +import com.hnac.hzims.ticket.twoTicket.properties.WorkTicketProperties; +import com.hnac.hzims.ticket.twoTicket.strategy.service.TicketService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 9:02 + */ +@Slf4j +public abstract class TicketAbstractService implements TicketService { + + + @Autowired + private TicketProperties ticketProperties; + + /** + * 查询所有的方法 + * + * @return + */ + public List getTicketList() { + log.info("实例化:" + ticketProperties); + List workTickets = ticketProperties.getWorkTickets(); + return workTickets; + } + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/core/TicketIdWorker.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/core/TicketIdWorker.java new file mode 100644 index 0000000..a8e4fd5 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/core/TicketIdWorker.java @@ -0,0 +1,197 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.core; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.text.NumberFormat; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + + +/** + * 生成票据编码工具类 + * + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 10:11 + */ +@Component +public class TicketIdWorker { + + private static Map cacheMap = new HashMap<>(); + + + @Autowired + private StringRedisTemplate redisTemplate; + + private static NumberFormat numberFormatter; + + + static { + //初始化 + numberFormatter = NumberFormat.getInstance(); + numberFormatter.setGroupingUsed(false); + numberFormatter.setMinimumIntegerDigits(3); + numberFormatter.setMaximumFractionDigits(3); + } + + /** + * 按规则生成票据编码:票据编码:AA-BB-CCCC-DDD格式 + * + * @param staff AA在建站之初由接站人员填写要求唯一 + * @param typeInstrument 票据种类,第一种票,第二种票 + * @param YearMonth 开票时间年月 + */ + public String getTicketCode(String staff, String typeInstrument, String YearMonth) { + ValueOperations operations = redisTemplate.opsForValue(); + AtomicInteger atomicInteger = new AtomicInteger(1); + String key = staff + ":" + typeInstrument + ":" + YearMonth; + // TicketCode ticketCode1 = cacheMap.get(key); + 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)); + String result = getTicketCode(staff, typeInstrument, YearMonth, atomicInteger.get()); + return result; + } + + String originalYearMonth = ticketCode.getYearMonth(); + + AtomicInteger sequencing = ticketCode.getSequencing(); + + //生成 票据排序 格式 001 010 111 + int code = getYearMonthCode(originalYearMonth, YearMonth, key, sequencing); + + String result = getTicketCode(staff, typeInstrument, YearMonth, code); + return result; + } + + + /** + * 生成的票据 编号 + */ + public String getTicketCode(String staff, String typeInstrument, String YearMonth, int sequencing) { + return staff.concat("-").concat(typeInstrument).concat("-").concat(YearMonth).concat("-").concat(numberFormatter.format(sequencing)); + } + + + /** + * 返回票据排序 + * + * @param + * @param originalYearMonth 上次的年月 年的后2位 + 月 + * @param nextYearMonth 现在的年月 年的后2位 + 月 + * @param key + * @param sequencing + * @return + */ + private int getYearMonthCode(String originalYearMonth, String nextYearMonth, String key, AtomicInteger sequencing) { + ValueOperations operations = redisTemplate.opsForValue(); + //1. 累计票据 + sequencing.incrementAndGet(); + //3. 判断年是否为空 + if (StringUtils.isEmpty(originalYearMonth) && StringUtils.isEmpty(nextYearMonth)) { + return sequencing.get(); + } + //4. 验证年 最后一位数 + String year1 = getSubstring(originalYearMonth, 1); + String year2 = getSubstring(nextYearMonth, 1); + if (!year1.equals(year2)) { + sequencing.compareAndSet(sequencing.get(), 1); + return sequencing.get(); + } + + //4. 验证倒数第二位数 + year1 = getSubstring(originalYearMonth, 2); + year2 = getSubstring(nextYearMonth, 2); + if (!year1.equals(year2)) { + sequencing.compareAndSet(sequencing.get(), 1); + return sequencing.get(); + } + + //4. 验证倒数第三位数 + year1 = getSubstring(originalYearMonth, 3); + year2 = getSubstring(nextYearMonth, 3); + if (!year1.equals(year2)) { + sequencing.compareAndSet(sequencing.get(), 1); + return sequencing.get(); + } + + + //6. sequencing 大于等于1000 的话,从头开始 + if (sequencing.get() >= 1000) { + sequencing.compareAndSet(sequencing.get(), 1); + System.out.println("sequencing >= 1000 被执行呢"); + redisTemplate.delete(key); + // cacheMap.remove(key); + return sequencing.get(); + } + + TicketCode ticketCode = new TicketCode(); + ticketCode.setYearMonth(nextYearMonth); + ticketCode.setSequencing(sequencing); + operations.set(key, JSON.toJSONString(ticketCode)); + //cacheMap.put(key, ticketCode); + + return sequencing.get(); + } + + /** + * 截取字符串 + * + * @param originalYearMonth + * @param digit 位数 + * @return + */ + private static String getSubstring(String originalYearMonth, int digit) { + return originalYearMonth.substring(originalYearMonth.length() - digit); + } + + + @Data + public static class TicketCode { + + /** + * 月份 + */ + private String yearMonth; + /** + * 记录数 + */ + private AtomicInteger sequencing = new AtomicInteger(1); + } + + public static void main(String[] args) { + + TicketIdWorker standardTicketIdWorker = new TicketIdWorker(); + int count = 1; + while (count <= 1000) { + + System.out.println("1 ===> " + standardTicketIdWorker.getTicketCode("aa", "bb", "2304")); + System.out.println("================================="); + //System.out.println("2 ===》" + standardTicketIdWorker.getTicketCode("aa", "bb", "2204")); + count++; + + } + + // NumberFormat numberFormatter = NumberFormat.getInstance(); + // numberFormatter.setGroupingUsed(false); + // numberFormatter.setMinimumIntegerDigits(3); + // numberFormatter.setMaximumFractionDigits(3); + // + // String format = numberFormatter.format(2); + // System.out.println(format); + } + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/entity/Ticket.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/entity/Ticket.java new file mode 100644 index 0000000..eae72f6 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/entity/Ticket.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:49 + */ +@Data +@Accessors(chain = true) +public class Ticket { + + /** + * 实例 key + */ + private String deploymentId ; + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/service/TicketService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/service/TicketService.java new file mode 100644 index 0000000..a9e59e4 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/service/TicketService.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.service; + +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; + +/** + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:39 + */ +public interface TicketService { + + /** + * 设置执行那种实现类 + * @param ticket + * @return + */ + Boolean isWorkflowTicket(Ticket ticket); + + + /** + * 两票管理业务方法 + * @param workflowTicket + */ + String calculate(WorkTicketInfoDto workflowTicket); + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/MakeTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/MakeTicketServiceImpl.java new file mode 100644 index 0000000..3ef853e --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/MakeTicketServiceImpl.java @@ -0,0 +1,53 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.serviceimpl; + +import com.hnac.hzims.ticket.twoTicket.properties.WorkTicketProperties; +import com.hnac.hzims.ticket.twoTicket.strategy.abstracts.TicketAbstractService; +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 开工作票流程实现类 + * + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 8:47 + */ +@Slf4j +@Service +public class MakeTicketServiceImpl extends TicketAbstractService { + /** + * 设置执行那种实现类 + * + * @param ticket + * @return + */ + @Override + public Boolean isWorkflowTicket(Ticket ticket) { + log.info("是否执行开工作票流程环节操作~~~~,流程ticket: {}", ticket); + List ticketList = this.getTicketList(); + WorkTicketProperties properties = ticketList.get(0); + if (properties.getFlowId().equals(ticket.getDeploymentId())) { + log.info("已执行开工作票流程环节操作~~~~"); + return true; + } + log.info("未是否执行开工作票流程环节操作,请联系管理员~~~~"); + return false; + } + + /** + * 两票管理业务方法 + * + * @param workflowTicket + */ + @Override + public String calculate(WorkTicketInfoDto workflowTicket) { + System.out.println("OperatorTicketServiceImpl"); + return "开票"; + + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java new file mode 100644 index 0000000..f8328cc --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/OperatorTicketServiceImpl.java @@ -0,0 +1,53 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.serviceimpl; + +import com.hnac.hzims.ticket.twoTicket.properties.WorkTicketProperties; +import com.hnac.hzims.ticket.twoTicket.strategy.abstracts.TicketAbstractService; +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 运行人实例类 (运行人接收) + * + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/28 8:47 + */ +@Slf4j +@Service +public class OperatorTicketServiceImpl extends TicketAbstractService { + /** + * 设置执行那种实现类 + * + * @param ticket + * @return + */ + @Override + public Boolean isWorkflowTicket(Ticket ticket) { + log.info("是否执行运行人接收操作~~~~,流程ticket: {}", ticket); + List ticketList = this.getTicketList(); + WorkTicketProperties properties = ticketList.get(2); + if (properties.getFlowId().equals(ticket.getDeploymentId())) { + log.info("已执行运行人接收操作~~~~"); + return true; + } + log.info("未执行运行人接收操作,请联系管理员~~~~"); + return false; + } + + /** + * 两票管理业务方法 + * + * @param workflowTicket + */ + @Override + public String calculate(WorkTicketInfoDto workflowTicket) { + System.out.println("OperatorTicketServiceImpl"); + return "运行人接收"; + + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java new file mode 100644 index 0000000..158294d --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/strategy/serviceimpl/SignatureTicketServiceImpl.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.ticket.twoTicket.strategy.serviceimpl; + +import com.hnac.hzims.ticket.twoTicket.properties.WorkTicketProperties; +import com.hnac.hzims.ticket.twoTicket.strategy.abstracts.TicketAbstractService; +import com.hnac.hzims.ticket.twoTicket.strategy.entity.Ticket; +import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 签发人实现类(签发人签发) + * + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:40 + */ +@Slf4j +@Service +public class SignatureTicketServiceImpl extends TicketAbstractService { + + + /** + * 设置执行那种实现类 + * + * @param ticket + * @return + */ + @Override + public Boolean isWorkflowTicket(Ticket ticket) { + log.info("是否执行运行人接收操作~~~~,流程ticket: {}", ticket); + List ticketList = this.getTicketList(); + WorkTicketProperties properties = ticketList.get(1); + if (properties.getFlowId().equals(ticket.getDeploymentId())){ + log.info("已执行运行人接收操作~~~~"); + return true; + } + log.info("未执行运行人接收操作,请联系管理员~~~~"); + return false; + } + + /** + * 两票管理业务方法 + * + * @param workflowTicket + */ + @Override + public String calculate(WorkTicketInfoDto workflowTicket) { + System.out.println("SignatureTicketServiceImpl"); + return "签发人签发"; + } +} diff --git a/hzims-service/ticket/src/main/resources/application.yml b/hzims-service/ticket/src/main/resources/application.yml index 34fc5c1..e6917e1 100644 --- a/hzims-service/ticket/src/main/resources/application.yml +++ b/hzims-service/ticket/src/main/resources/application.yml @@ -9,3 +9,48 @@ swagger: base-packages: - org.springbalde - com.hnac + + + +#ticket: +# workTickets: +# - status: 1 +# flowId: startEvent1 +# segment: 开票 +# - status: 2 +# flowId: sid-5E7013A9-385A-4EE4-91B6-FD5328D05E2A +# segment: 签发人签发 +# - status: 3 +# flowId: sid-355DB6EC-7D54-4537-B80F-C26CD716ADA1 +# segment: 运行人员接收 +# - status: 4 +# flowId: sid-F35C4A79-53AF-40B8-AFBD-AF7283CC5708 +# segment: 运行人员布置安全措施 +# - status: 5 +# flowId: sid-0CB1456A-D85C-4473-A032-FAEF62EFBF22 +# segment: 工作负责人确认安全措施 +# - status: 6 +# flowId: sid-5476EB52-438F-4C74-94FB-88A6EA6625EA +# segment: 工作负责人确认工作内容执行 +# - status: 7 +# flowId: sid-72E8C993-D426-476F-BF7F-F7EC3B783022 +# segment: 许可人确认工作票结束、终结 +# - status: 8 +# flowId: sid-308606FE-820A-4A23-AF2A-4B1E9BBD267C +# segment: 工作负责人确认工作票结束、终结 +# - status: 9 +# flowId: sid-DABC1AF3-EB78-4913-8BFE-EA44C887B418 +# segment: 签发人审核 +# - status: 10 +# flowId: sid-48995D69-1E09-4ED2-8C81-5D1A6D015FA5 +# segment: 许可人许可 +# - status: 11 +# flowId: sid-FB7BF0B3-5189-437F-B29D-B87E22A81460 +# segment: 工作票转移 +# - status: 12 +# flowId: sid-6358A80D-F592-4875-B281-A5B14A0EA39E +# segment: 工作票延期 + + + + diff --git a/hzims-service/ticket/src/main/resources/bootstrap.yml b/hzims-service/ticket/src/main/resources/bootstrap.yml index e69de29..4e6ce20 100644 --- a/hzims-service/ticket/src/main/resources/bootstrap.yml +++ b/hzims-service/ticket/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +spring: + cloud: + nacos: + discovery: + server-addr: 175.6.40.67:10042 + config: + extension-configs: + - data-id: hzims-ticket-dev.yaml + group: DEFAULT_GROUP + refresh: true + namespace: public + diff --git a/hzims-service/ticket/src/test/resources/application.yml b/hzims-service/ticket/src/test/resources/application.yml index 55bbe60..ed15fa0 100644 --- a/hzims-service/ticket/src/test/resources/application.yml +++ b/hzims-service/ticket/src/test/resources/application.yml @@ -9,3 +9,7 @@ swagger: base-packages: - org.springbalde - com.hnac + + + +