| | |
| | | import com.bstek.dorado.data.entity.EntityState; |
| | | import com.bstek.dorado.data.entity.EntityUtils; |
| | | import com.bstek.dorado.data.provider.Page; |
| | | import com.fzzy.common.constant.BizTypeEnum; |
| | | 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 com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | 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 |
| | |
| | | @Component |
| | | public class DeviceIotPR { |
| | | |
| | | @Resource |
| | | private DeviceIotService deviceIotService; |
| | | @Resource |
| | | private DeviceIotService deviceIotService; |
| | | |
| | | /** |
| | | * 查询设备,将操作信息调整为空 |
| | | * |
| | | * deviceIotPR#loadDeviceIotPage |
| | | * |
| | | * @param page |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public void loadDeviceIotPage(Page<DeviceIot> page, Map<String, Object> param) { |
| | | if (null == param) { |
| | | param = new HashMap<>(); |
| | | } |
| | | Map<String, Object> finalParam = param; |
| | | /** |
| | | * 查询设备,将操作信息调整为空 |
| | | * <p> |
| | | * deviceIotPR#loadDeviceIotPage |
| | | * |
| | | * @param page |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | 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()); |
| | | |
| | | //多参数分页查询 |
| | | 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; |
| | | if (null == param) { |
| | | param = new DeviceIotParam(); |
| | | } |
| | | deviceIotService.listPageData(corePage, param); |
| | | |
| | | public Predicate toPredicate(Root<DeviceIot> root, CriteriaQuery<?> query, CriteriaBuilder cb) { |
| | | List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言 |
| | | // 重新封装 |
| | | page.setEntities(corePage.getRecords()); |
| | | page.setEntityCount(Integer.parseInt(String.valueOf(corePage.getTotal()))); |
| | | } |
| | | |
| | | Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId()); |
| | | predicates.add(predicate1); |
| | | predicate1 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null)); |
| | | predicates.add(predicate1); |
| | | /** |
| | | * 保存 devicePR#saveAll |
| | | * |
| | | * @param depotDeviceIots |
| | | * @return |
| | | */ |
| | | @DataResolver |
| | | @Transactional |
| | | @Log(title = "Iot设备配置", businessType = BusinessType.OTHER, bizType = BizTypeEnum.SYS) |
| | | public String saveAll(List<DeviceIot> depotDeviceIots) { |
| | | String msg = ""; |
| | | DeviceIot deviceIot; |
| | | for (DeviceIot depotDeviceIot : depotDeviceIots) { |
| | | EntityState state = EntityUtils.getState(depotDeviceIot); |
| | | deviceIot = new DeviceIot(); |
| | | BeanUtils.copyProperties(depotDeviceIot, deviceIot); |
| | | if (state == EntityState.NEW) { |
| | | deviceIotService.updateDeviceIot(deviceIot); |
| | | msg = "添加成功!"; |
| | | } |
| | | if (state == EntityState.DELETED) { |
| | | deviceIotService.delDepotDeviceIot(deviceIot); |
| | | msg = "删除成功!"; |
| | | } |
| | | if (state == EntityState.MODIFIED) { |
| | | deviceIotService.updateDeviceIot(deviceIot); |
| | | msg = "修改成功!"; |
| | | } |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | |
| | | /** |
| | | * 保存 devicePR#saveAll |
| | | * |
| | | * @param depotDeviceIots |
| | | * @return |
| | | */ |
| | | @DataResolver |
| | | @Transactional |
| | | public String saveAll(List<DeviceIot> depotDeviceIots) { |
| | | String msg = ""; |
| | | DeviceIot deviceIot; |
| | | for (DeviceIot depotDeviceIot : depotDeviceIots) { |
| | | EntityState state = EntityUtils.getState(depotDeviceIot); |
| | | deviceIot = new DeviceIot(); |
| | | BeanUtils.copyProperties(depotDeviceIot, deviceIot); |
| | | if (state == EntityState.NEW) { |
| | | deviceIotService.updateDeviceIot(deviceIot); |
| | | msg = "添加成功!"; |
| | | } |
| | | if (state == EntityState.DELETED) { |
| | | deviceIotService.delDepotDeviceIot(deviceIot); |
| | | msg = "删除成功!"; |
| | | } |
| | | if (state == EntityState.MODIFIED) { |
| | | deviceIotService.updateDeviceIot(deviceIot); |
| | | msg = "修改成功!"; |
| | | } |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | /** |
| | | * devicePR#refreshCache |
| | | */ |
| | | @Expose |
| | | public void refreshCache(){ |
| | | deviceIotService.refreshCache(null); |
| | | } |
| | | /** |
| | | * devicePR#refreshCache |
| | | */ |
| | | @Expose |
| | | public void refreshCache() { |
| | | deviceIotService.refreshCache(null); |
| | | } |
| | | } |