From 370840766fe31af1c50a126eeec61e7e3fabc986 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 00:03:33 +0800 Subject: [PATCH 1/8] Update URLEncoder in downloadExcel method --- utils/src/main/java/com/wansensoft/utils/ExcelUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/src/main/java/com/wansensoft/utils/ExcelUtil.java b/utils/src/main/java/com/wansensoft/utils/ExcelUtil.java index 8cbb27de1..99d61586c 100644 --- a/utils/src/main/java/com/wansensoft/utils/ExcelUtil.java +++ b/utils/src/main/java/com/wansensoft/utils/ExcelUtil.java @@ -13,6 +13,8 @@ package com.wansensoft.utils; import java.io.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.*; import jxl.*; @@ -156,7 +158,7 @@ public static int getRightRows(Sheet src) { public static void downloadExcel(File excelFile, String fileName, HttpServletResponse response) throws Exception{ response.setContentType("application/octet-stream"); - fileName = new String(fileName.getBytes("gbk"),"ISO8859_1"); + fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8); response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + ".xls" + "\""); FileInputStream fis = new FileInputStream(excelFile); OutputStream out = response.getOutputStream(); From 5bce0c95876ed00bf73d3a7cba468c72e7646ab5 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 00:03:51 +0800 Subject: [PATCH 2/8] update template --- ...24\345\225\206\345\210\227\350\241\250.xlsx" | Bin 0 -> 13824 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\344\276\233\345\272\224\345\225\206\345\210\227\350\241\250.xlsx" diff --git "a/\344\276\233\345\272\224\345\225\206\345\210\227\350\241\250.xlsx" "b/\344\276\233\345\272\224\345\225\206\345\210\227\350\241\250.xlsx" new file mode 100644 index 0000000000000000000000000000000000000000..f354f0d1ed24948d0262d776b244e6f9515ae674 GIT binary patch literal 13824 zcmeHOYiv|S6h56j^qd=EOsaQ*Slvpg=Clpcy+Oo6_EhV%-TZmmz zVoBSGu@)2fgCQoyL?Ka#NQlIk;3Eh|qfv}S`Qa}`5?O}Q(S~y;QT?8CllIrovDcr;2b7Z?jr@< zE-Yl6gRYGJ%*kuX>wS@Ibi{rdHPMea*3cGOR=vI2U(i+?YVfcFT7&S{8NwQpdaD7RknQDuUFO+ zWbH*Q=(xP*TWJYUI-Nm(y>lPm<|q!akhW3-RZ}C~+t$mN%|j;yKiCENiFR=$Tuhy( zjTo<>DKYGsG3--g*xe)A9q>R9p6OjFDK5LqZu-N|^+LEME&csdFVGCfU2{@8T zOr;xDq0+0N%(|j3?slzPFY}je=ugm{Wk+cgpu;lFmB2x2Hc znY-=#ZgengOz1aq$bxzR&n%Ib+tIgJ;>KfHRn!d+L=-&p!b zIWFpMVPiar0Oe2?&7yfUhh}3>c}yN?U}J!$>7`pLZX#IaIXo@?2vA@fN#cG zgXNZ!L=O69!H^|CaFW9|+zUtvJOiu&ehLf$uK;_1gTVd3 zbUf1U0LKI02hIn630w#K6SxKF!8W}g7yupy<^ewj)&f14+j#pYN4@>yZN}RJ&A3;H zPPmB9#S1z^GXws$$JZt%f>bD zYVyk|pGX@Ik$j5{GTdh4H&|r9L8+ACCDaGwk;cf{U;>OsGMEjF$1s=%#=aTM4u<6$ zVh%7Y#t@4G&uDL(B!niWqHfFkU@_dBCtdLo6PQ?{cFp0W8sCiD0aj(dGq9 zvRD!r>&9&yix1DY$pl!c#cW`sET)0+8XDKx!FV+d<^UUGvA8JajAE`R=8j?>FrPI_ zd{kQk82{=p=1Yuf^G30x2*#`9lfPv6I^NcO`1WUvq9J-8J!CPCZW39Hx_%y7f zkH%STk@0C*$zdfltYjqP_#U>dYpniFEMP9$2k^jr4=_Z11k{KSB83 zHGR0_tBoX4cwbK2kiy)Av}KOH5GrhxKCz`0sm#r=#4eLDKgVtQ5WDAa3+HvpWJ`d9 fmSBcj=>sQEx89{cIhfy!opE@U*k>~Iq4@s>hct>8 literal 0 HcmV?d00001 From 78ae959701abffe2759dbac447198d32cc5b3eb1 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 00:04:17 +0800 Subject: [PATCH 3/8] remove quarterAccountReceivable filed in supplier data object --- .../wansensoft/entities/basic/Supplier.java | 27 +---------- .../wansensoft/dto/basic/AddSupplierDTO.kt | 16 ------- .../wansensoft/dto/basic/UpdateSupplierDTO.kt | 20 --------- .../com/wansensoft/vo/basic/SupplierVO.kt | 20 --------- .../service/common/CommonServiceImpl.java | 29 +++++------- .../service/basic/impl/SupplierServiceImpl.kt | 45 ------------------- 6 files changed, 11 insertions(+), 146 deletions(-) diff --git a/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java b/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java index a435f86f6..40890103a 100644 --- a/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java +++ b/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java @@ -77,7 +77,7 @@ public class Supplier implements Serializable { private Integer isSystem; /** - * 类型 + * 类型 (预留字段) */ private String type; @@ -86,26 +86,6 @@ public class Supplier implements Serializable { */ private Integer status; - /** - * 一季度应收账款 - */ - private BigDecimal firstQuarterAccountReceivable; - - /** - * 二季度应收账款 - */ - private BigDecimal secondQuarterAccountReceivable; - - /** - * 三季度应收账款 - */ - private BigDecimal thirdQuarterAccountReceivable; - - /** - * 四季度应收账款 - */ - private BigDecimal fourthQuarterAccountReceivable; - /** * 一季度应付账款 */ @@ -126,11 +106,6 @@ public class Supplier implements Serializable { */ private BigDecimal fourthQuarterAccountPayment; - /** - * 累计应收账款 - */ - private BigDecimal totalAccountReceivable; - /** * 累计应付账款 */ diff --git a/domain/src/main/kotlin/com/wansensoft/dto/basic/AddSupplierDTO.kt b/domain/src/main/kotlin/com/wansensoft/dto/basic/AddSupplierDTO.kt index ba7a2cf0e..e74abdd05 100644 --- a/domain/src/main/kotlin/com/wansensoft/dto/basic/AddSupplierDTO.kt +++ b/domain/src/main/kotlin/com/wansensoft/dto/basic/AddSupplierDTO.kt @@ -41,22 +41,6 @@ data class AddSupplierDTO ( * 状态 */ val status: Int? = null, - /** - * 第一季度应收账款 - */ - val firstQuarterAccountReceivable: Double? = null, - /** - * 第二季度应收账款 - */ - val secondQuarterAccountReceivable: Double? = null, - /** - * 第三季度应收账款 - */ - val thirdQuarterAccountReceivable: Double? = null, - /** - * 第四季度应收账款 - */ - val fourthQuarterAccountReceivable: Double? = null, /** * 第一季度应付账款 */ diff --git a/domain/src/main/kotlin/com/wansensoft/dto/basic/UpdateSupplierDTO.kt b/domain/src/main/kotlin/com/wansensoft/dto/basic/UpdateSupplierDTO.kt index 1f685c86a..79aa485b5 100644 --- a/domain/src/main/kotlin/com/wansensoft/dto/basic/UpdateSupplierDTO.kt +++ b/domain/src/main/kotlin/com/wansensoft/dto/basic/UpdateSupplierDTO.kt @@ -35,26 +35,6 @@ data class UpdateSupplierDTO( * 状态 */ val status: Int?, - /** - * 第一季度应收账款 - */ - val firstQuarterAccountReceivable: Double?, - /** - * 第二季度应收账款 - */ - val secondQuarterAccountReceivable: Double?, - /** - * 第三季度应收账款 - */ - val thirdQuarterAccountReceivable: Double?, - /** - * 第四季度应收账款 - */ - val fourthQuarterAccountReceivable: Double?, - /** - * 应收账款总额 - */ - val totalAccountReceivable: BigDecimal?, /** * 第一季度应付账款 */ diff --git a/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt b/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt index 76c0786c6..fc819ff7a 100644 --- a/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt +++ b/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt @@ -50,26 +50,6 @@ data class SupplierVO ( var status: Int, - @JsonSerialize(using = BigDecimalSerializerBO::class) - @ExcelExport(value = "一季度收款", sort = 7) - var firstQuarterAccountReceivable: BigDecimal?, - - @JsonSerialize(using = BigDecimalSerializerBO::class) - @ExcelExport(value = "二季度收款", sort = 8) - var secondQuarterAccountReceivable: BigDecimal?, - - @JsonSerialize(using = BigDecimalSerializerBO::class) - @ExcelExport(value = "三季度收款", sort = 9) - var thirdQuarterAccountReceivable: BigDecimal?, - - @JsonSerialize(using = BigDecimalSerializerBO::class) - @ExcelExport(value = "四季度收款", sort = 10) - var fourthQuarterAccountReceivable: BigDecimal?, - - @JsonSerialize(using = BigDecimalSerializerBO::class) - @ExcelExport(value = "累计应收账款", sort = 11) - var totalAccountReceivable: BigDecimal?, - @JsonSerialize(using = BigDecimalSerializerBO::class) @ExcelExport(value = "一季度付款", sort = 12) var firstQuarterAccountPayment: BigDecimal?, diff --git a/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java b/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java index 644d5e4c7..db7a18edd 100644 --- a/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java +++ b/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java @@ -210,7 +210,6 @@ public File exportExcel(String type) { } String[] columnNames = {"供应商名称", "联系人", "联系电话", "联系人电话", "邮箱", "传真", - "第一季度应收账款", "第二季度应收账款", "第三季度应收账款", "第四季度应收账款", "第一季度应付账款", "第二季度应付账款", "第三季度应付账款", "第四季度应付账款", "税号", "税率", "开户行", "账号", "地址", "备注"}; @@ -224,20 +223,16 @@ public File exportExcel(String type) { supplier[3] = StringUtils.hasText(item.getContactNumber()) ? item.getContactNumber() : ""; supplier[4] = StringUtils.hasText(item.getEmail()) ? item.getEmail() : ""; supplier[5] = StringUtils.hasText(item.getFax()) ? item.getFax() : ""; - supplier[6] = item.getFirstQuarterAccountReceivable() != null ? item.getFirstQuarterAccountReceivable().toString() : ""; - supplier[7] = item.getSecondQuarterAccountReceivable() != null ? item.getSecondQuarterAccountReceivable().toString() : ""; - supplier[8] = item.getThirdQuarterAccountReceivable() != null ? item.getThirdQuarterAccountReceivable().toString() : ""; - supplier[9] = item.getFourthQuarterAccountReceivable() != null ? item.getFourthQuarterAccountReceivable().toString() : ""; - supplier[10] = item.getFirstQuarterAccountPayment() != null ? item.getFirstQuarterAccountPayment().toString() : ""; - supplier[11] = item.getSecondQuarterAccountPayment() != null ? item.getSecondQuarterAccountPayment().toString() : ""; - supplier[12] = item.getThirdQuarterAccountPayment() != null ? item.getThirdQuarterAccountPayment().toString() : ""; - supplier[13] = item.getFourthQuarterAccountPayment() != null ? item.getFourthQuarterAccountPayment().toString() : ""; - supplier[14] = StringUtils.hasText(item.getTaxNumber()) ? item.getTaxNumber() : ""; - supplier[15] = item.getTaxRate() != null ? item.getTaxRate().toString() : ""; - supplier[16] = StringUtils.hasText(item.getBankName()) ? item.getBankName() : ""; - supplier[17] = item.getAccountNumber() != null ? item.getAccountNumber().toString() : ""; - supplier[18] = StringUtils.hasText(item.getAddress()) ? item.getAddress() : ""; - supplier[19] = StringUtils.hasText(item.getRemark()) ? item.getRemark() : ""; + supplier[6] = item.getFirstQuarterAccountPayment() != null ? item.getFirstQuarterAccountPayment().toString() : ""; + supplier[7] = item.getSecondQuarterAccountPayment() != null ? item.getSecondQuarterAccountPayment().toString() : ""; + supplier[8] = item.getThirdQuarterAccountPayment() != null ? item.getThirdQuarterAccountPayment().toString() : ""; + supplier[9] = item.getFourthQuarterAccountPayment() != null ? item.getFourthQuarterAccountPayment().toString() : ""; + supplier[10] = StringUtils.hasText(item.getTaxNumber()) ? item.getTaxNumber() : ""; + supplier[11] = item.getTaxRate() != null ? item.getTaxRate().toString() : ""; + supplier[12] = StringUtils.hasText(item.getBankName()) ? item.getBankName() : ""; + supplier[13] = item.getAccountNumber() != null ? item.getAccountNumber().toString() : ""; + supplier[14] = StringUtils.hasText(item.getAddress()) ? item.getAddress() : ""; + supplier[15] = StringUtils.hasText(item.getRemark()) ? item.getRemark() : ""; data.add(supplier); } @@ -263,10 +258,6 @@ private boolean readSuppliersFromExcel(MultipartFile file) throws IOException { .contactNumber(getCellValue(row.getCell(3), dataFormatter)) .email(getCellValue(row.getCell(4), dataFormatter)) .fax(getCellValue(row.getCell(5), dataFormatter)) - .firstQuarterAccountReceivable(getNumericCellValue(row.getCell(6))) - .secondQuarterAccountReceivable(getNumericCellValue(row.getCell(7))) - .thirdQuarterAccountReceivable(getNumericCellValue(row.getCell(8))) - .fourthQuarterAccountReceivable(getNumericCellValue(row.getCell(9))) .firstQuarterAccountPayment(getNumericCellValue(row.getCell(10))) .secondQuarterAccountPayment(getNumericCellValue(row.getCell(11))) .thirdQuarterAccountPayment(getNumericCellValue(row.getCell(12))) diff --git a/service/src/main/kotlin/com/wansensoft/service/basic/impl/SupplierServiceImpl.kt b/service/src/main/kotlin/com/wansensoft/service/basic/impl/SupplierServiceImpl.kt index 7252da234..bd9eaff89 100644 --- a/service/src/main/kotlin/com/wansensoft/service/basic/impl/SupplierServiceImpl.kt +++ b/service/src/main/kotlin/com/wansensoft/service/basic/impl/SupplierServiceImpl.kt @@ -65,11 +65,6 @@ open class SupplierServiceImpl( address = supplier.address, email = supplier.email, status = supplier.status, - firstQuarterAccountReceivable = supplier.firstQuarterAccountReceivable, - secondQuarterAccountReceivable = supplier.secondQuarterAccountReceivable, - thirdQuarterAccountReceivable = supplier.thirdQuarterAccountReceivable, - fourthQuarterAccountReceivable = supplier.fourthQuarterAccountReceivable, - totalAccountReceivable = supplier.totalAccountReceivable, firstQuarterAccountPayment = supplier.firstQuarterAccountPayment, secondQuarterAccountPayment = supplier.secondQuarterAccountPayment, thirdQuarterAccountPayment = supplier.thirdQuarterAccountPayment, @@ -103,10 +98,6 @@ open class SupplierServiceImpl( val supplierEntity = supplier?.let { Supplier().apply { BeanUtils.copyProperties(it, this) - firstQuarterAccountReceivable = it.firstQuarterAccountReceivable?.toBigDecimal() - secondQuarterAccountReceivable = it.secondQuarterAccountReceivable?.toBigDecimal() - thirdQuarterAccountReceivable = it.thirdQuarterAccountReceivable?.toBigDecimal() - fourthQuarterAccountReceivable = it.fourthQuarterAccountReceivable?.toBigDecimal() firstQuarterAccountPayment = it.firstQuarterAccountPayment?.toBigDecimal() secondQuarterAccountPayment = it.secondQuarterAccountPayment?.toBigDecimal() thirdQuarterAccountPayment = it.thirdQuarterAccountPayment?.toBigDecimal() @@ -115,15 +106,6 @@ open class SupplierServiceImpl( } } ?: Supplier() - val totalAccountReceivable = calculateTotalAccount( - listOf( - supplierEntity.firstQuarterAccountReceivable, - supplierEntity.secondQuarterAccountReceivable, - supplierEntity.thirdQuarterAccountReceivable, - supplierEntity.fourthQuarterAccountReceivable - ) - ) - val totalAccountPayment = calculateTotalAccount( listOf( supplierEntity.firstQuarterAccountPayment, @@ -133,7 +115,6 @@ open class SupplierServiceImpl( ) ) - supplierEntity.totalAccountReceivable = totalAccountReceivable supplierEntity.totalAccountPayment = totalAccountPayment supplierEntity.createTime = LocalDateTime.now() supplierEntity.createBy = baseService.currentUserId @@ -161,23 +142,11 @@ open class SupplierServiceImpl( if (supplierEntity == null) { val newSupplierEntity = Supplier().apply { BeanUtils.copyProperties(supplier, this) - firstQuarterAccountReceivable = supplier.firstQuarterAccountReceivable - secondQuarterAccountReceivable = supplier.secondQuarterAccountReceivable - thirdQuarterAccountReceivable = supplier.thirdQuarterAccountReceivable - fourthQuarterAccountReceivable = supplier.fourthQuarterAccountReceivable firstQuarterAccountPayment = supplier.firstQuarterAccountPayment secondQuarterAccountPayment = supplier.secondQuarterAccountPayment thirdQuarterAccountPayment = supplier.thirdQuarterAccountPayment fourthQuarterAccountPayment = supplier.fourthQuarterAccountPayment taxRate = supplier.taxRate - totalAccountReceivable = calculateTotalAccount( - listOf( - supplier.firstQuarterAccountReceivable, - supplier.secondQuarterAccountReceivable, - supplier.thirdQuarterAccountReceivable, - supplier.fourthQuarterAccountReceivable - ) - ) totalAccountPayment = calculateTotalAccount( listOf( supplier.firstQuarterAccountPayment, @@ -202,10 +171,6 @@ open class SupplierServiceImpl( val supplierEntity = supplier?.let { Supplier().apply { BeanUtils.copyProperties(it, this) - firstQuarterAccountReceivable = it.firstQuarterAccountReceivable?.toBigDecimal() - secondQuarterAccountReceivable = it.secondQuarterAccountReceivable?.toBigDecimal() - thirdQuarterAccountReceivable = it.thirdQuarterAccountReceivable?.toBigDecimal() - fourthQuarterAccountReceivable = it.fourthQuarterAccountReceivable?.toBigDecimal() firstQuarterAccountPayment = it.firstQuarterAccountPayment?.toBigDecimal() secondQuarterAccountPayment = it.secondQuarterAccountPayment?.toBigDecimal() thirdQuarterAccountPayment = it.thirdQuarterAccountPayment?.toBigDecimal() @@ -214,15 +179,6 @@ open class SupplierServiceImpl( } } ?: Supplier() - val totalAccountReceivable = calculateTotalAccount( - listOf( - supplierEntity.firstQuarterAccountReceivable, - supplierEntity.secondQuarterAccountReceivable, - supplierEntity.thirdQuarterAccountReceivable, - supplierEntity.fourthQuarterAccountReceivable - ) - ) - val totalAccountPayment = calculateTotalAccount( listOf( supplierEntity.firstQuarterAccountPayment, @@ -232,7 +188,6 @@ open class SupplierServiceImpl( ) ) - supplierEntity.totalAccountReceivable = totalAccountReceivable supplierEntity.totalAccountPayment = totalAccountPayment supplierEntity.updateTime = LocalDateTime.now() supplierEntity.updateBy = baseService.currentUserId From 55a5d51d7a8329545895e3753906373f44d7e68c Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 02:30:51 +0800 Subject: [PATCH 4/8] Add license in head file #78 --- .../com/wansensoft/api/basic/SupplierController.kt | 12 ++++++++++++ domain/src/main/kotlin/com/wansensoft/NoArg.kt | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/api/src/main/kotlin/com/wansensoft/api/basic/SupplierController.kt b/api/src/main/kotlin/com/wansensoft/api/basic/SupplierController.kt index 7568750d1..2fc33af87 100644 --- a/api/src/main/kotlin/com/wansensoft/api/basic/SupplierController.kt +++ b/api/src/main/kotlin/com/wansensoft/api/basic/SupplierController.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.basic import com.baomidou.mybatisplus.extension.plugins.pagination.Page diff --git a/domain/src/main/kotlin/com/wansensoft/NoArg.kt b/domain/src/main/kotlin/com/wansensoft/NoArg.kt index 449d393dc..e3b4647e3 100644 --- a/domain/src/main/kotlin/com/wansensoft/NoArg.kt +++ b/domain/src/main/kotlin/com/wansensoft/NoArg.kt @@ -1,3 +1,14 @@ +/* + * 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 - annotation class NoArg \ No newline at end of file From dee927d7c1793aeb8be9a83f0e6ed51b30b84066 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 02:31:13 +0800 Subject: [PATCH 5/8] Update accountNumber file type -> string --- .../src/main/java/com/wansensoft/entities/basic/Supplier.java | 2 +- domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java b/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java index 40890103a..32e6b8d39 100644 --- a/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java +++ b/domain/src/main/java/com/wansensoft/entities/basic/Supplier.java @@ -139,7 +139,7 @@ public class Supplier implements Serializable { /** * 账号 */ - private Long accountNumber; + private String accountNumber; /** * 税率 diff --git a/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt b/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt index fc819ff7a..a8a7a9ecd 100644 --- a/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt +++ b/domain/src/main/kotlin/com/wansensoft/vo/basic/SupplierVO.kt @@ -80,7 +80,7 @@ data class SupplierVO ( var bankName: String?, @ExcelExport(value = "账号", sort = 20) - var accountNumber: Long?, + var accountNumber: String?, @JsonSerialize(using = BigDecimalSerializerBO::class) @ExcelExport(value = "税率(%)", sort = 18) From db61ebaa7ca578f442f4a283952603beeaad9401 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 02:31:38 +0800 Subject: [PATCH 6/8] Add CustomerCodeEnum class --- .../main/java/com/wansensoft/utils/response/Response.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/src/main/java/com/wansensoft/utils/response/Response.java b/utils/src/main/java/com/wansensoft/utils/response/Response.java index 31db3d23f..6d6f51bb9 100644 --- a/utils/src/main/java/com/wansensoft/utils/response/Response.java +++ b/utils/src/main/java/com/wansensoft/utils/response/Response.java @@ -89,6 +89,13 @@ public static Response responseMsg(SupplierCodeEnum supplierCodeEnum) { return baseResponse; } + public static Response responseMsg(CustomerCodeEnum customerCodeEnum) { + Response baseResponse = new Response(); + baseResponse.setCode(customerCodeEnum.getCode()); + baseResponse.setMsg(customerCodeEnum.getMsg()); + return baseResponse; + } + public static Response responseData(T data) { Response baseResponse = new Response(); baseResponse.setCode(BaseCodeEnum.SUCCESS.getCode()); From 29b927930c9009b0c4854cd4e466748032e30bae Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 02:31:55 +0800 Subject: [PATCH 7/8] Add customer information data import --- .../service/common/CommonServiceImpl.java | 115 ++++++++++++------ 1 file changed, 76 insertions(+), 39 deletions(-) diff --git a/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java b/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java index db7a18edd..fdad53423 100644 --- a/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java +++ b/service/src/main/java/com/wansensoft/service/common/CommonServiceImpl.java @@ -19,8 +19,10 @@ import com.tencentcloudapi.sms.v20190711.SmsClient; import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest; import com.wansensoft.bo.SmsInfoBO; +import com.wansensoft.entities.basic.Customer; import com.wansensoft.entities.basic.Supplier; import com.wansensoft.entities.system.SysPlatformConfig; +import com.wansensoft.service.basic.CustomerService; import com.wansensoft.service.basic.SupplierService; import com.wansensoft.service.system.ISysPlatformConfigService; import com.wansensoft.utils.ExcelUtil; @@ -28,17 +30,16 @@ import com.wansensoft.utils.constants.SecurityConstants; import com.wansensoft.utils.constants.SmsConstants; import com.wansensoft.utils.enums.BaseCodeEnum; +import com.wansensoft.utils.enums.CustomerCodeEnum; import com.wansensoft.utils.enums.SupplierCodeEnum; import com.wansensoft.utils.redis.RedisUtil; import com.wansensoft.utils.response.Response; import com.wansensoft.vo.CaptchaVO; import com.wansensoft.vo.basic.SupplierVO; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.springframework.beans.BeanUtils; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.FastByteArrayOutputStream; import org.springframework.util.StringUtils; @@ -64,12 +65,15 @@ public class CommonServiceImpl implements CommonService{ private final SupplierService supplierService; + private final CustomerService customerService; + private final ISysPlatformConfigService platformConfigService; - public CommonServiceImpl(RedisUtil redisUtil, Producer producer, SupplierService supplierService, ISysPlatformConfigService platformConfigService) { + public CommonServiceImpl(RedisUtil redisUtil, Producer producer, SupplierService supplierService, CustomerService customerService, ISysPlatformConfigService platformConfigService) { this.redisUtil = redisUtil; this.producer = producer; this.supplierService = supplierService; + this.customerService = customerService; this.platformConfigService = platformConfigService; } @@ -178,9 +182,12 @@ public Response uploadExclsData(MultipartFile file) { } return Response.responseMsg(SupplierCodeEnum.ADD_SUPPLIER_SUCCESS); - } else if (filename.contains("222.xlsx")) { - System.out.println("其他文件"); - + } else if (filename.contains("客户")) { + var result = readCustomerFromExcel(file); + if(!result){ + return Response.responseMsg(CustomerCodeEnum.ADD_CUSTOMER_ERROR); + } + return Response.responseMsg(CustomerCodeEnum.ADD_CUSTOMER_SUCCESS); } else { log.error("上传Excel文件失败: 文件名不匹配"); return Response.responseMsg(BaseCodeEnum.FILE_UPLOAD_NO_FILENAME_MATCH); @@ -193,6 +200,68 @@ public Response uploadExclsData(MultipartFile file) { return Response.responseMsg(BaseCodeEnum.FILE_UPLOAD_ERROR); } + private boolean readSuppliersFromExcel(MultipartFile file) throws IOException { + List suppliers = new ArrayList<>(); + Workbook workbook = new HSSFWorkbook(file.getInputStream()); + Sheet sheet = workbook.getSheetAt(0); + DataFormatter dataFormatter = new DataFormatter(); + + for (int i = 2; i <= sheet.getLastRowNum(); ++i) { + Row row = sheet.getRow(i); + var supplier = Supplier.builder() + .supplierName(getCellValue(row.getCell(0), dataFormatter)) + .contact(getCellValue(row.getCell(1), dataFormatter)) + .phoneNumber(getCellValue(row.getCell(2), dataFormatter)) + .contactNumber(getCellValue(row.getCell(3), dataFormatter)) + .email(getCellValue(row.getCell(4), dataFormatter)) + .fax(getCellValue(row.getCell(5), dataFormatter)) + .firstQuarterAccountPayment(getNumericCellValue(row.getCell(10))) + .secondQuarterAccountPayment(getNumericCellValue(row.getCell(11))) + .thirdQuarterAccountPayment(getNumericCellValue(row.getCell(12))) + .fourthQuarterAccountPayment(getNumericCellValue(row.getCell(13))) + .taxNumber(getCellValue(row.getCell(14), dataFormatter)) + .taxRate(getNumericCellValue(row.getCell(15))) + .bankName(getCellValue(row.getCell(16), dataFormatter)) + .accountNumber(getCellValue(row.getCell(17), dataFormatter)) + .address(getCellValue(row.getCell(18), dataFormatter)) + .remark(getCellValue(row.getCell(19), dataFormatter)) + .build(); + suppliers.add(supplier); + workbook.close(); + } + return supplierService.batchAddSupplier(suppliers); + } + + private boolean readCustomerFromExcel(MultipartFile file) throws IOException { + List customers = new ArrayList<>(); + Workbook workbook = new HSSFWorkbook(file.getInputStream()); + Sheet sheet = workbook.getSheetAt(0); + DataFormatter dataFormatter = new DataFormatter(); + + for (int i = 2; i <= sheet.getLastRowNum(); ++i) { + Row row = sheet.getRow(i); + var customer = Customer.builder() + .customerName(getCellValue(row.getCell(0), dataFormatter)) + .contact(getCellValue(row.getCell(1), dataFormatter)) + .phoneNumber(getCellValue(row.getCell(2), dataFormatter)) + .email(getCellValue(row.getCell(3), dataFormatter)) + .firstQuarterAccountReceivable(getNumericCellValue(row.getCell(4))) + .secondQuarterAccountReceivable(getNumericCellValue(row.getCell(5))) + .thirdQuarterAccountReceivable(getNumericCellValue(row.getCell(6))) + .fourthQuarterAccountReceivable(getNumericCellValue(row.getCell(7))) + .taxNumber(getCellValue(row.getCell(8), dataFormatter)) + .taxRate(getNumericCellValue(row.getCell(9))) + .bankName(getCellValue(row.getCell(10), dataFormatter)) + .accountNumber(getCellValue(row.getCell(11), dataFormatter)) + .address(getCellValue(row.getCell(12), dataFormatter)) + .remark(getCellValue(row.getCell(13), dataFormatter)) + .build(); + customers.add(customer); + workbook.close(); + } + return customerService.batchAddCustomer(customers); + } + public File exportExcel(String type) { if (!StringUtils.hasLength(type)) { return null; @@ -210,6 +279,7 @@ public File exportExcel(String type) { } String[] columnNames = {"供应商名称", "联系人", "联系电话", "联系人电话", "邮箱", "传真", + "第一季度应收账款", "第二季度应收账款", "第三季度应收账款", "第四季度应收账款", "第一季度应付账款", "第二季度应付账款", "第三季度应付账款", "第四季度应付账款", "税号", "税率", "开户行", "账号", "地址", "备注"}; @@ -242,39 +312,6 @@ public File exportExcel(String type) { return file; } - - private boolean readSuppliersFromExcel(MultipartFile file) throws IOException { - List suppliers = new ArrayList<>(); - Workbook workbook = new HSSFWorkbook(file.getInputStream()); - Sheet sheet = workbook.getSheetAt(0); - DataFormatter dataFormatter = new DataFormatter(); - - for (int i = 2; i <= sheet.getLastRowNum(); ++i) { - Row row = sheet.getRow(i); - var supplier = Supplier.builder() - .supplierName(getCellValue(row.getCell(0), dataFormatter)) - .contact(getCellValue(row.getCell(1), dataFormatter)) - .phoneNumber(getCellValue(row.getCell(2), dataFormatter)) - .contactNumber(getCellValue(row.getCell(3), dataFormatter)) - .email(getCellValue(row.getCell(4), dataFormatter)) - .fax(getCellValue(row.getCell(5), dataFormatter)) - .firstQuarterAccountPayment(getNumericCellValue(row.getCell(10))) - .secondQuarterAccountPayment(getNumericCellValue(row.getCell(11))) - .thirdQuarterAccountPayment(getNumericCellValue(row.getCell(12))) - .fourthQuarterAccountPayment(getNumericCellValue(row.getCell(13))) - .taxNumber(getCellValue(row.getCell(14), dataFormatter)) - .taxRate(getNumericCellValue(row.getCell(15))) - .bankName(getCellValue(row.getCell(16), dataFormatter)) - .accountNumber(getLongCellValue(row.getCell(17))) - .address(getCellValue(row.getCell(18), dataFormatter)) - .remark(getCellValue(row.getCell(19), dataFormatter)) - .build(); - suppliers.add(supplier); - workbook.close(); - } - return supplierService.batchAddSupplier(suppliers); - } - private String getCellValue(Cell cell, DataFormatter dataFormatter) { if (cell != null) { String value = dataFormatter.formatCellValue(cell); From d64c127d710eb06c98d9fd5a74a998a08614818d Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 14 Oct 2023 02:32:30 +0800 Subject: [PATCH 8/8] Add API for customer information module (ordinary business logic) #41 --- .../api/basic/CustomerController.kt | 45 ++++ .../wansensoft/mappers/CustomerMapper.java | 8 + .../resources/mapper_xml/CustomerMapper.xml | 5 + .../wansensoft/entities/basic/Customer.java | 145 ++++++++++++ .../dto/basic/AddOrUpdateCustomerDTO.kt | 56 +++++ .../wansensoft/dto/basic/QueryCustomerDTO.kt | 30 +++ .../com/wansensoft/vo/basic/CustomerVO.kt | 70 ++++++ .../service/basic/CustomerService.kt | 34 +++ .../service/basic/impl/CustomerServiceImpl.kt | 212 ++++++++++++++++++ .../utils/enums/CustomerCodeEnum.kt | 20 ++ 10 files changed, 625 insertions(+) create mode 100644 api/src/main/kotlin/com/wansensoft/api/basic/CustomerController.kt create mode 100644 dao/src/main/java/com/wansensoft/mappers/CustomerMapper.java create mode 100644 dao/src/main/resources/mapper_xml/CustomerMapper.xml create mode 100644 domain/src/main/java/com/wansensoft/entities/basic/Customer.java create mode 100644 domain/src/main/kotlin/com/wansensoft/dto/basic/AddOrUpdateCustomerDTO.kt create mode 100644 domain/src/main/kotlin/com/wansensoft/dto/basic/QueryCustomerDTO.kt create mode 100644 domain/src/main/kotlin/com/wansensoft/vo/basic/CustomerVO.kt create mode 100644 service/src/main/kotlin/com/wansensoft/service/basic/CustomerService.kt create mode 100644 service/src/main/kotlin/com/wansensoft/service/basic/impl/CustomerServiceImpl.kt create mode 100644 utils/src/main/kotlin/com/wansensoft/utils/enums/CustomerCodeEnum.kt diff --git a/api/src/main/kotlin/com/wansensoft/api/basic/CustomerController.kt b/api/src/main/kotlin/com/wansensoft/api/basic/CustomerController.kt new file mode 100644 index 000000000..ea1b5cdbf --- /dev/null +++ b/api/src/main/kotlin/com/wansensoft/api/basic/CustomerController.kt @@ -0,0 +1,45 @@ +/* + * 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.basic + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.wansensoft.dto.basic.* +import com.wansensoft.service.basic.CustomerService +import com.wansensoft.utils.response.Response +import com.wansensoft.vo.basic.CustomerVO +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/basic/customer") +class CustomerController (private val customerService: CustomerService){ + + @PostMapping("/list") + fun customerList(@RequestBody queryCustomerDTO: QueryCustomerDTO?) : Response> { + return customerService.getCustomerList(queryCustomerDTO) + } + + @PostMapping("/addOrUpdate") + fun addOrUpdateCustomer(@RequestBody addOrUpdateCustomerDTO: AddOrUpdateCustomerDTO) : Response { + return customerService.addOrUpdateCustomer(addOrUpdateCustomerDTO) + } + + @DeleteMapping("/deleteBatch") + fun deleteBatchCustomer(@RequestParam ids: List?) : Response { + return customerService.deleteCustomer(ids) + } + + @PostMapping("/updateStatus") + fun updateCustomerStatus(@RequestParam("ids") ids: List?, @RequestParam("status") status: Int?) : Response { + return customerService.updateCustomerStatus(ids, status) + } +} \ No newline at end of file diff --git a/dao/src/main/java/com/wansensoft/mappers/CustomerMapper.java b/dao/src/main/java/com/wansensoft/mappers/CustomerMapper.java new file mode 100644 index 000000000..bbd21eadb --- /dev/null +++ b/dao/src/main/java/com/wansensoft/mappers/CustomerMapper.java @@ -0,0 +1,8 @@ +package com.wansensoft.mappers; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.wansensoft.entities.basic.Customer; + +public interface CustomerMapper extends BaseMapper { + +} diff --git a/dao/src/main/resources/mapper_xml/CustomerMapper.xml b/dao/src/main/resources/mapper_xml/CustomerMapper.xml new file mode 100644 index 000000000..17aa60787 --- /dev/null +++ b/dao/src/main/resources/mapper_xml/CustomerMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/domain/src/main/java/com/wansensoft/entities/basic/Customer.java b/domain/src/main/java/com/wansensoft/entities/basic/Customer.java new file mode 100644 index 000000000..58e6fdaa2 --- /dev/null +++ b/domain/src/main/java/com/wansensoft/entities/basic/Customer.java @@ -0,0 +1,145 @@ +package com.wansensoft.entities.basic; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("customer") +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Customer implements Serializable { + + @Serial + private static final long serialVersionUID = 15791051662L; + + /** + * 主键 + */ + @TableId(value = "id") + private Long id; + + /** + * 租户id + */ + private Long tenantId; + + /** + * 客户名称 + */ + private String customerName; + + /** + * 联系人 + */ + private String contact; + + /** + * 手机 + */ + private String phoneNumber; + + /** + * 电子邮箱 + */ + private String email; + + /** + * 一季度应收账款 + */ + private BigDecimal firstQuarterAccountReceivable; + + /** + * 二季度应收账款 + */ + private BigDecimal secondQuarterAccountReceivable; + + /** + * 三季度应收账款 + */ + private BigDecimal thirdQuarterAccountReceivable; + + /** + * 四季度应收账款 + */ + private BigDecimal fourthQuarterAccountReceivable; + + /** + * 累计应收账款 + */ + private BigDecimal totalAccountReceivable; + + /** + * 地址 + */ + private String address; + + /** + * 纳税人识别号 + */ + private String taxNumber; + + /** + * 开户行 + */ + private String bankName; + + /** + * 账号 + */ + private String accountNumber; + + /** + * 税率 + */ + private BigDecimal taxRate; + + /** + * 状态(0-启用,1-停用)默认启用 + */ + private Integer status; + + /** + * 备注 + */ + private String remark; + + /** + * 排序 + */ + private Integer sort; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 修改时间 + */ + private LocalDateTime updateTime; + + /** + * 创建人 + */ + private Long createBy; + + /** + * 修改人 + */ + private Long updateBy; + + /** + * 删除标记,0未删除,1删除 + */ + private Integer deleteFlag; +} diff --git a/domain/src/main/kotlin/com/wansensoft/dto/basic/AddOrUpdateCustomerDTO.kt b/domain/src/main/kotlin/com/wansensoft/dto/basic/AddOrUpdateCustomerDTO.kt new file mode 100644 index 000000000..830922cbc --- /dev/null +++ b/domain/src/main/kotlin/com/wansensoft/dto/basic/AddOrUpdateCustomerDTO.kt @@ -0,0 +1,56 @@ +/* + * 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.basic + +import com.wansensoft.NoArg +import java.math.BigDecimal + +@NoArg +data class AddOrUpdateCustomerDTO( + + val id: Long?, + + var customerName: String, + + var contact: String?, + + var phoneNumber: String?, + + var email: String?, + + var firstQuarterAccountReceivable: BigDecimal?, + + var secondQuarterAccountReceivable: BigDecimal?, + + var thirdQuarterAccountReceivable: BigDecimal?, + + var fourthQuarterAccountReceivable: BigDecimal?, + + var totalAccountReceivable: BigDecimal?, + + var address: String?, + + var taxNumber: String?, + + var bankName: String?, + + var accountNumber: String?, + + var taxRate: BigDecimal?, + + var status: Int?, + + var remark: String?, + + var sort: Int?, +) diff --git a/domain/src/main/kotlin/com/wansensoft/dto/basic/QueryCustomerDTO.kt b/domain/src/main/kotlin/com/wansensoft/dto/basic/QueryCustomerDTO.kt new file mode 100644 index 000000000..fb20966c9 --- /dev/null +++ b/domain/src/main/kotlin/com/wansensoft/dto/basic/QueryCustomerDTO.kt @@ -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.dto.basic + +data class QueryCustomerDTO( + + var customerName: String?, + + var contact: String?, + + var phoneNumber: String?, + + val page: Long?, + + val pageSize: Long?, + + val startDate: String?, + + val endDate: String?, +) diff --git a/domain/src/main/kotlin/com/wansensoft/vo/basic/CustomerVO.kt b/domain/src/main/kotlin/com/wansensoft/vo/basic/CustomerVO.kt new file mode 100644 index 000000000..5b8c6a36e --- /dev/null +++ b/domain/src/main/kotlin/com/wansensoft/vo/basic/CustomerVO.kt @@ -0,0 +1,70 @@ +/* + * 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.basic + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.wansensoft.NoArg +import com.wansensoft.bo.BigDecimalSerializerBO +import java.math.BigDecimal +import java.time.LocalDateTime + +@NoArg +data class CustomerVO ( + + @JsonFormat(shape = JsonFormat.Shape.STRING) + var id: Long?, + + var customerName: String?, + + var contact: String?, + + var phoneNumber: String?, + + var email: String?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var firstQuarterAccountReceivable: BigDecimal?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var secondQuarterAccountReceivable: BigDecimal?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var thirdQuarterAccountReceivable: BigDecimal?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var fourthQuarterAccountReceivable: BigDecimal?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var totalAccountReceivable: BigDecimal?, + + var address: String?, + + var taxNumber: String?, + + var bankName: String?, + + var accountNumber: String?, + + @JsonSerialize(using = BigDecimalSerializerBO::class) + var taxRate: BigDecimal?, + + var status: Int?, + + var remark: String?, + + var sort: Int?, + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + var createTime: LocalDateTime?, +) \ No newline at end of file diff --git a/service/src/main/kotlin/com/wansensoft/service/basic/CustomerService.kt b/service/src/main/kotlin/com/wansensoft/service/basic/CustomerService.kt new file mode 100644 index 000000000..a1ced907e --- /dev/null +++ b/service/src/main/kotlin/com/wansensoft/service/basic/CustomerService.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.service.basic + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.baomidou.mybatisplus.extension.service.IService +import com.wansensoft.dto.basic.AddOrUpdateCustomerDTO +import com.wansensoft.dto.basic.QueryCustomerDTO +import com.wansensoft.entities.basic.Customer +import com.wansensoft.utils.response.Response +import com.wansensoft.vo.basic.CustomerVO + +interface CustomerService: IService { + + fun getCustomerList(queryCustomerDTO: QueryCustomerDTO?): Response> + + fun addOrUpdateCustomer(addOrUpdateCustomerDTO: AddOrUpdateCustomerDTO): Response + + fun deleteCustomer(ids: List?): Response + + fun updateCustomerStatus(ids: List?, status: Int?): Response + + fun batchAddCustomer(customers: List?): Boolean +} \ No newline at end of file diff --git a/service/src/main/kotlin/com/wansensoft/service/basic/impl/CustomerServiceImpl.kt b/service/src/main/kotlin/com/wansensoft/service/basic/impl/CustomerServiceImpl.kt new file mode 100644 index 000000000..3b7efb805 --- /dev/null +++ b/service/src/main/kotlin/com/wansensoft/service/basic/impl/CustomerServiceImpl.kt @@ -0,0 +1,212 @@ +/* + * 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.basic.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.basic.AddOrUpdateCustomerDTO +import com.wansensoft.dto.basic.QueryCustomerDTO +import com.wansensoft.entities.basic.Customer +import com.wansensoft.mappers.CustomerMapper +import com.wansensoft.service.BaseService +import com.wansensoft.service.basic.CustomerService +import com.wansensoft.utils.SnowflakeIdUtil +import com.wansensoft.utils.constants.CommonConstants +import com.wansensoft.utils.enums.BaseCodeEnum +import com.wansensoft.utils.enums.CustomerCodeEnum +import com.wansensoft.utils.response.Response +import com.wansensoft.vo.basic.CustomerVO +import lombok.extern.slf4j.Slf4j +import org.springframework.beans.BeanUtils +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.math.BigDecimal +import java.math.RoundingMode +import java.time.LocalDateTime + +@Slf4j +@Service +open class CustomerServiceImpl( + private val baseService: BaseService, + private val customerMapper: CustomerMapper +) : ServiceImpl(), CustomerService { + + override fun getCustomerList(queryCustomerDTO: QueryCustomerDTO?): Response> { + val page = queryCustomerDTO?.run { Page(page ?: 1, pageSize ?: 10) } + val wrapper = LambdaQueryWrapper().apply { + queryCustomerDTO?.customerName?.let { like(Customer::getCustomerName, it) } + queryCustomerDTO?.contact?.let { like(Customer::getContact, it) } + queryCustomerDTO?.phoneNumber?.let { like(Customer::getPhoneNumber, it) } + queryCustomerDTO?.startDate?.let { ge(Customer::getCreateTime, it) } + queryCustomerDTO?.endDate?.let { le(Customer::getCreateTime, it) } + eq(Customer::getDeleteFlag, CommonConstants.NOT_DELETED) + } + + val result = page?.run { + customerMapper.selectPage(this, wrapper) + val listVo = records.map { customer -> + CustomerVO( + id = customer.id, + customerName = customer.customerName, + contact = customer.contact, + phoneNumber = customer.phoneNumber, + email = customer.email, + firstQuarterAccountReceivable = customer.firstQuarterAccountReceivable, + secondQuarterAccountReceivable = customer.secondQuarterAccountReceivable, + thirdQuarterAccountReceivable = customer.thirdQuarterAccountReceivable, + fourthQuarterAccountReceivable = customer.fourthQuarterAccountReceivable, + totalAccountReceivable = customer.totalAccountReceivable, + address = customer.address, + taxNumber = customer.taxNumber, + bankName = customer.bankName, + accountNumber = customer.accountNumber, + taxRate = customer.taxRate, + status = customer.status, + remark = customer.remark, + sort = customer.sort, + createTime = customer.createTime, + ) + } + Page().apply { + records = listVo + total = this@run.total + pages = this@run.pages + size = this@run.size + } + } + return result.let { Response.responseData(it) } ?: Response.responseMsg(BaseCodeEnum.QUERY_DATA_EMPTY) + } + + open fun calculateTotalAccount(list: List): BigDecimal { + return list.mapNotNull { it }.sumOf { it }.setScale(3, RoundingMode.HALF_UP) + } + + @Transactional + override fun addOrUpdateCustomer(addOrUpdateCustomerDTO: AddOrUpdateCustomerDTO): Response { + val userId = baseService.getCurrentUserId() + val isAdd = addOrUpdateCustomerDTO.id == null + + val customer = Customer().apply { + id = if (isAdd) SnowflakeIdUtil.nextId() else addOrUpdateCustomerDTO.id + customerName = addOrUpdateCustomerDTO.customerName.orEmpty() + contact = addOrUpdateCustomerDTO.contact.orEmpty() + phoneNumber = addOrUpdateCustomerDTO.phoneNumber.orEmpty() + email = addOrUpdateCustomerDTO.email.orEmpty() + firstQuarterAccountReceivable = addOrUpdateCustomerDTO.firstQuarterAccountReceivable ?: BigDecimal.ZERO + secondQuarterAccountReceivable = addOrUpdateCustomerDTO.secondQuarterAccountReceivable ?: BigDecimal.ZERO + thirdQuarterAccountReceivable = addOrUpdateCustomerDTO.thirdQuarterAccountReceivable ?: BigDecimal.ZERO + fourthQuarterAccountReceivable = addOrUpdateCustomerDTO.fourthQuarterAccountReceivable ?: BigDecimal.ZERO + totalAccountReceivable = calculateTotalAccount( + listOf( + addOrUpdateCustomerDTO.firstQuarterAccountReceivable, + addOrUpdateCustomerDTO.secondQuarterAccountReceivable, + addOrUpdateCustomerDTO.thirdQuarterAccountReceivable, + addOrUpdateCustomerDTO.fourthQuarterAccountReceivable + ) + ) + address = addOrUpdateCustomerDTO.address.orEmpty() + taxNumber = addOrUpdateCustomerDTO.taxNumber.orEmpty() + bankName = addOrUpdateCustomerDTO.bankName.orEmpty() + accountNumber = addOrUpdateCustomerDTO.accountNumber.orEmpty() + taxRate = addOrUpdateCustomerDTO.taxRate ?: BigDecimal.ZERO + status = addOrUpdateCustomerDTO.status ?: 0 + remark = addOrUpdateCustomerDTO.remark.orEmpty() + sort = addOrUpdateCustomerDTO.sort ?: 0 + if (isAdd) { + createTime = LocalDateTime.now() + createBy = userId + } else { + updateTime = LocalDateTime.now() + updateBy = userId + } + } + + val saveResult = saveOrUpdate(customer) + return when { + saveResult && isAdd -> Response.responseMsg(CustomerCodeEnum.ADD_CUSTOMER_SUCCESS) + saveResult && !isAdd -> Response.responseMsg(CustomerCodeEnum.UPDATE_CUSTOMER_SUCCESS) + else -> Response.fail() + } + } + + override fun deleteCustomer(ids: List?): Response { + return ids.takeIf { !it.isNullOrEmpty() } + ?.let { + val updateResult = customerMapper.deleteBatchIds(it) + if (updateResult > 0) { + Response.responseMsg(CustomerCodeEnum.DELETE_CUSTOMER_SUCCESS) + } else { + Response.responseMsg(CustomerCodeEnum.DELETE_CUSTOMER_ERROR) + } + } + ?: Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } + + override fun updateCustomerStatus(ids: List?, status: Int?): Response { + return ids.takeIf { !it.isNullOrEmpty() }?.let { + status?.let { s -> + val updateResult = lambdaUpdate() + .`in`(Customer::getId, it) + .set(Customer::getStatus, s) + .update() + + if (!updateResult) { + Response.responseMsg(CustomerCodeEnum.UPDATE_CUSTOMER_STATUS_ERROR) + } else { + Response.responseMsg(CustomerCodeEnum.UPDATE_CUSTOMER_STATUS_SUCCESS) + } + } + } ?: Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } + + @Transactional + override fun batchAddCustomer(customers: List?): Boolean { + val customerEntities = mutableListOf() + val existingCustomers = HashSet>() // 存储已存在的供应商名称和联系人的组合 + + customers?.forEach { customer -> + val customerKey = Pair(customer.customerName, customer.contact) + if (!existingCustomers.contains(customerKey)) { + val customerEntity = customerMapper.selectOne( + LambdaQueryWrapper() + .eq(Customer::getCustomerName, customer.customerName) + .eq(Customer::getContact, customer.contact) + ) + if (customerEntity == null) { + val newCustomerEntity = Customer().apply { + BeanUtils.copyProperties(customer, this) + firstQuarterAccountReceivable = customer.firstQuarterAccountReceivable + secondQuarterAccountReceivable = customer.secondQuarterAccountReceivable + thirdQuarterAccountReceivable = customer.thirdQuarterAccountReceivable + fourthQuarterAccountReceivable = customer.fourthQuarterAccountReceivable + taxRate = customer.taxRate + totalAccountReceivable = calculateTotalAccount( + listOf( + customer.firstQuarterAccountReceivable, + customer.secondQuarterAccountReceivable, + customer.thirdQuarterAccountReceivable, + customer.fourthQuarterAccountReceivable + ) + ) + createTime = LocalDateTime.now() + createBy = baseService.currentUserId + } + customerEntities.add(newCustomerEntity) + existingCustomers.add(customerKey) + } + } + } + return saveBatch(customerEntities) + } +} \ No newline at end of file diff --git a/utils/src/main/kotlin/com/wansensoft/utils/enums/CustomerCodeEnum.kt b/utils/src/main/kotlin/com/wansensoft/utils/enums/CustomerCodeEnum.kt new file mode 100644 index 000000000..cfebc983e --- /dev/null +++ b/utils/src/main/kotlin/com/wansensoft/utils/enums/CustomerCodeEnum.kt @@ -0,0 +1,20 @@ +package com.wansensoft.utils.enums + +/** + * 因为BaseCodeEnum.java类将来需要扩展其他业务代码,默认占用首字母ABC + * 所以这里CustomerCodeEnum枚举取第二个字母U大写 + */ +enum class CustomerCodeEnum(val code: String, val msg: String) { + + ADD_CUSTOMER_SUCCESS("U0001", "供应商添加成功"), + ADD_CUSTOMER_ERROR("U0500", "供应商添加失败"), + + UPDATE_CUSTOMER_SUCCESS("U0002", "供应商修改成功"), + UPDATE_CUSTOMER_ERROR("U0501", "供应商修改失败"), + + DELETE_CUSTOMER_SUCCESS("U0003", "供应商删除成功"), + DELETE_CUSTOMER_ERROR("U0504", "供应商删除失败"), + + UPDATE_CUSTOMER_STATUS_SUCCESS("U0004", "供应商状态修改成功"), + UPDATE_CUSTOMER_STATUS_ERROR("U0505", "供应商状态修改失败") +} \ No newline at end of file