Skip to content

Commit

Permalink
Merge pull request #75 from Jzow/master
Browse files Browse the repository at this point in the history
New added data objects related to product attribute interfaces
  • Loading branch information
Jzow authored Oct 8, 2023
2 parents 1354b95 + 7087005 commit 7027d8c
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 116 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.wansensoft.api.product

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.wansensoft.dto.product.AddOrUpdateProductAttributeDTO
import com.wansensoft.dto.product.ProductAttributeQueryDTO
import com.wansensoft.service.product.ProductAttributeService
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.product.ProductAttributeVO
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/product/attribute")
class ProductAttributeController(private val productAttributeService: ProductAttributeService) {

@PostMapping("/list")
fun productAttributeList(@RequestBody productAttributeQueryDTO: ProductAttributeQueryDTO): Response<Page<ProductAttributeVO>> {
return productAttributeService.productAttributeList(productAttributeQueryDTO)
}

@PostMapping("/addOrUpdate")
fun addOrUpdateProductAttribute(@RequestBody productAttributeDTO: AddOrUpdateProductAttributeDTO): Response<String> {
return productAttributeService.addOrUpdateProductAttribute(productAttributeDTO)
}

@DeleteMapping("/deleteBatch")
fun deleteProductAttribute(@RequestParam ids: List<Long>): Response<String> {
return productAttributeService.batchDeleteProductAttribute(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wansensoft.api.product
import com.wansensoft.dto.product.AddOrUpdateProductCategoryDTO
import com.wansensoft.service.product.ProductCategoryService
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.ProductCategoryVO
import com.wansensoft.vo.product.ProductCategoryVO
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wansensoft.dto.product

import lombok.Data

@Data
class AddOrUpdateProductAttributeDTO {

var id : Long? = null

var attributeName: String? = null

var attributeValue: String? = null

var remark: String? = null

var sort: String? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wansensoft.dto.product

import com.wansensoft.dto.PageSizeDTO
import lombok.Data

@Data
class ProductAttributeQueryDTO : PageSizeDTO() {

val attributeName: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public class ProductAttribute implements Serializable {
*/
private String attributeValue;

/**
* 备注
*/
private String remark;

/**
* 排序
*/
private Integer sort;

/**
* 创建时间
*/
Expand All @@ -75,7 +85,7 @@ public class ProductAttribute implements Serializable {
/**
* 删除标记,0未删除,1删除
*/
private Boolean deleteFlag;
private Integer deleteFlag;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.wansensoft.vo.product

import com.fasterxml.jackson.annotation.JsonFormat
import lombok.Data
import java.time.LocalDateTime

@Data
class ProductAttributeVO {

@JsonFormat(shape = JsonFormat.Shape.STRING)
var id : Long? = null

var attributeName: String? = null

var attributeValue: String? = null

var remark: String? = null

var sort: Int? = null

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
var createTime: LocalDateTime? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.vo;
package com.wansensoft.vo.product;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.service.product

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.IService
import com.wansensoft.dto.product.AddOrUpdateProductAttributeDTO
import com.wansensoft.dto.product.ProductAttributeQueryDTO
import com.wansensoft.entities.product.ProductAttribute
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.product.ProductAttributeVO

interface ProductAttributeService : IService<ProductAttribute> {

fun productAttributeList(productAttributeQuery : ProductAttributeQueryDTO?) : Response<Page<ProductAttributeVO>>

fun addOrUpdateProductAttribute(productAttributeAddOrUpdate: AddOrUpdateProductAttributeDTO?) : Response<String>

fun batchDeleteProductAttribute(ids: List<Long>?) : Response<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.baomidou.mybatisplus.extension.service.IService
import com.wansensoft.dto.product.AddOrUpdateProductCategoryDTO
import com.wansensoft.entities.product.ProductCategory
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.ProductCategoryVO
import com.wansensoft.vo.product.ProductCategoryVO

interface ProductCategoryService : IService<ProductCategory> {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.service.product.impl

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.wansensoft.dto.product.AddOrUpdateProductAttributeDTO
import com.wansensoft.dto.product.ProductAttributeQueryDTO
import com.wansensoft.entities.product.ProductAttribute
import com.wansensoft.mappers.product.ProductAttributeMapper
import com.wansensoft.service.product.ProductAttributeService
import com.wansensoft.service.user.ISysUserService
import com.wansensoft.utils.constants.CommonConstants
import com.wansensoft.utils.enums.BaseCodeEnum
import com.wansensoft.utils.enums.ProdcutCodeEnum
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.product.ProductAttributeVO
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import java.time.LocalDateTime

@Service
open class ProductAttributeServiceImpl(
private val productAttributeMapper: ProductAttributeMapper,
private val userService: ISysUserService
):ServiceImpl<ProductAttributeMapper, ProductAttribute>(), ProductAttributeService {

override fun productAttributeList(productAttributeQuery : ProductAttributeQueryDTO?): Response<Page<ProductAttributeVO>> {
val page = productAttributeQuery?.let { Page<ProductAttribute>(it.page, it.pageSize) }
val wrapper = LambdaQueryWrapper<ProductAttribute>().apply() {
productAttributeQuery?.attributeName?.let { like(ProductAttribute::getAttributeName, it) }
eq(ProductAttribute::getDeleteFlag, CommonConstants.NOT_DELETED)
}

val result = page?.run {
productAttributeMapper.selectPage(this, wrapper)
if (records.isNotEmpty()) {
val listVo = records.map { attribute ->
ProductAttributeVO().apply {
BeanUtils.copyProperties(attribute, this)
}
}
Page<ProductAttributeVO>().apply {
records = listVo
total = this@run.total
pages = this@run.pages
size = this@run.size
}

} else {
Page<ProductAttributeVO>()
}
}?: Page<ProductAttributeVO>()

return Response.responseData(result)
}

override fun addOrUpdateProductAttribute(productAttributeAddOrUpdate: AddOrUpdateProductAttributeDTO?): Response<String> {
productAttributeAddOrUpdate?.run {
val attribute = ProductAttribute().apply {
BeanUtils.copyProperties(this@run, this)
}
val userId = userService.currentUserId
when (attribute.id) {
null -> {
val wrapper = createWrapper(attribute)
val count = getCount(wrapper)
if (count > 0) {
return Response.responseMsg(ProdcutCodeEnum.PRODUCT_ATTRIBUTE_NAME_EXIST)
}
attribute.createTime = LocalDateTime.now()
attribute.createBy = userId
val saveResult = saveAttribute(attribute)
if (saveResult == 0) {
return Response.responseMsg(ProdcutCodeEnum.ADD_PRODUCT_ATTRIBUTE_ERROR)
}
return Response.responseMsg(ProdcutCodeEnum.ADD_PRODUCT_ATTRIBUTE_SUCCESS)
}
else -> {
val wrapper = createWrapper(attribute).ne(ProductAttribute::getId, attribute.id)
val count = getCount(wrapper)
if (count > 0) {
return Response.responseMsg(ProdcutCodeEnum.PRODUCT_ATTRIBUTE_NAME_EXIST)
}
attribute.updateBy = userId
attribute.updateTime = LocalDateTime.now()
val updateResult = updateAttribute(attribute)
if (updateResult == 0) {
return Response.responseMsg(ProdcutCodeEnum.UPDATE_PRODUCT_ATTRIBUTE_ERROR)
}
return Response.responseMsg(ProdcutCodeEnum.UPDATE_PRODUCT_ATTRIBUTE_SUCCESS)
}
}
} ?: return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}

private fun createWrapper(attribute: ProductAttribute) = LambdaQueryWrapper<ProductAttribute>().apply {
eq(ProductAttribute::getAttributeName, attribute.attributeName)
eq(ProductAttribute::getDeleteFlag, CommonConstants.NOT_DELETED)
}

private fun getCount(wrapper: LambdaQueryWrapper<ProductAttribute>) = productAttributeMapper.selectCount(wrapper)

private fun saveAttribute(attribute: ProductAttribute) = productAttributeMapper.insert(attribute)

private fun updateAttribute(attribute: ProductAttribute) = productAttributeMapper.updateById(attribute)

override fun batchDeleteProductAttribute(ids: List<Long>?): Response<String> {
// Change the status from unmodified to physically deleted data
ids?.let {
val deleteResult = productAttributeMapper.deleteBatchIds(ids)
if(deleteResult == 0) {
return Response.responseMsg(ProdcutCodeEnum.DELETE_PRODUCT_ATTRIBUTE_ERROR)
}
return Response.responseMsg(ProdcutCodeEnum.DELETE_PRODUCT_ATTRIBUTE_SUCCESS)
}?: return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}
}
Loading

0 comments on commit 7027d8c

Please sign in to comment.