|
|
@@ -0,0 +1,455 @@
|
|
|
+package restcontroller.sale.customer;
|
|
|
+
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.dataextend.DataExtend;
|
|
|
+import beans.datatag.DataTag;
|
|
|
+import beans.datateam.DataTeam;
|
|
|
+import beans.hr.Hr;
|
|
|
+import beans.proxy.Proxy;
|
|
|
+import beans.recycle.Recycle;
|
|
|
+import beans.salearea.SaleArea;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.annotation.CACHEING_CLEAN;
|
|
|
+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.webmanage.executorService.Executor;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+
|
|
|
+import static beans.customers.Customers.getRepeatCustomers;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 医院管理
|
|
|
+ */
|
|
|
+public class Hospital extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public Hospital(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "新增或更新", apiversion = R.ID20221012163902.v1.class, intervaltime = 2000)
|
|
|
+ @CACHEING_CLEAN(apiversions = {R.ID20221022165503.v1.class, R.ID20221011133602.class, R.ID20221013102602.class,
|
|
|
+ R.ID20221012164402.class, R.ID20221014164702.class, R.ID20220920083901.class, R.ID20220929085401.class,
|
|
|
+ R.ID20220920083901.v1.class})
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ String tablename = "sa_customers";
|
|
|
+ Long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ String type = content.getString("type");
|
|
|
+ Long sys_enterpriseid = content.getLong("sys_enterpriseid");
|
|
|
+ String enterprisename = content.getString("enterprisename");
|
|
|
+ String address = content.getStringValue("address");
|
|
|
+ String province = content.getStringValue("province");
|
|
|
+ String city = content.getStringValue("city");
|
|
|
+ String county = content.getStringValue("county");
|
|
|
+ Long saler_userid = content.getLongValue("saler_userid");
|
|
|
+ if (userInfo.isSaler()) {
|
|
|
+ saler_userid = userid;
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ //创建企业档案
|
|
|
+ if (sys_enterpriseid <= 0) {
|
|
|
+ sys_enterpriseid = createTableID("sys_enterprise");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sys_enterpriseid);
|
|
|
+ insertSQL.setValue("province", province);
|
|
|
+ insertSQL.setValue("city", city);
|
|
|
+ insertSQL.setValue("county", county);
|
|
|
+ insertSQL.setValue("address", address);
|
|
|
+ insertSQL.setValue("enterprisename", enterprisename);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_enterprise");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sys_enterpriseid);
|
|
|
+ updateSQL.setValue("province", province);
|
|
|
+ updateSQL.setValue("city", city);
|
|
|
+ updateSQL.setValue("county", county);
|
|
|
+ updateSQL.setValue("address", address);
|
|
|
+ updateSQL.setValue("enterprisename", enterprisename);
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isAdd = false;
|
|
|
+ if (sa_customersid <= 0) {
|
|
|
+ isAdd = true;
|
|
|
+ Rows stagenameRows = dbConnect.runSqlQuery("SELECT stagename from sa_devstage WHERE siteid='" + siteid + "' order by sequence LIMIT 1");
|
|
|
+ sa_customersid = createTableID(tablename);
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_customers");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_customersid);
|
|
|
+ insertSQL.setValue("billno", createBillCode("hospital"));
|
|
|
+ insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ insertSQL.setValue("name", enterprisename);
|
|
|
+ insertSQL.setValue("type", type);
|
|
|
+ insertSQL.setValue("grade", content.getStringValue("grade"));
|
|
|
+ insertSQL.setValue("host", content.getLongValue("host"));
|
|
|
+ insertSQL.setValue("room", content.getLongValue("room"));
|
|
|
+ insertSQL.setValue("bed", content.getLongValue("bed"));
|
|
|
+ insertSQL.setValue("scale", content.getLongValue("scale"));
|
|
|
+ insertSQL.setValue("sa_saleareaid", content.getLongValue("sa_saleareaid"));
|
|
|
+ insertSQL.setValue("province", province);
|
|
|
+ insertSQL.setValue("city", city);
|
|
|
+ insertSQL.setValue("county", county);
|
|
|
+ insertSQL.setValue("address", address);
|
|
|
+ insertSQL.setValue("stagename", stagenameRows.isNotEmpty() ? stagenameRows.get(0).getString("stagename") : "");
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_customers");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_customersid);
|
|
|
+ updateSQL.setValue("name", enterprisename);
|
|
|
+ updateSQL.setValue("type", type);
|
|
|
+ updateSQL.setValue("grade", content.getStringValue("grade"));
|
|
|
+ updateSQL.setValue("host", content.getLongValue("host"));
|
|
|
+ updateSQL.setValue("room", content.getLongValue("room"));
|
|
|
+ updateSQL.setValue("bed", content.getLongValue("bed"));
|
|
|
+ updateSQL.setValue("scale", content.getLongValue("scale"));
|
|
|
+ updateSQL.setValue("sa_saleareaid", content.getStringValue("sa_saleareaid"));
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isAdd) {
|
|
|
+ //标签
|
|
|
+ sqlList.add(DataTag.createTagSql(this, "sa_customers", sa_customersid, type));
|
|
|
+ //数据团队新增
|
|
|
+ sqlList.addAll(DataTeam.createTeamSQL(this, tablename, sa_customersid, saler_userid));
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, tablename, sa_customersid, "新建", "新建医院成功").getSQL());
|
|
|
+ //标记数据来源
|
|
|
+ DataExtend.markDataFrom(this, "sa_customers", sa_customersid);
|
|
|
+ } else {
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, tablename, sa_customersid, "编辑", "编辑医院成功").getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增时插入财务信息和联系人信息
|
|
|
+ if (isAdd) {
|
|
|
+ //添加地址
|
|
|
+ Long contactsid = createTableID("sys_enterprise_contacts");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_contacts");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("contactsid", contactsid);
|
|
|
+ insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ insertSQL.setValue("province", province);
|
|
|
+ insertSQL.setValue("city", city);
|
|
|
+ insertSQL.setValue("county", county);
|
|
|
+ insertSQL.setValue("address", address);
|
|
|
+ insertSQL.setValue("workaddress", 1);
|
|
|
+ insertSQL.setValue("isdefault", 1);
|
|
|
+ insertSQL.setValue("isprimary", 1);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+
|
|
|
+ }
|
|
|
+ content.put("sa_customersid", sa_customersid);
|
|
|
+ String time = userInfo.getDateTime_Str();
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ DataTag.deleteTag(this, "sa_customers", sa_customersid, "疑似重复");
|
|
|
+ Rows teamRows = DataTeam.queryTeamRowWithoutHeadpic(this, "sa_customers", sa_customersid);
|
|
|
+
|
|
|
+ Rows leaderRows = teamRows.toRowsMap("isleader").get("1");
|
|
|
+ Long leaderuserid = leaderRows.isNotEmpty() ? leaderRows.get(0).getLong("userid") : 0;
|
|
|
+ Long departmentid = getDepartment(leaderuserid).getLong("departmentid");
|
|
|
+ ArrayList<Long> userids = new ArrayList<>();
|
|
|
+ userids.add(leaderuserid);
|
|
|
+ userids.addAll(Proxy.getProxyUserids(this));
|
|
|
+ userids.add(Hr.getReportUserid(this, leaderuserid));
|
|
|
+ userids.addAll(Hr.getLeaderRows(this, departmentid).toArrayList("userid", new ArrayList<Long>()));
|
|
|
+ JSONObject extradata = new JSONObject();
|
|
|
+ extradata.put("extraUserList", userids);
|
|
|
+
|
|
|
+ //客户查重
|
|
|
+ if (isAdd) {
|
|
|
+ ArrayList<Long> repeatIds = getRepeatCustomers(this, sa_customersid);
|
|
|
+ repeatIds.add(120L);
|
|
|
+ for (Object obj : repeatIds) {
|
|
|
+ Long id = Long.valueOf(obj.toString());
|
|
|
+ JSONObject extradata1 = new JSONObject();
|
|
|
+ extradata1.put("extraUserList", DataTeam.queryTeamRowWithoutHeadpic(this, "sa_customers", id).toArrayList("userid", new ArrayList<>()));
|
|
|
+ Executor.sendEml_controller(this, "customers_repeat", sa_customersid, extradata1);
|
|
|
+ }
|
|
|
+
|
|
|
+ Executor.sendEml_controller(this, "customers_add_my", sa_customersid, extradata);
|
|
|
+ } else {
|
|
|
+ String changedValue = getChangedValue(sa_customersid, time);
|
|
|
+ if (StringUtils.isEmpty(changedValue)) {
|
|
|
+ DataContrlLog.createLog(this, "sa_customers", sa_customersid, "编辑", "编辑医院" + enterprisename + "(" + sa_customersid + "),无字段值更新").insert();
|
|
|
+ } else {
|
|
|
+ DataContrlLog.createLog(this, "sa_customers", sa_customersid, "编辑", "编辑医院" + enterprisename + "(" + sa_customersid + ");" + changedValue).insert();
|
|
|
+ Executor.sendEml_controller(this, "customers_update_my", sa_customersid, extradata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return selectDetail();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getChangedValue(Long sa_customersid, String time) throws YosException {
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "查询客户编辑操作记录值变化");
|
|
|
+ sqlFactory.addParameter("sa_customersid", sa_customersid);
|
|
|
+ sqlFactory.addParameter("time", time);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return rows.get(0).getString("content");
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "详细", apiversion = R.ID20221012164302.v1.class)
|
|
|
+ public String selectDetail() throws YosException {
|
|
|
+ Long sa_customersid = content.getLong("sa_customersid");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "客户详情");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_customersid", sa_customersid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_customersid", new ArrayList<>());
|
|
|
+
|
|
|
+ RowsMap leaderRows = DataTeam.getLeader(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
|
|
|
+ //标签
|
|
|
+ HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_customers", ids, false);
|
|
|
+ //系统标签
|
|
|
+ HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_customers", ids, true);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Long id = row.getLong("sa_customersid");
|
|
|
+ row.put("leader", leaderRows.get(row.getString("sa_customersid")));
|
|
|
+ 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<String>();
|
|
|
+ ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<String>();
|
|
|
+ if (row.getString("agentsstatus").equals("禁用") || row.getString("agentsstatus").equals("作废")) {
|
|
|
+ tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
|
|
|
+ sys_tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
|
|
|
+ }
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ //预估手术总量
|
|
|
+ row.putIfAbsent("totalop", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+ Long sys_enterpriseid = rows.isNotEmpty() ? row.getLong("sys_enterpriseid") : 0;
|
|
|
+ Rows addressRows = dbConnect.runSqlQuery("SELECT * from sys_enterprise_contacts WHERE isdefault=1 and workaddress=1 and deleted=0 and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
|
|
|
+ row.put("province", addressRows.isNotEmpty() ? addressRows.get(0).getString("province") : new Row());
|
|
|
+ row.put("city", addressRows.isNotEmpty() ? addressRows.get(0).getString("city") : new Row());
|
|
|
+ row.put("county", addressRows.isNotEmpty() ? addressRows.get(0).getString("county") : new Row());
|
|
|
+ row.put("address", addressRows.isNotEmpty() ? addressRows.get(0).getString("address") : new Row());
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(row).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "医院列表", apiversion = R.ID20221012164402.v1.class)
|
|
|
+ public String selectList() throws YosException, IOException {
|
|
|
+ // 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的
|
|
|
+ int type = content.getIntValue("type");
|
|
|
+ Long deleted = content.getLongValue("deleted");
|
|
|
+
|
|
|
+ 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(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //开发状态
|
|
|
+ if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //医院类型
|
|
|
+ if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //医院等级
|
|
|
+ if (whereObject.containsKey("grade") && !"".equals(whereObject.getString("grade"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.grade ='").append(whereObject.getString("grade")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //成交状态
|
|
|
+ if (whereObject.containsKey("tradingstatus") && !"".equals(whereObject.getString("tradingstatus"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.tradingstatus ='").append(whereObject.getString("tradingstatus")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //标签
|
|
|
+ if (whereObject.containsKey("tag") && !whereObject.getJSONArray("tag").isEmpty()) {
|
|
|
+ for (Object o : whereObject.getJSONArray("tag")) {
|
|
|
+ where.append(" and exists(select 1 from sys_datatag WHERE ownertable = 'sa_customers' and siteid='").append(siteid).append("' ");
|
|
|
+ where.append(" and tag='").append(o).append("' and t1.sa_customersid=ownerid ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开发阶段
|
|
|
+ if (whereObject.containsKey("stagename") && !"".equals(whereObject.getString("stagename"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.stagename ='").append(whereObject.getString("stagename")).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(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (deleted == 1) {
|
|
|
+ where.append(" and ( t1.datastatus =1 )");
|
|
|
+ } else {
|
|
|
+ where.append(" and ( t1.datastatus in (0,2) )");
|
|
|
+ }
|
|
|
+
|
|
|
+ String where2 = " 1=1 ";
|
|
|
+ if (deleted == 0) {
|
|
|
+ if (type == 0) {
|
|
|
+ where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
|
|
|
+ + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
|
|
|
+ } else {
|
|
|
+ where2 = DataTeam.getDataWhereStr(this, tablename, "t1", type);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ where2 = Recycle.getWhereSql(this, tablename, "t1.sa_customersid");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isExport = content.getBoolean("isExport");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "sa_customersid", "createby", "createdate",
|
|
|
+ "sys_enterpriseid", "status", "type", "tradingstatus", "datastatus", "billno", "province", "city", "county", "address", "stagename", "grade");
|
|
|
+ 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(where2);
|
|
|
+ if (isExport) {
|
|
|
+ querySQL.setPage(999999, 1);
|
|
|
+ } else {
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ }
|
|
|
+ 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");
|
|
|
+ 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>();
|
|
|
+ if (row.getString("agentsstatus").equals("禁用") || row.getString("agentsstatus").equals("作废")) {
|
|
|
+ tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
|
|
|
+ sys_tag.removeAll(row.getJSONArray("agentstag").toJavaList(String.class));
|
|
|
+ }
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ row.putIfAbsent("followdate", "");
|
|
|
+ //预估手术总量
|
|
|
+ row.putIfAbsent("totalop", 0);
|
|
|
+ //关键人
|
|
|
+ row.putIfAbsent("keyperson", "");
|
|
|
+ //签约经销商
|
|
|
+ row.putIfAbsent("signagent", "");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ if (isExport) {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("医院管理导出");
|
|
|
+
|
|
|
+ XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("医院管理");
|
|
|
+ XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
|
|
|
+ ExportExcel.setBatchDetailSheetColumn(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportExcel.createBodyCellStyle(xssfFWorkbook);
|
|
|
+ ExportExcel.download(sheet, titleCellStyle1, titleCellStyle2, rows);// 写入标题
|
|
|
+
|
|
|
+ Rows aa = uploadExcelToObs(excelFactory);
|
|
|
+ String url = "";
|
|
|
+ if (!aa.isEmpty()) {
|
|
|
+ url = aa.get(0).getString("url");
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(url).toString();
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+}
|