wu 4 месяцев назад
Родитель
Сommit
d270bb4d3e

+ 25 - 0
src/custom/restcontroller/R.java

@@ -7653,6 +7653,31 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025122510190402 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025122510234002 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025122510244202 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025122514195702 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025122514200302 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 3 - 0
src/custom/restcontroller/webmanage/sale/salestarget2/SQL/查询科室负责人.sql

@@ -0,0 +1,3 @@
+SELECT sa_hospitaldepid,GROUP_CONCAT(doctorname) doctors from sa_doctor
+WHERE  isleader=1 and siteid=$siteid$
+GROUP BY sa_hospitaldepid

+ 358 - 0
src/custom/restcontroller/webmanage/sale/salestarget2/salestarget.java

@@ -0,0 +1,358 @@
+package restcontroller.webmanage.sale.salestarget2;
+
+import beans.CommonHepler;
+import beans.brand.Brand;
+import beans.datacontrllog.DataContrlLog;
+import beans.datatag.DataTag;
+import beans.datateam.DataTeam;
+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.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class salestarget extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public salestarget(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "新增或编辑", apiversion = R.ID2025122510190402.v1.class)
+    public String insertOrUpdate() throws YosException {
+
+        Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
+
+        JSONArray items = content.getJSONArray("items");
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        ArrayList<Long> itemids = new ArrayList<>();
+        for (Object object : items) {
+            JSONObject item = (JSONObject) object;
+            Long itemid = item.getLongValue("itemid");
+            itemids.add(itemid);
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "plm_item", "*");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("itemid", itemids.toArray());
+        Rows rows = querySQL.query();
+        RowsMap rowsMap = rows.toRowsMap("itemid");
+
+        for (Object object : items) {
+            JSONObject item = (JSONObject) object;
+            Long sa_salestargetid = 0L;
+            Long sa_hospitaldepid = item.getLongValue("sa_hospitaldepid");
+            Long itemid = item.getLongValue("itemid");
+            Rows itemrows = rowsMap.get(item.getString("itemid"));
+            Row itemrow = itemrows.isNotEmpty() ? itemrows.get(0) : new Row();
+
+            Rows salestargetrows = dbConnect.runSqlQuery("SELECT * from sa_salestarget " +
+                    "WHERE siteid='" + siteid + "'  and sa_salestargetbillid=" + sa_salestargetbillid + " and sa_hospitaldepid=" + sa_hospitaldepid + " and itemid=" + itemid);
+
+            if (salestargetrows.isEmpty()) {
+                sa_salestargetid = createTableID("sa_salestarget");
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_salestarget");
+                insertSQL.setSiteid(siteid);
+                insertSQL.setUniqueid(sa_salestargetid);
+                insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
+                insertSQL.setValue("sa_salestargetbillid", sa_salestargetbillid);
+                insertSQL.setValue("itemid", itemid);
+                insertSQL.setValue("itemname", itemrow.getString("itemname"));
+                insertSQL.setValue("model", itemrow.getString("model"));
+                insertSQL.setValue("spec", itemrow.getString("spec"));
+                insertSQL.setValue("price", itemrow.getString("marketprice"));
+                insertSQL.setValue("m1", item.getBigDecimalValue("m1"));
+                insertSQL.setValue("m2", item.getBigDecimalValue("m2"));
+                insertSQL.setValue("m3", item.getBigDecimalValue("m3"));
+                insertSQL.setValue("m4", item.getBigDecimalValue("m4"));
+                insertSQL.setValue("m5", item.getBigDecimalValue("m5"));
+                insertSQL.setValue("m6", item.getBigDecimalValue("m6"));
+                insertSQL.setValue("m7", item.getBigDecimalValue("m7"));
+                insertSQL.setValue("m8", item.getBigDecimalValue("m8"));
+                insertSQL.setValue("m9", item.getBigDecimalValue("m9"));
+                insertSQL.setValue("m10", item.getBigDecimalValue("m10"));
+                insertSQL.setValue("m11", item.getBigDecimalValue("m11"));
+                insertSQL.setValue("m12", item.getBigDecimalValue("m12"));
+                sqlList.add(insertSQL.getSQL());
+                Rows hospitaldeprows = getHospitaldepRows(sa_hospitaldepid);
+                Row hospitaldeprow = hospitaldeprows.isNotEmpty() ? hospitaldeprows.get(0) : new Row();
+
+                sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "新建", "科室:" + hospitaldeprow.getString("hospitaldepname") + ";产品:" + itemrow.getString("itemname")).getSQL());
+
+            } else {
+                sa_salestargetid = salestargetrows.get(0).getLong("sa_salestargetid");
+                UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestarget");
+                updateSQL.setSiteid(siteid);
+                updateSQL.setUniqueid(sa_salestargetid);
+                updateSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
+                updateSQL.setValue("sa_salestargetbillid", sa_salestargetbillid);
+                updateSQL.setValue("itemid", itemid);
+                updateSQL.setValue("itemname", itemrow.getString("itemname"));
+                updateSQL.setValue("model", itemrow.getString("model"));
+                updateSQL.setValue("spec", itemrow.getString("spec"));
+                updateSQL.setValue("price", itemrow.getString("marketprice"));
+                updateSQL.setValue("m1", item.getBigDecimalValue("m1"));
+                updateSQL.setValue("m2", item.getBigDecimalValue("m2"));
+                updateSQL.setValue("m3", item.getBigDecimalValue("m3"));
+                updateSQL.setValue("m4", item.getBigDecimalValue("m4"));
+                updateSQL.setValue("m5", item.getBigDecimalValue("m5"));
+                updateSQL.setValue("m6", item.getBigDecimalValue("m6"));
+                updateSQL.setValue("m7", item.getBigDecimalValue("m7"));
+                updateSQL.setValue("m8", item.getBigDecimalValue("m8"));
+                updateSQL.setValue("m9", item.getBigDecimalValue("m9"));
+                updateSQL.setValue("m10", item.getBigDecimalValue("m10"));
+                updateSQL.setValue("m11", item.getBigDecimalValue("m11"));
+                updateSQL.setValue("m12", item.getBigDecimalValue("m12"));
+                sqlList.add(updateSQL.getSQL());
+                Rows hospitaldeprows = getHospitaldepRows(sa_hospitaldepid);
+                Row hospitaldeprow = hospitaldeprows.isNotEmpty() ? hospitaldeprows.get(0) : new Row();
+                sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "编辑", "科室:" + hospitaldeprow.getString("hospitaldepname") + ";产品:" + itemrow.getString("itemname")).getSQL());
+            }
+
+        }
+
+        dbConnect.runSqlUpdate(sqlList);
+
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "删除", apiversion = R.ID2025122510234002.v1.class)
+    public String delete() throws YosException {
+
+        JSONArray sa_salestargetids = content.getJSONArray("sa_salestargetids");
+        ArrayList<String> sqlList = new ArrayList<>();
+        for (Object sa_salestargetid : sa_salestargetids) {
+            Rows salestargetrows = dbConnect.runSqlQuery("SELECT * from sa_salestarget WHERE siteid='" + siteid + "'  and sa_salestargetid=" + sa_salestargetid);
+            if (salestargetrows.isEmpty()) {
+                throw new YosException("数据不存在");
+            }
+            Long sa_salestargetbillid = salestargetrows.get(0).getLong("sa_salestargetbillid");
+            Long sa_hospitaldepid = salestargetrows.get(0).getLong("sa_hospitaldepid");
+            Long itemid = salestargetrows.get(0).getLong("itemid");
+            Rows itemrows = getItemRows(itemid);
+            Row itemrow = itemrows.isNotEmpty() ? itemrows.get(0) : new Row();
+            Rows hospitaldeprows = getHospitaldepRows(sa_hospitaldepid);
+            Row hospitaldeprow = hospitaldeprows.isNotEmpty() ? hospitaldeprows.get(0) : new Row();
+            sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "删除", "科室:" + hospitaldeprow.getString("hospitaldepname") + ";产品:" + itemrow.getString("itemname")).getSQL());
+        }
+
+        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_salestarget");
+        deleteSQL.setSiteid(siteid);
+        deleteSQL.setWhere("sa_salestargetid", sa_salestargetids.toArray());
+        deleteSQL.delete();
+
+
+        dbConnect.runSqlUpdate(sqlList);
+
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "列表", apiversion = R.ID2025122510244202.v1.class)
+    public String list() throws YosException {
+        Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_salestarget", "*").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t1.sa_hospitaldepid=t2.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.sa_salestargetbillid", sa_salestargetbillid);
+
+
+        if (pageSorting.equals("''")) {
+            pageSorting = "t1.sa_hospitaldepid,t1.createdate";
+        }
+        querySQL.setCondition("t1.itemname", "t2.hospitaldepname");
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        for (Row row : rows) {
+            BigDecimal price = row.getBigDecimal("price");
+            row.put("m1_amount", price.multiply(row.getBigDecimal("m1")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m2_amount", price.multiply(row.getBigDecimal("m2")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m3_amount", price.multiply(row.getBigDecimal("m3")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m4_amount", price.multiply(row.getBigDecimal("m4")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m5_amount", price.multiply(row.getBigDecimal("m5")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m6_amount", price.multiply(row.getBigDecimal("m6")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m7_amount", price.multiply(row.getBigDecimal("m7")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m8_amount", price.multiply(row.getBigDecimal("m8")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m9_amount", price.multiply(row.getBigDecimal("m9")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m10_amount", price.multiply(row.getBigDecimal("m10")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m11_amount", price.multiply(row.getBigDecimal("m11")).setScale(2, RoundingMode.HALF_UP));
+            row.put("m12_amount", price.multiply(row.getBigDecimal("m12")).setScale(2, RoundingMode.HALF_UP));
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "选择科室", apiversion = R.ID2025122514195702.v1.class)
+    public String choosehospitaldep() 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.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(")");
+            }
+
+        }
+
+        Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
+
+        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.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setWhere("not exists(select 1 from  sa_salestarget where   sa_salestargetbillid=" + sa_salestargetbillid + " and sa_hospitaldepid=t1.sa_hospitaldepid and siteid='" + siteid + "'  )");
+        querySQL.setWhere("t2.sa_customersid in (SELECT sa_customersid from sa_salestargetbill WHERE sa_salestargetbillid="+sa_salestargetbillid+") ");
+        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.ID2025122514200302.v1.class)
+    public String chooseitems() 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("goodstype") && !"".equals(whereObject.getString("goodstype"))) {
+                where.append(" and(");
+                where.append("t1.goodstype ='").append(whereObject.getString("goodstype")).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 + "'))");
+            }
+
+        }
+
+        Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
+        Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item",
+                        "itemid", "itemno", "itemname", "model", "spec", "assistance", "goodstype", "explains", "marketprice", "orderminqty", "orderaddqty")
+                .setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_itemextend", "t2", "t2.itemid = t1.itemid AND t2.siteid = t1.siteid",
+                "erpitemname", "erpitemno");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t3", "t3.unitid = t1.unitid AND t3.siteid = t1.siteid");
+        querySQL.addQueryFields("unit", "t3.unitname");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+        querySQL.setWhere("not exists(select 1 from  sa_salestarget where sa_hospitaldepid=" + sa_hospitaldepid + " and   sa_salestargetbillid=" + sa_salestargetbillid + " and itemid=t1.itemid and siteid='" + siteid + "'  )");
+        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);
+        //查询附件
+        RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
+        for (Row row : rows) {
+            row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new 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 Rows getItemRows(Long itemid) throws YosException {
+        return dbConnect.runSqlQuery("SELECT * from plm_item WHERE siteid='" + siteid + "' and itemid=" + itemid);
+    }
+
+    public Rows getHospitaldepRows(Long sa_hospitaldepid) throws YosException {
+        return dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE siteid='" + siteid + "' and sa_hospitaldepid=" + sa_hospitaldepid);
+    }
+
+}

+ 0 - 1
src/custom/restcontroller/webmanage/sale/salestarget2/salestargetbill.java

@@ -1,7 +1,6 @@
 package restcontroller.webmanage.sale.salestarget2;
 
 import beans.datacontrllog.DataContrlLog;
-import beans.parameter.Parameter;
 import beans.salearea.SaleArea;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;