From c98b031bcb135a398416a158d037b0900c8fabd5 Mon Sep 17 00:00:00 2001 From: jiangxiaoming <7548901@qq.com> Date: Tue, 10 Sep 2024 10:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=AD=E8=AF=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/EntryCommandServiceImpl.java | 9 ++ .../seasky/ledgerincome/aspect/LogAspect.java | 9 +- .../repository/VoucherRepositoryImpl.java | 7 +- .../ledgerincome/utils/VoucherUtil.java | 124 +++++++++++------- 4 files changed, 97 insertions(+), 52 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 c964eefa..2d73d507 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 @@ -289,6 +289,9 @@ public class EntryCommandServiceImpl extends BaseControllerImpl implements Entry Long incomeId = cmd.getIncomeId(); Long voucherId = null; IncomeAggregate incomeAggregate = incomeRepository.findById(incomeId); + if(incomeAggregate.getReceiptBillVo().getIncomeSpeed().equals(IncomeSpeedEnum.鍏ヨ处.getValue())){ + throw new RuntimeException("宸茬粡鍏ヨ处鐨勫洖鍗曚笉鍏佽鍐嶆鍏ヨ处"); + } EntryBillAggregate entryBillAggregate = entryBillRepository.findByIncomeId(incomeId); List<EntryBillFlowEntity> flowEntityList = new ArrayList<>(); if(StringUtils.isNotEmpty(cmd.getVoucherCode())&& ObjectUtil.isNotEmpty(cmd.getVoucherDate())){ @@ -336,6 +339,9 @@ public class EntryCommandServiceImpl extends BaseControllerImpl implements Entry //1 Long incomeId = cmd.getIncomeId(); IncomeAggregate incomeAggregate = incomeRepository.findById(incomeId); + if(incomeAggregate.getReceiptBillVo().getIncomeSpeed().equals(IncomeSpeedEnum.鍏ヨ处.getValue())){ + throw new RuntimeException("宸茬粡鍏ヨ处鐨勫洖鍗曚笉鍏佽鍐嶆鍏ヨ处"); + } //2 鏌ヨ鍙戠エ List<Long> invoiceIds = incomeInvoiceQueryService.findPreInvoiceIdsWith(incomeId); if(invoiceIds == null || invoiceIds.isEmpty()){ @@ -395,6 +401,9 @@ public class EntryCommandServiceImpl extends BaseControllerImpl implements Entry @Override public void entryIncomeWithInvoice(SuppInvoiceCmd cmd) { IncomeAggregate incomeAggregate = incomeRepository.findById(cmd.getIncomeId()); + if(incomeAggregate.getReceiptBillVo().getIncomeSpeed().equals(IncomeSpeedEnum.鍏ヨ处.getValue())){ + throw new RuntimeException("宸茬粡鍏ヨ处鐨勫洖鍗曚笉鍏佽鍐嶆鍏ヨ处"); + } //1.淇濆瓨鍙戠エ InvoiceAggergate aggergate = InvoiceAssembler.toSuppInvoiceAggergate(cmd); aggergate.setInvoiceType(InvoiceTypeEnum.鍚屾寮€绁�.getValue()); 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 ba3bbe27..fe1934b5 100644 --- a/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java +++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/aspect/LogAspect.java @@ -48,7 +48,7 @@ public class LogAspect extends BaseControllerImpl { public void logPointcut() {} @Around("execution(* com.seasky.ledgerincome.interfaces.controller.*.*(..))") - public Object doAroundAdvice(ProceedingJoinPoint point) { + public Object doAroundAdvice(ProceedingJoinPoint point) throws Throwable { String userName = ""; String methodName = ""; try{ @@ -66,9 +66,14 @@ public class LogAspect extends BaseControllerImpl { logger.info("鐢ㄦ埛 [{}] 寮€濮嬫搷浣滄柟娉� [{}], 鍏ュ弬 [{}]", userName,methodName, arg); return point.proceed(); }catch (Throwable e) { + if (e instanceof RuntimeException) { + e.printStackTrace(); + logger.error("鐢ㄦ埛 [{}] 鎿嶄綔鏂规硶 [{}], 寮傚父 [{}]", userName,methodName, e); + throw ExceptionUtil.getException(null,e.getMessage()); + } e.printStackTrace(); logger.error("鐢ㄦ埛 [{}] 鎿嶄綔鏂规硶 [{}], 寮傚父 [{}]", userName,methodName, e); - throw ExceptionUtil.getException(null,e.getCause().getMessage()); + throw e; } } diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/repository/VoucherRepositoryImpl.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/repository/VoucherRepositoryImpl.java index 277d15db..1ad1f187 100644 --- a/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/repository/VoucherRepositoryImpl.java +++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/repository/VoucherRepositoryImpl.java @@ -8,8 +8,6 @@ import com.seasky.ledgerincome.domain.aggregate.voucher.VoucherAggregate; import com.seasky.ledgerincome.domain.aggregate.voucher.VoucherRepository; import com.seasky.ledgerincome.infrastructure.mapper.api.VoucherDetailMapper; import com.seasky.ledgerincome.infrastructure.mapper.api.VoucherMapper; -import com.seasky.ledgerincome.infrastructure.po.EntryBillFlowPo; -import com.seasky.ledgerincome.infrastructure.po.EntryBillPo; import com.seasky.ledgerincome.infrastructure.po.VoucherDetailPo; import com.seasky.ledgerincome.infrastructure.po.VoucherPo; import com.seasky.ledgerincome.infrastructure.repository.convert.VoucherConvert; @@ -24,6 +22,7 @@ import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -87,11 +86,11 @@ public class VoucherRepositoryImpl implements VoucherRepository { detailService.logicDeleteBatch(longList); } List<VchDetailEntity> saveBatchList = vchDetailList.stream().filter(t -> t.getId() == null).collect(Collectors.toList()); + AtomicInteger maxFlowIndex = new AtomicInteger(getMaxFlowIndex(po.getId())); if(saveBatchList!=null && !saveBatchList.isEmpty()){ saveBatchList.forEach(t->{ - Integer maxFlowIndex = getMaxFlowIndex(po.getId()); t.setVoucherId(po.getId()); - t.setRowIndex(maxFlowIndex); + t.setRowIndex(maxFlowIndex.incrementAndGet()); VoucherDetailPo detailPo = VoucherConvert.entityDetailToDetailPo(t); detailService.insert(detailPo); }); diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/VoucherUtil.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/VoucherUtil.java index 64913954..fb8fa879 100644 --- a/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/VoucherUtil.java +++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/VoucherUtil.java @@ -16,12 +16,15 @@ import com.seasky.ledgerincome.domain.enums.InvoiceTypeEnum; import com.seasky.ledgerincome.domain.enums.VoucherStateEnum; import com.seasky.ledgerincome.domain.value.AccountVo; import com.seasky.ledgerincome.domain.value.ReceiptBillVo; +import com.seasky.ledgerincome.infrastructure.mapper.api.BankAccountNumberMapper; import com.seasky.ledgerincome.infrastructure.mapper.api.EntryRuleMapper; import com.seasky.ledgerincome.infrastructure.mapper.api.EntryRuleSpecialMapper; import com.seasky.ledgerincome.infrastructure.mapper.api.InvoiceMapper; +import com.seasky.ledgerincome.infrastructure.po.BankAccountNumberPo; import com.seasky.ledgerincome.infrastructure.po.EntryRulePo; import com.seasky.ledgerincome.infrastructure.po.EntryRuleSpecialPo; import com.seasky.ledgerincome.infrastructure.po.VoucherPo; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -41,6 +44,7 @@ import java.util.regex.Pattern; * @Date 2024/8/16 15:54 * @Version 1.0 */ +@Slf4j @Component public class VoucherUtil { @@ -58,24 +62,23 @@ public class VoucherUtil { InvoiceMapper invoiceMapper; @Autowired EntryRuleSpecialMapper entryRuleSpecialMapper; + @Autowired + BankAccountNumberMapper bankAccountNumberMapper; //鏍规嵁鍏ヨ处瑙勫垯鐢熸垚鍑瘉 public VoucherAggregate generateVoucher(IncomeAggregate incomeAggregate, String isInvoicing,String voucherState){ try{ String incomeTypeName = incomeAggregate.getReceiptBillVo().getIncomeTypeName(); - String projectTypeName = incomeAggregate.getIncomeProject(); + String projectType = incomeAggregate.getIncomeProject(); Long incomeId = incomeAggregate.getIncomeId(); if(incomeTypeName == null){ incomeTypeName = "Z-寰呰棰�"; } //濡傛灉鏄ˉ寮€绁� 鍙栬ˉ寮€椤圭洰 - String projectType =""; Boolean isSupplementary = incomeAggregate.getIsSupplementary(); if(isSupplementary){ projectType = incomeAggregate.getReceiptBillVo().getRepairProject(); - }else{ - projectType = incomeAggregate.getReceiptBillVo().getProjectTypeName(); } - if(projectTypeName == null){ + if(projectType == null){ projectType = "寰呰棰�"; } @@ -90,6 +93,7 @@ public class VoucherUtil { voucherAggregate = new VoucherAggregate(incomeId, null, null, null, null, voucherState, vchDetailList); } + toVchDetailList(incomeAggregate,vchDetailList,entryRulePos); voucherAggregate.setVchDetailList(vchDetailList); return voucherAggregate; @@ -100,48 +104,44 @@ public class VoucherUtil { public List<EntryRulePo> queryList(String incomeTypeName,String projectType,String isInvoicing){ QueryWrapper<EntryRulePo> queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("income_type",incomeTypeName); + queryWrapper.eq("income_type", incomeTypeName) + .eq("invoicing", isInvoicing); + if ( Arrays.asList("搴旂即璐㈡斂涓撴埛娆�","宸ヨ祫琛ュ樊","搴斾氦鍥藉簱娆�").contains(incomeTypeName)) { + queryWrapper.and(wrapper -> wrapper.isNull("project_type").or().eq("project_type", "")); + } else { + queryWrapper.isNotNull("project_type"); + } if(!StringUtils.isEmpty(projectType) && "寰呰棰�".equals(projectType)){ queryWrapper.eq("project_type", projectType); }else{ - //绗竴绉嶆儏鍐� 鏁版嵁搴撻」鐩被鍨嬫槸绾瓧姣� + //INSTR 鏄� MySQL 鐨勪竴涓嚱鏁帮紝杩斿洖瀛愬瓧绗︿覆鍦ㄥ瓧绗︿覆涓涓€娆″嚭鐜扮殑浣嶇疆銆� // INSTR('DK0001', project_type) = 1 琛ㄧず project_type 鏄� DK0001 鐨勫墠缂€銆� // 娣诲姞 INSTR 鏉′欢鍖归厤鏌ヨ瀛楃涓插紑澶达紝鍚屾椂娣诲姞 REGEXP 鏉′欢纭繚 income_type 瀛楁涓虹函瀛楁瘝 - queryWrapper.apply("INSTR({0}, project_type) = 1 AND project_type REGEXP '^[A-Za-z]+$'", projectType); - //绗簩绉嶆儏鍐� 鏁版嵁搴撻」鐩被鍨嬪寘鍚�* 閫氶厤绗︾殑鎰忔€� - String finalProjectType = projectType; - queryWrapper.or(wrapper -> wrapper - .apply("INSTR({0}, '*') > 0", "project_type") // 妫€鏌ユ槸鍚﹀寘鍚槦鍙� - .apply("REPLACE(project_type, '*', '%') LIKE {0}", finalProjectType) - // 棰濆娣诲姞闀垮害妫€鏌ワ紝纭繚闀垮害绮剧‘鍖归厤 - .apply("LENGTH(REPLACE(project_type, '*', '')) = LENGTH({0})", finalProjectType.replaceAll("[^a-zA-Z0-9]", ""))); + // 灏嗗鏉傛煡璇㈡潯浠跺寘瑁瑰湪涓€涓� `or` 鏉′欢涓� + queryWrapper.and(wrapper -> wrapper + // 绗竴绉嶆儏鍐碉細鏁版嵁搴撳瓧娈垫槸绾瓧姣嶏紝涓斿尮閰嶄紶鍏ュ€煎墠缂€ + .or(w -> w.apply("INSTR({0}, project_type) = 1 AND project_type REGEXP '^[A-Za-z]+$'", projectType)) - //绗笁绉嶆儏鍐� - //棣栦綅鏄瓧姣嶇浜屼綅鏄� - - queryWrapper.or(wrapper -> wrapper - .apply("SUBSTRING(project_type, 1, 1) = {0}", finalProjectType.charAt(0)) // 棣栧瓧姣嶅尮閰� - .apply("SUBSTRING(project_type, 2, 1) = '-'") // 绗簩涓瓧绗︽槸 '-' - ); - //绗洓绉嶆儏鍐� 棣栦綅鏄瓧姣� 鍚庨潰鍏ㄦ槸涓枃 - // 姝e垯琛ㄨ揪寮忚В閲婏細纭繚棣栧瓧绗︿负 'A' 涓斿悗缁瓧绗︿负涓枃 - queryWrapper.or(wrapper -> wrapper - .apply("project_type REGEXP {0}", "^" + finalProjectType.charAt(0) + "[\\u4e00-\\u9fa5]+") - ); - //绗簲绉嶆儏鍐� 鏁版嵁搴撳瓧娈靛叏鏄腑鏂� - // 鏉′欢锛氬尮閰嶅叏涓枃瀛楁 - queryWrapper.or(wrapper -> wrapper - .apply("project_type REGEXP {0}", "^[\\u4e00-\\u9fa5]+$") // 鍏ㄤ腑鏂囧尮閰� - .like("project_type", finalProjectType) // 鐢ㄦ埛杈撳叆鐨勫尮閰� - ); - // 鏉′欢锛氬尮閰嶅惈鏈� `/` 鐨勫瓧娈� - queryWrapper.or(wrapper -> wrapper - .apply("project_type REGEXP {0}", "^[\\u4e00-\\u9fa5]+/[\\u4e00-\\u9fa5]+$") // 鍖呭惈 `/` 鐨勪腑鏂囧瓧娈� - .apply("FIND_IN_SET({0}, REPLACE(project_type, '/', ',')) > 0", finalProjectType) // 鎸� `/` 鍒嗗壊鍚庡尮閰� + // 绗簩绉嶆儏鍐碉細鏁版嵁搴撳瓧娈靛寘鍚� * 閫氶厤绗︼紝杩涜鍖归厤 + .or(w -> w + .apply("INSTR(project_type, '*') > 0") + .apply("{0} LIKE REPLACE(project_type, '*', '%') ", projectType.replace('*', '%'))) + + // 绗笁绉嶆儏鍐碉細棣栦綅鏄瓧姣嶄笖绗簩浣嶆槸 '-' + .or(w -> w.apply("SUBSTRING(project_type, 1, 1) = {0} AND SUBSTRING(project_type, 2, 1) = '-'", projectType.charAt(0))) + + // 绗洓绉嶆儏鍐碉細棣栧瓧姣嶆槸瀛楁瘝锛屽悗闈㈠叏鏄腑鏂� + .or(w -> w.apply("project_type REGEXP {0}", "^" + projectType.charAt(0) + "[\\u4e00-\\u9fa5]+")) + + // 绗簲绉嶆儏鍐碉細鏁版嵁搴撳瓧娈靛叏鏄腑鏂� + .or(w -> w.apply("project_type REGEXP {0}", "^[\\u4e00-\\u9fa5]+$").like("project_type", projectType)) + + // 绗叚绉嶆儏鍐碉細鏁版嵁搴撳瓧娈靛寘鍚� `/`锛屾寜 `/` 鍒嗗壊鍚庡尮閰嶅叾涓换鎰忎竴涓� + .or(w -> w.apply("project_type REGEXP {0}", "^[\\u4e00-\\u9fa5]+/[\\u4e00-\\u9fa5]+$") + .apply("FIND_IN_SET({0}, REPLACE(project_type, '/', ',')) > 0", projectType)) ); } - queryWrapper.eq("invoicing",isInvoicing); - queryWrapper.eq("available", Available.YES); List<EntryRulePo> entryRulePos = entryRuleMapper.selectList(queryWrapper); return entryRulePos; } @@ -150,10 +150,30 @@ public class VoucherUtil { Map<String, String> stringMap = transformMapDataType(incomeAggregate); for (EntryRulePo rulePo:entryRulePos) { VchDetailEntity vchDetailEntity = new VchDetailEntity(); - if(!StringUtils.isEmpty(rulePo.getVchAcctCode()) && "閾惰璐︽埛".equals(rulePo.getVchAcctCode())){ + //1.瀹氭湡瀛樻 鍏堜笉鍋氥€� + if(!StringUtils.isEmpty(rulePo.getVchAcctCode()) && !StringUtils.isEmpty(rulePo.getProjectType()) + && rulePo.getIncomeType().equals("瀹氭湡瀛樻") + && incomeAggregate.getInComeAccount().getAccountName().equals(rulePo.getBuinsessType())){ + //special(incomeAggregate,rulePo,vchDetailList); + continue; + } + //2.搴斾氦璐㈡斂涓撴埛娆� 璐锋柟 鎷� + if(!StringUtils.isEmpty(rulePo.getVchAcctCode()) && !StringUtils.isEmpty(rulePo.getProjectType()) + && rulePo.getDeorcr() == -1 + && rulePo.getIncomeType().equals("搴斾氦璐㈡斂涓撴埛娆�") + ){ + special(incomeAggregate,rulePo,vchDetailList); + continue; + } + // 3.宸ヨ祫閫€鍥� 鎷嗗垎閲戦 + if(!StringUtils.isEmpty(rulePo.getVchAcctCode()) && !StringUtils.isEmpty(rulePo.getProjectType()) + && rulePo.getDeorcr() == -1 + && rulePo.getIncomeType().equals("宸ヨ祫閫€鍥�")){ special(incomeAggregate,rulePo,vchDetailList); continue; } + + String deptCode = rulePo.getDeptCode(); if(!StringUtils.isEmpty(deptCode) && deptCode.equals("琛ュ厖椤圭洰鎵€鎸傞儴闂�")){ String repairProject = incomeAggregate.getReceiptBillVo().getRepairProject(); @@ -180,7 +200,15 @@ public class VoucherUtil { //棰濆害 vchDetailEntity.setControlCode(rulePo.getControlCode()); //绉戠洰 - vchDetailEntity.setVchAcctCode(rulePo.getVchAcctCode()); + if(!StringUtils.isEmpty(rulePo.getVchAcctCode()) + && rulePo.getVchAcctCode().equals("閾惰璐︽埛") + ){ + String account = incomeAggregate.getInComeAccount().getAccount(); + String acctCode = findVchAcctCode(account); + vchDetailEntity.setVchAcctCode(acctCode); + }else{ + vchDetailEntity.setVchAcctCode(rulePo.getVchAcctCode()); + } //鎽樿 String summary = rulePo.getSummary(); summary = generateSummary(summary, stringMap); @@ -196,6 +224,16 @@ public class VoucherUtil { } } + public String findVchAcctCode(String incomeAccount){ + QueryWrapper<BankAccountNumberPo> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("bank_number",incomeAccount); + queryWrapper.last("limit 1"); + BankAccountNumberPo numberPo = bankAccountNumberMapper.selectOne(queryWrapper); + if(numberPo==null || numberPo.getAccountCode() == null){ + return null; + } + return numberPo.getAccountCode(); + } private void special(IncomeAggregate incomeAggregate,EntryRulePo rulePo,List<VchDetailEntity> vchDetailList){ Long incomeId = incomeAggregate.getIncomeId(); Map<String, String> stringMap = transformMapDataType(incomeAggregate); @@ -232,12 +270,6 @@ public class VoucherUtil { vchDetailEntity.setVchAcctCode(rulePo.getVchAcctCode()); String summary = rulePo.getSummary(); summary = generateSummary(summary, stringMap); - if(entryRuleSpecialPo.getPrincipal()!=null && entryRuleSpecialPo.getPrincipal().compareTo(BigDecimal.ZERO)>0){ - summary = summary.replace("鍜屽埄鎭�",""); - } - if(entryRuleSpecialPo.getInterest()!=null && entryRuleSpecialPo.getInterest().compareTo(BigDecimal.ZERO)>0){ - summary = summary.replace("鏈噾鍜�",""); - } vchDetailEntity.setSummery(summary); } } -- GitLab