#厂家模块的接口返回值的补充
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user