Commit a91242bf by zhangxingmin

push

parent 8a4dd9fc
......@@ -147,7 +147,7 @@ public class ApiSalaryController implements ApiSalaryFeignClient {
*/
@Override
public Result<BigDecimal> getGrossAmount(ApiSalaryGrossAmountRequest request) {
return null;
return apiSalaryService.getGrossAmount(request);
}
/**
......
......@@ -30,12 +30,17 @@ import com.yd.csf.service.service.ISalaryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
......@@ -125,6 +130,9 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
checkAmount(request.getPaidAmount(),fzDTO.getTotalAmount());
//校验同一转介人同一薪资年月只能有一条薪资单记录
checkUniqueByBrokerMonth(request.getBrokerBizId(),request.getMonth(),"",false);
//校验:当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单
checkIsBilling(request.getBrokerBizId(),request.getMonth());
Salary salary = new Salary();
BeanUtils.copyProperties(request,salary);
//发放编号
......@@ -158,6 +166,9 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
//校验同一转介人同一薪资年月只能有一条薪资单记录
checkUniqueByBrokerMonth(request.getBrokerBizId(),request.getMonth(),
request.getSalaryBizId(),true);
//校验:当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单
checkIsBilling(request.getBrokerBizId(),request.getMonth());
BeanUtils.copyProperties(request,salary);
iSalaryService.saveOrUpdate(salary);
......@@ -258,6 +269,8 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
batchCheckUniqueByBrokerMonth(apiSalaryBatchAddDTOList);
//批量校验薪资单信息金额字段信息
batchAddCheckAmount(apiSalaryBatchAddDTOList);
//批量校验:当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单
batchCheckIsBilling(apiSalaryBatchAddDTOList);
Map<Salary,List<SalaryRemittance>> map = new HashMap<>();
apiSalaryBatchAddDTOList.forEach(dto -> {
......@@ -329,9 +342,16 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
//根据转介人和薪资年月查询是否有完成出账的记录
List<FortuneAccount> fortuneAccountList = fortuneAccountService.queryList(request.getBrokerBizId(),request.getMonth(), FortuneAccountStatusEnum.SENT.getItemValue());
if (CollectionUtils.isEmpty(fortuneAccountList)) {
throw new BusinessException("当前转介人对应的薪资月没有完成出账状态的记录,不能保存发放薪资");
}
return null;
//累加
BigDecimal totalAmount = fortuneAccountList.stream()
.map(dto -> {
BigDecimal hkdAmount = ObjectUtils.defaultIfNull(dto.getHkdAmount(), BigDecimal.ZERO);
return hkdAmount;
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
return Result.success(totalAmount);
}
/**
......@@ -507,6 +527,66 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
}
/**
* 批量校验:当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单
* @param apiSalaryBatchAddDTOList 批量新增薪资单DTO列表
*/
public void batchCheckIsBilling(List<ApiSalaryBatchAddDTO> apiSalaryBatchAddDTOList) {
if (CollectionUtils.isEmpty(apiSalaryBatchAddDTOList)) {
return;
}
// 1. 构建 pairs 列表(包含所有组合,不去重,因为查询时 OR 条件会自动去重,但也可以去重提升性能)
List<Map.Entry<String, String>> pairs = new ArrayList<>();
Map<String, ApiSalaryBatchAddDTO> keyToDto = new HashMap<>();
for (ApiSalaryBatchAddDTO dto : apiSalaryBatchAddDTOList) {
String brokerBizId = dto.getBrokerBizId();
String month = dto.getMonth();
if (StringUtils.isBlank(brokerBizId) || StringUtils.isBlank(month)) {
continue;
}
pairs.add(new AbstractMap.SimpleEntry<>(brokerBizId, month));
keyToDto.put(brokerBizId + "|" + month, dto);
}
if (pairs.isEmpty()) {
return;
}
// 2. 调用新方法查询已出账记录
List<FortuneAccount> existingAccounts = fortuneAccountService.queryList(pairs, FortuneAccountStatusEnum.SENT.getItemValue());
// 3. 构建已存在组合的 Set
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyyMM");
Set<String> existingKeys = existingAccounts.stream()
.map(fa -> {
// Date -> LocalDate
LocalDate date = fa.getFortuneAccountDate().toInstant()
.atZone(ZoneId.systemDefault()).toLocalDate();
return fa.getBrokerBizId() + "|" + date.format(monthFormatter);
})
.collect(Collectors.toSet());
// 4. 找出缺失的组合
List<String> missingKeys = pairs.stream()
.map(pair -> pair.getKey() + "|" + pair.getValue())
.filter(key -> !existingKeys.contains(key))
.distinct()
.collect(Collectors.toList());
if (!missingKeys.isEmpty()) {
List<String> missingDescriptions = missingKeys.stream()
.map(key -> {
ApiSalaryBatchAddDTO dto = keyToDto.get(key);
String name = dto != null && StringUtils.isNotBlank(dto.getBrokerName()) ? dto.getBrokerName() : key.split("\\|")[0];
String month = key.split("\\|")[1];
return name + "-" + month;
})
.collect(Collectors.toList());
throw new BusinessException("以下转介人与薪资月份组合没有完成出账状态的记录: " + String.join(", ", missingDescriptions));
}
}
/**
* 统计批量新增的汇款明细对象发放金额合计值
* @return
......@@ -563,6 +643,17 @@ public class ApiSalaryServiceImpl implements ApiSalaryService {
}
/**
* 校验:当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单
* @return
*/
public void checkIsBilling(String brokerBizId,String month) {
List<FortuneAccount> fortuneAccountList = fortuneAccountService.queryList(brokerBizId,month, FortuneAccountStatusEnum.SENT.getItemValue());
if (CollectionUtils.isEmpty(fortuneAccountList)) {
throw new BusinessException("当前转介人对应的薪资月没有完成出账状态的记录,不能保存薪资单");
}
}
/**
* 校验薪资单信息是否存在
* @param salaryBizId
*/
......
......@@ -43,4 +43,6 @@ public interface FortuneAccountService extends IService<FortuneAccount> {
FortuneAccount queryOne(String fortuneAccountBizId);
List<FortuneAccount> queryList(String brokerBizId,String month,String status);
List<FortuneAccount> queryList(List<Map.Entry<String, String>> pairs, String status);
}
......@@ -539,6 +539,46 @@ public class FortuneAccountServiceImpl extends ServiceImpl<FortuneAccountMapper,
// 执行查询
return list(wrapper);
}
@Override
public List<FortuneAccount> queryList(List<Map.Entry<String, String>> pairs, String status) {
LambdaQueryWrapper<FortuneAccount> wrapper = new LambdaQueryWrapper<>();
if (CollectionUtils.isNotEmpty(pairs)) {
wrapper.and(wq -> {
for (int i = 0; i < pairs.size(); i++) {
Map.Entry<String, String> pair = pairs.get(i);
String brokerBizId = pair.getKey();
String month = pair.getValue();
if (StringUtils.isBlank(brokerBizId) || StringUtils.isBlank(month)) {
continue;
}
YearMonth yearMonth = YearMonth.parse(month, DateTimeFormatter.ofPattern("yyyyMM"));
LocalDate startDate = yearMonth.atDay(1);
LocalDate endDate = yearMonth.atEndOfMonth();
if (i == 0) {
wq.eq(FortuneAccount::getBrokerBizId, brokerBizId)
.ge(FortuneAccount::getFortuneAccountDate, startDate)
.le(FortuneAccount::getFortuneAccountDate, endDate);
} else {
wq.or()
.eq(FortuneAccount::getBrokerBizId, brokerBizId)
.ge(FortuneAccount::getFortuneAccountDate, startDate)
.le(FortuneAccount::getFortuneAccountDate, endDate);
}
}
});
}
if (StringUtils.isNotBlank(status)) {
wrapper.eq(FortuneAccount::getStatus, status);
}
wrapper.orderByDesc(FortuneAccount::getFortuneAccountDate);
return list(wrapper);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment