package restcontroller; import common.Controller; import common.UserInfo; import common.YosException; import common.data.Row; import common.data.Rows; import java.util.ArrayList; 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); Rows areaRows = controller.dbConnect.runSqlQuery("SELECT GROUP_CONCAT(DISTINCT t2.areaname) areaname FROM sys_enterprise_tradefield t1 INNER JOIN sa_salearea t2 ON t2.sa_saleareaid=t1.sa_saleareaid WHERE t1.sys_enterpriseid='" + getEnterpriseId() + "'"); if (areaRows.isNotEmpty()) { agentsRow.put("areaname", areaRows.get(0).getString("areaname")); } agentsRow.putIfAbsent("areaname", ""); Rows salersRows = controller.dbConnect.runSqlQuery("SELECT GROUP_CONCAT(DISTINCT t2.NAME) salers FROM sys_enterprise_tradefield t1 INNER JOIN sys_hr t2 ON t2.hrid=t1.hrid WHERE t1.sys_enterpriseid='" + getEnterpriseId() + "'"); if (salersRows.isNotEmpty()) { agentsRow.put("salers", salersRows.get(0).getString("salers")); } agentsRow.putIfAbsent("salers", ""); } } 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"); } }