2022-03-10 17:57:46 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2022-09-21 13:38:06 +08:00
|
|
|
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
2022-05-31 11:21:51 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
2022-03-10 17:57:46 +08:00
|
|
|
import com.engine.core.impl.Service;
|
2022-05-09 14:11:07 +08:00
|
|
|
import com.engine.salary.biz.EmployBiz;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.biz.OtherDeductionBiz;
|
2022-06-10 18:07:25 +08:00
|
|
|
import com.engine.salary.encrypt.datacollection.OtherDeductionListDTOEncrypt;
|
|
|
|
|
import com.engine.salary.encrypt.datacollection.OtherDeductionRecordDTOEncrypt;
|
2022-05-09 14:11:07 +08:00
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
2022-04-28 17:44:26 +08:00
|
|
|
import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO;
|
2022-05-31 09:58:35 +08:00
|
|
|
import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO;
|
2022-10-28 16:35:51 +08:00
|
|
|
import com.engine.salary.entity.datacollection.param.*;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
|
2022-05-31 09:58:35 +08:00
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
|
|
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
|
|
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
|
|
|
|
import com.engine.salary.enums.UserStatusEnum;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2022-04-28 17:44:26 +08:00
|
|
|
import com.engine.salary.mapper.datacollection.OtherDeductionMapper;
|
2022-09-21 13:38:06 +08:00
|
|
|
import com.engine.salary.mapper.sys.SalarySysConfMapper;
|
2022-10-26 18:35:23 +08:00
|
|
|
import com.engine.salary.service.AddUpDeductionService;
|
|
|
|
|
import com.engine.salary.service.OtherDeductionService;
|
|
|
|
|
import com.engine.salary.service.SalaryEmployeeService;
|
|
|
|
|
import com.engine.salary.service.TaxAgentService;
|
2022-09-21 13:38:06 +08:00
|
|
|
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
2022-09-26 18:51:17 +08:00
|
|
|
import com.engine.salary.sys.entity.vo.OrderRuleVO;
|
|
|
|
|
import com.engine.salary.sys.service.SalarySysConfService;
|
|
|
|
|
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
2022-10-28 16:35:51 +08:00
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2022-04-28 17:44:26 +08:00
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
|
|
|
import com.engine.salary.util.excel.ExcelComment;
|
2022-05-31 09:58:35 +08:00
|
|
|
import com.engine.salary.util.excel.ExcelParseHelper;
|
2022-04-28 17:44:26 +08:00
|
|
|
import com.engine.salary.util.excel.ExcelUtil;
|
2022-05-31 09:58:35 +08:00
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2022-04-28 17:44:26 +08:00
|
|
|
import com.google.common.collect.Lists;
|
2022-05-31 09:58:35 +08:00
|
|
|
import com.google.common.collect.Maps;
|
2022-05-09 14:11:07 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-05-31 09:58:35 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
2022-03-10 17:57:46 +08:00
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
2022-05-31 09:58:35 +08:00
|
|
|
import weaver.file.ImageFileManager;
|
2022-05-20 14:41:42 +08:00
|
|
|
import weaver.general.Util;
|
2022-05-31 11:21:51 +08:00
|
|
|
import weaver.hrm.User;
|
2022-03-10 17:57:46 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2022-04-11 20:17:47 +08:00
|
|
|
import java.time.YearMonth;
|
2022-05-09 14:11:07 +08:00
|
|
|
import java.util.*;
|
2022-04-28 17:44:26 +08:00
|
|
|
import java.util.stream.Collectors;
|
2022-03-10 17:57:46 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
|
|
|
|
|
|
2022-03-10 17:57:46 +08:00
|
|
|
public class OtherDeductionServiceImpl extends Service implements OtherDeductionService {
|
|
|
|
|
|
2022-04-28 17:44:26 +08:00
|
|
|
private OtherDeductionMapper getOtherDeductionMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(OtherDeductionMapper.class);
|
|
|
|
|
}
|
2022-06-09 17:45:28 +08:00
|
|
|
|
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
2022-05-31 21:05:59 +08:00
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
2022-05-31 11:21:51 +08:00
|
|
|
}
|
2022-06-09 17:45:28 +08:00
|
|
|
|
2022-05-31 11:21:51 +08:00
|
|
|
private AddUpDeductionService getAddUpDeductionService(User user) {
|
|
|
|
|
return ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
|
|
|
|
|
}
|
2022-06-09 17:45:28 +08:00
|
|
|
|
2022-05-31 11:21:51 +08:00
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
}
|
2022-05-31 09:58:35 +08:00
|
|
|
|
2022-09-21 13:38:06 +08:00
|
|
|
private SalarySysConfMapper getSalarySysConfMapper() {
|
|
|
|
|
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 18:51:17 +08:00
|
|
|
private SalarySysConfService getSalarySysConfService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
|
|
|
|
|
}
|
2022-09-21 13:38:06 +08:00
|
|
|
|
2022-03-10 17:57:46 +08:00
|
|
|
@Override
|
2022-05-31 09:58:35 +08:00
|
|
|
public OtherDeductionPO getById(Long id) {
|
|
|
|
|
return getOtherDeductionMapper().getById(id);
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
|
2022-03-10 17:57:46 +08:00
|
|
|
@Override
|
2022-05-31 09:58:35 +08:00
|
|
|
public PageInfo<OtherDeductionListDTO> listPage(OtherDeductionQueryParam queryParam) {
|
2022-06-07 19:10:40 +08:00
|
|
|
//申报月份
|
|
|
|
|
List<String> declareMonth = queryParam.getDeclareMonth();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(declareMonth)) {
|
|
|
|
|
queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
|
2022-06-24 18:05:08 +08:00
|
|
|
queryParam.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
|
2022-06-07 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 18:51:17 +08:00
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
queryParam.setOrderRule(orderRule);
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
long employeeId = user.getUID();
|
|
|
|
|
|
2022-06-09 17:45:28 +08:00
|
|
|
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
|
|
|
|
|
if (needAuth) {
|
|
|
|
|
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentIdsAsAdmin)) {
|
|
|
|
|
return new PageInfo<>(OtherDeductionListDTO.class);
|
|
|
|
|
}
|
|
|
|
|
queryParam.setTaxAgentIds(taxAgentIdsAsAdmin);
|
2022-05-31 09:58:35 +08:00
|
|
|
}
|
2022-06-09 17:45:28 +08:00
|
|
|
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
|
|
|
|
|
List<OtherDeductionListDTO> list = getOtherDeductionMapper().list(queryParam);
|
2022-06-10 18:07:25 +08:00
|
|
|
OtherDeductionListDTOEncrypt.decryptOtherDeductionListDTOList(list);
|
2022-06-09 17:45:28 +08:00
|
|
|
return new PageInfo<>(list, OtherDeductionListDTO.class);
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-31 09:58:35 +08:00
|
|
|
public PageInfo<OtherDeductionRecordDTO> recordListPage(OtherDeductionQueryParam queryParam) {
|
|
|
|
|
long employeeId = user.getUID();
|
|
|
|
|
|
2022-06-24 18:05:08 +08:00
|
|
|
//申报月份
|
|
|
|
|
List<String> declareMonth = queryParam.getDeclareMonth();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(declareMonth)) {
|
|
|
|
|
queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
|
|
|
|
|
queryParam.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 17:45:28 +08:00
|
|
|
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
|
|
|
|
|
if (needAuth) {
|
|
|
|
|
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentIdsAsAdmin)) {
|
|
|
|
|
return new PageInfo<>(OtherDeductionRecordDTO.class);
|
|
|
|
|
}
|
|
|
|
|
queryParam.setTaxAgentIds(taxAgentIdsAsAdmin);
|
2022-05-31 09:58:35 +08:00
|
|
|
}
|
2022-06-09 17:45:28 +08:00
|
|
|
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
|
|
|
|
|
List<OtherDeductionRecordDTO> list = getOtherDeductionMapper().recordList(queryParam);
|
2022-06-10 18:07:25 +08:00
|
|
|
OtherDeductionRecordDTOEncrypt.decryptOtherDeductionRecordDTOList(list);
|
2022-06-09 17:45:28 +08:00
|
|
|
return new PageInfo<>(list, OtherDeductionRecordDTO.class);
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
|
2022-03-10 17:57:46 +08:00
|
|
|
@Override
|
2022-05-31 11:21:51 +08:00
|
|
|
public Map<String, Object> preview(OtherDeductionImportParam importParam) {
|
2022-05-31 09:58:35 +08:00
|
|
|
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<OtherDeductionListDTO> OtherDeductions = ExcelParseHelper.parse2Map(fileInputStream, OtherDeductionListDTO.class, 0, 1, 11, "OtherDeductionTemplate.xlsx");
|
|
|
|
|
apidatas.put("preview", OtherDeductions);
|
|
|
|
|
} finally {
|
|
|
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
|
|
|
}
|
|
|
|
|
return apidatas;
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-09 14:11:07 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
public Map<String, Object> importData(OtherDeductionImportParam importParam) {
|
2022-06-09 17:45:28 +08:00
|
|
|
|
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
Map<String, Object> apidatas = new HashMap<String, Object>();
|
|
|
|
|
EmployBiz employBiz = new EmployBiz();
|
2022-05-09 14:11:07 +08:00
|
|
|
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
|
|
|
|
|
|
2022-09-21 13:38:06 +08:00
|
|
|
//查询对于人员信息导入筛选的全局配置
|
|
|
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
|
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
//检验参数
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
InputStream fileInputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
|
|
|
|
|
List<OtherDeductionListDTO> OtherDeductions = ExcelParseHelper.parse2Map(fileInputStream, OtherDeductionListDTO.class, 0, 1, 11, "OtherDeductionTemplate.xlsx");
|
|
|
|
|
|
|
|
|
|
int total = OtherDeductions.size();
|
|
|
|
|
int index = 0;
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
int errorCount = 0;
|
|
|
|
|
|
|
|
|
|
//人员信息
|
|
|
|
|
List<DataCollectionEmployee> employees = employBiz.listEmployee();
|
|
|
|
|
// 获取所有个税扣缴义务人
|
2022-06-09 17:45:28 +08:00
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
2022-05-31 09:58:35 +08:00
|
|
|
//税款所属期
|
|
|
|
|
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
|
|
|
|
|
// 获取已经核算的数据
|
2022-05-31 11:21:51 +08:00
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
|
2022-05-31 09:58:35 +08:00
|
|
|
// 查询已有数据
|
2022-05-31 11:21:51 +08:00
|
|
|
List<OtherDeductionPO> list = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().declareMonth(declareMonth).build());
|
2022-05-31 09:58:35 +08:00
|
|
|
|
|
|
|
|
// 错误excel内容
|
|
|
|
|
List<Map> errorData = new ArrayList<>();
|
|
|
|
|
//合规数据
|
|
|
|
|
List<OtherDeductionPO> eligibleData = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = Lists.newArrayList();
|
|
|
|
|
for (int i = 0; i < OtherDeductions.size(); i++) {
|
|
|
|
|
OtherDeductionListDTO dto = OtherDeductions.get(i);
|
|
|
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
//待插入数据库对象
|
|
|
|
|
OtherDeductionPO po = OtherDeductionPO.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();
|
2022-08-25 11:43:52 +08:00
|
|
|
String mobile = dto.getMobile();
|
2022-09-21 13:38:06 +08:00
|
|
|
String workcode = dto.getJobNum();
|
2022-05-31 09:58:35 +08:00
|
|
|
List<Long> employeeSameIds = new ArrayList<>();
|
|
|
|
|
|
2022-09-21 13:38:06 +08:00
|
|
|
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
|
2022-09-21 15:49:55 +08:00
|
|
|
List<DataCollectionEmployee> emps = getSalaryEmployeeService(user).matchImportEmployee(employees, userName, deparmentName, mobile, workcode, null);
|
2022-05-31 09:58:35 +08:00
|
|
|
//含在职和离职,选在职数据
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 13:57:58 +08:00
|
|
|
//当人员信息导入筛选的全局配置为"0"时,姓名才是必填项
|
2022-09-21 13:38:06 +08:00
|
|
|
if (StringUtils.isBlank(userName) && "0".equals(confValue)) {
|
2022-05-31 09:58:35 +08:00
|
|
|
//姓名 不能为空
|
|
|
|
|
//错误消息对象
|
|
|
|
|
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();
|
2022-09-16 15:03:48 +08:00
|
|
|
errorMessageMap.put("message", rowIndex + "员工信息不存在或者存在多个员工");
|
2022-05-31 09:58:35 +08:00
|
|
|
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 = 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<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 = Maps.newHashMap();
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "个税扣缴义务人与导入时选择的不一致");
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
} else {
|
|
|
|
|
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
|
|
|
|
|
taxAgentEmployees = optionalTemp.get().getEmployeeList();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//个税扣缴义务人不存在
|
|
|
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
2022-06-21 22:37:22 +08:00
|
|
|
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在或不在权限范围内");
|
2022-05-31 09:58:35 +08:00
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//商业健康保险
|
|
|
|
|
String businessHealthyInsurance = dto.getBusinessHealthyInsurance();
|
|
|
|
|
po.setBusinessHealthyInsurance(businessHealthyInsurance);
|
|
|
|
|
//税延养老保险
|
|
|
|
|
String taxDelayEndowmentInsurance = dto.getTaxDelayEndowmentInsurance();
|
|
|
|
|
po.setTaxDelayEndowmentInsurance(taxDelayEndowmentInsurance);
|
|
|
|
|
//其他
|
|
|
|
|
String otherDeduction = dto.getOtherDeduction();
|
|
|
|
|
po.setOtherDeduction(otherDeduction);
|
|
|
|
|
//准予扣除的捐赠额
|
|
|
|
|
String deductionAllowedDonation = dto.getDeductionAllowedDonation();
|
|
|
|
|
po.setDeductionAllowedDonation(deductionAllowedDonation);
|
|
|
|
|
|
|
|
|
|
|
2022-08-25 16:46:12 +08:00
|
|
|
//fixme 分权判断
|
|
|
|
|
// if (openDevolution) {
|
|
|
|
|
// OtherDeductionPO finalPoE = po;
|
|
|
|
|
// Optional<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> optionalTaxAgentEmp = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPoE.getEmployeeId())).findFirst();
|
|
|
|
|
// if (!optionalTaxAgentEmp.isPresent()) {
|
|
|
|
|
// Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
|
|
|
// errorMessageMap.put("message", rowIndex + "该条数据不在个税扣缴义务人人员范围内,不可导入");
|
|
|
|
|
// errorData.add(errorMessageMap);
|
|
|
|
|
// errorSum += 1;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2022-05-31 09:58:35 +08:00
|
|
|
// 判断是否有核算过
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
|
|
|
|
|
OtherDeductionPO finalPo = po;
|
|
|
|
|
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId())).findFirst();
|
|
|
|
|
boolean isExist = list.stream().anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
|
|
|
|
|
if (optionalAcctEmp.isPresent() && isExist) {
|
|
|
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "该年月这条数据已经核算过,不可导入");
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (errorSum == 0) {
|
|
|
|
|
successCount += 1;
|
|
|
|
|
// 合格数据
|
|
|
|
|
eligibleData.add(po);
|
|
|
|
|
} else {
|
|
|
|
|
errorCount += 1;
|
|
|
|
|
// 添加错误数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//入库
|
|
|
|
|
OtherDeductionBiz.handleImportData(eligibleData);
|
|
|
|
|
|
|
|
|
|
apidatas.put("successCount", successCount);
|
|
|
|
|
apidatas.put("errorCount", errorCount);
|
|
|
|
|
apidatas.put("errorData", errorData);
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
|
|
|
}
|
|
|
|
|
return apidatas;
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
private void checkImportParam(OtherDeductionImportParam importParam) {
|
|
|
|
|
//excel文件id
|
|
|
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
|
|
|
//税款所属期
|
|
|
|
|
String declareMonthStr = Util.null2String(importParam.getDeclareMonth());
|
|
|
|
|
//个税扣缴义务人
|
|
|
|
|
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
|
2022-03-10 17:57:46 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
if (StringUtils.isBlank(imageId)) {
|
|
|
|
|
throw new SalaryRunTimeException("文件不存在");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(declareMonthStr)) {
|
|
|
|
|
throw new SalaryRunTimeException("税款所属期为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 11:21:51 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
/**
|
|
|
|
|
* 导出
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public XSSFWorkbook export(OtherDeductionQueryParam param) {
|
|
|
|
|
|
|
|
|
|
//获取操作按钮资源
|
|
|
|
|
List<List<String>> rowList = getExcelRowList(param);
|
|
|
|
|
|
|
|
|
|
//获取excel
|
2022-06-09 17:45:28 +08:00
|
|
|
return ExcelUtil.genWorkbook(rowList, "其他免税扣除");
|
2022-05-31 09:58:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取excel数据行
|
|
|
|
|
*
|
|
|
|
|
* @return 导出数据行集合
|
|
|
|
|
*/
|
|
|
|
|
private List<List<String>> getExcelRowList(OtherDeductionQueryParam param) {
|
|
|
|
|
long employeeId = user.getUID();
|
|
|
|
|
//excel标题
|
|
|
|
|
List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "商业健康保险", "税延养老保险", "其他", "准予扣除的捐赠额");
|
2022-09-26 18:51:17 +08:00
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
param.setOrderRule(orderRule);
|
2022-05-31 09:58:35 +08:00
|
|
|
|
2022-09-23 16:08:41 +08:00
|
|
|
//申报月份
|
|
|
|
|
List<String> declareMonth = param.getDeclareMonth();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(declareMonth)) {
|
|
|
|
|
param.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
|
|
|
|
|
param.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
List<OtherDeductionListDTO> list = getOtherDeductionMapper().list(param);
|
2022-06-23 14:08:55 +08:00
|
|
|
OtherDeductionListDTOEncrypt.decryptOtherDeductionListDTOList(list);
|
2022-05-31 09:58:35 +08:00
|
|
|
// 开启分权并且不是薪酬模块总管理员
|
2022-06-09 17:45:28 +08:00
|
|
|
if (getTaxAgentService(user).isOpenDevolution() && !getTaxAgentService(user).isChief(employeeId)) {
|
|
|
|
|
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
|
2022-05-31 09:58:35 +08:00
|
|
|
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.getBusinessHealthyInsurance()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getTaxDelayEndowmentInsurance()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getOtherDeduction()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getDeductionAllowedDonation()));
|
|
|
|
|
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(OtherDeductionQueryParam param) {
|
2022-05-09 14:11:07 +08:00
|
|
|
|
|
|
|
|
OtherDeductionBiz biz = new OtherDeductionBiz();
|
|
|
|
|
EmployBiz employBiz = new EmployBiz();
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
Long id = param.getOtherTaxExemptDeductionId();
|
2022-05-09 14:11:07 +08:00
|
|
|
if (id == null) {
|
|
|
|
|
throw new SalaryRunTimeException("id不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OtherDeductionPO po = biz.getById(id);
|
|
|
|
|
if (po == null) {
|
2022-05-31 09:58:35 +08:00
|
|
|
throw new SalaryRunTimeException(String.format("其他免税扣除不存在" + "[id:%s]", id));
|
2022-05-09 14:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()));
|
|
|
|
|
if (CollectionUtils.isEmpty(employeeList)) {
|
|
|
|
|
throw new SalaryRunTimeException("员工信息不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//构建参数
|
2022-05-31 09:58:35 +08:00
|
|
|
param.setEmployeeId(po.getEmployeeId());
|
2022-05-09 14:11:07 +08:00
|
|
|
//申报月份
|
2022-05-31 09:58:35 +08:00
|
|
|
List<String> declareMonth = param.getDeclareMonth();
|
2022-05-09 14:11:07 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(declareMonth)) {
|
2022-05-31 09:58:35 +08:00
|
|
|
param.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
|
2022-06-24 18:05:08 +08:00
|
|
|
param.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
|
2022-05-09 14:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
//获取操作按钮资源
|
|
|
|
|
List<List<String>> rowList = getExcelRowDetailList(param);
|
2022-05-09 14:11:07 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
//获取excel
|
2022-06-09 17:45:28 +08:00
|
|
|
return ExcelUtil.genWorkbook(rowList, "其他免税扣除明细");
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
/**
|
|
|
|
|
* 导出详情
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<List<String>> getExcelRowDetailList(OtherDeductionQueryParam param) {
|
|
|
|
|
//excel标题
|
|
|
|
|
List<String> title = Arrays.asList("姓名", "申报月份", "个税扣缴义务人", "部门", "手机号", "工号", "商业健康保险", "税延养老保险", "其他", "准予扣除的捐赠额");
|
2022-03-10 17:57:46 +08:00
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
|
|
|
|
|
//查询详细信息
|
|
|
|
|
List<OtherDeductionRecordDTO> list = getOtherDeductionMapper().recordList(param);
|
2022-06-23 14:08:55 +08:00
|
|
|
OtherDeductionRecordDTOEncrypt.decryptOtherDeductionRecordDTOList(list);
|
2022-05-31 09:58:35 +08:00
|
|
|
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.getMobile()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getJobNum()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getBusinessHealthyInsurance()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getTaxDelayEndowmentInsurance()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getOtherDeduction()));
|
|
|
|
|
cellList.add(Util.null2String(dto.getDeductionAllowedDonation()));
|
|
|
|
|
return cellList;
|
|
|
|
|
}).collect(Collectors.toList()))
|
|
|
|
|
.orElse(Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
List<List<String>> rowList = new ArrayList<>();
|
|
|
|
|
rowList.add(title);
|
|
|
|
|
rowList.addAll(dataRowList);
|
|
|
|
|
return rowList;
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:58:35 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
@Override
|
2022-06-29 17:38:00 +08:00
|
|
|
public List<OtherDeductionPO> getOtherDeductionList(YearMonth declareMonth, List<Long> employeeIds, Long taxAgentId) {
|
2022-04-11 20:17:47 +08:00
|
|
|
if (declareMonth == null) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100342, "参数有误:申报月份必传"));
|
|
|
|
|
}
|
|
|
|
|
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
|
2022-06-29 17:38:00 +08:00
|
|
|
return OtherDeductionBiz.listSome(OtherDeductionPO.builder().declareMonth(SalaryDateUtil.toDateStartOfMonth(declareMonth)).employeeIds(employeeIds).taxAgentId(taxAgentId).build());
|
2022-04-11 20:17:47 +08:00
|
|
|
}
|
2022-04-28 17:44:26 +08:00
|
|
|
|
2022-10-26 18:35:23 +08:00
|
|
|
@Override
|
|
|
|
|
public void editData(OtherDeductionParam otherDeductionParam) {
|
|
|
|
|
String declareMonthStr = otherDeductionParam.getDeclareMonth();
|
|
|
|
|
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
|
2022-10-28 14:08:27 +08:00
|
|
|
|
|
|
|
|
Long currentEmployeeId = (long) user.getUID();
|
|
|
|
|
// 获取所有个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
|
|
|
OtherDeductionPO byId = OtherDeductionBiz.getById(otherDeductionParam.getId());
|
|
|
|
|
if(byId == null){
|
|
|
|
|
throw new SalaryRunTimeException("该数据不存在!");
|
|
|
|
|
}
|
|
|
|
|
Long taxAgentId = byId.getTaxAgentId();
|
|
|
|
|
boolean canEdit = taxAgentList.stream().anyMatch(t -> t.getTaxAgentId() == taxAgentId);
|
|
|
|
|
if(!canEdit){
|
|
|
|
|
//没有编辑权限
|
|
|
|
|
throw new SalaryRunTimeException("该个税扣缴义务人无权限编辑此数据!");
|
|
|
|
|
}
|
2022-10-26 18:35:23 +08:00
|
|
|
// 获取已经核算的数据
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
|
|
|
|
|
// 判断是否有核算过
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
|
|
|
|
|
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(otherDeductionParam.getEmployeeId()) && f.getTaxAgentId().equals(otherDeductionParam.getTaxAgentId())).findFirst();
|
|
|
|
|
if (optionalAcctEmp.isPresent()) {
|
|
|
|
|
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可进行编辑!");
|
2022-10-28 14:08:27 +08:00
|
|
|
}
|
2022-10-26 18:35:23 +08:00
|
|
|
}
|
2022-10-28 14:08:27 +08:00
|
|
|
ArrayList<OtherDeductionPO> updateList = new ArrayList<>();
|
|
|
|
|
OtherDeductionPO build = OtherDeductionPO.builder().id(otherDeductionParam.getId()).businessHealthyInsurance(otherDeductionParam.getBusinessHealthyInsurance()).taxDelayEndowmentInsurance(otherDeductionParam.getTaxDelayEndowmentInsurance()).otherDeduction(otherDeductionParam.getOtherDeduction()).deductionAllowedDonation(otherDeductionParam.getDeductionAllowedDonation()).build();
|
|
|
|
|
updateList.add(build);
|
|
|
|
|
OtherDeductionBiz.batchUpdate(updateList);
|
2022-10-26 18:35:23 +08:00
|
|
|
}
|
|
|
|
|
|
2022-10-27 18:02:05 +08:00
|
|
|
@Override
|
|
|
|
|
public void createData(OtherDeductionParam otherDeductionParam) {
|
|
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
|
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
|
|
|
|
|
EmployBiz employBiz = new EmployBiz();
|
|
|
|
|
//查询对于人员信息导入筛选的全局配置
|
|
|
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
|
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
|
|
|
|
|
|
//税款所属期
|
|
|
|
|
String declareMonthStr = Util.null2String(otherDeductionParam.getDeclareMonth());
|
|
|
|
|
//人员信息
|
|
|
|
|
List<DataCollectionEmployee> employees = employBiz.listEmployee();
|
|
|
|
|
// 获取所有个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
|
|
|
//税款所属期
|
|
|
|
|
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
|
|
|
|
|
// 获取已经核算的数据
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
|
|
|
|
|
// 查询已有数据
|
|
|
|
|
List<OtherDeductionPO> list = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().declareMonth(declareMonth).build());
|
|
|
|
|
//合规数据
|
|
|
|
|
List<OtherDeductionPO> insertData = new ArrayList<>();
|
|
|
|
|
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = Lists.newArrayList();
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
//待插入数据库对象
|
|
|
|
|
OtherDeductionPO po = OtherDeductionPO.builder()
|
|
|
|
|
.tenantKey(DEFAULT_TENANT_KEY)
|
|
|
|
|
.createTime(now)
|
|
|
|
|
.updateTime(now)
|
|
|
|
|
.creator((long) user.getUID())
|
|
|
|
|
.declareMonth(declareMonth).build();
|
|
|
|
|
|
|
|
|
|
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
|
|
|
|
|
boolean employeeSameId = employees.stream().anyMatch(e -> e.getEmployeeId() == otherDeductionParam.getEmployeeId());
|
|
|
|
|
if(!employeeSameId){
|
|
|
|
|
throw new SalaryRunTimeException("员工信息不存在");
|
|
|
|
|
}
|
|
|
|
|
po.setEmployeeId(otherDeductionParam.getEmployeeId());
|
|
|
|
|
String taxAgentName = otherDeductionParam.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());
|
|
|
|
|
taxAgentEmployees = optionalTemp.get().getEmployeeList();
|
|
|
|
|
} else {
|
|
|
|
|
//个税扣缴义务人不存在或不在权限范围内
|
|
|
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//商业健康保险
|
|
|
|
|
String businessHealthyInsurance = otherDeductionParam.getBusinessHealthyInsurance();
|
|
|
|
|
po.setBusinessHealthyInsurance(businessHealthyInsurance);
|
|
|
|
|
//税延养老保险
|
|
|
|
|
String taxDelayEndowmentInsurance = otherDeductionParam.getTaxDelayEndowmentInsurance();
|
|
|
|
|
po.setTaxDelayEndowmentInsurance(taxDelayEndowmentInsurance);
|
|
|
|
|
//其他
|
|
|
|
|
String otherDeduction = otherDeductionParam.getOtherDeduction();
|
|
|
|
|
po.setOtherDeduction(otherDeduction);
|
|
|
|
|
//准予扣除的捐赠额
|
|
|
|
|
String deductionAllowedDonation = otherDeductionParam.getDeductionAllowedDonation();
|
|
|
|
|
po.setDeductionAllowedDonation(deductionAllowedDonation);
|
|
|
|
|
|
|
|
|
|
//fixme 分权判断
|
|
|
|
|
// if (openDevolution) {
|
|
|
|
|
// OtherDeductionPO finalPoE = po;
|
|
|
|
|
// Optional<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> optionalTaxAgentEmp = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPoE.getEmployeeId())).findFirst();
|
|
|
|
|
// if (!optionalTaxAgentEmp.isPresent()) {
|
|
|
|
|
// Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
|
|
|
// errorMessageMap.put("message", rowIndex + "该条数据不在个税扣缴义务人人员范围内,不可导入");
|
|
|
|
|
// errorData.add(errorMessageMap);
|
|
|
|
|
// errorSum += 1;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 判断是否有核算过
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
|
|
|
|
|
OtherDeductionPO finalPo = po;
|
|
|
|
|
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId())).findFirst();
|
|
|
|
|
boolean isExist = list.stream().anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
|
|
|
|
|
if (optionalAcctEmp.isPresent() && isExist) {
|
|
|
|
|
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可导入");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
insertData.add(po);
|
|
|
|
|
//入库
|
|
|
|
|
OtherDeductionBiz.handleImportData(insertData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteSelectData(AddUpDeductionRecordDeleteParam deleteParam) {
|
|
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
// 获取所有个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
2022-10-28 14:08:27 +08:00
|
|
|
OtherDeductionBiz otherDeductionBiz = new OtherDeductionBiz();
|
2022-10-27 18:02:05 +08:00
|
|
|
String declareMonthStr = deleteParam.getDeclareMonth();
|
|
|
|
|
List<Long> deleteIds = deleteParam.getIds();
|
|
|
|
|
// 已经核算过的不可操作
|
|
|
|
|
// 获取已经核算的数据
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
|
|
|
|
|
// 判断是否有核算过
|
|
|
|
|
List<Long> deleteList = new ArrayList<>();
|
|
|
|
|
for(int i=0; i<deleteIds.size(); i++){
|
|
|
|
|
Long id = deleteIds.get(i);
|
2022-10-28 14:08:27 +08:00
|
|
|
OtherDeductionPO byId = otherDeductionBiz.getById(id);
|
|
|
|
|
if(byId == null){
|
|
|
|
|
throw new SalaryRunTimeException("数据不存在或已被删除!");
|
|
|
|
|
}
|
2022-10-27 18:02:05 +08:00
|
|
|
// 判断是否在个税扣缴义务人范围内
|
|
|
|
|
Optional<TaxAgentManageRangeEmployeeDTO> first = taxAgentList.stream().filter(m -> m.getTaxAgentId() == byId.getTaxAgentId()).findFirst();
|
|
|
|
|
if(!first.isPresent()){
|
|
|
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
|
|
|
|
|
}
|
|
|
|
|
// 判断用户是否存在
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
|
|
|
|
|
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(byId.getEmployeeId()) && f.getTaxAgentId().equals(byId.getTaxAgentId())).findFirst();
|
|
|
|
|
if (optionalAcctEmp.isPresent()) {
|
|
|
|
|
throw new SalaryRunTimeException("所选数据在该年月中已经核算过并归档,不可进行删除!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
deleteList.add(byId.getId());
|
|
|
|
|
}
|
2022-10-28 14:08:27 +08:00
|
|
|
otherDeductionBiz.batchDeleteByIDS(deleteList);
|
2022-10-27 18:02:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteAllData(AddUpDeductionRecordDeleteParam deleteParam) {
|
|
|
|
|
String declareMonthStr = deleteParam.getDeclareMonth();
|
|
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
// 获取所有个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
|
|
|
List<Long> taxAgentIds = taxAgentList.stream().map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId).collect(Collectors.toList());
|
|
|
|
|
OtherDeductionBiz otherDeductionBiz = new OtherDeductionBiz();
|
|
|
|
|
Date declareMonthDate =null;
|
|
|
|
|
try {
|
|
|
|
|
declareMonthDate = sdf.parse(declareMonthStr+"-01");
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
throw new SalaryRunTimeException("日期异常");
|
|
|
|
|
}
|
2022-10-28 16:35:51 +08:00
|
|
|
|
|
|
|
|
OtherDeductionPO queryParam = null;
|
|
|
|
|
if(deleteParam.getTaxAgentId() != null && (!deleteParam.getTaxAgentId().equals(""))){
|
|
|
|
|
// 设置了个税扣缴义务人
|
|
|
|
|
Long taxAgentId = SalaryEntityUtil.string2Long(deleteParam.getTaxAgentId());
|
|
|
|
|
boolean canDelete = taxAgentIds.stream().anyMatch(t -> t == taxAgentId);
|
|
|
|
|
if(!canDelete){
|
|
|
|
|
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内!");
|
|
|
|
|
}
|
|
|
|
|
ArrayList<Long> tai = new ArrayList<>();
|
|
|
|
|
tai.add(taxAgentId);
|
|
|
|
|
queryParam = OtherDeductionPO.builder().declareMonth(declareMonthDate).taxAgentIds(tai).build();
|
|
|
|
|
}else {
|
|
|
|
|
queryParam = OtherDeductionPO.builder().declareMonth(declareMonthDate).taxAgentIds(taxAgentIds).build();
|
|
|
|
|
}
|
2022-10-27 18:02:05 +08:00
|
|
|
// 获取所有想要删除的数据
|
|
|
|
|
List<OtherDeductionPO> list = otherDeductionBiz.listSome(queryParam);
|
|
|
|
|
// 获取已经核算的数据
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
|
|
|
|
|
for(OtherDeductionPO item : list){
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
|
|
|
|
|
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(item.getEmployeeId()) && f.getTaxAgentId().equals(item.getTaxAgentId())).findFirst();
|
|
|
|
|
if (optionalAcctEmp.isPresent()) {
|
|
|
|
|
throw new SalaryRunTimeException("有员工在该年月中已经完成核算并归档,不能进行一键清空!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Long> deleteIds = list.stream().map(OtherDeductionPO::getId).collect(Collectors.toList());
|
|
|
|
|
otherDeductionBiz.batchDeleteByIDS(deleteIds);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 17:44:26 +08:00
|
|
|
@Override
|
|
|
|
|
public XSSFWorkbook downloadTemplate(OtherDeductionQueryParam param) {
|
|
|
|
|
// 1.工作簿名称
|
2022-05-31 09:58:35 +08:00
|
|
|
String sheetName = SalaryI18nUtil.getI18nLabel(101604, "其他免税扣除导入模板");
|
2022-04-28 17:44:26 +08:00
|
|
|
String[] header = {
|
2022-05-31 09:58:35 +08:00
|
|
|
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, "准予扣除的捐赠额")
|
2022-04-28 17:44:26 +08:00
|
|
|
};
|
|
|
|
|
// 2.表头
|
|
|
|
|
List<List<Object>> rows = new ArrayList<>();
|
2022-05-31 09:58:35 +08:00
|
|
|
List<Object> headerList = Arrays.asList(header);
|
2022-04-28 17:44:26 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 17:57:46 +08:00
|
|
|
}
|