mybatisplus Wrapper

public QueryWrapper<EamMaintRequirementEntity> getWrapper(Map<String, Object> params) {
    QueryWrapper<EamMaintRequirementEntity> wrapper = new QueryWrapper<>();
    String keyWord = (String) params.get("keyWord");
    // 查询keyword不为空
    if (StringUtils.isNotEmpty(keyWord)) {
        // 构造查询条件
        wrapper.lambda().and(
                t -> t.like(EamMaintRequirementEntity::getEquipmentNo, keyWord)
                        .or().like(EamMaintRequirementEntity::getRequirementNo, keyWord)
                        .or().like(EamMaintRequirementEntity::getEquipmentName, keyWord)
        );
    }

    //状态筛选
    if (StringUtils.isNotEmpty((String) params.get("statusType"))) {
        wrapper.lambda().and(
                t -> t.eq(EamMaintRequirementEntity::getMaintTypeValue, "repair")
                        .or().eq(EamMaintRequirementEntity::getMaintTypeValue, "maintainance")
        );
        String statusType = (String) params.get("statusType");
        if (statusType.equals("unclosed")) {
            wrapper.lambda().and(
                    t -> t.eq(EamMaintRequirementEntity::getStatusCode, 2)
                            .or().eq(EamMaintRequirementEntity::getStatusCode, 25)
                            .or().eq(EamMaintRequirementEntity::getStatusCode, 6)
                            .or().eq(EamMaintRequirementEntity::getStatusCode, 8)
            );
        }
        if (statusType.equals("weekly")) {
            LocalDate currentDate = LocalDate.now().plusDays(1);
            LocalDate sevenDaysAgo = currentDate.minusDays(7);
            wrapper.lambda().and(
                    t -> t.ne(EamMaintRequirementEntity::getStatusCode, 2)
                            .ne(EamMaintRequirementEntity::getStatusCode, 25)
                            .ne(EamMaintRequirementEntity::getStatusCode, 6)
                            .ne(EamMaintRequirementEntity::getStatusCode, 8)
                            .between(EamMaintRequirementEntity::getCreateTime, sevenDaysAgo, currentDate)
            );
        }

    }

    wrapper.orderByDesc(true, "create_time");
    return wrapper;

-------------------------------------------------------------------------------------------------------------------

发表回复