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

[核查模块] 修复了初始化自动核查的统计数据异常

上级 fc021738
package com.tykj.dev.device.confirmcheck.entity.cache;
import com.tykj.dev.device.user.subject.entity.Area;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* AreaCache.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/22 at 5:33 下午
*/
public class AreaCache {
private Map<String, Area> nameMap;
private Map<Integer, Area> idMap;
public AreaCache(List<Area> areaList) {
nameMap = areaList.stream().collect(Collectors.toMap(Area::getName, Function.identity()));
idMap = areaList.stream().collect(Collectors.toMap(Area::getId, Function.identity()));
}
public Area findFatherByName(String name) {
Area area = nameMap.get(name);
return idMap.get(area.getFatherId());
}
public Area findByName(String name) {
return nameMap.get(name);
}
public Area findById(Integer id) {
return idMap.get(id);
}
}
package com.tykj.dev.device.confirmcheck.entity.cache;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* CacheBeanConfig.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/22 at 6:24 下午
*/
@Configuration
public class CacheBeanConfig {
@Autowired
private AreaDao areaRepo;
@Bean
public AreaCache initAreaCache() {
return new AreaCache(areaRepo.findAll());
}
}
......@@ -49,4 +49,9 @@ public class CheckAreaStatVo {
* 该地区对应的详情账单id
*/
private int areaDetailId;
public CheckAreaStatVo addSuppose(int supposeCount) {
this.supposeCount += supposeCount;
return this;
}
}
......@@ -76,4 +76,9 @@ public class CheckDeviceStatVo {
return this;
}
public CheckDeviceStatVo addDeviceCount(int count){
this.deviceCount += count;
return this;
}
}
package com.tykj.dev.misc.utils;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* ObjectMapperUtils.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/22 at 7:05 下午
*/
public class MapperUtils {
private static ModelMapper modelMapper = new ModelMapper();
/**
* Model mapper property setting are specified in the following block.
* Default property matching strategy is set to Strict see {@link MatchingStrategies}
* Custom mappings are added using {@link ModelMapper#addMappings(PropertyMap)}
*/
static {
modelMapper = new ModelMapper();
modelMapper.getConfiguration().setAmbiguityIgnored(true);
//设置为严格匹配
modelMapper.getConfiguration().setFullTypeMatchingRequired(true);
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
}
/**
* Hide from public usage.
*/
private MapperUtils() {
}
/**
* <p>Note: outClass object must have default constructor with no arguments</p>
*
* @param <D> type of result object.
* @param <T> type of source object to map from.
* @param entity entity that needs to be mapped.
* @param outClass class of result object.
* @return new object of <code>outClass</code> type.
*/
public static <D, T> D map(final T entity, Class<D> outClass) {
return modelMapper.map(entity, outClass);
}
/**
* <p>Note: outClass object must have default constructor with no arguments</p>
*
* @param entityList list of entities that needs to be mapped
* @param outCLass class of result list element
* @param <D> type of objects in result list
* @param <T> type of entity in <code>entityList</code>
* @return list of mapped object with <code><D></code> type.
*/
public static <D, T> List<D> mapAll(final Collection<T> entityList, Class<D> outCLass) {
return entityList.stream()
.map(entity -> map(entity, outCLass))
.collect(Collectors.toList());
}
/**
* Maps {@code source} to {@code destination}.
*
* @param source object to map from
* @param destination object to map to
*/
public static <S, D> D map(final S source, D destination) {
modelMapper.map(source, destination);
return destination;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论