|
@@ -1,6 +1,7 @@
|
|
|
package restcontroller.webmanage.sale.salestarget;
|
|
|
|
|
|
import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.salearea.SaleArea;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
@@ -12,9 +13,13 @@ import common.data.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
import restcontroller.R;
|
|
|
+import restcontroller.sale.promotion.promotion;
|
|
|
+import restcontroller.sale.salestarget.enterprise;
|
|
|
import restcontroller.webmanage.saletool.orderclue.ExportExcel;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
public class enterprisetarget extends Controller {
|
|
@@ -193,6 +198,101 @@ public class enterprisetarget extends Controller {
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "经销商业绩列表(区域经理)", apiversion = R.ID20231103100503.v1.class)
|
|
|
+ public String selectAgentTargetList() throws YosException {
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int curryear = calendar.get(Calendar.YEAR);
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 and year="+curryear);
|
|
|
+
|
|
|
+ SQLFactory areasqlFactory = new SQLFactory(new promotion(content), "区域经理查询下属营销区域");
|
|
|
+ areasqlFactory.addParameter("siteid", siteid);
|
|
|
+ areasqlFactory.addParameter("hrid", hrid);
|
|
|
+ Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
|
|
|
+
|
|
|
+
|
|
|
+ if(arearows.isNotEmpty() && arearows.size()>1){
|
|
|
+ ArrayList<Long> arrayList =arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
|
|
|
+ arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
|
|
|
+ String sql = " and sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in "+arrayList+") ";
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ where=where.append(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //考核指标类型
|
|
|
+ String assessmentindicators="";
|
|
|
+ if(curryear!=0){
|
|
|
+ Rows rows =dbConnect.runSqlQuery("SELECT assessmentindicators FROM sa_salestargetbill WHERE `year` = " + curryear + " AND targettype ='企业目标' AND siteid = '" + siteid + "'");
|
|
|
+ if(rows.isNotEmpty()){
|
|
|
+ assessmentindicators=rows.get(0).getString("assessmentindicators");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ String sql = sqlFactory.getSQL();
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sql);
|
|
|
+
|
|
|
+ Rows actualRows = new Rows();
|
|
|
+ //开票
|
|
|
+// if (assessmentindicators.equals("开票")) {
|
|
|
+// sqlFactory = new SQLFactory(this, "企业-开票");
|
|
|
+// }
|
|
|
+// //订单
|
|
|
+// if (assessmentindicators.equals("订单")) {
|
|
|
+// sqlFactory = new SQLFactory(this, "企业-订单");
|
|
|
+// }
|
|
|
+// //出货
|
|
|
+// if (assessmentindicators.equals("出货")) {
|
|
|
+// sqlFactory = new SQLFactory(this, "企业-出货");
|
|
|
+// }
|
|
|
+ //收款
|
|
|
+ if (assessmentindicators.equals("收款")) {
|
|
|
+ sqlFactory = new SQLFactory(this, "企业-收款");
|
|
|
+ sqlFactory.addParameter_in("sys_enterpriseid", rows.toArrayList("sys_enterpriseid",new ArrayList<Long>()));
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("year", curryear);
|
|
|
+ actualRows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ }
|
|
|
+ for (Row row : rows) {
|
|
|
+ //初始化
|
|
|
+ if (assessmentindicators.equals("收款")) {
|
|
|
+ row = addActualRow(row);
|
|
|
+ Long year = row.getLong("year");
|
|
|
+ Long sys_enterpriseid = row.getLong("sys_enterpriseid");
|
|
|
+ Row actualRow = new Row();
|
|
|
+ for (Row tempActualRow : actualRows) {
|
|
|
+ if (tempActualRow.getLong("year") == year && tempActualRow.getLong("sys_enterpriseid")==sys_enterpriseid) {
|
|
|
+ actualRow.putAll(tempActualRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row.putAll(actualRow);
|
|
|
+ row.putAll(calculate(row, actualRow));
|
|
|
+ Rows monthRows = new Rows();
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ Row monthRow = new Row();
|
|
|
+ monthRow.put("l", row.getString("m" + i + "l"));
|
|
|
+ monthRow.put("h", row.getString("m" + i + "h"));
|
|
|
+ monthRow.put("a", row.getString("m" + i + "a"));
|
|
|
+ monthRow.put("pl", row.getString("m" + i + "pl"));
|
|
|
+ monthRow.put("ph", row.getString("m" + i + "ph"));
|
|
|
+ monthRow.put("month", i);
|
|
|
+ monthRows.add(monthRow);
|
|
|
+ }
|
|
|
+ row.put("month", monthRows);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
public String getSql(String target_l, String target_h, Long id, Long sys_enterpriseid, String type, int point) {
|
|
|
|
|
|
return " UPDATE sa_salestarget SET target_l=" + target_l + ",target_h = " + target_h + " WHERE sa_salestargetbillid =" + id + " and sys_enterpriseid =" + sys_enterpriseid + " and type ='" + type + "' AND point = " + point;
|
|
@@ -495,5 +595,83 @@ public class enterprisetarget extends Controller {
|
|
|
}
|
|
|
return sheet;
|
|
|
}
|
|
|
+ //添加实际数据
|
|
|
+ public Row addActualRow(Row targetRow) {
|
|
|
+ String key = "y1a";
|
|
|
+ targetRow.put(key, 0);
|
|
|
+ for (int i = 1; i < 5; i++) {
|
|
|
+ key = "s" + i + "a";
|
|
|
+ targetRow.put(key, 0);
|
|
|
+ }
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ key = "m" + i + "a";
|
|
|
+ targetRow.put(key, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return targetRow;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Row calculate(Row targetRow, Row actualRow) {
|
|
|
+
|
|
|
+ Row row = new Row();
|
|
|
+ String key_l = "y1l";
|
|
|
+ String key_h = "y1h";
|
|
|
+ String key_a = "y1a";
|
|
|
+ String key_p_l = "y1pl";
|
|
|
+ String key_p_h = "y1ph";
|
|
|
+ if (targetRow.getDouble(key_l) == 0) {
|
|
|
+ row.put(key_p_l, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
|
|
|
+ }
|
|
|
+ if (targetRow.getDouble(key_h) == 0) {
|
|
|
+ row.put(key_p_h, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 1; i < 5; i++) {
|
|
|
+ key_l = "s" + i + "l";
|
|
|
+ key_h = "s" + i + "h";
|
|
|
+ key_a = "s" + i + "a";
|
|
|
+ key_p_l = "s" + i + "pl";
|
|
|
+ key_p_h = "s" + i + "ph";
|
|
|
+ if (targetRow.getDouble(key_l) == 0) {
|
|
|
+ row.put(key_p_l, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
|
|
|
+ }
|
|
|
+ if (targetRow.getDouble(key_h) == 0) {
|
|
|
+ row.put(key_p_h, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ key_l = "m" + i + "l";
|
|
|
+ key_h = "m" + i + "h";
|
|
|
+ key_a = "m" + i + "a";
|
|
|
+ key_p_l = "m" + i + "pl";
|
|
|
+ key_p_h = "m" + i + "ph";
|
|
|
+ if (targetRow.getDouble(key_l) == 0) {
|
|
|
+ row.put(key_p_l, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
|
|
|
+ }
|
|
|
+ if (targetRow.getDouble(key_h) == 0) {
|
|
|
+ row.put(key_p_h, 0);
|
|
|
+ } else {
|
|
|
+ row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return row;
|
|
|
+ }
|
|
|
|
|
|
+ //(实际-目标)/目标
|
|
|
+ public double getPercent(Double a, Double b) {
|
|
|
+ double c = a * 100 / b;
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(c);
|
|
|
+ return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
}
|