|
|
@@ -10,6 +10,7 @@ import beans.itemclass.ItemClass;
|
|
|
import beans.proxy.Proxy;
|
|
|
import beans.recycle.Recycle;
|
|
|
import beans.salearea.SaleArea;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
@@ -632,7 +633,7 @@ public class Hospital 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("t2.sa_customersid",sa_customersid);
|
|
|
+ querySQL.setWhere("t2.sa_customersid", sa_customersid);
|
|
|
querySQL.addQueryFields("hospitalname", "t3.enterprisename");
|
|
|
querySQL.addQueryFields("agentname", "t5.enterprisename");
|
|
|
querySQL.addQueryFields("salername", "t6.name");
|
|
|
@@ -695,16 +696,16 @@ public class Hospital extends Controller {
|
|
|
.setTableAlias("t1");
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "plm_itemextend", "t2", "t2.itemid = t1.itemid AND t2.siteid = t1.siteid",
|
|
|
"erpitemname", "erpitemno");
|
|
|
- querySQL.addJoinTable(JOINTYPE.inner, "sa_hospitaldep_item", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid","sa_hospitaldep_itemid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_hospitaldep_item", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid", "sa_hospitaldep_itemid");
|
|
|
querySQL.addJoinTable(JOINTYPE.inner, "sa_devstage", "t4", "t4.sa_devstageid = t3.sa_devstageid AND t4.siteid = t3.siteid",
|
|
|
"stagename");
|
|
|
querySQL.addJoinTable(JOINTYPE.inner, "sa_hospitaldep", "t5", "t5.sa_hospitaldepid = t3.sa_hospitaldepid AND t5.siteid = t3.siteid",
|
|
|
- "hospitaldepname","sa_hospitaldepid");
|
|
|
+ "hospitaldepname", "sa_hospitaldepid");
|
|
|
querySQL.setWhere("t5.sa_customersid", sa_customersid);
|
|
|
querySQL.setSiteid(siteid);
|
|
|
querySQL.setWhere(where);
|
|
|
- if(pageSorting.equals("''")){
|
|
|
- pageSorting="t5.sa_hospitaldepid,t3.sa_hospitaldep_itemid";
|
|
|
+ if (pageSorting.equals("''")) {
|
|
|
+ pageSorting = "t5.sa_hospitaldepid,t3.sa_hospitaldep_itemid";
|
|
|
}
|
|
|
querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
Rows rows = querySQL.query();
|
|
|
@@ -721,5 +722,128 @@ public class Hospital extends Controller {
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "关联经销商查询", apiversion = R.ID2025102713075502.v1.class)
|
|
|
+ public String queryAgents() 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_customersid = content.getLong("sa_customersid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
|
|
|
+ "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate").
|
|
|
+ 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, "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.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ querySQL.setOrderBy("t1.createdate desc");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ RowsMap areaRowsMap = getAreaRowsMap(rows.toArrayList("sa_agentsid", new ArrayList<>()));
|
|
|
+ RowsMap salerRowsMap = getSalerNameRowsMap(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"), ","));
|
|
|
+ row.putIfAbsent("scale", "");
|
|
|
+ row.putIfAbsent("mainproducts", "");
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public RowsMap getAreaRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
|
|
|
+ if (sa_agentsids.size() == 0) {
|
|
|
+ return new RowsMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "SELECT DISTINCT t2.areaname,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
|
|
|
+ "INNER JOIN sa_salearea t2 ON t2.sa_saleareaid=t1.sa_saleareaid " +
|
|
|
+ "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+
|
|
|
+ return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
|
|
|
+ }
|
|
|
+
|
|
|
+ public RowsMap getSalerNameRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
|
|
|
+ if (sa_agentsids.size() == 0) {
|
|
|
+ return new RowsMap();
|
|
|
+ }
|
|
|
+ String sql = "SELECT DISTINCT t2.name,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
|
|
|
+ "INNER JOIN sys_hr t2 ON t2.hrid=t1.hrid " +
|
|
|
+ "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+
|
|
|
+ return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
|
|
|
+ }
|
|
|
+
|
|
|
+ @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();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|