weaver-hrm-salary/src/com/engine/salary/wrapper/TaxAgentWrapper.java

442 lines
17 KiB
Java
Raw Normal View History

2022-05-18 09:19:50 +08:00
package com.engine.salary.wrapper;
2022-11-22 15:37:07 +08:00
import com.cloudstore.dev.api.util.Util_DataCache;
2022-05-24 09:14:26 +08:00
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
2022-11-22 15:37:07 +08:00
import com.engine.salary.cache.SalaryCacheKey;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
2022-05-24 09:14:26 +08:00
import com.engine.salary.entity.hrm.HrmStatus;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
import com.engine.salary.entity.taxagent.dto.*;
2022-05-24 09:14:26 +08:00
import com.engine.salary.entity.taxagent.param.*;
2022-05-19 14:50:01 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentAdminPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2022-05-20 15:58:58 +08:00
import com.engine.salary.enums.UserStatusEnum;
2022-06-01 15:18:10 +08:00
import com.engine.salary.enums.salarysob.TargetTypeEnum;
2022-05-20 15:58:58 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2022-05-19 16:36:18 +08:00
import com.engine.salary.service.*;
2022-05-24 09:14:26 +08:00
import com.engine.salary.service.impl.*;
2022-05-19 16:36:18 +08:00
import com.engine.salary.util.SalaryI18nUtil;
2022-05-19 14:50:01 +08:00
import com.engine.salary.util.page.PageInfo;
2022-05-25 13:10:03 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
2022-05-18 09:19:50 +08:00
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2022-05-18 09:19:50 +08:00
import org.springframework.beans.BeanUtils;
2022-11-22 15:37:07 +08:00
import weaver.general.Util;
2022-05-24 09:14:26 +08:00
import weaver.hrm.User;
2022-05-18 09:19:50 +08:00
2022-05-31 21:15:33 +08:00
import java.util.*;
2022-05-18 09:19:50 +08:00
import java.util.stream.Collectors;
/**
2022-05-19 14:50:01 +08:00
* 个税扣缴义务人
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
2022-05-24 09:14:26 +08:00
public class TaxAgentWrapper extends Service {
2022-05-18 09:19:50 +08:00
2022-05-24 09:14:26 +08:00
public TaxAgentBaseService getTaxAgentBaseService(User user) {
return ServiceUtil.getService(TaxAgentBaseServiceImpl.class, user);
}
2022-05-19 14:50:01 +08:00
2022-05-24 09:14:26 +08:00
public TaxAgentAdminService getTaxAgentAdminService(User user) {
return ServiceUtil.getService(TaxAgentAdminServiceImpl.class, user);
}
2022-05-19 14:50:01 +08:00
2022-05-31 21:05:59 +08:00
public TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
2022-05-24 09:14:26 +08:00
}
2022-05-19 14:50:01 +08:00
2022-05-24 09:14:26 +08:00
public SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
2022-05-19 14:50:01 +08:00
2022-05-24 09:14:26 +08:00
public TaxAgentManageRangeService getTaxAgentManageRangeService(User user) {
return ServiceUtil.getService(TaxAgentManageRangeServiceImpl.class, user);
}
2022-05-19 14:50:01 +08:00
public TaxAgentExcelService getTaxAgentExcelService(User user) {
return ServiceUtil.getService(TaxAgentExcelServiceImpl.class, user);
}
2022-05-24 09:14:26 +08:00
// private PaymentAgencyService paymentAgencyService;
//
// private SIEmployeeStatusMapper siEmployeeStatusMapper;
//
// private HrmCommonHrmStatusService hrmCommonHrmStatusService;
//
// private HrmConfigSetCache hrmConfigSetCache;
2022-05-18 09:19:50 +08:00
/**
* 是否是薪酬模块总管理员
*
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public Boolean isChief(Long currentEmployeeId) {
2022-05-24 09:14:26 +08:00
return getTaxAgentService(user).isChief(currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 权限信息
*
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public Map<String, Boolean> permission(Long currentEmployeeId) {
2022-05-18 09:19:50 +08:00
Map<String, Boolean> resultMap = Maps.newHashMap();
2022-05-19 14:50:01 +08:00
Boolean isChief = isChief(currentEmployeeId);
2022-05-24 09:14:26 +08:00
Boolean isDefaultOpen = getTaxAgentService(user).isDefaultOpen(currentEmployeeId);
Boolean isAdminEnable = getTaxAgentService(user).isAdminEnable(currentEmployeeId);
2022-06-09 17:45:28 +08:00
Boolean isOpenDevolution = getTaxAgentService(user).isOpenDevolution();
2022-05-18 09:19:50 +08:00
resultMap.put("isChief", isChief);
resultMap.put("isDefaultOpen", isDefaultOpen);
resultMap.put("isAdminEnable", isAdminEnable);
2022-06-09 17:45:28 +08:00
resultMap.put("isOpenDevolution", isOpenDevolution);
2022-05-18 09:19:50 +08:00
return resultMap;
}
/**
* 个税口角义务人列表
*
* @param queryParam
* @return
*/
2022-05-30 20:13:03 +08:00
public PageInfo<Map<String, Object>> list(TaxAgentQueryParam queryParam) {
2022-05-18 09:19:50 +08:00
// 是否是总管理员
2022-05-24 09:14:26 +08:00
Boolean isChief = getTaxAgentService(user).isChief((long) user.getUID());
2022-05-18 09:19:50 +08:00
// 是否开启分权
2022-05-24 09:14:26 +08:00
boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution();
2022-05-18 09:19:50 +08:00
2022-05-19 14:50:01 +08:00
// List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
2022-05-18 09:19:50 +08:00
2022-05-19 14:50:01 +08:00
PageInfo<TaxAgentPO> page = null;
2022-05-30 14:17:02 +08:00
// 分权情况下,根据自己作为管理员过滤列表
if (isOpenDevolution && !isChief) {
List<TaxAgentPO> list = getTaxAgentService(user).list(queryParam);
// 1.判断自己是否是管理员, 如果是管理员,就是能够操作所属个税扣缴义务人下的所有人的数据
List<TaxAgentAdminPO> taxAgentAdminList = getTaxAgentAdminService(user).listByTaxAgentIdsAndEmployeeId(list.stream().map(TaxAgentPO::getId).collect(Collectors.toList()), (long) user.getUID());
// 是管理员的列表
List<Long> adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList());
list = list.stream().filter(f -> adminTaxAgentIds.contains(f.getId())).collect(Collectors.toList());
// 分页参数
// 填充总数和当页数据
PageInfo<TaxAgentPO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize());
dtoPage.setTotal(list.size());
dtoPage.setPageNum(queryParam.getCurrent());
dtoPage.setPageSize(queryParam.getPageSize());
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getPageSize(), list));
page = dtoPage;
2022-05-18 09:19:50 +08:00
} else {
2022-05-30 14:17:02 +08:00
page = getTaxAgentService(user).listPage(queryParam);
2022-05-18 09:19:50 +08:00
}
2022-05-19 16:36:18 +08:00
PageInfo<Map<String, Object>> listPage = new PageInfo<>();
2022-05-18 09:19:50 +08:00
2022-05-19 16:36:18 +08:00
String setLabel = SalaryI18nUtil.getI18nLabel(94614, "设置");
2022-05-18 09:19:50 +08:00
if (isOpenDevolution) {
2022-05-19 16:36:18 +08:00
List<TaxAgentPO> list = page.getList();
List<Long> taxAgentIds = list.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
2022-05-24 09:14:26 +08:00
List<TaxAgentAdminPO> taxAgentAdmins = getTaxAgentAdminService(user).listByTaxAgentIds(taxAgentIds);
List<DataCollectionEmployee> adminList = getSalaryEmployeeService(user).listByIds(taxAgentAdmins.stream().map(TaxAgentAdminPO::getEmployeeId).distinct().collect(Collectors.toList()));
2022-05-19 16:36:18 +08:00
listPage.setList(TaxAgentBO.convertToTableListDTO(page.getList(), null, taxAgentAdmins, adminList, setLabel));
2022-05-18 09:19:50 +08:00
} else {
2022-05-19 16:36:18 +08:00
listPage.setList(TaxAgentBO.convertToTableListDTO(page.getList(), null, setLabel));
2022-05-18 09:19:50 +08:00
}
2022-05-19 16:36:18 +08:00
2022-05-30 14:17:02 +08:00
listPage.setTotal(page.getTotal());
listPage.setPageNum(page.getPageNum());
listPage.setPageSize(page.getPageSize());
2022-05-18 09:19:50 +08:00
//构造表格
2022-05-30 20:13:03 +08:00
TaxAgentBO.buildTaxAgentTable(listPage, isOpenDevolution);
2022-05-19 16:36:18 +08:00
2022-05-30 20:13:03 +08:00
return listPage;
2022-05-19 16:36:18 +08:00
2022-05-18 09:19:50 +08:00
}
2022-05-24 09:14:26 +08:00
public List<Map<String, Object>> paymentAgencyList(TaxAgentQueryParam queryParam) {
// List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(queryParam.getIds());
// List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
// SalaryAssert.notEmpty(taxAgentPOS, "taxagent data is not exist");
// TaxAgentPO taxAgentPO = taxAgentPOS.get(0);
// return TaxAgentBO.buildPaymentAgency(taxAgentPO.getPaymentAgency(), paymentAgencyPOS);
return null;
2022-05-18 09:19:50 +08:00
}
2022-05-24 09:14:26 +08:00
public String paymentAgencySave(TaxAgentSaveParam param) {
// List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(Collections.singletonList(param.getId()));
2022-05-19 16:36:18 +08:00
// SalaryAssert.notEmpty(taxAgentPOS, "data is not exist");
// TaxAgentPO taxAgentPO = taxAgentPOS.get(0);
// List<String> errorList = new ArrayList<>();
// List<String> resultList = new ArrayList<>();
// if (StringUtils.isNotBlank(taxAgentPO.getPaymentAgency())) {
// List<String> originList = new ArrayList<>(Arrays.asList(taxAgentPO.getPaymentAgency().split(",")));
// List<String> list = new ArrayList<>(Arrays.asList(param.getPaymentAgency().split(",")));
// originList.removeAll(list);
// if (CollectionUtils.isNotEmpty(originList)) {
// originList.stream().forEach(e -> {
// List<InsuranceEmployeeStatusPO> employeeStatusPOS = new LambdaQueryChainWrapper<>(siEmployeeStatusMapper)
// .eq(InsuranceEmployeeStatusPO::getTenantKey)
// .eq(InsuranceEmployeeStatusPO::getPaymentAgency, Long.valueOf(e))
// .eq(InsuranceEmployeeStatusPO::getPaymentOrganization, param.getId())
// .list();
// if (CollectionUtils.isNotEmpty(employeeStatusPOS)) {
// errorList.add(e);
// }
// });
// }
// if (CollectionUtils.isNotEmpty(errorList)) {
// List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
// errorList.forEach(e -> {
// Optional<PaymentAgencyPO> optionalPaymentAgencyPO = paymentAgencyPOS.stream().filter(po -> Objects.equals(e, String.valueOf(po.getId()))).findFirst();
// optionalPaymentAgencyPO.ifPresent(paymentAgencyPO -> resultList.add(paymentAgencyPO.getAgencyName()));
// });
// }
// }
// if (CollectionUtils.isNotEmpty(resultList)) {
// return SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmploueeId, 115128, "有员工在") + String.join(",", resultList) + SalaryI18nUtil.getI18nLabel(currentTenantKey,
// currentEmploueeId, 115129, "缴纳社保福利,不可取消关联");
// } else {
// taxAgentPO.setPaymentAgency(param.getPaymentAgency());
2022-05-24 09:14:26 +08:00
// getTaxAgentService(user).paymentAgencyUpdate(taxAgentPO, currentEmploueeId);
2022-05-19 16:36:18 +08:00
// }
2022-05-18 09:19:50 +08:00
return "";
}
/**
* 获取个税扣缴义务人表单
*
* @param id
* @return
*/
2022-05-20 15:58:58 +08:00
public TaxAgentFormDTO getFrom(Long id) {
2022-05-18 09:19:50 +08:00
TaxAgentFormDTO taxAgentFromDTO = new TaxAgentFormDTO();
if (id != null) {
2022-05-24 09:14:26 +08:00
TaxAgentPO taxAgent = getTaxAgentService(user).getById(id);
2022-05-18 09:19:50 +08:00
if (taxAgent == null) {
2022-05-20 15:58:58 +08:00
throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(100543, "个税扣缴人不存在") + "[id:%s]", id));
2022-05-18 09:19:50 +08:00
}
BeanUtils.copyProperties(taxAgent, taxAgentFromDTO);
}
// 是否开启分权
2022-05-24 09:14:26 +08:00
boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution();
List<TaxAgentAdminPO> admins = getTaxAgentAdminService(user).listByTaxAgentIds(Collections.singletonList(id));
List<TaxAgentEmployeeOptionDTO> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(admins)) {
list = admins.stream()
.map(admin -> {
Long employeeId = admin.getEmployeeId();
DataCollectionEmployee employee = getSalaryEmployeeService(user).getEmployeeById(employeeId);
String content = employee == null ? "" : employee.getUsername();
return TaxAgentEmployeeOptionDTO.builder().id(employeeId).content(content).build();
2022-05-31 21:15:33 +08:00
})
.collect(Collectors.toList());
2022-05-18 09:19:50 +08:00
}
2022-05-20 15:58:58 +08:00
taxAgentFromDTO.setAdminUserIds(list);
2022-05-20 15:58:58 +08:00
return taxAgentFromDTO;
2022-05-18 09:19:50 +08:00
}
/**
* 保存个税扣缴义务人
*
* @param saveParam
* @return
*/
2022-05-24 09:14:26 +08:00
public String save(TaxAgentSaveParam saveParam) {
return getTaxAgentService(user).save(saveParam);
2022-05-18 09:19:50 +08:00
}
/**
* 编辑个税扣缴义务人
*
* @param saveParam
* @return
*/
2022-05-24 09:14:26 +08:00
public String update(TaxAgentSaveParam saveParam) {
return getTaxAgentService(user).update(saveParam);
2022-05-18 09:19:50 +08:00
}
/**
* 更换管理员校验
*
* @param checkParam
* @return
*/
2022-05-24 09:14:26 +08:00
public Boolean adminChangeCheck(TaxAgentAdminChangeCheckParam checkParam) {
return getTaxAgentService(user).adminChangeCheck(checkParam);
2022-05-18 09:19:50 +08:00
}
/**
* 删除个税扣缴义务人
*
* @param ids
* @return
*/
2022-12-02 16:58:19 +08:00
public String delete(List<Long> ids) {
2022-05-24 09:14:26 +08:00
return getTaxAgentService(user).delete(ids);
2022-05-18 09:19:50 +08:00
}
/**
* 个税扣缴义务人下拉列表
*
* @return
*/
2022-05-24 09:14:26 +08:00
public List<Map<String, Object>> selectList() {
return getTaxAgentService(user).selectList();
2022-05-18 09:19:50 +08:00
}
2022-07-05 15:31:18 +08:00
public List<Map<String, Object>> selectListAsAdmin() {
return getTaxAgentService(user).selectListAsAdmin(false);
}
2022-05-18 09:19:50 +08:00
/**
* 范围列表
*
* @param queryParam
* @return
*/
2022-05-19 16:36:18 +08:00
public PageInfo<TaxAgentManageRangeListDTO> listRangeInclude(TaxAgentRangeQueryParam queryParam) {
2022-05-24 09:14:26 +08:00
PageInfo<TaxAgentManageRangeListDTO> listPage = getTaxAgentManageRangeService(user).listPageByParamAndIncludeType(queryParam, NumberUtils.INTEGER_ONE);
2022-05-20 15:58:58 +08:00
return listPage;
2022-05-18 09:19:50 +08:00
}
/**
* 范围排除列表
*
* @param queryParam
* @return
*/
2022-05-20 15:58:58 +08:00
public PageInfo<TaxAgentManageRangeListDTO> listRangeExclude(TaxAgentRangeQueryParam queryParam) {
2022-05-24 09:14:26 +08:00
PageInfo<TaxAgentManageRangeListDTO> listPage = getTaxAgentManageRangeService(user).listPageByParamAndIncludeType(queryParam, NumberUtils.INTEGER_ZERO);
2022-05-20 15:58:58 +08:00
return listPage;
2022-05-18 09:19:50 +08:00
}
/**
* 获取管理范围表单
*
* @return
*/
2022-05-24 09:14:26 +08:00
public TaxAgentManageRangeFormDTO getRangeFrom() {
2022-05-18 09:19:50 +08:00
// 查询人员状态
2022-05-24 09:14:26 +08:00
List<HrmStatus> hrmStatusList = UserStatusEnum.getHrmStatusList();
2022-06-01 15:18:10 +08:00
//人员类型下拉列表
List<Map<String, Object>> selectList = TargetTypeEnum.getSelectList();
return TaxAgentManageRangeFormDTO.builder().employeeStatus(hrmStatusList).targetTypeList(selectList).build();
2022-05-18 09:19:50 +08:00
}
/**
* 保存管理范围
*
* @param saveParam
* @return
*/
2022-05-24 09:14:26 +08:00
public String saveRange(TaxAgentRangeSaveParam saveParam) {
getTaxAgentManageRangeService(user).save(saveParam);
2022-05-18 09:19:50 +08:00
return StringUtils.EMPTY;
}
/**
* 删除管理范围
*
* @param ids
* @return
*/
2022-05-24 09:14:26 +08:00
public String deleteRange(Collection<Long> ids) {
getTaxAgentManageRangeService(user).deleteByIds(ids);
2022-05-18 09:19:50 +08:00
return StringUtils.EMPTY;
}
/**
* 获取个税管理的人员情况
2022-11-22 15:37:07 +08:00
*
* @param id
* @return
*/
public List<TaxAgentManageRangeEmployeeDTO> getEmpListInTaxAgent(Long id) {
return getTaxAgentService(user).listTaxAgentAndEmployeeTree((long) user.getUID());
}
2022-11-22 15:37:07 +08:00
/**
2022-11-22 15:53:05 +08:00
* 同步当前人员管理的个税扣缴义务人人员范围
2022-11-22 15:37:07 +08:00
*
* @return
*/
public String syncRange() {
long currentEmployeeId = (long) user.getUID();
List<Long> taxAgentIds = this.getTaxAgentService(user).listAllTaxAgents(currentEmployeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
2022-11-22 15:53:05 +08:00
String index = SalaryCacheKey.TAX_AGENT_MANAGE_RANGE_SYNC + "-" + currentEmployeeId;
2022-11-22 15:37:07 +08:00
String syncRange = Util.null2String(Util_DataCache.getObjVal(index));
if (StringUtils.isEmpty(syncRange)) {
2022-11-22 15:53:05 +08:00
getTaxAgentManageRangeService(user).syncManageRange(taxAgentIds, index);
2022-11-24 17:33:48 +08:00
// try {
// TimeUnit.SECONDS.sleep(2);
// } catch (InterruptedException e) {
//
// }
2022-11-22 15:53:05 +08:00
} else {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(135788, "人员范围同步过于频繁,请稍后再试"));
}
return SalaryI18nUtil.getI18nLabel(93945, "同步成功");
}
/**
* 同步所有个税扣缴义务人的人员范围
*
* @return
*/
public String syncAllRange() {
String syncRange = Util.null2String(Util_DataCache.getObjVal(SalaryCacheKey.TAX_AGENT_MANAGE_RANGE_SYNC));
if (StringUtils.isEmpty(syncRange)) {
getTaxAgentManageRangeService(user).syncManageRange(null, SalaryCacheKey.TAX_AGENT_MANAGE_RANGE_SYNC);
2022-11-24 10:30:00 +08:00
// try {
// TimeUnit.SECONDS.sleep(2);
// } catch (InterruptedException e) {
//
// }
2022-11-22 15:37:07 +08:00
} else {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(135788, "人员范围同步过于频繁,请稍后再试"));
}
return SalaryI18nUtil.getI18nLabel(93945, "同步成功");
}
/**
* 下载人员范围导入模板
* @param downloadTemplateParam
* @return
*/
public XSSFWorkbook exportImportTemplate(TaxAgentRangeDownloadTemplateParam downloadTemplateParam) {
return getTaxAgentExcelService(user).downloadTemplateRange(downloadTemplateParam, user.getUID());
}
/**
* 预览人员范围
* @param taxAgentImportParam
*/
public Map<String, Object> preview(TaxAgentImportParam taxAgentImportParam) {
return getTaxAgentExcelService(user).preview(taxAgentImportParam);
}
/**
* 个税扣缴义务人-人员范围导入
* @param taxAgentImportParam
*/
public Map<String, Object> importData(TaxAgentImportParam taxAgentImportParam) {
return getTaxAgentManageRangeService(user).importData(taxAgentImportParam);
}
2022-05-18 09:19:50 +08:00
}