物料新增与修改在同一接口
This commit is contained in:
parent
26423085bc
commit
912dd6075a
@ -117,7 +117,7 @@ public class DeviceController {
|
||||
|
||||
|
||||
/**
|
||||
* 6. 设备分页查询(类型 可选 + 名称 可选)
|
||||
* 6. 设备模板库分页查询(类型 可选 + 名称 可选)
|
||||
* 输入参数:查询参数 type(可选),name(可选),pageNum(页码,默认1),pageSize(每页条数,默认10)
|
||||
* 输出参数:设备分页列表(按创建时间倒序)
|
||||
* @param type 设备类型(可选)
|
||||
@ -132,6 +132,9 @@ public class DeviceController {
|
||||
@RequestParam(defaultValue = "1") long pageNum,
|
||||
@RequestParam(defaultValue = "20") long pageSize) {
|
||||
QueryWrapper<Device> qw = new QueryWrapper<>();
|
||||
// 模板库设备 project_id 为 -1
|
||||
qw.eq("project_id", "-1");
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
qw.eq("type", type);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.yfd.business.css.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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.service.MaterialService;
|
||||
import com.yfd.platform.system.service.IUserService;
|
||||
@ -37,6 +38,12 @@ public class MaterialController {
|
||||
return materialService.saveMaterial(material);
|
||||
}
|
||||
|
||||
@PostMapping("/saveOrUpdate")
|
||||
public boolean saveOrUpdate(@RequestBody Material material) {
|
||||
material.setModifier(currentUsername());
|
||||
return materialService.saveOrUpdateByBusiness(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 编辑物料
|
||||
* 输入参数:请求体中的物料对象(需包含主键)
|
||||
@ -102,10 +109,12 @@ public class MaterialController {
|
||||
public Page<Material> search(@RequestParam(required = false) String name,
|
||||
@RequestParam(defaultValue = "1") long pageNum,
|
||||
@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()) {
|
||||
qw.like("name", name);
|
||||
}
|
||||
qw.orderByDesc("created_at");
|
||||
Page<Material> page = new Page<>(pageNum, pageSize, true);
|
||||
return materialService.page(page, qw);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.yfd.business.css.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yfd.business.css.domain.Device;
|
||||
import com.yfd.business.css.domain.Material;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -14,4 +15,6 @@ public interface MaterialService extends IService<Material> {
|
||||
* 新增物料
|
||||
*/
|
||||
boolean saveMaterial(Material material);
|
||||
|
||||
boolean saveOrUpdateByBusiness(Material material);
|
||||
}
|
||||
|
||||
@ -70,6 +70,28 @@ public class MaterialServiceImpl
|
||||
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) {
|
||||
try (Workbook wb = workbook) {
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user