# PlLayoutValidationServiceImpl.java

    package cloud.wconnect.finance.service.pl.impl;

    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.finance.entity.pl.M3Account;
    import cloud.wconnect.finance.entity.pl.PlLayoutValidation;
    import cloud.wconnect.finance.mapper.pl.PlLayoutValidationMapper;
    import cloud.wconnect.finance.service.pl.IPlLayoutValidationService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.fasterxml.jackson.core.type.TypeReference;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    /**
     * <p>
     * P&L功能Layout.xls公式验证表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2026-03-16
     */
    @Service
    @DS("finance")
    public class PlLayoutValidationServiceImpl extends ServiceImpl<PlLayoutValidationMapper, PlLayoutValidation> implements IPlLayoutValidationService {

        @Autowired
        private ObjectMapper objectMapper;

        /**
         * 根据资产id查询
         *
         * @param propertyId 资产id
         * @return java.util.List<cloud.wconnect.finance.entity.pl.PlLayoutValidation>
         * @author lichen
         * @date 2026-03-16
         */
        @Override
        public List<PlLayoutValidation> getByPropertyId(Integer propertyId) {
            return list(new LambdaQueryWrapper<PlLayoutValidation>().eq(PlLayoutValidation::getPropertyId, propertyId));
        }

        /**
         * 获取一组Account
         *
         * @param propertyId 资产id
         * @param m3Accounts Account数据集合
         * @param variables  Account的范围，{“start”:4000,"end":7999}
         * @return java.util.List<cloud.wconnect.finance.entity.pl.M3Account>
         * @author lichen
         * @date 2026-03-16
         */
        @Override
        public List<M3Account> getGroupAccount(Integer propertyId, List<M3Account> m3Accounts, String variables) {
            Map<String, Integer> hashMap = JsonUtils.convertStringByTypeReference(objectMapper, variables,
                    new TypeReference<>() {
                    });
            Integer start = hashMap.get("start");
            Integer end = hashMap.get("end");

            // 指定范围的Account
            return m3Accounts.stream().filter(m3Account -> {
                String accountNumber = m3Account.getAccountNumber();
                try {
                    int value = Integer.parseInt(accountNumber);
                    return value >= start && value <= end;
                } catch (Exception e) {
                    return false;
                }
            }).collect(Collectors.toList());
        }
    }