DataDashboard.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package restcontroller.webmanage.saletool.data;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import common.Controller;
  5. import common.YosException;
  6. import common.annotation.API;
  7. import common.data.*;
  8. import restcontroller.R;
  9. import java.util.ArrayList;
  10. /**
  11. * 数据大盘
  12. */
  13. public class DataDashboard extends Controller {
  14. /**
  15. * 构造函数
  16. *
  17. * @param content
  18. */
  19. public DataDashboard(JSONObject content) throws YosException {
  20. super(content);
  21. }
  22. @API(title = "账户使用概况", apiversion = R.ID2024061109144502.v1.class)
  23. public String accountUseOverview() throws YosException {
  24. Row row = new Row();
  25. row.put("company_used", DataDashboardHelper.getUsedCount(this, 1));
  26. row.put("company_unbind", DataDashboardHelper.getUnBindCount(this, 1));
  27. row.put("company_stop", DataDashboardHelper.getStopCount(this, 1));
  28. row.put("company_all", DataDashboardHelper.getAllCount(this, 1));
  29. row.put("agent_used", DataDashboardHelper.getUsedCount(this, 21));
  30. row.put("agent_unbind", DataDashboardHelper.getUnBindCount(this, 21));
  31. row.put("agent_stop", DataDashboardHelper.getStopCount(this, 21));
  32. row.put("agent_all", DataDashboardHelper.getAllCount(this, 21));
  33. row.put("agentstaff_used", DataDashboardHelper.getUsedCount(this, 22));
  34. row.put("agentstaff_unbind", DataDashboardHelper.getUnBindCount(this, 22));
  35. row.put("agentstaff_stop", DataDashboardHelper.getStopCount(this, 22));
  36. row.put("agentstaff_all", DataDashboardHelper.getAllCount(this, 22));
  37. return getSucReturnObject().setData(row).toString();
  38. }
  39. @API(title = "账号列表", apiversion = R.ID2024061110312202.v1.class)
  40. public String accountList() throws YosException {
  41. int usertype = content.getIntValue("usertype");
  42. int type = content.getIntValue("type");
  43. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_users",
  44. "accountno", "name", "phonenumber", "userid").setTableAlias("t");
  45. if (type == 1) {
  46. querySQL.setWhere("t.userid in (" + DataDashboardHelper.getUsedSql(this, usertype) + ")");
  47. }
  48. if (type == 2) {
  49. querySQL.setWhere("t.userid in (" + DataDashboardHelper.getUnBindSql(this, usertype) + ")");
  50. }
  51. if (type == 3) {
  52. querySQL.setWhere("t.userid in (" + DataDashboardHelper.getStopSql(this, usertype) + ")");
  53. }
  54. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  55. Rows rows = querySQL.query();
  56. for (Row row : rows) {
  57. row.put("usertype", usertype);
  58. row.put("rolename", userInfo.getUserRoleName(this, row.getLong("userid")));
  59. }
  60. return getSucReturnObject().setData(rows).toString();
  61. }
  62. @API(title = "添加分享记录", apiversion = R.ID2024061113525202.v1.class)
  63. public String insertShareLog() throws YosException {
  64. Long shareuserid = content.getLongValue("shareuserid");
  65. String channel = content.getStringValue("channel");
  66. String appname = content.getStringValue("appname");
  67. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_sharelog");
  68. insertSQL.setSiteid(siteid);
  69. insertSQL.setUniqueid(createTableID("sys_sharelog"));
  70. insertSQL.setValue("shareuserid", shareuserid);
  71. insertSQL.setValue("channel", channel);
  72. insertSQL.setValue("appname", appname);
  73. insertSQL.insert();
  74. return getSucReturnObject().toString();
  75. }
  76. @API(title = "账户使用情况", apiversion = R.ID2024061114184602.v1.class)
  77. public String accountInfo() throws YosException {
  78. int usertype = content.getIntValue("usertype");
  79. int type = 0;
  80. String begindate = "";
  81. String enddate = "";
  82. if (content.containsKey("where")) {
  83. JSONObject whereObject = content.getJSONObject("where");
  84. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  85. type = whereObject.getIntValue("type");
  86. }
  87. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  88. begindate = whereObject.getStringValue("begindate");
  89. type=0;
  90. }
  91. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  92. enddate = whereObject.getStringValue("enddate");
  93. type=0;
  94. }
  95. }
  96. QuerySQL t2 = SQLFactory.createQuerySQL(this, "sys_userrequestlog", "userid", "usersiteid", "siteid");
  97. t2.addGroupBy("userid", "usersiteid", "siteid");
  98. if (type == 1) {
  99. t2.setWhere("DATE(lastrequestdate) = CURDATE()");
  100. }
  101. if (type == 2) {
  102. t2.setWhere("DATE(lastrequestdate) = CURDATE() - INTERVAL 1 DAY");
  103. }
  104. if (type == 3) {
  105. t2.setWhere("lastrequestdate >= CURRENT_DATE - INTERVAL 7 DAY");
  106. }
  107. if (type == 4) {
  108. t2.setWhere("lastrequestdate >= CURRENT_DATE - INTERVAL 30 DAY");
  109. }
  110. if (!begindate.isEmpty() && !enddate.isEmpty()) {
  111. t2.setWhere("lastrequestdate >= '"+begindate+"' and lastrequestdate<='"+enddate+" 23:59:59'");
  112. }
  113. t2.addQueryFields("lastrequestdate", "max(lastrequestdate)");
  114. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_usersite", "userid").setTableAlias("t1");
  115. querySQL.addJoinTable(JOINTYPE.left, t2, "t2", "t2.usersiteid=t1.usersiteid and t2.userid=t1.userid and t2.siteid=t1.siteid", "lastrequestdate");
  116. querySQL.addJoinTable(JOINTYPE.inner, "sys_users", "t3", "t3.userid=t1.userid", "name");
  117. querySQL.setSiteid(siteid);
  118. querySQL.setWhere("usertype", usertype);
  119. querySQL.setWhere("t3.`status` in ('active','inactive')");
  120. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  121. Rows rows = querySQL.query();
  122. ArrayList<Long> userids = rows.toArrayList("userid", new ArrayList<>());
  123. QuerySQL share = SQLFactory.createQuerySQL(this, "sys_sharelog", "createuserid");
  124. share.addQueryFields("count", "count(DISTINCT createuserid,shareuserid)");
  125. share.setSiteid(siteid);
  126. share.setWhere("createuserid", userids);
  127. if (type == 1) {
  128. share.setWhere("DATE(createdate) = CURDATE()");
  129. }
  130. if (type == 2) {
  131. share.setWhere("DATE(createdate) = CURDATE() - INTERVAL 1 DAY");
  132. }
  133. if (type == 3) {
  134. share.setWhere("createdate >= CURRENT_DATE - INTERVAL 7 DAY");
  135. }
  136. if (type == 4) {
  137. share.setWhere("createdate >= CURRENT_DATE - INTERVAL 30 DAY");
  138. }
  139. if (!begindate.isEmpty() && !enddate.isEmpty()) {
  140. t2.setWhere("createdate >= '"+begindate+"' and createdate<='"+enddate+" 23:59:59'");
  141. }
  142. share.addGroupBy("createuserid");
  143. RowsMap shareRowsMap = share.query().toRowsMap("createuserid");
  144. QuerySQL appointment = SQLFactory.createQuerySQL(this, "sa_appointment", "createuserid");
  145. appointment.addQueryFields("count", "count(DISTINCT createuserid,shareuserid)");
  146. appointment.setSiteid(siteid);
  147. appointment.setWhere("createuserid", userids);
  148. if (type == 1) {
  149. appointment.setWhere("DATE(createdate) = CURDATE()");
  150. }
  151. if (type == 2) {
  152. appointment.setWhere("DATE(createdate) = CURDATE() - INTERVAL 1 DAY");
  153. }
  154. if (type == 3) {
  155. appointment.setWhere("createdate >= CURRENT_DATE - INTERVAL 7 DAY");
  156. }
  157. if (type == 4) {
  158. appointment.setWhere("createdate >= CURRENT_DATE - INTERVAL 30 DAY");
  159. }
  160. if (!begindate.isEmpty() && !enddate.isEmpty()) {
  161. appointment.setWhere("createdate >= '"+begindate+"' and createdate<='"+enddate+" 23:59:59'");
  162. }
  163. appointment.addGroupBy("createuserid");
  164. RowsMap appointmentRowsMap = appointment.query().toRowsMap("createuserid");
  165. RowsMap areaRowsMap;
  166. if (usertype == 1) {
  167. QuerySQL area = SQLFactory.createQuerySQL(this, "sa_salearea_hr", "siteid").setTableAlias("t1");
  168. area.addJoinTable(JOINTYPE.inner, "sys_hr", "t2", "t2.hrid=t1.hrid and t2.siteid=t1.siteid", "userid");
  169. area.addJoinTable(JOINTYPE.inner, "sa_salearea", "t3", "t3.sa_saleareaid = t1.sa_saleareaid and t3.siteid=t1.siteid");
  170. area.addQueryFields("areaname", "GROUP_CONCAT(DISTINCT t3.areaname SEPARATOR',')");
  171. area.addGroupBy("userid", "siteid");
  172. area.setSiteid(siteid);
  173. area.setWhere("t2.userid", userids);
  174. areaRowsMap = area.query().toRowsMap("userid");
  175. } else {
  176. QuerySQL areaEnterprise = SQLFactory.createQuerySQL(this, "sys_enterprise_tradefield", "siteid").setTableAlias("t1");
  177. areaEnterprise.addJoinTable(JOINTYPE.inner, "sys_enterprise_hr", "t2", "t2.sys_enterpriseid=t1.sys_enterpriseid and t2.siteid=t1.siteid", "userid");
  178. areaEnterprise.addJoinTable(JOINTYPE.inner, "sa_salearea", "t3", "t3.sa_saleareaid = t1.sa_saleareaid and t3.siteid=t1.siteid");
  179. areaEnterprise.addQueryFields("areaname", "GROUP_CONCAT(DISTINCT t3.areaname SEPARATOR',')");
  180. areaEnterprise.addGroupBy("userid", "siteid");
  181. areaEnterprise.setSiteid(siteid);
  182. areaEnterprise.setWhere("t2.userid", userids);
  183. areaRowsMap = areaEnterprise.query().toRowsMap("userid");
  184. }
  185. for (Row row : rows) {
  186. row.putIfAbsent("lastrequestdate", "");
  187. Rows shareRows = shareRowsMap.getOrDefault(row.getString("userid"), new Rows());
  188. row.put("cust_count", shareRows.isEmpty() ? 0 : shareRows.get(0).getLong("count"));
  189. Rows appointmentRows = appointmentRowsMap.getOrDefault(row.getString("userid"), new Rows());
  190. row.put("appoint_count", appointmentRows.isEmpty() ? 0 : appointmentRows.get(0).getLong("count"));
  191. Rows areaRows = areaRowsMap.getOrDefault(row.getString("userid"), new Rows());
  192. row.put("areaname", areaRows.isEmpty() ? "" : areaRows.get(0).getString("areaname"));
  193. }
  194. return getSucReturnObject().setData(rows).toString();
  195. }
  196. }