|
|
@@ -1,21 +1,32 @@
|
|
|
package restcontroller.webmanage.sale.salestarget2;
|
|
|
|
|
|
+import beans.CommonHepler;
|
|
|
import beans.brand.Brand;
|
|
|
+import beans.datatag.DataTag;
|
|
|
+import beans.datateam.DataTeam;
|
|
|
import beans.itemclass.ItemClass;
|
|
|
+import beans.recycle.Recycle;
|
|
|
import beans.salearea.SaleArea;
|
|
|
+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 org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import restcontroller.R;
|
|
|
+import restcontroller.sale.customer.ExportExcel;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.YearMonth;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.IsoFields;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
|
|
|
public class salestargetstatistics extends Controller {
|
|
|
/**
|
|
|
@@ -859,5 +870,210 @@ public class salestargetstatistics extends Controller {
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "查询当前账号所在区域以及下级区域的医院", apiversion = R.ID2026010516151802.v1.class)
|
|
|
+ public String hospitalList() throws YosException {
|
|
|
+ String tablename = "sa_customers";
|
|
|
+ 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.billno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.province like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.city like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.county like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.address like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t6.name like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t8.depname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.areaname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //营销区域
|
|
|
+
|
|
|
+ if (whereObject.containsKey("sa_saleareaid") && !"".equals(whereObject.getString("sa_saleareaid"))) {
|
|
|
+ Long sa_saleareaid = whereObject.getLong("sa_saleareaid");
|
|
|
+ ArrayList<Long> sa_saleareaids = SaleArea.getSubSaleAreaIds(this, sa_saleareaid);
|
|
|
+ sa_saleareaids.add(sa_saleareaid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT DISTINCT t2.userid from sa_salearea_hr t1 " +
|
|
|
+ "inner join sys_hr t2 ON t2.hrid=t1.hrid and t2.siteid=t1.siteid " +
|
|
|
+ "WHERE t1.siteid='" + siteid + "' and t1.sa_saleareaid in(" + StringUtils.join(sa_saleareaids, ",") + ") and t2.userid>0");
|
|
|
+ HashSet<Long> userIds = new HashSet<>(rows.toArrayList("userid", new ArrayList<>()));
|
|
|
+ userIds.add(-1L);
|
|
|
+ where.append(" and(");
|
|
|
+ where.append(" t6.userid in ").append(userIds.toString().replace("[", "(").replace("]", ")"));
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ where.append(" and ( t1.datastatus in (0,2) )");
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "sa_customersid", "createby", "createdate",
|
|
|
+ "sys_enterpriseid", "status", "type", "tradingstatus", "datastatus", "billno", "province", "city", "county", "address", "stagename", "grade", "sa_saleareaid");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t2.sys_enterpriseid = t1.sys_enterpriseid AND t2.siteid = t1.siteid", "enterprisename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t3", "t3.sa_saleareaid = t1.sa_saleareaid AND t3.siteid = t1.siteid", "areaname");
|
|
|
+
|
|
|
+ QuerySQL t5 = SQLFactory.createQuerySQL(this, "sys_datafollowup", "ownerid");
|
|
|
+ t5.setWhere("ownertable", "sa_customers");
|
|
|
+ t5.setSiteid(siteid);
|
|
|
+ t5.addGroupBy("ownerid");
|
|
|
+ t5.addQueryFields("followdate", "max(createdate)");
|
|
|
+ t5.setRoleDataLimit(false);
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, t5, "t5", "t5.ownerid = t1.sa_customersid", "followdate");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t6", "t6.ownerid = t1.sa_customersid and t6.siteid = t1.siteid and t6.ownertable = 'sa_customers' and t6.isleader = 1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_hr", "t7", "t7.userid = t6.userid and t7.siteid = t6.siteid ");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t8", "t8.departmentid = t7.departmentid and t8.siteid = t7.siteid ");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t10", "t1.siteid = t10.siteid and t1.sa_customersid = t10.ownerid and t10.ownertable = 'sa_customers'", "deletereason");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setWhere("t1.sa_saleareaid", getUserAreas());
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ if (pageSorting.equals("''")) {
|
|
|
+ pageSorting = "t1.createdate desc";
|
|
|
+ }
|
|
|
+ querySQL.setOrderBy(pageSorting);
|
|
|
+
|
|
|
+ querySQL.setRoleDataLimit(false);
|
|
|
+ querySQL.withDeleteData(true);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ RowsMap leaderRows = DataTeam.getLeaderWithoutHeadpic(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_customersid", new ArrayList<>());
|
|
|
+ //标签
|
|
|
+ HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, tablename, ids, false);
|
|
|
+ //系统标签
|
|
|
+ HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, tablename, ids, true);
|
|
|
+ Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
|
|
|
+ RowsMap AgentRowsMap = CommonHepler.getAgentRowsMap(this, ids);
|
|
|
+ RowsMap KeyDoctorsRowsMap = CommonHepler.getKeyDoctorsRowsMap(this, ids);
|
|
|
+ RowsMap opRowsMap = CommonHepler.getHospitalOPRowsMap(this);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Long id = row.getLong("sa_customersid");
|
|
|
+ row.put("leader", leaderRows.get(String.valueOf(id)));
|
|
|
+ if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
|
|
|
+ row.put("name", leaderRows.get(String.valueOf(id)).get(0).getString("name"));
|
|
|
+ row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
|
|
|
+ }
|
|
|
+ ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<String>();
|
|
|
+ ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<String>();
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ ArrayList<String> tags = new ArrayList<>();
|
|
|
+ tags.addAll(tag);
|
|
|
+ tags.addAll(sys_tag);
|
|
|
+ row.put("tagstr", StringUtils.join(tags, ","));
|
|
|
+ row.putIfAbsent("followdate", "");
|
|
|
+ //预估手术总量
|
|
|
+ Rows totalop = opRowsMap.getOrDefault(String.valueOf(id), new Rows());
|
|
|
+ row.putIfAbsent("totalop", totalop.isNotEmpty() ? totalop.get(0).getInteger("qty") : 0);
|
|
|
+ //关键人
|
|
|
+ Rows KeyDoctors = KeyDoctorsRowsMap.getOrDefault(String.valueOf(id), new Rows());
|
|
|
+ row.putIfAbsent("keyperson", StringUtils.join(KeyDoctors.toArray("doctorname"), ","));
|
|
|
+ //签约经销商
|
|
|
+ Rows signagent = AgentRowsMap.getOrDefault(String.valueOf(id), new Rows());
|
|
|
+ row.putIfAbsent("signagent", StringUtils.join(signagent.toArray("enterprisename"), ","));
|
|
|
+ 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.ID2026010516152802.v1.class)
|
|
|
+ public String agentList() 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.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t5.salernames like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ where.append(" and t1.status !='作废' ");
|
|
|
+
|
|
|
+ JSONArray sa_saleareaidsArray = content.getJSONArray("sa_saleareaids");
|
|
|
+ ArrayList<Long> sa_saleareaidsList = new ArrayList<>();
|
|
|
+ for (Object o : sa_saleareaidsArray) {
|
|
|
+ String sa_saleareaid = o.toString();
|
|
|
+ sa_saleareaidsList.add(Long.parseLong(sa_saleareaid));
|
|
|
+ sa_saleareaidsList.addAll(SaleArea.getSubSaleAreaIds(this, Long.parseLong(sa_saleareaid)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sa_saleareaidsList.size() > 0) {
|
|
|
+ String sqlStr = " and t1.sys_enterpriseid in (SELECT DISTINCT sys_enterpriseid from sys_enterprise_tradefield WHERE sa_saleareaid in " + sa_saleareaidsList + " )";
|
|
|
+ sqlStr = sqlStr.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(sqlStr);
|
|
|
+ } else {
|
|
|
+ String sqlStr = " and t1.sys_enterpriseid in (SELECT DISTINCT sys_enterpriseid from sys_enterprise_tradefield WHERE sa_saleareaid in " + getUserAreas() + " and hrid ='" + hrid + "' )";
|
|
|
+ sqlStr = sqlStr.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(sqlStr);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "查询经销商业务员");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
|
|
|
+ "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate", "scale", "mainproducts").
|
|
|
+ setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
|
|
|
+ "enterprisename", "province", "city", "county", "address");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
|
|
|
+ "erpagentnum");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t4", "t1.siteid = t4.siteid and t1.sa_agentsid = t4.ownerid and t4.ownertable = 'sa_agents'",
|
|
|
+ "deletereason");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, sqlFactory, "t5", "t5.sa_agentsid = t1.sa_agentsid", "salernames");
|
|
|
+ querySQL.addQueryFields("deletechangedate", "t4.changedate");
|
|
|
+ querySQL.addQueryFields("deletechangeby", "t4.changeby");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+
|
|
|
+ querySQL.setOrderBy("t1.createdate desc");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ RowsMap areaRowsMap = CommonHepler.getAreaRowsMap(this, rows.toArrayList("sa_agentsid", new ArrayList<>()));
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
|
|
|
+ Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
|
|
|
+ row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<Long> getUserAreas() throws YosException {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea_hr WHERE siteid='" + siteid + "' and hrid=" + hrid);
|
|
|
+ ArrayList<Long> sa_saleareaids = rows.toArrayList("sa_saleareaid", new ArrayList<>());
|
|
|
+ ArrayList<Long> subSaleAreaIds = SaleArea.getSubSaleAreaIds(this, sa_saleareaids);
|
|
|
+ subSaleAreaIds.addAll(sa_saleareaids);
|
|
|
+ subSaleAreaIds.add(-1L);
|
|
|
+ return subSaleAreaIds;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|