Browse Source

修复bug,写企业架构树界面

Bitliker 9 years ago
parent
commit
36c2ffe856

+ 1 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/MyApplication.java

@@ -14,7 +14,6 @@ import android.util.Log;
 import com.android.volley.RequestQueue;
 import com.android.volley.toolbox.Volley;
 import com.baidu.mapapi.SDKInitializer;
-import com.baidu.mapapi.model.LatLng;
 import com.facebook.stetho.Stetho;
 import com.lidroid.xutils.DbUtils;
 import com.lidroid.xutils.HttpUtils;
@@ -401,6 +400,7 @@ public class MyApplication extends Application {
         return dataCacheMap.get(key);
     }
 
+
     /**
      * 移除本地缓存
      *

+ 1 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/presenter/AddFlihtsPresenter.java

@@ -40,13 +40,13 @@ public class AddFlihtsPresenter {
 
     public void start(Intent intent) {
         model = intent.getParcelableExtra("data");
+        isUpdate = intent.getBooleanExtra("isUpdate", false);
         String title = null;
         if (model == null) {
             title = "新增班次";
             model = new FlightsModel();
         } else {
             title = "修改班次";
-            FlightsTimeModel timeModel = model.getTimeModel();
             if (model.getEmployeesModel() != null)
                 iAddFlihtsView.updateMunber(model.getEmployeesModel().getEmployeeNames());
             if (model.getHrorgsModel() != null)

+ 39 - 32
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/presenter/WorkPresenter.java

@@ -55,9 +55,11 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
     private String loaction;
     private String address;
 
-    private double companyLatitude;
-    private double companyLongitude;
-    private int companyDistance;
+    //    private double companyLatitude;
+//    private double companyLongitude;
+//    private int companyDistance;
+    private List<WorkLocationBean> locationList;
+    private WorkLocationBean companyLocation;
 
     private boolean isMacInNet = false;//服务器上是否有mac地址
     private boolean isSubmiting = false;
@@ -154,7 +156,6 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
 
     //设置位置信息
     private void setBaiduLocation() throws Exception {
-        log("setBaiduLocation");
         boolean isLocation = MyApplication.getInstance().getBdLocationHelper().locationOk();
         if (!isLocation) {
             if (iWorkView != null) {
@@ -175,10 +176,17 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
     //获取与公司距离
     private String getDistance() {
         try {
-            String dis = getInstence().getDistance(companyLongitude, companyLatitude, latitude, longitude);
-            distance = Double.valueOf(dis);
-            if (StringUtils.isEmpty(dis)) return "";
-            return "约" + dis + "米";
+            if (ListUtils.isEmpty(locationList)) return "";
+            for (WorkLocationBean b : locationList) {
+                String dis = getInstence().getDistance(b.getLatitude(), b.getLongitude(),
+                        latitude, longitude);
+                if (StringUtils.isEmpty(dis)) continue;
+                if (distance == 0 || distance > Double.valueOf(dis)) {
+                    distance = Double.valueOf(dis);
+                    companyLocation = b;
+                }
+            }
+            return "约" + distance + "米";
         } catch (Exception e) {
             return "";
         }
@@ -187,21 +195,26 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
     private final int ADDRESS_CHANGE = 0x14;
 
     public void gotoLocationActivity(Activity ct) {
+        if (companyLocation == null) {
+            iWorkView.showToast("没有可以选择的地址", R.color.load_error);
+            return;
+        }
         Intent intent = new Intent(ct, LocationSearchActivity.class);
         intent.putExtra("type", 1);
         intent.putExtra("title", "地点微调");
         intent.putExtra("single", true);
         intent.putExtra("radius", 300);
         intent.putExtra("isSort", true);
-        intent.putExtra("latlng", new LatLng(companyLongitude, companyLatitude));
+        intent.putExtra("latlng", companyLocation.getLatitude());
         intent.putExtra("resultCode", ADDRESS_CHANGE);
         intent.putExtra("resultName", "resultName");
         ct.startActivityForResult(intent, ADDRESS_CHANGE);
     }
 
     private void getPoi() {
+        if (companyLocation == null) return;
         //公司地址必须反过来
-        final LatLng compayLng = new LatLng(companyLongitude, companyLatitude);
+        final LatLng compayLng = new LatLng(companyLocation.getLongitude(), companyLocation.getLatitude());
         LatLng latLng = new LatLng(latitude, longitude);
         BaiduMapUtil.getInstence().getNearInfo(500, 0, latLng,
                 "公司", new BaiduMapUtil.OnSearchPoiListener() {
@@ -212,7 +225,7 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
                             if (ListUtils.isEmpty(pois)) return;
                             for (int i = 0; i < pois.size(); i++) {
                                 double dis = BaiduMapUtil.getInstence().distance(compayLng, pois.get(i).location);
-                                if (companyDistance < dis) {
+                                if (companyLocation.getInnerdistance() < dis) {
                                     pois.remove(i);
                                     i--;
                                 }
@@ -239,27 +252,17 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
             return;
         }
         JSONObject object = JSON.parseObject(message);
-        int innerdistance = handerLocation(object);
+        handerLocation(object);
         isFree = object.getBoolean("ifNeedSignCard");
         if (isFree) {
             loadLog(null, time);
             return;
         }
-        boolean comaddressset = object.getBooleanValue("comaddressset");
-        if (comaddressset) {
-            companyLongitude = object.getDoubleValue("longitude");
-            companyLatitude = object.getDoubleValue("latitude");
-            companyDistance = object.getIntValue("distance");
-            innerdistance = object.getIntValue("innerdistance");
-        }
         try {
-            getPoi();
-            if (companyLongitude == 0 || companyLatitude == 0 && iWorkView != null)
+            if (ListUtils.isEmpty(locationList) && iWorkView != null)
                 iWorkView.showToast(R.string.not_addr_message, R.color.load_warning);
-            PreferenceUtils.putInt("distance", companyDistance);
-            PreferenceUtils.putInt("innerdistance", innerdistance);
-            PreferenceUtils.putFloat("longitude", (float) companyLongitude);
-            PreferenceUtils.putFloat("latitude", (float) companyLatitude);
+            else getPoi();
+
             setBaiduLocation();
         } catch (ClassCastException e) {
             if (e != null)
@@ -290,17 +293,20 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
         loadLog(models, time);
     }
 
-    private int handerLocation(JSONObject object) {
+    private void handerLocation(JSONObject object) {
         JSONArray array = object.getJSONArray("comAddressdata");
         if (ListUtils.isEmpty(array)) {
             //TODO 为空时候
-            return 0;
+            return;
         }
-        List<WorkLocationBean> beanList = new ArrayList<>();
+        if (ListUtils.isEmpty(locationList))
+            locationList = new ArrayList<>();
+        else locationList.clear();
         WorkLocationBean bean = null;
         JSONObject o = null;
         float dis = 0;
         for (int i = 0; i < array.size(); i++) {
+            o = array.getJSONObject(i);
             bean = new WorkLocationBean();
             int id = o.getInteger("CS_ID");
             int innerdistance = o.getInteger("CS_INNERDISTANCE");//办公距离
@@ -316,15 +322,16 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
             bean.setShortName(shortname);
             bean.setWorkaddr(workaddr);
             bean.setInnerdistance(innerdistance);
-            beanList.add(bean);
+            locationList.add(bean);
             if (dis == 0) {
                 dis = BaiduMapUtil.getInstence().autoDistance(location);
+                companyLocation = bean;
             } else if (dis > BaiduMapUtil.getInstence().autoDistance(location)) {
                 dis = BaiduMapUtil.getInstence().autoDistance(location);
+                companyLocation = bean;
             }
         }
-        boolean saveOk = WorkLocationDao.getInstance().clearAndInsert(beanList);
-        return 0;
+        boolean saveOk = WorkLocationDao.getInstance().clearAndInsert(locationList);
     }
 
     /**
@@ -496,7 +503,7 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
             if (iWorkView != null)
                 iWorkView.showToast(R.string.not_signin_agin, R.color.load_warning);
             return false;
-        } else if (companyDistance == 0 || distance == 0 || companyDistance < distance) {
+        } else if (distance == 0 || companyLocation == null || companyLocation.getInnerdistance() < distance) {
             if (iWorkView != null)
                 iWorkView.showToast(R.string.too_long, R.color.load_warning);
             return false;

+ 43 - 26
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/util/auto/AutoErpSigninUitl.java

@@ -15,7 +15,9 @@ import com.xzjmyk.pm.activity.AppConfig;
 import com.xzjmyk.pm.activity.BdLocationHelper;
 import com.xzjmyk.pm.activity.MyApplication;
 import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.bean.oa.WorkLocationBean;
 import com.xzjmyk.pm.activity.db.dao.MissionDao;
+import com.xzjmyk.pm.activity.db.dao.WorkLocationDao;
 import com.xzjmyk.pm.activity.db.dao.WorkModelDao;
 import com.xzjmyk.pm.activity.ui.MainActivity;
 import com.xzjmyk.pm.activity.ui.erp.activity.oa.MissionActivity;
@@ -177,9 +179,9 @@ public class AutoErpSigninUitl implements HttpHandler.OnResultListener {
                 address = PreferenceUtils.getString("bdaddress");
             form.put("cl_address", address);
             form.put("cl_location", "android自动打卡记录");
-            int comDistance = PreferenceUtils.getInt("distance", 0);
-            float distance = BaiduMapUtil.getInstence().getDistance();
-            if (comDistance < distance) {
+//            int comDistance = PreferenceUtils.getInt("distance", 0);
+            float distance= BaiduMapUtil.getInstence().getDistance();
+            if (distance==0) {
                 //TODO 规定地址<实际地址  不符合
                 //判断是否有外勤
                 boolean isOutPlan = PreferenceUtils.getBoolean(AppConfig.HAVE_OUT_PLAN, false);
@@ -585,29 +587,7 @@ public class AutoErpSigninUitl implements HttpHandler.OnResultListener {
             return;
         }
         JSONObject object = JSON.parseObject(message);
-        boolean comaddressset = object.getBooleanValue("comaddressset");
-        double companyLongitude = 0;
-        double companyLatitude = 0;
-        int companyDistance = 0;
-        int innerdistance = 0;
-        if (comaddressset) {
-            companyLongitude = object.getDoubleValue("longitude");
-            companyLatitude = object.getDoubleValue("latitude");
-            companyDistance = object.getIntValue("distance");
-            innerdistance = object.getIntValue("innerdistance");
-        }
-        try {
-            PreferenceUtils.putInt("distance", companyDistance);
-            PreferenceUtils.putInt("innerdistance", innerdistance);
-            PreferenceUtils.putFloat("longitude", (float) companyLongitude);
-            PreferenceUtils.putFloat("latitude", (float) companyLatitude);
-        } catch (ClassCastException e) {
-            if (e != null)
-                log("handlerWorkData ClassCastException=" + e.getMessage());
-        } catch (Exception e) {
-            if (e != null)
-                log("handlerWorkData Exception=" + e.getMessage());
-        }
+        handerLocation(object);
         ArrayList<WorkModel> models = new ArrayList<>();
         if (object.containsKey("wd_degree")) {//有排班
             if (object.containsKey("Class1")) {
@@ -626,6 +606,43 @@ public class AutoErpSigninUitl implements HttpHandler.OnResultListener {
         loadLog(models);
     }
 
+
+    private void handerLocation(JSONObject object) {
+        JSONArray array = object.getJSONArray("comAddressdata");
+        if (ListUtils.isEmpty(array)) {
+            //TODO 为空时候
+            return ;
+        }
+        List<WorkLocationBean> beanList = new ArrayList<>();
+        WorkLocationBean bean = null;
+        JSONObject o = null;
+        float dis = 0;
+        for (int i = 0; i < array.size(); i++) {
+            o=array.getJSONObject(i);
+            bean = new WorkLocationBean();
+            int id = o.getInteger("CS_ID");
+            int innerdistance = o.getInteger("CS_INNERDISTANCE");//办公距离
+            double latitude = o.getDouble("CS_LATITUDE");//精度
+            double longitude = o.getDouble("CS_LONGITUDE");//纬度
+            LatLng location = new LatLng(latitude, longitude);
+            String validrange = o.getString("CS_VALIDRANGE");//打卡范围
+            String shortname = o.getString("CS_SHORTNAME");//位置
+            String workaddr = o.getString("CS_WORKADDR");//地址
+            bean.setId(id);
+            bean.setLocation(location);
+            bean.setValidrange(Integer.valueOf(validrange));
+            bean.setShortName(shortname);
+            bean.setWorkaddr(workaddr);
+            bean.setInnerdistance(innerdistance);
+            beanList.add(bean);
+            if (dis == 0) {
+                dis = BaiduMapUtil.getInstence().autoDistance(location);
+            } else if (dis > BaiduMapUtil.getInstence().autoDistance(location)) {
+                dis = BaiduMapUtil.getInstence().autoDistance(location);
+            }
+        }
+        boolean saveOk = WorkLocationDao.getInstance().clearAndInsert(beanList);
+    }
     /**
      * 处理班次情况,简化代码  分开函数
      *

+ 3 - 15
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/util/auto/ReckonAutoUtil.java

@@ -82,24 +82,14 @@ public class ReckonAutoUtil {
         long offEnd = getTimeByHHmm(model.getOffend());
 
         if (workStart < System.currentTimeMillis() && workEnd > System.currentTimeMillis()) {
-            int comDistance = PreferenceUtils.getInt(MyApplication.getInstance(), "distance", 0);//规定距离
-            if (comDistance == 0) {
-                //TODO  公司距离为空
-                return null;
-            }
             //公司规定范围 大于当前位置范围
-            boolean is = comDistance > BaiduMapUtil.getInstence().getDistance() &&
+            boolean is = BaiduMapUtil.getInstence().isInWorkPlce() &&
                     StringUtils.isEmpty(model.getWorkSignin());
             if (is)
                 return model;
         } else if (offStart < System.currentTimeMillis() && offEnd > System.currentTimeMillis()) {
-            int comDistance = PreferenceUtils.getInt(MyApplication.getInstance(), "distance", 0);//规定距离
-            if (comDistance == 0) {
-                //TODO  公司距离为空
-                return null;
-            }
             //公司规定范围 大于当前位置范围
-            boolean is = comDistance > BaiduMapUtil.getInstence().getDistance() &&
+            boolean is = BaiduMapUtil.getInstence().isInWorkPlce() &&
                     StringUtils.isEmpty(model.getOffSignin());
             if (is)
                 return model;
@@ -176,9 +166,7 @@ public class ReckonAutoUtil {
     //5.判断是否离开工作范围
     protected boolean isOutoffWork(WorkModel model) {
         if (!isWorkTime(model)) return false;
-        int comDistance = PreferenceUtils.getInt(MyApplication.getInstance(), "innerdistance", 0);//规定距离
-        if (comDistance == 0) return false;
-        boolean is = comDistance < BaiduMapUtil.getInstence().getDistance() && !model.isLeaveAlarm();
+        boolean is = BaiduMapUtil.getInstence().isInnerdistance() && !model.isLeaveAlarm();
         if (is) {
             model.setLeaveAlarm(true);
             WorkModelDao.getInstance().update(model);

+ 59 - 12
WeiChat/src/main/java/com/xzjmyk/pm/activity/util/BaiduMapUtil.java

@@ -35,6 +35,8 @@ import com.xzjmyk.pm.activity.AppConfig;
 import com.xzjmyk.pm.activity.BdLocationHelper;
 import com.xzjmyk.pm.activity.MyApplication;
 import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.bean.oa.WorkLocationBean;
+import com.xzjmyk.pm.activity.db.dao.WorkLocationDao;
 import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
 
 import java.text.DecimalFormat;
@@ -122,25 +124,70 @@ public class BaiduMapUtil {
         return df.format(distance);
     }
 
-    //计算公司距离
-    public float getDistance() {
+    /**
+     * 判断是否在打卡范围之内
+     *
+     * @return
+     */
+    public boolean isInWorkPlce() {
         float dis = 0;
         try {
-            double Longitude = PreferenceUtils.getFloat("longitude", 0);
-            double Latitude = PreferenceUtils.getFloat("latitude", 0);
-            if (Latitude == 0 || Longitude == 0) return 1200000;
+            List<WorkLocationBean> beanList = WorkLocationDao.getInstance().queryByEnCode();
+            if (ListUtils.isEmpty(beanList)) return false;
             BdLocationHelper helper = MyApplication.getInstance().getBdLocationHelper();
-            String chche = BaiduMapUtil.getInstence().getDistance(Longitude, Latitude,
-                    helper.getLatitude(), helper.getLongitude());
-            dis = Float.valueOf(chche);
+            for (WorkLocationBean bean : beanList) {
+                String chche = BaiduMapUtil.getInstence().getDistance(bean.getLatitude(),
+                        bean.getLongitude(), helper.getLatitude(), helper.getLongitude());
+                dis = Float.valueOf(chche);
+                if (dis < bean.getValidrange()) return true;
+            }
+            return false;
         } catch (NumberFormatException e) {
-            return 1200000;
+            return false;
         } catch (Exception e) {
-            return 1200000;
-        } finally {
-            return dis;
+            return false;
         }
     }
