Merge branch 'develop-business-css' of http://121.37.111.42:3000/ThbTech/JavaProjectRepo into develop-business-css
This commit is contained in:
commit
5e03b4e79f
@ -34,7 +34,13 @@ public class DeviceController {
|
||||
@PostMapping
|
||||
public boolean create(@RequestBody Device device) {
|
||||
device.setModifier(currentUsername());
|
||||
return deviceService.save(device);
|
||||
return deviceService.createDevice(device);
|
||||
}
|
||||
|
||||
@PostMapping("/saveOrUpdate")
|
||||
public boolean saveOrUpdate(@RequestBody Device device) {
|
||||
device.setModifier(currentUsername());
|
||||
return deviceService.saveOrUpdateByBusiness(device);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +117,7 @@ public class DeviceController {
|
||||
|
||||
|
||||
/**
|
||||
* 6. 设备分页查询(类型 可选 + 名称 可选)
|
||||
* 6. 设备模板库分页查询(类型 可选 + 名称 可选)
|
||||
* 输入参数:查询参数 type(可选),name(可选),pageNum(页码,默认1),pageSize(每页条数,默认10)
|
||||
* 输出参数:设备分页列表(按创建时间倒序)
|
||||
* @param type 设备类型(可选)
|
||||
@ -126,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;
|
||||
@ -34,7 +35,13 @@ public class MaterialController {
|
||||
@PostMapping
|
||||
public boolean create(@RequestBody Material material) {
|
||||
material.setModifier(currentUsername());
|
||||
return materialService.save(material);
|
||||
return materialService.saveMaterial(material);
|
||||
}
|
||||
|
||||
@PostMapping("/saveOrUpdate")
|
||||
public boolean saveOrUpdate(@RequestBody Material material) {
|
||||
material.setModifier(currentUsername());
|
||||
return materialService.saveOrUpdateByBusiness(material);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -9,5 +9,7 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
boolean importDevices(MultipartFile file, String deviceType);
|
||||
|
||||
public boolean createDevice(Device device) ;
|
||||
boolean createDevice(Device device) ;
|
||||
|
||||
boolean saveOrUpdateByBusiness(Device device);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -9,4 +10,11 @@ public interface MaterialService extends IService<Material> {
|
||||
* 导入物料
|
||||
*/
|
||||
boolean importMaterials(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 新增物料
|
||||
*/
|
||||
boolean saveMaterial(Material material);
|
||||
|
||||
boolean saveOrUpdateByBusiness(Material material);
|
||||
}
|
||||
|
||||
@ -67,6 +67,28 @@ public class DeviceServiceImpl
|
||||
// 2. 如果前端传了 deviceId,直接使用
|
||||
return this.save(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveOrUpdateByBusiness(Device device) {
|
||||
|
||||
String deviceId = device.getDeviceId();
|
||||
|
||||
// 情况 1:未传 deviceId → 直接新增
|
||||
if (StrUtil.isBlank(deviceId)) {
|
||||
return this.save(device);
|
||||
}
|
||||
|
||||
// 情况 2:传了 deviceId,判断是否存在
|
||||
Device dbDevice = this.getById(deviceId);
|
||||
|
||||
if (dbDevice == null) {
|
||||
// 数据库不存在 → 新增(使用传入的 deviceId)
|
||||
return this.save(device);
|
||||
} else {
|
||||
// 数据库存在 → 更新
|
||||
return this.updateById(device);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean importExcel(Workbook workbook, String deviceType) {
|
||||
try (Workbook wb = workbook) {
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
package com.yfd.business.css.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.business.css.domain.Device;
|
||||
import com.yfd.business.css.domain.Material;
|
||||
import com.yfd.business.css.mapper.MaterialMapper;
|
||||
import com.yfd.business.css.service.MaterialService;
|
||||
import com.yfd.platform.system.service.IUserService;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -53,6 +58,40 @@ public class MaterialServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveMaterial(Material material) {
|
||||
|
||||
// 1. 如果前端没有传 materialId,显式生成
|
||||
if (StrUtil.isBlank(material.getMaterialId())) {
|
||||
material.setMaterialId(IdUtil.fastUUID());
|
||||
}
|
||||
|
||||
// 2. 如果前端传了 materialId,直接使用
|
||||
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