|
|
@@ -0,0 +1,254 @@
|
|
|
+package restcontroller.prsx.hospitaldep;
|
|
|
+
|
|
|
+import beans.brand.Brand;
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.itemclass.ItemClass;
|
|
|
+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;
|
|
|
+
|
|
|
+public class hospitaldepitem extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public hospitaldepitem(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "添加科室关联产品", apiversion = R.ID2025102110170902.v1.class)
|
|
|
+ public String insert() throws YosException {
|
|
|
+
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ Long sa_hospitaldepid = content.getLong("sa_hospitaldepid");
|
|
|
+ JSONArray itemids = content.getJSONArray("itemids");
|
|
|
+ Rows stageRows = dbConnect.runSqlQuery("SELECT sa_devstageid from sa_devstage WHERE siteid='" + siteid + "' order by sequence LIMIT 1");
|
|
|
+
|
|
|
+ Rows itemRows = dbConnect.runSqlQuery("SELECT itemid FROM sa_hospitaldep_item WHERE sa_hospitaldepid=" + sa_hospitaldepid + " AND siteid='" + siteid + "'");
|
|
|
+ RowsMap itemRowsMap = itemRows.toRowsMap("itemid");
|
|
|
+ for (Object object : itemids) {
|
|
|
+ if (itemRowsMap.containsKey(object.toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long itemid = Long.valueOf(object.toString());
|
|
|
+ Long sa_hospitaldep_itemid = createTableID("sa_hospitaldep_item");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_hospitaldep_item");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_hospitaldep_itemid);
|
|
|
+ insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
|
|
|
+ insertSQL.setValue("itemid", itemid);
|
|
|
+ insertSQL.setValue("sa_devstageid", stageRows.isNotEmpty() ? stageRows.get(0).getString("sa_devstageid") : 0);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "添加", "添加产品:" + getItemName(itemid)).getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ updateStages(sa_hospitaldepid);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "设置阶段", apiversion = R.ID2025102110224102.v1.class)
|
|
|
+ public String updateStage() throws YosException {
|
|
|
+ Long sa_hospitaldep_itemid = content.getLongValue("sa_hospitaldep_itemid");
|
|
|
+ Long sa_devstageid = content.getLongValue("sa_devstageid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep_item where sa_hospitaldep_itemid=" + sa_hospitaldep_itemid);
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("数据不存在").toString();
|
|
|
+ }
|
|
|
+ Long sa_hospitaldepid = rows.isNotEmpty() ? rows.get(0).getLong("sa_hospitaldepid") : 0;
|
|
|
+ Long itemid = rows.isNotEmpty() ? rows.get(0).getLong("itemid") : 0;
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_hospitaldep_item");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_hospitaldep_itemid);
|
|
|
+ updateSQL.setValue("sa_devstageid", sa_devstageid);
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+ DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "设置阶段", "产品【" + getItemName(itemid) + "】设置阶段:" + getStageName(sa_devstageid)).insert();
|
|
|
+
|
|
|
+ updateStages(sa_hospitaldepid);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "删除科室关联产品", apiversion = R.ID2025102110202602.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+ Long sa_hospitaldep_itemid = content.getLong("sa_hospitaldep_itemid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep_item where sa_hospitaldep_itemid=" + sa_hospitaldep_itemid);
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("数据不存在").toString();
|
|
|
+ }
|
|
|
+ Long sa_hospitaldepid = rows.isNotEmpty() ? rows.get(0).getLong("sa_hospitaldepid") : 0;
|
|
|
+ Long itemid = rows.isNotEmpty() ? rows.get(0).getLong("itemid") : 0;
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_hospitaldep_item");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setUniqueid(sa_hospitaldep_itemid);
|
|
|
+ deleteSQL.delete();
|
|
|
+
|
|
|
+ DataContrlLog.createLog(this, "sa_hospitaldep", sa_hospitaldepid, "删除", "删除产品:" + getItemName(itemid)).insert();
|
|
|
+
|
|
|
+ updateStages(sa_hospitaldepid);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "查询科室关联产品", apiversion = R.ID2025102110205102.v1.class)
|
|
|
+ public String list() 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.assistance like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.explains like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t4.stagename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ Long sa_hospitaldepid = content.getLong("sa_hospitaldepid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item",
|
|
|
+ "itemid", "itemno", "itemname", "model", "spec", "assistance", "goodstype", "explains")
|
|
|
+ .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");
|
|
|
+ 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");
|
|
|
+ querySQL.setWhere("t3.sa_hospitaldepid", sa_hospitaldepid);
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "选择产品列表", apiversion = R.ID2025102110220202.v1.class)
|
|
|
+ public String chooseList() 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.assistance like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.explains like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("model") && !"".equals(whereObject.getString("model"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.model like'%").append(whereObject.getString("model")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("spec") && !"".equals(whereObject.getString("spec"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.spec like'%").append(whereObject.getString("spec")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("itemclassid") && !"".equals(whereObject.getString("itemclassid"))) {
|
|
|
+ Long itemclassid = whereObject.getLong("itemclassid");
|
|
|
+ ArrayList<Long> itemclassids = ItemClass.getSubItemClassIds(this, itemclassid);
|
|
|
+ itemclassids.add(itemclassid);
|
|
|
+ String sql = " and t1.itemid in( SELECT itemid from sa_itemsaleclass WHERE itemclassid in " + itemclassids + " and siteid='" + siteid + "')";
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(sql);
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("sa_brandid") && !"".equals(whereObject.getString("sa_brandid"))) {
|
|
|
+ where.append(" and t1.itemid in( SELECT DISTINCT itemid from sa_itemsaleclass WHERE itemclassid in (SELECT itemclassid from plm_itemclass WHERE sa_brandid = " + whereObject.getLong("sa_brandid") + " and siteid = '" + siteid + "'))");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item",
|
|
|
+ "itemid", "itemno", "itemname", "model", "spec", "assistance", "goodstype", "explains")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_itemextend", "t2", "t2.itemid = t1.itemid AND t2.siteid = t1.siteid",
|
|
|
+ "erpitemname", "erpitemno");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ // 附件
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
|
|
|
+ // 商品品牌
|
|
|
+ RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
|
|
|
+ RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Rows brandRows = brandRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ Rows itemclassRows = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ row.put("brandname", StringUtils.join(brandRows.toArray("brandname"), ","));
|
|
|
+ row.put("itemclassname", StringUtils.join(itemclassRows.toArray("itemclassname"), ","));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateStages(Long sa_hospitaldepid) throws YosException {
|
|
|
+ String stagename = "";
|
|
|
+ //获取最初的阶段
|
|
|
+ Rows stagenameRows = dbConnect.runSqlQuery("SELECT sa_devstageid from sa_devstage WHERE siteid='" + siteid + "' order by sequence LIMIT 1");
|
|
|
+ stagename = stagenameRows.isNotEmpty() ? stagenameRows.get(0).getString("stagename") : "";
|
|
|
+
|
|
|
+ stagenameRows = dbConnect.runSqlQuery("SELECT stagename FROM sa_hospitaldep_item t1 " +
|
|
|
+ "INNER JOIN sa_devstage t2 ON t2.sa_devstageid=t1.sa_devstageid " +
|
|
|
+ "WHERE t1.sa_hospitaldepid=" + sa_hospitaldepid + " ORDER BY sequence DESC LIMIT 1");
|
|
|
+ if (stagenameRows.isNotEmpty()) {
|
|
|
+ stagename = stagenameRows.get(0).getString("stagename");
|
|
|
+ }
|
|
|
+ //更新科室阶段
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_hospitaldep");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_hospitaldepid", sa_hospitaldepid);
|
|
|
+ updateSQL.setValue("stagename", stagename);
|
|
|
+ updateSQL.update();
|
|
|
+ //更新医院阶段
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE sa_hospitaldepid=" + sa_hospitaldepid);
|
|
|
+ Long sa_customersid = rows.isNotEmpty() ? rows.get(0).getLong("sa_customersid") : 0;
|
|
|
+
|
|
|
+ stagenameRows=dbConnect.runSqlQuery("SELECT t2.stagename FROM sa_hospitaldep_item t1 " +
|
|
|
+ "INNER JOIN sa_devstage t2 ON t2.sa_devstageid=t1.sa_devstageid " +
|
|
|
+ "INNER JOIN sa_hospitaldep t3 ON t3.sa_hospitaldepid=t1.sa_hospitaldepid " +
|
|
|
+ "WHERE t3.sa_customersid="+sa_customersid+" ORDER BY sequence DESC LIMIT 1");
|
|
|
+ if (stagenameRows.isNotEmpty()) {
|
|
|
+ stagename = stagenameRows.get(0).getString("stagename");
|
|
|
+ }
|
|
|
+ updateSQL = SQLFactory.createUpdateSQL(this, "sa_customers");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_customersid", sa_customersid);
|
|
|
+ updateSQL.setValue("stagename", stagename);
|
|
|
+ updateSQL.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getItemName(Long itemid) throws YosException {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from plm_item WHERE siteid='" + siteid + "' and itemid=" + itemid);
|
|
|
+ return rows.isNotEmpty() ? rows.get(0).getString("itemno") + "-" + rows.get(0).getString("itemname") : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getStageName(Long sa_devstageid) throws YosException {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_devstage WHERE siteid='" + siteid + "' and sa_devstageid=" + sa_devstageid);
|
|
|
+ return rows.isNotEmpty() ? rows.get(0).getString("stagename") : "";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|