2023-07-20 09:58:27 +08:00
|
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
|
2023-08-08 19:39:53 +08:00
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
|
import com.engine.core.impl.Service;
|
2023-08-28 13:31:11 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
2023-08-08 19:39:53 +08:00
|
|
|
|
import com.engine.salary.entity.extemp.po.ExtEmpPO;
|
2023-08-28 13:31:11 +08:00
|
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
|
|
|
|
|
import com.engine.salary.entity.taxapiflow.bo.TaxApiFlowBO;
|
|
|
|
|
|
import com.engine.salary.entity.taxapiflow.dto.TaxDeclarationApiFlowRecordListDTO;
|
|
|
|
|
|
import com.engine.salary.entity.taxapiflow.param.TaxDeclarationApiFlowRecordQueryParam;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
import com.engine.salary.entity.taxapiflow.po.TaxDeclarationApiFlowRecordPO;
|
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationApiConfigPO;
|
|
|
|
|
|
import com.engine.salary.enums.taxdeclaration.EnumDeclareApiBusinessType;
|
|
|
|
|
|
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationApiFlowRecordMapper;
|
2023-08-28 13:31:11 +08:00
|
|
|
|
import com.engine.salary.service.*;
|
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
2023-08-29 13:55:36 +08:00
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2023-08-20 14:03:43 +08:00
|
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
2023-08-29 13:55:36 +08:00
|
|
|
|
import com.engine.salary.util.excel.ExcelUtil;
|
2023-08-28 13:31:11 +08:00
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2023-08-29 13:55:36 +08:00
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
2023-08-08 19:39:53 +08:00
|
|
|
|
import weaver.hrm.User;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
|
2023-08-28 13:31:11 +08:00
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
2023-08-28 13:31:11 +08:00
|
|
|
|
public class TaxDeclarationApiBillingServiceImpl extends Service implements TaxDeclarationApiBillingService {
|
|
|
|
|
|
|
2023-08-20 14:03:43 +08:00
|
|
|
|
private TaxDeclarationApiFlowRecordMapper getTaxDeclarationApiFlowRecordMapper() {
|
|
|
|
|
|
return MapperProxyFactory.getProxy(TaxDeclarationApiFlowRecordMapper.class);
|
|
|
|
|
|
}
|
2023-08-28 13:31:11 +08:00
|
|
|
|
|
2023-08-08 19:39:53 +08:00
|
|
|
|
public TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
|
|
|
|
}
|
2023-08-28 13:31:11 +08:00
|
|
|
|
|
2023-08-08 19:39:53 +08:00
|
|
|
|
public SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
|
}
|
2023-08-28 13:31:11 +08:00
|
|
|
|
|
|
|
|
|
|
public TaxDeclarationApiFlowWarnService getTaxDeclarationApiFlowWarnService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxDeclarationApiFlowWarnServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-28 15:46:56 +08:00
|
|
|
|
public ExtEmpService getExtEmpService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(ExtEmpServiceImpl.class, user);
|
|
|
|
|
|
}
|
2023-07-20 09:58:27 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void updateApiFlowInfo(ApiFlowUpdateWrapper updateWrapper) {
|
|
|
|
|
|
// 保存流量使用详情
|
2023-08-28 13:31:11 +08:00
|
|
|
|
saveApiFlowRecord(updateWrapper);
|
2023-07-20 09:58:27 +08:00
|
|
|
|
// 流量不足提醒
|
2023-08-28 13:31:11 +08:00
|
|
|
|
getTaxDeclarationApiFlowWarnService(user).sendFlowWarnMessage(updateWrapper);
|
2023-07-20 09:58:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void saveApiFlowRecord(ApiFlowUpdateWrapper updateWrapper) {
|
|
|
|
|
|
if (!updateWrapper.getApiFlowDetailPOList().isEmpty()) {
|
2023-08-23 15:46:18 +08:00
|
|
|
|
List<List<TaxDeclarationApiFlowRecordPO>> failPartition = Lists.partition(updateWrapper.getApiFlowDetailPOList(), 50);
|
2023-08-20 14:03:43 +08:00
|
|
|
|
failPartition.forEach(list -> getTaxDeclarationApiFlowRecordMapper().batchInsert(list));
|
2023-07-20 09:58:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-28 13:31:11 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public PageInfo<TaxDeclarationApiFlowRecordListDTO> pageFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam) {
|
|
|
|
|
|
TaxDeclarationApiFlowRecordPO queryChainWrapper = getFlowRecordQueryChainWrapper(queryParam);
|
|
|
|
|
|
List<TaxDeclarationApiFlowRecordPO> records = getTaxDeclarationApiFlowRecordMapper().listSome(queryChainWrapper);
|
|
|
|
|
|
|
|
|
|
|
|
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 SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), listDTOS, TaxDeclarationApiFlowRecordListDTO.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public List<TaxDeclarationApiFlowRecordListDTO> listFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam) {
|
|
|
|
|
|
TaxDeclarationApiFlowRecordPO queryChainWrapper = getFlowRecordQueryChainWrapper(queryParam);
|
|
|
|
|
|
List<TaxDeclarationApiFlowRecordPO> list = getTaxDeclarationApiFlowRecordMapper().listSome(queryChainWrapper);
|
|
|
|
|
|
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) {
|
|
|
|
|
|
Map<Long, Long> employeeTaxAgentMap = SalaryEntityUtil.convert2Map(list, TaxDeclarationApiFlowRecordPO::getEmployeeId, TaxDeclarationApiFlowRecordPO::getTaxAgentId);
|
|
|
|
|
|
// 获取人员信息
|
2023-08-29 13:55:36 +08:00
|
|
|
|
List<DataCollectionEmployee> employeeComInfos = getSalaryEmployeeService(user).getEmployeeByIdsAll(new ArrayList<>(employeeTaxAgentMap.keySet()));
|
2023-08-28 13:31:11 +08:00
|
|
|
|
Map<Long, String> empNameMap = SalaryEntityUtil.convert2Map(employeeComInfos, DataCollectionEmployee::getEmployeeId, DataCollectionEmployee::getUsername);
|
|
|
|
|
|
Map<Long, String> empIdNoMap = getSalaryEmployeeService(user).mapByEmployeeIds(employeeTaxAgentMap.keySet());
|
2023-08-30 10:47:41 +08:00
|
|
|
|
|
|
|
|
|
|
//非系统人员信息
|
2023-08-28 15:46:56 +08:00
|
|
|
|
List<ExtEmpPO> extEmployeePOS = getExtEmpService(user).listAll();
|
2023-08-28 13:31:11 +08:00
|
|
|
|
Map<Long, ExtEmpPO> extEmployeeMap = SalaryEntityUtil.convert2Map(extEmployeePOS, ExtEmpPO::getId);
|
2023-08-30 10:47:41 +08:00
|
|
|
|
|
2023-08-28 13:31:11 +08:00
|
|
|
|
// 获取个税扣缴义务人信息
|
|
|
|
|
|
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(new HashSet<>(employeeTaxAgentMap.values()));
|
|
|
|
|
|
Map<Long, String> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgentPOS, TaxAgentPO::getId, TaxAgentPO::getName);
|
2023-08-30 10:47:41 +08:00
|
|
|
|
|
|
|
|
|
|
//创建人信息
|
|
|
|
|
|
List<Long> creators = SalaryEntityUtil.properties(list, TaxDeclarationApiFlowRecordPO::getCreator, Collectors.toList());
|
|
|
|
|
|
List<DataCollectionEmployee> creatorInfos = getSalaryEmployeeService(user).getEmployeeByIdsAll(new ArrayList<>(creators));
|
|
|
|
|
|
Map<Long, String> creatorNameMap = SalaryEntityUtil.convert2Map(creatorInfos, DataCollectionEmployee::getEmployeeId, DataCollectionEmployee::getUsername);
|
|
|
|
|
|
|
|
|
|
|
|
return new TempPropertiesWrapper(empNameMap, empIdNoMap, taxAgentNameMap, extEmployeeMap, creatorNameMap);
|
|
|
|
|
|
|
2023-08-28 13:31:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TaxDeclarationApiFlowRecordPO getFlowRecordQueryChainWrapper(TaxDeclarationApiFlowRecordQueryParam queryParam) {
|
|
|
|
|
|
TaxDeclarationApiFlowRecordPO build = TaxDeclarationApiFlowRecordPO.builder()
|
|
|
|
|
|
.taxAgentId(queryParam.getTaxAgentId())
|
|
|
|
|
|
.businessType(queryParam.getBusinessType())
|
|
|
|
|
|
.resultStatus(queryParam.getResult())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
if (queryParam.getStartDate() != null && queryParam.getEndDate() != null) {
|
|
|
|
|
|
build.setUseTimeStartDate(queryParam.getStartDate());
|
|
|
|
|
|
build.setUseTimeEndDate(queryParam.getEndDate());
|
|
|
|
|
|
}
|
|
|
|
|
|
return build;
|
|
|
|
|
|
}
|
2023-08-08 19:39:53 +08:00
|
|
|
|
|
2023-08-29 13:55:36 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public XSSFWorkbook exportFlowRecord(TaxDeclarationApiFlowRecordQueryParam queryParam) {
|
|
|
|
|
|
List<List<Object>> rows = new ArrayList<>();
|
|
|
|
|
|
// 表头
|
|
|
|
|
|
List<Object> headers = new ArrayList<>();
|
|
|
|
|
|
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, "结果"));
|
2023-08-30 10:47:41 +08:00
|
|
|
|
rows.add(headers);
|
2023-08-29 13:55:36 +08:00
|
|
|
|
// 获取数据
|
|
|
|
|
|
List<TaxDeclarationApiFlowRecordListDTO> dtoList = listFlowRecord(queryParam);
|
|
|
|
|
|
// 组装数据
|
|
|
|
|
|
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());
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 生成表格
|
|
|
|
|
|
return ExcelUtil.genWorkbookV2(rows, "接口使用记录数据");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-28 13:31:11 +08:00
|
|
|
|
|
2023-07-20 09:58:27 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 封装一些临时的集合类,便于方法复用
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Data
|
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
|
public static class TempPropertiesWrapper {
|
|
|
|
|
|
// 姓名
|
|
|
|
|
|
private Map<Long, String> empNameMap;
|
|
|
|
|
|
// 身份证
|
|
|
|
|
|
private Map<Long, String> empIdNoMap;
|
|
|
|
|
|
// 获取个税扣缴义务人信息
|
|
|
|
|
|
private Map<Long, String> taxAgentNameMap;
|
|
|
|
|
|
// 获取非系统人员
|
2023-08-08 19:39:53 +08:00
|
|
|
|
private Map<Long, ExtEmpPO> extEmployeeMap;
|
2023-08-30 10:47:41 +08:00
|
|
|
|
//创建人
|
|
|
|
|
|
private Map<Long, String> creatorNameMap;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
|
public static class ApiFlowUpdateWrapper {
|
|
|
|
|
|
private String tenantKey;
|
|
|
|
|
|
private Long currentEmployeeId;
|
|
|
|
|
|
// 税款所属期
|
2023-08-08 19:39:53 +08:00
|
|
|
|
private Date taxYearMonth;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
// api流量使用情况
|
|
|
|
|
|
private List<TaxDeclarationApiFlowRecordPO> apiFlowDetailPOList;
|
|
|
|
|
|
// 当前租户的api接口配置
|
|
|
|
|
|
private TaxDeclarationApiConfigPO apiConfig;
|
|
|
|
|
|
// 接口类型
|
|
|
|
|
|
private EnumDeclareApiBusinessType businessType;
|
|
|
|
|
|
|
2023-08-29 13:55:36 +08:00
|
|
|
|
public ApiFlowUpdateWrapper(Date taxYearMonth, TaxDeclarationApiConfigPO apiConfig, EnumDeclareApiBusinessType businessType, Long currentEmployeeId) {
|
2023-07-20 09:58:27 +08:00
|
|
|
|
this.taxYearMonth = taxYearMonth;
|
|
|
|
|
|
this.apiFlowDetailPOList = new ArrayList<>();
|
|
|
|
|
|
this.apiConfig = apiConfig;
|
|
|
|
|
|
this.businessType = businessType;
|
2023-08-28 16:48:52 +08:00
|
|
|
|
this.currentEmployeeId = currentEmployeeId;
|
2023-07-20 09:58:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|