From 1911be8941e5fe2705c2c56e74e52bd426468793 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 06 八月 2025 15:26:34 +0800
Subject: [PATCH] 固化流程,建立node;

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java |  135 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 123 insertions(+), 12 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java
index 4393ff3..6d95ef7 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java
@@ -2,11 +2,12 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BizServiceImpl;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.mdm.basesetting.machine.entity.Machine;
-import org.springblade.mdm.basesetting.machine.entity.MachineSpec;
 import org.springblade.mdm.basesetting.machine.mapper.MachineMapper;
 import org.springblade.mdm.basesetting.machine.vo.MachineQueryVO;
 import org.springblade.mdm.basesetting.machine.vo.MachineSaveVO;
@@ -14,21 +15,71 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 @Service
 public class MachineService extends BizServiceImpl<MachineMapper, Machine> {
 
 	@Transactional
 	public void saveMachine(MachineSaveVO vo){
-		//TODO
+		checkMachine(vo);
+		if(existsByCode(vo.getCode(),null)){
+			throw new ServiceException("鏈哄簥缂栫爜宸插瓨鍦�:"+vo.getCode());
+		}
+
 		Machine machine = new Machine();
 		BeanUtil.copyProperties(vo, machine);
+		machine.setId(null);
 		this.save(machine);
 	}
 
+	/**
+	 * 妫�鏌ユ満搴婂綍鍏ユ暟鎹�
+	 * @param vo 褰曞叆鐨勮〃鍗曟暟鎹甐O
+	 */
+	void checkMachine(MachineSaveVO vo){
+		if(Func.isEmpty(vo.getCode())){
+			throw new ServiceException("鏈哄簥缂栫爜涓嶈兘涓虹┖");
+		}
+
+		if(Func.isEmpty(vo.getName())){
+			throw new ServiceException("鏈哄簥绫诲瀷涓嶈兘涓虹┖");
+		}
+
+		if(Func.isEmpty(vo.getMachineGroupCode())){
+			throw new ServiceException("鎵�灞炵粍缁囦笉鑳戒负绌�");
+		}
+
+		if(Func.isEmpty(vo.getMachineSpec())){
+			throw new ServiceException("鏈哄簥绫诲瀷涓嶈兘涓虹┖");
+		}
+	}
+
+	/**
+	 * 鏍规嵁鏈哄簥缂栫爜鍒ゆ柇鏈哄簥鏄惁瀛樺湪
+	 * @param code 鏈哄簥缂栫爜
+	 * @param excludeId 鎺掗櫎id
+	 * @return 鏄惁瀛樺湪
+	 */
+	boolean existsByCode(String code,Long excludeId){
+		return this.lambdaQuery().eq(Machine::getCode, code).ne(excludeId!=null,Machine::getId, excludeId).count()>0;
+	}
+
 	public boolean updateMachine(MachineSaveVO vo) {
+
+		checkMachine(vo);
+		if(existsByCode(vo.getCode(),vo.getId())){
+			throw new ServiceException("鏈哄簥缂栫爜宸插瓨鍦�:"+vo.getCode());
+		}
+
 		Machine machine = this.getById(vo.getId());
 
 		machine.setMachineSpec(vo.getMachineSpec());
+		machine.setCode(vo.getCode());
 		machine.setName(vo.getName());
 		machine.setMachineGroupCode(vo.getMachineGroupCode());
 		machine.setManufacturer(vo.getManufacturer());
@@ -38,6 +89,7 @@
 		machine.setPollingHours(vo.getPollingHours());
 		machine.setProgSendDir(vo.getProgSendDir());
 		machine.setProgReceiveDir(vo.getProgReceiveDir());
+		machine.setStatus(vo.getStatus());
 		machine.setRemark(vo.getRemark());
 
 		return this.updateById(machine);
@@ -54,17 +106,76 @@
 	public IPage<MachineVO> pageQuery(MachineQueryVO query) {
 
 		LambdaQueryWrapper<Machine> queryWrapper = new LambdaQueryWrapper<>();
-		queryWrapper.eq(query.getMachineGroupCode()!=null, Machine::getMachineGroupCode, query.getMachineGroupCode());
-		IPage<MachineVO> page = this.getBaseMapper().pageQuery(Condition.getPage(query),queryWrapper);
+		//queryWrapper.eq(query.getMachineGroupCode()!=null, Machine::getMachineGroupCode, query.getMachineGroupCode());
+		//String keys = query.getKeyword();
 
-		//MachineSpec.valueOf()
-		for (MachineVO record : page.getRecords()) {
-			if(record.getMachineSpec() != null){
-				MachineSpec spec = MachineSpec.valueOf(record.getMachineSpec());
-				record.setMachineSpecName(spec.getText());
-			}
-
-		}
+		//queryWrapper.and(StringUtils.isNotEmpty(keys), wrapper -> wrapper.like(Machine::getCode, keys).or().like(Machine::getName, keys));
+		IPage<MachineVO> page = this.getBaseMapper().pageQuery(Condition.getPage(query),query);
 		return page;
 	}
+
+	/**
+	 * 鏌ヨ璇︽儏
+	 * @param id 鏈哄簥id
+	 * @return
+	 */
+	public MachineVO detail(long id) {
+		Machine machine = this.getById(id);
+
+		MachineVO vo = new MachineVO();
+		BeanUtil.copyProperties(machine, vo);
+
+		return vo;
+	}
+
+	/**
+	 * 浜х敓鏈哄簥鍥炰紶缁撴瀯鏁版嵁
+	 * @param id
+	 */
+	public void genMachineFileBackDirs(Long id) throws IOException {
+		Machine machine = this.getById(id);
+		if(Func.isNotBlank(machine.getProgReceiveDir())){
+			if(isLegalDirectoryPath(machine.getProgReceiveDir())) {
+				Path path = Paths.get(machine.getProgReceiveDir());
+				Files.createDirectories(path);
+			}else{
+				throw new RuntimeException("闈炴硶鐨勭洰褰曟牸寮�");
+			}
+		}
+	}
+
+	/**
+	 * 鍒ゆ柇鏄惁鏄悎娉曠殑鐩綍鏍煎紡
+	 * @param path
+	 * @return
+	 */
+	static boolean isLegalDirectoryPath(String path) {
+		// 鍩虹妫�鏌�
+		if (path == null || path.trim().isEmpty()) {
+			return false;
+		}
+
+		// 浣跨敤NIO妫�鏌ヨ矾寰勬牸寮�
+		Path nioPath;
+		try {
+			nioPath = Paths.get(path);
+			if (!nioPath.normalize().toString().equals(path)) {
+				return false; // 璺緞涓嶈鑼�
+			}
+		} catch (InvalidPathException ex) {
+			return false;
+		}
+
+		return true;
+
+	}
+
+	/**
+	 * 鏍规嵁鏈哄簥缂栫爜鑾峰彇鏈哄簥
+	 * @param machineCode 鏈哄簥缂栫爜
+	 * @return
+	 */
+	public Machine getByCode(String machineCode) {
+		return this.lambdaQuery().eq(Machine::getCode, machineCode).one();
+	}
 }

--
Gitblit v1.9.3