# FdProcedureCheckServiceImpl.java

    package cloud.wconnect.workperformance.service.fdprocedurecheck.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.internationalization.InternationalizationDateTimeDTO;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.workperformance.cons.fdprocedurecheck.FdProcedureCheckHandledResultEnum;
    import cloud.wconnect.workperformance.cons.fdprocedurecheck.FdProcedureCheckI18nConstant;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheck;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckComment;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckErrorType;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckProblemDesc;
    import cloud.wconnect.workperformance.mapper.fdprocedurecheck.FdProcedureCheckMapper;
    import cloud.wconnect.workperformance.pojo.dto.fdprocedurecheck.*;
    import cloud.wconnect.workperformance.pojo.query.fdprocedurecheck.FdProcedureCheckQuery;
    import cloud.wconnect.workperformance.pojo.vo.fdprocedurecheck.FdProcedureCheckVO;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckCommentService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckErrorTypeService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckProblemDescService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
    import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.google.common.collect.Sets;
    import jakarta.annotation.Resource;
    import org.apache.commons.collections.CollectionUtils;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.context.i18n.LocaleContextHolder;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.text.MessageFormat;
    import java.util.*;
    import java.util.function.Function;
    import java.util.stream.Collectors;

    /**
     * <p>
     * FD Procedure Check 服务实现类
     * </p>
     *
     * @author zc
     * @since 2023-10-05
     */
    @Service
    @DS("work_performance")
    public class FdProcedureCheckServiceImpl extends ServiceImpl<FdProcedureCheckMapper, FdProcedureCheck> implements IFdProcedureCheckService {
        @Resource
        private IFdProcedureCheckErrorTypeService fdProcedureCheckErrorTypeService;
        @Resource
        private IFdProcedureCheckProblemDescService fdProcedureCheckProblemDescService;
        @Resource
        private IFdProcedureCheckCommentService fdProcedureCheckCommentService;
        @Resource
        private PropertyInternalService propertyInternalService;
        @Resource
        private I18nMessageUtils i18nMessageUtils;
        @Resource
        private UserInternalService userInternalService;
        @Resource
        private BeanMapper beanMapper;

        /**
         * 校验 Error Type 是否已被使用
         *
         * @param propertyId  资产 id
         * @param errorTypeId Error Type id
         * @author zc
         * @date 2023/10/5
         */
        @Override
        public void checkErrorTypeInUse(int propertyId, int errorTypeId) {
            FdProcedureCheck fdProcedureCheck = getOne(new QueryWrapper<FdProcedureCheck>().lambda()
                    .eq(FdProcedureCheck::getPropertyId, propertyId)
                    .eq(FdProcedureCheck::getErrorTypeId, errorTypeId)
                    .last("limit 1"));
            if (Objects.nonNull(fdProcedureCheck)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_IS_IN_USE,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The errorType has been used and cannot be deleted");
            }
        }

        /**
         * 校验 Problem Description 是否已被使用
         *
         * @param propertyId    资产 id
         * @param problemDescId Problem Description id
         * @author zc
         * @date 2023/10/5
         */
        @Override
        public void checkProblemDescInUse(int propertyId, int problemDescId) {
            FdProcedureCheck fdProcedureCheck = getOne(new QueryWrapper<FdProcedureCheck>().lambda()
                    .eq(FdProcedureCheck::getPropertyId, propertyId)
                    .eq(FdProcedureCheck::getProblemDescId, problemDescId)
                    .last("limit 1"));
            if (Objects.nonNull(fdProcedureCheck)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_IS_IN_USE,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The problemDesc has been used and cannot be deleted");
            }
        }

        /**
         * 获取 FD Procedure Check
         *
         * @param tenantId            租户 id
         * @param propertyId          资产 id
         * @param procedureCheckQuery 查询条件
         * @return FdProcedureCheckDTO 集合
         * @author zc
         * @date 2023/10/6
         */
        @Override
        public ListPagedDTO<FdProcedureCheckDTO> list(int tenantId, int propertyId, FdProcedureCheckQuery procedureCheckQuery) {
            // 组装查询语句
            LambdaQueryWrapper<FdProcedureCheck> queryWrapper = packageQueryWrapper(propertyId, procedureCheckQuery);
            Page<FdProcedureCheck> page = page(new Page<>(procedureCheckQuery.getPage(),
                    procedureCheckQuery.getSize()), queryWrapper);

            List<FdProcedureCheck> procedureCheckList = page.getRecords();
            if (CollectionUtils.isEmpty(procedureCheckList)) {
                return new ListPagedDTO<>();
            }

            // 提取 Error Type
            Map<Integer, FdProcedureCheckErrorType> id2ErrorType = extractErrorType(procedureCheckList);

            // 提取 Problem Description
            Map<Integer, FdProcedureCheckProblemDesc> id2ProblemDesc = extractProblemDesc(procedureCheckList);

            // 提取用户名称
            Map<Integer, String> userId2UserName = extractUserName(tenantId, procedureCheckList);

            // 获取评论数量
            Map<Long, Long> fdId2CommentsCount = fdProcedureCheckCommentService.getCommentsCountByFdIds(propertyId,
                    procedureCheckList.stream().map(FdProcedureCheck::getId).toList());

            return new ListPagedDTO<>(page.getTotal(), beanMapper.mapList(procedureCheckList,
                    FdProcedureCheckDTO.class, (item, dto) -> {
                        dto.setFdName(Objects.nonNull(item.getFdNameUserId()) ?
                                userId2UserName.get(item.getFdNameUserId()) : null);
                        dto.setFdReview(Objects.nonNull(item.getFdReviewUserId()) ?
                                userId2UserName.get(item.getFdReviewUserId()) : null);
                        dto.setCommentsCount(fdId2CommentsCount.getOrDefault(item.getId(), BaseConstant.LONG_ZERO));

                        // 组装 Error Type
                        FdProcedureCheckErrorType errorType = id2ErrorType.get(item.getErrorTypeId());
                        if (Objects.nonNull(errorType)) {
                            dto.setErrorType(beanMapper.map(errorType, FdProcedureCheckErrorTypeDTO.class));
                        }
                        // 组装 Problem Description
                        FdProcedureCheckProblemDesc problemDesc = id2ProblemDesc.get(item.getProblemDescId());
                        if (Objects.nonNull(problemDesc)) {
                            dto.setProblemDesc(beanMapper.map(problemDesc, FdProcedureCheckProblemDescriptionDTO.class));
                        }
                        // 组装 Handled
                        dto.setHandled(FdProcedureCheckOperatorDTO.builder()
                                .userId(item.getHandledBy())
                                .userName(userId2UserName.get(item.getHandledBy()))
                                .operateTime(item.getHandledTime())
                                .build());
                        // 组装 Confirmed
                        dto.setConfirmed(FdProcedureCheckOperatorDTO.builder()
                                .userId(item.getConfirmedBy())
                                .userName(userId2UserName.get(item.getConfirmedBy()))
                                .operateTime(item.getConfirmedTime())
                                .build());
                    }));
        }

        /**
         * 提取 Error Type
         *
         * @param procedureCheckList Procedure Check 数据
         * @return Error Type
         * @author zc
         * @date 2023/10/6
         */
        private Map<Integer, FdProcedureCheckErrorType> extractErrorType(List<FdProcedureCheck> procedureCheckList) {
            List<Integer> errorTypeIds = procedureCheckList.stream().map(FdProcedureCheck::getErrorTypeId)
                    .filter(item -> item > BaseConstant.ZERO).toList();
            if (CollectionUtils.isEmpty(errorTypeIds)) {
                return Collections.emptyMap();
            }
            return fdProcedureCheckErrorTypeService.listByIds(errorTypeIds).stream()
                    .collect(Collectors.toMap(FdProcedureCheckErrorType::getId, Function.identity()));
        }

        /**
         * 提取 Problem Desc
         *
         * @param procedureCheckList Procedure Check 数据
         * @return Problem Desc
         * @author zc
         * @date 2023/10/6
         */
        private Map<Integer, FdProcedureCheckProblemDesc> extractProblemDesc(List<FdProcedureCheck> procedureCheckList) {
            List<Integer> problemDescIds = procedureCheckList.stream().map(FdProcedureCheck::getProblemDescId)
                    .filter(item -> item > BaseConstant.ZERO).toList();
            if (CollectionUtils.isEmpty(problemDescIds)) {
                return Collections.emptyMap();
            }
            return fdProcedureCheckProblemDescService.listByIds(problemDescIds).stream()
                    .collect(Collectors.toMap(FdProcedureCheckProblemDesc::getId, Function.identity()));
        }

        /**
         * 提取用户名称
         *
         * @param tenantId           租户 id
         * @param procedureCheckList Procedure Check 数据
         * @return 用户名称
         * @author zc
         * @date 2023/10/6
         */
        private Map<Integer, String> extractUserName(int tenantId, List<FdProcedureCheck> procedureCheckList) {
            Set<Integer> userIds = Sets.newHashSet();
            procedureCheckList.forEach(item -> {
                userIds.add(item.getFdNameUserId());
                if (Objects.nonNull(item.getFdReviewUserId())) {
                    userIds.add(item.getFdReviewUserId());
                }
                userIds.add(item.getCreatedBy());
                userIds.add(item.getHandledBy());
            });
            return userInternalService.getNameMapByIds(tenantId, userIds.stream()
                    .filter(item -> item > BaseConstant.ZERO).toList());
        }

        /**
         * 组装查询语句
         *
         * @param propertyId          资产 id
         * @param procedureCheckQuery 查询条件
         * @return queryWrapper
         * @author zc
         * @date 2023/10/6
         */
        private LambdaQueryWrapper<FdProcedureCheck> packageQueryWrapper(int propertyId, FdProcedureCheckQuery procedureCheckQuery) {
            LambdaQueryWrapper<FdProcedureCheck> queryWrapper = new QueryWrapper<FdProcedureCheck>().lambda()
                    .eq(FdProcedureCheck::getPropertyId, propertyId)
                    .ge(Objects.nonNull(procedureCheckQuery.getFromDate()),
                            FdProcedureCheck::getTheDate, procedureCheckQuery.getFromDate())
                    .le(Objects.nonNull(procedureCheckQuery.getEndDate()),
                            FdProcedureCheck::getTheDate, procedureCheckQuery.getEndDate())
                    .eq(Objects.nonNull(procedureCheckQuery.getHandledResult()),
                            FdProcedureCheck::getHandledResult, procedureCheckQuery.getHandledResult());
            List<Integer> types = procedureCheckQuery.getTypes();
            if (CollectionUtils.isNotEmpty(types)) {
                if (types.contains(FdProcedureCheckQuery.TYPE_FD_NAME) || types.contains(FdProcedureCheckQuery.TYPE_FD_AFTER_REVIEW)) {
                    if (Objects.nonNull(procedureCheckQuery.getUserId())) {
                        queryWrapper.and(wrapper -> wrapper
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_FD_NAME),
                                        FdProcedureCheck::getFdNameUserId, procedureCheckQuery.getUserId())
                                .or()
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_FD_AFTER_REVIEW),
                                        FdProcedureCheck::getFdReviewUserId, procedureCheckQuery.getUserId())
                                .or()
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_NOT_SURE),
                                        FdProcedureCheck::getFdNameUserId, BaseConstant.ZERO)
                                .or()
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_N_A),
                                        FdProcedureCheck::getFdReviewUserId, BaseConstant.ZERO));
                    } else {
                        queryWrapper.and(wrapper -> wrapper
                                .gt(types.contains(FdProcedureCheckQuery.TYPE_FD_NAME),
                                        FdProcedureCheck::getFdNameUserId, BaseConstant.ZERO)
                                .or()
                                .gt(types.contains(FdProcedureCheckQuery.TYPE_FD_AFTER_REVIEW),
                                        FdProcedureCheck::getFdReviewUserId, BaseConstant.ZERO)
                                .or()
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_NOT_SURE),
                                        FdProcedureCheck::getFdNameUserId, BaseConstant.ZERO)
                                .or()
                                .eq(types.contains(FdProcedureCheckQuery.TYPE_N_A),
                                        FdProcedureCheck::getFdReviewUserId, BaseConstant.ZERO));
                    }
                } else if (types.contains(FdProcedureCheckQuery.TYPE_NOT_SURE) || types.contains(FdProcedureCheckQuery.TYPE_N_A)) {
                    queryWrapper.and(wrapper -> wrapper
                            .eq(types.contains(FdProcedureCheckQuery.TYPE_NOT_SURE),
                                    FdProcedureCheck::getFdNameUserId, BaseConstant.ZERO)
                            .or()
                            .eq(types.contains(FdProcedureCheckQuery.TYPE_N_A),
                                    FdProcedureCheck::getFdReviewUserId, BaseConstant.ZERO));
                }
            }
            return queryWrapper.orderByAsc(FdProcedureCheck::getTheDate);
        }

        /**
         * 新增 FD Procedure Check 数据
         *
         * @param propertyId            资产 id
         * @param operatorId            操作人 id
         * @param procedureCheckSaveDTO 数据内容
         * @author zc
         * @date 2023/10/6
         */
        @Override
        public void add(int propertyId, int operatorId, FdProcedureCheckSaveDTO procedureCheckSaveDTO) {
            save(beanMapper.map(procedureCheckSaveDTO, FdProcedureCheck.class, item -> {
                item.setPropertyId(propertyId);
                item.setCreatedBy(operatorId);
                item.setCreatedTime(DateTimeUtils.nowTimestamp());
            }));
        }

        /**
         * 校验 FD Procedure Check 数据是否存在
         *
         * @param id FD Procedure Check id
         * @return FdProcedureCheck
         * @author zc
         * @date 2023/10/6
         */
        @Override
        public FdProcedureCheck checkExist(long id) {
            FdProcedureCheck procedureCheck = getById(id);
            if (Objects.isNull(procedureCheck)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The procedureCheck is not found; id: " + id);
            }
            return procedureCheck;
        }

        /**
         * 校验数据归属
         *
         * @param propertyId       资产 id
         * @param fdProcedureCheck Fd Procedure Check 数据
         * @author zc
         * @date 2023/10/6
         */
        @Override
        public void checkBelong(int propertyId, FdProcedureCheck fdProcedureCheck) {
            if (!fdProcedureCheck.getPropertyId().equals(propertyId)) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(),
                        MessageFormat.format("The fdProcedureCheck does not belong to this property; propertyId:{0}; fdProcedureCheckId:{1}",
                                propertyId, fdProcedureCheck.getId()));
            }
        }

        /**
         * 更新数据
         *
         * @param operatorId            操作人 id
         * @param procedureCheckSaveDTO 更新内容
         * @author zc
         * @date 2023/10/6
         */
        @Override
        public void update(int operatorId, FdProcedureCheckSaveDTO procedureCheckSaveDTO) {
            LambdaUpdateWrapper<FdProcedureCheck> updateWrapper = new UpdateWrapper<FdProcedureCheck>().lambda()
                    .eq(FdProcedureCheck::getId, procedureCheckSaveDTO.getId())
                    .set(FdProcedureCheck::getLostPoint, procedureCheckSaveDTO.getLostPoint())
                    .set(FdProcedureCheck::getUpdatedBy, operatorId)
                    .set(FdProcedureCheck::getUpdatedTime, DateTimeUtils.nowTimestamp());

            update(beanMapper.map(procedureCheckSaveDTO, FdProcedureCheck.class), updateWrapper);
        }

        /**
         * 删除数据
         *
         * @param id Fd Procedure Check id
         * @author zc
         * @date 2023/10/6
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void delete(long id) {
            // 删除数据
            removeById(id);

            // 删除评论
            fdProcedureCheckCommentService.deleteByFdId(id);
        }

        /**
         * 确认 FD Procedure Check
         *
         * @param id         Fd Procedure Check id
         * @param operatorId 操作人 id
         * @author zc
         * @date 2023/10/7
         */
        @Override
        public void confirm(long id, int operatorId) {
            updateById(FdProcedureCheck.builder()
                    .id(id)
                    .confirmedBy(operatorId)
                    .confirmedTime(DateTimeUtils.nowTimestamp())
                    .build());
        }

        /**
         * 变更 FOM's clarification
         *
         * @param propertyId                资产 id
         * @param id                        Fd Procedure Check id
         * @param changeFomClarificationDTO 变更数据
         * @param operatorId                操作人 id
         * @author zc
         * @date 2023/10/7
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void changeFomClarification(int propertyId, long id, ChangeFomClarificationDTO changeFomClarificationDTO, int operatorId) {
            long nowTimestamp = DateTimeUtils.nowTimestamp();

            FdProcedureCheck fdProcedureCheck = new FdProcedureCheck();
            fdProcedureCheck.setId(id);
            fdProcedureCheck.setHandledResult(changeFomClarificationDTO.getHandledResult());
            fdProcedureCheck.setHandledBy(operatorId);
            fdProcedureCheck.setHandledTime(nowTimestamp);
            // 若 Handled Result = 2: Confirm，需要清空原确认人、确认时间
            if (changeFomClarificationDTO.getHandledResult().equals(FdProcedureCheckHandledResultEnum.CONFIRM.getStatus())) {
                fdProcedureCheck.setConfirmedBy(0);
                fdProcedureCheck.setConfirmedTime(0L);
            }
            // 更新数据
            updateById(fdProcedureCheck);

            // 保存评论数据
            if (StringUtils.isNotBlank(changeFomClarificationDTO.getComment())) {
                fdProcedureCheckCommentService.save(FdProcedureCheckComment.builder()
                        .propertyId(propertyId)
                        .fdId(id)
                        .comment(changeFomClarificationDTO.getComment())
                        .createdBy(operatorId)
                        .createdTime(nowTimestamp)
                        .build());
            }
        }

        /**
         * 获取导出数据
         *
         * @param propertyId          资产 id
         * @param procedureCheckQuery 查询条件
         * @return FdProcedureCheckVO 集合
         * @author zc
         * @date 2023/10/7
         */
        @Override
        public List<FdProcedureCheckVO> exportList(int propertyId, FdProcedureCheckQuery procedureCheckQuery) {
            // 获取数据
            List<FdProcedureCheck> procedureCheckList = list(packageQueryWrapper(propertyId, procedureCheckQuery));
            if (CollectionUtils.isEmpty(procedureCheckList)) {
                return Collections.emptyList();
            }
            PropertyDTO propertyDTO = propertyInternalService.getOne(propertyId);

            // 转换为 VO
            return convertToVo(propertyDTO, LocaleContextHolder.getLocale(), procedureCheckList);
        }

        /**
         * 转换为 VO
         *
         * @param propertyDTO        资产
         * @param local              local
         * @param procedureCheckList 数据
         * @return FdProcedureCheckVO 集合
         * @author zc
         * @date 2024/10/30
         */
        @Override
        public List<FdProcedureCheckVO> convertToVo(PropertyDTO propertyDTO, Locale local, List<FdProcedureCheck> procedureCheckList) {
            InternationalizationDateTimeDTO dateTimeDTO = propertyDTO.getInternationalization().getDateTime();
            // 提取 Error Type
            Map<Integer, FdProcedureCheckErrorType> id2ErrorType = extractErrorType(procedureCheckList);

            // 提取 Problem Description
            Map<Integer, FdProcedureCheckProblemDesc> id2ProblemDesc = extractProblemDesc(procedureCheckList);

            // 提取用户名称
            Map<Integer, String> userId2UserName = extractUserName(propertyDTO.getTenantId(), procedureCheckList);

            String notSure = i18nMessageUtils.message(FdProcedureCheckI18nConstant.NOT_SURE, local);
            String na = i18nMessageUtils.message(FdProcedureCheckI18nConstant.NA, local);

            // 组装返回数据
            return procedureCheckList.stream().map(item -> {
                FdProcedureCheckErrorType errorType = id2ErrorType.get(item.getErrorTypeId());
                FdProcedureCheckProblemDesc problemDesc = id2ProblemDesc.get(item.getProblemDescId());
                return FdProcedureCheckVO.builder()
                        .theDate(InternationalizationUtils.formatDateTime(item.getTheDate(), dateTimeDTO.getLongDate(), StringUtils.EMPTY,
                                propertyDTO.getTimezone(), local))
                        .lostPoint(item.getLostPoint())
                        .fdName(Objects.nonNull(item.getFdNameUserId()) ?
                                userId2UserName.getOrDefault(item.getFdNameUserId(), notSure) : "--")
                        .fdReview(Objects.nonNull(item.getFdReviewUserId()) ?
                                userId2UserName.getOrDefault(item.getFdReviewUserId(), na) : "--")
                        .reservation(item.getReservation())
                        .errorType(Objects.isNull(errorType) ? StringUtils.EMPTY : errorType.getLabel())
                        .errorTypeAdditional(item.getErrorTypeAdditional())
                        .problemDesc(Objects.isNull(problemDesc) ? StringUtils.EMPTY : problemDesc.getLabel())
                        .problemDescAdditional(item.getProblemDescAdditional())
                        .revLost(item.getRevLost())
                        .nightAuditNote(item.getNightAuditNote())
                        .handledResult(i18nMessageUtils.message(FdProcedureCheckHandledResultEnum.getI18nCode(item.getHandledResult()), local))
                        .build();
            }).toList();
        }

        /**
         * 根据状态获取数据
         *
         * @param propertyId    资产 id
         * @param handledResult 处理结果
         * @param limit         限制条数
         * @return FdProcedureCheck 集合
         * @author zc
         * @date 2024/11/13
         */
        @Override
        public List<FdProcedureCheck> listLimitByStatus(int propertyId, int handledResult, int limit) {
            return list(new QueryWrapper<FdProcedureCheck>().lambda()
                    .eq(FdProcedureCheck::getPropertyId, propertyId)
                    .eq(FdProcedureCheck::getHandledResult, handledResult)
                    .orderByDesc(FdProcedureCheck::getTheDate)
                    .last("LIMIT " + limit));
        }

        /**
         * 根据状态获取总数
         *
         * @param propertyId 资产 id
         * @param status     状态
         * @return 总数
         * @author zc
         * @date 2024/11/13
         */
        @Override
        public long getTotalByStatus(int propertyId, int status) {
            return count(new LambdaQueryWrapper<FdProcedureCheck>()
                    .eq(FdProcedureCheck::getPropertyId, propertyId)
                    .eq(FdProcedureCheck::getHandledResult, status));
        }
    }