package com.engine.salary.service.impl; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.hrm.biz.OrganizationShowSetBiz; import com.engine.salary.biz.EmployBiz; import com.engine.salary.biz.SalarySobRangeBiz; 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.salarysob.bo.SalarySobRangeBO; import com.engine.salary.entity.salarysob.bo.SalarySobRangeSaveBO; import com.engine.salary.entity.salarysob.dto.SalarySobRangeListDTO; import com.engine.salary.entity.salarysob.param.SalarySobRangeQueryParam; import com.engine.salary.entity.salarysob.param.SalarySobRangeSaveParam; import com.engine.salary.entity.salarysob.po.SalarySobPO; import com.engine.salary.entity.salarysob.po.SalarySobRangePO; import com.engine.salary.enums.salarysob.TargetTypeEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.service.SalarySobRangeService; import com.engine.salary.service.SalarySobService; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.page.PageInfo; import com.engine.salary.util.page.PageUtil; import com.engine.salary.util.valid.ValidUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import weaver.hrm.User; import java.util.*; import java.util.stream.Collectors; /** * 薪资账套人员范围 *

Copyright: Copyright (c) 2022

*

Company: 泛微软件

* * @author qiantao * @version 1.0 **/ public class SalarySobRangeServiceImpl extends Service implements SalarySobRangeService { private SalarySobRangeBiz salarySobRangeBiz = new SalarySobRangeBiz(); private EmployBiz employBiz = new EmployBiz(); OrganizationShowSetBiz orgBiz = new OrganizationShowSetBiz(); private SalarySobService getSalarySobService(User user) { return (SalarySobService) ServiceUtil.getService(SalarySobServiceImpl.class, user); } // private ComInfoCache comInfoCache; // private LoggerTemplate salarySobLoggerTemplate; @Override public List listByIds(Collection ids) { if (CollectionUtils.isEmpty(ids)) { return Collections.emptyList(); } return salarySobRangeBiz.listSome(SalarySobRangePO.builder().ids(ids).build()); } @Override public List listBySalarySobIdAndIncludeType(Long salarySobId, Integer includeType) { return salarySobRangeBiz.listSome(SalarySobRangePO.builder().salarySobId(salarySobId).includeType(includeType).build()); } @Override public PageInfo listPageByParamAndIncludeType(SalarySobRangeQueryParam queryParam, Integer includeType) { // 查询人员范围 List salarySobRangePOS = listBySalarySobIdAndIncludeType(queryParam.getSalarySobId(), includeType); // 查询人员信息 List employeeIds = salarySobRangePOS.stream() .filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue())) .map(SalarySobRangePO::getTargetId) .collect(Collectors.toList()); List empInfos = employBiz.getEmployeeByIds(employeeIds); // 查询部门信息 List deptInfos = salarySobRangePOS.stream() .filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue())) .map(SalarySobRangePO::getTargetId) .map(id -> { return DeptInfo.builder().id(id).name(orgBiz.getDepartmentShow(String.valueOf(id), "0", "-")).build(); }) .collect(Collectors.toList()); // 查询岗位信息 List positionIds = salarySobRangePOS.stream() .filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue())) .map(SalarySobRangePO::getTargetId) .collect(Collectors.toList()); List positionInfos = employBiz.listPositionInfo(positionIds); // 薪资账套的人员范围po转换成列表dto List salarySobRangeListDTOS = SalarySobRangeBO.convert2ListDTO(salarySobRangePOS, empInfos, deptInfos, positionInfos); // 根据对象名称过滤 if (StringUtils.isNotEmpty(queryParam.getTargetName())) { salarySobRangeListDTOS = salarySobRangeListDTOS.stream() .filter(salarySobRangeListDTO -> salarySobRangeListDTO.getTargetName().contains(queryParam.getTargetName())) .collect(Collectors.toList()); } // 填充总数和当页数据 PageInfo pageInfo = new PageInfo(salarySobRangeListDTOS,SalarySobRangeListDTO.class); pageInfo.setTotal(salarySobRangeListDTOS.size()); pageInfo.setList(PageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salarySobRangeListDTOS)); return pageInfo; } @Override public void save(SalarySobRangeSaveParam saveParam) { ValidUtil.doValidator(saveParam); // 查询薪资账套 SalarySobPO salarySobPO = getSalarySobService(user).getById(saveParam.getSalarySobId()); if (Objects.isNull(salarySobPO)) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除")); } // 查询已有的人员范围 List salarySobRangePOS = listBySalarySobIdAndIncludeType(saveParam.getSalarySobId(), saveParam.getIncludeType()); // 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新) SalarySobRangeSaveBO.Result result = SalarySobRangeSaveBO.handle(salarySobRangePOS, saveParam, (long) user.getUID()); // 保存 if (CollectionUtils.isNotEmpty(result.getNeedInsertSalarySobRanges())) { salarySobRangeBiz.batchInsert(result.getNeedInsertSalarySobRanges()); } if (CollectionUtils.isNotEmpty(result.getNeedUpdateSalarySobRanges())) { result.getNeedUpdateSalarySobRanges().forEach(e -> salarySobRangeBiz.updateById(e)); } // todo 记录日志 // String operateTypeName = Objects.equals(saveParam.getIncludeType(), NumberUtils.INTEGER_ONE) ? // SalaryI18nUtil.getI18nLabel(98601, "关联人员范围新增对象") : SalaryI18nUtil.getI18nLabel(98602, "从范围中排除新增对象"); // LoggerContext loggerContext = new LoggerContext<>(); // loggerContext.setTargetId("" + salarySobPO.getId()); // loggerContext.setTargetName(salarySobPO.getName()); // loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); // loggerContext.setOperateTypeName(operateTypeName); // loggerContext.setOperatedesc(operateTypeName); // loggerContext.setNewValues(saveParam); // salarySobLoggerTemplate.write(loggerContext); } @Override public void deleteByIds(Collection ids) { // 查询薪资账套的人员范围 List salarySobRangePOS = listByIds(ids); if (CollectionUtils.isEmpty(salarySobRangePOS)) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98604, "数据不存在或已被删除")); } ids = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getId); // 删除薪资账套的人员范围 salarySobRangeBiz.deleteByIds(ids); // 查询薪资账套 Set salarySobIds = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getSalarySobId); List salarySobPOS = getSalarySobService(user).listByIds(salarySobIds); // 是"关联人员范围"还是"从范围中排除" Integer includeType = salarySobRangePOS.get(0).getIncludeType(); // todo 记录日志 String operateTypeName = Objects.equals(includeType, NumberUtils.INTEGER_ONE) ? SalaryI18nUtil.getI18nLabel(98605, "关联人员范围删除对象") : SalaryI18nUtil.getI18nLabel(98606, "从范围中排除删除对象"); // salarySobPOS.forEach(salarySobPO -> { // LoggerContext loggerContext = new LoggerContext<>(); // loggerContext.setTargetId("" + salarySobPO.getId()); // loggerContext.setTargetName(salarySobPO.getName()); // loggerContext.setOperateType(OperateTypeEnum.DELETE.getValue()); // loggerContext.setOperateTypeName(operateTypeName); // loggerContext.setOperatedesc(operateTypeName); // }); } @Override public void deleteBySalarySobIds(Collection salarySobIds) { salarySobRangeBiz.deleteBySalarySobIds(salarySobIds); } }