wu пре 2 месеци
родитељ
комит
b031b8455c

+ 25 - 0
src/custom/restcontroller/R.java

@@ -7532,6 +7532,31 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025111909582402 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025111911232002 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025111914313002 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025111914425902 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025111915343902 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 170 - 3
src/custom/restcontroller/prsx/hospitaldep/hospitaldep.java

@@ -4,6 +4,8 @@ import beans.CommonHepler;
 import beans.datacontrllog.DataContrlLog;
 import beans.datatag.DataTag;
 import beans.datateam.DataTeam;
+import beans.proxy.Proxy;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
 import common.YosException;
@@ -92,7 +94,7 @@ public class hospitaldep extends Controller {
         HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
         //系统标签
         HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
-        RowsMap doctorRowsMap =CommonHepler. getDoctorRowsMap(this,ids);
+        RowsMap doctorRowsMap = CommonHepler.getDoctorRowsMap(this, ids);
         for (Row row : rows) {
             Long id = row.getLong("sa_hospitaldepid");
             row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
@@ -184,7 +186,7 @@ public class hospitaldep extends Controller {
         querySQL.setSiteid(siteid);
         querySQL.setWhere(where);
         querySQL.setWhere(where2);
-        querySQL.setPage(pageSize,pageNumber).setOrderBy(pageSorting);
+        querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
         Rows rows = querySQL.query();
 
         ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
@@ -194,7 +196,7 @@ public class hospitaldep extends Controller {
         //系统标签
         HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
         Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
-        RowsMap doctorRowsMap = CommonHepler. getDoctorRowsMap(this,ids);
+        RowsMap doctorRowsMap = CommonHepler.getDoctorRowsMap(this, ids);
         for (Row row : rows) {
             Long id = row.getLong("sa_hospitaldepid");
             row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
@@ -356,4 +358,169 @@ public class hospitaldep extends Controller {
     }
 
 
+    @API(title = "选择经销商列表", apiversion = R.ID2025102714042402.v1.class)
+    public String chooseAgents() throws YosException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        where.append(" and t1.status ='启用' ");
+
+        ArrayList<Long> hrids = Proxy.getProxyHrids(this);
+        hrids.add(hrid);
+
+        Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
+
+
+        where.append(" and t1.sa_agentsid not in (SELECT sa_agentsid from sa_agents_hospital " +
+                "WHERE sa_hospitaldepid="+sa_hospitaldepid+")");
+
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
+                        "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate", "scale", "mainproducts").
+                setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "province", "city", "county", "address");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
+                "erpagentnum");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_tradefield", "t4", "t4.sa_agentsid=t1.sa_agentsid and t4.siteid=t1.siteid");
+        querySQL.setWhere("t4.hrid", hrids);
+
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy("t1.createdate desc");
+        Rows rows = querySQL.query();
+
+        RowsMap areaRowsMap = CommonHepler.getAreaRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        RowsMap salerRowsMap = CommonHepler.getSalerNameRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        for (Row row : rows) {
+            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
+            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
+            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "添加经销商", apiversion = R.ID2025102713181402.v1.class)
+    public String addAgents() throws YosException {
+
+        Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
+        JSONArray sa_agentsids = content.getJSONArray("sa_agentsids");
+
+        Long sa_customersid = 0L;
+        Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE sa_hospitaldepid=" + sa_hospitaldepid);
+        if (rows.isNotEmpty()) {
+            sa_customersid = rows.get(0).getLong("sa_customersid");
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        for (Object object : sa_agentsids) {
+            Long sa_agentsid = Long.valueOf(object.toString());
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_agents_hospital");
+            insertSQL.setUniqueid(createTableID("sa_agents_hospital"));
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("sa_agentsid", sa_agentsid);
+            insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
+            insertSQL.setValue("sa_customersid", sa_customersid);
+            insertSQL.setWhere(" not exists(select 1 from sa_agents_hospital where sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "'  and sa_hospitaldepid='" + sa_hospitaldepid + "')");
+            sqlList.add(insertSQL.getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "关联经销商", "关联经销商ID:" + sa_agentsid).getSQL());
+        }
+        dbConnect.runSqlUpdate(sqlList);
+
+        DataTag.createSystemTag(this, "sa_customers", sa_customersid, "经销");
+
+        return getSucReturnObject().toString();
+    }
+
+
+    @API(title = "删除经销商关联", apiversion = R.ID2025102713243702.v1.class)
+    public String deleteAgents() throws YosException {
+        Long sa_agents_hospitalid = content.getLong("sa_agents_hospitalid");
+        Rows rows = dbConnect.runSqlQuery("SELECT * from sa_agents_hospital WHERE sa_agents_hospitalid=" + sa_agents_hospitalid + " and siteid='" + siteid + "'");
+        Long sa_agentsid = rows.isNotEmpty() ? rows.get(0).getLong("sa_agentsid") : 0;
+        Long sa_customersid = rows.isNotEmpty() ? rows.get(0).getLong("sa_customersid") : 0;
+        Long sa_hospitaldepid = rows.isNotEmpty() ? rows.get(0).getLong("sa_hospitaldepid") : 0;
+
+        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_agents_hospital");
+        deleteSQL.setSiteid(siteid);
+        deleteSQL.setWhere("sa_agents_hospitalid", sa_agents_hospitalid);
+        deleteSQL.delete();
+
+        DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "删除经销商", "删除经销商ID:" + sa_agentsid).insert();
+
+        if (dbConnect.runSqlQuery("SELECT * from sa_agents_hospital WHERE sa_customersid=" + sa_customersid + " and siteid='" + siteid + "'").isEmpty()) {
+            DataTag.deleteTag(this, "sa_customers", sa_customersid, "经销");
+            DataTag.createSystemTag(this, "sa_customers", sa_customersid, "直销");
+        }
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "查询关联的经销商", apiversion = R.ID2025111911232002.v1.class)
+    public String queryList() throws YosException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        where.append(" and t1.status ='启用' ");
+
+        Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
+                        "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate", "scale", "mainproducts").
+                setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "province", "city", "county", "address");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
+                "erpagentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t4.siteid = t1.siteid and t4.sa_agentsid = t1.parentid");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t5", "t5.siteid = t4.siteid and t5.sys_enterpriseid = t4.sys_enterpriseid");
+        querySQL.addQueryFields("parent_enterprisename", "t5.enterprisename");
+        querySQL.setWhere("t1.sa_agentsid in (SELECT sa_agentsid from sa_agents_hospital WHERE sa_hospitaldepid=" + sa_hospitaldepid + " and siteid='" + siteid + "')");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy("t1.createdate desc");
+        Rows rows = querySQL.query();
+
+        RowsMap areaRowsMap = CommonHepler.getAreaRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        RowsMap salerRowsMap = CommonHepler.getSalerNameRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        for (Row row : rows) {
+            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
+            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
+            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
 }

