package com.nokia.scenes.area;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.nokia.scenes.business.business1.mapper.shi.SuanFaMapper;
@SpringBootTest
@RunWith(SpringRunner.class)
public class getArea{
@Autowired
private SuanFaMapper suanFaMapper;
@Test
public void getDataFromResource(){
Double beadmwidth = 130.0;
Double outRadius = 200.0 * 0.000009;
Double inRadius = 0.0 * 0.000009;
List<Map<String, Object>> list = suanFaMapper.getDataFromRepo();
List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
for(int i = 0 ; i < list.size(); i++){
Map<String, Object> map = list.get(i);
if(map.get("longitude") != null && map.get("latitude") != null && map.get("azimuth") != null){
Double longitude = Double.parseDouble(to_String(map.get("longitude")));
Double latitude = Double.parseDouble(to_String(map.get("latitude")));
Double azimuth = Double.parseDouble(to_String(map.get("azimuth")));
String returnStr = getVmap("室外", longitude, latitude, azimuth, beadmwidth, outRadius, inRadius);
String str = returnStr.replaceAll(";", ",");
map.put("str", str);
resList.add(map);
}
}
int count = resList.size();
List<Map<String, Object>> sqlList = null;
int data = 1000;
int x = count / data;
int y = count % data;
int j = 1;
while(j <= x){
sqlList = new ArrayList<Map<String,Object>>();
for(int i = (j - 1) * 1000; i < j * 1000; i++){
sqlList.add(resList.get(i));
}
suanFaMapper.insertToTable(sqlList);
j++;
}
if(y != 0){
sqlList = new ArrayList<Map<String,Object>>();
for(int i = x * 1000; i < count; i++){
sqlList.add(resList.get(i));
}
suanFaMapper.insertToTable(sqlList);
}
System.out.println(resList.size());
}
// @Test
public void getData() {
double outRadius = 100 * 0.000009;
String str = getVmap("室外", 113.362950, 22.917890, 260.0, 130.0, outRadius, 0.0);
System.out.println(str);
}
// SITETYPE 覆盖类型(室内和室外) LONGITUDE 经度 LATITUDE 纬度 AZIMUTH 方位角 BEAMWIDTH 130
// outRadius 外经 (挂高*1.2) inRadius 内径 0
public static String getVmap(String SITETYPE, Double LONGITUDE, Double LATITUDE, Double AZIMUTH, Double BEAMWIDTH,
Double outRadius, Double inRadius) {
String vamp = "";
if (SITETYPE != null & SITETYPE.trim().equals("室外")) {
vamp = GetMarcoArcPoints(LONGITUDE, LATITUDE, AZIMUTH, BEAMWIDTH, outRadius, inRadius);
} else {
vamp = GetIndoorArcPoints(LONGITUDE, LATITUDE, outRadius, inRadius);
}
return vamp;
}
public static String getSGEO(String SITETYPE, Double LONGITUDE, Double LATITUDE, Double AZIMUTH, Double BEAMWIDTH,
Double outCAL_RADIUS, Double inCAL_RADIUS) {
String vmapnew = "";
if (SITETYPE != null & SITETYPE.trim().equals("室外")) {
vmapnew = GetMarcoArcPoints(LONGITUDE, LATITUDE, AZIMUTH, BEAMWIDTH, outCAL_RADIUS, inCAL_RADIUS);
} else {
vmapnew = GetIndoorArcPoints(LONGITUDE, LATITUDE, outCAL_RADIUS, inCAL_RADIUS);
}
vmapnew = vmapnew.replaceAll(";", ",");
if (vmapnew.length() > 0 & vmapnew.trim().substring(vmapnew.length() - 1, vmapnew.length()).equals(",")) {
vmapnew = vmapnew.substring(0, vmapnew.length() - 1);
}
return vmapnew;
}
public static String GetMarcoArcPoints(double x, double y, double dir, double bw, double outRadius,
double inRadius) {
String points = "";
DecimalFormat df2 = new DecimalFormat("#0.000000");
try {
String[] x1s = new String[5];
String[] y1s = new String[5];
for (int j = 1; j < 6; j++) {
double tx = x + outRadius * Math.cos(Math.PI / 180 * (90 - dir + (3 - j) * bw / 5));
x1s[j - 1] = df2.format(tx);
double ty = y + outRadius * Math.sin(Math.PI / 180 * (90 - dir + (3 - j) * bw / 5));
y1s[j - 1] = df2.format(ty);
;
}
if (inRadius == outRadius) {
points = df2.format(x) + " " + df2.format(y) + ";" + x1s[0] + " " + y1s[0] + ";" + x1s[1] + " " + y1s[1]
+ ";" + x1s[2] + " " + y1s[2] + ";" + x1s[3] + " " + y1s[3] + ";" + x1s[4] + " " + y1s[4];
} else {
String[] x2s = new String[5];
String[] y2s = new String[5];
for (int j = 1; j < 6; j++) {
double tx = x + inRadius * Math.cos(Math.PI / 180 * (90 - dir + (3 - j) * bw / 5));
x2s[j - 1] = df2.format(tx);
double ty = y + inRadius * Math.sin(Math.PI / 180 * (90 - dir + (3 - j) * bw / 5));
y2s[j - 1] = df2.format(ty);
}
points = df2.format(x) + " " + df2.format(y) + ";" + x1s[0] + " " + y1s[0] + ";" + x1s[1] + " " + y1s[1]
+ ";" + x1s[2] + " " + y1s[2] + ";" + x1s[3] + " " + y1s[3] + ";" + x1s[4] + " " + y1s[4] + ";"
+ df2.format(x) + " " + df2.format(y) + ";" + x2s[4] + " " + y2s[4] + ";" + x2s[3] + " "
+ y2s[3] + ";" + x2s[2] + " " + y2s[2] + ";" + x2s[1] + " " + y2s[1] + ";" + x2s[0] + " "
+ y2s[0];
}
} catch (Exception e) {
e.printStackTrace();
}
return points;
}
public static String GetIndoorArcPoints(double x, double y, double outRadius, double inRadius) {
String points = "";
DecimalFormat df2 = new DecimalFormat("#0.000000");
try {
String[] x1s = new String[3];
String[] y1s = new String[3];
double[] dirs = { 60, 180, 300 };
double bw = 120;
for (int i = 0; i < dirs.length; i++) {
double dir = dirs[i];
double tx = x + outRadius * Math.cos(Math.PI / 180 * (90 - dir + (9 - 1) * bw / 16));
x1s[i] = df2.format(tx);
double ty = y + outRadius * Math.sin(Math.PI / 180 * (90 - dir + (9 - 1) * bw / 16));
y1s[i] = df2.format(ty);
;
}
if (inRadius == outRadius) {
points = x1s[0] + " " + y1s[0] + ";" + x1s[1] + " " + y1s[1] + ";" + x1s[2] + " " + y1s[2];
} else {
String[] x2s = new String[3];
String[] y2s = new String[3];
for (int i = 0; i < dirs.length; i++) {
double dir = dirs[i];
double tx = x + inRadius * Math.cos(Math.PI / 180 * (90 - dir + (9 - 1) * bw / 16));
x2s[i] = df2.format(tx);
double ty = y + inRadius * Math.sin(Math.PI / 180 * (90 - dir + (9 - 1) * bw / 16));
y2s[i] = df2.format(ty);
;
}
points = x1s[0] + " " + y1s[0] + ";" + x1s[1] + " " + y1s[1] + ";" + x1s[2] + " " + y1s[2] + ";"
+ x1s[0] + " " + y1s[0] + ";" + x2s[0] + " " + y2s[0] + ";" + x2s[2] + " " + y2s[2] + ";"
+ x2s[1] + " " + y2s[1] + ";" + x2s[0] + " " + y2s[0];
}
} catch (Exception e) {
e.printStackTrace();
}
return points;
}
public String to_String(Object obj){
String str = "";
if(null != obj){
str = obj + "";
}
return str;
}
}