物料新增与修改在同一接口

This commit is contained in:
wanxiaoli 2026-01-16 18:30:49 +08:00
parent 26423085bc
commit 912dd6075a
4 changed files with 39 additions and 2 deletions

View File

@ -117,7 +117,7 @@ public class DeviceController {
/** /**
* 6. 设备分页查询类型 可选 + 名称 可选 * 6. 设备模板库分页查询类型 可选 + 名称 可选
* 输入参数查询参数 type可选name可选pageNum页码默认1pageSize每页条数默认10 * 输入参数查询参数 type可选name可选pageNum页码默认1pageSize每页条数默认10
* 输出参数设备分页列表按创建时间倒序 * 输出参数设备分页列表按创建时间倒序
* @param type 设备类型可选 * @param type 设备类型可选
@ -132,6 +132,9 @@ public class DeviceController {
@RequestParam(defaultValue = "1") long pageNum, @RequestParam(defaultValue = "1") long pageNum,
@RequestParam(defaultValue = "20") long pageSize) { @RequestParam(defaultValue = "20") long pageSize) {
QueryWrapper<Device> qw = new QueryWrapper<>(); QueryWrapper<Device> qw = new QueryWrapper<>();
// 模板库设备 project_id -1
qw.eq("project_id", "-1");
if (type != null && !type.isEmpty()) { if (type != null && !type.isEmpty()) {
qw.eq("type", type); qw.eq("type", type);
} }

View File

@ -2,6 +2,7 @@ package com.yfd.business.css.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.business.css.domain.Device;
import com.yfd.business.css.domain.Material; import com.yfd.business.css.domain.Material;
import com.yfd.business.css.service.MaterialService; import com.yfd.business.css.service.MaterialService;
import com.yfd.platform.system.service.IUserService; import com.yfd.platform.system.service.IUserService;
@ -37,6 +38,12 @@ public class MaterialController {
return materialService.saveMaterial(material); return materialService.saveMaterial(material);
} }
@PostMapping("/saveOrUpdate")
public boolean saveOrUpdate(@RequestBody Material material) {
material.setModifier(currentUsername());
return materialService.saveOrUpdateByBusiness(material);
}
/** /**
* 2. 编辑物料 * 2. 编辑物料
* 输入参数请求体中的物料对象需包含主键 * 输入参数请求体中的物料对象需包含主键
@ -102,10 +109,12 @@ public class MaterialController {
public Page<Material> search(@RequestParam(required = false) String name, public Page<Material> search(@RequestParam(required = false) String name,
@RequestParam(defaultValue = "1") long pageNum, @RequestParam(defaultValue = "1") long pageNum,
@RequestParam(defaultValue = "20") long pageSize) { @RequestParam(defaultValue = "20") long pageSize) {
QueryWrapper<Material> qw = new QueryWrapper<Material>().orderByDesc("created_at"); QueryWrapper<Material> qw = new QueryWrapper<>();
qw.eq("project_id", "-1");
if (name != null && !name.isEmpty()) { if (name != null && !name.isEmpty()) {
qw.like("name", name); qw.like("name", name);
} }
qw.orderByDesc("created_at");
Page<Material> page = new Page<>(pageNum, pageSize, true); Page<Material> page = new Page<>(pageNum, pageSize, true);
return materialService.page(page, qw); return materialService.page(page, qw);
} }

View File

@ -1,6 +1,7 @@
package com.yfd.business.css.service; package com.yfd.business.css.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.business.css.domain.Device;
import com.yfd.business.css.domain.Material; import com.yfd.business.css.domain.Material;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -14,4 +15,6 @@ public interface MaterialService extends IService<Material> {
* 新增物料 * 新增物料
*/ */
boolean saveMaterial(Material material); boolean saveMaterial(Material material);
boolean saveOrUpdateByBusiness(Material material);
} }

View File

@ -70,6 +70,28 @@ public class MaterialServiceImpl
return this.save(material); return this.save(material);
} }
@Override
public boolean saveOrUpdateByBusiness(Material material) {
String materialId = material.getMaterialId();
// 情况 1未传 materialId 直接新增
if (StrUtil.isBlank(materialId)) {
return this.save(material);
}
// 情况 2传了 materialId判断是否存在
Material dbMaterial = this.getById(materialId);
if (dbMaterial == null) {
// 数据库不存在 新增使用传入的 materialId
return this.save(material);
} else {
// 数据库存在 更新
return this.updateById(material);
}
}
private boolean importExcel(Workbook workbook) { private boolean importExcel(Workbook workbook) {
try (Workbook wb = workbook) { try (Workbook wb = workbook) {
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);