703 lines
33 KiB
Java
703 lines
33 KiB
Java
package com.engine.salary.service.impl;
|
|
|
|
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
|
import com.engine.common.util.ServiceUtil;
|
|
import com.engine.core.impl.Service;
|
|
import com.engine.salary.biz.EmployBiz;
|
|
import com.engine.salary.biz.SpecialAddDeductionBiz;
|
|
import com.engine.salary.encrypt.datacollection.SpecialAddDeductionEncrypt;
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionListDTO;
|
|
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO;
|
|
import com.engine.salary.entity.datacollection.param.*;
|
|
import com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO;
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeTaxAgentDTO;
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
|
import com.engine.salary.enums.UserStatusEnum;
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
import com.engine.salary.mapper.datacollection.SpecialAddDeductionMapper;
|
|
import com.engine.salary.mapper.sys.SalarySysConfMapper;
|
|
import com.engine.salary.service.AddUpDeductionService;
|
|
import com.engine.salary.service.SalaryEmployeeService;
|
|
import com.engine.salary.service.SpecialAddDeductionService;
|
|
import com.engine.salary.service.TaxAgentService;
|
|
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
|
import com.engine.salary.sys.entity.vo.OrderRuleVO;
|
|
import com.engine.salary.sys.service.SalarySysConfService;
|
|
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
import com.engine.salary.util.excel.ExcelComment;
|
|
import com.engine.salary.util.excel.ExcelParseHelper;
|
|
import com.engine.salary.util.excel.ExcelUtil;
|
|
import com.engine.salary.util.page.PageInfo;
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.Validate;
|
|
import org.apache.poi.util.IOUtils;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import weaver.file.ImageFileManager;
|
|
import weaver.general.Util;
|
|
import weaver.hrm.User;
|
|
|
|
import java.io.InputStream;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.YearMonth;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
|
|
|
|
public class SpecialAddDeductionServiceImpl extends Service implements SpecialAddDeductionService {
|
|
|
|
private SpecialAddDeductionBiz getSpecialAddDeductionBiz() {
|
|
return new SpecialAddDeductionBiz();
|
|
}
|
|
|
|
private SpecialAddDeductionMapper getSpecialAddDeductionMapper() {
|
|
return MapperProxyFactory.getProxy(SpecialAddDeductionMapper.class);
|
|
}
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
}
|
|
|
|
private AddUpDeductionService getAddUpDeductionService(User user) {
|
|
return ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
|
|
}
|
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
}
|
|
|
|
private SalarySysConfMapper getSalarySysConfMapper() {
|
|
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
|
|
}
|
|
|
|
private SalarySysConfService getSalarySysConfService(User user) {
|
|
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
|
|
}
|
|
|
|
@Override
|
|
public SpecialAddDeductionPO getById(Long id) {
|
|
return getSpecialAddDeductionBiz().getById(id);
|
|
}
|
|
|
|
|
|
@Override
|
|
public PageInfo<SpecialAddDeductionListDTO> listPage(SpecialAddDeductionQueryParam queryParam) {
|
|
//排序配置
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
queryParam.setOrderRule(orderRule);
|
|
|
|
long employeeId = user.getUID();
|
|
|
|
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
|
|
if (needAuth) {
|
|
putQueryRange(queryParam, employeeId);
|
|
}
|
|
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
|
|
List<SpecialAddDeductionListDTO> list = getSpecialAddDeductionMapper().listByParam(queryParam);
|
|
SpecialAddDeductionEncrypt.decrypt(list);
|
|
return new PageInfo<>(list, SpecialAddDeductionListDTO.class);
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<SpecialAddDeductionRecordDTO> recordListPage(SpecialAddDeductionQueryParam queryParam) {
|
|
long employeeId = user.getUID();
|
|
|
|
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
|
|
if (needAuth) {
|
|
putQueryRange(queryParam, employeeId);
|
|
}
|
|
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
|
|
List<SpecialAddDeductionRecordDTO> list = getSpecialAddDeductionMapper().listDtoByParam(queryParam);
|
|
SpecialAddDeductionEncrypt.decrypt(list);
|
|
|
|
return new PageInfo<>(list, SpecialAddDeductionRecordDTO.class);
|
|
}
|
|
|
|
private void putQueryRange(SpecialAddDeductionQueryParam queryParam, long employeeId) {
|
|
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user)
|
|
.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId)
|
|
.collect(Collectors.toList());
|
|
if (CollectionUtils.isEmpty(taxAgentIdsAsAdmin)) {
|
|
// 不是个税扣缴义务人管理员,限定搜索范围为当前登录人
|
|
List<Long> taxAgentIdsAsEmployee = getTaxAgentService(user)
|
|
.listAllTaxAgentsAsRange(Collections.singletonList(employeeId))
|
|
.stream().filter(t -> t.getEmployeeId().equals(employeeId))
|
|
.map(TaxAgentEmployeeTaxAgentDTO::getTaxAgentIds)
|
|
.flatMap(Collection::stream)
|
|
.collect(Collectors.toList());
|
|
queryParam.setTaxAgentIds(taxAgentIdsAsEmployee);
|
|
queryParam.setEmployeeId(employeeId);
|
|
} else {
|
|
//管理员设置相应的个税扣缴义务人来筛选
|
|
queryParam.setTaxAgentIds(taxAgentIdsAsAdmin);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public Map<String, Object> preview(SpecialAddDeductionImportParam importParam) {
|
|
Map<String, Object> apidatas = new HashMap<String, Object>();
|
|
|
|
//excel文件id
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
Validate.notBlank(imageId, "imageId为空");
|
|
|
|
InputStream fileInputStream = null;
|
|
try {
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
|
|
List<SpecialAddDeductionListDTO> SpecialAddDeductions =
|
|
ExcelParseHelper.parse2Map(fileInputStream, SpecialAddDeductionListDTO.class, 0, 1, 11,
|
|
"SpecialAddDeductionTemplate.xlsx");
|
|
apidatas.put("preview", SpecialAddDeductions);
|
|
} finally {
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
}
|
|
return apidatas;
|
|
}
|
|
|
|
|
|
public Map<String, Object> importData(SpecialAddDeductionImportParam importParam) {
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
long currentEmployeeId = user.getUID();
|
|
Map<String, Object> apidatas = new HashMap<String, Object>();
|
|
EmployBiz employBiz = new EmployBiz();
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
|
|
//查询对于人员信息导入筛选的全局配置
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
//检验参数
|
|
checkImportParam(importParam);
|
|
|
|
//excel文件id
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
Validate.notBlank(imageId, "imageId为空");
|
|
//个税扣缴义务人
|
|
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
|
|
|
|
InputStream fileInputStream = null;
|
|
try {
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
|
|
List<SpecialAddDeductionListDTO> SpecialAddDeductions = ExcelParseHelper.parse2Map(fileInputStream, SpecialAddDeductionListDTO.class, 0, 1, 14, "SpecialAddDeductionTemplate.xlsx");
|
|
|
|
int total = SpecialAddDeductions.size();
|
|
int index = 0;
|
|
int successCount = 0;
|
|
int errorCount = 0;
|
|
|
|
//人员信息
|
|
List<DataCollectionEmployee> employees = employBiz.listEmployee();
|
|
// 获取所有个税扣缴义务人
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
// 查询已有数据
|
|
List<SpecialAddDeductionPO> list = getSpecialAddDeductionBiz()
|
|
.listByTaxAgentIds(null);
|
|
|
|
// 错误excel内容
|
|
List<Map> errorData = new ArrayList<>();
|
|
//合规数据
|
|
List<SpecialAddDeductionPO> eligibleData = new ArrayList<>();
|
|
|
|
for (int i = 0; i < SpecialAddDeductions.size(); i++) {
|
|
SpecialAddDeductionListDTO dto = SpecialAddDeductions.get(i);
|
|
|
|
Date now = new Date();
|
|
//待插入数据库对象
|
|
SpecialAddDeductionPO po = SpecialAddDeductionPO.builder()
|
|
.tenantKey(DEFAULT_TENANT_KEY)
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.creator((long) user.getUID())
|
|
.build();
|
|
|
|
//异常点数量
|
|
int errorSum = 0;
|
|
|
|
//行号
|
|
String rowIndex = String.format("第%s行", i + 2);
|
|
|
|
//相同的姓名
|
|
String userName = dto.getUsername();
|
|
String deparmentName = dto.getDepartmentName();
|
|
String mobile = dto.getMobile();
|
|
String workcode = dto.getJobNum();
|
|
List<Long> employeeSameIds = new ArrayList<>();
|
|
|
|
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
|
|
List<DataCollectionEmployee> emps = getSalaryEmployeeService(user)
|
|
.matchImportEmployee(employees, userName, deparmentName, mobile, workcode, null);
|
|
//含在职和离职,选在职数据
|
|
if (CollectionUtils.isNotEmpty(emps) && emps.size() > 1) {
|
|
employeeSameIds = emps.stream()
|
|
.filter(e -> UserStatusEnum.getNormalStatus().contains(e.getStatus()))
|
|
.map(DataCollectionEmployee::getEmployeeId)
|
|
.collect(Collectors.toList());
|
|
}
|
|
if (CollectionUtils.isNotEmpty(emps) && emps.size() == 1) {
|
|
employeeSameIds = emps.stream()
|
|
.map(DataCollectionEmployee::getEmployeeId)
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
//当人员信息导入筛选的全局配置为"0"时,姓名才是必填项
|
|
if (StringUtils.isBlank(userName) && "0".equals(confValue)) {
|
|
//姓名 不能为空
|
|
//错误消息对象
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
errorMessageMap.put("message", rowIndex + "姓名不能为空");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
} else if (CollectionUtils.isEmpty(employeeSameIds) || employeeSameIds.size() > 1) {
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
errorMessageMap.put("message", rowIndex + "员工信息不存在或者存在多个员工");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
} else {
|
|
Long employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0) : null;
|
|
if (employeeId != null && employeeId > 0) {
|
|
po.setEmployeeId(employeeId);
|
|
} else {
|
|
//姓名错误,系统内不存在该姓名
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
}
|
|
}
|
|
|
|
|
|
String taxAgentName = dto.getTaxAgentName();
|
|
if (StringUtils.isBlank(taxAgentName)) {
|
|
//个税扣缴义务人不能为空
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不能为空");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
} else {
|
|
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
|
|
if (optionalTemp.isPresent()) {
|
|
if (StringUtils.isNotEmpty(taxAgentId) && !optionalTemp.get().getTaxAgentId().equals(Long.valueOf(taxAgentId))) {
|
|
//个税扣缴义务人与导入时选择的不一致
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
errorMessageMap.put("message", rowIndex + "个税扣缴义务人与导入时选择的不一致");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
} else {
|
|
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
|
|
}
|
|
} else {
|
|
//个税扣缴义务人不存在
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在或不在权限范围内");
|
|
errorData.add(errorMessageMap);
|
|
errorSum += 1;
|
|
}
|
|
}
|
|
|
|
// 核心字段
|
|
po.setInfantCare(dto.getInfantCare())
|
|
.setSeriousIllnessTreatment(dto.getSeriousIllnessTreatment())
|
|
.setSupportingElder(dto.getSupportingElder())
|
|
.setHousingRent(dto.getHousingRent())
|
|
.setHousingLoanInterest(dto.getHousingLoanInterest())
|
|
.setContinuingEducation(dto.getContinuingEducation())
|
|
.setChildrenEducation(dto.getChildrenEducation());
|
|
|
|
|
|
//fixme 分权判断
|
|
if (errorSum == 0) {
|
|
successCount += 1;
|
|
// 合格数据
|
|
eligibleData.add(po);
|
|
} else {
|
|
errorCount += 1;
|
|
// 添加错误数据
|
|
}
|
|
}
|
|
|
|
//入库
|
|
SpecialAddDeductionBiz.handleImportData(eligibleData);
|
|
|
|
apidatas.put("successCount", successCount);
|
|
apidatas.put("errorCount", errorCount);
|
|
apidatas.put("errorData", errorData);
|
|
|
|
} finally {
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
}
|
|
return apidatas;
|
|
}
|
|
|
|
private void checkImportParam(SpecialAddDeductionImportParam importParam) {
|
|
//excel文件id
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
//个税扣缴义务人
|
|
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
|
|
|
|
if (StringUtils.isBlank(imageId)) {
|
|
throw new SalaryRunTimeException("文件不存在");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 导出
|
|
*
|
|
* @param param
|
|
* @return
|
|
*/
|
|
public XSSFWorkbook export(SpecialAddDeductionQueryParam param) {
|
|
|
|
//获取操作按钮资源
|
|
List<List<String>> rowList = getExcelRowList(param);
|
|
|
|
//获取excel
|
|
return ExcelUtil.genWorkbook(rowList, "其他免税扣除");
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取excel数据行
|
|
*
|
|
* @return 导出数据行集合
|
|
*/
|
|
private List<List<String>> getExcelRowList(SpecialAddDeductionQueryParam param) {
|
|
long employeeId = user.getUID();
|
|
//excel标题
|
|
List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "子女教育", "继续教育", "住房贷款利息", "住房租金", "赡养老人", "大病医疗", "婴幼儿照护");
|
|
//排序配置
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
param.setOrderRule(orderRule);
|
|
|
|
List<SpecialAddDeductionListDTO> list = getSpecialAddDeductionBiz().listByParam(param);
|
|
// 开启分权并且不是薪酬模块总管理员
|
|
if (getTaxAgentService(user).isOpenDevolution() && !getTaxAgentService(user).isChief(employeeId)) {
|
|
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
|
|
list = list.stream().filter(f ->
|
|
// 作为管理员
|
|
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
|
|
).collect(Collectors.toList());
|
|
}
|
|
|
|
|
|
final List<List<String>> dataRowList = Optional.ofNullable(list)
|
|
.map(List::stream)
|
|
.map(operatorStream -> operatorStream.map(dto -> {
|
|
List<String> cellList = new ArrayList<>();
|
|
cellList.add(Util.null2String(dto.getUsername()));
|
|
cellList.add(Util.null2String(dto.getTaxAgentName()));
|
|
cellList.add(Util.null2String(dto.getDepartmentName()));
|
|
cellList.add(Util.null2String(dto.getMobile()));
|
|
cellList.add(Util.null2String(dto.getJobNum()));
|
|
cellList.add(Util.null2String(dto.getIdNo()));
|
|
cellList.add(Util.null2String(dto.getHiredate()));
|
|
cellList.add(Util.null2String(dto.getChildrenEducation()));
|
|
cellList.add(Util.null2String(dto.getContinuingEducation()));
|
|
cellList.add(Util.null2String(dto.getHousingLoanInterest()));
|
|
cellList.add(Util.null2String(dto.getHousingRent()));
|
|
cellList.add(Util.null2String(dto.getSupportingElder()));
|
|
cellList.add(Util.null2String(dto.getSeriousIllnessTreatment()));
|
|
cellList.add(Util.null2String(dto.getInfantCare()));
|
|
return cellList;
|
|
}).collect(Collectors.toList()))
|
|
.orElse(Collections.emptyList());
|
|
|
|
List<List<String>> rowList = new ArrayList<>();
|
|
rowList.add(title);
|
|
rowList.addAll(dataRowList);
|
|
return rowList;
|
|
}
|
|
|
|
|
|
/**
|
|
* 导出详情列表
|
|
*
|
|
* @param param
|
|
* @return
|
|
*/
|
|
public XSSFWorkbook exportDetail(SpecialAddDeductionQueryParam param) {
|
|
|
|
SpecialAddDeductionBiz biz = new SpecialAddDeductionBiz();
|
|
EmployBiz employBiz = new EmployBiz();
|
|
|
|
Long id = param.getSpecialAddDeductionId();
|
|
if (id == null) {
|
|
throw new SalaryRunTimeException("id不能为空");
|
|
}
|
|
|
|
SpecialAddDeductionPO po = biz.getById(id);
|
|
if (po == null) {
|
|
throw new SalaryRunTimeException(String.format("专项附加扣除不存在" + "[id:%s]", id));
|
|
}
|
|
|
|
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()));
|
|
if (CollectionUtils.isEmpty(employeeList)) {
|
|
throw new SalaryRunTimeException("员工信息不存在");
|
|
}
|
|
|
|
//构建参数
|
|
param.setEmployeeId(po.getEmployeeId());
|
|
|
|
|
|
//获取操作按钮资源
|
|
List<List<String>> rowList = getExcelRowDetailList(param);
|
|
|
|
//获取excel
|
|
return ExcelUtil.genWorkbook(rowList, "专项附加扣除明细");
|
|
}
|
|
|
|
|
|
/**
|
|
* 导出详情
|
|
*
|
|
* @param param
|
|
* @return
|
|
*/
|
|
private List<List<String>> getExcelRowDetailList(SpecialAddDeductionQueryParam param) {
|
|
//excel标题
|
|
List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "子女教育", "继续教育", "住房贷款利息", "住房租金", "赡养老人", "大病医疗", "婴幼儿照护");
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
|
|
//查询详细信息
|
|
List<SpecialAddDeductionRecordDTO> list = getSpecialAddDeductionBiz().listDTOByParam(param);
|
|
SpecialAddDeductionEncrypt.decrypt(list);
|
|
final List<List<String>> dataRowList = Optional.ofNullable(list)
|
|
.map(List::stream)
|
|
.map(operatorStream -> operatorStream.map(dto -> {
|
|
List<String> cellList = new ArrayList<>();
|
|
cellList.add(Util.null2String(dto.getUsername()));
|
|
cellList.add(Util.null2String(dto.getTaxAgentName()));
|
|
cellList.add(Util.null2String(dto.getDepartmentName()));
|
|
cellList.add(Util.null2String(dto.getMobile()));
|
|
cellList.add(Util.null2String(dto.getJobNum()));
|
|
cellList.add(Util.null2String(dto.getChildrenEducation()));
|
|
cellList.add(Util.null2String(dto.getContinuingEducation()));
|
|
cellList.add(Util.null2String(dto.getHousingLoanInterest()));
|
|
cellList.add(Util.null2String(dto.getHousingRent()));
|
|
cellList.add(Util.null2String(dto.getSupportingElder()));
|
|
cellList.add(Util.null2String(dto.getSeriousIllnessTreatment()));
|
|
cellList.add(Util.null2String(dto.getInfantCare()));
|
|
return cellList;
|
|
}).collect(Collectors.toList()))
|
|
.orElse(Collections.emptyList());
|
|
|
|
List<List<String>> rowList = new ArrayList<>();
|
|
rowList.add(title);
|
|
rowList.addAll(dataRowList);
|
|
return rowList;
|
|
}
|
|
|
|
|
|
@Override
|
|
public List<SpecialAddDeductionPO> getSpecialAddDeductionList(YearMonth declareMonth, List<Long> employeeIds, Long taxAgentId) {
|
|
if (declareMonth == null) {
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100342, "参数有误:申报月份必传"));
|
|
}
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
return SpecialAddDeductionBiz.listByTaxAgentIds(null);
|
|
}
|
|
|
|
@Override
|
|
public void editData(SpecialAddDeductionParam specialAddDeductionParam) {
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
|
|
Long currentEmployeeId = (long) user.getUID();
|
|
// 获取所有个税扣缴义务人
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
|
|
getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
SpecialAddDeductionPO byId = SpecialAddDeductionBiz.getById(specialAddDeductionParam.getId());
|
|
if (byId == null) {
|
|
throw new SalaryRunTimeException("该数据不存在!");
|
|
}
|
|
Long taxAgentId = byId.getTaxAgentId();
|
|
boolean canEdit = taxAgentList.stream().anyMatch(t -> Objects.equals(t.getTaxAgentId(), taxAgentId));
|
|
if (!canEdit) {
|
|
//没有编辑权限
|
|
throw new SalaryRunTimeException("该个税扣缴义务人无权限编辑此数据!");
|
|
}
|
|
ArrayList<SpecialAddDeductionPO> updateList = new ArrayList<>();
|
|
SpecialAddDeductionPO build = SpecialAddDeductionPO.builder()
|
|
.id(specialAddDeductionParam.getId())
|
|
.childrenEducation(specialAddDeductionParam.getChildrenEducation())
|
|
.continuingEducation(specialAddDeductionParam.getContinuingEducation())
|
|
.housingLoanInterest(specialAddDeductionParam.getHousingLoanInterest())
|
|
.housingRent(specialAddDeductionParam.getHousingRent())
|
|
.build();
|
|
updateList.add(build);
|
|
SpecialAddDeductionBiz.batchUpdate(updateList);
|
|
}
|
|
|
|
@Override
|
|
public void createData(SpecialAddDeductionParam specialAddDeductionParam) {
|
|
long currentEmployeeId = user.getUID();
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
EmployBiz employBiz = new EmployBiz();
|
|
//查询对于人员信息导入筛选的全局配置
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
//人员信息
|
|
List<DataCollectionEmployee> employees = employBiz.listEmployee();
|
|
// 获取所有个税扣缴义务人
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
// 查询已有数据
|
|
List<SpecialAddDeductionPO> list = getSpecialAddDeductionBiz().listByTaxAgentIds(null);
|
|
//合规数据
|
|
List<SpecialAddDeductionPO> insertData = new ArrayList<>();
|
|
Date now = new Date();
|
|
//待插入数据库对象
|
|
SpecialAddDeductionPO po = SpecialAddDeductionPO.builder()
|
|
.tenantKey(DEFAULT_TENANT_KEY)
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.creator((long) user.getUID())
|
|
.build();
|
|
|
|
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
|
|
boolean employeeSameId = employees.stream()
|
|
.anyMatch(e -> Objects.equals(e.getEmployeeId(), specialAddDeductionParam.getEmployeeId()));
|
|
if (!employeeSameId) {
|
|
throw new SalaryRunTimeException("员工信息不存在");
|
|
}
|
|
po.setEmployeeId(specialAddDeductionParam.getEmployeeId());
|
|
String taxAgentName = specialAddDeductionParam.getTaxAgentName();
|
|
if (StringUtils.isBlank(taxAgentName)) {
|
|
//个税扣缴义务人不能为空
|
|
throw new SalaryRunTimeException("个税扣缴义务人不能为空");
|
|
} else {
|
|
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
|
|
if (optionalTemp.isPresent()) {
|
|
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
|
|
} else {
|
|
//个税扣缴义务人不存在或不在权限范围内
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
|
|
}
|
|
}
|
|
//数据填充
|
|
po.setContinuingEducation(specialAddDeductionParam.getContinuingEducation())
|
|
.setChildrenEducation(specialAddDeductionParam.getChildrenEducation())
|
|
.setHousingLoanInterest(specialAddDeductionParam.getHousingLoanInterest())
|
|
.setHousingRent(specialAddDeductionParam.getHousingRent())
|
|
.setSupportingElder(specialAddDeductionParam.getSupportingElder())
|
|
.setSeriousIllnessTreatment(specialAddDeductionParam.getSeriousIllnessTreatment())
|
|
.setInfantCare(specialAddDeductionParam.getInfantCare());
|
|
//fixme 分权判断
|
|
insertData.add(po);
|
|
//入库
|
|
SpecialAddDeductionBiz.handleImportData(insertData);
|
|
}
|
|
|
|
@Override
|
|
public void deleteSelectData(SpecialAddDeductionRecordDeleteParam deleteParam) {
|
|
long currentEmployeeId = user.getUID();
|
|
// 获取所有个税扣缴义务人
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
|
|
getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
List<Long> deleteIds = deleteParam.getIds();
|
|
List<Long> deleteList = new ArrayList<>();
|
|
for (Long id : deleteIds) {
|
|
SpecialAddDeductionPO byId = SpecialAddDeductionBiz.getById(id);
|
|
if (byId == null) {
|
|
throw new SalaryRunTimeException("数据不存在或已被删除!");
|
|
}
|
|
// 判断是否在个税扣缴义务人范围内
|
|
boolean isNotInRegion =
|
|
taxAgentList.stream()
|
|
.noneMatch(m -> Objects.equals(m.getTaxAgentId(), byId.getTaxAgentId()));
|
|
if (isNotInRegion) {
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
|
|
}
|
|
deleteList.add(byId.getId());
|
|
}
|
|
SpecialAddDeductionBiz.batchDeleteByIds(deleteList);
|
|
}
|
|
|
|
@Override
|
|
public void deleteAllData(SpecialAddDeductionRecordDeleteParam deleteParam) {
|
|
// 获取所有个税扣缴义务人
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
|
|
getTaxAgentService(user).listTaxAgentAndEmployeeTree((long) user.getUID());
|
|
List<Long> taxAgentIds = taxAgentList.stream()
|
|
.map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId)
|
|
.collect(Collectors.toList());
|
|
SpecialAddDeductionBiz specialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
|
|
if (deleteParam.getTaxAgentId() != null && (!deleteParam.getTaxAgentId().equals(""))) {
|
|
// 设置了个税扣缴义务人
|
|
Long taxAgentId = SalaryEntityUtil.string2Long(deleteParam.getTaxAgentId());
|
|
boolean canDelete = taxAgentIds.stream().anyMatch(t -> Objects.equals(t, taxAgentId));
|
|
if (!canDelete) {
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内!");
|
|
}
|
|
ArrayList<Long> tai = new ArrayList<>();
|
|
tai.add(taxAgentId);
|
|
taxAgentIds = tai;
|
|
}
|
|
// 获取所有想要删除的数据
|
|
List<SpecialAddDeductionPO> list = specialAddDeductionBiz.listByTaxAgentIds(taxAgentIds);
|
|
List<Long> deleteIds = list.stream().map(SpecialAddDeductionPO::getId).collect(Collectors.toList());
|
|
specialAddDeductionBiz.batchDeleteByIds(deleteIds);
|
|
}
|
|
|
|
@Override
|
|
public List<SpecialAddDeductionPO> getSpecialAddDeductionPOByEmployee(List<Long> employeeId, Long taxAgentId) {
|
|
return getSpecialAddDeductionBiz().getByEmployeeId(employeeId, taxAgentId);
|
|
}
|
|
|
|
@Override
|
|
public SpecialAddDeductionRecordDTO getRecordById(Long id) {
|
|
return getSpecialAddDeductionBiz()
|
|
.listDTOByParam(SpecialAddDeductionQueryParam.builder().specialAddDeductionId(id).build())
|
|
.stream().findFirst().orElse(null);
|
|
}
|
|
|
|
@Override
|
|
public XSSFWorkbook downloadTemplate(SpecialAddDeductionQueryParam param) {
|
|
// 1.工作簿名称
|
|
String sheetName = SalaryI18nUtil.getI18nLabel(101604, "其他免税扣除导入模板");
|
|
String[] header = {
|
|
SalaryI18nUtil.getI18nLabel(85429, "姓名"),
|
|
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
|
|
SalaryI18nUtil.getI18nLabel(86185, "部门"),
|
|
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
|
|
SalaryI18nUtil.getI18nLabel(86317, "工号"),
|
|
SalaryI18nUtil.getI18nLabel(86318, "证件号码"),
|
|
SalaryI18nUtil.getI18nLabel(86319, "入职日期"),
|
|
SalaryI18nUtil.getI18nLabel(91238, "商业健康保险"),
|
|
SalaryI18nUtil.getI18nLabel(91239, "税延养老保险"),
|
|
SalaryI18nUtil.getI18nLabel(84500, "其他"),
|
|
SalaryI18nUtil.getI18nLabel(91240, "准予扣除的捐赠额")
|
|
};
|
|
// 2.表头
|
|
List<List<Object>> rows = new ArrayList<>();
|
|
List<Object> headerList = Arrays.asList(header);
|
|
rows.add(headerList);
|
|
|
|
// 4.注释
|
|
List<ExcelComment> excelComments = Lists.newArrayList();
|
|
excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
|
excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
|
excelComments.add(new ExcelComment(7, 0, 10, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
|
|
excelComments.add(new ExcelComment(8, 0, 11, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
|
|
excelComments.add(new ExcelComment(9, 0, 12, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
|
|
excelComments.add(new ExcelComment(10, 0, 13, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
|
|
|
|
XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments);
|
|
return book;
|
|
}
|
|
|
|
}
|