Search in sources :

Example 1 with Pagination

use of com.diboot.core.vo.Pagination in project diboot by dibo-software.

the class TestIssue72 method testQueryPage.

@Test
public void testQueryPage() {
    PurchaseFormPlanQueryDto pfpQueryDto = new PurchaseFormPlanQueryDto();
    pfpQueryDto.setGoodsNm("abcd");
    QueryWrapper<DbPurchaseFormPlan> queryWrapper = QueryBuilder.toQueryWrapper(pfpQueryDto);
    // svc + DTO qw + Bo.class 查询 bo
    // bo必须要有所有this.xxx fields.
    // Invalid property 'purchaseFormPlanId' of bean class [club.walnuts.pms.data.bo.DbPurchaseFormPlanBo]
    Pagination pagination = new Pagination(1);
    pagination.setPageSize(10);
    // 前端传入total 缓存,本次不计算。
    // pagination.setTotalCount(100);
    // 默认asc, pagination.setOrderBy("orderBy=shortName:DESC,age:ASC,birthdate");
    pagination.setOrderBy("purchase_form_plan_id");
    // ### SQL: SELECT purchase_form_plan_id, goods_id FROM tbl_purchase_rel_plan_goods WHERE deleted = 0 AND (purchase_form_plan_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) AND tenant_id = 1
    // ### Cause: java.sql.SQLSyntaxErrorException: Unknown column 'deleted' in 'where clause'
    List<DbPurchaseFormPlanVO> p2 = dbPurchaseFormPlanSvc.getViewObjectList(queryWrapper, pagination, DbPurchaseFormPlanVO.class);
    Assert.assertTrue(p2 != null && p2.get(0).getName() != null);
}
Also used : PurchaseFormPlanQueryDto(diboot.core.test.binder.dto.PurchaseFormPlanQueryDto) Pagination(com.diboot.core.vo.Pagination) DbPurchaseFormPlanVO(diboot.core.test.binder.vo.DbPurchaseFormPlanVO) DbPurchaseFormPlan(diboot.core.test.binder.entity.DbPurchaseFormPlan) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Pagination

use of com.diboot.core.vo.Pagination in project diboot by dibo-software.

the class JsonTest method testJsonResult.

@Test
public void testJsonResult() {
    User user = new User();
    user.setId(123L);
    user.setUsername("zhangs").setCreateTime(new Date());
    user.setBirthdate(D.convert2Date("1988-09-12 12:34"));
    List<User> userList = new ArrayList<>();
    userList.add(user);
    Pagination pagination = new Pagination();
    pagination.setTotalCount(100).setPageIndex(2);
    JsonResult jsonResult = JsonResult.OK(userList).bindPagination(pagination);
    String jsonStr = JSON.toJSONString(jsonResult);
    PagingJsonResult pagingJsonResult = JSON.toJavaObject(jsonStr, PagingJsonResult.class);
    Assert.assertTrue(pagingJsonResult.getPage().getPageIndex() == 2);
    List<User> userList1 = (List<User>) pagingJsonResult.getData();
    Assert.assertTrue(userList1 != null && userList1.size() == 1);
}
Also used : Pagination(com.diboot.core.vo.Pagination) User(diboot.core.test.binder.entity.User) PagingJsonResult(com.diboot.core.vo.PagingJsonResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date) PagingJsonResult(com.diboot.core.vo.PagingJsonResult) JsonResult(com.diboot.core.vo.JsonResult) Test(org.junit.Test)

Example 3 with Pagination

use of com.diboot.core.vo.Pagination in project diboot by dibo-software.

the class TestJoinQuery method testDynamicSqlQuery.

@Test
public void testDynamicSqlQuery() {
    // 初始化DTO,测试不涉及关联的情况
    DepartmentDTO dto = new DepartmentDTO();
    dto.setParentId(10001L);
    // 验证 转换后的wrapper可以直接查询
    QueryWrapper<DepartmentDTO> queryWrapper = QueryBuilder.toQueryWrapper(dto);
    QueryWrapper<Department> deptQueryWrapper = new QueryWrapper<>();
    deptQueryWrapper.eq("parent_id", 10001L);
    List<Department> departments = departmentService.list(deptQueryWrapper);
    Assert.assertTrue(departments.size() == 3);
    // builder直接查询,不分页 3条结果
    List<Department> builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class);
    Assert.assertTrue(builderResultList.size() == 3);
    // 初始化DTO
    dto = new DepartmentDTO();
    dto.setParentId(10001L);
    dto.setParentName("产品部");
    // boolean类型
    dto.setOrgName("苏州帝博");
    // 验证直接查询指定字段
    List<String> fields = Arrays.asList("parentId", "parentName", "orgName");
    builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto, fields).queryList(Department.class);
    Assert.assertTrue(builderResultList.size() == 3);
    // 转换为queryWrapper
    queryWrapper.clear();
    queryWrapper = QueryBuilder.toQueryWrapper(dto);
    queryWrapper.select("id,name,parent_id,org_id");
    // 查询单条记录
    Department department = Binder.joinQueryOne(queryWrapper, Department.class);
    Assert.assertTrue(department.getName() != null);
    // 不分页 3条结果
    List<Department> list = JoinsBinder.queryList(queryWrapper, Department.class);
    Assert.assertTrue(list.size() == 3);
    // 不分页,直接用wrapper查
    list = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class);
    Assert.assertTrue(list.size() == 3);
    // 测试继续绑定VO  是否有影响
    List<DepartmentVO> voList = Binder.convertAndBindRelations(list, DepartmentVO.class);
    Assert.assertTrue(voList.size() == 3);
    Assert.assertTrue(voList.get(0).getDepartment() != null);
    Assert.assertTrue(voList.get(0).getOrganizationVO() != null);
    // 分页
    Pagination pagination = new Pagination();
    pagination.setPageSize(2);
    pagination.setPageIndex(1);
    // 第一页  2条结果
    list = Binder.joinQueryList(queryWrapper, Department.class, pagination);
    Assert.assertTrue(list.size() == pagination.getPageSize());
    // 测试排序
    pagination.setOrderBy("orgName:DESC,parentName");
    pagination.setPageIndex(2);
    // 第二页 1条结果
    list = Binder.joinQueryList(queryWrapper, Department.class, pagination);
    Assert.assertTrue(list.size() == 1);
}
Also used : DepartmentDTO(diboot.core.test.binder.dto.DepartmentDTO) Pagination(com.diboot.core.vo.Pagination) Department(diboot.core.test.binder.entity.Department) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DepartmentVO(diboot.core.test.binder.vo.DepartmentVO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Pagination (com.diboot.core.vo.Pagination)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 JsonResult (com.diboot.core.vo.JsonResult)1 PagingJsonResult (com.diboot.core.vo.PagingJsonResult)1 DepartmentDTO (diboot.core.test.binder.dto.DepartmentDTO)1 PurchaseFormPlanQueryDto (diboot.core.test.binder.dto.PurchaseFormPlanQueryDto)1 DbPurchaseFormPlan (diboot.core.test.binder.entity.DbPurchaseFormPlan)1 Department (diboot.core.test.binder.entity.Department)1 User (diboot.core.test.binder.entity.User)1 DbPurchaseFormPlanVO (diboot.core.test.binder.vo.DbPurchaseFormPlanVO)1 DepartmentVO (diboot.core.test.binder.vo.DepartmentVO)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1