瀏覽代碼

自动生成设备编号,自动生成区域编码

LLL 1 年之前
父節點
當前提交
c2f5491031

+ 17 - 5
jeecg_module_ems/src/main/java/org/jeecg/modules/space/controller/SpaceController.java

@@ -21,6 +21,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
+import org.jeecg.modules.util.AutoCodeUtil;
+import org.jeecg.modules.util.UserConstants;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -50,6 +52,8 @@ import org.jeecg.common.aspect.annotation.AutoLog;
 public class SpaceController extends JeecgController<Space, ISpaceService>{
 	@Autowired
 	private ISpaceService spaceService;
+	@Autowired
+	private AutoCodeUtil autoCodeUtil;
 
 	/**
 	 * 分页列表查询
@@ -191,7 +195,7 @@ public class SpaceController extends JeecgController<Space, ISpaceService>{
             return Result.error("批量查询子节点失败:" + e.getMessage());
         }
     }
-	
+
 	/**
 	 *   添加
 	 *
@@ -203,10 +207,14 @@ public class SpaceController extends JeecgController<Space, ISpaceService>{
     //@RequiresPermissions("org.jeecg.modules:ems_space:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody Space space) {
+		//自动生成区域编码
+		if (space.getSerialnum() == null || "".equals(space.getSerialnum())) {
+			space.setSerialnum(autoCodeUtil.genSerialCode(UserConstants.EMSSPACE_CODE, null));
+		}
 		spaceService.addSpace(space);
 		return Result.OK("添加成功!");
 	}
-	
+
 	/**
 	 *  编辑
 	 *
@@ -218,10 +226,14 @@ public class SpaceController extends JeecgController<Space, ISpaceService>{
     //@RequiresPermissions("org.jeecg.modules:ems_space:edit")
 	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
 	public Result<String> edit(@RequestBody Space space) {
+		//自动生成区域编码
+		if (space.getSerialnum() == null || "".equals(space.getSerialnum())) {
+			space.setSerialnum(autoCodeUtil.genSerialCode(UserConstants.EMSSPACE_CODE, null));
+		}
 		spaceService.updateSpace(space);
 		return Result.OK("编辑成功!");
 	}
-	
+
 	/**
 	 *   通过id删除
 	 *
@@ -236,7 +248,7 @@ public class SpaceController extends JeecgController<Space, ISpaceService>{
 		spaceService.deleteSpace(id);
 		return Result.OK("删除成功!");
 	}
-	
+
 	/**
 	 *  批量删除
 	 *
@@ -251,7 +263,7 @@ public class SpaceController extends JeecgController<Space, ISpaceService>{
 		this.spaceService.removeByIds(Arrays.asList(ids.split(",")));
 		return Result.OK("批量删除成功!");
 	}
-	
+
 	/**
 	 * 通过id查询
 	 *

+ 18 - 6
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipment/controller/TpmEquipmentController.java

@@ -20,6 +20,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
+import org.jeecg.modules.util.AutoCodeUtil;
+import org.jeecg.modules.util.UserConstants;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -49,7 +51,9 @@ import org.jeecg.common.aspect.annotation.AutoLog;
 public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEquipmentService> {
 	@Autowired
 	private ITpmEquipmentService tpmEquipmentService;
-	
+	@Autowired
+	private AutoCodeUtil autoCodeUtil;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -71,7 +75,7 @@ public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEq
 		IPage<TpmEquipment> pageList = tpmEquipmentService.page(page, queryWrapper);
 		return Result.OK(pageList);
 	}
-	
+
 	/**
 	 *   添加
 	 *
@@ -83,10 +87,14 @@ public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEq
 	//@RequiresPermissions("org.jeecg.modules:ems_tpm_equipment:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody TpmEquipment tpmEquipment) {
+		// 如果设备编号为空,则自动生成设备编号
+		if (tpmEquipment.getEquipmentcode() == null || "".equals(tpmEquipment.getEquipmentcode())) {
+			tpmEquipment.setEquipmentcode(autoCodeUtil.genSerialCode(UserConstants.MACHINERY_CODE, null));
+		}
 		tpmEquipmentService.save(tpmEquipment);
 		return Result.OK("添加成功!");
 	}
-	
+
 	/**
 	 *  编辑
 	 *
@@ -98,10 +106,14 @@ public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEq
 	//@RequiresPermissions("org.jeecg.modules:ems_tpm_equipment:edit")
 	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
 	public Result<String> edit(@RequestBody TpmEquipment tpmEquipment) {
+		// 如果设备编号为空,则自动生成设备编号
+		if (tpmEquipment.getEquipmentcode() == null || "".equals(tpmEquipment.getEquipmentcode())) {
+			tpmEquipment.setEquipmentcode(autoCodeUtil.genSerialCode(UserConstants.MACHINERY_CODE, null));
+		}
 		tpmEquipmentService.updateById(tpmEquipment);
 		return Result.OK("编辑成功!");
 	}
-	
+
 	/**
 	 *   通过id删除
 	 *
@@ -116,7 +128,7 @@ public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEq
 		tpmEquipmentService.removeById(id);
 		return Result.OK("删除成功!");
 	}
-	
+
 	/**
 	 *  批量删除
 	 *
@@ -131,7 +143,7 @@ public class TpmEquipmentController extends JeecgController<TpmEquipment, ITpmEq
 		this.tpmEquipmentService.removeByIds(Arrays.asList(ids.split(",")));
 		return Result.OK("批量删除成功!");
 	}
-	
+
 	/**
 	 * 通过id查询
 	 *