+ 52 - 0
src/custom/restcontroller/prsx/trial/trial.java

@@ -1,5 +1,6 @@
 package restcontroller.prsx.trial;
 
+import beans.CommonHepler;
 import beans.datacontrllog.DataContrlLog;
 import beans.dataextend.DataExtend;
 import beans.datateam.DataTeam;
@@ -10,6 +11,7 @@ import common.Controller;
 import common.YosException;
 import common.annotation.API;
 import common.data.*;
+import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
 import java.util.ArrayList;
@@ -323,5 +325,55 @@ public class trial extends Controller {
         return rec_contactsid;
     }
 
+    @API(title = "关联查询经销商", apiversion = R.ID2025111915343902.v1.class)
+    public String newApiMethod() throws YosException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        where.append(" and t1.status ='启用' ");
+
+        Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
+                        "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate", "scale", "mainproducts").
+                setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "province", "city", "county", "address");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
+                "erpagentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t4.siteid = t1.siteid and t4.sa_agentsid = t1.parentid");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t5", "t5.siteid = t4.siteid and t5.sys_enterpriseid = t4.sys_enterpriseid");
+        querySQL.addQueryFields("parent_enterprisename", "t5.enterprisename");
+        querySQL.setWhere("t1.sa_agentsid in (SELECT sa_agentsid from sa_agents_hospital WHERE sa_hospitaldepid=" + sa_hospitaldepid + " and siteid='" + siteid + "')");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy("t1.createdate desc");
+        Rows rows = querySQL.query();
+
+        RowsMap areaRowsMap = CommonHepler.getAreaRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        RowsMap salerRowsMap = CommonHepler.getSalerNameRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        for (Row row : rows) {
+            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
+            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
+            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
 
 }

