Browse Source

门店定位调整

eganwu 1 year ago
parent
commit
6a09193145

+ 27 - 18
src/custom/restcontroller/webmanage/saletool/store/Store.java

@@ -180,24 +180,33 @@ public class Store extends Controller {
 
         String longitude = content.getStringValue("longitude");
         String latitude = content.getStringValue("latitude");
+        Long sa_storeid = content.getLongValue("sa_storeid");
+        Rows rows;
+
+        if(sa_storeid>0){
+            rows = StoreHelper.queryStores(this,sa_storeid, longitude, latitude);
+        }else {
+            if (usertype == 21 || usertype == 22) {
+                Long sys_enterprise_hrid = getEnterpriseHr(userid).getLong("sys_enterprise_hrid");
+                rows = StoreHelper.queryAgentsStores(this, sys_enterprise_hrid, longitude, latitude);
+                if (rows.isEmpty()) {
+                    rows = StoreHelper.queryStores(this, longitude, latitude);
+                }
+            } else {
+                rows = StoreHelper.queryStores(this, longitude, latitude);
+            }
+        }
 
 
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_store").setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
-                , "name","phonenumber","userid");
-        querySQL.addQueryFields("distance", "st_distance_sphere(point(longitude,latitude),point('" + longitude + "','" + latitude + "'))");
-        querySQL.setOrderBy("distance");
-        Rows rows = querySQL.query();
-        Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
-        detailRow.put("distance", String.format("%.2f", detailRow.getDouble("distance")));
-        long sa_storeid = detailRow.getLong("sa_storeid");
-        detailRow.put("attinfos", Attachment.get(this, "sa_store", sa_storeid));
-        detailRow.put("headpic",getHeadPic(detailRow.getLong("userid")));
-
-        addHistory(sa_storeid);
+        for (Row row : rows) {
+            row.put("distance", String.format("%.2f", row.getDouble("distance")));
+            row.put("attinfos", Attachment.get(this, "sa_store", row.getLong("sa_storeid")));
+            row.put("headpic", getHeadPic(row.getLong("userid")));
+            addHistory(row.getLong("sa_storeid"));
+        }
 
 
-        return getSucReturnObject().setData(detailRow).toString();
+        return getSucReturnObject().setData(rows).toString();
     }
 
 
@@ -237,20 +246,20 @@ public class Store extends Controller {
         QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sa_store")
                 .setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
-                , "name","phonenumber","userid");
+                , "name", "phonenumber", "userid");
         querySQL.addJoinTable(JOINTYPE.inner, "sa_store_history", "t3", "t3.sa_storeid=t1.sa_storeid and t3.siteid=t1.siteid");
         querySQL.addQueryFields("distance", "st_distance_sphere(point(longitude,latitude),point('" + longitude + "','" + latitude + "'))");
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t3.userid",userid);
+        querySQL.setWhere("t3.userid", userid);
         querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
         Rows rows = querySQL.query();
 
         RowsMap attinfoRows = Attachment.get(controller, sa_store, rows.toArrayList("sa_storeid", new ArrayList<>()));
 
-        for (Row row:rows) {
+        for (Row row : rows) {
             row.put("attinfos", attinfoRows.getOrDefault(row.getString("sa_storeid"), new Rows()));
             row.put("distance", String.format("%.2f", row.getDouble("distance")));
-            row.put("headpic",getHeadPic(row.getLong("userid")));
+            row.put("headpic", getHeadPic(row.getLong("userid")));
         }
 
 

+ 44 - 0
src/custom/restcontroller/webmanage/saletool/store/StoreHelper.java

@@ -127,4 +127,48 @@ public class StoreHelper extends BaseClass {
         insertSQL.insert();
     }
 
+    public static Rows queryStores(Controller controller, String longitude, String latitude) throws YosException {
+        Rows temprows = new Rows();
+        QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sa_store").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
+                , "name", "phonenumber", "userid");
+        querySQL.addQueryFields("distance", "st_distance_sphere(point(longitude,latitude),point('" + longitude + "','" + latitude + "'))");
+        querySQL.setWhere("status", "审核");
+        querySQL.setOrderBy("distance");
+        Rows rows = querySQL.query();
+        if (rows.isNotEmpty()) {
+            temprows.add(rows.get(0));
+        }
+        return temprows;
+    }
+
+    public static Rows queryStores(Controller controller, Long sa_storeid, String longitude, String latitude) throws YosException {
+        Rows temprows = new Rows();
+        QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sa_store").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
+                , "name", "phonenumber", "userid");
+        querySQL.addQueryFields("distance", "st_distance_sphere(point(longitude,latitude),point('" + longitude + "','" + latitude + "'))");
+        querySQL.setWhere("status", "审核");
+        querySQL.setWhere("sa_storeid", sa_storeid);
+        querySQL.setOrderBy("distance");
+        Rows rows = querySQL.query();
+        if (rows.isNotEmpty()) {
+            temprows.add(rows.get(0));
+        }
+        return temprows;
+    }
+
+    //查询经销商的门店信息
+    public static Rows queryAgentsStores(Controller controller, long sys_enterprise_hrid, String longitude, String latitude) throws YosException {
+        QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sa_store").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
+                , "name", "phonenumber", "userid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_store_hr", "t3", "t3.sa_storeid=t1.sa_storeid and t3.siteid=t1.siteid");
+        querySQL.addQueryFields("distance", "st_distance_sphere(point(longitude,latitude),point('" + longitude + "','" + latitude + "'))");
+        querySQL.setWhere("t3.sys_enterprise_hrid", sys_enterprise_hrid);
+        querySQL.setWhere("status", "审核");
+        querySQL.setOrderBy("distance");
+        return querySQL.query();
+    }
+
 }