weaver-hrm-salary/src/com/engine/salary/service/impl/TaxDeclarationApiBillingSer...

214 lines
11 KiB
Java
Raw Normal View History

2023-07-20 09:58:27 +08:00
package com.engine.salary.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
2023-08-08 09:21:14 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2023-07-20 09:58:27 +08:00
import com.engine.salary.entity.taxapiflow.bo.TaxApiFlowBO;
import com.engine.salary.entity.taxapiflow.dto.TaxDeclarationApiFlowRecordListDTO;
import com.engine.salary.entity.taxapiflow.param.TaxDeclarationApiFlowRecordQueryParam;
import com.engine.salary.entity.taxapiflow.po.TaxDeclarationApiFlowRecordPO;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationApiConfigPO;
2023-08-08 09:21:14 +08:00
import com.engine.salary.enums.sicategory.DeleteTypeEnum;
2023-07-20 09:58:27 +08:00
import com.engine.salary.enums.taxdeclaration.EnumDeclareApiBusinessType;
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationApiFlowRecordMapper;
import com.engine.salary.service.SalaryEmployeeService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.service.TaxDeclarationApiBillingService;
import com.engine.salary.service.TaxDeclarationApiFlowWarnService;
2023-08-08 09:21:14 +08:00
import com.engine.salary.util.SalaryEntityUtil;
2023-07-20 09:58:27 +08:00
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* @author chengliming
* @date 2022-11-11 2:57 PM
**/
@Slf4j
public class TaxDeclarationApiBillingServiceImpl implements TaxDeclarationApiBillingService {
private TaxDeclarationApiFlowRecordMapper taxDeclarationApiFlowRecordMapper;
private TaxAgentService taxAgentService;
private SalaryEmployeeService salaryEmployeeService;
// private SalaryBatchService salaryBatchService;
private TaxDeclarationApiFlowWarnService taxDeclarationApiFlowWarnService;
// private ComInfoCache comInfoCache;
// private ExtEmployeeService extEmployeeService;
@Override
public void updateApiFlowInfo(ApiFlowUpdateWrapper updateWrapper) {
// 保存流量使用详情
saveApiFlowRecord(updateWrapper);
// 流量不足提醒
taxDeclarationApiFlowWarnService.sendFlowWarnMessage(updateWrapper);
}
private void saveApiFlowRecord(ApiFlowUpdateWrapper updateWrapper) {
if (!updateWrapper.getApiFlowDetailPOList().isEmpty()) {
List<List<TaxDeclarationApiFlowRecordPO>> failPartition = Lists.partition(updateWrapper.getApiFlowDetailPOList(), 1000);
failPartition.forEach(list -> taxDeclarationApiFlowRecordMapper.batchInsert(list));
}
}
@Override
public PageInfo<TaxDeclarationApiFlowRecordListDTO> pageFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam) {
LambdaQueryChainWrapper<TaxDeclarationApiFlowRecordPO> queryChainWrapper = getFlowRecordQueryChainWrapper(queryParam);
Page<TaxDeclarationApiFlowRecordPO> flowRecordPOPage = queryChainWrapper.page(new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true));
List<TaxDeclarationApiFlowRecordPO> records = flowRecordPOPage.getRecords();
if (records.isEmpty()) {
return new PageInfo<>();
}
TempPropertiesWrapper propertiesWrapper = getUserInfoAndTaxAgentMap(records);
// 转换数据
AtomicInteger indexNum = new AtomicInteger(1);
List<TaxDeclarationApiFlowRecordListDTO> listDTOS = records.stream().map(e ->
TaxApiFlowBO.taxDeclarationApiFlowRecordPo2ListDTO(propertiesWrapper, indexNum, e)
).collect(Collectors.toList());
return new SalaryPage<>(queryParam.getCurrent(), queryParam.getPageSize(), flowRecordPOPage.getTotal(), listDTOS);
}
@Override
public List<TaxDeclarationApiFlowRecordListDTO> listFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam) {
LambdaQueryChainWrapper<TaxDeclarationApiFlowRecordPO> queryChainWrapper = getFlowRecordQueryChainWrapper(queryParam);
List<TaxDeclarationApiFlowRecordPO> list = queryChainWrapper.list();
if (list.isEmpty()) {
return new ArrayList<>();
}
TempPropertiesWrapper propertiesWrapper = getUserInfoAndTaxAgentMap(list);
// 转换数据
AtomicInteger indexNum = new AtomicInteger(1);
return list.stream().map(e -> TaxApiFlowBO.taxDeclarationApiFlowRecordPo2ListDTO(propertiesWrapper, indexNum, e)).collect(Collectors.toList());
}
private TempPropertiesWrapper getUserInfoAndTaxAgentMap(List<TaxDeclarationApiFlowRecordPO> list, String currentTenantKey) {
Map<Long, Long> employeeTaxAgentMap = SalaryEntityUtil.convert2Map(list, TaxDeclarationApiFlowRecordPO::getEmployeeId, TaxDeclarationApiFlowRecordPO::getTaxAgentId);
// 获取人员信息
List<HrmEmployeeComInfo> employeeComInfos = comInfoCache.getCacheList(HrmEmployeeComInfo.class, new ArrayList<>(employeeTaxAgentMap.keySet()));
Map<Long, String> empNameMap = SalaryEntityUtil.convert2Map(employeeComInfos, HrmEmployeeComInfo::getId, HrmEmployeeComInfo::getUsername);
Map<Long, String> empIdNoMap = salaryEmployeeService.mapByEmployeeIds(employeeTaxAgentMap.keySet());
List<ExtEmployeePO> extEmployeePOS = extEmployeeService.listAll(currentTenantKey);
Map<Long, ExtEmployeePO> extEmployeeMap = SalaryEntityUtil.convert2Map(extEmployeePOS, ExtEmployeePO::getId);
// 获取个税扣缴义务人信息
List<TaxAgentPO> taxAgentPOS = taxAgentService.listByIds(new HashSet<>(employeeTaxAgentMap.values()));
Map<Long, String> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgentPOS, TaxAgentPO::getId, TaxAgentPO::getName);
return new TempPropertiesWrapper(empNameMap, empIdNoMap, taxAgentNameMap, extEmployeeMap);
}
private LambdaQueryChainWrapper<TaxDeclarationApiFlowRecordPO> getFlowRecordQueryChainWrapper(TaxDeclarationApiFlowRecordQueryParam queryParam, String currentTenantKey) {
LambdaQueryChainWrapper<TaxDeclarationApiFlowRecordPO> chainWrapper = new LambdaQueryChainWrapper<>(taxDeclarationApiFlowRecordMapper)
.eq(TaxDeclarationApiFlowRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue())
.eq(TaxDeclarationApiFlowRecordPO::getTenantKey)
.eq(queryParam.getTaxAgentId() != null, TaxDeclarationApiFlowRecordPO::getTaxAgentId, queryParam.getTaxAgentId())
.eq(queryParam.getBusinessType() != null, TaxDeclarationApiFlowRecordPO::getBusinessType, queryParam.getBusinessType())
.eq(queryParam.getResult() != null, TaxDeclarationApiFlowRecordPO::getResultStatus, queryParam.getResult());
if (queryParam.getStartDate() != null && queryParam.getEndDate() != null) {
chainWrapper = chainWrapper.ge(TaxDeclarationApiFlowRecordPO::getUseTime, queryParam.getStartDate())
.le(TaxDeclarationApiFlowRecordPO::getUseTime, queryParam.getEndDate());
}
return chainWrapper;
}
@Override
public void exportFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam, Map<String, Object> map) {
ExportWrapper exportWrapper = new ExportWrapper(map, employeeId, tenantKey);
// 表头
List<String> headers = exportWrapper.getHeaders();
headers.add(SalaryI18nUtil.getI18nLabel( 159083, "时间"));
headers.add(SalaryI18nUtil.getI18nLabel( 86184, "个税扣缴义务人"));
headers.add(SalaryI18nUtil.getI18nLabel( 100133, "人员"));
headers.add(SalaryI18nUtil.getI18nLabel( 106277, "身份证号"));
headers.add(SalaryI18nUtil.getI18nLabel( 159085, "接口服务"));
headers.add(SalaryI18nUtil.getI18nLabel( 85435, "操作人"));
headers.add(SalaryI18nUtil.getI18nLabel( 159086, "结果"));
exportWrapper.getExcelSheetData().setHeaders(Collections.singletonList(headers.toArray(new String[]{})));
// 获取数据
List<TaxDeclarationApiFlowRecordListDTO> dtoList = listFlowRecord(queryParam, employeeId, tenantKey);
// 组装数据
for (TaxDeclarationApiFlowRecordListDTO dto : dtoList) {
List<Object> row = new ArrayList<>();
row.add(dto.getCreateTime());
row.add(dto.getTaxAgentName());
row.add(dto.getEmployeeName());
row.add(dto.getIdCardNo());
row.add(dto.getBusinessTypeName());
row.add(dto.getCreator());
row.add(dto.getResult());
exportWrapper.getRows().add(row);
}
// 生成表格
buildExcelData(exportWrapper);
}
/**
* 构建excel数据
*
* @param wrapper
*/
private void buildExcelData(ExportWrapper wrapper) {
wrapper.getExcelSheetData().setRows(wrapper.getRows());
wrapper.getSheetList().add(wrapper.getExcelSheetData());
salaryBatchService.simpleExportExcel(wrapper.buildExportExcelInfo(), wrapper.getSheetList());
}
@BatchExportHandler("exportFlowRecord")
public void exportFlowRecordHandler() {
BatchCallbackMessage message = BatchExportContext.getBatchCallbackMessage();
log.info("接收到流量使用记录导出的结果:{}", JSONObject.toJSONString(message));
}
/**
* 封装一些临时的集合类便于方法复用
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class TempPropertiesWrapper {
// 姓名
private Map<Long, String> empNameMap;
// 身份证
private Map<Long, String> empIdNoMap;
// 获取个税扣缴义务人信息
private Map<Long, String> taxAgentNameMap;
// 获取非系统人员
private Map<Long, ExtEmployeePO> extEmployeeMap;
}
@Data
public static class ApiFlowUpdateWrapper {
private String tenantKey;
private Long currentEmployeeId;
// 税款所属期
private LocalDate taxYearMonth;
// api流量使用情况
private List<TaxDeclarationApiFlowRecordPO> apiFlowDetailPOList;
// 当前租户的api接口配置
private TaxDeclarationApiConfigPO apiConfig;
// 接口类型
private EnumDeclareApiBusinessType businessType;
public ApiFlowUpdateWrapper(String tenantKey, Long currentEmployeeId, LocalDate taxYearMonth, TaxDeclarationApiConfigPO apiConfig, EnumDeclareApiBusinessType businessType) {
this.tenantKey = tenantKey;
this.currentEmployeeId = currentEmployeeId;
this.taxYearMonth = taxYearMonth;
this.apiFlowDetailPOList = new ArrayList<>();
this.apiConfig = apiConfig;
this.businessType = businessType;
}
}
}