FlowNoService.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. package easydo.technology.service;
  2. import easydo.technology.components.JdbcClient;
  3. import easydo.technology.enums.MESEnum;
  4. import easydo.technology.exception.BizException;
  5. import easydo.technology.model.*;
  6. import easydo.technology.utils.StringUtil;
  7. import org.springframework.stereotype.Service;
  8. import javax.annotation.Resource;
  9. import javax.sql.DataSource;
  10. import java.sql.Connection;
  11. import java.time.LocalDateTime;
  12. import java.time.format.DateTimeFormatter;
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. @Service
  16. public class FlowNoService {
  17. private static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  18. private static final DateTimeFormatter DFY_MD_2 = DateTimeFormatter.ofPattern("yyyyMMdd");
  19. @Resource
  20. private JdbcClient jdbcClient;
  21. @Resource
  22. private DataSource dataSource;
  23. // 为每个类定义独立的私有锁,实现细粒度并发控制 (Warehouse 锁 Warehouse)
  24. private final Object warehouseLock = new Object();
  25. private final Object qualityLock = new Object();
  26. private final Object processStageLock = new Object();
  27. private final Object processRouteLock = new Object();
  28. private final Object productMaterialLock = new Object();
  29. private final Object customerLock = new Object();
  30. private final Object productBomLock = new Object();
  31. private final Object salePlanLock = new Object();
  32. private final Object purchasePlanLock = new Object();
  33. private final Object outsourcingPlanLock = new Object();
  34. private final Object productPlanLock = new Object();
  35. private final Object purchaseOrderLock = new Object();
  36. private final Object productOrderLock = new Object();
  37. private final Object productOrderDispatchLock = new Object();
  38. private final Object materialRequisitionLock = new Object();
  39. private final Object warehouseOutboundLock = new Object();
  40. /**
  41. * 生成仓库编码 (Warehouse) - 独立解耦实现
  42. */
  43. public String generateWarehouseCode(Warehouse model, Connection connection) throws Exception {
  44. synchronized (warehouseLock) {
  45. String manualCode = model.getCode();
  46. String tenantId = model.getTenantId();
  47. if (StringUtil.isNotEmpty(manualCode)) {
  48. Map<String, Object> checkMap = new HashMap<>();
  49. checkMap.put("code", manualCode);
  50. checkMap.put("tenantId", tenantId);
  51. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Warehouse.class, connection);
  52. if (count > 0) {
  53. throw new BizException("仓库编号已存在: " + manualCode);
  54. }
  55. return manualCode;
  56. }
  57. while (true) {
  58. FlowNo flowNo = new FlowNo();
  59. flowNo.setType(MESEnum.FLOW_NO_TYPE_WAREHOUSE.getValue());
  60. flowNo.setTenantId(tenantId);
  61. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  62. if (flowNo == null) throw new BizException("未配置仓库流水号规则");
  63. String currDate = DFY_MD.format(LocalDateTime.now());
  64. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  65. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  66. flowNo.setCurrDate(currDate);
  67. flowNo.setCurrSeq(1);
  68. } else {
  69. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  70. }
  71. String no;
  72. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  73. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  74. } else {
  75. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  76. }
  77. flowNo.setCurrNo(no);
  78. Map<String, Object> updateMap = new HashMap<>();
  79. updateMap.put("type", MESEnum.FLOW_NO_TYPE_WAREHOUSE.getValue());
  80. updateMap.put("tenantId", tenantId);
  81. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  82. Map<String, Object> checkMap = new HashMap<>();
  83. checkMap.put("code", no);
  84. checkMap.put("tenantId", tenantId);
  85. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Warehouse.class, connection);
  86. if (count == 0) return no;
  87. }
  88. }
  89. }
  90. /**
  91. * 生成质检方案编码 (QualityInspectProgram) - 独立解耦实现
  92. */
  93. public String generateQualityCode(QualityInspectProgram model, Connection connection) throws Exception {
  94. synchronized (qualityLock) {
  95. String manualCode = model.getCode();
  96. String tenantId = model.getTenantId();
  97. if (StringUtil.isNotEmpty(manualCode)) {
  98. Map<String, Object> checkMap = new HashMap<>();
  99. checkMap.put("code", manualCode);
  100. checkMap.put("tenantId", tenantId);
  101. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, QualityInspectProgram.class, connection);
  102. if (count > 0) {
  103. throw new BizException("质检编号已存在: " + manualCode);
  104. }
  105. return manualCode;
  106. }
  107. while (true) {
  108. FlowNo flowNo = new FlowNo();
  109. flowNo.setType(MESEnum.FLOW_NO_TYPE_QUALITY_INSPECT_PROGRAM.getValue());
  110. flowNo.setTenantId(tenantId);
  111. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  112. if (flowNo == null) throw new BizException("未配置质检流水号规则");
  113. String currDate = DFY_MD.format(LocalDateTime.now());
  114. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  115. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  116. flowNo.setCurrDate(currDate);
  117. flowNo.setCurrSeq(1);
  118. } else {
  119. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  120. }
  121. String no;
  122. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  123. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  124. } else {
  125. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  126. }
  127. flowNo.setCurrNo(no);
  128. Map<String, Object> updateMap = new HashMap<>();
  129. updateMap.put("type", MESEnum.FLOW_NO_TYPE_QUALITY_INSPECT_PROGRAM.getValue());
  130. updateMap.put("tenantId", tenantId);
  131. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  132. Map<String, Object> checkMap = new HashMap<>();
  133. checkMap.put("code", no);
  134. checkMap.put("tenantId", tenantId);
  135. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, QualityInspectProgram.class, connection);
  136. if (count == 0) return no;
  137. }
  138. }
  139. }
  140. /**
  141. * 生成工序管理编码 (ProcessStage) - 独立解耦实现
  142. */
  143. public String generateProcessStageCode(ProcessStage model, Connection connection) throws Exception {
  144. synchronized (processStageLock) {
  145. String manualCode = model.getCode();
  146. String tenantId = model.getTenantId();
  147. if (StringUtil.isNotEmpty(manualCode)) {
  148. Map<String, Object> checkMap = new HashMap<>();
  149. checkMap.put("code", manualCode);
  150. checkMap.put("tenantId", tenantId);
  151. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProcessStage.class, connection);
  152. if (count > 0) {
  153. throw new BizException("工序编号已存在: " + manualCode);
  154. }
  155. return manualCode;
  156. }
  157. while (true) {
  158. FlowNo flowNo = new FlowNo();
  159. flowNo.setType(MESEnum.FLOW_NO_TYPE_PROCESS_STAGE.getValue());
  160. flowNo.setTenantId(tenantId);
  161. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  162. if (flowNo == null) throw new BizException("未配置工序流水号规则");
  163. String currDate = DFY_MD.format(LocalDateTime.now());
  164. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  165. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  166. flowNo.setCurrDate(currDate);
  167. flowNo.setCurrSeq(1);
  168. } else {
  169. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  170. }
  171. String no;
  172. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  173. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  174. } else {
  175. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  176. }
  177. flowNo.setCurrNo(no);
  178. Map<String, Object> updateMap = new HashMap<>();
  179. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PROCESS_STAGE.getValue());
  180. updateMap.put("tenantId", tenantId);
  181. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  182. Map<String, Object> checkMap = new HashMap<>();
  183. checkMap.put("code", no);
  184. checkMap.put("tenantId", tenantId);
  185. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProcessStage.class, connection);
  186. if (count == 0) return no;
  187. }
  188. }
  189. }
  190. /**
  191. * 生成工艺路线编码 (ProcessRoute) - 独立解耦实现
  192. */
  193. public String generateProcessRouteCode(ProcessRoute model, Connection connection) throws Exception {
  194. synchronized (processRouteLock) {
  195. String manualCode = model.getCode();
  196. String tenantId = model.getTenantId();
  197. if (StringUtil.isNotEmpty(manualCode)) {
  198. Map<String, Object> checkMap = new HashMap<>();
  199. checkMap.put("code", manualCode);
  200. checkMap.put("tenantId", tenantId);
  201. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProcessRoute.class, connection);
  202. if (count > 0) {
  203. throw new BizException("工艺路线编号已存在: " + manualCode);
  204. }
  205. return manualCode;
  206. }
  207. while (true) {
  208. FlowNo flowNo = new FlowNo();
  209. flowNo.setType(MESEnum.FLOW_NO_TYPE_PROCESS_ROUTE.getValue());
  210. flowNo.setTenantId(tenantId);
  211. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  212. if (flowNo == null) throw new BizException("未配置工艺路线流水号规则");
  213. String currDate = DFY_MD.format(LocalDateTime.now());
  214. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  215. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  216. flowNo.setCurrDate(currDate);
  217. flowNo.setCurrSeq(1);
  218. } else {
  219. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  220. }
  221. String no;
  222. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  223. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  224. } else {
  225. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  226. }
  227. flowNo.setCurrNo(no);
  228. Map<String, Object> updateMap = new HashMap<>();
  229. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PROCESS_ROUTE.getValue());
  230. updateMap.put("tenantId", tenantId);
  231. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  232. Map<String, Object> checkMap = new HashMap<>();
  233. checkMap.put("code", no);
  234. checkMap.put("tenantId", tenantId);
  235. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProcessRoute.class, connection);
  236. if (count == 0) return no;
  237. }
  238. }
  239. }
  240. /**
  241. * 生成物料编码 (ProductMaterial) - 独立解耦实现
  242. */
  243. public String generateProductMaterialCode(ProductMaterial model, Connection connection) throws Exception {
  244. synchronized (productMaterialLock) {
  245. String manualCode = model.getCode();
  246. String tenantId = model.getTenantId();
  247. if (StringUtil.isNotEmpty(manualCode)) {
  248. Map<String, Object> checkMap = new HashMap<>();
  249. checkMap.put("code", manualCode);
  250. checkMap.put("tenantId", tenantId);
  251. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductMaterial.class, connection);
  252. if (count > 0) {
  253. throw new BizException("物料编号已存在: " + manualCode);
  254. }
  255. return manualCode;
  256. }
  257. while (true) {
  258. FlowNo flowNo = new FlowNo();
  259. flowNo.setType(MESEnum.FLOW_NO_TYPE_PRODUCT_MATERIAL.getValue());
  260. flowNo.setTenantId(tenantId);
  261. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  262. if (flowNo == null) throw new BizException("未配置物料流水号规则");
  263. String currDate = DFY_MD.format(LocalDateTime.now());
  264. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  265. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  266. flowNo.setCurrDate(currDate);
  267. flowNo.setCurrSeq(1);
  268. } else {
  269. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  270. }
  271. String no;
  272. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  273. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  274. } else {
  275. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  276. }
  277. flowNo.setCurrNo(no);
  278. Map<String, Object> updateMap = new HashMap<>();
  279. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PRODUCT_MATERIAL.getValue());
  280. updateMap.put("tenantId", tenantId);
  281. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  282. Map<String, Object> checkMap = new HashMap<>();
  283. checkMap.put("code", no);
  284. checkMap.put("tenantId", tenantId);
  285. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductMaterial.class, connection);
  286. if (count == 0) return no;
  287. }
  288. }
  289. }
  290. /**
  291. * 生成客户编码 (Customer) - 独立解耦实现
  292. */
  293. public String generateCustomerCode(Customer model, Connection connection) throws Exception {
  294. synchronized (customerLock) {
  295. String manualCode = model.getCode();
  296. String tenantId = model.getTenantId();
  297. if (StringUtil.isNotEmpty(manualCode)) {
  298. Map<String, Object> checkMap = new HashMap<>();
  299. checkMap.put("code", manualCode);
  300. checkMap.put("tenantId", tenantId);
  301. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Customer.class, connection);
  302. if (count > 0) {
  303. throw new BizException("客户编号已存在: " + manualCode);
  304. }
  305. return manualCode;
  306. }
  307. while (true) {
  308. FlowNo flowNo = new FlowNo();
  309. flowNo.setType(MESEnum.FLOW_NO_TYPE_CUSTOMER.getValue());
  310. flowNo.setTenantId(tenantId);
  311. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  312. if (flowNo == null) throw new BizException("未配置客户流水号规则");
  313. String currDate = DFY_MD.format(LocalDateTime.now());
  314. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  315. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  316. flowNo.setCurrDate(currDate);
  317. flowNo.setCurrSeq(1);
  318. } else {
  319. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  320. }
  321. String no;
  322. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  323. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  324. } else {
  325. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  326. }
  327. flowNo.setCurrNo(no);
  328. Map<String, Object> updateMap = new HashMap<>();
  329. updateMap.put("type", MESEnum.FLOW_NO_TYPE_CUSTOMER.getValue());
  330. updateMap.put("tenantId", tenantId);
  331. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  332. Map<String, Object> checkMap = new HashMap<>();
  333. checkMap.put("code", no);
  334. checkMap.put("tenantId", tenantId);
  335. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Customer.class, connection);
  336. if (count == 0) return no;
  337. }
  338. }
  339. }
  340. /**
  341. * 生成物料BOM编码 (ProductBom) - 独立解耦实现
  342. */
  343. public String generateProductBomCode(ProductBom model, Connection connection) throws Exception {
  344. synchronized (productBomLock) {
  345. String manualCode = model.getBomCode();
  346. String tenantId = model.getTenantId();
  347. if (StringUtil.isNotEmpty(manualCode)) {
  348. Map<String, Object> checkMap = new HashMap<>();
  349. checkMap.put("bomCode", manualCode);
  350. checkMap.put("tenantId", tenantId);
  351. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductBom.class, connection);
  352. if (count > 0) {
  353. throw new BizException("BOM编号已存在: " + manualCode);
  354. }
  355. return manualCode;
  356. }
  357. while (true) {
  358. FlowNo flowNo = new FlowNo();
  359. flowNo.setType(MESEnum.FLOW_NO_TYPE_PRODUCT_BOM.getValue());
  360. flowNo.setTenantId(tenantId);
  361. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  362. if (flowNo == null) throw new BizException("未配置物料BOM流水号规则");
  363. String currDate = DFY_MD.format(LocalDateTime.now());
  364. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  365. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  366. flowNo.setCurrDate(currDate);
  367. flowNo.setCurrSeq(1);
  368. } else {
  369. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  370. }
  371. String no;
  372. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  373. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  374. } else {
  375. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  376. }
  377. flowNo.setCurrNo(no);
  378. Map<String, Object> updateMap = new HashMap<>();
  379. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PRODUCT_BOM.getValue());
  380. updateMap.put("tenantId", tenantId);
  381. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  382. Map<String, Object> checkMap = new HashMap<>();
  383. checkMap.put("bomCode", no);
  384. checkMap.put("tenantId", tenantId);
  385. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductBom.class, connection);
  386. if (count == 0) return no;
  387. }
  388. }
  389. }
  390. /**
  391. * 生成销售计划编码 (SalePlan) - 独立解耦实现
  392. */
  393. public String generateSalePlanCode(SalePlan model, Connection connection) throws Exception {
  394. synchronized (salePlanLock) {
  395. String manualCode = model.getCode();
  396. String tenantId = model.getTenantId();
  397. if (StringUtil.isNotEmpty(manualCode)) {
  398. Map<String, Object> checkMap = new HashMap<>();
  399. checkMap.put("code", manualCode);
  400. checkMap.put("tenantId", tenantId);
  401. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, SalePlan.class, connection);
  402. if (count > 0) {
  403. throw new BizException("销售计划编号已存在: " + manualCode);
  404. }
  405. return manualCode;
  406. }
  407. while (true) {
  408. FlowNo flowNo = new FlowNo();
  409. flowNo.setType(MESEnum.FLOW_NO_TYPE_SALE_PLAN.getValue());
  410. flowNo.setTenantId(tenantId);
  411. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  412. if (flowNo == null) throw new BizException("未配置销售计划流水号规则");
  413. String currDate = DFY_MD.format(LocalDateTime.now());
  414. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  415. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  416. flowNo.setCurrDate(currDate);
  417. flowNo.setCurrSeq(1);
  418. } else {
  419. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  420. }
  421. String no;
  422. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  423. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  424. } else {
  425. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  426. }
  427. flowNo.setCurrNo(no);
  428. Map<String, Object> updateMap = new HashMap<>();
  429. updateMap.put("type", MESEnum.FLOW_NO_TYPE_SALE_PLAN.getValue());
  430. updateMap.put("tenantId", tenantId);
  431. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  432. Map<String, Object> checkMap = new HashMap<>();
  433. checkMap.put("code", no);
  434. checkMap.put("tenantId", tenantId);
  435. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, SalePlan.class, connection);
  436. if (count == 0) return no;
  437. }
  438. }
  439. }
  440. /**
  441. * 生成生产计划编码 (ProductPlan) - 独立解耦实现
  442. */
  443. public String generateProductPlanCode(ProductPlan model, Connection connection) throws Exception {
  444. synchronized (productPlanLock) {
  445. String manualCode = model.getCode();
  446. String tenantId = model.getTenantId();
  447. if (StringUtil.isNotEmpty(manualCode)) {
  448. Map<String, Object> checkMap = new HashMap<>();
  449. checkMap.put("code", manualCode);
  450. checkMap.put("tenantId", tenantId);
  451. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductPlan.class, connection);
  452. if (count > 0) {
  453. throw new BizException("生产计划编号已存在: " + manualCode);
  454. }
  455. return manualCode;
  456. }
  457. while (true) {
  458. FlowNo flowNo = new FlowNo();
  459. flowNo.setType(MESEnum.FLOW_NO_TYPE_PRODUCT_PLAN.getValue());
  460. flowNo.setTenantId(tenantId);
  461. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  462. if (flowNo == null) throw new BizException("未配置生产计划流水号规则");
  463. String currDate = DFY_MD.format(LocalDateTime.now());
  464. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  465. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  466. flowNo.setCurrDate(currDate);
  467. flowNo.setCurrSeq(1);
  468. } else {
  469. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  470. }
  471. String no;
  472. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  473. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  474. } else {
  475. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  476. }
  477. flowNo.setCurrNo(no);
  478. Map<String, Object> updateMap = new HashMap<>();
  479. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PRODUCT_PLAN.getValue());
  480. updateMap.put("tenantId", tenantId);
  481. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  482. Map<String, Object> checkMap = new HashMap<>();
  483. checkMap.put("code", no);
  484. checkMap.put("tenantId", tenantId);
  485. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductPlan.class, connection);
  486. if (count == 0) return no;
  487. }
  488. }
  489. }
  490. /**
  491. * 生成采购计划编码 (PurchasePlan) - 独立解耦实现
  492. */
  493. public String generatePurchasePlanCode(PurchasePlan model, Connection connection) throws Exception {
  494. synchronized (purchasePlanLock) {
  495. String manualCode = model.getCode();
  496. String tenantId = model.getTenantId();
  497. if (StringUtil.isNotEmpty(manualCode)) {
  498. Map<String, Object> checkMap = new HashMap<>();
  499. checkMap.put("code", manualCode);
  500. checkMap.put("tenantId", tenantId);
  501. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, PurchasePlan.class, connection);
  502. if (count > 0) {
  503. throw new BizException("采购计划编号已存在: " + manualCode);
  504. }
  505. return manualCode;
  506. }
  507. while (true) {
  508. FlowNo flowNo = new FlowNo();
  509. flowNo.setType(MESEnum.FLOW_NO_TYPE_PURCHASE_PLAN.getValue());
  510. flowNo.setTenantId(tenantId);
  511. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  512. if (flowNo == null) throw new BizException("未配置采购计划流水号规则");
  513. String currDate = DFY_MD.format(LocalDateTime.now());
  514. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  515. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  516. flowNo.setCurrDate(currDate);
  517. flowNo.setCurrSeq(1);
  518. } else {
  519. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  520. }
  521. String no;
  522. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  523. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  524. } else {
  525. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  526. }
  527. flowNo.setCurrNo(no);
  528. Map<String, Object> updateMap = new HashMap<>();
  529. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PURCHASE_PLAN.getValue());
  530. updateMap.put("tenantId", tenantId);
  531. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  532. Map<String, Object> checkMap = new HashMap<>();
  533. checkMap.put("code", no);
  534. checkMap.put("tenantId", tenantId);
  535. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, PurchasePlan.class, connection);
  536. if (count == 0) return no;
  537. }
  538. }
  539. }
  540. /**
  541. * 生成委外计划编码 (OutsourcingPlan) - 独立解耦实现
  542. */
  543. public String generateOutsourcingPlanCode(OutsourcingPlan model, Connection connection) throws Exception {
  544. synchronized (outsourcingPlanLock) {
  545. String manualCode = model.getCode();
  546. String tenantId = model.getTenantId();
  547. if (StringUtil.isNotEmpty(manualCode)) {
  548. Map<String, Object> checkMap = new HashMap<>();
  549. checkMap.put("code", manualCode);
  550. checkMap.put("tenantId", tenantId);
  551. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, OutsourcingPlan.class, connection);
  552. if (count > 0) {
  553. throw new BizException("委外计划编号已存在: " + manualCode);
  554. }
  555. return manualCode;
  556. }
  557. while (true) {
  558. FlowNo flowNo = new FlowNo();
  559. flowNo.setType(MESEnum.FLOW_NO_TYPE_OUTSOURCING_PLAN.getValue());
  560. flowNo.setTenantId(tenantId);
  561. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  562. if (flowNo == null) throw new BizException("未配置委外计划流水号规则");
  563. String currDate = DFY_MD.format(LocalDateTime.now());
  564. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  565. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  566. flowNo.setCurrDate(currDate);
  567. flowNo.setCurrSeq(1);
  568. } else {
  569. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  570. }
  571. String no;
  572. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  573. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  574. } else {
  575. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  576. }
  577. flowNo.setCurrNo(no);
  578. Map<String, Object> updateMap = new HashMap<>();
  579. updateMap.put("type", MESEnum.FLOW_NO_TYPE_OUTSOURCING_PLAN.getValue());
  580. updateMap.put("tenantId", tenantId);
  581. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  582. Map<String, Object> checkMap = new HashMap<>();
  583. checkMap.put("code", no);
  584. checkMap.put("tenantId", tenantId);
  585. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, OutsourcingPlan.class, connection);
  586. if (count == 0) return no;
  587. }
  588. }
  589. }
  590. /**
  591. * 生成采购订单编码 (PurchaseOrder) - 独立解耦实现
  592. */
  593. public String generatePurchaseOrderCode(PurchaseOrder model, Connection connection) throws Exception {
  594. synchronized (purchaseOrderLock) {
  595. String manualCode = model.getCode();
  596. String tenantId = model.getTenantId();
  597. if (StringUtil.isNotEmpty(manualCode)) {
  598. Map<String, Object> checkMap = new HashMap<>();
  599. checkMap.put("code", manualCode);
  600. checkMap.put("tenantId", tenantId);
  601. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, PurchaseOrder.class, connection);
  602. if (count > 0) {
  603. throw new BizException("采购订单编号已存在: " + manualCode);
  604. }
  605. return manualCode;
  606. }
  607. while (true) {
  608. FlowNo flowNo = new FlowNo();
  609. flowNo.setType(MESEnum.FLOW_NO_TYPE_PURCHASE_ORDER.getValue());
  610. flowNo.setTenantId(tenantId);
  611. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  612. if (flowNo == null) throw new BizException("未配置采购订单流水号规则");
  613. String currDate = DFY_MD.format(LocalDateTime.now());
  614. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  615. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  616. flowNo.setCurrDate(currDate);
  617. flowNo.setCurrSeq(1);
  618. } else {
  619. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  620. }
  621. String no;
  622. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  623. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  624. } else {
  625. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  626. }
  627. flowNo.setCurrNo(no);
  628. Map<String, Object> updateMap = new HashMap<>();
  629. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PURCHASE_ORDER.getValue());
  630. updateMap.put("tenantId", tenantId);
  631. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  632. Map<String, Object> checkMap = new HashMap<>();
  633. checkMap.put("code", no);
  634. checkMap.put("tenantId", tenantId);
  635. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, PurchaseOrder.class, connection);
  636. if (count == 0) return no;
  637. }
  638. }
  639. }
  640. /**
  641. * 生成工单编码 (ProductOrder) - 独立解耦实现
  642. */
  643. public String generateProductOrderCode(ProductOrder model, Connection connection) throws Exception {
  644. synchronized (productOrderLock) {
  645. String manualCode = model.getCode();
  646. String tenantId = model.getTenantId();
  647. if (StringUtil.isNotEmpty(manualCode)) {
  648. Map<String, Object> checkMap = new HashMap<>();
  649. checkMap.put("code", manualCode);
  650. checkMap.put("tenantId", tenantId);
  651. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductOrder.class, connection);
  652. if (count > 0) {
  653. throw new BizException("工单编号已存在: " + manualCode);
  654. }
  655. return manualCode;
  656. }
  657. while (true) {
  658. FlowNo flowNo = new FlowNo();
  659. flowNo.setType(MESEnum.FLOW_NO_TYPE_PRODUCT_ORDER.getValue());
  660. flowNo.setTenantId(tenantId);
  661. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  662. if (flowNo == null) throw new BizException("未配置工单流水号规则");
  663. String currDate = DFY_MD.format(LocalDateTime.now());
  664. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  665. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  666. flowNo.setCurrDate(currDate);
  667. flowNo.setCurrSeq(1);
  668. } else {
  669. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  670. }
  671. String no;
  672. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  673. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  674. } else {
  675. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  676. }
  677. flowNo.setCurrNo(no);
  678. Map<String, Object> updateMap = new HashMap<>();
  679. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PRODUCT_ORDER.getValue());
  680. updateMap.put("tenantId", tenantId);
  681. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  682. Map<String, Object> checkMap = new HashMap<>();
  683. checkMap.put("code", no);
  684. checkMap.put("tenantId", tenantId);
  685. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductOrder.class, connection);
  686. if (count == 0) return no;
  687. }
  688. }
  689. }
  690. /**
  691. * 生成派工单编码 (ProductOrderDispatch) - 独立解耦实现
  692. */
  693. public String generateProductOrderDispatchCode(ProductOrderDispatch model, Connection connection) throws Exception {
  694. synchronized (productOrderDispatchLock) {
  695. String manualCode = model.getCode();
  696. String tenantId = model.getTenantId();
  697. if (StringUtil.isNotEmpty(manualCode)) {
  698. Map<String, Object> checkMap = new HashMap<>();
  699. checkMap.put("code", manualCode);
  700. checkMap.put("tenantId", tenantId);
  701. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductOrderDispatch.class, connection);
  702. if (count > 0) {
  703. throw new BizException("派工单编号已存在: " + manualCode);
  704. }
  705. return manualCode;
  706. }
  707. while (true) {
  708. FlowNo flowNo = new FlowNo();
  709. flowNo.setType(MESEnum.FLOW_NO_TYPE_PRODUCT_ORDER_DISPATCH.getValue());
  710. flowNo.setTenantId(tenantId);
  711. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  712. if (flowNo == null) throw new BizException("未配置派工单流水号规则");
  713. String currDate = DFY_MD.format(LocalDateTime.now());
  714. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  715. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  716. flowNo.setCurrDate(currDate);
  717. flowNo.setCurrSeq(1);
  718. } else {
  719. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  720. }
  721. String no;
  722. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  723. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  724. } else {
  725. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  726. }
  727. flowNo.setCurrNo(no);
  728. Map<String, Object> updateMap = new HashMap<>();
  729. updateMap.put("type", MESEnum.FLOW_NO_TYPE_PRODUCT_ORDER_DISPATCH.getValue());
  730. updateMap.put("tenantId", tenantId);
  731. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  732. Map<String, Object> checkMap = new HashMap<>();
  733. checkMap.put("code", no);
  734. checkMap.put("tenantId", tenantId);
  735. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, ProductOrderDispatch.class, connection);
  736. if (count == 0) return no;
  737. }
  738. }
  739. }
  740. /**
  741. * 生成领料单编码 (MaterialRequisition) - 独立解耦实现
  742. */
  743. public String generateMaterialRequisitionCode(MaterialRequisition model, Connection connection) throws Exception {
  744. synchronized (materialRequisitionLock) {
  745. String manualCode = model.getCode();
  746. String tenantId = model.getTenantId();
  747. if (StringUtil.isNotEmpty(manualCode)) {
  748. Map<String, Object> checkMap = new HashMap<>();
  749. checkMap.put("code", manualCode);
  750. checkMap.put("tenantId", tenantId);
  751. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, MaterialRequisition.class, connection);
  752. if (count > 0) {
  753. throw new BizException("领料单编号已存在: " + manualCode);
  754. }
  755. return manualCode;
  756. }
  757. while (true) {
  758. FlowNo flowNo = new FlowNo();
  759. flowNo.setType(MESEnum.FLOW_NO_TYPE_MATERIAL_REQUISITION.getValue());
  760. flowNo.setTenantId(tenantId);
  761. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  762. if (flowNo == null) throw new BizException("未配置领料单流水号规则");
  763. String currDate = DFY_MD.format(LocalDateTime.now());
  764. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  765. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  766. flowNo.setCurrDate(currDate);
  767. flowNo.setCurrSeq(1);
  768. } else {
  769. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  770. }
  771. String no;
  772. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  773. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  774. } else {
  775. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  776. }
  777. flowNo.setCurrNo(no);
  778. Map<String, Object> updateMap = new HashMap<>();
  779. updateMap.put("type", MESEnum.FLOW_NO_TYPE_MATERIAL_REQUISITION.getValue());
  780. updateMap.put("tenantId", tenantId);
  781. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  782. Map<String, Object> checkMap = new HashMap<>();
  783. checkMap.put("code", no);
  784. checkMap.put("tenantId", tenantId);
  785. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, MaterialRequisition.class, connection);
  786. if (count == 0) return no;
  787. }
  788. }
  789. }
  790. /**
  791. * 生成出库单编码 (WarehouseOutbound) - 独立解耦实现
  792. */
  793. public String generateWarehouseOutboundCode(WarehouseOutbound model, Connection connection) throws Exception {
  794. synchronized (warehouseOutboundLock) {
  795. String manualCode = model.getCode();
  796. String tenantId = model.getTenantId();
  797. if (StringUtil.isNotEmpty(manualCode)) {
  798. Map<String, Object> checkMap = new HashMap<>();
  799. checkMap.put("code", manualCode);
  800. checkMap.put("tenantId", tenantId);
  801. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, WarehouseOutbound.class, connection);
  802. if (count > 0) {
  803. throw new BizException("出库单编号已存在: " + manualCode);
  804. }
  805. return manualCode;
  806. }
  807. while (true) {
  808. FlowNo flowNo = new FlowNo();
  809. flowNo.setType(MESEnum.FLOW_NO_TYPE_WAREHOUSE_OUTBOUND.getValue());
  810. flowNo.setTenantId(tenantId);
  811. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  812. if (flowNo == null) throw new BizException("未配置出库单流水号规则");
  813. String currDate = DFY_MD.format(LocalDateTime.now());
  814. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  815. if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
  816. flowNo.setCurrDate(currDate);
  817. flowNo.setCurrSeq(1);
  818. } else {
  819. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  820. }
  821. String no;
  822. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  823. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
  824. } else {
  825. no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
  826. }
  827. flowNo.setCurrNo(no);
  828. Map<String, Object> updateMap = new HashMap<>();
  829. updateMap.put("type", MESEnum.FLOW_NO_TYPE_WAREHOUSE_OUTBOUND.getValue());
  830. updateMap.put("tenantId", tenantId);
  831. jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
  832. Map<String, Object> checkMap = new HashMap<>();
  833. checkMap.put("code", no);
  834. checkMap.put("tenantId", tenantId);
  835. int count = (int) jdbcClient.getJdbcCountByMap(checkMap, WarehouseOutbound.class, connection);
  836. if (count == 0) return no;
  837. }
  838. }
  839. }
  840. /**
  841. * 原始流水号生成方法
  842. */
  843. public String getFlowNo(String type, Connection... connections) throws Exception {
  844. Connection connection = null;
  845. if (connections.length > 0) {
  846. connection = connections[0];
  847. } else {
  848. connection = dataSource.getConnection();
  849. }
  850. try {
  851. FlowNo flowNo = new FlowNo();
  852. flowNo.setType(type);
  853. flowNo = jdbcClient.getJdbcModel(flowNo, connection);
  854. DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  855. DateTimeFormatter DFY_MD_2 = DateTimeFormatter.ofPattern("yyyyMMdd");
  856. String currDate = DFY_MD.format(LocalDateTime.now());
  857. String currDate2 = DFY_MD_2.format(LocalDateTime.now());
  858. String no;
  859. if (StringUtil.isNotEmpty(flowNo.getCurrDate()) && !flowNo.getCurrDate().equals(currDate)) {
  860. flowNo.setCurrDate(currDate);
  861. flowNo.setCurrSeq(1);
  862. } else {
  863. flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
  864. }
  865. if (StringUtil.isEmpty(flowNo.getCurrDate())) {
  866. String currSeq = String.format("%06d", flowNo.getCurrSeq());
  867. no = flowNo.getPrefix() + currSeq;
  868. } else {
  869. String currSeq = String.format("%05d", flowNo.getCurrSeq());
  870. no = flowNo.getPrefix() + currDate2 + currSeq;
  871. }
  872. flowNo.setCurrNo(no);
  873. Map<String, Object> paramMap = new HashMap<>();
  874. paramMap.put("type", type);
  875. jdbcClient.jdbcUpdate(flowNo, paramMap, connection);
  876. return no;
  877. } catch (Exception e) {
  878. throw new BizException(e.getMessage());
  879. } finally {
  880. if (connections.length == 0) {
  881. connection.close();
  882. }
  883. }
  884. }
  885. }