提交 8eca049f authored 作者: zhoushaopan's avatar zhoushaopan

feat(装备模块): 构建条件构造器

构建条件构造器
上级 dd0485c6
......@@ -425,7 +425,7 @@ public class DeviceLibraryController {
@ApiOperation(value = "模糊查询日常管理装备父子分页", notes = "可以通过这个接口查询装备列表")
@PostMapping("/core/feature/summary/daily")
public ResponseEntity selectDailyDevicePage(@RequestBody DeviceLibrarySelectVo deviceLibrarySelectVo) {
public ResponseEntity selectDailyDevicePage(@RequestBody DeviceLibrarySelectVo deviceLibrarySelectVo){
Boolean hasModelDim = deviceLibrarySelectVo.getModelDim()!=null;
Boolean hasNameDim = deviceLibrarySelectVo.getNameDim()!=null;
Boolean hasSeqDim = deviceLibrarySelectVo.getSeqDim()!=null;
......@@ -438,8 +438,8 @@ public class DeviceLibraryController {
Boolean hasTypeDim = deviceLibrarySelectVo.getTypeDim() != null;
Map<String,Object> map = new HashMap<>();
List<DeviceLibrary> resultList = deviceLibraryService.getList(deviceLibrarySelectVo);
// List<DeviceLibrary> resultList = deviceLibraryService.getList(deviceLibrarySelectVo);
List<DeviceLibrary> resultList = deviceLibraryService.getAlldevList(deviceLibrarySelectVo);
resultList.forEach(DeviceLibrary::setConfigName);
if (hasModelDim||hasLifeStatusDim||hasLocationUnitDim||hasNameDim||hasOwnUnitDim||hasSeqDim) {
resultList = resultList.stream().filter(deviceLibrary -> {
......
......@@ -483,4 +483,6 @@ public interface DeviceLibraryService {
* 更新装备的状态 正式和试用
*/
void updateTry(List<DeviceLibrary> deviceLibraries);
List<DeviceLibrary> getAlldevList(DeviceLibrarySelectVo deviceLibrarySelectVo);
}
package com.tykj.dev.device.library.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.dev.blockcha.subject.entity.BcHash;
......@@ -24,6 +25,7 @@ import com.tykj.dev.device.user.subject.service.UserPublicService;
import com.tykj.dev.device.user.util.UserUtils;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
......@@ -36,6 +38,7 @@ import org.springframework.stereotype.Service;
import javax.persistence.Transient;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
......@@ -47,6 +50,7 @@ import static java.util.stream.Collectors.groupingBy;
* @author dengdiyi
*/
@Service
@Slf4j
public class DeviceLibraryServiceImpl implements DeviceLibraryService {
@Autowired
......@@ -1035,6 +1039,26 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
});
}
@Override
public List<DeviceLibrary> getAlldevList(DeviceLibrarySelectVo deviceLibrarySelectVo) {
List<DeviceLibrary> deviceLibraryList = cacheLibraryService.getAllDeviceLibraryList();
List<Integer> status = new ArrayList<>(Arrays.asList(2, 11, 14));
String currentUserUnitName = userUtils.getCurrentUserUnitName();
deviceLibraryList = deviceLibraryList.stream().filter(deviceLibrary -> deviceLibrary.getOwnUnit().equals(currentUserUnitName)
&&deviceLibrary.getLocationUnit().equals(currentUserUnitName))
.filter(deviceLibrary -> status.contains(deviceLibrary.getLifeStatus()) )
.collect(Collectors.toList());
List list = null;
try {
long l = System.currentTimeMillis();
list = filterFields(deviceLibraryList, deviceLibrarySelectVo);
log.info("过滤时间为:{}"+(System.currentTimeMillis()-l));
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
// @Override
// @UpdateCache
// public int updatePartParentId(List<Integer> deviceIds) {
......@@ -1211,5 +1235,58 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
private List<DeviceStatisticsVo> selectByName(String name, List<DeviceStatisticsVo> deviceStatisticsVos) {
return deviceStatisticsVos.stream().filter(deviceStatisticsVo -> deviceStatisticsVo.getName().equals(name)).collect(Collectors.toList());
}
private List<DeviceLibrary> getAllDevww(DeviceLibrarySelectVo deviceLibrarySelectVo) throws Exception {
List<DeviceLibrary> deviceLibraryList = cacheLibraryService.getAllDeviceLibraryList();
long l = System.currentTimeMillis();
List<DeviceLibrary> list = filterFields(deviceLibraryList, deviceLibrarySelectVo);
log.info("过滤时间为:{}",(System.currentTimeMillis()-l));
return list;
}
public List<DeviceLibrary> filterFields(List<DeviceLibrary> list,DeviceLibrarySelectVo params) throws Exception {
Method[] methods = params.getClass().getMethods();
// getUserName getPassWord
List<Method> useMethods = Arrays.stream(methods).filter(method -> !method.getName().equals("getClass")
&& method.getName().startsWith("get")).collect(Collectors.toList());
// Map<String,Object> filterFields = new HashMap<>();
//获取参数不为空的集合 如 username = "张三",password = "123456" age = "null"
Set<String> nameMethods = new HashSet<>();
for (DeviceLibrary deviceLibrary : list) {
for (Method declaredField : deviceLibrary.getClass().getDeclaredMethods()) {
nameMethods.add(declaredField.getName());
}
}
for (Method useMethod : useMethods) {
Object invoke = params.getClass().getMethod(useMethod.getName()).invoke(params);
//判断是否为空
if (ObjectUtil.isNotNull(invoke)) {
if (invoke instanceof ArrayList){
if (((ArrayList<?>) invoke).size() == 3){
list = list;
}
}else {
if (nameMethods.contains(useMethod.getName())) {
list = list.stream().filter(deviceLibrary1 -> {
try {
Object invoke1 = deviceLibrary1.getClass().getMethod(useMethod.getName())
.invoke(deviceLibrary1);
//判断是不是同一个
if (ObjectUtil.equal(invoke, invoke1) || ObjectUtil.contains(invoke1, invoke)) {
return true;
}
} catch (Exception e) {
}
return false;
}).collect(Collectors.toList());
}
}
}
}
return list;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论