Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update delete api -> deleteBatch api #74

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ProductCategoryController(private val productCategoryService: ProductCateg
return productCategoryService.addOrUpdateProductCategory(productCategory)
}

@PostMapping("/delete")
fun deleteProductCategory(@RequestParam id: Long): Response<String> {
return productCategoryService.deleteProductCategory(id)
@PostMapping("/deleteBatch")
fun deleteProductCategory(@RequestParam ids: List<Long>): Response<String> {
return productCategoryService.deleteProductCategory(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ class AddOrUpdateProductCategoryDTO {

val categoryName: String? = null

val categoryLevel: Int? = null
val categoryNumber: String? = null

val parentId: Long? = null

val sort: Int? = null

val serialNumber: String? = null

val remark: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class ProductCategory implements Serializable {
private String categoryName;

/**
* 等级
* 分类编号
*/
private Integer categoryLevel;
private String categoryNumber;

/**
* 上级id
Expand All @@ -68,11 +68,6 @@ public class ProductCategory implements Serializable {
*/
private Integer sort;

/**
* 编号
*/
private String serialNumber;

/**
* 备注
*/
Expand Down
15 changes: 10 additions & 5 deletions domain/src/main/java/com/wansensoft/vo/ProductCategoryVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
Expand All @@ -27,16 +29,19 @@ public class ProductCategoryVO {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long parentId;

private String categoryName;

private Integer categoryLevel;
private String categoryNumber;

private String serialNumber;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long parentId;

private String parentName;

private String remark;

private Integer sort;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ interface ProductCategoryService : IService<ProductCategory> {

fun addOrUpdateProductCategory(productCategory: AddOrUpdateProductCategoryDTO) : Response<String>

fun deleteProductCategory(id: Long?) : Response<String>
fun deleteProductCategory(ids: List<Long>?) : Response<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ open class ProductCategoryServiceImpl(
.list()
productCategories.forEach {
val productCategoryVO = ProductCategoryVO()
// 获取item的父级分类名称
val parentId = it.parentId
if (parentId != null) {
val parentCategory = lambdaQuery()
.eq(ProductCategory::getId, parentId)
.one()
productCategoryVO.parentName = parentCategory.categoryName
}
BeanUtils.copyProperties(it, productCategoryVO)
productCategoryVOs.add(productCategoryVO)
}
Expand All @@ -61,10 +69,9 @@ open class ProductCategoryServiceImpl(
.id(SnowflakeIdUtil.nextId())
.tenantId(userId)
.categoryName(dto.categoryName)
.categoryLevel(dto.categoryLevel)
.categoryNumber(dto.categoryNumber)
.parentId(dto.parentId)
.sort(dto.sort)
.serialNumber(dto.serialNumber)
.remark(dto.remark)
.createTime(LocalDateTime.now())
.createBy(userId)
Expand All @@ -80,10 +87,9 @@ open class ProductCategoryServiceImpl(
.eq(ProductCategory::getId, dto.id)
.apply {
set(StringUtils.hasText(dto.categoryName), ProductCategory::getCategoryName, dto.categoryName)
set(dto.categoryLevel != null, ProductCategory::getCategoryLevel, dto.categoryLevel)
set(StringUtils.hasText(dto.categoryNumber), ProductCategory::getCategoryNumber, dto.categoryNumber)
set(dto.parentId != null, ProductCategory::getParentId, dto.parentId)
set(dto.sort != null, ProductCategory::getSort, dto.sort)
set(StringUtils.hasText(dto.serialNumber), ProductCategory::getSerialNumber, dto.serialNumber)
set(StringUtils.hasText(dto.remark), ProductCategory::getRemark, dto.remark)
set(ProductCategory::getUpdateTime, LocalDateTime.now())
set(ProductCategory::getUpdateBy, userId)
Expand All @@ -98,13 +104,13 @@ open class ProductCategoryServiceImpl(
}
}

override fun deleteProductCategory(id: Long?): Response<String> {
override fun deleteProductCategory(ids: List<Long>?): Response<String> {
// 如果id为空返回参数错误 否则进行逻辑删除产品分类id
if(id == null) {
if(ids.isNullOrEmpty()) {
return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}
val deleteResult = lambdaUpdate()
.eq(ProductCategory::getId, id)
.`in`(ProductCategory::getId, ids)
.set(ProductCategory::getDeleteFlag, CommonConstants.DELETED)
.update()

Expand Down