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

270 lines
12 KiB
Java
Raw Normal View History

2022-04-07 11:39:22 +08:00
package com.engine.salary.wrapper;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.salaryBill.dto.SalarySendCheckDTO;
2022-04-07 11:39:22 +08:00
import com.engine.salary.entity.salaryacct.bo.SalaryAcctRecordBO;
import com.engine.salary.entity.salaryacct.dto.SalaryAcctEmployeeCountDTO;
import com.engine.salary.entity.salaryacct.dto.SalaryAcctRecordFormDTO;
import com.engine.salary.entity.salaryacct.dto.SalaryAcctRecordListDTO;
import com.engine.salary.entity.salaryacct.param.SalaryAcctRecordQueryParam;
import com.engine.salary.entity.salaryacct.param.SalaryAcctRecordSaveParam;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
import com.engine.salary.entity.salarysob.po.SalarySobPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2022-04-07 11:39:22 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2023-04-12 15:27:35 +08:00
import com.engine.salary.service.*;
import com.engine.salary.service.impl.*;
2022-04-07 11:39:22 +08:00
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.SalarySobUtil;
2022-04-07 11:39:22 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.proxy.SalaryAcctRecordWrapperProxy;
2022-04-07 11:39:22 +08:00
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import weaver.hrm.User;
2022-04-18 17:28:34 +08:00
import java.util.*;
2022-04-07 11:39:22 +08:00
import java.util.stream.Collectors;
/**
* 薪资核算记录
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class SalaryAcctRecordWrapper extends Service implements SalaryAcctRecordWrapperProxy {
2022-04-07 11:39:22 +08:00
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
2022-04-07 11:39:22 +08:00
}
2022-04-18 17:28:34 +08:00
2022-04-07 11:39:22 +08:00
private SalarySobService getSalarySobService(User user) {
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
2022-04-07 11:39:22 +08:00
}
2022-04-18 17:28:34 +08:00
2022-04-08 16:30:10 +08:00
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
2022-04-08 16:30:10 +08:00
}
private SalarySendService getSalarySendService(User user) {
return ServiceUtil.getService(SalarySendServiceImpl.class, user);
}
2023-04-12 15:27:35 +08:00
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
2023-05-31 09:55:24 +08:00
private SalaryItemService getSalaryItemService(User user) {
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
2022-04-07 11:39:22 +08:00
// private ComInfoCache comInfoCache;
public PageInfo<SalaryAcctRecordListDTO> listPage(SalaryAcctRecordQueryParam queryParam) {
// 处理历史数据将薪资账套中将关联人员状态转换为List
SalarySobUtil.handleEmployeeStatusHistory();
// 处理工资单发放历史数据
getSalarySendService(user).handleHistory();
2022-04-07 11:39:22 +08:00
// 查询薪资核算记录(分页)
PageInfo<SalaryAcctRecordPO> page = getSalaryAcctRecordService(user).listPageByParam(queryParam);
2022-04-08 16:30:10 +08:00
PageInfo<SalaryAcctRecordListDTO> dtoPage = new PageInfo<SalaryAcctRecordListDTO>(SalaryAcctRecordListDTO.class);
2022-04-07 11:39:22 +08:00
dtoPage.setPageNum(queryParam.getCurrent());
dtoPage.setPageSize(queryParam.getPageSize());
dtoPage.setTotal(page.getTotal());
2022-04-07 11:39:22 +08:00
List<SalaryAcctRecordPO> list = page.getList();
if (CollectionUtils.isNotEmpty(list)) {
// 查询薪资账套
Set<Long> salarySobIds = SalaryEntityUtil.properties(list, SalaryAcctRecordPO::getSalarySobId);
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
// 查询薪资核算记录的创建人员的人员信息
List<Long> employeeIds = SalaryEntityUtil.properties(list, SalaryAcctRecordPO::getCreator, Collectors.toList());
2023-04-12 15:27:35 +08:00
List<DataCollectionEmployee> employeeComInfos = getSalaryEmployeeService(user).getEmployeeByIdsAll(employeeIds);
2022-04-07 11:39:22 +08:00
// 查询薪资核算人数的数量
Set<Long> salaryAcctRecordIds = SalaryEntityUtil.properties(list, SalaryAcctRecordPO::getId);
2022-04-08 16:30:10 +08:00
List<SalaryAcctEmployeeCountDTO> salaryAcctEmployeeCountDTOS = getSalaryAcctEmployeeService(user).countBySalaryAcctRecordId(salaryAcctRecordIds);
// 查询工资单的查询情况
List<SalarySendCheckDTO> salarySendCheckResult = getSalarySendService(user).getSalarySendCheckResult(salaryAcctRecordIds);
Set<Long> taxAgentIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getTaxAgentId);
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(taxAgentIds);
2022-04-07 11:39:22 +08:00
// 转换成列表dto
List<SalaryAcctRecordListDTO> salaryAcctRecordListDTOS = SalaryAcctRecordBO.convert2ListDTO(list, salarySobPOS, employeeComInfos, salaryAcctEmployeeCountDTOS, salarySendCheckResult, taxAgentPOS);
2022-04-07 11:39:22 +08:00
dtoPage.setList(salaryAcctRecordListDTOS);
}
2022-04-06 20:01:00 +08:00
// WeaTable<SalaryAcctRecordListDTO> weaTable = SalaryFormatUtil.<SalaryAcctRecordListDTO>getInstance().buildTable(SalaryAcctRecordListDTO.class, dtoPage);
2022-04-07 11:39:22 +08:00
// 只有未归档时可以"核算"、"删除"、"归档"
// 归档后、申报后可以"查看"、"重新核算"
2022-04-06 20:01:00 +08:00
// for (int i = 0; i < page.getRecords().size(); i++) {
// SalaryAcctRecordPO salaryAcctRecord = page.getRecords().get(i);
// List<Permission> permissions = weaTable.getOperatesPermission().get(i);
// for (int j = 0; j < permissions.size(); j++) {
// Permission permission = permissions.get(j);
// if ((j == 0 || j == 1 || j == 3) && !Objects.equals(salaryAcctRecord.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())) {
// permission.setVisible(false);
// permission.setDisabled(false);
// }
// if ((j == 2 || j == 5) && Objects.equals(salaryAcctRecord.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())) {
// permission.setVisible(false);
// permission.setDisabled(false);
// }
// }
// }
2022-04-07 11:39:22 +08:00
return dtoPage;
}
2023-05-31 09:55:24 +08:00
/**
* @description 处理历史数据给薪资项目都增加个默认排序
* @return null
* @author Harryxzy
* @date 2023/5/29 14:37
*/
2023-06-01 17:52:31 +08:00
// private void generateSalaryItemSortedIndex() {
// // 查询所有薪资项目
// List<SalaryItemPO> salaryItemList = getSalaryItemService(user).listByParamOrderById(SalaryItemSearchParam.builder().build());
// Optional<SalaryItemPO> needGenerate = salaryItemList.stream().filter(item -> item.getSortedIndex() == null).findFirst();
// if(needGenerate.isPresent()){
// Map<Integer, List<SalaryItemPO>> salaryItemMap = SalaryEntityUtil.group2Map(salaryItemList, SalaryItemPO::getUseInEmployeeSalary);
// for(Map.Entry<Integer, List<SalaryItemPO>> entry : salaryItemMap.entrySet()){
// List<SalaryItemPO> values = entry.getValue();
// if(CollectionUtils.isNotEmpty(values)){
// // 将系统薪资项目放到最后
// values = values.stream()
// .sorted(Comparator.comparing(SalaryItemPO::getSystemType))
// .collect(Collectors.toList());
// // 添加默认sortedIndex
// AtomicInteger index = new AtomicInteger(values.size());
// values.stream().forEach(value -> value.setSortedIndex(index.getAndDecrement()));
// // 保存排序
// getSalaryItemService(user).batchUpdateSortedIndex(values);
// }
// }
// }
// }
2023-05-31 09:55:24 +08:00
2022-04-07 11:39:22 +08:00
/**
* 薪资核算记录详情
*
2022-04-18 17:28:34 +08:00
* @param id 薪资核算记录id
2022-04-07 11:39:22 +08:00
* @return
*/
public Map<String, Object> getForm(Long id) {
2022-04-07 11:39:22 +08:00
SalaryAcctRecordFormDTO formDTO = new SalaryAcctRecordFormDTO();
// 查询所有启用的薪资账套
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
// 薪资核算详情表单中"薪资账套"的下拉选择项
2022-04-18 17:28:34 +08:00
List<Map<String, Object>> salarySobs = salarySobPOS.stream()
.map(salarySobPO -> {
Map<String, Object> map = new HashMap<>();
map.put("id", salarySobPO.getId());
map.put("name", salarySobPO.getName());
2022-04-18 17:28:34 +08:00
return map;
})
.collect(Collectors.toList());
2022-04-07 11:39:22 +08:00
if (Objects.nonNull(id)) {
// 查询薪资核算
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(id);
if (Objects.isNull(salaryAcctRecordPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
}
// 查询薪资账套
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
if (Objects.isNull(salarySobPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "薪资账套不存在或已被删除"));
}
// 转换成薪资核算记录详情dto
formDTO.setId(salaryAcctRecordPO.getId())
.setSalarySobId(salarySobPO.getId())
.setSalarySobName(salarySobPO.getName())
.setSalaryMonth(SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()).toString())
.setDescription(salaryAcctRecordPO.getDescription());
}
// 转换成前端所需的数据格式
Map<String, Object> result = new HashMap<>();
result.put("formDTO", formDTO);
result.put("salarySobs", salarySobs);
2022-04-18 17:28:34 +08:00
return result;
2022-04-07 11:39:22 +08:00
}
/**
* 薪资核算记录所用的薪资账套薪资周期考勤周期
*
2022-04-18 17:28:34 +08:00
* @param id 薪资核算记录的id
2022-04-07 11:39:22 +08:00
* @return
*/
public SalarySobCycleDTO getSalarySobCycleById(Long id) {
return getSalaryAcctRecordService(user).getSalarySobCycleById(id);
}
/**
* 保存
*
2022-04-18 17:28:34 +08:00
* @param saveParam 保存参数
2022-04-07 11:39:22 +08:00
* @return
*/
public Long save(SalaryAcctRecordSaveParam saveParam) {
return getSalaryAcctRecordService(user).save(saveParam);
}
/**
* 删除
*
2022-04-18 17:28:34 +08:00
* @param ids 薪资核算记录的id
2022-04-07 11:39:22 +08:00
*/
public void delete(Collection<Long> ids) {
getSalaryAcctRecordService(user).deleteByIds(ids);
}
/**
* 归档
*
2022-04-18 17:28:34 +08:00
* @param id 薪资核算记录的id
2022-04-07 11:39:22 +08:00
*/
2022-04-07 16:54:10 +08:00
public void file(Long id) {
2022-04-07 11:39:22 +08:00
getSalaryAcctRecordService(user).file(id);
}
/**
2022-06-07 19:10:40 +08:00
* 重新核算
2022-04-07 11:39:22 +08:00
*
2022-04-18 17:28:34 +08:00
* @param id 薪资核算记录的id
2022-04-07 11:39:22 +08:00
*/
public void reCalculate(Long id) {
getSalaryAcctRecordService(user).reCalculate(id);
}
2022-04-07 11:39:22 +08:00
/**
* 判断是否存在合并计税
*
2022-04-18 17:28:34 +08:00
* @param id 主键id
2022-04-07 11:39:22 +08:00
* @return
*/
public Integer hasConsolidatedTax(Long id) {
return getSalaryAcctRecordService(user).hasConsolidatedTax(id);
}
/**
* @description 回算
* @return void
* @author Harryxzy
* @date 2022/11/24 15:52
*/
public void backCalculate(Long salaryAcctRecordId){
getSalaryAcctRecordService(user).backCalculate(salaryAcctRecordId);
}
2022-04-07 11:39:22 +08:00
}