//package com.engine.salary.entity.sicategory.bo;
//
//import com.baomidou.mybatisplus.core.conditions.Wrapper;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.weaver.common.distribution.genid.IdGenerator;
//import com.weaver.hrm.salary.entity.sicategory.dto.InsuranceCategoryFormDTO;
//import com.weaver.hrm.salary.entity.sicategory.dto.InsuranceCategoryListDTO;
//import com.weaver.hrm.salary.entity.sicategory.po.InsuranceCategoryPO;
//import com.weaver.hrm.salary.enums.sicategory.PaymentScopeEnum;
//import com.weaver.hrm.salary.enums.sicategory.WelfareTypeEnum;
//import com.weaver.hrm.salary.util.SalaryEnumUtil;
//import com.weaver.hrm.salary.util.SalaryI18nUtil;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//
//import java.time.LocalDateTime;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * @Description:
// * @Author: zhangheng
// * @CreateDate: 2021/11/12 9:08
// * @Version: v1.0
// */
//public class InsuranceCategoryBO {
//
//    public static InsuranceCategoryFormDTO convertToInsuranceCategoryFromDTO(InsuranceCategoryPO insuranceCategoryPO, Long employeeId, String tenantKey) {
//        InsuranceCategoryFormDTO insuranceCategoryFormDTO = new InsuranceCategoryFormDTO();
//        BeanUtils.copyProperties(insuranceCategoryPO, insuranceCategoryFormDTO);
//        if (insuranceCategoryPO.getWelfareType() != null) {
//            insuranceCategoryFormDTO.setWelfareType(InsuranceCategoryBO.matchWelfareTypeEnum(insuranceCategoryPO.getWelfareType()));
//        }
//        if (StringUtils.isNotBlank(insuranceCategoryPO.getPaymentScope())) {
//            insuranceCategoryFormDTO.setPaymentScope(SalaryEnumUtil.stringToEnums(insuranceCategoryPO.getPaymentScope(), ","));
//        }
//        return insuranceCategoryFormDTO;
//    }
//
//    public static InsuranceCategoryPO convertToInsuranceCategoryPO(InsuranceCategoryFormDTO dto, Long employeeId, String tenantKey) {
//        if (Objects.isNull(dto)) {
//            return null;
//        }
//        return InsuranceCategoryPO.builder()
//            .paymentScope(SalaryEnumUtil.enumArrToString(dto.getPaymentScope()))
//            .welfareType(dto.getWelfareType().getValue())
//            .insuranceName(dto.getInsuranceName())
//            .isUse(dto.getIsUse())
//            .createTime(LocalDateTime.now())
//            .updateTime(LocalDateTime.now())
//            .creator(employeeId)
//            .tenantKey(tenantKey)
//            .build();
//
//    }
//
//    public static Wrapper<InsuranceCategoryPO> buildCustomCategoryListWrapper(WelfareTypeEnum welfareType,) {
//        LambdaQueryWrapper<InsuranceCategoryPO> lambdaQueryWrapper = Wrappers.lambdaQuery();
//        lambdaQueryWrapper.eq(InsuranceCategoryPO::getTenantKey, tenantKey)
//            .eq(InsuranceCategoryPO::getDeleteType, 0);
//        if (welfareType != null) {
//            lambdaQueryWrapper.eq(InsuranceCategoryPO::getWelfareType, welfareType.getValue());
//        }
//        lambdaQueryWrapper.orderByDesc(InsuranceCategoryPO::getUpdateTime);
//        return lambdaQueryWrapper;
//    }
//
//    public static List<InsuranceCategoryListDTO> convertToCustomCategoryList(Collection<InsuranceCategoryPO> insuranceCategoryPOS,
//                                                                             Long employeeId, String tenantKey) {
//        if (CollectionUtils.isEmpty(insuranceCategoryPOS)) {
//            return Collections.emptyList();
//        }
//        return insuranceCategoryPOS.stream().map(item ->
//            InsuranceCategoryListDTO.builder()
//                .id(item.getId())
//                .isUse(item.getIsUse())
//                .welfareType(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, matchWelfareTypeEnum(item.getWelfareType()).getLabelId(),
//                    matchWelfareTypeEnum(item.getWelfareType()).getDefaultLabel()))
//                .paymentScopt(buildPaymentScope(item.getPaymentScope(), employeeId, tenantKey))
//                .insuranceName(item.getInsuranceName())
//                .build()
//        ).collect(Collectors.toList());
//    }
//
//    public static String buildPaymentScope(String paymentScopeValues, Long employeeId, String tenantKey) {
//        if (StringUtils.isBlank(paymentScopeValues)) {
//            return "";
//        }
//        List<String> collect = Arrays.stream(paymentScopeValues.split(",")).map(item -> {
//            PaymentScopeEnum paymentScopeEnum = SalaryEnumUtil.enumMatchByValue(Integer.valueOf(item), PaymentScopeEnum.values(), PaymentScopeEnum.class);
//            return SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, paymentScopeEnum.getLabelId(), paymentScopeEnum.getDefaultLabel());
//        }).collect(Collectors.toList());
//
//        return StringUtils.join(collect, "、");
//    }
//
//    public static WelfareTypeEnum matchWelfareTypeEnum(Integer value) {
//        return SalaryEnumUtil.enumMatchByValue(value, WelfareTypeEnum.values(), WelfareTypeEnum.class);
//    }
//}