+ 2 - 106
src/custom/restcontroller/sale/customer/Hospital.java

@@ -201,17 +201,6 @@ public class Hospital extends Controller {
             }
         }
 
-        if (content.containsKey("sa_agentsid")) {
-            Long sa_agentsid = content.getLongValue("sa_agentsid");
-            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_agents_hospital");
-            insertSQL.setUniqueid(createTableID("sa_agents_hospital"));
-            insertSQL.setSiteid(siteid);
-            insertSQL.setValue("sa_agentsid", sa_agentsid);
-            insertSQL.setValue("sa_customersid", sa_customersid);
-            insertSQL.setWhere(" not exists(select 1 from sa_agents_hospital where sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "'  and sa_customersid='" + sa_customersid + "')");
-            insertSQL.insert();
-        }
-
         return selectDetail();
     }
 
@@ -736,7 +725,7 @@ public class Hospital extends Controller {
                 where.append(")");
             }
         }
-        where.append(" and t1.status !='作废' ");
+        where.append(" and t1.status ='启用' ");
 
         Long sa_customersid = content.getLong("sa_customersid");
 
@@ -749,9 +738,8 @@ public class Hospital extends Controller {
                 "erpagentnum");
         querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t4.siteid = t1.siteid and t4.sa_agentsid = t1.parentid");
         querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t5", "t5.siteid = t4.siteid and t5.sys_enterpriseid = t4.sys_enterpriseid");
-        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents_hospital", "t9", "t9.sa_agentsid=t1.sa_agentsid and t9.siteid=t1.siteid", "sa_agents_hospitalid");
         querySQL.addQueryFields("parent_enterprisename", "t5.enterprisename");
-        querySQL.setWhere("t9.sa_customersid", sa_customersid);
+        querySQL.setWhere("t1.sa_agentsid in (SELECT sa_agentsid from sa_agents_hospital WHERE sa_customersid=" + sa_customersid + " and siteid='" + siteid + "')");
         querySQL.setSiteid(siteid);
         querySQL.setWhere(where);
         querySQL.setPage(pageSize, pageNumber);
