ClientUserInfo.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. }
  68. }
  69. return agentsRow;
  70. }
  71. public long getAgentID() throws YosException {
  72. Row row = getAgentRow();
  73. if (row == null || row.isEmpty()) {
  74. return 0;
  75. }
  76. return row.getLong("sa_agentsid");
  77. }
  78. public boolean isSaler() throws YosException {
  79. return controller.dbConnect.runSqlQuery("select *from sa_salearea_hr where siteid='" + getSiteId() + "' and hrid=" + controller.hrid).isNotEmpty();
  80. }
  81. /**
  82. * 获取当前企业的营销区域id
  83. */
  84. public ArrayList<Long> getSaleAreaIds() throws YosException {
  85. if (getEnterpriseId() == 0) {
  86. return new ArrayList<>();
  87. }
  88. Rows rows = controller.dbConnect.runSqlQuery("select distinct sa_saleareaid from sys_enterprise_tradefield where siteid='" + getSiteId() + "' and sys_enterpriseid=" + getEnterpriseId());
  89. return rows.toArrayList("sa_saleareaid", new ArrayList<>());
  90. }
  91. public Row getReportHrRow() throws YosException {
  92. if (reportHrRow == null) {
  93. 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());
  94. if (hrRows.isNotEmpty()) {
  95. reportHrRow = hrRows.getRow(0);
  96. }
  97. }
  98. return reportHrRow;
  99. }
  100. //返回汇报对象的userid
  101. public Long getReportUserid() throws YosException {
  102. reportHrRow = getReportHrRow();
  103. if (reportHrRow != null && !reportHrRow.isEmpty()) {
  104. return reportHrRow.getLong("userid");
  105. }
  106. return -1L;
  107. }
  108. //返回部门的主管userid
  109. public Long getLeaderUserid(Long departmentid) throws YosException {
  110. Rows rows = controller.dbConnect.runSqlQuery("SELECT userid from sys_hr WHERE departmentid = " + departmentid + " and isleader=1 and siteid='" + getSiteId() + "'");
  111. return rows.isEmpty() ? -1 : rows.get(0).getLong("userid");
  112. }
  113. }