提交 ea9ff455 authored 作者: Matrix's avatar Matrix

[核查模块] 修复了核查速度过慢的问题

上级 ba71042a
package com.tykj.dev.device.confirmcheck.common;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* UnitAreaBean.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/1/18 at 4:45 下午
*/
@Configuration
public class UnitAreaBean {
@Autowired
private AreaDao areaDao;
@Autowired
private UnitsDao unitsDao;
@Bean(name = "unMap")
public Map<String, AreaUnit> unitNameMap(){
return unitsDao.findAll().stream()
.map(unit -> {
int areaId = unitsDao.findAreaIdByName(unit.getName());
Area area = areaDao.findById(areaId).get();
return new AreaUnit(area, unit);
}).collect(Collectors.toMap(AreaUnit::getUnitName, Function.identity()));
}
}
...@@ -17,6 +17,7 @@ import com.tykj.dev.device.user.subject.dao.AreaDao; ...@@ -17,6 +17,7 @@ import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao; import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.dao.UserDao; import com.tykj.dev.device.user.subject.dao.UserDao;
import com.tykj.dev.device.user.subject.entity.User; import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import com.tykj.dev.device.user.subject.service.AuService; import com.tykj.dev.device.user.subject.service.AuService;
import com.tykj.dev.misc.base.BeanHelper; import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.base.BusinessEnum; import com.tykj.dev.misc.base.BusinessEnum;
...@@ -29,11 +30,9 @@ import org.springframework.stereotype.Component; ...@@ -29,11 +30,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -67,6 +66,9 @@ public class ObjTransUtil { ...@@ -67,6 +66,9 @@ public class ObjTransUtil {
@Autowired @Autowired
private TaskDao taskDao; private TaskDao taskDao;
@Resource(name = "unMap")
private Map<String, AreaUnit> unMap;
/** /**
* 装备转化为初始化的装备统计类 * 装备转化为初始化的装备统计类
...@@ -76,8 +78,8 @@ public class ObjTransUtil { ...@@ -76,8 +78,8 @@ public class ObjTransUtil {
*/ */
public CheckDeviceStatVo device2InitStatVo(DeviceLibrary device) { public CheckDeviceStatVo device2InitStatVo(DeviceLibrary device) {
String ownUnit = device.getOwnUnit(); String ownUnit = device.getOwnUnit();
int areaId = unitRepo.findAreaIdByName(ownUnit); // 这里选择从初始化集合中获取
String areaName = areaRepo.findNameById(areaId); String areaName = unMap.get(ownUnit).getName();
List<CheckAreaStatVo> areaStatList = Lists.newArrayList(new CheckAreaStatVo(areaName, 0, 1, 0, 0, 0, 0)); List<CheckAreaStatVo> areaStatList = Lists.newArrayList(new CheckAreaStatVo(areaName, 0, 1, 0, 0, 0, 0));
return new CheckDeviceStatVo(device.getModel(), device.getName(), 1, areaStatList); return new CheckDeviceStatVo(device.getModel(), device.getName(), 1, areaStatList);
} }
......
...@@ -29,6 +29,8 @@ public class AreaUnit { ...@@ -29,6 +29,8 @@ public class AreaUnit {
private Integer fatherId; private Integer fatherId;
private String unitName;
/** /**
* 默认等于{@link #unitList}里的第一个元素 * 默认等于{@link #unitList}里的第一个元素
*/ */
...@@ -45,6 +47,7 @@ public class AreaUnit { ...@@ -45,6 +47,7 @@ public class AreaUnit {
this.type = area.getType(); this.type = area.getType();
this.orders = area.getOrders(); this.orders = area.getOrders();
this.fatherId = area.getFatherId(); this.fatherId = area.getFatherId();
this.unitName = units.getName();
this.unit = new Unit(units.getUnitId(), units.getName(), units.getUnitDesc(), units.getCode()); this.unit = new Unit(units.getUnitId(), units.getName(), units.getUnitDesc(), units.getCode());
this.unitList = Lists.newArrayList(this.unit); this.unitList = Lists.newArrayList(this.unit);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论