浏览代码

物品申购规则引擎生成编号

大数据与最优化研究所 1 年之前
父节点
当前提交
d077a70294

+ 13 - 23
src/main/java/com/xjrsoft/module/ledger/service/impl/WfSubscriptionServiceImpl.java

@@ -206,50 +206,40 @@ public class WfSubscriptionServiceImpl extends MPJBaseServiceImpl<WfSubscription
         WfSubscription wfSubscription = this.getById(formId);
 
         if(wfSubscription != null){
+
+            Date shenQingRiQi = wfSubscription.getShenQingRiQi4752();
+            LocalDate localDate = shenQingRiQi.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+
+            String year = String.valueOf(localDate.getYear());
+
             //获取当前内存中的最大编号
             LambdaQueryWrapper<WfSubscription> wfSubscriptionLambdaQueryWrapper = new LambdaQueryWrapper<>();
             wfSubscriptionLambdaQueryWrapper
                     .select(WfSubscription.class, x -> VoToColumnUtil.fieldsToColumns(WfSubscription.class).contains(x.getProperty()))
+                    .likeRight(WfSubscription::getNumber, year)
                     .orderByDesc(WfSubscription::getNumber)
                     .last("limit 1");
             WfSubscription wfSubscriptionMax = this.getOne(wfSubscriptionLambdaQueryWrapper);
             if(wfSubscriptionMax != null){
                 String number = wfSubscriptionMax.getNumber();
-                String ysarStr = "";
-                if(number != null && number.length() >= 3) {
-                    number = number.trim();
-                    ysarStr = number.substring(0, number.length() - 3);
-                }
-
-                Date shenQingRiQi = wfSubscription.getShenQingRiQi4752();
-                LocalDate localDate = shenQingRiQi.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
-
-                String year = String.valueOf(localDate.getYear());
 
                 WfSubscription wfSubscriptionNew = new WfSubscription();
 
-                if(year.equals(ysarStr)){
-                    int num = Integer.parseInt(number);
-                    num = num + 1;
-                    wfSubscriptionNew.setNumber(String.valueOf(num));
-                }else {
-                    wfSubscriptionNew.setNumber(year+"001");
-                }
+                int num = Integer.parseInt(number);
+                num = num + 1;
+                wfSubscriptionNew.setNumber(String.valueOf(num));
+
                 wfSubscriptionNew.setId(wfSubscription.getId());
                 wfSubscriptionNew.setStatus(1);
 
-                this.updateById(wfSubscriptionNew);
+                return this.updateById(wfSubscriptionNew);
             }else{
-                Date shenQingRiQi = wfSubscription.getShenQingRiQi4752();
-                LocalDate localDate = shenQingRiQi.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
-
-                String year = String.valueOf(localDate.getYear());
                 WfSubscription wfSubscriptionNew = new WfSubscription();
                 wfSubscriptionNew.setNumber(year + "001");
                 wfSubscriptionNew.setId(wfSubscription.getId());
                 wfSubscriptionNew.setStatus(1);
 
-                this.updateById(wfSubscriptionNew);
+                return this.updateById(wfSubscriptionNew);
             }
         }
         return true;

+ 1 - 1
src/test/java/com/xjrsoft/module/ledger/service/impl/WfSubscriptionServiceImplTest.java

@@ -12,6 +12,6 @@ class WfSubscriptionServiceImplTest {
     private IWfSubscriptionService wfSubscriptionService;
     @Test
     void dataHandle() {
-        wfSubscriptionService.dataHandle(1764944082720788480L);
+        wfSubscriptionService.dataHandle(1732930141714182144L);
     }
 }