ClientUserInfo.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package restcontroller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import common.Controller;
  5. import common.UserInfo;
  6. import common.YosException;
  7. import common.data.Row;
  8. import common.data.Rows;
  9. import org.apache.commons.lang.StringUtils;
  10. import java.util.ArrayList;
  11. import java.util.LinkedHashSet;
  12. public class ClientUserInfo extends UserInfo {
  13. public ClientUserInfo(Controller controller) {
  14. super(controller);
  15. }
  16. public static Row setLoginReturn(long usersiteid, Row userrow) {
  17. return userrow;
  18. }
  19. private Row hrRow = null;
  20. private Row enterpriseRow = null;
  21. private Row enterprise_HrRow = null;
  22. private Row agentsRow = null;
  23. private Row reportHrRow = null;
  24. public Row getHrRow() throws YosException {
  25. if (hrRow == null) {
  26. Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and userid=" + getUserId());
  27. if (hrRows.isNotEmpty()) {
  28. hrRow = hrRows.getRow(0);
  29. }
  30. }
  31. return hrRow;
  32. }
  33. public Row getHrRow(Long hrid) throws YosException {
  34. Row hrRow = new Row();
  35. Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and hrid=" + hrid);
  36. if (hrRows.isNotEmpty()) {
  37. hrRow = hrRows.getRow(0);
  38. }
  39. return hrRow;
  40. }
  41. public Row getEnterpriseRow() throws YosException {
  42. if (enterpriseRow == null) {
  43. 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)");
  44. if (enterpriseRows.isNotEmpty()) {
  45. enterpriseRow = enterpriseRows.getRow(0);
  46. }
  47. }
  48. return enterpriseRow;
  49. }
  50. public long getEnterpriseId() throws YosException {
  51. Row row = getEnterpriseRow();
  52. if (row == null || row.isEmpty()) {
  53. return 0;
  54. }
  55. return row.getLong("sys_enterpriseid");
  56. }
  57. public Row getEnterprise_HrRow() throws YosException {
  58. if (enterprise_HrRow == null) {
  59. Rows enterprise_HrRows = controller.dbConnect.runSqlQuery("select * from sys_enterprise_hr where siteid='" + getSiteId() + "' and userid=" + getUserId());
  60. if (enterprise_HrRows.isNotEmpty()) {
  61. enterprise_HrRow = enterprise_HrRows.getRow(0);
  62. }
  63. }
  64. return enterprise_HrRow;
  65. }
  66. public Row getAgentRow() throws YosException {
  67. if (agentsRow == null) {
  68. Rows agentsRows = controller.dbConnect.runSqlQuery("select * from sa_agents where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId());
  69. if (agentsRows.isNotEmpty()) {
  70. agentsRow = agentsRows.getRow(0);
  71. }
  72. }
  73. return agentsRow;
  74. }
  75. public long getAgentID() throws YosException {
  76. Row row = getAgentRow();
  77. if (row == null || row.isEmpty()) {
  78. return 0;
  79. }
  80. return row.getLong("sa_agentsid");
  81. }
  82. public boolean isSaler() throws YosException {
  83. return controller.dbConnect.runSqlQuery("select *from sa_salearea_hr where siteid='" + getSiteId() + "' and hrid=" + controller.hrid).isNotEmpty();
  84. }
  85. /**
  86. * 获取当前企业的营销区域id
  87. */
  88. public ArrayList<Long> getSaleAreaIds() throws YosException {
  89. if (getEnterpriseId() == 0) {
  90. return new ArrayList<>();
  91. }
  92. Rows rows = controller.dbConnect.runSqlQuery("select distinct sa_saleareaid from sys_enterprise_tradefield where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId());
  93. return rows.toArrayList("sa_saleareaid", new ArrayList<>());
  94. }
  95. public Row getReportHrRow() throws YosException {
  96. if (reportHrRow == null) {
  97. 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());
  98. if (hrRows.isNotEmpty()) {
  99. reportHrRow = hrRows.getRow(0);
  100. }
  101. }
  102. return reportHrRow;
  103. }
  104. //返回汇报对象的userid
  105. public Long getReportUserid() throws YosException {
  106. reportHrRow = getReportHrRow();
  107. if (reportHrRow != null && !reportHrRow.isEmpty()) {
  108. return reportHrRow.getLong("userid");
  109. }
  110. return -1L;
  111. }
  112. //返回部门的主管userid
  113. public Long getLeaderUserid(Long departmentid) throws YosException {
  114. Rows rows = controller.dbConnect.runSqlQuery("SELECT userid from sys_hr WHERE departmentid = " + departmentid + " and isleader=1 and siteid='" + getSiteId() + "'");
  115. return rows.isEmpty() ? -1 : rows.get(0).getLong("userid");
  116. }
  117. //获取微信操作端信息
  118. public String getWechatAppPage(String systemclient, String name) throws YosException {
  119. String path = "";
  120. Rows rows = controller.dbConnect.runSqlQuery("SELECT * from sys_wechatapp WHERE systemclient='" + systemclient + "'");
  121. if (rows.isEmpty()) {
  122. return "";
  123. }
  124. JSONArray jsonArray = rows.get(0).getJSONArray("pages");
  125. for (Object object : jsonArray) {
  126. JSONObject jsonObject = (JSONObject) object;
  127. if (jsonObject.getString("name").equals(name)) {
  128. path = jsonObject.getStringValue("path");
  129. }
  130. }
  131. return path;
  132. }
  133. public String getAreaName(Controller controller) throws YosException {
  134. Rows areaRows = controller.dbConnect.runSqlQuery("SELECT DISTINCT t1.areaname from sa_salearea t1 " +
  135. "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid = t1.sa_saleareaid " +
  136. "WHERE t2.sys_enterpriseid=" + controller.sys_enterpriseid + " and t1.siteid='" + controller.siteid + "'");
  137. return StringUtils.join(areaRows.toArray("areaname"), ",");
  138. }
  139. public String getAreaName(Controller controller, Long sys_enterpriseid) throws YosException {
  140. Rows areaRows = controller.dbConnect.runSqlQuery("SELECT DISTINCT t1.areaname from sa_salearea t1 " +
  141. "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid = t1.sa_saleareaid " +
  142. "WHERE t2.sys_enterpriseid=" + sys_enterpriseid + " and t1.siteid='" + controller.siteid + "'");
  143. return StringUtils.join(areaRows.toArray("areaname"), ",");
  144. }
  145. public String getUserRoleName(Controller controller, Long userid) throws YosException {
  146. Rows rolenameRows = controller.dbConnect.runSqlQuery("select rolename from sys_userrole t1 " +
  147. "inner join sys_role t2 ON t2.roleid=t1.roleid and t2.siteid=t1.siteid " +
  148. "WHERE t1.userid=" + userid + " and t1.siteid='" + controller.siteid + "'");
  149. return StringUtils.join(rolenameRows.toArray("rolename"), ",");
  150. }
  151. public String getSiteLogo(Controller controller) throws YosException {
  152. Row row = controller.dbConnect.runSqlQuery(0, "select siteuid,siteid,sitename,enterprisename from sys_site where siteid='" + controller.siteid + "'");
  153. Rows rows = controller.getAttachmentUrl("sys_site", row.getLong("siteuid"));
  154. return rows.isNotEmpty() ? rows.get(0).getString("url") : "";
  155. }
  156. public LinkedHashSet<Long> getSaleareaidsPath(Controller controller, Long sys_enterpriseid) throws YosException {
  157. Rows rows = controller.dbConnect.runSqlQuery("SELECT DISTINCT sa_saleareaids FROM sa_salearea t1 " +
  158. "INNER JOIN sys_enterprise_tradefield t2 ON t2.sa_saleareaid=t1.sa_saleareaid and t2.siteid=t1.siteid " +
  159. "WHERE t1.siteid='" + controller.siteid + "' and t2.sys_enterpriseid=" + sys_enterpriseid + "");
  160. LinkedHashSet<Long> ids = new LinkedHashSet<>();
  161. ids.add(-1L);
  162. for (Row row : rows) {
  163. JSONArray jsonArray = row.getJSONArray("sa_saleareaids");
  164. for (Object object : jsonArray) {
  165. ids.add(Long.parseLong(object.toString()));
  166. }
  167. }
  168. return ids;
  169. }
  170. }