package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.LocationMapper;
|
import com.stylefeng.guns.modular.system.dao.SiteMapper;
|
import com.stylefeng.guns.modular.system.model.Dispatch;
|
import com.stylefeng.guns.modular.system.model.Site;
|
import com.stylefeng.guns.modular.system.service.IDispatchService;
|
import com.stylefeng.guns.modular.system.service.ISiteService;
|
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
|
import com.stylefeng.guns.modular.system.warpper.SiteWarpper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
|
@Service
|
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {
|
|
@Resource
|
private SiteMapper siteMapper;
|
|
@Resource
|
private LocationMapper locationMapper;
|
|
@Autowired
|
private GDMapElectricFenceUtil gdMapElectricFenceUtil;
|
|
@Autowired
|
private IDispatchService dispatchService;
|
|
|
|
|
|
|
/**
|
* 获取站点
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<SiteWarpper> querySite(Integer startSiteId, Integer uid) throws Exception {
|
List<Map<String, Object>> sites = null;
|
Integer companyId = null;
|
Dispatch dispatch = dispatchService.selectById(uid);
|
if(dispatch.getFranchiseeId() == null || dispatch.getFranchiseeId().compareTo(0) == 0){
|
companyId = dispatch.getCompanyId();
|
}else{
|
companyId = dispatch.getFranchiseeId();
|
}
|
if(null == startSiteId){
|
sites = siteMapper.querySite(null, companyId);
|
}else{
|
sites = siteMapper.querySite(startSiteId, companyId);
|
}
|
Set<String> set = new HashSet<>();
|
for(Map<String, Object> site : sites) {
|
set.add(site.get("cityCode").toString());
|
}
|
|
List<SiteWarpper> list = new ArrayList<>();
|
for(String c : set){
|
SiteWarpper siteWarpper = new SiteWarpper();
|
List<Object> data = new ArrayList<>();
|
String name = "";
|
String code = "";
|
for(Map<String, Object> s : sites){
|
if(c.equals(s.get("cityCode").toString())){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", s.get("id"));
|
map.put("name", s.get("name").toString());
|
name = s.get("cityName").toString();
|
code = s.get("cityCode").toString();
|
data.add(map);
|
}
|
}
|
siteWarpper.setName(name);
|
siteWarpper.setCode(code);
|
siteWarpper.setSites(data);
|
list.add(siteWarpper);
|
}
|
return list;
|
}
|
|
|
/**
|
* 根据站点id获取地点区域
|
* @param siteId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryLocation(Integer siteId) throws Exception {
|
return locationMapper.queryLocation(siteId);
|
}
|
|
|
|
/**
|
* 判断点是都在区域范围内
|
* @param siteId
|
* @param code
|
* @param lonLat
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public boolean areaMonitoring(Integer siteId, Integer code, String lonLat) throws Exception {
|
List<Map<String, Object>> list = this.queryLocation(siteId);
|
String province = code.toString().substring(0, 2) + "0000";
|
String city = code.toString().substring(0, 4) + "00";
|
for(Map<String, Object> map : list){
|
if(Integer.valueOf(map.get("type").toString()) == 1){//行政区域
|
if(null != map.get("districtCode")){
|
if(code.toString().equals(map.get("districtCode").toString())){
|
return true;
|
}
|
continue;
|
}
|
if(null != map.get("cityCode")){
|
if(city.equals(map.get("cityCode").toString())){
|
return true;
|
}
|
continue;
|
}
|
if(null != map.get("provinceCode")){
|
if(province.equals(map.get("provinceCode").toString())){
|
return true;
|
}
|
continue;
|
}
|
}
|
if(Integer.valueOf(map.get("type").toString()) == 2){//电子围栏
|
List<String> list1 = gdMapElectricFenceUtil.monitorElectricFenc("", lonLat);
|
return list1.size() > 0 ? true : false;
|
}
|
}
|
return false;
|
}
|
}
|