From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/ZhiliangBiaozhunGuanliServiceImpl.java | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 155 insertions(+), 0 deletions(-)
diff --git a/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/ZhiliangBiaozhunGuanliServiceImpl.java b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/ZhiliangBiaozhunGuanliServiceImpl.java
new file mode 100644
index 0000000..a2ad1ea
--- /dev/null
+++ b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/ZhiliangBiaozhunGuanliServiceImpl.java
@@ -0,0 +1,155 @@
+package jnpf.limsService.impl;
+
+import jnpf.audit.sdk.annotation.AuditLog;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import jnpf.base.service.SuperServiceImpl;
+import jnpf.exception.DataException;
+import jnpf.limsEntity.BizEnabledEnum;
+import jnpf.limsEntity.ZhiliangBiaozhunGuanliEntity;
+import jnpf.limsEntity.ZhiliangBiaozhunGuanliZixiangEntity;
+import jnpf.limsMapper.ZhiliangBiaozhunGuanliMapper;
+import jnpf.limsService.ZhiliangBiaozhunGuanliService;
+import jnpf.limsService.ZhiliangBiaozhunGuanliZixiangService;
+import jnpf.util.RandomUtil;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class ZhiliangBiaozhunGuanliServiceImpl
+ extends SuperServiceImpl<ZhiliangBiaozhunGuanliMapper, ZhiliangBiaozhunGuanliEntity>
+ implements ZhiliangBiaozhunGuanliService {
+
+ @Autowired
+ private ZhiliangBiaozhunGuanliZixiangService zhiliangBiaozhunGuanliZixiangService;
+
+ /** copyProperties 鏃剁粺涓�蹇界暐鐨勭郴缁�/涓婚敭瀛楁 */
+ private static final String[] MAIN_IGNORE = {
+ "id", "tenantId",
+ "creatorUserId", "creatorTime", "lastModifyUserId", "lastModifyTime",
+ "deleteMark", "deleteTime", "deleteUserId"
+ };
+
+ private static final String[] ZIXIANG_IGNORE = {
+ "id", "foreignId", "tenantId",
+ "deleteMark", "deleteTime", "deleteUserId"
+ };
+
+ @Override
+ public ZhiliangBiaozhunGuanliEntity findByYangpinId(String yangpinId) {
+ QueryWrapper<ZhiliangBiaozhunGuanliEntity> wrapper = new QueryWrapper<>();
+ wrapper.eq("yangpin_id", yangpinId);
+ wrapper.orderByDesc("f_id");
+ wrapper.last("LIMIT 1");
+ return this.getOne(wrapper);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ @AuditLog(action = "VERSION_UPGRADE", label = "璐ㄩ噺鏍囧噯鐗堟湰鍗囩骇", bizType = "ZHILIANG_BIAOZHUN",
+ bizCodeExpr = "#result ?: ''", targetTable = "zhiliang_biaozhun_guanli",
+ targetIdExpr = "#result", diff = true,
+ entityClass = ZhiliangBiaozhunGuanliEntity.class)
+ public String versionUpgrade(Map<String, Object> formData) {
+ if (formData == null || formData.isEmpty()) {
+ throw new DataException("鍏ュ弬涓嶈兘涓虹┖");
+ }
+
+ // 璺敱澶嶇敤锛歩d 涓虹┖ = 鏂板缓鍦烘櫙锛堝疄闄呭啓鍏ョ敱 jnpf 鍦ㄧ嚎琛ㄥ崟瀹屾垚锛夛紝鐩存帴鏀捐
+ // id 鏈夊�� = 鐗堟湰鍗囩骇鍦烘櫙锛岄渶瑕佷负鏃ф暟鎹敓鎴愬巻鍙插揩鐓�
+ //
+ // 鐗堟湰鍗囩骇娴佺▼锛歫npf 琛ㄥ崟鐨� beforeSubmit 閽╁瓙鍏堣皟鐢ㄦ湰鎺ュ彛锛�
+ // 鎴戜滑鎶婂綋鍓� DB 涓殑婧愯褰曟暣浠藉鍒舵垚涓�鏉� biz_enabled=disabled 鐨勫巻鍙插揩鐓ц锛�
+ // 鎺ュ彛杩斿洖鎴愬姛鍚� jnpf 鎵嶆墽琛屽畠鍘熺敓鐨� UPDATE锛屾妸婧愯锛堝悓涓� f_id锛夋洿鏂版垚琛ㄥ崟閲�
+ // 鐢ㄦ埛濉啓鐨�"鏂扮増鏈暟鎹�"銆�
+ // 鍥犳锛氭湰鏂规硶 INSERT 鐨勯偅鏉℃柊琛� = 鍘嗗彶蹇収锛堟棫鏁版嵁锛夛紱
+ // 婧愯锛堣 jnpf 鍚庣画 UPDATE锛�= 鍗囩骇鍚庣殑褰撳墠娲昏穬鐗堟湰銆�
+ String sourceId = asString(formData.get("id"));
+ if (sourceId == null || sourceId.isEmpty()) {
+ return null;
+ }
+
+ // 1. 鐢� id 鏌ユ簮涓昏〃锛堝綋鍓嶅湪 DB 閲岀殑鏃ф暟鎹級
+ ZhiliangBiaozhunGuanliEntity source = this.getById(sourceId);
+ if (source == null) {
+ throw new DataException("鏈壘鍒板搴旂殑璐ㄩ噺鏍囧噯璁板綍锛坕d=" + sourceId + "锛�");
+ }
+
+ // 1.1 鏍¢獙鍓嶇浼犲叆鐨� biaozhun_banben 鍦� (yangpin_id, biaozhun_bianhao) 缁村害涓嬫槸鍚﹀敮涓�
+ validateBiaozhunBanbenUnique(formData, source);
+
+ // 2. 鏌ユ簮璁板綍鐨勫瓙琛ㄩ」
+ List<ZhiliangBiaozhunGuanliZixiangEntity> sourceZixiangList =
+ zhiliangBiaozhunGuanliZixiangService.listByForeignId(sourceId);
+
+ // 3. 鎶婃簮涓昏〃鏁翠綋澶嶅埗鎴�"鍘嗗彶蹇収"琛岋細鏂� f_id銆乥iz_enabled=disabled
+ String historicalSnapshotId = RandomUtil.uuId();
+ ZhiliangBiaozhunGuanliEntity historicalSnapshot = new ZhiliangBiaozhunGuanliEntity();
+ BeanUtils.copyProperties(source, historicalSnapshot, MAIN_IGNORE);
+ historicalSnapshot.setId(historicalSnapshotId);
+ historicalSnapshot.setBizEnabled(BizEnabledEnum.DISABLED.getCode());
+ // 鍏滃簳锛氬鏋� MetaObjectHandler 娌$敓鏁堬紝鑷冲皯 creatorTime 鏈夊��
+ historicalSnapshot.setCreatorTime(new Date());
+
+ this.save(historicalSnapshot);
+
+ // 4. 澶嶅埗婧愬瓙琛ㄩ」鍒板巻鍙插揩鐓т笅锛氭瘡鏉℃柊 f_id锛宖_foreign_id 鎸囧悜蹇収涓昏〃 f_id
+ if (sourceZixiangList != null && !sourceZixiangList.isEmpty()) {
+ List<ZhiliangBiaozhunGuanliZixiangEntity> historicalZixiangList = new ArrayList<>(sourceZixiangList.size());
+ for (ZhiliangBiaozhunGuanliZixiangEntity src : sourceZixiangList) {
+ ZhiliangBiaozhunGuanliZixiangEntity copy = new ZhiliangBiaozhunGuanliZixiangEntity();
+ BeanUtils.copyProperties(src, copy, ZIXIANG_IGNORE);
+ copy.setId(RandomUtil.uuId());
+ copy.setForeignId(historicalSnapshotId);
+ historicalZixiangList.add(copy);
+ }
+ zhiliangBiaozhunGuanliZixiangService.saveBatch(historicalZixiangList);
+ }
+
+ return historicalSnapshotId;
+ }
+
+ private static String asString(Object v) {
+ return v == null ? null : v.toString();
+ }
+
+ /**
+ * 浠呭仛鍓嶇鎷︽埅鐢細鏍¢獙 formData 閲岀殑 biaozhun_banben 鍦ㄥ悓涓�
+ * (yangpin_id, biaozhun_bianhao) 缁村害涓嬫槸鍚﹀凡瀛樺湪 鈥斺�� 涓嶅悓鏍囧噯缂栧彿涓嬬殑鐗堟湰鍙锋槸闅旂鐨勶紝
+ * 涓嶅簲璺ㄦ爣鍑嗕簰鐩稿垽閲嶃�倅angpin_id 涓� biaozhun_bianhao 閮藉彇鑷� DB 婧愯褰曪紝
+ * 閬垮厤鍓嶇绡℃敼銆備换涓�鍊肩己澶卞垯璺宠繃鏍¢獙銆�
+ */
+ private void validateBiaozhunBanbenUnique(Map<String, Object> formData,
+ ZhiliangBiaozhunGuanliEntity source) {
+ String biaozhunBanben = asString(formData.get("biaozhun_banben"));
+ if (biaozhunBanben == null || biaozhunBanben.isEmpty()) {
+ return;
+ }
+ String yangpinId = source.getYangpinId();
+ String biaozhunBianhao = source.getBiaozhunBianhao();
+ if (yangpinId == null || yangpinId.isEmpty()
+ || biaozhunBianhao == null || biaozhunBianhao.isEmpty()) {
+ return;
+ }
+ QueryWrapper<ZhiliangBiaozhunGuanliEntity> w = new QueryWrapper<>();
+ w.eq("yangpin_id", yangpinId);
+ w.eq("biaozhun_bianhao", biaozhunBianhao);
+ w.eq("biaozhun_banben", biaozhunBanben);
+ w.and(q -> q.isNull("f_delete_mark").or().ne("f_delete_mark", 1));
+ // 鎺掗櫎婧愯褰曡嚜韬細upgrade 鍦烘櫙涓嬫柊璁板綍鏄粠婧愬鍒剁殑锛屾簮涓嶅簲涓庤嚜宸卞啿绐�
+ if (source.getId() != null && !source.getId().isEmpty()) {
+ w.ne("f_id", source.getId());
+ }
+ if (this.count(w) > 0) {
+ throw new DataException("璇ユ牱鍝佺殑鏍囧噯缂栧彿銆�" + biaozhunBianhao
+ + "銆戜笅宸插瓨鍦ㄧ増鏈彿銆�" + biaozhunBanben + "銆戯紝璇蜂娇鐢ㄥ叾浠栫増鏈彿");
+ }
+ }
+}
--
Gitblit v1.8.0