| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- package restcontroller.prsx.hospitaldep;
- 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;
- import common.annotation.API;
- import common.data.*;
- import org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- /**
- * 医院科室管理
- */
- public class hospitaldep extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public hospitaldep(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "新建或编辑", apiversion = R.ID2025101409385002.v1.class)
- public String insertOrUpdate() throws YosException {
- ArrayList<String> sqlList = new ArrayList<>();
- Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
- Long sa_customersid = content.getLongValue("sa_customersid");
- String hospitaldepname = content.getStringValue("hospitaldepname");
- if (!dbConnect.runSqlQuery("select * from sa_hospitaldep WHERE siteid='" + siteid + "' and sa_customersid=" + sa_customersid + " and hospitaldepname='" + hospitaldepname + "' and sa_hospitaldepid !='" + sa_hospitaldepid + "'").isEmpty()) {
- return getErrReturnObject().setErrMsg("该医院科室不可重复创建!").toString();
- }
- Rows stagenameRows = dbConnect.runSqlQuery("SELECT stagename from sa_devstage WHERE siteid='" + siteid + "' order by sequence LIMIT 1");
- if (sa_hospitaldepid <= 0) {
- sa_hospitaldepid = createTableID("sa_hospitaldep");
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_hospitaldep");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(sa_hospitaldepid);
- insertSQL.setValue("hospitaldepname", hospitaldepname);
- insertSQL.setValue("sa_customersid", sa_customersid);
- insertSQL.setValue("type", content.getStringValue("type"));
- insertSQL.setValue("remarks", content.getStringValue("remarks"));
- insertSQL.setValue("stagename", stagenameRows.isNotEmpty() ? stagenameRows.get(0).getString("stagename") : "");
- sqlList.add(insertSQL.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "新建", "新建成功").getSQL());
- //数据团队新增
- sqlList.addAll(DataTeam.createTeamSQL(this, "sa_hospitaldep", sa_hospitaldepid, userid));
- } else {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_hospitaldep");
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_hospitaldepid);
- updateSQL.setValue("hospitaldepname", content.getStringValue("hospitaldepname"));
- updateSQL.setValue("sa_customersid", sa_customersid);
- updateSQL.setValue("type", content.getStringValue("type"));
- updateSQL.setValue("remarks", content.getStringValue("remarks"));
- sqlList.add(updateSQL.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "编辑", "编辑成功").getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- content.put("sa_hospitaldepid", sa_hospitaldepid);
- return detail();
- }
- @API(title = "详情", apiversion = R.ID2025101409393102.v1.class)
- public String detail() throws YosException {
- Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
- 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("t1.sa_hospitaldepid", sa_hospitaldepid);
- 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);
- 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"), ","));
- }
- Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
- return getSucReturnObject().setData(row).toString();
- }
- @API(title = "删除", apiversion = R.ID2025101409395902.v1.class)
- public String delete() throws YosException {
- Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_hospitaldep");
- deleteSQL.setSiteid(siteid);
- deleteSQL.setUniqueid(sa_hospitaldepid);
- deleteSQL.delete();
- DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "删除", "删除成功").insert();
- return getSucReturnObject().toString();
- }
- @API(title = "列表", apiversion = R.ID2025101409402402.v1.class)
- public String list() throws YosException {
- // 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的
- String tablename = "sa_hospitaldep";
- int type = content.getIntValue("type");
- 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("or t3.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t5.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t6.doctors like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
- where.append(" and(");
- where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and(");
- where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
- where.append(")");
- }
- //科室类别
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
- where.append(" and(");
- where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
- where.append(")");
- }
- //开发阶段
- if (whereObject.containsKey("stagename") && !"".equals(whereObject.getString("stagename"))) {
- where.append(" and(");
- where.append("t1.stagename ='").append(whereObject.getString("stagename")).append("' ");
- where.append(")");
- }
- }
- String where2 = " 1=1 ";
- if (type == 0) {
- where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
- + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
- } else {
- where2 = DataTeam.getDataWhereStr(this, tablename, "t1", type);
- }
- SQLFactory sqlFactory = new SQLFactory(this, "查询科室负责人");
- sqlFactory.addParameter("siteid", siteid);
- 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.addJoinTable(JOINTYPE.left, "sys_datateam", "t5", "t5.ownerid = t1.sa_hospitaldepid and t5.siteid = t1.siteid and t5.ownertable = 'sa_hospitaldep' and t5.isleader = 1");
- querySQL.addJoinTable(JOINTYPE.left, sqlFactory, "t6", "t6.sa_hospitaldepid = t1.sa_hospitaldepid", "doctors");
- querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t7", "t7.ownertable = 'sa_hospitaldep' and t7.siteid = t1.siteid and t7.ownerid = t1.sa_hospitaldepid and t7.isleader = 1");
- querySQL.addQueryFields("leadername", "t7.name");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where);
- querySQL.setWhere(where2);
- 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();
- }
- @API(title = "选择医院列表", apiversion = R.ID2025101409411402.v1.class)
- public String chooseHospital() throws YosException {
- String tablename = "sa_customers";
- 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.billno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.province like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.city like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.county like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.address like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t6.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t8.depname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- where.append(" and ( t1.datastatus in (0,2) )");
- String where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
- + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "sa_customersid", "createby", "createdate",
- "sys_enterpriseid", "status", "type", "tradingstatus", "datastatus", "billno", "province", "city", "county", "address", "stagename", "grade");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t2.sys_enterpriseid = t1.sys_enterpriseid AND t2.siteid = t1.siteid", "enterprisename");
- querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t3", "t3.sa_saleareaid = t1.sa_saleareaid AND t3.siteid = t1.siteid", "areaname");
- 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.setSiteid(siteid);
- querySQL.setWhere(where);
- querySQL.setWhere(where2);
- querySQL.setPage(pageSize, pageNumber);
- querySQL.setOrderBy(pageSorting);
- querySQL.setRoleDataLimit(false);
- querySQL.withDeleteData(true);
- 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<>());
- //标签
- HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, tablename, ids, false);
- //系统标签
- HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, tablename, ids, true);
- Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
- for (Row row : rows) {
- Long id = row.getLong("sa_customersid");
- row.put("leader", leaderRows.get(String.valueOf(id)));
- if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
- row.put("name", leaderRows.get(String.valueOf(id)).get(0).getString("name"));
- row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
- }
- 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>();
- //非系统标签
- row.put("tag", tag);
- //系统标签
- row.put("tag_sys", sys_tag);
- 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.ID2025102214574202.v1.class)
- public String doctorlist() 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.doctorname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.professional like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t4.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t2.sa_hospitaldepid=t1.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
- querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t3", "t3.sa_customersid=t1.sa_customersid");
- querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t3.sys_enterpriseid",
- "enterprisename");
- querySQL.setWhere(where);
- querySQL.setWhere("t2.sa_hospitaldepid", sa_hospitaldepid);
- querySQL.setSiteid(siteid);
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("sa_doctorid", new ArrayList<>());
- RowsMap leaderRows = DataTeam.getLeader(this, "sa_doctor", rows.toArrayList("sa_doctorid")).toRowsMap("ownerid");
- //标签
- HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_doctor", ids, false);
- //系统标签
- HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_doctor", ids, true);
- for (Row row : rows) {
- Long id = row.getLong("sa_doctorid");
- row.put("leader", leaderRows.get(row.getString("sa_doctorid")));
- 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);
- }
- return getSucReturnObject().setData(rows).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);
- 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+")");
- String sql=" and t1.sa_agentsid in (SELECT sa_agentsid from sys_enterprise_tradefield " +
- "WHERE hrid in "+hrids+")";
- sql= sql.replace("[","(").replace("]",")");
- where.append(sql);
- 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.addJoinTable(JOINTYPE.inner, "sa_agents_hospital", "t6", "t6.siteid = t1.siteid and t6.sa_agentsid = t1.sa_agentsid","sa_agents_hospitalid");
- querySQL.addQueryFields("parent_enterprisename", "t5.enterprisename");
- querySQL.setWhere("t6.sa_hospitaldepid",sa_hospitaldepid);
- 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();
- }
- }
|