From e46cde259f2823879c18bc6c83bb0a3bc84696c6 Mon Sep 17 00:00:00 2001
From: jiangxiaoming <7548901@qq.com>
Date: Fri, 22 Nov 2024 16:24:38 +0800
Subject: [PATCH 1/2] 1

---
 .../command/EntryCommandServiceImpl.java      | 149 ++++++++++--------
 1 file changed, 80 insertions(+), 69 deletions(-)

diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
index 93f5b1bf..2c483ae5 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
@@ -364,72 +364,77 @@ public class EntryCommandServiceImpl implements EntryCommandService {
     @Transactional
     @Override
     public void complete(CompleteIncomeCmd cmd) {
-        List<String> entryCodeList = cmd.getEntryCodeList();
-        if(entryCodeList == null){
-            throw new RuntimeException("entryCodeList涓虹┖");
-        }
-        Date date;
-        List<Long> entryCodeLongs = entryCodeList.stream().map(Long::parseLong).collect(Collectors.toList());
-        //浼犺繃鏉ユ槸鍏ヨ处鐢宠鍗曞彿 闇€瑕佹煡鍑篿ncomeId
-        for (Long entryCodeLong: entryCodeLongs) {
-            List<Long> incomeIds = entryBillRepository.findIncomeIds(Arrays.asList(entryCodeLong));
-            for (Long incomeId:incomeIds) {
-                //1 鏌ヨ
-                VoucherAggregate voucherAggregate = voucherRepository.findByOutOrderNo(incomeId);
-                if(voucherAggregate == null){
-                    throw ExceptionUtil.getException(null,"鏈壘鍒板搴旂殑鍑瘉"+incomeId);
-                }
-                EntryBillAggregate entryBillAggregate = entryBillRepository.findByIncomeIdWithDetail(incomeId);
-                IncomeAggregate incomeAggregate = incomeRepository.findByOutOrderNo(incomeId);
-                //瀹屾垚
-                if(cmd.getResult()!=null && cmd.getResult().intValue() == 1){
-                    try {
-                        date = new SimpleDateFormat("yyyy-MM-dd").parse(cmd.getVoucherDate());
-                    } catch (ParseException e) {
-                        throw new RuntimeException(e);
-                    }
-                    voucherAggregate.setVoucherCode(cmd.getVoucherCode());
-                    voucherAggregate.setVoucherDate(date);
-                    //3鏇存柊鍥炲崟琛� 瀹屾垚
-                    List<EntryBillFlowEntity> flowEntityList = entryBillAggregate.getFlowEntityList();
-                    if(entryBillAggregate.getVoucherState().getValue().equals(VoucherStateEnum.鏆傚瓨.getValue())){
-                        incomeAggregate.getReceiptBillVo().setIncomeSpeed(IncomeSpeedEnum.鍏ヨ处.getValue());
-                    }
-                    if(entryBillAggregate.getVoucherState().getValue().equals(VoucherStateEnum.宸插叆璐�.getValue())){
-                        incomeAggregate.getReceiptBillVo().setIncomeSpeed(IncomeSpeedEnum.瀹屾垚.getValue());
-                        //4 鏇存柊鍏ヨ处杩囩▼琛�
-                        entryBillAggregate = new EntryBillAggregate(
-                                entryBillAggregate.getEntryBillId(),incomeId,null,null,
-                                VoucherStateEnum.getByValue(VoucherStateEnum.宸插叆璐�.getValue())
-                                ,null
-                        );
-                        List<EntryBillFlowEntity> collect = flowEntityList.stream().filter(t -> t.getBatchId().equals(entryCodeLong)
-                                && t.getEntryType().getValue().equals(EntryTypeEnum.琛ュ紑绁ㄥ叆璐�.getValue())
-                        ).collect(Collectors.toList());
-                        if(collect!=null && collect.size()>0){
-                            entryBillAggregate = new EntryBillAggregate(
-                                    entryBillAggregate.getEntryBillId(),incomeId,null,null,
-                                    VoucherStateEnum.getByValue(VoucherStateEnum.琛ュ紑绁�.getValue())
-                                    ,null);
-                        }
-                    }
-                    incomeRepository.save(incomeAggregate);
-                    entryBillRepository.save(entryBillAggregate);
-                    voucherAggregate.setVoucherState(VoucherStateApplyEnum.宸插叆璐�.getValue());
-                }else{
-                    voucherAggregate.setRejectReason(cmd.getRejectReason());
-                    voucherAggregate.setVoucherState(VoucherStateApplyEnum.椹冲洖.getValue());
-                    //椹冲洖鐨勫叆璐﹁繃绋� 涓嶆樉绀�
-                    Long entryBillId = entryBillAggregate.getEntryBillId();
-                    UpdateWrapper<EntryBillFlowPo> wrapper = new UpdateWrapper<>();
-                    wrapper.set("available","NO");
-                    wrapper.eq("batch_id",entryCodeLong);
-                    wrapper.eq("entry_id",entryBillId);
-                    entryBillFlowMapper.update(null,wrapper);
+        String key = cmd.getUserCode()+"-"+cmd.getUserName();
+        String lockKey = "lock:complete:" + key;
+        Boolean success = redisTemplate.opsForValue().setIfAbsent(lockKey, "locked", LOCK_TIMEOUT, TimeUnit.SECONDS);
+        if (success != null && success) {
+             try{
+                 List<String> entryCodeList = cmd.getEntryCodeList();
+                 if(entryCodeList == null){
+                     throw new RuntimeException("entryCodeList涓虹┖");
+                 }
+                 Date date;
+                 List<Long> entryCodeLongs = entryCodeList.stream().map(Long::parseLong).collect(Collectors.toList());
+                 //浼犺繃鏉ユ槸鍏ヨ处鐢宠鍗曞彿 闇€瑕佹煡鍑篿ncomeId
+                 for (Long entryCodeLong: entryCodeLongs) {
+                     List<Long> incomeIds = entryBillRepository.findIncomeIds(Arrays.asList(entryCodeLong));
+                     for (Long incomeId : incomeIds) {
+                         //1 鏌ヨ
+                         VoucherAggregate voucherAggregate = voucherRepository.findByOutOrderNo(incomeId);
+                         if (voucherAggregate == null) {
+                             throw ExceptionUtil.getException(null, "鏈壘鍒板搴旂殑鍑瘉" + incomeId);
+                         }
+                         EntryBillAggregate entryBillAggregate = entryBillRepository.findByIncomeIdWithDetail(incomeId);
+                         IncomeAggregate incomeAggregate = incomeRepository.findByOutOrderNo(incomeId);
+                         //瀹屾垚
+                         if (cmd.getResult() != null && cmd.getResult().intValue() == 1) {
+                             try {
+                                 date = new SimpleDateFormat("yyyy-MM-dd").parse(cmd.getVoucherDate());
+                             } catch (ParseException e) {
+                                 throw new RuntimeException(e);
+                             }
+                             voucherAggregate.setVoucherCode(cmd.getVoucherCode());
+                             voucherAggregate.setVoucherDate(date);
+                             //3鏇存柊鍥炲崟琛� 瀹屾垚
+                             List<EntryBillFlowEntity> flowEntityList = entryBillAggregate.getFlowEntityList();
+                             if (entryBillAggregate.getVoucherState().getValue().equals(VoucherStateEnum.鏆傚瓨.getValue())) {
+                                 incomeAggregate.getReceiptBillVo().setIncomeSpeed(IncomeSpeedEnum.鍏ヨ处.getValue());
+                             }
+                             if (entryBillAggregate.getVoucherState().getValue().equals(VoucherStateEnum.宸插叆璐�.getValue())) {
+                                 incomeAggregate.getReceiptBillVo().setIncomeSpeed(IncomeSpeedEnum.瀹屾垚.getValue());
+                                 //4 鏇存柊鍏ヨ处杩囩▼琛�
+                                 entryBillAggregate = new EntryBillAggregate(
+                                         entryBillAggregate.getEntryBillId(), incomeId, null, null,
+                                         VoucherStateEnum.getByValue(VoucherStateEnum.宸插叆璐�.getValue())
+                                         , null
+                                 );
+                                 List<EntryBillFlowEntity> collect = flowEntityList.stream().filter(t -> t.getBatchId().equals(entryCodeLong)
+                                         && t.getEntryType().getValue().equals(EntryTypeEnum.琛ュ紑绁ㄥ叆璐�.getValue())
+                                 ).collect(Collectors.toList());
+                                 if (collect != null && collect.size() > 0) {
+                                     entryBillAggregate = new EntryBillAggregate(
+                                             entryBillAggregate.getEntryBillId(), incomeId, null, null,
+                                             VoucherStateEnum.getByValue(VoucherStateEnum.琛ュ紑绁�.getValue())
+                                             , null);
+                                 }
+                             }
+                             incomeRepository.save(incomeAggregate);
+                             entryBillRepository.save(entryBillAggregate);
+                             voucherAggregate.setVoucherState(VoucherStateApplyEnum.宸插叆璐�.getValue());
+                         } else {
+                             voucherAggregate.setRejectReason(cmd.getRejectReason());
+                             voucherAggregate.setVoucherState(VoucherStateApplyEnum.椹冲洖.getValue());
+                             //椹冲洖鐨勫叆璐﹁繃绋� 涓嶆樉绀�
+                             Long entryBillId = entryBillAggregate.getEntryBillId();
+                             UpdateWrapper<EntryBillFlowPo> wrapper = new UpdateWrapper<>();
+                             wrapper.set("available", "NO");
+                             wrapper.eq("batch_id", entryCodeLong);
+                             wrapper.eq("entry_id", entryBillId);
+                             entryBillFlowMapper.update(null, wrapper);
 
-                    //鏆傚瓨鏃跺€欓┏鍥� 鍒犻櫎鍏ヨ处杩囩▼ entry_bill_flow NO  鍥炲崟杩涘害鏀逛负鍙戝竷 2024-11-12
-                    //鍥炲崟娌℃殏瀛� 琚┏鍥炵殑
-                    //2024-11-14 鍥為€€
+                             //鏆傚瓨鏃跺€欓┏鍥� 鍒犻櫎鍏ヨ处杩囩▼ entry_bill_flow NO  鍥炲崟杩涘害鏀逛负鍙戝竷 2024-11-12
+                             //鍥炲崟娌℃殏瀛� 琚┏鍥炵殑
+                             //2024-11-14 鍥為€€
                    /* if(entryBillAggregate.getVoucherState().getValue().equals(VoucherStateEnum.鏆傚瓨.getValue())){
                         Long entryBillId = entryBillAggregate.getEntryBillId();
                         //
@@ -445,10 +450,16 @@ public class EntryCommandServiceImpl implements EntryCommandService {
                         incomeAggregate.getReceiptBillVo().setIncomeSpeed(IncomeSpeedEnum.鍙戝竷.getValue());
                         incomeRepository.save(incomeAggregate);
                     }*/
-                }
-                //2鏇存柊鍑瘉
-                voucherRepository.save(voucherAggregate);
-            }
+                         }
+                         //2鏇存柊鍑瘉
+                         voucherRepository.save(voucherAggregate);
+                     }
+                 }
+             }finally {
+                 redisTemplate.delete(lockKey);
+             }
+        }else{
+            log.info("complete鎺ュ彛鏈夊悓涓€涓敤鎴峰苟鍙戣姹傚凡鎷︽埅锛屽叆鍙傦細"+cmd.toString());
         }
     }
 
-- 
GitLab


From 77b910c74d6cedbc4d40db154e25812f95fb1205 Mon Sep 17 00:00:00 2001
From: jiangxiaoming <7548901@qq.com>
Date: Fri, 22 Nov 2024 16:37:06 +0800
Subject: [PATCH 2/2] 33

---
 .../main/java/com/seasky/ledgerincome/aspect/LogAspect.java    | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java
index 1925601a..46e433a5 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java
@@ -290,6 +290,9 @@ public class LogAspect{
                 }
                 List<Long> incomeIds = entryBillRepository.findIncomeIds(batchIds);
                 if(incomeIds!=null && incomeIds.size()>0){
+                    incomeIds = incomeIds.stream()
+                            .distinct()
+                            .collect(Collectors.toList());
                     for(Long t:incomeIds){
                         LogPo log = new LogPo(t,progressStage,personName,userName,desc,new Date());
                         logMapper.insert(log);
-- 
GitLab