2022-03-22 21:01:38 +08:00
|
|
|
|
package com.engine.salary.wrapper;
|
|
|
|
|
|
|
2024-09-03 09:21:57 +08:00
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
|
import com.engine.core.impl.Service;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
|
|
|
|
|
import com.engine.salary.entity.salaryitem.bo.SysSalaryItemBO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobBO;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobBackItemBO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobBasicFormDTO;
|
2022-05-31 21:05:59 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobListDTO;
|
2024-08-30 10:49:46 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.param.*;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobDefaultBackItemPO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
2022-05-31 21:05:59 +08:00
|
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import com.engine.salary.enums.sicategory.DeleteTypeEnum;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import com.engine.salary.service.*;
|
|
|
|
|
|
import com.engine.salary.service.impl.*;
|
2022-05-31 21:05:59 +08:00
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2022-10-08 17:21:38 +08:00
|
|
|
|
import com.engine.salary.util.SalarySobUtil;
|
2024-01-25 11:38:38 +08:00
|
|
|
|
import com.engine.salary.util.db.IdGenerator;
|
2024-08-30 10:49:46 +08:00
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
2022-05-31 21:05:59 +08:00
|
|
|
|
import java.util.*;
|
2022-11-22 14:36:59 +08:00
|
|
|
|
import java.util.stream.Collectors;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 薪资账套
|
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author qiantao
|
|
|
|
|
|
* @version 1.0
|
|
|
|
|
|
**/
|
|
|
|
|
|
public class SalarySobWrapper extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
public SalarySobService getSalarySobService(User user) {
|
2022-06-06 16:55:02 +08:00
|
|
|
|
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-02 17:10:54 +08:00
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
|
|
|
|
}
|
2022-11-18 14:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
private SalarySobBackItemService getSalarySobBackItemService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SalarySobBackItemServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-22 14:36:59 +08:00
|
|
|
|
private SalaryItemService getSalaryItemService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SysSalaryItemService getSysSalaryItemService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SysSalaryItemServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 16:03:29 +08:00
|
|
|
|
private SalarySobItemService getSalarySobItemService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 薪资账套列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param queryParam 列表查询参数
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-05-31 21:05:59 +08:00
|
|
|
|
public PageInfo<SalarySobListDTO> listPage(SalarySobListQueryParam queryParam) {
|
|
|
|
|
|
|
2022-11-18 14:20:18 +08:00
|
|
|
|
// 处理历史数据,将薪资账套中将关联人员状态转换为List
|
2022-10-08 17:21:38 +08:00
|
|
|
|
SalarySobUtil.handleEmployeeStatusHistory();
|
2024-09-05 10:26:52 +08:00
|
|
|
|
getSalarySobService(user).handleHistory();
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-31 21:05:59 +08:00
|
|
|
|
// 查询薪资账套
|
|
|
|
|
|
PageInfo<SalarySobPO> page = getSalarySobService(user).listPageByParam(queryParam);
|
|
|
|
|
|
// 薪资账套po转换成薪资账套列表dto
|
2022-06-07 15:43:22 +08:00
|
|
|
|
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAll();
|
|
|
|
|
|
|
2024-09-05 10:26:52 +08:00
|
|
|
|
|
|
|
|
|
|
List<SalarySobListDTO> salarySobListDTOS = page.getList().stream()
|
|
|
|
|
|
.map(salarySobPO -> {
|
|
|
|
|
|
List<Long> taxAgentIds = salarySobPO.getTaxAgentIds();
|
|
|
|
|
|
String taxAgentName = taxAgentPOS.stream().filter(po -> taxAgentIds.contains(po.getId())).map(TaxAgentPO::getName).collect(Collectors.joining(","));
|
|
|
|
|
|
return SalarySobListDTO.builder()
|
|
|
|
|
|
.id(salarySobPO.getId())
|
|
|
|
|
|
.name(salarySobPO.getName())
|
|
|
|
|
|
.taxAgentName(taxAgentName)
|
|
|
|
|
|
.taxAgentIds(taxAgentIds)
|
|
|
|
|
|
.salaryCycle(SalarySobBO.buildSalaryCycle(salarySobPO))
|
|
|
|
|
|
.disable(salarySobPO.getDisable())
|
|
|
|
|
|
.description(salarySobPO.getDescription())
|
|
|
|
|
|
// .opts(salarySobPO.getOpts())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-31 21:05:59 +08:00
|
|
|
|
PageInfo<SalarySobListDTO> dtoPage = new PageInfo<>(salarySobListDTOS, SalarySobListDTO.class);
|
|
|
|
|
|
dtoPage.setTotal(page.getTotal());
|
|
|
|
|
|
dtoPage.setPageNum(page.getPageNum());
|
|
|
|
|
|
dtoPage.setPageSize(page.getPageSize());
|
2022-11-22 14:36:59 +08:00
|
|
|
|
// 处理历史数据,为薪资账套默认添加回算薪资项目
|
|
|
|
|
|
handleSalarySobBackItemHistory(queryParam);
|
2022-05-31 21:05:59 +08:00
|
|
|
|
// 转换成前端所需的数据格式
|
|
|
|
|
|
return dtoPage;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-07 09:52:21 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 薪资账套列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<SalarySobPO> listAll() {
|
|
|
|
|
|
return getSalarySobService(user).listAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-13 13:45:24 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 薪资账套列表(分权)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<SalarySobPO> listAllByAuth() {
|
|
|
|
|
|
return getSalarySobService(user).listAllByAuth();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-22 14:36:59 +08:00
|
|
|
|
private void handleSalarySobBackItemHistory(SalarySobListQueryParam queryParam) {
|
|
|
|
|
|
queryParam.setPageSize(100000);
|
|
|
|
|
|
List<SalarySobPO> list = getSalarySobService(user).listPageByParam(queryParam).getList();
|
2024-09-03 09:21:57 +08:00
|
|
|
|
if (list != null && list.size() > 0) {
|
2022-11-22 14:36:59 +08:00
|
|
|
|
List<Long> salarySobIds = list.stream().map(SalarySobPO::getId).collect(Collectors.toList());
|
|
|
|
|
|
Long count = getSalarySobBackItemService(user).getCountBySalarySobIdIn(salarySobIds);
|
2024-09-03 09:21:57 +08:00
|
|
|
|
if (count.equals(0L)) {
|
2022-11-22 14:36:59 +08:00
|
|
|
|
// 薪资账套的默认的回算薪资项目
|
|
|
|
|
|
Set<Long> SalarySobBackItemIds = SalaryEntityUtil.properties(SalarySobBackItemBO.getDefault(), SalarySobDefaultBackItemPO::getSysSalaryItemId);
|
|
|
|
|
|
// 获取薪资项目中是否已经添加回算薪资项目
|
|
|
|
|
|
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listBySysSalaryItemIds(SalarySobBackItemIds);
|
|
|
|
|
|
Set<Long> salaryBackItemSysIds = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getSysSalaryItemId);
|
|
|
|
|
|
// 需要添加进薪资项目中的回算薪资项目
|
|
|
|
|
|
List<Long> needAddSalaryBackItemIds = SalarySobBackItemIds.stream().filter(salarySobBackItemId -> !salaryBackItemSysIds.contains(salarySobBackItemId)).collect(Collectors.toList());
|
|
|
|
|
|
List<SysSalaryItemPO> needAddSysSalaryBackItemPOS = getSysSalaryItemService(user).listByIds(needAddSalaryBackItemIds);
|
|
|
|
|
|
// 需要保存的回算薪资项目
|
|
|
|
|
|
List<SalaryItemPO> needInsertSalaryItemPOS = SysSalaryItemBO.convert2SalaryItemPO(needAddSysSalaryBackItemPOS, (long) user.getUID());
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(needInsertSalaryItemPOS)) {
|
|
|
|
|
|
getSalaryItemService(user).batchSave(needInsertSalaryItemPOS);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 没有回算薪资项目数据,给所有薪资账套添加默认回算薪资项目
|
|
|
|
|
|
List<SalarySobBackItemPO> salarySobBackItems = new ArrayList<>();
|
|
|
|
|
|
// 获取默认添加后的回算薪资项目
|
|
|
|
|
|
List<SalaryItemPO> salaryBackItemPOS = getSalaryItemService(user).listBySysSalaryItemIds(SalarySobBackItemIds);
|
2024-09-03 09:21:57 +08:00
|
|
|
|
for (Long id : salarySobIds) {
|
2022-11-22 14:36:59 +08:00
|
|
|
|
for (SalarySobDefaultBackItemPO salarySobDefaultBackItemPO : SalarySobBackItemBO.getDefault()) {
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
Map<Long, SalaryItemPO> sysSalaryItemMap = SalaryEntityUtil.convert2Map(salaryBackItemPOS, SalaryItemPO::getSysSalaryItemId);
|
|
|
|
|
|
SalaryItemPO salaryItemPO = sysSalaryItemMap.get(salarySobDefaultBackItemPO.getSysSalaryItemId());
|
|
|
|
|
|
SalarySobBackItemPO salarySobBackItemPO = SalarySobBackItemPO.builder()
|
|
|
|
|
|
.id(IdGenerator.generate())
|
|
|
|
|
|
.salarySobId(id)
|
|
|
|
|
|
.salaryItemId(salaryItemPO.getId())
|
|
|
|
|
|
.salaryItemCode(salaryItemPO.getCode())
|
|
|
|
|
|
.dataType(salaryItemPO.getDataType())
|
|
|
|
|
|
.roundingMode(salaryItemPO.getRoundingMode())
|
|
|
|
|
|
.pattern(salaryItemPO.getPattern())
|
|
|
|
|
|
.valueType(salaryItemPO.getValueType())
|
|
|
|
|
|
.formulaId(salarySobDefaultBackItemPO.getFormulaId())
|
|
|
|
|
|
.backCalcType(salarySobDefaultBackItemPO.getBackCalcType())
|
2024-09-03 09:21:57 +08:00
|
|
|
|
.creator((long) user.getUID())
|
2022-11-22 14:36:59 +08:00
|
|
|
|
.createTime(now)
|
|
|
|
|
|
.updateTime(now)
|
|
|
|
|
|
.deleteType(DeleteTypeEnum.NOT_DELETED.getValue())
|
|
|
|
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY).build();
|
|
|
|
|
|
salarySobBackItems.add(salarySobBackItemPO);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 入库
|
|
|
|
|
|
getSalarySobBackItemService(user).batchInsert(salarySobBackItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-11-18 14:20:18 +08:00
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 薪资账套详情
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 薪资账套id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Map<String, Object> getForm(Long id) {
|
2022-05-31 21:05:59 +08:00
|
|
|
|
long employeeId = user.getUID();
|
2022-03-22 21:01:38 +08:00
|
|
|
|
Map<String, Object> data = new HashMap<>(16);
|
2022-05-31 21:05:59 +08:00
|
|
|
|
|
|
|
|
|
|
// 是否可以编辑(分权后,总管理员不可以编辑管理员新建的账套)
|
|
|
|
|
|
boolean canEdit = Objects.isNull(id) || canEdit(id, employeeId);
|
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// 薪资账套基础设置详情(目前核算人员范围的值固定为"1")
|
|
|
|
|
|
SalarySobBasicFormDTO basicForm = new SalarySobBasicFormDTO()
|
|
|
|
|
|
.setEmployeeRange("1")
|
2022-05-31 21:05:59 +08:00
|
|
|
|
.setTaxableItems(IncomeCategoryEnum.WAGES_AND_SALARIES.getValue())
|
|
|
|
|
|
.setCanEdit(canEdit);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
if (!Objects.isNull(id)) {
|
|
|
|
|
|
// 查询薪资账套
|
|
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(id);
|
|
|
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
|
|
|
|
|
}
|
|
|
|
|
|
// 薪资装套po转换成薪资账套详情dto
|
2024-09-03 09:21:57 +08:00
|
|
|
|
basicForm = SalarySobBO.convert2FormDTO(basicForm, salarySobPO);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 转换成前端所需的数据格式
|
|
|
|
|
|
data.put("basicForm", basicForm);
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param saveParam 保存参数
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Long save(SalarySobBasicSaveParam saveParam) {
|
|
|
|
|
|
return getSalarySobService(user).save(saveParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新薪资账套的基础设置
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param saveParam 更新参数
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Long update(SalarySobBasicSaveParam saveParam) {
|
|
|
|
|
|
return getSalarySobService(user).update(saveParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 启用/禁用薪资账套
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param disableParam 更新参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void updateDisable(SalarySobDisableParam disableParam) {
|
|
|
|
|
|
getSalarySobService(user).updateDisable(disableParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除薪资账套
|
|
|
|
|
|
*
|
2022-05-31 21:05:59 +08:00
|
|
|
|
* @param ids 薪资账套的id
|
2022-03-22 21:01:38 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public void delete(Collection<Long> ids) {
|
|
|
|
|
|
getSalarySobService(user).deleteByIds(ids);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 复制
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param duplicateParam 复制参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void duplicate(SalarySobDuplicateParam duplicateParam) {
|
|
|
|
|
|
getSalarySobService(user).duplicate(duplicateParam);
|
|
|
|
|
|
}
|
2022-05-31 21:05:59 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断是否可以编辑薪资账套
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
* @param employeeId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean canEdit(Long id, Long employeeId) {
|
|
|
|
|
|
// 查询薪资账套
|
2024-09-05 10:26:52 +08:00
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(id);
|
2022-05-31 21:05:59 +08:00
|
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否开启了分权
|
2022-06-02 17:10:54 +08:00
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
2022-05-31 21:05:59 +08:00
|
|
|
|
if (!openDevolution) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-06-02 17:10:54 +08:00
|
|
|
|
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId);
|
2022-05-31 21:05:59 +08:00
|
|
|
|
Set<Long> taxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId);
|
2024-09-03 09:21:57 +08:00
|
|
|
|
Collection intersection = CollectionUtil.intersection(taxAgentIds, salarySobPO.getTaxAgentIds());
|
|
|
|
|
|
return intersection.size() > 0;
|
2022-05-31 21:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-30 10:49:46 +08:00
|
|
|
|
public List<SalarySobPO> listByTaxAgent(SalarySobQueryParam param) {
|
2024-09-03 09:21:57 +08:00
|
|
|
|
return getSalarySobService(user).list(param);
|
2024-08-22 15:37:50 +08:00
|
|
|
|
}
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|