+    public float getDistance(){
+        float dis = 0;
+        try {
+            List<WorkLocationBean> beanList = WorkLocationDao.getInstance().queryByEnCode();
+            if (ListUtils.isEmpty(beanList)) return 0;
+            BdLocationHelper helper = MyApplication.getInstance().getBdLocationHelper();
+            for (WorkLocationBean bean : beanList) {
+                String chche = BaiduMapUtil.getInstence().getDistance(bean.getLatitude(),
+                        bean.getLongitude(), helper.getLatitude(), helper.getLongitude());
+                dis = Float.valueOf(chche);
+                if (dis < bean.getValidrange()) return dis;
+            }
+            return 0;
+        } catch (NumberFormatException e) {
+            return 0;
+        } catch (Exception e) {
+            return 0;
+        }
+    }
+
+    public boolean isInnerdistance() {
+        float dis = 0;
+        try {
+            List<WorkLocationBean> beanList = WorkLocationDao.getInstance().queryByEnCode();
+            if (ListUtils.isEmpty(beanList)) return false;
+            BdLocationHelper helper = MyApplication.getInstance().getBdLocationHelper();
+            for (WorkLocationBean bean : beanList) {
+                String chche = BaiduMapUtil.getInstence().getDistance(bean.getLongitude(),
+                        bean.getLatitude(), helper.getLatitude(), helper.getLongitude());
+                dis = Float.valueOf(chche);
+                if (dis < bean.getInnerdistance()) return true;
+            }
+            return false;
+        } catch (NumberFormatException e) {
+            return false;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
 
     //计算距离
     public String getDistance(double a1, double a2, double b1, double b2) {