| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.hibernate.Session; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.bstek.bdf2.core.orm.hibernate.HibernateDao; |
| | | import com.bstek.dorado.data.entity.EntityState; |
| | | import com.bstek.dorado.data.entity.EntityUtils; |
| | |
| | | */ |
| | | @Component |
| | | public class BuildingService extends HibernateDao { |
| | | |
| | | String BEAN_ID = "core.buildingService"; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | |
| | | } |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | session.saveOrUpdate(data); |
| | | refreshCache(data.getCompanyId()); |
| | | refreshCache(data.getCompanyId(), data.getDeptId()); |
| | | } finally { |
| | | session.flush(); |
| | | session.close(); |
| | |
| | | } |
| | | } |
| | | |
| | | refreshCache(items.get(0).getCompanyId()); |
| | | refreshCache(items.get(0).getCompanyId(), items.get(0).getDeptId()); |
| | | } finally { |
| | | session.flush(); |
| | | session.close(); |
| | |
| | | List<Building> result = (List<Building>) redisUtil.get(key); |
| | | |
| | | if (null == result) { |
| | | refreshCache(companyId); |
| | | refreshCache(companyId, deptId); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | if(null == deptId) return result; |
| | | |
| | | return result.stream().filter(item -> item.getDeptId().equals(deptId)) |
| | | .collect(Collectors.toList()); |
| | | return result; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public Building getCacheBuilding(String companyId, String deptId, String buildingId) { |
| | | if(StringUtils.isEmpty(companyId)){ |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | |
| | | String key = RedisConst.buildKey(companyId, RedisConst.KEY_BUILDING_LIST); |
| | | |
| | | List<Building> result = (List<Building>) redisUtil.get(key); |
| | | |
| | | if (null == result) { |
| | | refreshCache(companyId, deptId); |
| | | |
| | | return null; |
| | | } |
| | | for (Building building : result) { |
| | | if(buildingId.equals(building.getId())){ |
| | | return building; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public void refreshCache(String companyId) { |
| | | public void refreshCache(String companyId, String deptId) { |
| | | Map<String, Object> parameter = new HashMap<String, Object>(); |
| | | parameter.put("companyId", companyId); |
| | | parameter.put("deptId", deptId); |
| | | List<Building> list = this.loadData(parameter); |
| | | |
| | | redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_BUILDING_LIST),list); |
| | | redisUtil.set(RedisConst.buildKey(companyId, deptId, RedisConst.KEY_BUILDING_LIST),list); |
| | | } |
| | | } |