| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- package restcontroller.prsx.hospitaldep;
- import beans.datacontrllog.DataContrlLog;
- import beans.datatag.DataTag;
- import beans.datateam.DataTeam;
- 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 = getDoctorRowsMap(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(")");
- }
- 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);
- }
- 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(where2);
- 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 = getDoctorRowsMap(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);
- 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>();
- 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);
- //系统标签
- row.put("tag_sys", sys_tag);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- public RowsMap getDoctorRowsMap(List<Long> sa_hospitaldepids) throws YosException {
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("t1.isleader=1");
- querySQL.setWhere("t1.sa_hospitaldepid ", sa_hospitaldepids);
- Rows rows = querySQL.query();
- return rows.toRowsMap("sa_hospitaldepid");
- }
- }
|