Skip to content

Commit

Permalink
Merge pull request #122 from Jzow/master
Browse files Browse the repository at this point in the history
Improve the methods for adding and modifying advance payment information
  • Loading branch information
Jzow authored Oct 27, 2023
2 parents 797f56c + 97780bd commit b777189
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 88 deletions.
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,26 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package com.wansensoft.service.financial.impl

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.wansensoft.bo.AdvanceChargeDataBO
import com.wansensoft.dto.financial.AddOrUpdateAdvanceChargeDTO
import com.wansensoft.dto.financial.QueryAdvanceChargeDTO
import com.wansensoft.entities.SysDepartment
Expand All @@ -31,6 +32,7 @@ import com.wansensoft.service.user.ISysUserDeptRelService
import com.wansensoft.utils.SnowflakeIdUtil
import com.wansensoft.utils.TimeUtil
import com.wansensoft.utils.enums.BaseCodeEnum
import com.wansensoft.utils.enums.FinancialCodeEnum
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.financial.AdvanceChargeDetailVO
import com.wansensoft.vo.financial.AdvanceChargeVO
Expand All @@ -41,8 +43,7 @@ import org.springframework.util.StringUtils

@Service
@Slf4j
open class AdvanceChargeServiceImpl (
private val financialMainMapper: FinancialMainMapper,
open class AdvanceChargeServiceImpl(
private val baseService: BaseService,
private val userDeptRelService: ISysUserDeptRelService,
private val departmentService: SysDepartmentService,
Expand All @@ -52,96 +53,82 @@ open class AdvanceChargeServiceImpl (

@Transactional
override fun addOrUpdateAdvanceCharge(advanceChargeDTO: AddOrUpdateAdvanceChargeDTO): Response<String> {
// 先判断如果memberId 和 receiptDate为空返回必填参数错误
if (advanceChargeDTO.memberId == null || !StringUtils.hasLength(advanceChargeDTO.receiptDate)) {
// 先判断如果memberId和receiptDate为空返回必填参数错误
if (advanceChargeDTO.memberId == null || advanceChargeDTO.receiptDate.isNullOrEmpty()) {
return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}

val userId = baseService.currentUserId;
val userId = baseService.currentUserId
var deptId: Long? = null
val userDeptRelList = userDeptRelService.queryByUserId(userId)

if (userDeptRelList.isNotEmpty()) {
val deptIdList = userDeptRelList.map { it.deptId }
val deptList = departmentService.lambdaQuery()
.`in`(deptIdList.isNotEmpty(), SysDepartment::getId, deptIdList)
deptId = userDeptRelList.takeIf { it.isNotEmpty() }
?.map { it.deptId }
?.let { deptIdList ->
departmentService.lambdaQuery()
.`in`(deptIdList.isNotEmpty(), SysDepartment::getId, deptIdList)
.list()
.firstOrNull()
?.let { it.parentId ?: it.id }
}

if (advanceChargeDTO.id != null) {
val financialSubList = financialSubService.lambdaQuery()
.eq(FinancialSub::getFinancialMainId, advanceChargeDTO.id)
.list()
if (deptList.isNotEmpty()) {
val dept = deptList.first()
deptId = dept.parentId ?: dept.id

if (financialSubList.isNotEmpty()) {
val financialSubIdList = financialSubList.map { it.id }
val deleteFinancialSubResult = financialSubService.removeByIds(financialSubIdList)

if (!deleteFinancialSubResult) {
return Response.responseMsg(FinancialCodeEnum.UPDATE_ADVANCE_ERROR)
}
}
}

// If the id is empty, it is a new addition, otherwise it is a modification
if (advanceChargeDTO.id == null) {
val files = advanceChargeDTO.files
var fileIds = ""
if (!files.isNullOrEmpty()) {
fileIds = files.map { it.id }.joinToString(",")
}
if (advanceChargeDTO.tableData.isNotEmpty()) {
val accountIdList = advanceChargeDTO.tableData.map { it.accountId }
val accountIdSet = accountIdList.toSet()
if (accountIdSet.size == 1) {
// Selected an account
val accountId = accountIdSet.first()
val financialMain = FinancialMain.builder()
.id(SnowflakeIdUtil.nextId())
.organizationId(deptId)
.handsPersonId(advanceChargeDTO.financialPersonnelId)
.accountId(accountId)
.type("收预付款")
.changePrice(advanceChargeDTO.totalAmount)
.totalPrice(advanceChargeDTO.totalAmount)
.receiptNumber(advanceChargeDTO.receiptNumber)
.receiptSource(0)
.receiptTime(TimeUtil.parse(advanceChargeDTO.receiptDate))
.fileId(fileIds)
.remark(advanceChargeDTO.remark)
.build()
save(financialMain)

// 把tableData的数据插入到financial_sub表中 循环批量插入
val financialSubList = mutableListOf<FinancialSub>()
for (advanceChargeDataBO in advanceChargeDTO.tableData) {
val financialSub = FinancialSub.builder()
.id(SnowflakeIdUtil.nextId())
.financialMainId(financialMain.id)
.accountId(advanceChargeDataBO.accountId)
.singleAmount(advanceChargeDataBO.amount)
.remark(advanceChargeDataBO.remark)
.build()
financialSubList.add(financialSub)
}
financialSubService.saveBatch(financialSubList)

} else {
// Multiple accounts selected
val financialMainList = mutableListOf<FinancialMain>()
for (accountId in accountIdSet) {
val financialMain = FinancialMain.builder()
.id(SnowflakeIdUtil.nextId())
.organizationId(deptId)
.handsPersonId(advanceChargeDTO.financialPersonnelId)
.accountId(accountId)
.type("收预付款")
.changePrice(advanceChargeDTO.totalAmount)
.totalPrice(advanceChargeDTO.totalAmount)
.receiptNumber(advanceChargeDTO.receiptNumber)
.receiptSource(0)
.receiptTime(TimeUtil.parse(advanceChargeDTO.receiptDate))
.fileId(fileIds)
.remark(advanceChargeDTO.remark)
.build()
financialMainList.add(financialMain)
}
saveBatch(financialMainList)
}
// Modify member prepayment balance
memberService.updateAdvanceChargeAmount(advanceChargeDTO.memberId, advanceChargeDTO.totalAmount)
val fileIds = advanceChargeDTO.files?.map { it.id }?.joinToString(",")

if (advanceChargeDTO.tableData.isNotEmpty()) {
val financialMainId = SnowflakeIdUtil.nextId()
val financialMain = FinancialMain.builder()
.id(financialMainId)
.organizationId(deptId)
.handsPersonId(advanceChargeDTO.financialPersonnelId)
.type("收预付款")
.changePrice(advanceChargeDTO.totalAmount)
.totalPrice(advanceChargeDTO.totalAmount)
.receiptNumber(advanceChargeDTO.receiptNumber)
.receiptSource(0)
.receiptTime(TimeUtil.parse(advanceChargeDTO.receiptDate))
.fileId(fileIds)
.remark(advanceChargeDTO.remark)
.build()

val isFinancialMainAdded = saveOrUpdate(financialMain)

val financialSubList = advanceChargeDTO.tableData.toFinancialSubList(financialMainId)
val areFinancialSubsAdded = financialSubService.saveBatch(financialSubList)
val isMemberUpdated = memberService.updateAdvanceChargeAmount(advanceChargeDTO.memberId, advanceChargeDTO.totalAmount)

if (isFinancialMainAdded && areFinancialSubsAdded && isMemberUpdated) {
return Response.responseMsg(FinancialCodeEnum.ADD_ADVANCE_SUCCESS)
}
return Response.responseMsg(FinancialCodeEnum.ADD_ADVANCE_ERROR)
}
return Response.responseMsg(BaseCodeEnum.QUERY_DATA_EMPTY)
}

private fun List<AdvanceChargeDataBO>.toFinancialSubList(financialMainId: Long): List<FinancialSub> {
return map {
FinancialSub.builder()
.id(SnowflakeIdUtil.nextId())
.financialMainId(financialMainId)
.accountId(it.accountId)
.singleAmount(it.amount)
.remark(it.remark)
.build()
}
return Response.success();
}

override fun getAdvanceChargePageList(advanceChargeDTO: QueryAdvanceChargeDTO?): Response<Page<AdvanceChargeVO>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ public enum FinancialCodeEnum {

UPDATE_ACCOUNT_STATUS_SUCCESS("F0004", "修改账号状态成功"),

UPDATE_ACCOUNT_STATUS_ERROR("F0503", "修改账号状态失败");
UPDATE_ACCOUNT_STATUS_ERROR("F0503", "修改账号状态失败"),

ADD_ADVANCE_SUCCESS("F0005", "新增预收款成功"),

ADD_ADVANCE_ERROR("F0504", "新增预收款失败"),

UPDATE_ADVANCE_SUCCESS("F0006", "更新预收款数据成功"),

UPDATE_ADVANCE_ERROR("F0505", "更新预收款数据失败"),

DELETE_ADVANCE_SUCCESS("F0007", "删除预收款数据成功"),

DELETE_ADVANCE_ERROR("F0506", "删除预收款数据失败");

/**
* 响应状态码
*/
private final String code;

/**
* 响应提示
*/
private final String msg;

FinancialCodeEnum(String code, String msg) {
Expand Down
24 changes: 24 additions & 0 deletions utils/src/test/java/TimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.wansensoft.utils.TimeUtil;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

public class TimeTest {

@Test
public void testMyMethod() {
// Arrange
String a = "2023-10-27 17:37:21";
String b = "yyyy-MM-dd HH:mm:ss";

// Act
LocalDateTime result = myMethod(a, b);

// Assert
assert result.getDayOfMonth() == result.getDayOfMonth();
}

public LocalDateTime myMethod(String a, String b) {
return TimeUtil.parse(a, b);
}
}

0 comments on commit b777189

Please sign in to comment.