package restcontroller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.UserInfo; import common.YosException; import common.data.Row; import common.data.Rows; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; import java.util.LinkedHashSet; public class ClientUserInfo extends UserInfo { public ClientUserInfo(Controller controller) { super(controller); } public static Row setLoginReturn(long usersiteid, Row userrow) { return userrow; } private Row hrRow = null; private Row enterpriseRow = null; private Row enterprise_HrRow = null; private Row agentsRow = null; private Row reportHrRow = null; public Row getHrRow() throws YosException { if (hrRow == null) { Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and userid=" + getUserId()); if (hrRows.isNotEmpty()) { hrRow = hrRows.getRow(0); } } return hrRow; } public Row getHrRow(Long hrid) throws YosException { Row hrRow = new Row(); Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and hrid=" + hrid); if (hrRows.isNotEmpty()) { hrRow = hrRows.getRow(0); } return hrRow; } public Row getEnterpriseRow() throws YosException { if (enterpriseRow == null) { Rows enterpriseRows = controller.dbConnect.runSqlQuery("select * from sys_enterprise t1 where t1.siteid='" + getSiteId() + "' and exists(select *from sys_enterprise_hr where siteid='" + getSiteId() + "' and userid=" + getUserId() + " and t1.sys_enterpriseid=sys_enterpriseid)"); if (enterpriseRows.isNotEmpty()) { enterpriseRow = enterpriseRows.getRow(0); } } return enterpriseRow; } public long getEnterpriseId() throws YosException { Row row = getEnterpriseRow(); if (row == null || row.isEmpty()) { return 0; } return row.getLong("sys_enterpriseid"); } public Row getEnterprise_HrRow() throws YosException { if (enterprise_HrRow == null) { Rows enterprise_HrRows = controller.dbConnect.runSqlQuery("select * from sys_enterprise_hr where siteid='" + getSiteId() + "' and userid=" + getUserId()); if (enterprise_HrRows.isNotEmpty()) { enterprise_HrRow = enterprise_HrRows.getRow(0); } } return enterprise_HrRow; } public Row getAgentRow() throws YosException { if (agentsRow == null) { Rows agentsRows = controller.dbConnect.runSqlQuery("select * from sa_agents where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId()); if (agentsRows.isNotEmpty()) { agentsRow = agentsRows.getRow(0); } } return agentsRow; } public long getAgentID() throws YosException { Row row = getAgentRow(); if (row == null || row.isEmpty()) { return 0; } return row.getLong("sa_agentsid"); } public boolean isSaler() throws YosException { return controller.dbConnect.runSqlQuery("select *from sa_salearea_hr where siteid='" + getSiteId() + "' and hrid=" + controller.hrid).isNotEmpty(); } /** * 获取当前企业的营销区域id */ public ArrayList getSaleAreaIds() throws YosException { if (getEnterpriseId() == 0) { return new ArrayList<>(); } Rows rows = controller.dbConnect.runSqlQuery("select distinct sa_saleareaid from sys_enterprise_tradefield where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId()); return rows.toArrayList("sa_saleareaid", new ArrayList<>()); } public Row getReportHrRow() throws YosException { if (reportHrRow == null) { Rows hrRows = controller.dbConnect.runSqlQuery("SELECT t2.*FROM sys_hr t1 INNER JOIN sys_hr t2 ON t2.hrid=t1.reporthrid AND t2.siteid=t1.siteid WHERE t1.siteid='" + getSiteId() + "' AND t1.userid=" + getUserId()); if (hrRows.isNotEmpty()) { reportHrRow = hrRows.getRow(0); } } return reportHrRow; } //返回汇报对象的userid public Long getReportUserid() throws YosException { reportHrRow = getReportHrRow(); if (reportHrRow != null && !reportHrRow.isEmpty()) { return reportHrRow.getLong("userid"); } return -1L; } //返回部门的主管userid public Long getLeaderUserid(Long departmentid) throws YosException { Rows rows = controller.dbConnect.runSqlQuery("SELECT userid from sys_hr WHERE departmentid = " + departmentid + " and isleader=1 and siteid='" + getSiteId() + "'"); return rows.isEmpty() ? -1 : rows.get(0).getLong("userid"); } //获取微信操作端信息 public String getWechatAppPage(String systemclient, String name) throws YosException { String path = ""; Rows rows = controller.dbConnect.runSqlQuery("SELECT * from sys_wechatapp WHERE systemclient='" + systemclient + "'"); if (rows.isEmpty()) { return ""; } JSONArray jsonArray = rows.get(0).getJSONArray("pages"); for (Object object : jsonArray) { JSONObject jsonObject = (JSONObject) object; if (jsonObject.getString("name").equals(name)) { path = jsonObject.getStringValue("path"); } } return path; } public String getAreaName(Controller controller) throws YosException { Rows areaRows = controller.dbConnect.runSqlQuery("SELECT DISTINCT t1.areaname from sa_salearea t1 " + "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid = t1.sa_saleareaid " + "WHERE t2.sys_enterpriseid=" + controller.sys_enterpriseid + " and t1.siteid='" + controller.siteid + "'"); return StringUtils.join(areaRows.toArray("areaname"), ","); } public String getAreaName(Controller controller, Long sys_enterpriseid) throws YosException { Rows areaRows = controller.dbConnect.runSqlQuery("SELECT DISTINCT t1.areaname from sa_salearea t1 " + "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid = t1.sa_saleareaid " + "WHERE t2.sys_enterpriseid=" + sys_enterpriseid + " and t1.siteid='" + controller.siteid + "'"); return StringUtils.join(areaRows.toArray("areaname"), ","); } public String getUserRoleName(Controller controller, Long userid) throws YosException { Rows rolenameRows = controller.dbConnect.runSqlQuery("select rolename from sys_userrole t1 " + "inner join sys_role t2 ON t2.roleid=t1.roleid and t2.siteid=t1.siteid " + "WHERE t1.userid=" + userid + " and t1.siteid='" + controller.siteid + "'"); return StringUtils.join(rolenameRows.toArray("rolename"), ","); } public String getSiteLogo(Controller controller) throws YosException { Row row = controller.dbConnect.runSqlQuery(0, "select siteuid,siteid,sitename,enterprisename from sys_site where siteid='" + controller.siteid + "'"); Rows rows = controller.getAttachmentUrl("sys_site", row.getLong("siteuid")); return rows.isNotEmpty() ? rows.get(0).getString("url") : ""; } public LinkedHashSet getSaleareaidsPath(Controller controller, Long sys_enterpriseid) throws YosException { Rows rows = controller.dbConnect.runSqlQuery("SELECT DISTINCT sa_saleareaids FROM sa_salearea t1 " + "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid=t1.sa_saleareaid and t2.siteid=t1.siteid " + "WHERE t1.siteid='" + controller.siteid + "' and t2.sys_enterpriseid=" + sys_enterpriseid + ""); LinkedHashSet ids = new LinkedHashSet<>(); ids.add(-1L); for (Row row : rows) { JSONArray jsonArray = row.getJSONArray("sa_saleareaids"); for (Object object : jsonArray) { ids.add(Long.parseLong(object.toString())); } } return ids; } }