zeus常用dao操作:

1.省略if判断写法

1
2
3
4
Criteria criteria = Criteria.where(WaitingGetMaterial::getTaskId).ne("").
and(WaitingGetMaterial::getBusinessUnit).is(vo.getBusinessUnit(),Objects::nonNull)
.and(WaitingGetMaterial::getMarker).fullLike(vo.getMarker(), StringUtils::isNotBlank)
.and(WaitingGetMaterial::getMaterialName).is(name,Objects::nonNull);

2.添加两个互为或的条件

1
2
3
4
5
6
7
8
// 如果查询字符串不为空,添加模糊查询条件
if (StringUtils.isNotEmpty(dto.getQueryString())) {
Criteria orCriteria = Criteria.or(
Criteria.where(WarehouseHistory::getMarker).likedto.getQueryString() + "%"),
Criteria.where(WarehouseHistory::getProductName).likedto.getQueryString() + "%")
);
criteria = Criteria.and(criteria, orCriteria);
}

3.sort用法

1
2
3
4
5
6
7
8
9
10
11
Sort sort = null;
if(taskDTO.getTaskState() == 0){
criteria.and("task_state").in(Arrays.asList(2,3,5));
sort = new Sort(Sort.Direction.DESC, "task_state");
sort.and(new Sort(Sort.Direction.ASC,"release_time"));
}else{
criteria.and("task_state").is(4);
sort = new Sort(Sort.Direction.DESC,"sign_for_time");
}
return __findPage(Query.query(criteria).with(new PageRequest(taskDTO.getPageNum()-1 , taskDTO.getPageSize() ,sort)));

4.使用.ne排除

1
2
3
4
Criteria criteria = Criteria.where("del").is(false)
.and("business_people").in(userIds)
.and("order_state").ne(SaleOrderEnum.CANCEL.getCode()) // 1024新增 排除订单终止的
.and("is_external").is(false); // 1207新增 排除外加工销售订单

5.当执行修改操作不成功时直接抛出操作异常(继承运行时异常),简化校验代码,无需返回结果

1
2
3
4
5
6
7
8
9
 public void updateByIds(List<Long> intoWarehouseIdList, int state, boolean whetherComplete) {
IntoWarehouse build = IntoWarehouse.builder()
.state(state)
.whetherComplete(whetherComplete)
.build();
if (!super.__update(build, Criteria.where(IntoWarehouse::getId).in(intoWarehouseIdList)).isSuccess()) {
throw new OperationFailException();
}
}
1
2
3
4
5
6
7
8
9
10
11
public Page<ScrapApply> queryScrap(OnlineToolListRequest request) {
Criteria criteria = Criteria.where(ScrapApply::getDel).is(false);
Criteria orCriteria = null;
if (ObjectUtils.isNotEmpty(request.getQueryString())) {
orCriteria = Criteria.or(
Criteria.where(ScrapApply::getItemModel).like(request.getQueryString() + "%"),
Criteria.where(ScrapApply::getItemName).like(request.getQueryString() + "%"));
}
criteria = Criteria.and(criteria, orCriteria);
return findPage(Query.query(criteria).with(new PageRequest(request.getPageNum() - 1, request.getPageSize(),new Sort("create_time"))));
}