ClientUserInfo.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package restcontroller;
  2. import common.Controller;
  3. import common.UserInfo;
  4. import common.YosException;
  5. import common.data.Row;
  6. import common.data.Rows;
  7. import java.util.ArrayList;
  8. public class ClientUserInfo extends UserInfo {
  9. public ClientUserInfo(Controller controller) {
  10. super(controller);
  11. }
  12. public static Row setLoginReturn(long usersiteid, Row userrow) {
  13. return userrow;
  14. }
  15. private Row hrRow = null;
  16. private Row enterpriseRow = null;
  17. private Row enterprise_HrRow = null;
  18. private Row agentsRow = null;
  19. private Row reportHrRow = null;
  20. public Row getHrRow() throws YosException {
  21. if (hrRow == null) {
  22. Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and userid=" + getUserId());
  23. if (hrRows.isNotEmpty()) {
  24. hrRow = hrRows.getRow(0);
  25. }
  26. }
  27. return hrRow;
  28. }
  29. public Row getHrRow(Long hrid) throws YosException {
  30. Row hrRow = new Row();
  31. Rows hrRows = controller.dbConnect.runSqlQuery("select * from sys_hr where siteid='" + getSiteId() + "' and hrid=" + hrid);
  32. if (hrRows.isNotEmpty()) {
  33. hrRow = hrRows.getRow(0);
  34. }
  35. return hrRow;
  36. }
  37. public Row getEnterpriseRow() throws YosException {
  38. if (enterpriseRow == null) {
  39. 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)");
  40. if (enterpriseRows.isNotEmpty()) {
  41. enterpriseRow = enterpriseRows.getRow(0);
  42. }
  43. }
  44. return enterpriseRow;
  45. }
  46. public long getEnterpriseId() throws YosException {
  47. Row row = getEnterpriseRow();
  48. if (row == null || row.isEmpty()) {
  49. return 0;
  50. }
  51. return row.getLong("sys_enterpriseid");
  52. }
  53. public Row getEnterprise_HrRow() throws YosException {
  54. if (enterprise_HrRow == null) {
  55. Rows enterprise_HrRows = controller.dbConnect.runSqlQuery("select * from sys_enterprise_hr where siteid='" + getSiteId() + "' and userid=" + getUserId());
  56. if (enterprise_HrRows.isNotEmpty()) {
  57. enterprise_HrRow = enterprise_HrRows.getRow(0);
  58. }
  59. }
  60. return enterprise_HrRow;
  61. }
  62. public Row getAgentRow() throws YosException {
  63. if (agentsRow == null) {
  64. Rows agentsRows = controller.dbConnect.runSqlQuery("select * from sa_agents where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId());
  65. if (agentsRows.isNotEmpty()) {
  66. agentsRow = agentsRows.getRow(0);
  67. 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() + "'");
  68. if (areaRows.isNotEmpty()) {
  69. agentsRow.put("areaname", areaRows.get(0).getString("areaname"));
  70. }
  71. agentsRow.putIfAbsent("areaname", "");
  72. 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() + "'");
  73. if (salersRows.isNotEmpty()) {
  74. agentsRow.put("salers", salersRows.get(0).getString("salers"));
  75. }
  76. agentsRow.putIfAbsent("salers", "");
  77. }
  78. }
  79. return agentsRow;
  80. }
  81. public long getAgentID() throws YosException {
  82. Row row = getAgentRow();
  83. if (row == null || row.isEmpty()) {
  84. return 0;
  85. }
  86. return row.getLong("sa_agentsid");
  87. }
  88. public boolean isSaler() throws YosException {
  89. return controller.dbConnect.runSqlQuery("select *from sa_salearea_hr where siteid='" + getSiteId() + "' and hrid=" + controller.hrid).isNotEmpty();
  90. }
  91. /**
  92. * 获取当前企业的营销区域id
  93. */
  94. public ArrayList<Long> getSaleAreaIds() throws YosException {
  95. if (getEnterpriseId() == 0) {
  96. return new ArrayList<>();
  97. }
  98. Rows rows = controller.dbConnect.runSqlQuery("select distinct sa_saleareaid from sys_enterprise_tradefield where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId());
  99. return rows.toArrayList("sa_saleareaid", new ArrayList<>());
  100. }
  101. public Row getReportHrRow() throws YosException {
  102. if (reportHrRow == null) {
  103. 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());
  104. if (hrRows.isNotEmpty()) {
  105. reportHrRow = hrRows.getRow(0);
  106. }
  107. }
  108. return reportHrRow;
  109. }
  110. //返回汇报对象的userid
  111. public Long getReportUserid() throws YosException {
  112. reportHrRow = getReportHrRow();
  113. if (reportHrRow != null && !reportHrRow.isEmpty()) {
  114. return reportHrRow.getLong("userid");
  115. }
  116. return -1L;
  117. }
  118. //返回部门的主管userid
  119. public Long getLeaderUserid(Long departmentid) throws YosException {
  120. Rows rows = controller.dbConnect.runSqlQuery("SELECT userid from sys_hr WHERE departmentid = " + departmentid + " and isleader=1 and siteid='" + getSiteId() + "'");
  121. return rows.isEmpty() ? -1 : rows.get(0).getLong("userid");
  122. }
  123. }