hospitaldep.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package restcontroller.prsx.hospitaldep;
  2. import beans.datacontrllog.DataContrlLog;
  3. import beans.datatag.DataTag;
  4. import beans.datateam.DataTeam;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.data.*;
  10. import org.apache.commons.lang.StringUtils;
  11. import restcontroller.R;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. /**
  16. * 医院科室管理
  17. */
  18. public class hospitaldep extends Controller {
  19. /**
  20. * 构造函数
  21. *
  22. * @param content
  23. */
  24. public hospitaldep(JSONObject content) throws YosException {
  25. super(content);
  26. }
  27. @API(title = "新建或编辑", apiversion = R.ID2025101409385002.v1.class)
  28. public String insertOrUpdate() throws YosException {
  29. ArrayList<String> sqlList = new ArrayList<>();
  30. Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
  31. Long sa_customersid = content.getLongValue("sa_customersid");
  32. String hospitaldepname = content.getStringValue("hospitaldepname");
  33. if (!dbConnect.runSqlQuery("select * from sa_hospitaldep WHERE siteid='" + siteid + "' and sa_customersid=" + sa_customersid + " and hospitaldepname='" + hospitaldepname + "' and sa_hospitaldepid !='" + sa_hospitaldepid + "'").isEmpty()) {
  34. return getErrReturnObject().setErrMsg("该医院科室不可重复创建!").toString();
  35. }
  36. Rows stagenameRows = dbConnect.runSqlQuery("SELECT stagename from sa_devstage WHERE siteid='" + siteid + "' order by sequence LIMIT 1");
  37. if (sa_hospitaldepid <= 0) {
  38. sa_hospitaldepid = createTableID("sa_hospitaldep");
  39. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_hospitaldep");
  40. insertSQL.setSiteid(siteid);
  41. insertSQL.setUniqueid(sa_hospitaldepid);
  42. insertSQL.setValue("hospitaldepname", hospitaldepname);
  43. insertSQL.setValue("sa_customersid", sa_customersid);
  44. insertSQL.setValue("type", content.getStringValue("type"));
  45. insertSQL.setValue("remarks", content.getStringValue("remarks"));
  46. insertSQL.setValue("stagename", stagenameRows.isNotEmpty() ? stagenameRows.get(0).getString("stagename") : "");
  47. sqlList.add(insertSQL.getSQL());
  48. sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "新建", "新建成功").getSQL());
  49. //数据团队新增
  50. sqlList.addAll(DataTeam.createTeamSQL(this, "sa_hospitaldep", sa_hospitaldepid, userid));
  51. } else {
  52. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_hospitaldep");
  53. updateSQL.setSiteid(siteid);
  54. updateSQL.setUniqueid(sa_hospitaldepid);
  55. updateSQL.setValue("hospitaldepname", content.getStringValue("hospitaldepname"));
  56. updateSQL.setValue("sa_customersid", sa_customersid);
  57. updateSQL.setValue("type", content.getStringValue("type"));
  58. updateSQL.setValue("remarks", content.getStringValue("remarks"));
  59. sqlList.add(updateSQL.getSQL());
  60. sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "编辑", "编辑成功").getSQL());
  61. }
  62. dbConnect.runSqlUpdate(sqlList);
  63. content.put("sa_hospitaldepid", sa_hospitaldepid);
  64. return detail();
  65. }
  66. @API(title = "详情", apiversion = R.ID2025101409393102.v1.class)
  67. public String detail() throws YosException {
  68. Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
  69. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
  70. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  71. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
  72. querySQL.setSiteid(siteid);
  73. querySQL.setWhere("t1.sa_hospitaldepid", sa_hospitaldepid);
  74. Rows rows = querySQL.query();
  75. ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
  76. RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
  77. //标签
  78. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
  79. //系统标签
  80. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
  81. RowsMap doctorRowsMap = getDoctorRowsMap(ids);
  82. for (Row row : rows) {
  83. Long id = row.getLong("sa_hospitaldepid");
  84. row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
  85. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  86. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  87. }
  88. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
  89. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
  90. //非系统标签
  91. row.put("tag", tag);
  92. //系统标签
  93. row.put("tag_sys", sys_tag);
  94. //科室负责人
  95. Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
  96. row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"),","));
  97. }
  98. Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
  99. return getSucReturnObject().setData(row).toString();
  100. }
  101. @API(title = "删除", apiversion = R.ID2025101409395902.v1.class)
  102. public String delete() throws YosException {
  103. Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
  104. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_hospitaldep");
  105. deleteSQL.setSiteid(siteid);
  106. deleteSQL.setUniqueid(sa_hospitaldepid);
  107. deleteSQL.delete();
  108. DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "删除", "删除成功").insert();
  109. return getSucReturnObject().toString();
  110. }
  111. @API(title = "列表", apiversion = R.ID2025101409402402.v1.class)
  112. public String list() throws YosException {
  113. // 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的
  114. String tablename = "sa_hospitaldep";
  115. int type = content.getIntValue("type");
  116. StringBuffer where = new StringBuffer(" 1=1 ");
  117. if (content.containsKey("where")) {
  118. JSONObject whereObject = content.getJSONObject("where");
  119. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  120. where.append(" and(");
  121. where.append("t1.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
  122. where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  123. where.append(")");
  124. }
  125. if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
  126. where.append(" and(");
  127. where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
  128. where.append(")");
  129. }
  130. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  131. where.append(" and(");
  132. where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  133. where.append(")");
  134. }
  135. //科室类别
  136. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  137. where.append(" and(");
  138. where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
  139. where.append(")");
  140. }
  141. //开发阶段
  142. if (whereObject.containsKey("stagename") && !"".equals(whereObject.getString("stagename"))) {
  143. where.append(" and(");
  144. where.append("t1.stagename ='").append(whereObject.getString("stagename")).append("' ");
  145. where.append(")");
  146. }
  147. }
  148. String where2 = " 1=1 ";
  149. if (type == 0) {
  150. where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
  151. + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
  152. } else {
  153. where2 = DataTeam.getDataWhereStr(this, tablename, "t1", type);
  154. }
  155. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
  156. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  157. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
  158. querySQL.setSiteid(siteid);
  159. querySQL.setWhere(where);
  160. querySQL.setWhere(where2);
  161. Rows rows = querySQL.query();
  162. ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
  163. RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
  164. //标签
  165. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
  166. //系统标签
  167. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
  168. Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
  169. RowsMap doctorRowsMap = getDoctorRowsMap(ids);
  170. for (Row row : rows) {
  171. Long id = row.getLong("sa_hospitaldepid");
  172. row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
  173. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  174. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  175. }
  176. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
  177. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
  178. //非系统标签
  179. row.put("tag", tag);
  180. //系统标签
  181. row.put("tag_sys", sys_tag);
  182. //科室负责人
  183. Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
  184. row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"),","));
  185. String stagename = row.getString("stagename");
  186. for (Row stageRow : stageRows) {
  187. if (stagename.equals(stageRow.getString("stagename"))) {
  188. stageRow.put("active", 1);
  189. }
  190. stageRow.putIfAbsent("active", 0);
  191. }
  192. row.put("stages", stageRows);
  193. }
  194. return getSucReturnObject().setData(rows).toString();
  195. }
  196. @API(title = "选择医院列表", apiversion = R.ID2025101409411402.v1.class)
  197. public String chooseHospital() throws YosException {
  198. String tablename = "sa_customers";
  199. StringBuffer where = new StringBuffer(" 1=1 ");
  200. if (content.containsKey("where")) {
  201. JSONObject whereObject = content.getJSONObject("where");
  202. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  203. where.append(" and(");
  204. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  205. where.append("or t1.province like'%").append(whereObject.getString("condition")).append("%' ");
  206. where.append("or t1.city like'%").append(whereObject.getString("condition")).append("%' ");
  207. where.append("or t1.county like'%").append(whereObject.getString("condition")).append("%' ");
  208. where.append("or t1.address like'%").append(whereObject.getString("condition")).append("%' ");
  209. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  210. where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
  211. where.append("or t6.name like'%").append(whereObject.getString("condition")).append("%' ");
  212. where.append("or t8.depname like'%").append(whereObject.getString("condition")).append("%' ");
  213. where.append(")");
  214. }
  215. }
  216. where.append(" and ( t1.datastatus in (0,2) )");
  217. String where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
  218. + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
  219. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "sa_customersid", "createby", "createdate",
  220. "sys_enterpriseid", "status", "type", "tradingstatus", "datastatus", "billno", "province", "city", "county", "address", "stagename", "grade");
  221. querySQL.setTableAlias("t1");
  222. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t2.sys_enterpriseid = t1.sys_enterpriseid AND t2.siteid = t1.siteid", "enterprisename");
  223. querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t3", "t3.sa_saleareaid = t1.sa_saleareaid AND t3.siteid = t1.siteid", "areaname");
  224. 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");
  225. querySQL.addJoinTable(JOINTYPE.left, "sys_hr", "t7", "t7.userid = t6.userid and t7.siteid = t6.siteid ");
  226. querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t8", "t8.departmentid = t7.departmentid and t8.siteid = t7.siteid ");
  227. querySQL.setSiteid(siteid);
  228. querySQL.setWhere(where);
  229. querySQL.setWhere(where2);
  230. querySQL.setPage(pageSize, pageNumber);
  231. querySQL.setOrderBy(pageSorting);
  232. querySQL.setRoleDataLimit(false);
  233. querySQL.withDeleteData(true);
  234. Rows rows = querySQL.query();
  235. RowsMap leaderRows = DataTeam.getLeaderWithoutHeadpic(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
  236. ArrayList<Long> ids = rows.toArrayList("sa_customersid", new ArrayList<>());
  237. //标签
  238. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, tablename, ids, false);
  239. //系统标签
  240. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, tablename, ids, true);
  241. for (Row row : rows) {
  242. Long id = row.getLong("sa_customersid");
  243. row.put("leader", leaderRows.get(String.valueOf(id)));
  244. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  245. row.put("name", leaderRows.get(String.valueOf(id)).get(0).getString("name"));
  246. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  247. }
  248. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<String>();
  249. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<String>();
  250. if (row.getString("agentsstatus").equals("禁用") || row.getString("agentsstatus").equals("作废")) {
  251. tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
  252. sys_tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
  253. }
  254. //非系统标签
  255. row.put("tag", tag);
  256. //系统标签
  257. row.put("tag_sys", sys_tag);
  258. }
  259. return getSucReturnObject().setData(rows).toString();
  260. }
  261. public RowsMap getDoctorRowsMap(List<Long> sa_hospitaldepids) throws YosException {
  262. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
  263. querySQL.setSiteid(siteid);
  264. querySQL.setWhere("t1.isleader=1");
  265. querySQL.setWhere("t1.sa_hospitaldepid ", sa_hospitaldepids);
  266. Rows rows = querySQL.query();
  267. return rows.toRowsMap("sa_hospitaldepid");
  268. }
  269. }