Controller.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. package com.cnd3b.common;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.cnd3b.common.data.Rows;
  5. import com.cnd3b.common.data.RowsMap;
  6. import com.cnd3b.common.data.SQLFactory;
  7. import com.cnd3b.common.data.db.DBConnect;
  8. import com.cnd3b.common.data.db.DataPool;
  9. import com.cnd3b.common.parameter.parameter;
  10. import com.cnd3b.common.data.Row;
  11. import org.apache.poi.ss.formula.functions.T;
  12. import p2.p2server.P2Server;
  13. import p2.pao.PaoRemote;
  14. import p2.pao.PaoSetRemote;
  15. import p2.security.ConnectionKey;
  16. import p2.util.P2Exception;
  17. import java.lang.reflect.Array;
  18. import java.lang.reflect.Constructor;
  19. import java.lang.reflect.Method;
  20. import java.sql.Connection;
  21. import java.util.*;
  22. public class Controller extends BaseClass {
  23. // 请求正文
  24. public JSONObject content;
  25. public int returnMaxCount = 1000;
  26. public D3BReturnObject returnObject;
  27. /**
  28. * 不要预加载数据,false表示需要预加载,true表示不需要预加载
  29. */
  30. public boolean donotpreloading = false;
  31. public int pageNumber = 1;
  32. public int pageSize = 20;
  33. public String $classname = "";
  34. public String $method = "";
  35. public String $accesstoken = "";
  36. public long userid = 0L;
  37. public String username = "";
  38. public String siteid = "";
  39. public long tagentsid = 0L;
  40. public String fusertype = "";
  41. public String fphonenumber = "";
  42. public DBConnect dbConnect = null;
  43. public boolean fissysadministrator = false;
  44. public boolean fisadministrator = false;
  45. public String hostipport;//访问地址url 如http://localhost:8080 http://127.0.0.1:8080
  46. public Date sysdate;
  47. /**
  48. * 构造函数
  49. *
  50. * @param content
  51. */
  52. public Controller(JSONObject content) {
  53. this.dbConnect = new DBConnect();
  54. sysdate = getDateTime();
  55. this.content = content;
  56. if (content.containsKey("returnMaxCount")) {
  57. returnMaxCount = content.getIntValue("returnMaxCount");
  58. }
  59. returnObject = new D3BReturnObject(this);
  60. donotpreloading = content.containsKey("donotpreloading") && content.getBoolean("donotpreloading");
  61. this.content.remove("donotpreloading");
  62. if (this.content.containsKey("pageNumber")) {
  63. pageNumber = this.content.getIntValue("pageNumber");
  64. }
  65. if (this.content.containsKey("pageSize")) {
  66. pageSize = this.content.getIntValue("pageSize");
  67. }
  68. if (this.content.containsKey("$classname")) {
  69. $classname = this.content.getString("$classname");
  70. }
  71. if (this.content.containsKey("$method")) {
  72. $method = this.content.getString("$method");
  73. }
  74. if (this.content.containsKey("$requestHost")) {
  75. hostipport = this.content.getString("$requestHost");
  76. }
  77. if (this.content.containsKey("userid")) {
  78. userid = this.content.getLongValue("userid");
  79. } else if (this.content.containsKey("$accesstoken")) {
  80. $accesstoken = this.content.getString("$accesstoken");
  81. if (parameter.tokenlist.containsKey($accesstoken)) {
  82. userid = parameter.tokenlist.get($accesstoken);
  83. }
  84. }
  85. if (parameter.userIdList.containsKey(userid)) {
  86. Row row = parameter.userIdList.get(userid);
  87. siteid = row.getString("siteid");
  88. tagentsid = row.getLong("tagentsid");
  89. fusertype = row.getString("fusertype");
  90. username = row.getString("fname");
  91. fphonenumber = row.getString("fphonenumber");
  92. fissysadministrator = row.getBoolean("fissysadministrator");
  93. fisadministrator = row.getBoolean("fisadministrator");
  94. createRequestLog();
  95. }
  96. }
  97. public String getSort(String[] sortfield, String defaultsort) {
  98. String sort = "";
  99. if (content.containsKey("sort") && Arrays.asList(sortfield).contains(content.getString("sort").replace("desc", "").replace("asc", "").trim())) {
  100. sort = content.getString("sort");
  101. } else {
  102. sort = defaultsort;
  103. }
  104. return sort;
  105. }
  106. /**
  107. * 每次从数据库里获取数据时,后台自动加载一定数据的数据至缓存中
  108. *
  109. * @param loadcount
  110. */
  111. public void preloading(int loadcount) {
  112. if (!donotpreloading && loadcount > 0) {
  113. /**
  114. * 获得当前页码
  115. */
  116. int pageNumber = this.pageNumber;
  117. new Thread() {
  118. @Override
  119. public void run() {
  120. super.run();
  121. for (int i = 1; i <= loadcount; i++) {
  122. /**
  123. * 先将是否需要缓存数据的key移除
  124. */
  125. content.remove("donotpreloading");
  126. /**
  127. * 设定需要缓存的页码。
  128. */
  129. if (content.get("pageNumber") instanceof String) {
  130. content.put("pageNumber", String.valueOf(pageNumber + i));
  131. } else {
  132. content.put("pageNumber", (pageNumber + i));
  133. }
  134. /**
  135. * 判断该数据是否存在于缓存中,如果不存在则查询一条
  136. */
  137. if (!DataPool.datapoolCtrl.containsKey(content.toString())) {
  138. /**
  139. * 缓存时,强制命令下次不再进行缓存
  140. */
  141. content.put("donotpreloading", true);
  142. try {
  143. /**
  144. * 执行请求方法
  145. */
  146. Class clz = Class.forName("com.cnd3b.restcontroller." + $classname);
  147. Constructor cla = clz.getDeclaredConstructor(JSONObject.class);
  148. Object obj = cla.newInstance(content);
  149. Method method = obj.getClass().getDeclaredMethod($method);
  150. method.invoke(obj);
  151. } catch (Exception e) {
  152. e.printStackTrace();
  153. }
  154. }
  155. }
  156. }
  157. }.start();
  158. }
  159. }
  160. public long getUniqueIDValue(String tablename, String tableidname) {
  161. ConnectionKey locala = null;
  162. try {
  163. locala = P2Server.getP2Server().getSystemUserInfo()
  164. .getConnectionKey();
  165. Connection localConnection = P2Server.getP2Server()
  166. .getDBConnProvider().getConnection(locala);
  167. return p2.pao.m
  168. .a(localConnection, tablename, tableidname);
  169. } catch (Exception e) {
  170. return 0;
  171. } finally {
  172. P2Server.getP2Server().getDBConnProvider().freeConnection(locala);
  173. }
  174. }
  175. public void saveDataLog(PaoRemote pao) throws P2Exception {
  176. if (content.containsKey("datalog")) {
  177. JSONArray datalogArray = content.getJSONArray("datalog");
  178. PaoSetRemote tdatalog = pao.getPaoSet("$tdatalog", "tdatalog");
  179. for (Object o : datalogArray) {
  180. JSONObject datalogObject = (JSONObject) o;
  181. PaoRemote datalog = tdatalog.addAtEnd();
  182. datalog.setValue("siteid", siteid, 11L);
  183. datalog.setValue("ftablename", pao.getName(), 11L);
  184. datalog.setValue("ftableid", pao.getUniqueIDValue(), 11L);
  185. datalog.setValue("ftype", datalogObject.getString("ftype"), 11L);
  186. datalog.setValue("flog", datalogObject.getString("flog"), 11L);
  187. datalog.setValue("changeby", username, 11L);
  188. datalog.setValue("changedate", getDateTime(), 11L);
  189. datalog.setValue("tenterprise_userid", userid, 11L);
  190. }
  191. }
  192. }
  193. public Rows getDataLog(String ftablename, String ftableid) {
  194. return dbConnect.runSqlQuery("select changeby,changedate,ftype,flog,tenterprise_userid from tdatalog where siteid='" + siteid
  195. + "' and ftablename='" + ftablename + "' and ftableid='" + ftableid + "'");
  196. }
  197. public Rows getDataLog(String ftablename, long ftableid) {
  198. return getDataLog(ftablename, String.valueOf(ftableid));
  199. }
  200. //userid:tuserrequestlogid
  201. public static HashMap<Long, Long> userRequestLogMap = new HashMap<>();
  202. //userid:count
  203. public static HashMap<Long, Long> userRequestLogcountMap = new HashMap<>();
  204. public static String lastday = "";
  205. /**
  206. * 创建请求日志
  207. */
  208. private void createRequestLog() {
  209. new Thread() {
  210. @Override
  211. public void run() {
  212. String nowday = getDate_Str();
  213. if (!lastday.equals(nowday)) {
  214. lastday = nowday;
  215. userRequestLogMap.clear();
  216. }
  217. if (!userRequestLogMap.containsKey(userid)) {
  218. Rows rows = dbConnect.runSqlQuery("select tuserrequestlogid from tuserrequestlog where siteid='" + siteid + "' and tenterprise_userid='" + userid + "' and convert(varchar(10),fdate,120)=convert(varchar(10),getdate(),120) ");
  219. if (rows.isEmpty()) {
  220. long tuserrequestlogid = createTableID("tuserrequestlog", "tuserrequestlogid");
  221. SQLFactory sqlFactory = new SQLFactory(this, "请求日志插入");
  222. sqlFactory.addParameter("tuserrequestlogid", tuserrequestlogid);
  223. sqlFactory.addParameter("siteid", siteid);
  224. sqlFactory.addParameter("tenterprise_userid", userid);
  225. sqlFactory.addParameter("tagentsid", tagentsid);
  226. String status = dbConnect.runSqlUpdate(sqlFactory.getSQL());
  227. if ("true".equals(status)) {
  228. userRequestLogMap.put(userid, tuserrequestlogid);
  229. }
  230. } else {
  231. userRequestLogMap.put(userid, rows.get(0).getLong("tuserrequestlogid"));
  232. }
  233. userRequestLogcountMap.put(userid, 1L);
  234. } else {
  235. long count = userRequestLogcountMap.get(userid) + 1;
  236. if (count > 9) {
  237. userRequestLogcountMap.put(userid, 1L);
  238. long tuserrequestlogid = userRequestLogMap.get(userid);
  239. dbConnect.runSqlUpdate("update tuserrequestlog set flastrequestdate=getdate(),frequesttimes=frequesttimes+" + count + " where siteid='" + siteid + "' and tenterprise_userid='" + userid + "' and tuserrequestlogid=" + tuserrequestlogid);
  240. } else {
  241. userRequestLogcountMap.put(userid, count);
  242. }
  243. }
  244. }
  245. }.start();
  246. }
  247. /**
  248. * 获取一个新的表数据ID
  249. */
  250. private static HashMap<String, Long> tableidmap = new HashMap<>();
  251. public long createTableID(String tablename, String fieldname) {
  252. synchronized (Controller.class) {
  253. tablename = tablename.toLowerCase();
  254. fieldname = fieldname.toLowerCase();
  255. if (!tableidmap.containsKey(tablename)) {
  256. Rows rows = dbConnect.runSqlQuery("select convert(bigint,isnull(max(" + fieldname + "),0)) as " + fieldname + " from " + tablename);
  257. if (!rows.isEmpty()) {
  258. long id = rows.get(0).getLong(fieldname);
  259. tableidmap.put(tablename, id);
  260. }
  261. }
  262. tableidmap.put(tablename, tableidmap.get(tablename) + 1);
  263. return tableidmap.get(tablename);
  264. }
  265. }
  266. public long createTableID(String tablename, String fieldname, int count) {
  267. synchronized (Controller.class) {
  268. tablename = tablename.toLowerCase();
  269. fieldname = fieldname.toLowerCase();
  270. if (!tableidmap.containsKey(tablename)) {
  271. Rows rows = dbConnect.runSqlQuery("select convert(bigint,isnull(max(" + fieldname + "),0)) as " + fieldname + " from " + tablename);
  272. if (!rows.isEmpty()) {
  273. long id = rows.get(0).getLong(fieldname);
  274. tableidmap.put(tablename, id);
  275. }
  276. }
  277. tableidmap.put(tablename, tableidmap.get(tablename) + 1 + count);
  278. return tableidmap.get(tablename) - count;
  279. }
  280. }
  281. public Row getUser(String userid) {
  282. return dbConnect.runSqlQuery("select * from tenterprise_users where siteid='" + siteid + "' and tenterprise_userid=" + userid).get(0);
  283. }
  284. public Row getUser(String userid, String siteid) {
  285. return dbConnect.runSqlQuery("select * from tenterprise_users where siteid='" + siteid + "' and tenterprise_userid=" + userid).get(0);
  286. }
  287. public RowsMap getUser(String userids[]) {
  288. StringBuilder where = new StringBuilder("''");
  289. for (String userid : userids) {
  290. where.append(",'").append(userid).append("'");
  291. }
  292. return dbConnect.runSqlQuery("select * from tenterprise_users where siteid='" + siteid + "' and tenterprise_userid in(" + where + ")").toRowsMap("tenterprise_userid");
  293. }
  294. /**
  295. * 获取用户账户余额
  296. *
  297. * @return
  298. */
  299. public long getUserBalance() {
  300. Rows balancerows = dbConnect.runSqlQuery("select faccountbalance from tenterprise_users where siteid='" + siteid + "' and tenterprise_userid=" + userid);
  301. if (!balancerows.isEmpty()) {
  302. return balancerows.get(0).getLong("faccountbalance");
  303. } else {
  304. return 0L;
  305. }
  306. }
  307. /**
  308. * 获取用户账户冻结金额
  309. *
  310. * @return
  311. */
  312. public long getUserFreez() {
  313. Rows freezrows = dbConnect.runSqlQuery("select ffreezamount from accountfreez_view where siteid='" + siteid + "' and tenterprise_userid=" + userid);
  314. if (!freezrows.isEmpty()) {
  315. return freezrows.get(0).getLong("ffreezamount");
  316. } else {
  317. return 0L;
  318. }
  319. }
  320. /**
  321. * 获取账户可用余额
  322. *
  323. * @return
  324. */
  325. public long getUserCanUseAmount() {
  326. Rows canuseamountrows = dbConnect.runSqlQuery("select (isnull(t1.faccountbalance,0)-isnull(t2.ffreezamount,0))as fcanuseamount from tenterprise_users t1 left join accountfreez_view t2 on t1.siteid=t2.siteid and t1.tenterprise_userid=t2.tenterprise_userid where t1.siteid='" + siteid + "' and t1.tenterprise_userid='" + userid + "'");
  327. if (!canuseamountrows.isEmpty()) {
  328. return canuseamountrows.get(0).getLong("fcanuseamount");
  329. } else {
  330. return 0L;
  331. }
  332. }
  333. /**
  334. * 获取商学院功能说明
  335. *
  336. * @return
  337. */
  338. public long getAppHelpNotes(String ftype) {
  339. long tarchives_scid = 0L;
  340. if (parameter.isdebug()) {
  341. if ("销售系统".equals(ftype)) {
  342. tarchives_scid = 2305L;
  343. }
  344. } else {
  345. if ("销售系统".equals(ftype)) {
  346. tarchives_scid = 2305L;
  347. }
  348. }
  349. return tarchives_scid;
  350. }
  351. public D3BReturnObject_Err getErrReturnObject() {
  352. return returnObject.getErrObject();
  353. }
  354. public D3BReturnObject_Suc getSucReturnObject() {
  355. return returnObject.getSucObject();
  356. }
  357. /**
  358. * 获取当前及下属的账号列表,返回一个账号列表字符串
  359. *
  360. * @return
  361. */
  362. public String[] getSubUsers() {
  363. if (content.containsKey("fsalerid") && !"".equals(content.getString("fsalerid"))) {
  364. return getSubUsers(content.getString("fsalerid"));
  365. } else {
  366. Rows rows = getSubUserRows();
  367. return rows.toArray("tenterprise_userid");
  368. }
  369. }
  370. /**
  371. * 获取当前及下属的账号列表,返回一个账号列表字符串
  372. *
  373. * @return
  374. */
  375. public String[] getSubUsers(String userid) {
  376. Rows rows = getSubUserRows(siteid, userid);
  377. return rows.toArray("tenterprise_userid");
  378. }
  379. /**
  380. * 获取当前及下属的账号列表,返回一个账号列表字符串
  381. *
  382. * @return
  383. */
  384. public String[] getSubUsers(String siteid, String userid) {
  385. Rows rows = getSubUserRows(siteid, userid);
  386. return rows.toArray("tenterprise_userid");
  387. }
  388. public Rows getSubUserRows() {
  389. String key = siteid + userid;
  390. Object object = DataPool.get(key);
  391. if (object != null) {
  392. return (Rows) object;
  393. }
  394. SQLFactory sqlFactory = new SQLFactory("下属账号列表获取");
  395. sqlFactory.addParameter("userid", userid);
  396. sqlFactory.addParameter("siteid", siteid);
  397. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  398. DataPool.put(key, rows, 60);
  399. return rows;
  400. }
  401. public Rows getSubUserRows(String siteid, String userid) {
  402. String key = siteid + userid;
  403. Object object = DataPool.get(key);
  404. if (object != null) {
  405. return (Rows) object;
  406. }
  407. SQLFactory sqlFactory = new SQLFactory("下属账号列表获取");
  408. sqlFactory.addParameter("userid", userid);
  409. sqlFactory.addParameter("siteid", siteid);
  410. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  411. DataPool.put(key, rows, 60);
  412. return rows;
  413. }
  414. public Row getAttachmentUrl(long tattachmentid) {
  415. SQLFactory docfactory = new SQLFactory("附件查询_ID");
  416. docfactory.addParameter("siteid", siteid);
  417. docfactory.addParameter("tattachmentid", tattachmentid);
  418. return dbConnect.runSqlQuery(docfactory.getSQL()).getRow(0);
  419. }
  420. public RowsMap getAttachmentUrl(String ownertable, String[] ownerids) {
  421. return getAttachmentUrl(ownertable, ownerids, "default");
  422. }
  423. public RowsMap getAttachmentUrl(String ownertable, ArrayList<String> ownerids) {
  424. return getAttachmentUrl(ownertable, ownerids, "default");
  425. }
  426. public Rows getAttachmentUrl(String ownertable, String ownerid) {
  427. return getAttachmentUrl(ownertable, ownerid, "default");
  428. }
  429. public RowsMap getAttachmentUrl(String ownertable, ArrayList<String> ownerids, String ftype) {
  430. return getAttachmentUrl(ownertable, ownerids.toArray(new String[0]), ftype);
  431. }
  432. public RowsMap getAttachmentUrl(String ownertable, String[] ownerids, String ftype) {
  433. SQLFactory docfactory = new SQLFactory("附件查询");
  434. docfactory.addParameter("siteid", siteid);
  435. docfactory.addParameter("ownertable", ownertable);
  436. docfactory.addParameter_in("ownerid", ownerids);
  437. docfactory.addParameter("ftype", ftype);
  438. return dbConnect.runSqlQuery(docfactory.getSQL()).toRowsMap("ownerid");
  439. }
  440. public static HashMap<Long, String> headPicMap = new HashMap<>();
  441. /**
  442. * 获取用户头像
  443. *
  444. * @return
  445. */
  446. public String getHeadPic(long userid) {
  447. if (!headPicMap.containsKey(userid)) {
  448. Rows rows = getAttachmentUrl("tenterprise_users", String.valueOf(userid), "headportrait");
  449. if (!rows.isEmpty()) {
  450. headPicMap.put(userid, rows.get(0).getString("fobsurl_minimage"));
  451. }
  452. }
  453. return headPicMap.getOrDefault(userid, "");
  454. }
  455. public Rows getAttachmentUrl(String ownertable, String ownerid, String ftype) {
  456. SQLFactory docfactory = new SQLFactory("附件查询");
  457. docfactory.addParameter("siteid", siteid);
  458. docfactory.addParameter("ownertable", ownertable);
  459. docfactory.addParameter_in("ownerid", ownerid);
  460. docfactory.addParameter("ftype", ftype);
  461. return dbConnect.runSqlQuery(docfactory.getSQL());
  462. }
  463. public RowsMap getAttachmentQty(String ownertable, String[] ownerids) {
  464. return getAttachmentQty(ownertable, ownerids, "default");
  465. }
  466. public RowsMap getAttachmentQty(String ownertable, ArrayList<String> ownerids) {
  467. return getAttachmentQty(ownertable, ownerids, "default");
  468. }
  469. public Rows getAttachmentQty(String ownertable, String ownerids) {
  470. return getAttachmentQty(ownertable, ownerids, "default");
  471. }
  472. public RowsMap getAttachmentQty(String ownertable, ArrayList<String> ownerids, String ftype) {
  473. return getAttachmentQty(ownertable, ownerids.toArray(new String[0]), ftype);
  474. }
  475. public RowsMap getAttachmentQty(String ownertable, String[] ownerids, String ftype) {
  476. SQLFactory docfactory = new SQLFactory("附件数量查询");
  477. docfactory.addParameter("siteid", siteid);
  478. docfactory.addParameter("ownertable", ownertable);
  479. docfactory.addParameter_in("ownerid", ownerids);
  480. docfactory.addParameter("ftype", ftype);
  481. return dbConnect.runSqlQuery(docfactory.getSQL()).toRowsMap("ownerid");
  482. }
  483. public Rows getAttachmentQty(String ownertable, String ownerids, String ftype) {
  484. SQLFactory docfactory = new SQLFactory("附件数量查询");
  485. docfactory.addParameter("siteid", siteid);
  486. docfactory.addParameter("ownertable", ownertable);
  487. docfactory.addParameter_in("ownerid", ownerids);
  488. docfactory.addParameter("ftype", ftype);
  489. Rows rows = dbConnect.runSqlQuery(docfactory.getSQL());
  490. return rows;
  491. }
  492. public static HashMap<String, String> uniquecolumnnamemap = new HashMap<>();
  493. public String getuniquecolumnname(String tablename) {
  494. tablename = tablename.toLowerCase();
  495. if (!uniquecolumnnamemap.containsKey(tablename)) {
  496. SQLFactory sqlFactory = new SQLFactory("表ID字段查询");
  497. sqlFactory.addParameter("tablename", tablename);
  498. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  499. for (Row row : rows) {
  500. uniquecolumnnamemap.put(row.getString("tablename").toLowerCase(), row.getString("uniquecolumnname").toLowerCase());
  501. }
  502. }
  503. return uniquecolumnnamemap.get(tablename);
  504. }
  505. public Rows addAttachmentUrl(Rows rows, String tablename, String fdoctype, String jsonkeyname) {
  506. String uniquecolumnname = getuniquecolumnname(tablename);
  507. RowsMap rowsMap = getAttachmentUrl(tablename, rows.toArrayList(uniquecolumnname), fdoctype);
  508. for (Row row : rows) {
  509. String ownerid = row.getString(uniquecolumnname);
  510. if (rowsMap.containsKey(ownerid)) {
  511. row.put(jsonkeyname, rowsMap.get(ownerid));
  512. } else {
  513. row.put(jsonkeyname, "[]");
  514. }
  515. }
  516. return rows;
  517. }
  518. /**
  519. * 获取请求访问地址数据key
  520. *
  521. * @return
  522. */
  523. public long getRequestAuthorDataKey() throws P2Exception {
  524. long datakey = 0L;
  525. PaoSetRemote trequestauthor = getP2ServerSystemPaoSet("trequestauthor");
  526. PaoRemote pao = trequestauthor.addAtEnd();
  527. pao.setValue("siteid", siteid, 11L);
  528. Calendar calendar = Calendar.getInstance();
  529. pao.setValue("createdate", calendar.getTime(), 11L);
  530. calendar.add(Calendar.SECOND, 20);
  531. pao.setValue("closedate", calendar.getTime(), 11L);
  532. pao.setValue("tenterprise_userid", userid, 11L);
  533. datakey = pao.getUniqueIDValue();
  534. trequestauthor.save();
  535. return datakey;
  536. }
  537. public void p2ServerSystemPaoSetClose() {
  538. for (PaoSetRemote paoset : PaoSetRemoteList) {
  539. try {
  540. paoset.close();
  541. } catch (Exception e) {
  542. e.printStackTrace();
  543. }
  544. }
  545. PaoSetRemoteList.clear();
  546. }
  547. public static HashMap<Long, ArrayList<Long>> imdialog_usermap = new HashMap<>();
  548. /**
  549. * 根据消息对话框ID获取用户id
  550. *
  551. * @param timdialogid
  552. * @return
  553. */
  554. public ArrayList<Long> getUserIds(long timdialogid) {
  555. if (!imdialog_usermap.containsKey(timdialogid)) {
  556. Rows rows = dbConnect.runSqlQuery("select tenterprise_userid from timdialogusers where siteid='" + siteid + "' and timdialogid='" + timdialogid + "' and fisremove=0");
  557. ArrayList<Long> list = new ArrayList<>();
  558. for (Row row : rows) {
  559. list.add(row.getLong("tenterprise_userid"));
  560. }
  561. imdialog_usermap.put(timdialogid, list);
  562. }
  563. return imdialog_usermap.get(timdialogid);
  564. }
  565. }