weaver-hrm-salary/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java

750 lines
36 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.engine.salary.service.impl;
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.biz.AddUpDeductionBiz;
import com.engine.salary.biz.EmployBiz;
import com.engine.salary.biz.TaxAgentBiz;
import com.engine.salary.common.LocalDateRange;
import com.engine.salary.entity.datacollection.AddUpDeduction;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO;
import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpDeductionImportParam;
import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam;
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.entity.taxrate.TaxAgent;
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.datacollection.AddUpDeductionMapper;
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryDateUtil;
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 weaver.systeminfo.SystemEnv;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
public class AddUpDeductionServiceImpl extends Service implements AddUpDeductionService {
private AddUpDeductionMapper getAddUpDeductionMapper() {
return MapperProxyFactory.getProxy(AddUpDeductionMapper.class);
}
private TaxAgentV2Service getTaxAgentV2Service(User user) {
return ServiceUtil.getService(TaxAgentV2ServiceImpl.class, user);
}
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
}
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
@Override
public Map<String, Object> getSearchCondition(Map<String, Object> params) {
Map<String, Object> apidatas = new HashMap<String, Object>();
ConditionFactory conditionFactory = new ConditionFactory(user);
//条件组
List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();
List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();
//文本输入框
SearchConditionItem username = conditionFactory.createCondition(ConditionType.INPUT,25034, "username");
username.setInputType("input");
username.setColSpan(2);//定义一行显示条件数默认值为2,当值为1时标识该条件单独占一行
username.setFieldcol(16); //条件输入框所占宽度默认值18
username.setLabelcol(8);
username.setViewAttr(2); // 编辑权限 1只读2可编辑 3必填 默认2
username.setLabel("姓名"); //设置文本值 这个将覆盖多语言标签的值
conditionItems.add(username);
SearchConditionItem departmentName = conditionFactory.createCondition(ConditionType.BROWSER,502227,"departmentIds","4");
departmentName.setInputType("browser");
departmentName.setColSpan(2);
departmentName.setFieldcol(16);
departmentName.setLabelcol(8);
departmentName.setViewAttr(2);
departmentName.setIsQuickSearch(false);
departmentName.setLabel("部门");
conditionItems.add(departmentName);
SearchConditionItem jobNum = conditionFactory.createCondition(ConditionType.INPUT,25034, "jobNum");
jobNum.setInputType("input");
jobNum.setColSpan(2);
jobNum.setFieldcol(16);
jobNum.setLabelcol(8);
jobNum.setViewAttr(2);
jobNum.setLabel("工号");
conditionItems.add(jobNum);
SearchConditionItem idNo = conditionFactory.createCondition(ConditionType.INPUT,25034, "idNo");
idNo.setInputType("input");
idNo.setColSpan(2);
idNo.setFieldcol(16);
idNo.setLabelcol(8);
idNo.setViewAttr(2);
idNo.setLabel("证件号码");
conditionItems.add(idNo);
//日期范围选项
List<SearchConditionOption> dateOptions = new ArrayList<SearchConditionOption>();
dateOptions.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(32530, user.getLanguage()),true));//指定日期范围(必须为6)
SearchConditionItem hiredate = conditionFactory.createCondition(ConditionType.RANGEPICKER, 18648, new String[]{"hiredate","hiredate"});
hiredate.setInputType("rangepicker");
hiredate.setFormat("yyyy-MM-dd");
hiredate.setFieldcol(16);
hiredate.setLabelcol(8);
hiredate.setViewAttr(2);
hiredate.setLabel("入职日期");
hiredate.setOptions(dateOptions);
conditionItems.add(hiredate);
SearchConditionItem mobile = conditionFactory.createCondition(ConditionType.INPUT,25034, "mobile");
mobile.setInputType("input");
mobile.setColSpan(2);
mobile.setFieldcol(16);
mobile.setLabelcol(8);
mobile.setViewAttr(2);
mobile.setLabel("手机号");
conditionItems.add(mobile);
addGroups.add(new SearchConditionGroup("常用条件",true,conditionItems));
apidatas.put("condition",addGroups);
return apidatas;
}
@Override
public Map<String, Object> importAddUpDeduction(AddUpDeductionImportParam importParam) {
Map<String, Object> apidatas = new HashMap<String, Object>();
EmployBiz employBiz = new EmployBiz();
AddUpDeductionBiz addUpDeductionBiz = new AddUpDeductionBiz();
//检验参数
checkImportParam(importParam);
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
Validate.notBlank(imageId, "imageId为空");
//税款所属期
String declareMonthStr = Util.null2String(importParam.getDeclareMonth());
//个税扣缴义务人
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
// 获取租户下所有的人员
List<DataCollectionEmployeePO> employees = addUpDeductionMapper.listEmployee(tenantKey);
// 已经核算过的不可操作
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAccountedEmployeeData(declareMonth, tenantKey);
// 查询已有数据
List<AddUpDeductionPO> list = new LambdaQueryChainWrapper<>(addUpDeductionMapper)
.eq(AddUpDeductionPO::getDeleteType, 0)
.eq(AddUpDeductionPO::getTenantKey, tenantKey)
.eq(AddUpDeductionPO::getDeclareMonth, LocalDate.parse(declareMonth+"-01", SalaryDateUtil.DATE_FORMATTER))
.list();
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
List<AddUpDeductionDTO> addUpDeductions = ExcelParseHelper.parse2Map(fileInputStream, AddUpDeductionDTO.class, 0, 1, 14, "addUpDeductionTemplate.xlsx");
int total = addUpDeductions.size();
int index = 0;
int successCount = 0;
int errorCount = 0;
//人员信息
List<DataCollectionEmployee> employees = employBiz.listEmployee();
List<TaxAgent> taxAgents = new TaxAgentBiz().listAll();
//税款所属期
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
// 错误excel内容
List<Map> errorData = new ArrayList<>();
//合规数据
List<AddUpDeduction> eligibleData = new ArrayList<>();
for (int i = 0; i < addUpDeductions.size(); i++) {
AddUpDeductionDTO dto = addUpDeductions.get(i);
Date now = new Date();
//待插入数据库对象
AddUpDeduction addUpDeduction = AddUpDeduction.builder()
.tenantKey(DEFAULT_TENANT_KEY)
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.declareMonth(declareMonth).build();
//异常点数量
int errorSum = 0;
//行号
String rowIndex = String.format("第%s行", i + 2);
//相同的姓名
String userName = dto.getUsername();
String deparmentName = dto.getDepartmentName();
List<Long> employeeSameIds = employees.stream().filter(e -> (StringUtils.isBlank(userName) || Objects.equals(e.getUsername(), userName))
&& (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDepartmentName(), deparmentName))).map(DataCollectionEmployee::getEmployeeId)
.collect(Collectors.toList());
if (StringUtils.isBlank(userName)) {
//姓名 不能为空
//错误消息对象
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) {
addUpDeduction.setEmployeeId(employeeId);
} else {
//姓名错误,系统内不存在该姓名
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
String taxAgentName = dto.getTaxAgentName();
if (StringUtils.isBlank(taxAgentName)) {
//个税扣缴义务人不能为空
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不能为空");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
Optional<TaxAgent> optionalTemp = taxAgents.stream().filter(m -> m.getName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
if (StringUtils.isNotEmpty(taxAgentId) && !optionalTemp.get().getId().equals(Long.valueOf(taxAgentId))) {
//个税扣缴义务人与导入时选择的不一致
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人与导入时选择的不一致");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
addUpDeduction.setTaxAgentId(optionalTemp.get().getId());
}
} else {
//个税扣缴义务人不存在
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
//累计子女教育
BigDecimal addUpChildEducation = dto.getAddUpChildEducation();
addUpDeduction.setAddUpChildEducation(Util.null2String(addUpChildEducation));
//累计继续教育
BigDecimal addUpContinuingEducation = dto.getAddUpContinuingEducation();
addUpDeduction.setAddUpContinuingEducation(Util.null2String(addUpContinuingEducation));
//累计住房贷款利息
BigDecimal addUpHousingLoanInterest = dto.getAddUpHousingLoanInterest();
addUpDeduction.setAddUpHousingLoanInterest(Util.null2String(addUpHousingLoanInterest));
//累计住房租金
BigDecimal addUpHousingRent = dto.getAddUpHousingRent();
addUpDeduction.setAddUpHousingRent(Util.null2String(addUpHousingRent));
//累计赡养老人
BigDecimal addUpSupportElderly = dto.getAddUpSupportElderly();
addUpDeduction.setAddUpSupportElderly(Util.null2String(addUpSupportElderly));
addUpDeduction.setAddUpIllnessMedical(Util.null2String(dto.getAddUpIllnessMedical()));
addUpDeduction.setAddUpInfantCare(Util.null2String(dto.getAddUpInfantCare()));
if (errorSum == 0) {
successCount += 1;
// 合格数据
eligibleData.add(addUpDeduction);
} else {
errorCount += 1;
// 添加错误数据
}
}
//入库
addUpDeductionBiz.handleImportData(eligibleData);
apidatas.put("successCount", successCount);
apidatas.put("errorCount", errorCount);
apidatas.put("errorData", errorData);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
private void checkImportParam(AddUpDeductionImportParam importParam) {
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
//税款所属期
String declareMonthStr = Util.null2String(importParam.getDeclareMonth());
//个税扣缴义务人
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException("文件不存在");
}
if (StringUtils.isBlank(declareMonthStr)) {
throw new SalaryRunTimeException("税款所属期为空");
}
}
@Override
public Map<String, Object> preview(AddUpDeductionImportParam 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<AddUpDeductionDTO> addUpDeductions = ExcelParseHelper.parse2Map(fileInputStream, AddUpDeductionDTO.class, 0, 1, 14, "addUpDeductionTemplate.xlsx");
apidatas.put("preview", addUpDeductions);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
@Override
public AddUpDeduction getById(Long id) {
return getAddUpDeductionMapper().getById(id);
}
// /**
// * 获取作为修改者的最新记录
// * 说明以人员id和个税口角义务人id去重
// *
// * @param currentEmployeeId
// * @return
// */
// private List<AddUpDeduction> getLastListByModifier(Long currentEmployeeId) {
// List<AddUpDeductionPO> list = new LambdaQueryChainWrapper<>(getAddUpDeductionMapper())
// .eq(AddUpDeductionPO::getDeleteType, 0)
// .eq(AddUpDeductionPO::getTenantKey)
// .eq(AddUpDeductionPO::getModifier, currentEmployeeId)
// .orderByDesc(AddUpDeductionPO::getDeclareMonth)
// .list();
// return list.stream()
// .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))), ArrayList::new));
// }
@Override
public PageInfo<AddUpDeductionDTO> listPage(AddUpDeductionQueryParam queryParam) {
long employeeId = (long) user.getUID();
// 未开启分权或是薪酬模块总管理员
if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpDeductionDTO> list = getAddUpDeductionMapper().list(queryParam);
return new PageInfo<>(list, AddUpDeductionDTO.class);
} else {
List<TaxAgentEmployeeDTO> taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpDeductionPO> lastList = getLastListByModifier(employeeId);
List<AddUpDeductionDTO> list = getAddUpDeductionMapper().list(queryParam);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l -> l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getDeclareMonth().isBefore(f.getDeclareMonth()))
).collect(Collectors.toList());
// 填充总数和当页数据
// 分页参数
PageInfo<AddUpDeductionDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), AddUpDeductionDTO.class);
dtoPage.setTotal(list.size());
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), list));
return dtoPage;
}
}
@Override
public PageInfo<AddUpDeductionRecordDTO> recordListPage(AddUpDeductionQueryParam queryParam) {
long employeeId = (long) user.getUID();
// 未开启分权或是薪酬模块总管理员
if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpDeductionRecordDTO> list = getAddUpDeductionMapper().recordList(queryParam);
return new PageInfo<>(list, AddUpDeductionRecordDTO.class);
} else {
List<TaxAgentEmployeeDTO> taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpDeductionPO> lastList = getLastListByModifier(employeeId, tenantKey);
List<AddUpDeductionRecordDTO> list = getAddUpDeductionMapper().recordList(queryParam);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l -> l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getDeclareMonth().isBefore(f.getDeclareMonth()))
).collect(Collectors.toList());
// 分页参数
// 填充总数和当页数据
PageInfo<AddUpDeductionRecordDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), AddUpDeductionRecordDTO.class);
dtoPage.setTotal(list.size());
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), list));
return dtoPage;
}
}
/**
* 导出详情列表
*
* @return
*/
public XSSFWorkbook exportDetail(Long beLongEmployeeId, boolean isChief, AddUpDeductionQueryParam queryParam) {
queryParam.setEmployeeId(beLongEmployeeId);
EmployBiz employBiz = new EmployBiz();
AddUpDeductionBiz biz = new AddUpDeductionBiz();
Long id = queryParam.getAccumulatedSpecialAdditionalDeductionId();
if (id == null) {
throw new SalaryRunTimeException("id不能为空");
}
AddUpDeduction 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("员工信息不存在");
}
//查询参数
queryParam.setEmployeeId(po.getEmployeeId());
//申报月份
List<String> declareMonth = queryParam.getDeclareMonth();
if (CollectionUtils.isNotEmpty(declareMonth)) {
queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
}
//获取操作按钮资源
List<List<String>> rowList = getExcelRowDetailList(isChief, queryParam);
//获取excel
return ExcelUtil.genWorkbook(rowList, "累计专项附加扣除明细");
}
/**
* 导出详情
*
* @param param
* @return
*/
private List<List<String>> getExcelRowDetailList(boolean isChief, AddUpDeductionQueryParam param) {
long employeeId = user.getUID();
//excel标题
List<String> title = Arrays.asList("姓名", "申报月份", "个税扣缴义务人", "部门", "工号", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人", "累计大病医疗", "累计婴幼儿照护");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
//查询详细信息
List<AddUpDeductionRecordDTO> list = new AddUpDeductionBiz().recordList(param);
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.getDeclareMonth() == null ? "" : formatter.format(dto.getDeclareMonth())));
cellList.add(Util.null2String(dto.getTaxAgentName()));
cellList.add(Util.null2String(dto.getDepartmentName()));
cellList.add(Util.null2String(dto.getJobNum()));
cellList.add(Util.null2String(dto.getAddUpChildEducation()));
cellList.add(Util.null2String(dto.getAddUpContinuingEducation()));
cellList.add(Util.null2String(dto.getAddUpHousingLoanInterest()));
cellList.add(Util.null2String(dto.getAddUpHousingRent()));
cellList.add(Util.null2String(dto.getAddUpSupportElderly()));
cellList.add(Util.null2String(dto.getAddUpIllnessMedical()));
cellList.add(Util.null2String(dto.getAddUpInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
// 开启分权并且不是薪酬模块总管理员
if (getTaxAgentV2Service(user).isOpenDevolution() && !isChief) {
List<TaxAgentEmployeeDTO> taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpDeduction> lastList = getLastListByModifier(employeeId, tenantKey);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// 作为分管理员
|| TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l -> l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getDeclareMonth().isBefore(f.getDeclareMonth()))
).collect(Collectors.toList());
}
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
}
@Override
public List<AddUpDeduction> getAddUpDeductionList(YearMonth declareMonth, List<Long> employeeIds) {
AddUpDeductionBiz addUpDeductionBiz = new AddUpDeductionBiz();
if (declareMonth == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100342, "参数有误申报月份、租户key必传"));
}
return addUpDeductionBiz.listSome(AddUpDeduction.builder().declareMonth(SalaryDateUtil.toDateStartOfMonth(declareMonth)).employeeIds(employeeIds).build());
}
@Override
public XSSFWorkbook downloadTemplate(boolean isChief, AddUpDeductionQueryParam queryParam) {
String sheetName = SalaryI18nUtil.getI18nLabel(101603, "累计专项附加扣除导入模板");
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(86321, "累计子女教育"),
SalaryI18nUtil.getI18nLabel(86323, "累计继续教育"),
SalaryI18nUtil.getI18nLabel(86324, "累计住房贷款利息"),
SalaryI18nUtil.getI18nLabel(86325, "累计住房租金"),
SalaryI18nUtil.getI18nLabel(86326, "累计赡养老人"),
SalaryI18nUtil.getI18nLabel(105142, "累计大病医疗"),
SalaryI18nUtil.getI18nLabel(105142, "累计婴幼儿照护")
};
List<Object> headerList = Arrays.asList(header);
List<List<Object>> rows = new ArrayList<>();
rows.add(headerList);
// // 2.表头
// if (queryParam.getDeclareMonth() != null) {
// queryParam.setDeclareMonth(queryParam.getDeclareMonth().stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
// }
// // 获取累计专项附加扣除
// List<AddUpDeductionDTO> list = getAddUpDeductionMapper().list(queryParam);
// // 人员信息赋值
// list.forEach(m -> {
// // todo 身份证号
// m.setIdNo("");
// });
//
// for (AddUpDeductionDTO dto : list) {
// List<Object> row = new ArrayList<>();
// row.add(Util.null2String(dto.getUsername()));
// row.add(Util.null2String(dto.getTaxAgentName()));
// row.add(Util.null2String(dto.getDepartmentName()));
// row.add(Util.null2String(dto.getMobile()));
// row.add(Util.null2String(dto.getJobNum()));
// row.add(Util.null2String(dto.getIdNo()));
// row.add(Util.null2String(dto.getHiredate()));
// row.add(Util.null2String(dto.getAddUpChildEducation()));
// row.add(Util.null2String(dto.getAddUpContinuingEducation()));
// row.add(Util.null2String(dto.getAddUpHousingLoanInterest()));
// row.add(Util.null2String(dto.getAddUpHousingRent()));
// row.add(Util.null2String(dto.getAddUpSupportElderly()));
// row.add(Util.null2String(dto.getAddUpIllnessMedical()));
// row.add(Util.null2String(dto.getAddUpInfantCare()));
// rows.add(row);
// }
// 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, "输入数字")));
excelComments.add(new ExcelComment(11, 0, 14, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(12, 0, 15, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(13, 0, 16, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments);
return book;
}
@Override
public XSSFWorkbook export(boolean isChief, AddUpDeductionQueryParam queryParam) {
//获取操作按钮资源
List<List<String>> rowList = getExcelRowList(isChief, queryParam);
//获取excel
return ExcelUtil.genWorkbook(rowList, "累计专项附加扣除");
}
/**
* 获取excel数据行
*
* @return 导出数据行集合
*/
private List<List<String>> getExcelRowList(boolean isChief, AddUpDeductionQueryParam param) {
Long employeeId = (long) user.getUID();
//excel标题
List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人", "累计大病医疗", "累计婴幼儿照护");
List<AddUpDeductionDTO> list = new AddUpDeductionBiz().list(param);
// 开启分权并且不是薪酬模块总管理员
if (getTaxAgentV2Service(user).isOpenDevolution() && !isChief) {
List<TaxAgentEmployeeDTO> taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpDeductionPO> lastList = getLastListByModifier(employeeId);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// 作为分管理员
|| TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l->l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getDeclareMonth().isBefore(f.getDeclareMonth()))
).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.getAddUpChildEducation()));
cellList.add(Util.null2String(dto.getAddUpContinuingEducation()));
cellList.add(Util.null2String(dto.getAddUpHousingLoanInterest()));
cellList.add(Util.null2String(dto.getAddUpHousingRent()));
cellList.add(Util.null2String(dto.getAddUpSupportElderly()));
cellList.add(Util.null2String(dto.getAddUpIllnessMedical()));
cellList.add(Util.null2String(dto.getAddUpInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
}
/**
* 根据年月获取已核算数据
*
* @param yearMonth
* @return
*/
@Override
public List<SalaryAcctEmployeePO> getAccountedEmployeeData(String yearMonth) {
List<SalaryAcctEmployeePO> list = Lists.newArrayList();
LocalDate salaryMonthDate = LocalDate.parse(yearMonth + "-01", SalaryDateUtil.DATE_FORMATTER);
List<SalaryAcctRecordPO> salaryAcctRecords = getSalaryAcctRecordService(user).listBySalaryMonth(LocalDateRange.builder().fromDate(SalaryDateUtil.localDateToDate(salaryMonthDate)).endDate(SalaryDateUtil.localDateToDate(salaryMonthDate)).build());
salaryAcctRecords.forEach(e -> {
boolean isAccounted = e.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue();
if (isAccounted) {
list.addAll(getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIds(Collections.singleton(salaryAcctRecords.get(0).getId())));
}
});
return list;
}
}