2022-11-25 10:53:23 +08:00
|
|
|
|
package com.engine.salary.service.impl;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
import com.engine.core.impl.Service;
|
2022-11-25 10:53:23 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
|
import com.engine.salary.entity.hrm.DeptInfo;
|
|
|
|
|
|
import com.engine.salary.entity.hrm.PositionInfo;
|
|
|
|
|
|
import com.engine.salary.entity.hrm.SubCompanyInfo;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.dto.SalarySendRangeListDTO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.dto.SalarySendRangeObjDTO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.param.SalarySendRangeQueryParam;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.param.SalarySendRangeSaveParam;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.po.SalarySendRangeObj;
|
|
|
|
|
|
import com.engine.salary.entity.salaryBill.po.SalarySendRangePO;
|
2022-11-29 14:36:37 +08:00
|
|
|
|
import com.engine.salary.enums.salarysend.SalarySendGrantTypeEnum;
|
2022-11-25 10:53:23 +08:00
|
|
|
|
import com.engine.salary.enums.salarysend.SalarySendRangeTargetTypeEnum;
|
|
|
|
|
|
import com.engine.salary.enums.salarysend.SalarySendRangeTypeEnum;
|
|
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
|
|
|
|
import com.engine.salary.mapper.salarybill.SalarySendRangeMapper;
|
|
|
|
|
|
import com.engine.salary.service.SalaryEmployeeService;
|
|
|
|
|
|
import com.engine.salary.service.SalarySendRangeObjService;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
import com.engine.salary.service.SalarySendRangeService;
|
2022-11-25 10:53:23 +08:00
|
|
|
|
import com.engine.salary.service.TaxAgentService;
|
|
|
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
|
|
import weaver.conn.mybatis.MyBatisFactory;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
|
|
|
|
|
public class SalarySendRangeServiceImpl extends Service implements SalarySendRangeService {
|
2022-11-25 10:53:23 +08:00
|
|
|
|
private SalaryEmployeeService getSalaryEmployeeService() {
|
|
|
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
|
}
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
private TaxAgentService getTaxAgentService() {
|
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
private <R> R applyMapper(Function<SalarySendRangeMapper, R> mapper) {
|
|
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
|
|
|
|
|
final SalarySendRangeMapper salarySendRangeMapper = sqlSession.getMapper(SalarySendRangeMapper.class);
|
|
|
|
|
|
R apply = mapper.apply(salarySendRangeMapper);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
return apply;
|
|
|
|
|
|
}
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
private void runMapper(Consumer<SalarySendRangeMapper> mapper) {
|
|
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
|
|
|
|
|
final SalarySendRangeMapper salarySendRangeMapper = sqlSession.getMapper(SalarySendRangeMapper.class);
|
|
|
|
|
|
mapper.accept(salarySendRangeMapper);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
private SalarySendRangeObjService getSalarySendRangeObjService() {
|
|
|
|
|
|
return ServiceUtil.getService(SalarySendRangeObjServiceImpl.class, user);
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-11-25 10:53:23 +08:00
|
|
|
|
public void save(SalarySendRangeSaveParam param) {
|
2022-11-29 14:36:37 +08:00
|
|
|
|
if (user == null) {
|
|
|
|
|
|
throw new SalaryRunTimeException("您没有此操作的权限");
|
|
|
|
|
|
}
|
2022-11-25 10:53:23 +08:00
|
|
|
|
SalarySendRangeSaveParam.checkParam(param, (long) user.getUID(), DEFAULT_TENANT_KEY);
|
|
|
|
|
|
SalarySendRangePO salarySendRangePO = param.toSalarySendRangePO(user);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果传入id, 则做查询后更新
|
|
|
|
|
|
if (salarySendRangePO.getId() != null) {
|
|
|
|
|
|
SalarySendRangePO oldInfo = applyMapper(mapper -> mapper.selectByPrimaryKey(salarySendRangePO.getId()));
|
|
|
|
|
|
if (oldInfo == null) {
|
|
|
|
|
|
throw new SalaryRunTimeException("传入发放范围不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
runMapper(mapper -> mapper.updateByPrimaryKeySelective(salarySendRangePO));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
runMapper(mapper -> mapper.insertSelective(salarySendRangePO));
|
|
|
|
|
|
}
|
|
|
|
|
|
param.setSalarySendRangeId(salarySendRangePO.getId());
|
|
|
|
|
|
|
|
|
|
|
|
List<SalarySendRangeObj> rangeObjs = param.toSalarySendRangeObj(user);
|
|
|
|
|
|
getSalarySendRangeObjService().replaceAllByRangeIds(salarySendRangePO.getId(), rangeObjs);
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-11-25 10:53:23 +08:00
|
|
|
|
public PageInfo<SalarySendRangeListDTO> listPage(SalarySendRangeQueryParam queryParam) {
|
|
|
|
|
|
SalarySendRangeMapper mapper = MapperProxyFactory.getProxy(SalarySendRangeMapper.class);
|
|
|
|
|
|
List<SalarySendRangeListDTO> listDTOs = mapper.selectByParam(queryParam);
|
|
|
|
|
|
PageInfo<SalarySendRangeListDTO> page = new PageInfo<>(listDTOs, SalarySendRangeListDTO.class);
|
|
|
|
|
|
listDTOs = listDTOs.stream().map(s -> {
|
|
|
|
|
|
List<SalarySendRangeObj> rangeObjs = getSalarySendRangeObjService().listBySalarySendIdAndRangeIds(queryParam.getSalarySendId(),
|
|
|
|
|
|
Collections.singletonList(s.getId()));
|
|
|
|
|
|
Map<Integer, List<SalarySendRangeObjDTO>> groupedMap = rangeObjs.stream()
|
|
|
|
|
|
.map(rangeObj -> {
|
|
|
|
|
|
SalarySendRangeTargetTypeEnum typeEnum = SalarySendRangeTargetTypeEnum.fromValue(rangeObj.getTargetType());
|
|
|
|
|
|
if (typeEnum == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
String targetName = null;
|
|
|
|
|
|
switch (typeEnum) {
|
|
|
|
|
|
case USER:
|
|
|
|
|
|
DataCollectionEmployee employee =
|
|
|
|
|
|
getSalaryEmployeeService().getEmployeeById(rangeObj.getTargetId());
|
|
|
|
|
|
targetName = Optional.ofNullable(employee)
|
|
|
|
|
|
.map(DataCollectionEmployee::getUsername)
|
|
|
|
|
|
.orElse(null);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DEPT:
|
2023-03-07 17:14:25 +08:00
|
|
|
|
targetName = getSalaryEmployeeService().getDeptInfoList(Collections.singletonList(rangeObj.getTargetId()))
|
2022-11-25 10:53:23 +08:00
|
|
|
|
.stream().findFirst()
|
|
|
|
|
|
.map(DeptInfo::getName).orElse(null);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SUB_COMPANY:
|
2023-03-07 17:14:25 +08:00
|
|
|
|
targetName = getSalaryEmployeeService().getSubCompanyInfoList(Collections.singletonList(rangeObj.getTargetId()))
|
2022-11-25 10:53:23 +08:00
|
|
|
|
.stream().findFirst()
|
|
|
|
|
|
.map(SubCompanyInfo::getName).orElse(null);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case POSITION:
|
2023-03-07 17:14:25 +08:00
|
|
|
|
targetName = getSalaryEmployeeService().listPositionInfo(Collections.singletonList(rangeObj.getTargetId()))
|
2022-11-25 10:53:23 +08:00
|
|
|
|
.stream().findFirst()
|
|
|
|
|
|
.map(PositionInfo::getName).orElse(null);
|
|
|
|
|
|
break;
|
2022-12-08 15:45:15 +08:00
|
|
|
|
// case TAX_AGENT:
|
|
|
|
|
|
// targetName = Optional.ofNullable(getTaxAgentService().getById(rangeObj.getTargetId()))
|
|
|
|
|
|
// .map(TaxAgentPO::getName).orElse(null);
|
|
|
|
|
|
// break;
|
2022-11-25 10:53:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
return SalarySendRangeObjDTO.builder()
|
|
|
|
|
|
.targetType(rangeObj.getTargetType())
|
|
|
|
|
|
.targetTypeName(typeEnum.getDefaultLabel())
|
|
|
|
|
|
.targetName(targetName)
|
|
|
|
|
|
.rangeType(rangeObj.getRangeType())
|
|
|
|
|
|
.targetId(rangeObj.getTargetId())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}).filter(Objects::nonNull)
|
|
|
|
|
|
.collect(Collectors.groupingBy(SalarySendRangeObjDTO::getRangeType));
|
|
|
|
|
|
//如果有查询,则做筛选
|
|
|
|
|
|
if (StrUtil.isNotEmpty(queryParam.getTargetName())) {
|
|
|
|
|
|
boolean nameLike = false;
|
|
|
|
|
|
for (List<SalarySendRangeObjDTO> value : groupedMap.values()) {
|
|
|
|
|
|
nameLike |= value.stream()
|
|
|
|
|
|
.anyMatch(item -> Optional.ofNullable(item.getTargetName()).orElse("")
|
|
|
|
|
|
.contains(queryParam.getTargetName()));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!nameLike) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
s.setIncludeObj(groupedMap.getOrDefault(SalarySendRangeTypeEnum.INCLUDE_OBJ.getValue(), Collections.emptyList()));
|
|
|
|
|
|
s.setExcludeObj(groupedMap.getOrDefault(SalarySendRangeTypeEnum.EXCLUDE_OBJ.getValue(), Collections.emptyList()));
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}).filter(Objects::nonNull)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2022-12-12 10:25:55 +08:00
|
|
|
|
page.setTotal(listDTOs.size());
|
|
|
|
|
|
List<SalarySendRangeListDTO> list = SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), listDTOs);
|
|
|
|
|
|
page.setList(list);
|
2022-11-25 10:53:23 +08:00
|
|
|
|
return page;
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void deleteBySalarySendIds(Collection<Long> sendIds) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-11-25 10:53:23 +08:00
|
|
|
|
public void deleteByIds(List<Long> sendRangeIds) {
|
2022-12-12 10:25:55 +08:00
|
|
|
|
runMapper(mapper -> {
|
2022-11-25 10:53:23 +08:00
|
|
|
|
for (Long sendRangeId : sendRangeIds) {
|
|
|
|
|
|
mapper.deleteByPrimaryKey(sendRangeId);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
getSalarySendRangeObjService().deleteBySalarySendRangeIds(sendRangeIds);
|
|
|
|
|
|
}
|
2022-11-17 11:11:58 +08:00
|
|
|
|
|
2022-11-25 10:53:23 +08:00
|
|
|
|
@Override
|
2022-11-29 14:36:37 +08:00
|
|
|
|
public List<Long> getSendInfoIdsBySendId(Long sendId, List<Long> sendRangeIds, SalarySendGrantTypeEnum grantType) {
|
2022-11-25 10:53:23 +08:00
|
|
|
|
List<Long> rangeIdList =
|
2022-11-29 14:36:37 +08:00
|
|
|
|
applyMapper(mapper -> mapper.selectIdsBySendIdAndGrantType(sendId, grantType.getValue()));
|
2022-11-25 10:53:23 +08:00
|
|
|
|
|
|
|
|
|
|
rangeIdList = rangeIdList.stream()
|
|
|
|
|
|
.filter(sendRangeIds::contains)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
return getSalarySendRangeObjService().getSendInfoIdsBySalarySendIdAndRangeIds(sendId, rangeIdList);
|
2022-11-17 11:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|