visitors.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. package restcontroller.webmanage.users;
  2. import beans.attachment.Attachment;
  3. import beans.datatag.DataTag;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.mysql.cj.x.protobuf.MysqlxCrud;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.data.*;
  10. import org.apache.commons.lang.StringUtils;
  11. import restcontroller.R;
  12. import java.time.LocalDate;
  13. import java.time.temporal.ChronoUnit;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import static restcontroller.webmanage.sale.enterprise.enterprise.validatePhoneNumber;
  17. /**
  18. * 营销宝,我的,游客
  19. */
  20. public class visitors extends Controller {
  21. /**
  22. * 构造函数
  23. *
  24. * @param content
  25. */
  26. public visitors(JSONObject content) throws YosException {
  27. super(content);
  28. }
  29. @API(title = "【游客,工作台】个人信息", apiversion = R.ID20240510104102.v1.class)
  30. public String visitorsInfo() throws YosException {
  31. Row row = new Row();
  32. //统计我的访问店铺数量
  33. Rows rows = dbConnect.runSqlQuery("SELECT count(*) count from sa_store_history WHERE userid=" + userid + " and siteid='" + siteid + "'");
  34. row.put("count_historystore", rows.get(0).getLong("count"));
  35. //预约
  36. rows = dbConnect.runSqlQuery("SELECT count(*) count from sa_appointment WHERE createuserid=" + userid + " and siteid='" + siteid + "'");
  37. row.put("count_appointment", rows.get(0).getLong("count"));
  38. //地址
  39. rows = dbConnect.runSqlQuery("SELECT count(*) count from sys_enterprise_contacts WHERE createuserid=" + userid + " and siteid='" + siteid + "' and deleted=0");
  40. row.put("count_address", rows.get(0).getLong("count"));
  41. //收藏
  42. rows = dbConnect.runSqlQuery("SELECT count(*) count from sys_datacollect WHERE userid=" + userid + " and siteid='" + siteid + "' and type=1");
  43. row.put("count_collect", rows.get(0).getLong("count"));
  44. //订单
  45. rows = dbConnect.runSqlQuery("SELECT count(*) count from sa_custorder WHERE createuserid=" + userid + " and siteid='" + siteid + "' and deleted=0");
  46. row.put("count_order", rows.get(0).getLong("count"));
  47. rows = dbConnect.runSqlQuery("SELECT count(*) count from sys_phonebook WHERE sys_phonebookgroupid in (SELECT sys_phonebookgroupid from sys_phonebookgroup WHERE classid=1) and siteid='"+siteid+"'");
  48. // 通讯录
  49. row.put("count_addressbook", rows.get(0).getLong("count"));
  50. //考试成绩
  51. rows = dbConnect.runSqlQuery("SELECT count(*) count from sat_courseware_test WHERE userid=" + userid + " and siteid='" + siteid + "' ");
  52. row.put("count_coursewaretest", rows.get(0).getLong("count"));
  53. // 问卷调查
  54. row.put("count_questions", 0);
  55. rows = dbConnect.runSqlQuery("SELECT count(*) count from sa_feedback WHERE changeuserid=" + userid + " and siteid='" + siteid + "' ");
  56. // 意见反馈
  57. row.put("count_feedback", rows.get(0).getLong("count"));
  58. row.putAll(getUser(userid));
  59. row.put("headpic", getHeadPic(userid));
  60. row.put("attinfos", Attachment.get(this, "sys_users", userid, "headportrait"));
  61. //查询角色
  62. Rows rolenameRows = dbConnect.runSqlQuery("select rolename from sys_userrole t1 " +
  63. "inner join sys_role t2 ON t2.roleid=t1.roleid and t2.siteid=t1.siteid " +
  64. "WHERE t1.userid=" + userid + " and t1.siteid='" + siteid + "'");
  65. row.put("rolenames", StringUtils.join(rolenameRows.toArray("rolename"), ","));
  66. //加入团队时间
  67. LocalDate startDate = LocalDate.parse(row.getString("createdate").substring(0, 10));
  68. LocalDate endDate = LocalDate.now();
  69. long days = ChronoUnit.DAYS.between(startDate, endDate);
  70. row.put("joindays", days);
  71. //签到时间
  72. Rows signRows = dbConnect.runSqlQuery("SELECT count(DISTINCT t1.sat_sharematerialid) count from sat_sharematerial_read t1 " +
  73. "inner join sat_sharematerial t2 ON t2.sat_sharematerialid=t1.sat_sharematerialid " +
  74. "WHERE t2.classid=1 and t1.createuserid=" + userid + " and t1.type=0 and t1.siteid='" + siteid + "'");
  75. row.put("signdays", signRows.get(0).getLong("count"));
  76. Rows storerows = dbConnect.runSqlQuery("SELECT t1.*from sa_store t1 \n" +
  77. "inner join sa_store_hr t2 on t2.sa_storeid=t1.sa_storeid and t2.siteid=t1.siteid\n" +
  78. "inner join sys_enterprise_hr t3 ON t3.sys_enterprise_hrid=t2.sys_enterprise_hrid and t3.siteid=t2.siteid\n" +
  79. "WHERE t1.sys_enterpriseid=" + sys_enterpriseid + " and t1.siteid='" + siteid + "' and t3.userid='" + userid + "'");
  80. row.put("stores", storerows);
  81. row.put("areaname", userInfo.getAreaName(this));
  82. row.put("sys_enterpriseid", sys_enterpriseid);
  83. row.put("enterprise_hr", userInfo.getEnterprise_HrRow());
  84. return getSucReturnObject().setData(row).toString();
  85. }
  86. @API(title = "名片信息", apiversion = R.ID20240514161502.v1.class)
  87. public String cardInfo() throws YosException {
  88. Long tempuserid = content.getLongValue("userid");
  89. //插入浏览记录
  90. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_datacollect");
  91. insertSQL.setUniqueid(createTableID("sys_datacollect"));
  92. insertSQL.setSiteid(siteid);
  93. insertSQL.setValue("userid", userid);
  94. insertSQL.setValue("ownertable", "sys_users");
  95. insertSQL.setValue("ownerid", tempuserid);
  96. insertSQL.setValue("type", 3);
  97. insertSQL.insert();
  98. Row row = getUser(tempuserid);
  99. Row enterpriseRow = getEnterpriseHr(tempuserid);
  100. String enterprisename = "";
  101. if (!enterpriseRow.isEmpty()) {
  102. enterprisename = enterpriseRow.getString("enterprisename");
  103. }
  104. row.put("enterprisename", enterprisename);
  105. row.put("headpic", getHeadPic(tempuserid));
  106. //查询角色
  107. Rows rolenameRows = dbConnect.runSqlQuery("select rolename from sys_userrole t1 " +
  108. "inner join sys_role t2 ON t2.roleid=t1.roleid and t2.siteid=t1.siteid " +
  109. "WHERE t1.userid=" + tempuserid + " and t1.siteid='" + siteid + "'");
  110. row.put("rolenames", StringUtils.join(rolenameRows.toArray("rolename"), ","));
  111. Rows attinfoRows = Attachment.get(this, "sys_users", tempuserid);
  112. row.put("attinfos", attinfoRows);
  113. //标签
  114. ArrayList<String> tagList = DataTag.queryTag(this, "sys_users", tempuserid, false);
  115. //系统标签
  116. tagList.addAll(DataTag.queryTag(this, "sys_users", tempuserid, true));
  117. row.put("tag", tagList);
  118. Rows rows = dbConnect.runSqlQuery("SELECT count(*) count from sys_datacollect WHERE siteid='" + siteid + "' and type=2 and ownertable='sys_users' and ownerid='" + tempuserid + "'");
  119. row.put("count_like", rows.get(0).getLong("count"));
  120. rows = dbConnect.runSqlQuery("SELECT count(*) count from sys_datacollect WHERE siteid='" + siteid + "' and type=3 and ownertable='sys_users' and ownerid='" + tempuserid + "'");
  121. row.put("count_read", rows.get(0).getLong("count"));
  122. if (dbConnect.runSqlQuery("SELECT * from sys_datacollect WHERE siteid='" + siteid + "' and type=2 and ownertable='sys_users' and ownerid='" + tempuserid + "' and userid=" + userid).isNotEmpty()) {
  123. row.put("islike", 1);
  124. } else {
  125. row.put("islike", 0);
  126. }
  127. rows = dbConnect.runSqlQuery("SELECT userid,max(createdate) createdate from sys_datacollect WHERE siteid='" + siteid + "' and type=3 and ownertable='sys_users' and ownerid='" + tempuserid + "' GROUP BY userid LIMIT 3");
  128. for (Row readrow : rows) {
  129. readrow.put("headpic", getHeadPic(readrow.getLong("userid")));
  130. }
  131. row.put("readusers", rows);
  132. return getSucReturnObject().setData(row).toString();
  133. }
  134. @API(title = "更新游客信息", apiversion = R.ID20240511151602.v1.class)
  135. public String updatevisitorsInfo() throws YosException {
  136. String phonenumber = content.getStringValue("phonenumber");
  137. if (!content.getStringValue("phonenumber").isEmpty()) {
  138. boolean isValidPhoneNumber = validatePhoneNumber(phonenumber);
  139. if (!isValidPhoneNumber) {
  140. return getErrReturnObject().setErrMsg("请输入正确的手机号").toString();
  141. }
  142. if (dbConnect.runSqlQuery("select *from sys_users where phonenumber='" + phonenumber + "' and userid!='" + userid + "'").isNotEmpty()) {
  143. return getErrReturnObject().setErrMsg("存在重复的手机号信息").toString();
  144. }
  145. }
  146. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_users");
  147. updateSQL.setUniqueid(userid);
  148. updateSQL.setValue("name", content.getStringValue("name"));
  149. updateSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
  150. updateSQL.setValue("email", content.getStringValue("email"));
  151. updateSQL.setValue("address", content.getStringValue("address"));
  152. updateSQL.setValue("remarks", content.getStringValue("remarks"));
  153. updateSQL.update();
  154. return visitorsInfo();
  155. }
  156. @API(title = "全局搜索", apiversion = R.ID20240513085802.v1.class)
  157. public String search() throws YosException {
  158. //1:产品:来源单品、案例-电器系统
  159. //2:效果图:来源效果图管理;
  160. //3:课件:来源商学院授权可查看的课程中的课件;
  161. //4:资料:来源装备资源库授权可查看的资料;
  162. int type = content.getIntValue("type");
  163. Rows rows = new Rows();
  164. if (type == 1) {
  165. rows = searchFads();
  166. }
  167. if (type == 2) {
  168. rows = searchRenderings();
  169. }
  170. if (type == 3) {
  171. rows = searchCoursewaredetail();
  172. }
  173. if (type == 4) {
  174. rows = searchEquipmentResourceLibrary();
  175. }
  176. return getSucReturnObject().setData(rows).toString();
  177. }
  178. public Rows searchFads() throws YosException {
  179. StringBuffer where = new StringBuffer(" 1=1 ");
  180. if (content.containsKey("where")) {
  181. JSONObject whereObject = content.getJSONObject("where");
  182. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  183. where.append(" and (");
  184. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  185. where.append(")");
  186. }
  187. }
  188. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad", "sa_fadid").setTableAlias("t1");
  189. querySQL.setWhere("isonsale", 1);
  190. querySQL.setWhere("classid", 1);
  191. querySQL.addQueryFields("title", "t1.name");
  192. querySQL.setWhere(where.toString());
  193. querySQL.setSiteid(siteid);
  194. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  195. Rows rows = querySQL.query();
  196. RowsMap RowsMap = getAttachmentUrl("sa_fad", rows.toArrayList("sa_fadid", new ArrayList<>()));
  197. for (Row row : rows) {
  198. Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
  199. attRows.sortby("sequence", "linksid");
  200. row.put("attinfos", attRows);
  201. }
  202. return rows;
  203. }
  204. public Rows searchRenderings() throws YosException {
  205. StringBuffer where = new StringBuffer(" 1=1 ");
  206. if (content.containsKey("where")) {
  207. JSONObject whereObject = content.getJSONObject("where");
  208. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  209. where.append(" and (");
  210. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  211. where.append(")");
  212. }
  213. }
  214. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial", "sat_sharematerialid", "title").setTableAlias("t1");
  215. querySQL.setWhere("classid", 4);
  216. querySQL.setWhere("status", "发布");
  217. querySQL.setWhere(where.toString());
  218. querySQL.setSiteid(siteid);
  219. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  220. Rows rows = querySQL.query();
  221. RowsMap RowsMap = getAttachmentUrl("sat_sharematerial", rows.toArrayList("sat_sharematerialid", new ArrayList<>()));
  222. for (Row row : rows) {
  223. Rows attRows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  224. attRows.sortby("sequence", "linksid");
  225. row.put("attinfos", attRows);
  226. }
  227. return rows;
  228. }
  229. //课件
  230. public Rows searchCoursewaredetail() throws YosException {
  231. StringBuffer where = new StringBuffer(" 1=1 ");
  232. if (content.containsKey("where")) {
  233. JSONObject whereObject = content.getJSONObject("where");
  234. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  235. where.append(" and (");
  236. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  237. where.append(")");
  238. }
  239. }
  240. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware", "sat_coursewareid").setTableAlias("t1");
  241. querySQL.setSiteid(siteid);
  242. querySQL.setWhere("status", "发布");
  243. querySQL.setDataAuth(true);
  244. Rows rows = querySQL.query();
  245. ArrayList<Long> sat_coursewareids = rows.toArrayList("sat_coursewareid", new ArrayList<>());
  246. querySQL = SQLFactory.createQuerySQL(this, "sat_coursewaredetail", "sat_coursewaredetailid", "title").setTableAlias("t1");
  247. querySQL.setWhere("sat_coursewareid", sat_coursewareids);
  248. querySQL.setWhere("status", "上架");
  249. querySQL.setWhere(where.toString());
  250. querySQL.setSiteid(siteid);
  251. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  252. rows = querySQL.query();
  253. RowsMap RowsMap = getAttachmentUrl("sat_coursewaredetail", rows.toArrayList("sat_coursewaredetailid", new ArrayList<>()));
  254. for (Row row : rows) {
  255. Rows attRows = RowsMap.getOrDefault(row.getString("sat_coursewaredetailid"), new Rows());
  256. attRows.sortby("sequence", "linksid");
  257. row.put("attinfos", attRows);
  258. }
  259. return rows;
  260. }
  261. public Rows searchEquipmentResourceLibrary() throws YosException {
  262. StringBuffer where = new StringBuffer(" 1=1 ");
  263. if (content.containsKey("where")) {
  264. JSONObject whereObject = content.getJSONObject("where");
  265. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  266. where.append(" and (");
  267. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  268. where.append(")");
  269. }
  270. }
  271. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial", "sat_sharematerialid", "title").setTableAlias("t1");
  272. querySQL.setSiteid(siteid);
  273. querySQL.setWhere("classid", 3);
  274. querySQL.setWhere("status", "发布");
  275. querySQL.setWhere(where.toString());
  276. querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  277. querySQL.setDataAuth(true);
  278. Rows rows = querySQL.query();
  279. RowsMap RowsMap = getAttachmentUrl("sat_sharematerial", rows.toArrayList("sat_sharematerialid", new ArrayList<>()));
  280. for (Row row : rows) {
  281. Rows attRows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  282. attRows.sortby("sequence", "linksid");
  283. row.put("attinfos", attRows);
  284. }
  285. return rows;
  286. }
  287. }