|
|
@@ -75,22 +75,7 @@ public class salestargetstatistics extends Controller {
|
|
|
Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
Row row = new Row();
|
|
|
row.put("sa_saleareaid", sa_saleareaid);
|
|
|
- row.put("ym", date);
|
|
|
- row.put("amount", dateDate.isNotEmpty() ? dateDate.get(0).getBigDecimal("amount") : 0);
|
|
|
- //根据日期中的月份(如 "11")从 targetRows 中动态取出对应的 m{月}amount 字段值
|
|
|
- String monthPart = date.split("-")[1];
|
|
|
- String fieldName = "m" + Integer.parseInt(monthPart) + "amount";
|
|
|
- BigDecimal target = BigDecimal.ZERO;
|
|
|
- if (!targetRows.isEmpty()) {
|
|
|
- Object val = targetRows.get(0).get(fieldName);
|
|
|
- if (val instanceof BigDecimal) {
|
|
|
- target = (BigDecimal) val;
|
|
|
- } else if (val != null) {
|
|
|
- target = new BigDecimal(val.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- row.put("target", target);
|
|
|
- datas.add(row);
|
|
|
+ processDataRows(datas, row, dateDate, targetRows, date);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -149,22 +134,7 @@ public class salestargetstatistics extends Controller {
|
|
|
Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
Row row = new Row();
|
|
|
row.put("userid", userid);
|
|
|
- row.put("ym", date);
|
|
|
- row.put("amount", dateDate.isNotEmpty() ? dateDate.get(0).getBigDecimal("amount") : 0);
|
|
|
- //根据日期中的月份(如 "11")从 targetRows 中动态取出对应的 m{月}amount 字段值
|
|
|
- String monthPart = date.split("-")[1];
|
|
|
- String fieldName = "m" + Integer.parseInt(monthPart) + "amount";
|
|
|
- BigDecimal target = BigDecimal.ZERO;
|
|
|
- if (!targetRows.isEmpty()) {
|
|
|
- Object val = targetRows.get(0).get(fieldName);
|
|
|
- if (val instanceof BigDecimal) {
|
|
|
- target = (BigDecimal) val;
|
|
|
- } else if (val != null) {
|
|
|
- target = new BigDecimal(val.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- row.put("target", target);
|
|
|
- datas.add(row);
|
|
|
+ processDataRows(datas, row, dateDate, targetRows, date);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -220,22 +190,7 @@ public class salestargetstatistics extends Controller {
|
|
|
Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
Row row = new Row();
|
|
|
row.put("sa_customersid", sa_customersid);
|
|
|
- row.put("ym", date);
|
|
|
- row.put("amount", dateDate.isNotEmpty() ? dateDate.get(0).getBigDecimal("amount") : 0);
|
|
|
- //根据日期中的月份(如 "11")从 targetRows 中动态取出对应的 m{月}amount 字段值
|
|
|
- String monthPart = date.split("-")[1];
|
|
|
- String fieldName = "m" + Integer.parseInt(monthPart) + "amount";
|
|
|
- BigDecimal target = BigDecimal.ZERO;
|
|
|
- if (!targetRows.isEmpty()) {
|
|
|
- Object val = targetRows.get(0).get(fieldName);
|
|
|
- if (val instanceof BigDecimal) {
|
|
|
- target = (BigDecimal) val;
|
|
|
- } else if (val != null) {
|
|
|
- target = new BigDecimal(val.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- row.put("target", target);
|
|
|
- datas.add(row);
|
|
|
+ processDataRows(datas, row, dateDate, targetRows, date);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -291,22 +246,7 @@ public class salestargetstatistics extends Controller {
|
|
|
Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
Row row = new Row();
|
|
|
row.put("sa_agentsid", sa_agentsid);
|
|
|
- row.put("ym", date);
|
|
|
- row.put("amount", dateDate.isNotEmpty() ? dateDate.get(0).getBigDecimal("amount") : 0);
|
|
|
- //根据日期中的月份(如 "11")从 targetRows 中动态取出对应的 m{月}amount 字段值
|
|
|
- String monthPart = date.split("-")[1];
|
|
|
- String fieldName = "m" + Integer.parseInt(monthPart) + "amount";
|
|
|
- BigDecimal target = BigDecimal.ZERO;
|
|
|
- if (!targetRows.isEmpty()) {
|
|
|
- Object val = targetRows.get(0).get(fieldName);
|
|
|
- if (val instanceof BigDecimal) {
|
|
|
- target = (BigDecimal) val;
|
|
|
- } else if (val != null) {
|
|
|
- target = new BigDecimal(val.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- row.put("target", target);
|
|
|
- datas.add(row);
|
|
|
+ processDataRows(datas, row, dateDate, targetRows, date);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -327,12 +267,13 @@ public class salestargetstatistics extends Controller {
|
|
|
|
|
|
@API(title = "统计看板", apiversion = R.ID2025122915143202.v1.class)
|
|
|
public String peoplePanel() throws YosException {
|
|
|
+ int type = content.getIntValue("type", 1);
|
|
|
int year = content.getIntValue("year");
|
|
|
int befyear = year - 1;
|
|
|
Long userid = content.getLongValue("userid");
|
|
|
Long sa_customersid = content.getLongValue("sa_customersid");
|
|
|
Long sa_agentsid = content.getLongValue("sa_agentsid");
|
|
|
- int type = content.getIntValue("type", 1);
|
|
|
+
|
|
|
|
|
|
Rows itemclassrows = dbConnect.runSqlQuery("SELECT DISTINCT itemclassname from plm_itemclass WHERE siteid='" + siteid + "' ");
|
|
|
|
|
|
@@ -417,21 +358,195 @@ public class salestargetstatistics extends Controller {
|
|
|
return getSucReturnObject().setData(itemclassrows).toString();
|
|
|
}
|
|
|
|
|
|
- @API(title = "医院统计看板", apiversion = R.ID2025123014532102.v1.class)
|
|
|
- public String doctorPanel() throws YosException {
|
|
|
+ @API(title = "统计明细", apiversion = R.ID2025123014532102.v1.class)
|
|
|
+ public String targetMX() throws YosException {
|
|
|
+ int type = content.getIntValue("type", 1);
|
|
|
+ int year = content.getIntValue("year");
|
|
|
+ int befyear = year - 1;
|
|
|
+ String yearMonthStr = year + "-12";
|
|
|
+ Long userid = content.getLongValue("userid");
|
|
|
+ Long sa_customersid = content.getLongValue("sa_customersid");
|
|
|
+ Long sa_agentsid = content.getLongValue("sa_agentsid");
|
|
|
+
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("sa_customersid") && !"".equals(whereObject.getString("sa_customersid"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t4.sa_customersid ='").append(whereObject.getString("sa_customersid")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("sa_hospitaldepid") && !"".equals(whereObject.getString("sa_hospitaldepid"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.sa_hospitaldepid ='").append(whereObject.getString("sa_hospitaldepid")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("itemclassname") && !"".equals(whereObject.getString("itemclassname"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t8.itemclassname ='").append(whereObject.getString("itemclassname")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- return getSucReturnObject().setData("").toString();
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "查询人员的统计商品明细");
|
|
|
+ if (type == 1) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询人员的统计商品明细");
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ }
|
|
|
+ if (type == 2) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询医院的统计商品明细");
|
|
|
+ sqlFactory.addParameter("sa_customersid", sa_customersid);
|
|
|
+ }
|
|
|
+ if (type == 3) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询经销商的统计商品明细");
|
|
|
+ sqlFactory.addParameter("sa_agentsid", sa_agentsid);
|
|
|
+ }
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", year);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ Rows itemrows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+
|
|
|
+ sqlFactory = new SQLFactory(this, "查询人员的订单商品明细统计");
|
|
|
+ if (type == 1) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询人员的订单商品明细统计");
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ }
|
|
|
+ if (type == 2) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询医院的订单商品明细统计");
|
|
|
+ sqlFactory.addParameter("sa_customersid", sa_customersid);
|
|
|
+ }
|
|
|
+ if (type == 3) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询经销商的订单商品明细统计");
|
|
|
+ sqlFactory.addParameter("sa_agentsid", sa_agentsid);
|
|
|
+ }
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", year);
|
|
|
+ sqlFactory.addParameter("befyear", befyear);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ RowsMap salesRowsMap = rows.toRowsMap("keyid");
|
|
|
+
|
|
|
+ sqlFactory = new SQLFactory(this, "查询人员的目标商品明细统计");
|
|
|
+ if (type == 1) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询人员的目标商品明细统计");
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ }
|
|
|
+ if (type == 2) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询医院的目标商品明细统计");
|
|
|
+ sqlFactory.addParameter("sa_customersid", sa_customersid);
|
|
|
+ }
|
|
|
+ if (type == 3) {
|
|
|
+ sqlFactory = new SQLFactory(this, "查询经销商的目标商品明细统计");
|
|
|
+ sqlFactory.addParameter("sa_agentsid", sa_agentsid);
|
|
|
+ }
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", year);
|
|
|
+ sqlFactory.addParameter("befyear", befyear);
|
|
|
+ Rows targetrows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ RowsMap targetRowsMap = targetrows.toRowsMap("keyid");
|
|
|
+
|
|
|
+ ArrayList<String> keyids = itemrows.toArrayList("keyid");
|
|
|
+ ArrayList<String> alldates = yearToDate(yearMonthStr);
|
|
|
+ Rows datas = new Rows();
|
|
|
+ for (String keyid : keyids) {
|
|
|
+ Rows salesRows = salesRowsMap.getOrDefault(keyid, new Rows());
|
|
|
+ RowsMap dateDateRow = salesRows.toRowsMap("ym");
|
|
|
+ Rows targetRows = targetRowsMap.getOrDefault(keyid, new Rows());
|
|
|
+ for (String date : alldates) {
|
|
|
+ Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
+ Row row = new Row();
|
|
|
+ row.put("keyid", keyid);
|
|
|
+ processDataRows(datas, row, dateDate, targetRows, date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ RowsMap dataRowsMap = datas.toRowsMap("keyid");
|
|
|
+
|
|
|
+ for (Row itemrow : itemrows) {
|
|
|
+ Rows dataRows = dataRowsMap.getOrDefault(itemrow.getString("keyid"), new Rows());
|
|
|
+ //计算月份
|
|
|
+ for (String date : alldates) {
|
|
|
+ String monthPart = date.split("-")[1];
|
|
|
+ String fieldName = "m" + Integer.parseInt(monthPart);
|
|
|
+ calculate(fieldName, itemrow, dataRows, date);
|
|
|
+ }
|
|
|
+ //计算年度
|
|
|
+ calculate("y", itemrow, dataRows, yearToDate(yearMonthStr));
|
|
|
+ }
|
|
|
+
|
|
|
+ Row totalRow = new Row();
|
|
|
+ totalRow.put("hospitalname", "合计");
|
|
|
+ totalRow.put("hospitaldepname", "合计");
|
|
|
+ // 处理1-12月数据
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
+ processMonthData(itemrows, totalRow, "m" + i);
|
|
|
+ }
|
|
|
+ // 处理年度数据
|
|
|
+ processMonthData(itemrows, totalRow, "y");
|
|
|
+ itemrows.add(0, totalRow);
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(itemrows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "营销类别明细", apiversion = R.ID2025123014533002.v1.class)
|
|
|
+ public String itemclassname() throws YosException {
|
|
|
+
|
|
|
+ Rows rows=dbConnect.runSqlQuery("SELECT DISTINCT itemclassname from plm_itemclass WHERE siteid='"+siteid+"'");
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows.toArrayList("itemclassname")).toString();
|
|
|
}
|
|
|
|
|
|
- @API(title = "经销商统计看板", apiversion = R.ID2025123014533002.v1.class)
|
|
|
- public String agentPanel() throws YosException {
|
|
|
+ @API(title = "经销商目标明细", apiversion = R.ID2025123114300602.v1.class)
|
|
|
+ public String agentMX() throws YosException {
|
|
|
|
|
|
|
|
|
return getSucReturnObject().setData("").toString();
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private void processDataRows(Rows datas, Row row, Rows dateDate, Rows targetRows, String date) {
|
|
|
+ row.put("ym", date);
|
|
|
+ row.put("amount", dateDate.isNotEmpty() ? dateDate.get(0).getBigDecimal("amount") : 0);
|
|
|
+ //根据日期中的月份(如 "11")从 targetRows 中动态取出对应的 m{月}amount 字段值
|
|
|
+ String monthPart = date.split("-")[1];
|
|
|
+ String fieldName = "m" + Integer.parseInt(monthPart) + "amount";
|
|
|
+ BigDecimal target = BigDecimal.ZERO;
|
|
|
+ if (!targetRows.isEmpty()) {
|
|
|
+ Object val = targetRows.get(0).get(fieldName);
|
|
|
+ if (val instanceof BigDecimal) {
|
|
|
+ target = (BigDecimal) val;
|
|
|
+ } else if (val != null) {
|
|
|
+ target = new BigDecimal(val.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row.put("target", target);
|
|
|
+ datas.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算合计
|
|
|
+ private void processMonthData(Rows itemrows, Row row, String key) {
|
|
|
+ BigDecimal saleamount = itemrows.sum(key + "_saleamount");
|
|
|
+ BigDecimal saleamount_mom = itemrows.sum(key + "_saleamount_mom");
|
|
|
+ BigDecimal saleamount_yoy = itemrows.sum(key + "_saleamount_yoy");
|
|
|
+ BigDecimal targetamount = itemrows.sum(key + "_targetamount");
|
|
|
+
|
|
|
+ row.put(key + "_saleamount", saleamount);
|
|
|
+ row.put(key + "_saleamount_mom", saleamount_mom);
|
|
|
+ row.put(key + "_saleamount_yoy", saleamount_yoy);
|
|
|
+ row.put(key + "_targetamount", targetamount);
|
|
|
+
|
|
|
+ // 计算达成率
|
|
|
+ row.put(key + "_rate_achieve", calculateAchieveRate(saleamount, targetamount));
|
|
|
+ // 计算环比
|
|
|
+ row.put(key + "_rate_mom", calculateRate(saleamount, saleamount_mom));
|
|
|
+ // 计算同比
|
|
|
+ row.put(key + "_rate_yoy", calculateRate(saleamount, saleamount_yoy));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void calculate(String key, Row arearow, Rows dataRows, ArrayList<String> dates) {
|
|
|
BigDecimal saleamount = BigDecimal.ZERO;
|
|
|
BigDecimal saleamount_mom = BigDecimal.ZERO;
|