diff --git a/api/src/main/java/com/wansensoft/api/product/ProductAttributeController.kt b/api/src/main/java/com/wansensoft/api/product/ProductAttributeController.kt index f5f86cc3b..c0c003fd3 100644 --- a/api/src/main/java/com/wansensoft/api/product/ProductAttributeController.kt +++ b/api/src/main/java/com/wansensoft/api/product/ProductAttributeController.kt @@ -1,3 +1,15 @@ +/* + * 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.api.product import com.baomidou.mybatisplus.extension.plugins.pagination.Page diff --git a/api/src/main/java/com/wansensoft/api/product/ProductCategoryController.kt b/api/src/main/java/com/wansensoft/api/product/ProductCategoryController.kt index f0cb92025..44cdf9033 100644 --- a/api/src/main/java/com/wansensoft/api/product/ProductCategoryController.kt +++ b/api/src/main/java/com/wansensoft/api/product/ProductCategoryController.kt @@ -1,3 +1,15 @@ +/* + * 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.api.product import com.wansensoft.dto.product.AddOrUpdateProductCategoryDTO diff --git a/api/src/main/java/com/wansensoft/api/product/ProductUnitController.kt b/api/src/main/java/com/wansensoft/api/product/ProductUnitController.kt new file mode 100644 index 000000000..c814b0608 --- /dev/null +++ b/api/src/main/java/com/wansensoft/api/product/ProductUnitController.kt @@ -0,0 +1,47 @@ +/* + * 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.api.product + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.wansensoft.dto.product.AddOrUpdateProductUnitDTO +import com.wansensoft.dto.product.ProductUnitQueryDTO +import com.wansensoft.dto.product.ProductUnitStatusDTO +import com.wansensoft.service.product.ProductUnitService +import com.wansensoft.utils.response.Response +import com.wansensoft.vo.product.ProductUnitVO +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/product/unit") +class ProductUnitController(private val productUnitService: ProductUnitService) { + + @PostMapping("/list") + fun productUnitList(@RequestBody productUnitQuery: ProductUnitQueryDTO): Response> { + return productUnitService.productUnitList(productUnitQuery) + } + + @PostMapping("/addOrUpdate") + fun addOrUpdateProductUnit(@RequestBody productUnit: AddOrUpdateProductUnitDTO): Response { + return productUnitService.addOrUpdateProductUnit(productUnit) + } + + @DeleteMapping("/deleteBatch") + fun deleteProductUnit(@RequestParam ids: List): Response { + return productUnitService.deleteProductUnit(ids) + } + + @PostMapping("/updateUnitStatus") + fun updateUnitStatus(@RequestBody productUnitStatus: ProductUnitStatusDTO): Response { + return productUnitService.updateUnitStatus(productUnitStatus) + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/wansensoft/bo/BigDecimalSerializerBO.kt b/domain/src/main/java/com/wansensoft/bo/BigDecimalSerializerBO.kt new file mode 100644 index 000000000..f65429d32 --- /dev/null +++ b/domain/src/main/java/com/wansensoft/bo/BigDecimalSerializerBO.kt @@ -0,0 +1,34 @@ +/* + * 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.bo + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import java.math.BigDecimal +import java.math.RoundingMode + +class BigDecimalSerializerBO : JsonSerializer() { + override fun serialize(value: BigDecimal?, gen: JsonGenerator, serializers: SerializerProvider) { + if (value != null) { + val scaledValue = value.setScale(3, RoundingMode.HALF_UP) + if (scaledValue.stripTrailingZeros().scale() <= 0) { + gen.writeNumber(scaledValue.toBigInteger()) + } else { + gen.writeNumber(scaledValue) + } + } else { + gen.writeNull() + } + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/wansensoft/bo/SmsInfoBO.java b/domain/src/main/java/com/wansensoft/bo/SmsInfoBO.java index 85ed25996..a566a41d2 100644 --- a/domain/src/main/java/com/wansensoft/bo/SmsInfoBO.java +++ b/domain/src/main/java/com/wansensoft/bo/SmsInfoBO.java @@ -1,9 +1,19 @@ +/* + * 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.bo; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; @Data @Builder diff --git a/domain/src/main/java/com/wansensoft/dto/department/AddOrUpdateDeptDTO.kt b/domain/src/main/java/com/wansensoft/dto/department/AddOrUpdateDeptDTO.kt index cb2098370..2873d46c6 100644 --- a/domain/src/main/java/com/wansensoft/dto/department/AddOrUpdateDeptDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/department/AddOrUpdateDeptDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.department import lombok.Data diff --git a/domain/src/main/java/com/wansensoft/dto/department/DeptListDTO.java b/domain/src/main/java/com/wansensoft/dto/department/DeptListDTO.java index 36c307af1..067d36055 100644 --- a/domain/src/main/java/com/wansensoft/dto/department/DeptListDTO.java +++ b/domain/src/main/java/com/wansensoft/dto/department/DeptListDTO.java @@ -1,3 +1,15 @@ +/* + * 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.dto.department; import com.wansensoft.dto.PageSizeDTO; diff --git a/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductAttributeDTO.kt b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductAttributeDTO.kt index 39d006c6c..9f0d6f1ff 100644 --- a/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductAttributeDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductAttributeDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.product import lombok.Data diff --git a/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductCategoryDTO.kt b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductCategoryDTO.kt index 1e92743df..6bfee1324 100644 --- a/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductCategoryDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductCategoryDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.product import lombok.Data diff --git a/api/src/main/java/com/wansensoft/api/product/ProductUnitController.java b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductUnitDTO.kt similarity index 57% rename from api/src/main/java/com/wansensoft/api/product/ProductUnitController.java rename to domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductUnitDTO.kt index a7cc10005..1a9df5b0f 100644 --- a/api/src/main/java/com/wansensoft/api/product/ProductUnitController.java +++ b/domain/src/main/java/com/wansensoft/dto/product/AddOrUpdateProductUnitDTO.kt @@ -10,22 +10,27 @@ * 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.api.product; +package com.wansensoft.dto.product -import org.springframework.web.bind.annotation.RequestMapping; +import java.math.BigDecimal -import org.springframework.web.bind.annotation.RestController; +data class AddOrUpdateProductUnitDTO ( -/** - *

- * 多单位表 前端控制器 - *

- * - * @author James Zow - * @since 2023-09-05 - */ -@RestController -@RequestMapping("/product-unit") -public class ProductUnitController { + val id : Long? = null, + + var basicUnit: String? = null, + + var otherUnit: String? = null, + + var otherUnitTwo: String? = null, + + var otherUnitThree: String? = null, + + var ratio: BigDecimal? = null, + + var ratioTwo: BigDecimal? = null, + + var ratioThree: BigDecimal? = null, -} + var status: Int? = null +) \ No newline at end of file diff --git a/domain/src/main/java/com/wansensoft/dto/product/ProductAttributeQueryDTO.kt b/domain/src/main/java/com/wansensoft/dto/product/ProductAttributeQueryDTO.kt index 98312a573..abc1972aa 100644 --- a/domain/src/main/java/com/wansensoft/dto/product/ProductAttributeQueryDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/product/ProductAttributeQueryDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.product import com.wansensoft.dto.PageSizeDTO diff --git a/service/src/main/java/com/wansensoft/service/product/IProductUnitService.java b/domain/src/main/java/com/wansensoft/dto/product/ProductUnitQueryDTO.kt similarity index 67% rename from service/src/main/java/com/wansensoft/service/product/IProductUnitService.java rename to domain/src/main/java/com/wansensoft/dto/product/ProductUnitQueryDTO.kt index ee929f535..6397353a6 100644 --- a/service/src/main/java/com/wansensoft/service/product/IProductUnitService.java +++ b/domain/src/main/java/com/wansensoft/dto/product/ProductUnitQueryDTO.kt @@ -10,16 +10,13 @@ * 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; +package com.wansensoft.dto.product -import com.wansensoft.entities.product.ProductUnit; -import com.baomidou.mybatisplus.extension.service.IService; +import com.wansensoft.dto.PageSizeDTO -/** - *

- * 多单位表 服务类 - *

- */ -public interface IProductUnitService extends IService { +data class ProductUnitQueryDTO ( + + val page: PageSizeDTO? = null, -} + val computeUnit: String? = null, +) \ No newline at end of file diff --git a/domain/src/main/java/com/wansensoft/dto/product/ProductUnitStatusDTO.kt b/domain/src/main/java/com/wansensoft/dto/product/ProductUnitStatusDTO.kt new file mode 100644 index 000000000..3bf928452 --- /dev/null +++ b/domain/src/main/java/com/wansensoft/dto/product/ProductUnitStatusDTO.kt @@ -0,0 +1,8 @@ +package com.wansensoft.dto.product + +data class ProductUnitStatusDTO( + + val id: Long? = null, + + var status: Int? = null +) diff --git a/domain/src/main/java/com/wansensoft/dto/role/AddOrUpdateRoleDTO.kt b/domain/src/main/java/com/wansensoft/dto/role/AddOrUpdateRoleDTO.kt index 9c7182c8b..dd30e2c0f 100644 --- a/domain/src/main/java/com/wansensoft/dto/role/AddOrUpdateRoleDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/role/AddOrUpdateRoleDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.role import com.wansensoft.dto.PageSizeDTO diff --git a/domain/src/main/java/com/wansensoft/dto/role/RoleListDTO.java b/domain/src/main/java/com/wansensoft/dto/role/RoleListDTO.java index 624ed26f2..f3aa9227f 100644 --- a/domain/src/main/java/com/wansensoft/dto/role/RoleListDTO.java +++ b/domain/src/main/java/com/wansensoft/dto/role/RoleListDTO.java @@ -1,3 +1,15 @@ +/* + * 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.dto.role; import com.wansensoft.dto.PageSizeDTO; diff --git a/domain/src/main/java/com/wansensoft/dto/role/RolePermissionDTO.kt b/domain/src/main/java/com/wansensoft/dto/role/RolePermissionDTO.kt index f45eae9cc..ea9254cd0 100644 --- a/domain/src/main/java/com/wansensoft/dto/role/RolePermissionDTO.kt +++ b/domain/src/main/java/com/wansensoft/dto/role/RolePermissionDTO.kt @@ -1,3 +1,15 @@ +/* + * 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.dto.role import lombok.Data diff --git a/domain/src/main/java/com/wansensoft/dto/user/AddOrUpdateUserDTO.java b/domain/src/main/java/com/wansensoft/dto/user/AddOrUpdateUserDTO.java index 88c71e1b7..45fe2e169 100644 --- a/domain/src/main/java/com/wansensoft/dto/user/AddOrUpdateUserDTO.java +++ b/domain/src/main/java/com/wansensoft/dto/user/AddOrUpdateUserDTO.java @@ -1,3 +1,15 @@ +/* + * 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.dto.user; import lombok.Data; diff --git a/domain/src/main/java/com/wansensoft/dto/user/MobileLoginDTO.java b/domain/src/main/java/com/wansensoft/dto/user/MobileLoginDTO.java index 8cb2e327b..40ba27171 100644 --- a/domain/src/main/java/com/wansensoft/dto/user/MobileLoginDTO.java +++ b/domain/src/main/java/com/wansensoft/dto/user/MobileLoginDTO.java @@ -1,3 +1,15 @@ +/* + * 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.dto.user; import lombok.Data; diff --git a/domain/src/main/java/com/wansensoft/dto/user/UserListDTO.java b/domain/src/main/java/com/wansensoft/dto/user/UserListDTO.java index 9f63f027d..9d076a364 100644 --- a/domain/src/main/java/com/wansensoft/dto/user/UserListDTO.java +++ b/domain/src/main/java/com/wansensoft/dto/user/UserListDTO.java @@ -1,3 +1,15 @@ +/* + * 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.dto.user; import com.wansensoft.dto.PageSizeDTO; diff --git a/domain/src/main/java/com/wansensoft/entities/product/ProductUnit.java b/domain/src/main/java/com/wansensoft/entities/product/ProductUnit.java index 3a4966f61..a503572e9 100644 --- a/domain/src/main/java/com/wansensoft/entities/product/ProductUnit.java +++ b/domain/src/main/java/com/wansensoft/entities/product/ProductUnit.java @@ -47,9 +47,9 @@ public class ProductUnit implements Serializable { private Long tenantId; /** - * 名称,支持多单位 + * 计量单位,计算得出 */ - private String name; + private String computeUnit; /** * 基础单位 @@ -89,7 +89,7 @@ public class ProductUnit implements Serializable { /** * 启用 */ - private Boolean status; + private Integer status; /** * 创建时间 @@ -114,7 +114,7 @@ public class ProductUnit implements Serializable { /** * 删除标记,0未删除,1删除 */ - private Boolean deleteFlag; + private Integer deleteFlag; } diff --git a/domain/src/main/java/com/wansensoft/vo/product/ProductAttributeVO.kt b/domain/src/main/java/com/wansensoft/vo/product/ProductAttributeVO.kt index edb0ee2a9..bcec944a4 100644 --- a/domain/src/main/java/com/wansensoft/vo/product/ProductAttributeVO.kt +++ b/domain/src/main/java/com/wansensoft/vo/product/ProductAttributeVO.kt @@ -1,3 +1,15 @@ +/* + * 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.vo.product import com.fasterxml.jackson.annotation.JsonFormat diff --git a/domain/src/main/java/com/wansensoft/vo/product/ProductUnitVO.kt b/domain/src/main/java/com/wansensoft/vo/product/ProductUnitVO.kt new file mode 100644 index 000000000..7d49483fe --- /dev/null +++ b/domain/src/main/java/com/wansensoft/vo/product/ProductUnitVO.kt @@ -0,0 +1,59 @@ +/* + * 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.vo.product + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.wansensoft.bo.BigDecimalSerializerBO +import java.math.BigDecimal +import java.time.LocalDateTime + +data class ProductUnitVO ( + + @JsonFormat(shape = JsonFormat.Shape.STRING) + var id : Long? = null, + + var basicUnit: String? = null, + + var otherUnit: String? = null, + + // Table All Unit Assembly Text Data + var computeUnit : String? = null, + + // Table Multiple Unit Text Data + var otherComputeUnit : String? = null, + + var otherUnitTwo: String? = null, + + // Table Multiple Unit 2 Text Data + var otherComputeUnitTwo : String? = null, + + var otherUnitThree: String? = null, + + // Table Multiple Unit 3 Text Data + var otherComputeUnitThree : String? = null, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var ratio: BigDecimal? = null, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var ratioTwo: BigDecimal? = null, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var ratioThree: BigDecimal? = null, + + var status: Int? = null, + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + var createTime: LocalDateTime? = null +) \ No newline at end of file diff --git a/service/src/main/java/com/wansensoft/service/BaseService.java b/service/src/main/java/com/wansensoft/service/BaseService.java new file mode 100644 index 000000000..5d74894fe --- /dev/null +++ b/service/src/main/java/com/wansensoft/service/BaseService.java @@ -0,0 +1,48 @@ +package com.wansensoft.service; + +import com.wansensoft.utils.redis.RedisUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import java.util.Optional; + +@Service +@Slf4j +public class BaseService { + + private final RedisUtil redisUtil; + + public BaseService(RedisUtil redisUtil) { + this.redisUtil = redisUtil; + } + + public Long getCurrentUserId() { + var token = httpServletRequestContextToken(); + return Long.parseLong(redisUtil.getString(token + ":userId")); + } + + public Long getCurrentTenantId() { + var token = httpServletRequestContextToken(); + return Long.parseLong(redisUtil.getString(token + ":tenantId")); + } + + public String getCurrentUserName() { + var token = httpServletRequestContextToken(); + return redisUtil.getString(token + ":userName"); + } + + public String getCurrentUserAccount() { + var token = httpServletRequestContextToken(); + return redisUtil.getString(token + ":userAccount"); + } + + private String httpServletRequestContextToken() { + var sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (sra == null) { + log.error("[异常]获取HttpServletRequest为空"); + } + return Optional.ofNullable(sra.getRequest().getHeader("Authorization")).orElseThrow(null); + } +} diff --git a/service/src/main/java/com/wansensoft/service/product/ProductUnitService.kt b/service/src/main/java/com/wansensoft/service/product/ProductUnitService.kt new file mode 100644 index 000000000..43703c6cf --- /dev/null +++ b/service/src/main/java/com/wansensoft/service/product/ProductUnitService.kt @@ -0,0 +1,33 @@ +/* + * 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.AddOrUpdateProductUnitDTO +import com.wansensoft.dto.product.ProductUnitQueryDTO +import com.wansensoft.dto.product.ProductUnitStatusDTO +import com.wansensoft.entities.product.ProductUnit +import com.wansensoft.utils.response.Response +import com.wansensoft.vo.product.ProductUnitVO + +interface ProductUnitService: IService { + + fun productUnitList(productUnitQuery: ProductUnitQueryDTO?): Response> + + fun addOrUpdateProductUnit(productUnit: AddOrUpdateProductUnitDTO?): Response + + fun deleteProductUnit(ids: List?): Response + + fun updateUnitStatus(productUnitStatus: ProductUnitStatusDTO?): Response +} \ No newline at end of file diff --git a/service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.kt b/service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.kt index fa5b9955f..7d743c0c6 100644 --- a/service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.kt +++ b/service/src/main/java/com/wansensoft/service/product/impl/ProductAttributeServiceImpl.kt @@ -21,6 +21,7 @@ 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.SnowflakeIdUtil import com.wansensoft.utils.constants.CommonConstants import com.wansensoft.utils.enums.BaseCodeEnum import com.wansensoft.utils.enums.ProdcutCodeEnum @@ -45,23 +46,18 @@ open class ProductAttributeServiceImpl( val result = page?.run { productAttributeMapper.selectPage(this, wrapper) - if (records.isNotEmpty()) { - val listVo = records.map { attribute -> - ProductAttributeVO().apply { - BeanUtils.copyProperties(attribute, this) - } - } - Page().apply { - records = listVo - total = this@run.total - pages = this@run.pages - size = this@run.size + val listVo = records.map { attribute -> + ProductAttributeVO().apply { + BeanUtils.copyProperties(attribute, this) } - - } else { - Page() } - }?: Page() + Page().apply { + records = listVo + total = this@run.total + pages = this@run.pages + size = this@run.size + } + } ?: Page() return Response.responseData(result) } @@ -79,6 +75,7 @@ open class ProductAttributeServiceImpl( if (count > 0) { return Response.responseMsg(ProdcutCodeEnum.PRODUCT_ATTRIBUTE_NAME_EXIST) } + attribute.id = SnowflakeIdUtil.nextId() attribute.createTime = LocalDateTime.now() attribute.createBy = userId val saveResult = saveAttribute(attribute) diff --git a/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.java b/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.java deleted file mode 100644 index 71fdf8804..000000000 --- a/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.wansensoft.service.product.IProductUnitService; -import com.wansensoft.entities.product.ProductUnit; -import com.wansensoft.mappers.product.ProductUnitMapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -/** - *

- * 多单位表 服务实现类 - *

- */ -@Service -public class ProductUnitServiceImpl extends ServiceImpl implements IProductUnitService { - -} diff --git a/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.kt b/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.kt new file mode 100644 index 000000000..1a3dea2fa --- /dev/null +++ b/service/src/main/java/com/wansensoft/service/product/impl/ProductUnitServiceImpl.kt @@ -0,0 +1,188 @@ +/* + * 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.AddOrUpdateProductUnitDTO +import com.wansensoft.dto.product.ProductUnitQueryDTO +import com.wansensoft.dto.product.ProductUnitStatusDTO +import com.wansensoft.entities.product.ProductUnit +import com.wansensoft.mappers.product.ProductUnitMapper +import com.wansensoft.service.BaseService +import com.wansensoft.service.product.ProductUnitService +import com.wansensoft.utils.SnowflakeIdUtil +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.ProductUnitVO +import org.springframework.stereotype.Service +import java.math.BigDecimal +import java.math.RoundingMode +import java.time.LocalDateTime + +@Service +open class ProductUnitServiceImpl( + private val productUnitMapper: ProductUnitMapper, + private val baseService: BaseService +) :ServiceImpl(), ProductUnitService { + + override fun productUnitList(productUnitQuery: ProductUnitQueryDTO?): Response> { + val page = productUnitQuery?.let { query -> + val pageSizeDTO = query.page + val page = pageSizeDTO?.page ?: 0L + val pageSize = pageSizeDTO?.pageSize ?: 10L + Page(page, pageSize) + } + val wrapper = LambdaQueryWrapper().apply { + productUnitQuery?.computeUnit?.let { like(ProductUnit::getComputeUnit, it) } + eq(ProductUnit::getDeleteFlag, CommonConstants.NOT_DELETED) + } + + val result = page?.run { + productUnitMapper.selectPage(this, wrapper) + val listVo = records.map { unit -> + ProductUnitVO( + id = unit.id, + computeUnit = unit.computeUnit, + basicUnit = unit.basicUnit, + otherUnit = unit.otherUnit, + otherUnitTwo = unit.otherUnitTwo, + otherUnitThree = unit.otherUnitThree, + ratio = unit.ratio, + ratioTwo = unit.ratioTwo, + ratioThree = unit.ratioThree, + status = unit.status, + createTime = unit.createTime, + otherComputeUnit = formatBigDecimal(unit.ratio, unit.otherUnit, unit.basicUnit), + otherComputeUnitTwo = formatBigDecimal(unit.ratioTwo, unit.otherUnitTwo, unit.basicUnit), + otherComputeUnitThree = formatBigDecimal(unit.ratioThree, unit.otherUnitThree, unit.basicUnit) + ) + } + Page().apply { + records = listVo + total = this@run.total + pages = this@run.pages + size = this@run.size + } + } ?: Page() + + return Response.responseData(result) + } + + private fun formatBigDecimal(ratio: BigDecimal?, otherUnit: String?, basicUnit: String?): String? { + return ratio?.let { + val scaledValue = it.setScale(3, RoundingMode.HALF_UP) + val formattedValue = if (scaledValue.stripTrailingZeros().scale() <= 0) { + scaledValue.toBigInteger().toString() + } else { + scaledValue.toString() + } + "$otherUnit=$formattedValue$basicUnit" + } + } + + override fun addOrUpdateProductUnit(productUnit: AddOrUpdateProductUnitDTO?): Response { + productUnit?.let { unit -> + val unitId = unit.id ?: SnowflakeIdUtil.nextId() + val unitWrapper = LambdaQueryWrapper().apply { + eq(ProductUnit::getComputeUnit, buildComputeUnit(unit)) + eq(ProductUnit::getDeleteFlag, CommonConstants.NOT_DELETED) + unit.id?.let { ne(ProductUnit::getId, it) } + } + val unitExists = productUnitMapper.exists(unitWrapper) + if (unitExists) { + return Response.responseMsg(ProdcutCodeEnum.PRODUCT_COMPUTE_UNIT_EXIST) + } + + val result = if (unit.id == null) { + save(buildProductUnit(unitId, unit)) + } else { + updateById(buildProductUnit(unitId, unit)) + } + + return if (result) { + if (unit.id == null) { + Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_ADD_SUCCESS) + } else { + Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_UPDATE_SUCCESS) + } + } else { + if (unit.id == null) { + Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_ADD_ERROR) + } else { + Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_UPDATE_ERROR) + } + } + } ?: return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } + + private fun buildProductUnit(id: Long, unit: AddOrUpdateProductUnitDTO): ProductUnit { + val creator = baseService.currentUserId + return ProductUnit().apply { + this.id = id + computeUnit = buildComputeUnit(unit) + basicUnit = unit.basicUnit + otherUnit = unit.otherUnit + otherUnitTwo = unit.otherUnitTwo + otherUnitThree = unit.otherUnitThree + ratio = unit.ratio + ratioTwo = unit.ratioTwo + ratioThree = unit.ratioThree + status = unit.status + // 如果id为空,说明是新增,需要设置创建时间 + if (unit.id == null) { + createTime = LocalDateTime.now() + createBy = creator + } else { + updateTime = LocalDateTime.now() + updateBy = creator + } + } + } + + private fun buildComputeUnit(productUnit: AddOrUpdateProductUnitDTO): String { + val computeUnit = StringBuilder() + computeUnit.append("${productUnit.basicUnit}/(${productUnit.otherUnit}=${productUnit.ratio}${productUnit.basicUnit})") + productUnit.otherUnitTwo?.let { computeUnit.append("/(${it}=${productUnit.ratioTwo}${productUnit.basicUnit})") } + productUnit.otherUnitThree?.let { computeUnit.append("/(${it}=${productUnit.ratioThree}${productUnit.basicUnit})") } + return computeUnit.toString() + } + + override fun deleteProductUnit(ids: List?): Response { + ids?.let { + val deleteResult = productUnitMapper.deleteBatchIds(ids) + if(deleteResult == 0) { + return Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_DELETE_ERROR) + } + return Response.responseMsg(ProdcutCodeEnum.PRODUCT_UNIT_DELETE_SUCCESS) + }?: return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } + + override fun updateUnitStatus(productUnitStatus: ProductUnitStatusDTO?): Response { + return productUnitStatus?.let { item -> + val unit = ProductUnit().apply { + id = item.id + status = item.status + } + val updateResult = productUnitMapper.updateById(unit) + if (updateResult == 0) { + Response.responseMsg(ProdcutCodeEnum.UPDATE_PRODUCT_UNIT_STATUS_ERROR) + } else { + Response.responseMsg(ProdcutCodeEnum.UPDATE_PRODUCT_UNIT_STATUS_SUCCESS) + } + } ?: Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } +} \ No newline at end of file diff --git a/utils/pom.xml b/utils/pom.xml index 72badc5b4..fa42c01e5 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -73,6 +73,12 @@ kaptcha 2.3.2 + + + com.fasterxml.jackson.module + jackson-module-kotlin + 2.14.2 + \ No newline at end of file diff --git a/utils/src/main/java/com/wansensoft/utils/enums/ProdcutCodeEnum.java b/utils/src/main/java/com/wansensoft/utils/enums/ProdcutCodeEnum.java index 7b3768883..62c5ddf32 100644 --- a/utils/src/main/java/com/wansensoft/utils/enums/ProdcutCodeEnum.java +++ b/utils/src/main/java/com/wansensoft/utils/enums/ProdcutCodeEnum.java @@ -30,7 +30,26 @@ public enum ProdcutCodeEnum { DELETE_PRODUCT_ATTRIBUTE_SUCCESS("P0005", "删除商品属性成功"), - DELETE_PRODUCT_ATTRIBUTE_ERROR("P0505", "删除商品属性失败"); + DELETE_PRODUCT_ATTRIBUTE_ERROR("P0505", "删除商品属性失败"), + + // Product Unit Code + PRODUCT_COMPUTE_UNIT_EXIST("P0507", "商品计量单位已存在"), + + PRODUCT_UNIT_ADD_SUCCESS("P0006", "添加商品单位成功"), + + PRODUCT_UNIT_ADD_ERROR("P0506", "添加商品单位失败"), + + PRODUCT_UNIT_UPDATE_SUCCESS("P0007", "修改商品单位成功"), + + PRODUCT_UNIT_UPDATE_ERROR("P0507", "修改商品单位失败"), + + PRODUCT_UNIT_DELETE_SUCCESS("P0008", "删除商品单位成功"), + + PRODUCT_UNIT_DELETE_ERROR("P0508", "删除商品单位失败"), + + UPDATE_PRODUCT_UNIT_STATUS_SUCCESS("P0009", "修改商品单位状态成功"), + + UPDATE_PRODUCT_UNIT_STATUS_ERROR("P0509", "修改商品单位状态失败"); private final String code;