@@ -770,103 +758,11 @@ public class Hospital extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
-    @API(title = "添加经销商", apiversion = R.ID2025102713181402.v1.class)
-    public String addAgents() throws YosException {
-
-        Long sa_customersid = content.getLong("sa_customersid");
-        JSONArray sa_agentsids = content.getJSONArray("sa_agentsids");
-
-        ArrayList<String> sqlList = new ArrayList<>();
-
-        for (Object object : sa_agentsids) {
-            Long sa_agentsid = Long.valueOf(object.toString());
-            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_agents_hospital");
-            insertSQL.setUniqueid(createTableID("sa_agents_hospital"));
-            insertSQL.setSiteid(siteid);
-            insertSQL.setValue("sa_agentsid", sa_agentsid);
-            insertSQL.setValue("sa_customersid", sa_customersid);
-            insertSQL.setWhere(" not exists(select 1 from sa_agents_hospital where sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "'  and sa_customersid='" + sa_customersid + "')");
-            sqlList.add(insertSQL.getSQL());
-            sqlList.add(DataContrlLog.createLog(this, "sa_customers", sa_customersid, "关联经销商", "关联经销商ID:" + sa_agentsid).getSQL());
-        }
-        dbConnect.runSqlUpdate(sqlList);
-
-        DataTag.createSystemTag(this, "sa_customers", sa_customersid, "经销");
-
-        return getSucReturnObject().toString();
-    }
-
-    @API(title = "删除经销商关联", apiversion = R.ID2025102713243702.v1.class)
-    public String deleteAgents() throws YosException {
-        Long sa_agents_hospitalid = content.getLong("sa_agents_hospitalid");
-        Rows rows = dbConnect.runSqlQuery("SELECT * from sa_agents_hospital WHERE sa_agents_hospitalid=" + sa_agents_hospitalid + " and siteid='" + siteid + "'");
-        Long sa_agentsid = rows.isNotEmpty() ? rows.get(0).getLong("sa_agentsid") : 0;
-        Long sa_customersid = rows.isNotEmpty() ? rows.get(0).getLong("sa_customersid") : 0;
-
-        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_agents_hospital");
-        deleteSQL.setSiteid(siteid);
-        deleteSQL.setWhere("sa_agents_hospitalid", sa_agents_hospitalid);
-        deleteSQL.delete();
-
-        DataContrlLog.createLog(this, "sa_customers", sa_customersid, "关联经销商", "关联经销商ID:" + sa_agentsid).insert();
-
-        if (dbConnect.runSqlQuery("SELECT * from sa_agents_hospital WHERE sa_customersid=" + sa_customersid + " and siteid='" + siteid + "'").isEmpty()) {
-            DataTag.deleteTag(this, "sa_customers", sa_customersid, "经销");
-            DataTag.createSystemTag(this, "sa_customers", sa_customersid, "直销");
-        }
-
-        return getSucReturnObject().toString();
-    }
 
-    @API(title = "选择经销商列表", apiversion = R.ID2025102714042402.v1.class)
-    public String chooseAgents() throws YosException {
-        StringBuffer where = new StringBuffer(" 1=1 ");
-        if (content.containsKey("where")) {
-            JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
-                where.append(" and(");
-                where.append("t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append(")");
-            }
-        }
-        where.append(" and t1.status !='作废' ");
 
-        ArrayList<Long> hrids = Proxy.getProxyHrids(this);
-        hrids.add(hrid);
 
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
-                        "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate", "scale", "mainproducts").
-                setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
-                "enterprisename", "province", "city", "county", "address");
-        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
-                "erpagentnum");
-        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_tradefield", "t4", "t4.sa_agentsid=t1.sa_agentsid and t4.siteid=t1.siteid");
-        querySQL.setWhere("t4.hrid", hrids);
 
-        querySQL.setSiteid(siteid);
-        querySQL.setWhere(where);
-        querySQL.setPage(pageSize, pageNumber);
-        querySQL.setOrderBy("t1.createdate desc");
-        Rows rows = querySQL.query();
 
-        RowsMap areaRowsMap = CommonHepler.getAreaRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
-        RowsMap salerRowsMap = CommonHepler.getSalerNameRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
-        for (Row row : rows) {
-            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
-            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
-            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
-            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
-            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
-        }
-        return getSucReturnObject().setData(rows).toString();
-    }
 
 
 }

+ 171 - 8
src/custom/restcontroller/webmanage/sale/agents/agents2.java

@@ -1,10 +1,12 @@
 package restcontroller.webmanage.sale.agents;
 
 import beans.CommonHepler;
+import beans.datacontrllog.DataContrlLog;
 import beans.datatag.DataTag;
 import beans.datateam.DataTeam;
 import beans.recycle.Recycle;
 import beans.salearea.SaleArea;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
 import common.YosException;
