一周总结

14次阅读

共计 2342 个字符,预计需要花费 6 分钟才能阅读完成。

引言

各个项目接近尾声,收尾工作其实并不是一件简单的事情,在此对本周的一些小问题进行一下总结。

器具别名显示问题

后台加入软删除,在前台器具类别管理中删除器具别名时,因加入软删除删除时 deleted 字段改为true,但是查询时没有对其加入限制,所以全部显示

  1. 想法
    感觉没什么难度,后台使用我们强大的综合查询直接吧deleted 字段 set false 就行了。
  2. 实现

      public Page<InstrumentCategory> getAll(String name, Long subjectCategoryId, Pageable pageable) {logger.debug("设置查询条件");
            InstrumentAlias instrumentAlias = new InstrumentAlias();
            InstrumentCategory instrumentCategory = new InstrumentCategory();
            CommonService.setAllFieldsToNull(instrumentCategory);
            CommonService.setAllFieldsToNull(instrumentAlias);
            instrumentCategory.setName(name);
            instrumentAlias.setDeleted(false);
            instrumentCategory.setInstrumentAliasList(Collections.singletonList(instrumentAlias));
            SubjectCategory subjectCategory = subjectCategoryRepository.findById(subjectCategoryId).orElse(null);
            instrumentCategory.setSubjectCategory(subjectCategory);
    
            return (Page<InstrumentCategory>) yunzhiService.page(instrumentCategoryRepository, instrumentCategory, pageable);
        }

    然而处于我综合查询知道的少之又少,只知道它查询快为好用,却不知道不支持一对多和多对多查询

  3. 只能在前台或者后台自己手动的去处理,实现如下:
 // 过滤 InstrumentAlias,显示 deleted 字段为 false 的
    public filterInstrumentAlias() {this.instrumentCategoryList.content.forEach((instrumentCategory: InstrumentCategory) => {this.instrumentAliasList = instrumentCategory.instrumentAliasList.filter((instrumentAlias: InstrumentAlias) => {return instrumentAlias.deleted === false;});
            instrumentCategory.instrumentAliasList = this.instrumentAliasList;
        });
    }

    // 过滤 InstrumentSpecification,显示 deleted 字段为 false 的
    public filterInstrumentSpecification() {this.instrumentCategoryList.content.forEach((instrumentCategory: InstrumentCategory) => {this.instrumentSpecificationList = instrumentCategory.instrumentSpecificationsList.filter((instrumentSpecification: InstrumentSpecification) => {return instrumentSpecification.deleted === false;});
            instrumentCategory.instrumentSpecificationsList = this.instrumentSpecificationList;
        });
    }

总结

虽然没什么问题,我觉得在对一件事,一个项目或者一个需求,你了解多少,你就可以少走多少弯路,甚至可以体现出你在其中的价值、地位。

实现只有正常状态才能发送申请

最初的实现:

    // 判断器具状态显示正常时才能发起申请
    public showVerificationApplication() {this.instrumentPage.content.forEach((instrument) => {if (instrument.state === this.defaultStatus) {this.show = true;} else {this.show = false;}
        });
    }

这样是有问题的,当没有器具的时候就不执行了,会存在问题
改进:

    // 判断器具状态显示正常时才能发起申请
    public showVerificationApplication() {if (this.params.state === this.defaultStatus) {this.show = true;} else {this.show = false;}
    }

在偶然间张喜硕组长的一句提示,让我觉的自身的不足(考虑为什么我当时没有想到);

总结

自己的想法考虑的太不全面,有时候看问题只看到表面,一个小小的问题就可能困惑我,不能换个角度去思考,在想法和思想上还有待提高

正文完
 0

一周总结

14次阅读

共计 683 个字符,预计需要花费 2 分钟才能阅读完成。

又到了一周写汇报的时候,细细想来,这周的状态其实不太好,然后又因为报了驾校,课余时间又得分出去一部分,所以这周的项目进展主要是在靠学长和潘哥的推动,自己只写了几个小功能。就简单的总结一下这周遇到的问题。
observable 未订阅
在项目中写了一个 http 请求的函数,但是无论如何这个函数就是没有网络请求,后来偶然发现没有订阅 observable,订阅一下就可以了。通过这件事牢牢记住了 obervable 的对象必须订阅。
使用 timer() 遇到的坑
timer 定时器是很好用的,但由于开始对 angular 的生命周期和 timer 不太熟悉,费了好长时间才在学长和潘哥的帮助下解决遇到的一个 bug。
在说 bug 之前先简单的说说 timer 怎么使用。
timner 的简单用法
想要完整的学习,自然得通过官方文档的方式, 但只是想简单使用,可以参照下面:
先定义一个 Subscription

定义定时器的操作

一个简单的定时器就完成了。
突然出现的报错
在计算列表为空的情况下会发出带数据的请求。

开始怎么检查都觉得代码没问题,找不到他产生的原因,研究了半天,发现他是几个一出现几个一出现,而且几个任务执行的间隔绝对不到定时器执行的时间,学长突然想到了是不是 timer 不会随着组件销毁而销毁,经过测试果然是这样。

angular 生命周期
既然定时器不能自动销毁,只能靠我们自己销毁了,这时候就要用到 ngOnDestroy, 当组件销毁时,主动去取消 timer 的订阅。
/**
* 组件销毁方法
*/
public ngOnDestroy() {
// 取消定时器订阅
this.yunzhiTimer.unsubscribe();
}

正文完
 0