| | |
| | | import com.bstek.dorado.data.entity.EntityState; |
| | | import com.bstek.dorado.data.entity.EntityUtils; |
| | | import com.bstek.dorado.data.provider.Page; |
| | | import com.fzzy.igds.data.DeviceIotParam; |
| | | import com.fzzy.igds.domain.DeviceIot; |
| | | import com.fzzy.igds.service.DeviceIotService; |
| | | import com.fzzy.igds.utils.ContextUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.domain.PageRequest; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import javax.annotation.Resource; |
| | | import javax.persistence.criteria.CriteriaBuilder; |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Description |
| | |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public void loadDeviceIotPage(Page<DeviceIot> page, Map<String, Object> param) { |
| | | if (null == param) { |
| | | param = new HashMap<>(); |
| | | public void loadDeviceIotPage(Page<DeviceIot> page, DeviceIotParam param) { |
| | | com.baomidou.mybatisplus.extension.plugins.pagination.Page<DeviceIot> corePage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPageNo(), page.getPageSize()); |
| | | |
| | | if(null == param) { |
| | | param = new DeviceIotParam(); |
| | | } |
| | | Map<String, Object> finalParam = param; |
| | | deviceIotService.listPageData(corePage, param); |
| | | |
| | | //多参数分页查询 |
| | | Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.ASC, DeviceIot.SORT_PROP); |
| | | Specification<DeviceIot> specification = new Specification<DeviceIot>() { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public Predicate toPredicate(Root<DeviceIot> root, CriteriaQuery<?> query, CriteriaBuilder cb) { |
| | | List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言 |
| | | |
| | | Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId()); |
| | | predicates.add(predicate1); |
| | | predicate1 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null)); |
| | | predicates.add(predicate1); |
| | | |
| | | String key = (String) finalParam.get("depotId"); |
| | | if (StringUtils.isNotEmpty(key)) { |
| | | predicate1 = cb.equal(root.get("depotId"), key); |
| | | predicates.add(predicate1); |
| | | } |
| | | key = (String) finalParam.get("type"); |
| | | if (StringUtils.isNotEmpty(key)) { |
| | | predicate1 = cb.equal(root.get("type"), key); |
| | | predicates.add(predicate1); |
| | | } |
| | | key = (String) finalParam.get("serId"); |
| | | if (StringUtils.isNotEmpty(key)) { |
| | | predicate1 = cb.equal(root.get("serId"), key); |
| | | predicates.add(predicate1); |
| | | } |
| | | |
| | | return cb.and(predicates.toArray(new Predicate[0])); |
| | | } |
| | | }; |
| | | org.springframework.data.domain.Page<DeviceIot> japPage = deviceIotService.findAll(specification, pageable); |
| | | page.setEntityCount((int) japPage.getTotalElements()); |
| | | page.setEntities(japPage.getContent()); |
| | | // 重新封装 |
| | | page.setEntities(corePage.getRecords()); |
| | | page.setEntityCount(Integer.parseInt(String.valueOf(corePage.getTotal()))); |
| | | } |
| | | |
| | | /** |