package com.zteits.park.dao.impl; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.geo.Point; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import com.clouds.common.cache.park.ParkingLotGeoCacheUtil; import com.clouds.common.utils.ListPageHelper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.apibase.constants.LonLatTypeEnum; import com.zteits.clouds.api.dto.park.param.ParkingLotGeoForPageRequest; import com.zteits.park.dao.ParkingLotGeoDao; import com.zteits.park.domain.Coordinate; import com.zteits.park.domain.ParkingLotGeo; import com.zteits.park.domain.ParkingLotGeoExample; import com.zteits.park.mapper.ParkingLotGeoMapper; import com.zteits.park.mapper.smapper.ParkingLotGeoSMapper; /** * Copyright: Copyright (c) 2017 zteits * * @ClassName: ParkingLotGeoDaoImpl.java * @Description: * @version: v1.0.0 * @author: langlw * @date: 2017年6月1日 上午9:55:00 * Modification History: * Date Author Version Description * ---------------------------------------------------------* * 2017年6月1日 langlw v1.0.0 创建 */ @Component public class ParkingLotGeoDaoImpl implements ParkingLotGeoDao { @Autowired private ParkingLotGeoMapper parkingLotGeoMapper; @Autowired private ParkingLotGeoSMapper parkingLotGeoSMapper; @Override public PageInfo queryParkingLotGeoForPage(ParkingLotGeoForPageRequest request) { // 1.设置分页信息 PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize()); //2.查询数据 ParkingLotGeo parkingLotGeo = new ParkingLotGeo(); BeanUtils.copyProperties(request, parkingLotGeo); List list = parkingLotGeoSMapper.queryParkingLotGeoForList(parkingLotGeo); return new PageInfo(list); } @Override public ParkingLotGeo queryParkingLotGeoByPrimaryKey(Long geoId) { return parkingLotGeoMapper.selectByPrimaryKey(geoId); } @Transactional @Override public Long saveOrModifyParkingLotGeo(ParkingLotGeo parkingLotGeo) { parkingLotGeo.setModifyTime(new Date()); Long flg = null; if (null == parkingLotGeo.getGeoId()) { parkingLotGeo.setCreateTime(new Date()); parkingLotGeo.setDataStatus(1); int flgNum = parkingLotGeoMapper.insertSelective(parkingLotGeo); if(flgNum > 0){ flg = 1L; } } else { int flgNum = parkingLotGeoMapper.updateByPrimaryKeySelective(parkingLotGeo); if(flgNum > 0){ flg = 1L; } } //把ID返回去--白取id,因为没有放值 return flg; } @Override public List queryParkingLotGeoByExample(ParkingLotGeoExample record) { return parkingLotGeoMapper.selectByExample(record); } @Override public Boolean deleteParkingLotGeoByPlNos(List plNos,Long opId) { ParkingLotGeoExample exampleGeo = new ParkingLotGeoExample(); ParkingLotGeo recordGeo = new ParkingLotGeo(); recordGeo.setDataStatus(DataStatusEnum.DATA_STATUS_NO_VALID.value()); recordGeo.setModifyTime(new Date()); recordGeo.setModifyOp(opId); exampleGeo.createCriteria().andPlNoIn(plNos); parkingLotGeoMapper.updateByExampleSelective(recordGeo, exampleGeo); /**删除redis中的经纬度.*/ plNos.forEach(plNo->{ ParkingLotGeoCacheUtil.deletePointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1, plNo); ParkingLotGeoCacheUtil.deletePointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_3, plNo); }); return true; } @Override public Boolean batchSaveParkingLotGeo(List lotGeos) { if (CollectionUtils.isEmpty(lotGeos)) { return true; } int savenum = parkingLotGeoSMapper.batchSaveParkingLotGeo(lotGeos); return savenum > 0 ? true : false; } @Override public Coordinate queryParkingLotGeoByParkNo(String pklNo,Integer lonLatType) { Coordinate coordinate = new Coordinate(); List points = Lists.newArrayList(); if(lonLatType == LonLatTypeEnum.LON_LAT_TYPE_1.value()){ points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1, pklNo); }else{ points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_3, pklNo); } if(CollectionUtils.isEmpty(points) || points.get(0) == null){ //查询数据库 List parkingLotGeos = parkingLotGeoSMapper.queryParkingLotGeoByParkNo(pklNo,null,lonLatType); if(!CollectionUtils.isEmpty(parkingLotGeos)){ ParkingLotGeo parkingLotGeo = parkingLotGeos.get(0); coordinate.setId(pklNo); if(parkingLotGeo!=null && parkingLotGeo.getLonId()!=null && parkingLotGeo.getLatId()!=null){ coordinate.setLon(parkingLotGeo.getLonId().doubleValue()); coordinate.setLat(parkingLotGeo.getLatId().doubleValue()); } else{ coordinate.setLon(0.0); coordinate.setLat(0.0); } } }else{ coordinate.setId(pklNo); coordinate.setLon(points.get(0).getX()); coordinate.setLat(points.get(0).getY()); } return coordinate; } @Override public Map> queryParkingLotGeoListByParkNos(List pklNos, Integer geoType,Integer lonLatType) { List list = new ArrayList(); ListPageHelper pageInfo = new ListPageHelper(pklNos, 500); for (int i = 1; i <= pageInfo.getTotalPages(); i++) { List ll = parkingLotGeoSMapper.queryParkingLotGeoListByParkNos(pklNos, geoType,lonLatType); if (!CollectionUtils.isEmpty(ll)) { list.addAll(ll); } } if(CollectionUtils.isEmpty(list)){ return new HashMap<>(); } Map> map = list.stream().collect(Collectors.groupingBy(ParkingLotGeo::getPlNo)); return map; } }