From e22366fdc5b20be7841522b800d5b4820fb7c909 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Thu, 23 Mar 2023 16:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E9=83=A8=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E7=94=9F=E6=88=90=E7=99=BB=E5=BD=95=E5=90=8D=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- .../GenerateLoginIdAction.java | 51 +++++++++++++++++-- .../mapper/GenerateLoginIdMapper.java | 11 ++++ src/test/java/youhong/ai/pcn/UtilTest.java | 38 ++++++++++++++ 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a1f5db0..bfc3e78 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ DirectoryV2.xml /lib/classbeanLib/ecology-dev-lib.jar /lib/classbeanLib/web-inf-class-lib.jar /lib/weaverLib/ +/lib/jitulib/ *.groovy *.log *.iml @@ -46,5 +47,5 @@ src/test/resources/font src/main/resources/WEB-INF/vm/outFile target/ *.back -src/main/old_src/ - +src/main/aiyh_old_src/ +src/main/jitu_src/ \ No newline at end of file diff --git a/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/GenerateLoginIdAction.java b/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/GenerateLoginIdAction.java index 5732d89..8a0b35f 100644 --- a/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/GenerateLoginIdAction.java +++ b/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/GenerateLoginIdAction.java @@ -15,6 +15,7 @@ import weaver.soa.workflow.request.RequestInfo; import weaver.youhong.ai.pcn.actioin.generateloginid.mapper.GenerateLoginIdMapper; import java.text.NumberFormat; +import java.util.List; import java.util.Map; /** @@ -57,9 +58,11 @@ public class GenerateLoginIdAction extends SafeCusBaseAction { Map mainTableValue = super.getMainTableValue(requestInfo); String subCompanyName = mainTableValue.get(subCompanyTextField); String subCompanyId = mapper.selectSubCompanyIdBySubCompanyName(subCompanyName); - Map lastLoginIdInfo = mapper.selectLastLoginId(subCompanyName, subCompanyId, subCompanyName + "%"); - String loginIdNo = lastLoginIdInfo.get("loginIdNo"); - String loginId = prefixFill(loginIdNo, subCompanyName); + // Map lastLoginIdInfo = mapper.selectLastLoginId(subCompanyName, subCompanyId, subCompanyName + "%"); + // String loginIdNo = lastLoginIdInfo.get("loginIdNo"); + // String loginId = prefixFill(loginIdNo, subCompanyName); + List loginIdList = mapper.selectLoginIdList(subCompanyId); + String loginId = subCompanyName + formatList(loginIdList, Integer.parseInt(numberFillQuantity)); if (mapper.updateLoginId(billTable, requestId, loginId, loginIdField)) { try { Thread.sleep(500); @@ -74,6 +77,48 @@ public class GenerateLoginIdAction extends SafeCusBaseAction { } } + + /** + *

前缀补齐

+ * + * @param list 登录名编号 + * @param length 前缀 + * @return 登录名 + */ + public String formatList(List list, int length) { + NumberFormat format = NumberFormat.getInstance(); + format.setMinimumIntegerDigits(length); + format.setGroupingUsed(false); + if (list == null || list.isEmpty()) { + return format.format(0); + } + int maxNum = 0; + for (String s : list) { + if (s != null && !s.isEmpty()) { + int num = 0; + boolean foundNum = false; + // 从末尾向前读取 + for (int i = s.length() - 1; i >= 0; i--) { + char c = s.charAt(i); + if (Character.isDigit(c)) { + foundNum = true; + int digit = c - '0'; + // 根据数字位数计算数字大小 + num += digit * Math.pow(10, s.length() - i - 1); + } else if (foundNum) { + // 遇到非数字字符,停止读取 + break; + } + } + if (num > maxNum) { + maxNum = num; + } + } + } + + return format.format(maxNum + 1); + } + /** *

前缀补齐

* diff --git a/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/mapper/GenerateLoginIdMapper.java b/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/mapper/GenerateLoginIdMapper.java index a12019d..3041419 100644 --- a/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/mapper/GenerateLoginIdMapper.java +++ b/src/main/java/weaver/youhong/ai/pcn/actioin/generateloginid/mapper/GenerateLoginIdMapper.java @@ -5,6 +5,7 @@ import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; import aiyh.utils.annotation.recordset.Update; +import java.util.List; import java.util.Map; /** @@ -47,6 +48,16 @@ public interface GenerateLoginIdMapper { ); + /** + *

查询分部下的所有人员登录账号

+ * + * @param subCompanyId 分部id + * @return 所有人员登录账号 + */ + @Select("select LOGINID from hrmresource where SUBCOMPANYID1 = #{subCompanyId}") + List selectLoginIdList(@ParamMapper("subCompanyId") String subCompanyId); + + /** *

更新流程中的loginId字段

* diff --git a/src/test/java/youhong/ai/pcn/UtilTest.java b/src/test/java/youhong/ai/pcn/UtilTest.java index f7af5c0..1c1a056 100644 --- a/src/test/java/youhong/ai/pcn/UtilTest.java +++ b/src/test/java/youhong/ai/pcn/UtilTest.java @@ -27,6 +27,7 @@ import youhong.ai.pcn.pojo.Student; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.text.NumberFormat; import java.util.*; import static com.alibaba.fastjson.JSON.parseObject; @@ -257,5 +258,42 @@ public class UtilTest extends BaseTest { @Test public void testOaNum() { + out.println(formatList(Arrays.asList("PCN2P000001", "PCNS0000002", "PDJA000003", "PDC0000405"), 10)); } + + public static String formatList(List list, int length) { + NumberFormat format = NumberFormat.getInstance(); + format.setMinimumIntegerDigits(length); + format.setGroupingUsed(false); + if (list == null || list.isEmpty()) { + return format.format(0); + } + int maxNum = 0; + for (String s : list) { + if (s != null && !s.isEmpty()) { + int num = 0; + boolean foundNum = false; + // 从末尾向前读取 + for (int i = s.length() - 1; i >= 0; i--) { + char c = s.charAt(i); + if (Character.isDigit(c)) { + foundNum = true; + int digit = c - '0'; + // 根据数字位数计算数字大小 + num += digit * Math.pow(10, s.length() - i - 1); + } else if (foundNum) { + // 遇到非数字字符,停止读取 + break; + } + } + if (num > maxNum) { + maxNum = num; + } + } + } + + return format.format(maxNum + 1); + } + + }