|
|
@@ -2,6 +2,7 @@ package restcontroller.webmanage.sale.salestarget2;
|
|
|
|
|
|
import beans.brand.Brand;
|
|
|
import beans.itemclass.ItemClass;
|
|
|
+import beans.salearea.SaleArea;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
@@ -534,13 +535,13 @@ public class salestargetstatistics extends Controller {
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "sys_hr", "t6", "t6.hrid=t2.saler_hrid and t6.siteid=t2.siteid");
|
|
|
|
|
|
querySQL.addQueryFields("salename", "t6.name");
|
|
|
- if(type==1){
|
|
|
+ if (type == 1) {
|
|
|
querySQL.setWhere("t6.userid", userid);
|
|
|
}
|
|
|
- if(type==2){
|
|
|
+ if (type == 2) {
|
|
|
querySQL.setWhere("t2.sa_customersid", sa_customersid);
|
|
|
}
|
|
|
- if(type==3){
|
|
|
+ if (type == 3) {
|
|
|
querySQL.setWhere("t2.sa_agentsid", sa_agentsid);
|
|
|
}
|
|
|
|
|
|
@@ -653,6 +654,7 @@ public class salestargetstatistics extends Controller {
|
|
|
arearow.putIfAbsent(key + "_saleamount_mom", saleamount_mom);
|
|
|
arearow.putIfAbsent(key + "_saleamount_yoy", saleamount_yoy);
|
|
|
arearow.putIfAbsent(key + "_targetamount", targetamount);
|
|
|
+ arearow.putIfAbsent(key+"_balanceamount", saleamount.subtract(targetamount));
|
|
|
//计算达成率
|
|
|
arearow.put(key + "_rate_achieve", calculateAchieveRate(saleamount, targetamount));
|
|
|
//计算环比
|
|
|
@@ -773,4 +775,83 @@ public class salestargetstatistics extends Controller {
|
|
|
YearMonth ym = YearMonth.parse(yyyyMM);
|
|
|
return ym.minusYears(1).format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
}
|
|
|
+
|
|
|
+ @API(title = "小程序人员目标概况", apiversion = R.ID2026010509531602.v1.class)
|
|
|
+ public String mAPeopleInfo() throws YosException {
|
|
|
+ int year = content.getIntValue("year");
|
|
|
+ int befyear = year - 1;
|
|
|
+ int month = content.getIntValue("month");
|
|
|
+ String currentMonth = year + "-" + (month > 9 ? month : "0" + month);
|
|
|
+ Long sa_saleareaid = content.getLongValue("sa_saleareaid");
|
|
|
+
|
|
|
+ ArrayList<Long> sa_saleareaids = new ArrayList<>();
|
|
|
+ if (sa_saleareaid == 0) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea_hr WHERE siteid='" + siteid + "' and hrid=" + hrid);
|
|
|
+ sa_saleareaids = rows.toArrayList("sa_saleareaid", new ArrayList<>());
|
|
|
+ if (sa_saleareaids.size() == 0) {
|
|
|
+ rows = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea WHERE siteid='" + siteid + "' and level=1");
|
|
|
+ sa_saleareaids = rows.toArrayList("sa_saleareaid", new ArrayList<>());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ sa_saleareaids.add(sa_saleareaid);
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<Long> subSaleAreaIds = SaleArea.getSubSaleAreaIds(this, sa_saleareaids);
|
|
|
+ subSaleAreaIds.add(sa_saleareaid);
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ String sql = " and t4.sa_saleareaid in " + subSaleAreaIds + " ";
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(sql);
|
|
|
+
|
|
|
+ Rows arearows = new Rows();
|
|
|
+ Row temprow = new Row();
|
|
|
+ temprow.put("yearmonth", currentMonth);
|
|
|
+ arearows.add(temprow);
|
|
|
+
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "小程序人员订单概况");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", year);
|
|
|
+ sqlFactory.addParameter("befyear", befyear);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ RowsMap salesRowsMap = rows.toRowsMap("ym");
|
|
|
+
|
|
|
+ sqlFactory = new SQLFactory(this, "小程序人员目标概况");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", year);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ Rows targetrows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+
|
|
|
+
|
|
|
+ Rows datas = new Rows();
|
|
|
+ Rows salesRows = salesRowsMap.getOrDefault(currentMonth, new Rows());
|
|
|
+ RowsMap dateDateRow = salesRows.toRowsMap("ym");
|
|
|
+ for (String date : yearToDate(year + "-12")) {
|
|
|
+ Rows dateDate = dateDateRow.getOrDefault(date, new Rows());
|
|
|
+ Row row = new Row();
|
|
|
+ row.put("currentMonth", currentMonth);
|
|
|
+ processDataRows(datas, row, dateDate, targetrows, date);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ RowsMap dataRowsMap = datas.toRowsMap("tempMonth");
|
|
|
+
|
|
|
+ for (Row arearow : arearows) {
|
|
|
+ Rows dataRows = dataRowsMap.getOrDefault(arearow.getString("tempMonth"), new Rows());
|
|
|
+ //计算当前月份
|
|
|
+ ArrayList<String> dates = new ArrayList<>();
|
|
|
+ dates.add(currentMonth);
|
|
|
+ calculate("m", arearow, dataRows, dates);
|
|
|
+ //计算季度
|
|
|
+ calculate("s", arearow, dataRows, quarterToDate(currentMonth));
|
|
|
+ //计算年度
|
|
|
+ calculate("y", arearow, dataRows, yearToDate(currentMonth));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(arearows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|