#厂家模块的接口返回值的补充
This commit is contained in:
@@ -3,6 +3,7 @@ package com.maibu.web.controller.system;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.maibu.core.business.DeviceModel;
|
||||
import com.maibu.core.business.Product;
|
||||
import com.maibu.core.business.dto.ProductDTO;
|
||||
import com.maibu.core.controller.BaseController;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.page.TableDataInfo;
|
||||
@@ -13,10 +14,12 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -32,16 +35,20 @@ public class SysProductController extends BaseController {
|
||||
/**
|
||||
* 分页查询产品列表
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('iot:product:list')")
|
||||
// @PreAuthorize("@ss.hasPermi('iot:product:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询产品列表")
|
||||
public TableDataInfo list(Product product) {
|
||||
public TableDataInfo list(ProductDTO productDTO) {
|
||||
Integer pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
|
||||
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
|
||||
|
||||
Page<Product> page = new Page<>(pageNum, pageSize);
|
||||
Page<Product> resultPage = productService.selectProductPage(page, product);
|
||||
|
||||
// DTO 转 Entity 用于查询筛选
|
||||
Product product = new Product();
|
||||
BeanUtils.copyProperties(productDTO, product);
|
||||
|
||||
Page<Product> resultPage = productService.selectProductPage(page, product);
|
||||
return getDataTable(resultPage.getRecords(), resultPage.getTotal());
|
||||
}
|
||||
|
||||
@@ -51,21 +58,26 @@ public class SysProductController extends BaseController {
|
||||
//@PreAuthorize("@ss.hasPermi('iot:product:add')")
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增产品")
|
||||
public AjaxResult add(@RequestBody Product product) {
|
||||
// 参数校验
|
||||
if (product.getName() == null || product.getName().isEmpty()) {
|
||||
public AjaxResult add(@RequestBody ProductDTO productDTO) {
|
||||
if (productDTO.getName() == null || productDTO.getName().isEmpty()) {
|
||||
return AjaxResult.error("产品名称不能为空");
|
||||
}
|
||||
if (product.getCode() == null || product.getCode().isEmpty()) {
|
||||
if (productDTO.getCode() == null || productDTO.getCode().isEmpty()) {
|
||||
return AjaxResult.error("产品编码不能为空");
|
||||
}
|
||||
|
||||
// 检查编码是否重复
|
||||
Product existProduct = productService.selectByCode(product.getCode());
|
||||
Product existProduct = productService.selectByCode(productDTO.getCode());
|
||||
if (existProduct != null) {
|
||||
return AjaxResult.error("产品编码已存在");
|
||||
}
|
||||
|
||||
// DTO 转 Entity
|
||||
Product product = new Product();
|
||||
BeanUtils.copyProperties(productDTO, product);
|
||||
product.setCreateTime(LocalDateTime.now());
|
||||
product.setDelFlag(false);
|
||||
|
||||
boolean success = productService.save(product);
|
||||
return toAjax(success ? 1 : 0);
|
||||
}
|
||||
@@ -73,28 +85,31 @@ public class SysProductController extends BaseController {
|
||||
/**
|
||||
* 修改产品
|
||||
*/
|
||||
//@PreAuthorize("@ss.hasPermi('iot:product:edit')")
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改产品")
|
||||
public AjaxResult edit(@RequestBody Product product) {
|
||||
if (product.getId() == null) {
|
||||
return AjaxResult.error("产品ID不能为空");
|
||||
public AjaxResult edit(@RequestBody ProductDTO productDTO) {
|
||||
if (productDTO.getId() == null) {
|
||||
return AjaxResult.error("产品 ID 不能为空");
|
||||
}
|
||||
|
||||
// 检查产品是否存在
|
||||
Product existProduct = productService.getById(product.getId());
|
||||
Product existProduct = productService.getById(productDTO.getId());
|
||||
if (existProduct == null) {
|
||||
return AjaxResult.error("产品不存在");
|
||||
}
|
||||
|
||||
// 如果修改了编码,检查是否重复
|
||||
if (product.getCode() != null && !product.getCode().equals(existProduct.getCode())) {
|
||||
Product duplicate = productService.selectByCode(product.getCode());
|
||||
if (productDTO.getCode() != null && !productDTO.getCode().equals(existProduct.getCode())) {
|
||||
Product duplicate = productService.selectByCode(productDTO.getCode());
|
||||
if (duplicate != null) {
|
||||
return AjaxResult.error("产品编码已存在");
|
||||
}
|
||||
}
|
||||
|
||||
// DTO 转 Entity
|
||||
Product product = new Product();
|
||||
BeanUtils.copyProperties(productDTO, product);
|
||||
product.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
boolean success = productService.updateById(product);
|
||||
return toAjax(success ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.Map;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@TableName("iot_device_product")
|
||||
@TableName(value = "device_product", autoResultMap = true)
|
||||
public class Product extends BaseDO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -52,4 +52,6 @@ public class Product extends BaseDO {
|
||||
|
||||
private Integer status;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ProductInterface> interfaces; // 产品接口列表
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.Map;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@TableName("iot_device_product_inter")
|
||||
@TableName("device_product_inter")
|
||||
public class ProductInterface extends BaseDO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.maibu.core.business.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.maibu.core.business.ProductInterface;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
public class ProductDTO extends BaseDO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
|
||||
private String manufacturer;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String protocolCode;
|
||||
|
||||
private String transport;
|
||||
|
||||
private String uploadTopic;
|
||||
|
||||
private String subscribeTopic;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, Object> thingsModels;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -23,4 +23,15 @@ public interface DeviceProductService extends IService<Product> {
|
||||
Product selectByCode(String code);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增产品(含接口表入库)
|
||||
*/
|
||||
boolean insertProduct(Product product);
|
||||
/**
|
||||
* 修改产品(含接口表入库)
|
||||
*/
|
||||
boolean updateProduct(Product product);
|
||||
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user