-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from Jzow/master
New added data objects related to product attribute interfaces
- Loading branch information
Showing
18 changed files
with
296 additions
and
116 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
api/src/main/java/com/wansensoft/api/product/ProductAttributeController.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
api/src/main/java/com/wansensoft/api/product/ProductAttributeController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductAttributeDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
10 changes: 10 additions & 0 deletions
10
domain/src/main/java/com/wansensoft/dto/product/ProductAttributeQueryDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
domain/src/main/java/com/wansensoft/vo/product/ProductAttributeVO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
service/src/main/java/com/wansensoft/service/product/IProductAttributeService.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
service/src/main/java/com/wansensoft/service/product/ProductAttributeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.java
This file was deleted.
Oops, something went wrong.
129 changes: 129 additions & 0 deletions
129
service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.