Commit df81069f by 丁伟峰

bugfix:Class的生命周期是Spring在管理,在多次请求中,会复用;因此,2个hashmap,需要改成局部初始化模式;

1 parent 668794c0
...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.SkillGroupEntity; ...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.SkillGroupEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity; import com.dituhui.pea.order.entity.SkillInfoEntity;
import com.dituhui.pea.order.service.BusinessBaseService; import com.dituhui.pea.order.service.BusinessBaseService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -46,28 +47,14 @@ public class BusinessBaseServiceImpl implements BusinessBaseService { ...@@ -46,28 +47,14 @@ public class BusinessBaseServiceImpl implements BusinessBaseService {
@Override @Override
public Result<?> getSkillList(BusinessSkillListDTO.Request req) { public Result<?> getSkillList(BusinessSkillListDTO.Request req) {
Pageable pageable = PageRequest.of(req.getPage() - 1, req.getSize()); Pageable pageable = PageRequest.of(req.getPage() - 1, req.getSize());
this.initMaps();
Page<SkillInfoEntity> page = skillInfoDao.findAll(pageable); Page<SkillInfoEntity> page = skillInfoDao.findAll(pageable);
List<BusinessSkillListDTO.Content> contents = page.getContent().stream().map(e -> { List<BusinessSkillListDTO.Content> contents = page.getContent().stream().map(e -> {
return new BusinessSkillListDTO.Content() BusinessSkillListDTO.Content content = new BusinessSkillListDTO.Content();
.setSkillCode(e.getSkillCode()) BeanUtils.copyProperties(e, content);
.setBrand(e.getBrand()) content.setSkillGroupName(mapSkillGroup.get(e.getSkillCode()));
.setType(e.getType()) content.setLayerName(mapLayer.get(e.getLayerId()));
.setSkill(e.getSkill()) return content;
.setTakeTime(e.getTakeTime())
.setTakeEngineer(e.getTakeEngineer())
.setLowElectricianCert(e.getLowElectricianCert())
.setGasCert(e.getGasCert())
//.setPriority(e.getPriority())
.setSkillGroupCode(e.getSkillGroupCode())
.setSkillGroupName(this.getSkillGroupName(e.getSkillCode()))
.setLayerId(e.getLayerId())
.setLayerName(this.getLayerName(e.getLayerId()))
.setTypeCategory(e.getTypeCategory())
.setSkillCategory(e.getSkillCategory())
.setMemo(e.getMemo())
.setCreateTime(e.getCreateTime())
.setUpdateTime(e.getUpdateTime());
}).collect(Collectors.toList()); }).collect(Collectors.toList());
BusinessSkillListDTO.Result rs = new BusinessSkillListDTO.Result(); BusinessSkillListDTO.Result rs = new BusinessSkillListDTO.Result();
rs.setTotal(page.getTotalElements()) rs.setTotal(page.getTotalElements())
...@@ -88,18 +75,4 @@ public class BusinessBaseServiceImpl implements BusinessBaseService { ...@@ -88,18 +75,4 @@ public class BusinessBaseServiceImpl implements BusinessBaseService {
mapSkillGroup.putAll(skillGroupDao.findAll().stream().collect(Collectors.toMap(SkillGroupEntity::getSkillGroupCode, SkillGroupEntity::getSkillGroup))); mapSkillGroup.putAll(skillGroupDao.findAll().stream().collect(Collectors.toMap(SkillGroupEntity::getSkillGroupCode, SkillGroupEntity::getSkillGroup)));
log.info("initMaps ====> mapLayer ==> {}, mapSkillGroup ==> {}", mapLayer, mapSkillGroup); log.info("initMaps ====> mapLayer ==> {}, mapSkillGroup ==> {}", mapLayer, mapSkillGroup);
} }
String getLayerName(String layerId) {
if (mapLayer == null) {
initMaps();
}
return mapLayer.get(layerId);
}
String getSkillGroupName(String skillGroupCode) {
if (mapSkillGroup == null) {
initMaps();
}
return mapSkillGroup.get(skillGroupCode);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!