@@ -53,15 +55,16 @@ public class agents2 extends Controller {
         querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t6", "t6.ownerid = t1.sa_customersid and t6.siteid = t1.siteid and t6.ownertable = 'sa_customers' and t6.isleader = 1");
         querySQL.addJoinTable(JOINTYPE.left, "sys_hr", "t7", "t7.userid = t6.userid and t7.siteid = t6.siteid ");
         querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t8", "t8.departmentid = t7.departmentid and t8.siteid = t7.siteid ");
-        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents_hospital", "t9", "t9.sa_customersid=t1.sa_customersid and t9.siteid=t1.siteid");
+
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t9.sa_agentsid", sa_agentsid);
+        querySQL.setWhere("t1.sa_customersid in (SELECT sa_customersid from sa_agents_hospital WHERE sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "')");
         querySQL.setWhere("t1.datastatus in (0,2) ");
         querySQL.setPage(pageSize, pageNumber);
         querySQL.setOrderBy(pageSorting);
 
         querySQL.setRoleDataLimit(false);
         querySQL.withDeleteData(true);
+        querySQL.setCondition("t1.billno", "t2.enterprisename");
         Rows rows = querySQL.query();
         RowsMap leaderRows = DataTeam.getLeaderWithoutHeadpic(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
         ArrayList<Long> ids = rows.toArrayList("sa_customersid", new ArrayList<>());
@@ -80,10 +83,6 @@ public class agents2 extends Controller {
             }
             ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<String>();
             ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<String>();
-            if (row.getString("agentsstatus").equals("禁用") || row.getString("agentsstatus").equals("作废")) {
-                tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
-                sys_tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
-            }
             //非系统标签
             row.put("tag", tag);
             //系统标签
@@ -92,7 +91,69 @@ public class agents2 extends Controller {
             row.putIfAbsent("totalop", 0);
             //关键人
             Rows KeyDoctors = KeyDoctorsRowsMap.getOrDefault(String.valueOf(id), new Rows());
-            row.putIfAbsent("keyperson", StringUtils.join(KeyDoctors.toArray("doctorname"),","));
+            row.putIfAbsent("keyperson", StringUtils.join(KeyDoctors.toArray("doctorname"), ","));
+            String stagename = row.getString("stagename");
+            for (Row stageRow : stageRows) {
+                if (stagename.equals(stageRow.getString("stagename"))) {
+                    stageRow.put("active", 1);
+                }
+                stageRow.putIfAbsent("active", 0);
+            }
+            row.put("stages", stageRows);
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "关联查询科室", apiversion = R.ID2025111909582402.v1.class)
+    public String queryhospitaldepList() throws YosException {
+
+        Long sa_agentsid = content.getLongValue("sa_agentsid");
+
+
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setWhere("t1.sa_hospitaldepid in (SELECT sa_hospitaldepid from sa_agents_hospital WHERE sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "')");
+        querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
+        RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
+        //标签
+        HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
+        //系统标签
+        HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
+        Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
+        RowsMap doctorRowsMap = CommonHepler.getDoctorRowsMap(this, ids);
+        for (Row row : rows) {
+            Long id = row.getLong("sa_hospitaldepid");
+            row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
+            if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
+                row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
+            }
+            ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
+            ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
+            //非系统标签
+            row.put("tag", tag);
+            //系统标签
+            row.put("tag_sys", sys_tag);
+            //科室负责人
+            Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
+            row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"), ","));
             String stagename = row.getString("stagename");
             for (Row stageRow : stageRows) {
                 if (stagename.equals(stageRow.getString("stagename"))) {
@@ -102,9 +163,11 @@ public class agents2 extends Controller {
             }
             row.put("stages", stageRows);
         }
+
         return getSucReturnObject().setData(rows).toString();
     }
 
+
     @API(title = "关联查询合同", apiversion = R.ID2025102710011202.v1.class)
     public String queryContractList() throws YosException {
 
@@ -135,7 +198,7 @@ public class agents2 extends Controller {
         querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t7", "t1.siteid = t7.siteid and t1.sa_contractid = t7.ownerid and t7.ownertable = 'sa_contract'", "deletereason");
         querySQL.setSiteid(siteid);
         querySQL.setWhere(where);
-        querySQL.setWhere("t4.sa_agentsid",sa_agentsid);
+        querySQL.setWhere("t4.sa_agentsid", sa_agentsid);
         querySQL.addQueryFields("hospitalname", "t3.enterprisename");
         querySQL.addQueryFields("agentname", "t5.enterprisename");
         querySQL.addQueryFields("salername", "t6.name");
@@ -172,5 +235,105 @@ public class agents2 extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+    @API(title = "添加科室", apiversion = R.ID2025111914313002.v1.class)
+    public String addhospitaldep() throws YosException {
+
+
+        Long sa_agentsid = content.getLongValue("sa_agentsid");
+        JSONArray sa_hospitaldepids = content.getJSONArray("sa_hospitaldepids");
+
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        for (Object object : sa_hospitaldepids) {
+            Long sa_hospitaldepid = Long.valueOf(object.toString());
+            Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE sa_hospitaldepid=" + sa_hospitaldepid);
+            Long sa_customersid = 0L;
+            if (rows.isNotEmpty()) {
+                sa_customersid = rows.get(0).getLong("sa_customersid");
+            }
+
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_agents_hospital");
+            insertSQL.setUniqueid(createTableID("sa_agents_hospital"));
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("sa_agentsid", sa_agentsid);
+            insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
+            insertSQL.setValue("sa_customersid", sa_customersid);
+            insertSQL.setWhere(" not exists(select 1 from sa_agents_hospital where sa_agentsid=" + sa_agentsid + " and siteid='" + siteid + "'  and sa_hospitaldepid='" + sa_hospitaldepid + "')");
+            sqlList.add(insertSQL.getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "关联经销商", "关联经销商ID:" + sa_agentsid).getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "签约科室", "签约科室ID:" + sa_hospitaldepid).getSQL());
+            DataTag.createSystemTag(this, "sa_customers", sa_customersid, "经销");
+        }
+        dbConnect.runSqlUpdate(sqlList);
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "选择科室", apiversion = R.ID2025111914425902.v1.class)
+    public String chooseHospitalDep() throws YosException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        Long sa_agentsid = content.getLongValue("sa_agentsid");
+        where.append(" and t1.sa_hospitaldepid in (SELECT ownerid from sys_enterprise_tradefield t1 " +
+                "INNER JOIN sys_hr t2 ON t2.hrid=t1.hrid and t2.siteid=t1.siteid " +
+                "INNER JOIN sys_datateam t3 ON t3.userid=t2.userid and t3.ownertable='sa_hospitaldep' and t3.isleader=1 and t3.siteid=t2.siteid " +
+                "WHERE sa_agentsid="+sa_agentsid+")");
+        where.append(" and t1.sa_hospitaldepid not in (SELECT sa_hospitaldepid from sa_agents_hospital " +
+                "WHERE sa_agentsid="+sa_agentsid+")");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
+        RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
+        //标签
+        HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
+        //系统标签
+        HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
+        Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
+        RowsMap doctorRowsMap = CommonHepler.getDoctorRowsMap(this, ids);
+        for (Row row : rows) {
+            Long id = row.getLong("sa_hospitaldepid");
+            row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
+            if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
+                row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
+            }
+            ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
+            ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
+            //非系统标签
+            row.put("tag", tag);
+            //系统标签
+            row.put("tag_sys", sys_tag);
+            //科室负责人
+            Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
+            row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"), ","));
+            String stagename = row.getString("stagename");
+            for (Row stageRow : stageRows) {
+                if (stagename.equals(stageRow.getString("stagename"))) {
+                    stageRow.put("active", 1);
+                }
+                stageRow.putIfAbsent("active", 0);
+            }
+            row.put("stages", stageRows);
+        }
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
 
 }

+ 1 - 2
src/custom/restcontroller/webmanage/sale/order/Order2.java

@@ -592,8 +592,7 @@ public class Order2 extends Controller {
                 "enterprisename", "province", "city", "county", "address");
 
         if (sa_customersid > 0) {
-            querySQL.addJoinTable(JOINTYPE.inner, "sa_agents_hospital", "t9", "t9.sa_agentsid=t1.sa_agentsid and t9.siteid=t1.siteid", "sa_agents_hospitalid");
-            querySQL.setWhere("t9.sa_customersid", sa_customersid);
+            querySQL.setWhere("t1.sa_agentsid in (SELECT sa_agentsid from sa_agents_hospital WHERE sa_customersid=" + sa_customersid + " and siteid='" + siteid + "')");
         }
         querySQL.setSiteid(siteid);
         querySQL.setWhere(where);