From 43b6b4b905fb272e2d7d9c0738610c4204c958ce Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期五, 22 八月 2025 01:07:24 +0800
Subject: [PATCH] 增加首页搜索接口参数调整

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/basesetting/machine/MachineService.java |  164 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 150 insertions(+), 14 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 567179e..0f9d47c 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,35 +2,105 @@
 
 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.api.R;
 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;
 import org.springblade.mdm.basesetting.machine.vo.MachineVO;
+import org.springblade.system.feign.ISysClient;
+import org.springblade.system.pojo.entity.Dept;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+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> {
-
+	@Autowired
+	private ISysClient sysClient;
 	@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.setMachineGroupId(vo.getMachineGroupId());
+		machine.setMachineGroupCode(vo.getMachineGroupCode());
+		machine.setManufacturer(vo.getManufacturer());
+		machine.setOperator(vo.getOperator());
+		machine.setControlSystem(vo.getControlSystem());
+		machine.setOwnerDept(vo.getOwnerDept());
+		machine.setPollingHours(vo.getPollingHours());
+		machine.setProgSendDir(vo.getProgSendDir());
+		machine.setProgReceiveDir(vo.getProgReceiveDir());
+		machine.setProgTempDir(vo.getProgTempDir());
+		machine.setStatus(vo.getStatus());
+		machine.setRemark(vo.getRemark());
+		machine.setSendDirExpiryHours(vo.getSendDirExpiryHours());
+		machine.setReceiveDirExpiryHours(vo.getReceiveDirExpiryHours());
+
 		return this.updateById(machine);
 	}
 
@@ -44,18 +114,84 @@
 	 */
 	public IPage<MachineVO> pageQuery(MachineQueryVO query) {
 
-		LambdaQueryWrapper<Machine> queryWrapper = new LambdaQueryWrapper<>();
-		queryWrapper.eq(query.getMachineGroupId()!=null, Machine::getMachineGroupId, query.getMachineGroupId());
-		IPage<MachineVO> page = this.getBaseMapper().pageQuery(Condition.getPage(query),queryWrapper);
-
-		//MachineSpec.valueOf()
-		for (MachineVO record : page.getRecords()) {
-			if(record.getMachineSpec() != null){
-				MachineSpec spec = MachineSpec.valueOf(record.getMachineSpec());
-				record.setMachineSpecName(spec.getText());
+		if (query.getDeptId() != null) {
+			R<Dept> rs = sysClient.getDept(query.getDeptId());
+			if(rs.isSuccess()){
+				query.setDeptAncestors(rs.getData().getAncestors()+","+rs.getData().getId());
 			}
-
 		}
+		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();
+	}
+
+	@Transactional
+	public String importMachines(MultipartFile file) {
+		return "";//瀵煎叆鎴愬姛锛岀粰绌轰覆锛岄儴鍒嗕笉鎴愬姛缁欐彁绀�
+	}
 }

--
Gitblit v1.9.3