AccountUtils.java 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. package com.uas.sso.util;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.alibaba.fastjson.TypeReference;
  5. import com.uas.sso.AccountConfig;
  6. import com.uas.sso.ResultWrap;
  7. import com.uas.sso.SSOHelper;
  8. import com.uas.sso.common.util.HttpUtil;
  9. import com.uas.sso.entity.*;
  10. import com.uas.sso.support.Page;
  11. import org.springframework.ui.ModelMap;
  12. import org.springframework.util.StringUtils;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.Map;
  16. /**
  17. * 客户端使用,操作企业资料、用户资料
  18. *
  19. * @author wangmh
  20. *
  21. */
  22. public class AccountUtils {
  23. /**
  24. * 企业解除绑定的应用
  25. *
  26. * @author wangmh
  27. * @date 2018/1/26 16:34
  28. * @param spaceUU 企业uu号
  29. * @param appId 应用id
  30. * @throws Exception
  31. */
  32. public static void unbindApp(Long spaceUU, String appId) throws Exception {
  33. String saveUrl = AccountConfig.getSpaceSaveUrl();
  34. if (!StringUtils.isEmpty(saveUrl)) {
  35. ModelMap formData = new ModelMap();
  36. formData.put("_operate", "unbind");
  37. formData.put("spaceUU", spaceUU);
  38. formData.put("appId", appId);
  39. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  40. if (!res.isSuccess()) {
  41. throw new Exception(res.getContent());
  42. } else {
  43. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  44. if (!result.isSuccess()) {
  45. throw new Exception(result.getErrMsg());
  46. }
  47. }
  48. }
  49. }
  50. /**
  51. * 企业开通应用
  52. * @param spaceUU 企业uu号
  53. * @param appId 应用id
  54. * @throws Exception
  55. */
  56. public static void bindApp(Long spaceUU, String appId) throws Exception {
  57. String saveUrl = AccountConfig.getSpaceSaveUrl();
  58. if (!StringUtils.isEmpty(saveUrl)) {
  59. ModelMap formData = new ModelMap();
  60. formData.put("_operate", "bind");
  61. formData.put("spaceUU", spaceUU);
  62. formData.put("appId", appId);
  63. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  64. if (!res.isSuccess()) {
  65. throw new Exception(res.getContent());
  66. } else {
  67. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  68. if (!result.isSuccess()) {
  69. throw new Exception(result.getErrMsg());
  70. }
  71. }
  72. }
  73. }
  74. /**
  75. * 用户解除绑定企业
  76. * @param userUU 用户uu号
  77. * @param spaceUU 企业uu号
  78. * @throws Exception
  79. */
  80. public static void removeUser(Long userUU, Long spaceUU) throws Exception {
  81. String saveUrl = AccountConfig.getUserSaveUrl();
  82. if (!StringUtils.isEmpty(saveUrl)) {
  83. ModelMap formData = new ModelMap();
  84. formData.put("_operate", "unbind");
  85. formData.put("userUU", userUU);
  86. formData.put("spaceUU", spaceUU);
  87. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  88. if (!res.isSuccess()) {
  89. throw new Exception(res.getContent());
  90. } else {
  91. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  92. if (!result.isSuccess()) {
  93. throw new Exception(result.getErrMsg());
  94. }
  95. }
  96. }
  97. }
  98. /**
  99. * 企业添加已注册用户
  100. * @param userUU 用户uu号
  101. * @param spaceUU 企业uu号
  102. * @throws Exception
  103. */
  104. public static void addUser(Long userUU, Long spaceUU) throws Exception {
  105. String saveUrl = AccountConfig.getUserSaveUrl();
  106. if (!StringUtils.isEmpty(saveUrl)) {
  107. ModelMap formData = new ModelMap();
  108. formData.put("_operate", "bind");
  109. formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
  110. formData.put("userUU", userUU);
  111. formData.put("spaceUU", spaceUU);
  112. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  113. if (!res.isSuccess()) {
  114. throw new Exception(res.getContent());
  115. } else {
  116. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  117. if (!result.isSuccess()) {
  118. throw new Exception(result.getErrMsg());
  119. }
  120. }
  121. }
  122. }
  123. /**
  124. * 企业添加未注册用户
  125. * @param spaceUU
  126. * @param user
  127. * @throws Exception
  128. */
  129. public static UserView addUser(Long spaceUU, UserView user) throws Exception {
  130. String saveUrl = AccountConfig.getUserSaveUrl();
  131. if (!StringUtils.isEmpty(saveUrl)) {
  132. JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
  133. formData.put("_operate", "add");
  134. formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
  135. formData.put("spaceUU", spaceUU);
  136. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  137. if (!res.isSuccess()) {
  138. throw new Exception(res.getContent());
  139. } else {
  140. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  141. if (!result.isSuccess()) {
  142. throw new Exception(result.getErrMsg());
  143. } else if (result.getContent() != null) {
  144. return JSON.parseObject(result.getContent().toString(), UserView.class);
  145. }
  146. }
  147. }
  148. return null;
  149. }
  150. /**
  151. * 修改用户信息
  152. *
  153. * @param user
  154. * @return
  155. * @throws Exception
  156. */
  157. public static List<UserView> saveUser(UserView user, Object spaceDialectUID) throws Exception {
  158. String saveUrl = AccountConfig.getUserSaveUrl();
  159. String appId = SSOHelper.getSSOService().getConfig().getAppName();
  160. if (!StringUtils.isEmpty(saveUrl)) {
  161. JSONObject formData = new JSONObject();
  162. if (user != null) {
  163. formData = JSON.parseObject(JSON.toJSONString(user));
  164. }
  165. // HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  166. // if (!res.isSuccess()) {
  167. // throw new Exception(res.getContent());
  168. // } else {
  169. // ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  170. // if (result.isError()) {
  171. // throw new Exception(result.getErrMsg());
  172. // } else {
  173. // return JSON.parseArray(JSON.toJSONString(result.getContent()), UserView.class);
  174. // }
  175. // }
  176. }
  177. return null;
  178. }
  179. /**
  180. * 根据营业执照号获得企业信息
  181. * @param businessCode 营业执照号
  182. * @return
  183. */
  184. public static UserSpaceView findByBusinessCode(String businessCode) throws Exception {
  185. String saveUrl = AccountConfig.getSpaceSaveUrl();
  186. if (!StringUtils.isEmpty(saveUrl)) {
  187. ModelMap formData = new ModelMap();
  188. saveUrl = saveUrl + "/info/businessCode";
  189. formData.put("businessCode", businessCode);
  190. HttpUtil.ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
  191. if (!res.isSuccess()) {
  192. throw new Exception(res.getContent());
  193. } else {
  194. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  195. if (!result.isSuccess()) {
  196. throw new Exception(result.getErrMsg());
  197. } else if (result.getContent() != null){
  198. return JSON.parseObject(result.getContent().toString(), UserSpaceView.class);
  199. }
  200. }
  201. }
  202. return null;
  203. }
  204. /**
  205. * 根据企业名获得企业信息
  206. * @param spaceName 企业名
  207. * @return
  208. */
  209. public static UserSpaceView findBySpaceName(String spaceName) throws Exception {
  210. String saveUrl = AccountConfig.getSpaceSaveUrl();
  211. if (!StringUtils.isEmpty(saveUrl)) {
  212. ModelMap formData = new ModelMap();
  213. saveUrl = saveUrl + "/info/name";
  214. formData.put("name", spaceName);
  215. HttpUtil.ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
  216. if (!res.isSuccess()) {
  217. throw new Exception(res.getContent());
  218. } else {
  219. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  220. if (!result.isSuccess()) {
  221. throw new Exception(result.getErrMsg());
  222. } else if (result.getContent() != null){
  223. return JSON.parseObject(result.getContent().toString(), UserSpaceView.class);
  224. }
  225. }
  226. }
  227. return null;
  228. }
  229. /**
  230. * 用户申请绑定企业
  231. * @param userUU 用户uu号
  232. * @param spaceUU 企业uu号
  233. * @throws Exception
  234. */
  235. public static void applyUserSpace(Long userUU, Long spaceUU) throws Exception {
  236. String saveUrl = AccountConfig.getUserSaveUrl();
  237. if (!StringUtils.isEmpty(saveUrl)) {
  238. ModelMap formData = new ModelMap();
  239. saveUrl = saveUrl + "/apply/bind";
  240. formData.put("userUU", userUU);
  241. formData.put("spaceUU", spaceUU);
  242. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  243. if (!res.isSuccess()) {
  244. throw new Exception(res.getContent());
  245. } else {
  246. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  247. if (!result.isSuccess()) {
  248. throw new Exception(result.getErrMsg());
  249. }
  250. }
  251. }
  252. }
  253. /**
  254. * 分页查找个人申请记录
  255. *
  256. * @author wangmh
  257. * @date 2018/2/1 15:47
  258. * @param userUU 用户uu号
  259. * @param page 页数(从0开始)
  260. * @param size 每页大小
  261. * @return
  262. * @throws Exception
  263. */
  264. public static Page<ApplyUserSpaceView> findApplyInfo(Long userUU, int page, int size) throws Exception {
  265. String url = AccountConfig.getUserSaveUrl();
  266. if (!StringUtils.isEmpty(url)) {
  267. url = url + "/apply/info";
  268. ModelMap data = new ModelMap();
  269. data.put("userUU", userUU);
  270. data.put("page", page);
  271. data.put("size", size);
  272. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  273. if (!res.isSuccess()) {
  274. throw new Exception(res.getContent());
  275. } else {
  276. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  277. if (!result.isSuccess()) {
  278. throw new Exception(result.getErrMsg());
  279. } else if (result.getContent() != null) {
  280. return JSON.parseObject(result.getContent().toString(), new TypeReference<Page<ApplyUserSpaceView>>() {
  281. });
  282. }
  283. }
  284. }
  285. return null;
  286. }
  287. /**
  288. * 统计该企业申请记录数量
  289. * @param spaceUU 企业uu号
  290. * @return
  291. * @throws Exception
  292. */
  293. public static Map<String, Integer> applyCount(Long spaceUU) throws Exception {
  294. String url = AccountConfig.getSpaceSaveUrl();
  295. if (!StringUtils.isEmpty(url)) {
  296. url = url + "/apply/count";
  297. ModelMap data = new ModelMap();
  298. data.put("spaceUU", spaceUU);
  299. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  300. if (!res.isSuccess()) {
  301. throw new Exception(res.getContent());
  302. } else {
  303. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  304. if (!result.isSuccess()) {
  305. throw new Exception(result.getErrMsg());
  306. } else if (result.getContent() != null) {
  307. return JSON.parseObject(result.getContent().toString(), Map.class);
  308. }
  309. }
  310. }
  311. return null;
  312. }
  313. /**
  314. * 校验企业名称
  315. * @param spaceName 企业名称
  316. */
  317. public static void checkSpaceName(String spaceName) throws Exception {
  318. String url = AccountConfig.getSpaceSaveUrl();
  319. if (!StringUtils.isEmpty(url)) {
  320. url = url + "/checkSpaceName";
  321. ModelMap data = new ModelMap();
  322. data.put("spaceName", spaceName);
  323. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  324. if (!res.isSuccess()) {
  325. throw new Exception(res.getContent());
  326. } else {
  327. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  328. if (!result.isSuccess()) {
  329. throw new Exception(result.getErrMsg());
  330. }
  331. }
  332. }
  333. }
  334. /**
  335. * 校验企业营业执照号
  336. * @param businessCode 企业营业执照号
  337. */
  338. public static void checkBusinessCode(String businessCode) throws Exception {
  339. String url = AccountConfig.getSpaceSaveUrl();
  340. if (!StringUtils.isEmpty(url)) {
  341. url = url + "/checkBusinessCode";
  342. ModelMap data = new ModelMap();
  343. data.put("businessCode", businessCode);
  344. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  345. if (!res.isSuccess()) {
  346. throw new Exception(res.getContent());
  347. } else {
  348. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  349. if (!result.isSuccess()) {
  350. throw new Exception(result.getErrMsg());
  351. }
  352. }
  353. }
  354. }
  355. /**
  356. * 根据用户uu号获取用户信息
  357. * @param userUU 用户uu号
  358. * @return
  359. * @throws Exception
  360. */
  361. public static UserView findByUserUU(Long userUU) throws Exception {
  362. String url = AccountConfig.getUserSaveUrl();
  363. if (!StringUtils.isEmpty(url)) {
  364. url = url + "/info";
  365. ModelMap data = new ModelMap();
  366. data.put("userUU", userUU);
  367. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  368. if (!res.isSuccess()) {
  369. throw new Exception(res.getContent());
  370. } else {
  371. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  372. if (!result.isSuccess()) {
  373. throw new Exception(result.getErrMsg());
  374. } else if (result.getContent() != null) {
  375. return JSON.parseObject(result.getContent().toString(), UserView.class);
  376. }
  377. }
  378. }
  379. return null;
  380. }
  381. /**
  382. * 根据企业uu号获取企业信息
  383. * @param spaceUU 企业uu号
  384. * @return
  385. * @throws Exception
  386. */
  387. public static UserSpaceView findBySpaceUU(Long spaceUU) throws Exception {
  388. String url = AccountConfig.getSpaceSaveUrl();
  389. if (!StringUtils.isEmpty(url)) {
  390. url = url + "/info/spaceUU";
  391. ModelMap data = new ModelMap();
  392. data.put("spaceUU", spaceUU);
  393. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  394. if (!res.isSuccess()) {
  395. throw new Exception(res.getContent());
  396. } else {
  397. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  398. if (!result.isSuccess()) {
  399. throw new Exception(result.getErrMsg());
  400. } else if (result.getContent() != null) {
  401. return JSON.parseObject(result.getContent().toString(), UserSpaceView.class);
  402. }
  403. }
  404. }
  405. return null;
  406. }
  407. /**
  408. * 通过当前企业号和企业列表中的企业号查询申请状态
  409. *
  410. * @return
  411. * @throws Exception
  412. */
  413. public static RequestStatus getStatusByCustUidAndVendUid(String custBusinessCode, String vendBusinessCode) throws Exception {
  414. String url = AccountConfig.getEnPartnersUrl();
  415. RequestStatus request = new RequestStatus();
  416. if (!StringUtils.isEmpty(url)) {
  417. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "getRequestStatus")
  418. .addAttribute("vendBusinessCode", vendBusinessCode)
  419. .addAttribute("custBusinessCode", custBusinessCode));
  420. if (!res.isSuccess()) {
  421. throw new Exception(res.getContent());
  422. } else {
  423. request = JSON.parseObject(res.getContent(), RequestStatus.class);
  424. }
  425. }
  426. return request;
  427. }
  428. /**
  429. * 校验密码
  430. *
  431. * <pre>
  432. * 全匹配模式
  433. * </pre>
  434. *
  435. * @param user
  436. * @throws Exception
  437. */
  438. public static boolean fuzzyCheckPassword(UserView user) throws Exception {
  439. String saveUrl = AccountConfig.getUserSaveUrl();
  440. if (!StringUtils.isEmpty(saveUrl)) {
  441. JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
  442. formData.put("_operate", "fuzzyCheck");
  443. HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  444. if (!res.isSuccess()) {
  445. throw new Exception(res.getContent());
  446. } else {
  447. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  448. if (!result.isSuccess()) {
  449. throw new Exception(result.getErrMsg());
  450. } else {
  451. return true;
  452. }
  453. }
  454. }
  455. return false;
  456. }
  457. /// 之后方法会恢复并修改
  458. //
  459. // /**
  460. // * 获取校验码
  461. // *
  462. // * @param username
  463. // * 手机号或邮箱地址
  464. // * @return
  465. // */
  466. // public static void sendValidCode(String username) throws Exception {
  467. // String saveUrl = AccountConfig.getUserSaveUrl();
  468. // if (!StringUtils.isEmpty(saveUrl)) {
  469. // ResponseWrap res = HttpUtil.doGet(saveUrl, new ModelMap("_operate", "getVcode").addAttribute("username", username));
  470. // if (!res.isSuccess())
  471. // throw new Exception(res.getContent());
  472. // else {
  473. // ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  474. // if (!result.isSuccess())
  475. // throw new Exception(result.getErrMsg());
  476. // }
  477. // }
  478. // }
  479. //
  480. // /**
  481. // * 验证校验码
  482. // *
  483. // * @param username
  484. // * 手机号或邮箱地址
  485. // * @param validCode
  486. // * 校验码
  487. // * @return
  488. // */
  489. // public static boolean checkValidCode(String username, String validCode) throws Exception {
  490. // String saveUrl = AccountConfig.getUserSaveUrl();
  491. // if (!StringUtils.isEmpty(saveUrl)) {
  492. // ResponseWrap res = HttpUtil.doGet(saveUrl, new ModelMap("_operate", "checkVcode").addAttribute("username", username)
  493. // .addAttribute("validCode", validCode));
  494. // if (!res.isSuccess())
  495. // throw new Exception(res.getContent());
  496. // else {
  497. // ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  498. // if (!result.isSuccess())
  499. // throw new Exception(result.getErrMsg());
  500. // else
  501. // return true;
  502. // }
  503. // }
  504. // return false;
  505. // }
  506. //
  507. // public static String getAccessToken(String appId, String spaceDialectUID, String uid) throws Exception {
  508. // String saveUrl = AccountConfig.getUserSaveUrl();
  509. // if (!StringUtils.isEmpty(saveUrl)) {
  510. // saveUrl = saveUrl + "/getToken";
  511. // JSONObject formData = new JSONObject();
  512. // formData.put("appId", appId);
  513. // formData.put("spaceDialectUID", spaceDialectUID);
  514. // formData.put("uid", uid);
  515. // ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
  516. // if (!res.isSuccess()) {
  517. // throw new Exception(res.getContent());
  518. // } else {
  519. // return res.getContent();
  520. // }
  521. // }
  522. // return null;
  523. // }
  524. /**
  525. * 验证密码,返回绑定身份信息的token
  526. *
  527. * @return
  528. */
  529. public static String getAccessToken(UserView user) throws Exception {
  530. String saveUrl = AccountConfig.getUserSaveUrl();
  531. if (!StringUtils.isEmpty(saveUrl)) {
  532. JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
  533. formData.put("_operate", "getToken");
  534. HttpUtil.ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
  535. if (!res.isSuccess()) {
  536. throw new Exception(res.getContent());
  537. } else {
  538. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  539. if (!result.isSuccess()) {
  540. throw new Exception(result.getErrMsg());
  541. } else {
  542. return String.valueOf(result.getContent());
  543. }
  544. }
  545. }
  546. return null;
  547. }
  548. //
  549. // /**
  550. // * 验证token,返回当前应用相关的身份信息
  551. // *
  552. // * @return
  553. // */
  554. // public static UserView checkAccessToken(String token) throws Exception {
  555. // String saveUrl = AccountConfig.getUserSaveUrl();
  556. // if (!StringUtils.isEmpty(saveUrl)) {
  557. // ResponseWrap res = HttpUtil.doGet(
  558. // saveUrl,
  559. // new ModelMap("_operate", "checkToken").addAttribute("token", token).addAttribute("appId",
  560. // SSOHelper.getSSOService().getConfig().getAppName()));
  561. // if (!res.isSuccess())
  562. // throw new Exception(res.getContent());
  563. // else {
  564. // ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  565. // if (!result.isSuccess())
  566. // throw new Exception(result.getErrMsg());
  567. // else
  568. // return JSON.parseObject(JSON.toJSONString(result.getContent()), UserView.class);
  569. // }
  570. // }
  571. // return null;
  572. // }
  573. //
  574. // /**
  575. // * 用token验证登录
  576. // *
  577. // * @param request
  578. // * @param response
  579. // * @param token
  580. // * @throws Exception
  581. // */
  582. // public static UserView loginByAccessToken(HttpServletRequest request, HttpServletResponse response, String token) throws Exception {
  583. // UserView user = checkAccessToken(token);
  584. // if (null != user) {
  585. // SSOToken st = new SSOToken(request, user.getUid());
  586. // st.setData(JSON.toJSONString(user));
  587. // SSOHelper.setSSOCookie(request, response, st, true);
  588. // }
  589. // return user;
  590. // }
  591. /**
  592. * 传入当前登录的企业的营业执照号,查询发出的申请
  593. *
  594. * @param businessCode 营业执照号
  595. * @param statusCode 状态吗
  596. * @param keyword 关键词
  597. * @param pageNumber 页号(0开始)
  598. * @param pageSize 每页数量
  599. * @return
  600. * @throws Exception
  601. */
  602. public static Page<PartnershipRecordView> getAllRequest(String businessCode, Integer statusCode, String keyword, int pageNumber,
  603. int pageSize) throws Exception {
  604. String getUrl = AccountConfig.getEnPartnersUrl();
  605. if (!StringUtils.isEmpty(getUrl)) {
  606. HttpUtil.ResponseWrap res = HttpUtil.doGet(getUrl, new ModelMap("_operate", "getAllRequest").addAttribute("businessCode", businessCode)
  607. .addAttribute("statusCode", statusCode).addAttribute("businessCode", businessCode).addAttribute("keyword", keyword)
  608. .addAttribute("pageNumber", pageNumber).addAttribute("pageSize", pageSize));
  609. if (!res.isSuccess()) {
  610. throw new Exception(res.getContent());
  611. } else {
  612. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  613. if (!result.isSuccess()) {
  614. throw new Exception(result.getErrMsg());
  615. } else if (result.getContent() != null) {
  616. return JSONObject.parseObject(result.getContent().toString(), new TypeReference<Page<PartnershipRecordView>>() {});
  617. }
  618. }
  619. }
  620. return null;
  621. }
  622. //
  623. // /**
  624. // * 通过已存在uu过滤,取出全部合作伙伴(UAS接口用)
  625. // * @param businessCode
  626. // * @param statusCode
  627. // * @param keyword
  628. // * @param pageNumber
  629. // * @param pageSize
  630. // * @param partnerUUs
  631. // * @return
  632. // */
  633. // public static Page<PartnershipRecord> getRequestFilterByPartnerUUs(String businessCode, Integer statusCode, String keyword, List<Long> partnerUUs, int pageNumber, int pageSize) throws Exception {
  634. // String getUrl = AccountConfig.getEnPartnersUrl();
  635. // if (!StringUtils.isEmpty(getUrl)) {
  636. // ResponseWrap res = HttpUtil.doGet(getUrl, new ModelMap("_operate", "getAllRequestFilterByPartnerUUs").addAttribute("businessCode", businessCode)
  637. // .addAttribute("statusCode", statusCode).addAttribute("keyword", keyword).addAttribute("partnerUUs", JSON.toJSON(partnerUUs))
  638. // .addAttribute("pageNumber", pageNumber).addAttribute("pageSize", pageSize));
  639. // if (!res.isSuccess())
  640. // throw new Exception(res.getContent());
  641. // return JSON.parseObject(res.getContent(), new TypeReference<Page<PartnershipRecord>>() {
  642. // });
  643. // }
  644. // return null;
  645. // }
  646. //
  647. /**
  648. * 进入企业圈
  649. *
  650. * @return
  651. * @throws Exception
  652. */
  653. public static String redirectContactPage() throws Exception {
  654. String enterUrl = AccountConfig.getContactPageUrl();
  655. return enterUrl;
  656. }
  657. /**
  658. * 通过关键词搜索企业信息
  659. *
  660. * @param keyword
  661. * @return
  662. * @throws Exception
  663. */
  664. public static Page<UserSpaceView> getUserSpacesByKeyword(String keyword, int pageNumber, int pageSize) throws Exception {
  665. String Url = AccountConfig.getSpaceSaveUrl();
  666. if (!StringUtils.isEmpty(Url)) {
  667. HttpUtil.ResponseWrap res = HttpUtil.doGet(Url,
  668. new ModelMap("_operate", "getUserSpaces").addAttribute("keyword", keyword).addAttribute("pageNumber", pageNumber)
  669. .addAttribute("pageSize", pageSize));
  670. if (!res.isSuccess()) {
  671. throw new Exception(res.getContent());
  672. }
  673. return JSON.parseObject(res.getContent(), new TypeReference<Page<UserSpaceView>>() {
  674. });
  675. }
  676. return null;
  677. }
  678. //
  679. // /**
  680. // * 通过手机号搜索用户账号信息
  681. // *
  682. // * @param uid
  683. // * @return
  684. // * @throws Exception
  685. // */
  686. // public static List<User> getUserInfoByUid(String uid) throws Exception {
  687. // String Url = AccountConfig.getSpaceSaveUrl();
  688. // if (!StringUtils.isEmpty(Url)) {
  689. // ResponseWrap res = HttpUtil.doGet(Url + "/userInfo",
  690. // new ModelMap("uid", uid));
  691. // if (!res.isSuccess())
  692. // throw new Exception(res.getContent());
  693. // String resText = res.getContent();
  694. // JSONObject object = JSON.parseObject(resText);
  695. // String contentText = object.getString("content");
  696. // return JSON.parseArray(contentText, User.class);
  697. // }
  698. // return null;
  699. // }
  700. //
  701. // /**
  702. // * 通过营业执照号获取企业应用
  703. // *
  704. // * @param uid
  705. // * @return
  706. // * @throws Exception
  707. // */
  708. // public static List<UserSpace> getUserSpaceByUid(String uid) throws Exception {
  709. // String Url = AccountConfig.getSpaceSaveUrl();
  710. // if (!StringUtils.isEmpty(Url)) {
  711. // ResponseWrap res = HttpUtil.doGet(Url + "/" + uid);
  712. // if (!res.isSuccess())
  713. // throw new Exception(res.getContent());
  714. // String resText = res.getContent();
  715. // JSONObject object = JSON.parseObject(resText);
  716. // String contentText = object.getString("content");
  717. // return JSON.parseArray(contentText, UserSpace.class);
  718. // }
  719. // return null;
  720. // }
  721. /**
  722. * 新增一条合作关系记录
  723. *
  724. * @param record
  725. * @return
  726. * @throws Exception
  727. */
  728. public static String addNewRecord(PartnershipRecordView record) throws Exception {
  729. String url = AccountConfig.getEnPartnersUrl();
  730. String result = null;
  731. if (!StringUtils.isEmpty(url)) {
  732. JSONObject formData = JSON.parseObject(JSON.toJSONString(record));
  733. formData.put("_operate", "addPartner");
  734. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, formData);
  735. result = res.getContent();
  736. }
  737. return result;
  738. }
  739. /**
  740. * 同步供应商关系为合作关系记录
  741. *
  742. * @param record
  743. * @return
  744. * @throws Exception
  745. */
  746. public static String synchronizeRecord(PartnershipRecordView record) throws Exception {
  747. String url = AccountConfig.getEnPartnersUrl();
  748. String result = null;
  749. if (!StringUtils.isEmpty(url)) {
  750. JSONObject formData = JSON.parseObject(JSON.toJSONString(record));
  751. formData.put("_operate", "synchronizePartner");
  752. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, formData);
  753. result = res.getContent();
  754. }
  755. return result;
  756. }
  757. /**
  758. * 通过id和申请人的电话进行确认
  759. *
  760. * @param id
  761. * @param vendUserTel
  762. * @param appId
  763. * @return
  764. * @throws Exception
  765. */
  766. public static String acceptRequest(Long id, String vendUserTel, String appId) throws Exception {
  767. String url = AccountConfig.getEnPartnersUrl();
  768. String result = null;
  769. if (!StringUtils.isEmpty(url)) {
  770. HttpUtil.ResponseWrap res = HttpUtil.doGet(
  771. url,
  772. new ModelMap("_operate", "acceptRequest").addAttribute("id", id).addAttribute("vendUserTel", vendUserTel)
  773. .addAttribute("appId", appId));
  774. if (!res.isSuccess()) {
  775. throw new Exception(res.getContent());
  776. } else {
  777. result = res.getContent();
  778. }
  779. }
  780. return result;
  781. }
  782. //
  783. /**
  784. * 申请不通过,通过申请人的电话操作,并标出原因
  785. *
  786. * @param id
  787. * @param reason
  788. * @param vendUserTel
  789. * @param appId
  790. * @return
  791. * @throws Exception
  792. */
  793. public static String rejectRequest(Long id, String reason, String vendUserTel, String appId) throws Exception {
  794. String url = AccountConfig.getEnPartnersUrl();
  795. String result = null;
  796. if (!StringUtils.isEmpty(url)) {
  797. HttpUtil.ResponseWrap res = HttpUtil.doGet(
  798. url,
  799. new ModelMap("_operate", "rejectRequest").addAttribute("id", id).addAttribute("reason", reason)
  800. .addAttribute("vendUserTel", vendUserTel).addAttribute("appId", appId));
  801. if (!res.isSuccess()) {
  802. throw new Exception(res.getContent());
  803. } else {
  804. result = res.getContent();
  805. }
  806. }
  807. return result;
  808. }
  809. /**
  810. * 搜索词通过id返回数据
  811. *
  812. * @param ids
  813. * @return
  814. * @throws Exception
  815. */
  816. public static List<UserSpaceView> findAll(String ids) throws Exception {
  817. String url = AccountConfig.getSpaceSaveUrl();
  818. List<UserSpaceView> details = new ArrayList<UserSpaceView>();
  819. if (!StringUtils.isEmpty(url)) {
  820. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "findAll").addAttribute("ids", ids));
  821. if(!res.isSuccess()) {
  822. throw new Exception(res.getContent());
  823. } else {
  824. details = JSONObject.parseArray(res.getContent(), UserSpaceView.class);
  825. }
  826. }
  827. return details;
  828. }
  829. /**
  830. * 通过企业营业执照查询收到的待处理的请求
  831. *
  832. * @param businessCode
  833. * @return
  834. * @throws Exception
  835. */
  836. public static String getRequestTodo(String businessCode) throws Exception {
  837. String url = AccountConfig.getEnPartnersUrl();
  838. String result = null;
  839. if (!StringUtils.isEmpty(url)) {
  840. HttpUtil.ResponseWrap res = HttpUtil.doGet(url,
  841. new ModelMap("_operate", "getRequestTodo").addAttribute("businessCode", businessCode));
  842. if (!res.isSuccess()) {
  843. throw new Exception(res.getContent());
  844. } else {
  845. result = res.getContent();
  846. }
  847. }
  848. return result;
  849. }
  850. /**
  851. * 其他应用发起邀请注册,同步数据
  852. *
  853. * @param jsonStr
  854. * @throws Exception
  855. */
  856. public static void synchroInvitation(String jsonStr) throws Exception {
  857. String url = AccountConfig.getEnPartnersUrl();
  858. if (!StringUtils.isEmpty(url)) {
  859. HttpUtil.doPost(url, new ModelMap("_operate", "invitation").addAttribute("jsonStr", jsonStr));
  860. }
  861. }
  862. /**
  863. * ERP、SAAS新开账套名称校验
  864. *
  865. * @param name
  866. * @return
  867. * @throws Exception
  868. */
  869. public static String validName(String name) throws Exception {
  870. String result = null;
  871. String url = AccountConfig.getSpaceSaveUrl();
  872. if (!StringUtils.isEmpty(url)) {
  873. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "validName").addAttribute("name", name),
  874. 60 * 1000);
  875. if (!res.isSuccess()) {
  876. throw new Exception(res.getContent());
  877. } else {
  878. result = res.getContent();
  879. }
  880. }
  881. return result;
  882. }
  883. /**
  884. * ERP、SAAS新开账套名称校验
  885. *
  886. * @param businessCode
  887. * @return
  888. * @throws Exception
  889. */
  890. public static String validBusinessCode(String businessCode) throws Exception {
  891. String result = null;
  892. String url = AccountConfig.getSpaceSaveUrl();
  893. if (!StringUtils.isEmpty(url)) {
  894. HttpUtil.ResponseWrap res = HttpUtil.doGet(url,
  895. new ModelMap("_operate", "validBusinessCode").addAttribute("businessCode", businessCode), 60 * 1000);
  896. if (!res.isSuccess()) {
  897. throw new Exception(res.getContent());
  898. } else {
  899. result = res.getContent();
  900. }
  901. }
  902. return result;
  903. }
  904. /**
  905. * ERP、SAAS新开账套
  906. *
  907. * @param userSpaceDetail
  908. * @param users
  909. * @throws Exception
  910. */
  911. public static String applyApp(UserSpaceView userSpaceDetail, List<UserView> users) throws Exception {
  912. String url = AccountConfig.getSpaceSaveUrl();
  913. String result = null;
  914. if (!StringUtils.isEmpty(url)) {
  915. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, new ModelMap("_operate", "registerBranchAccount")
  916. .addAttribute("detail", JSON.toJSON(userSpaceDetail))
  917. .addAttribute("userInfos", JSON.toJSON(users)));
  918. if (!res.isSuccess()) {
  919. throw new Exception(res.getContent());
  920. } else {
  921. result = res.getContent();
  922. }
  923. }
  924. return result;
  925. }
  926. /**
  927. * 商城个人账号增加企业注册
  928. *
  929. * @param userSpaceView 企业信息
  930. * @throws Exception
  931. */
  932. public static UserSpaceView register(UserSpaceView userSpaceView, UserView admin) throws Exception {
  933. String url = AccountConfig.getSpaceSaveUrl();
  934. if (!StringUtils.isEmpty(url)) {
  935. url = url + "/register/other";
  936. // 不把管理员设置成null会400
  937. userSpaceView.setAdmin(null);
  938. JSONObject data = JSON.parseObject(JSON.toJSONString(userSpaceView));
  939. data.putAll(JSON.parseObject(JSON.toJSONString(admin)));
  940. data.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
  941. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, data);
  942. if (!res.isSuccess()) {
  943. throw new Exception(res.getContent());
  944. } else {
  945. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  946. if (!result.isSuccess()) {
  947. throw new Exception(result.getErrMsg());
  948. } else {
  949. return JSON.parseObject(result.getContent().toString(), UserSpaceView.class);
  950. }
  951. }
  952. }
  953. return null;
  954. }
  955. /**
  956. * 商城个人账号增加企业注册
  957. *
  958. * @param userSpaceView 企业信息
  959. * @param admin 管理员信息
  960. * @param isSync 是否同步到来源应用
  961. * @throws Exception
  962. */
  963. public static UserSpaceView register(UserSpaceView userSpaceView, UserView admin, boolean isSync) throws Exception {
  964. String url = AccountConfig.getSpaceSaveUrl();
  965. if (!StringUtils.isEmpty(url)) {
  966. url = url + "/register/other";
  967. // 不把管理员设置成null会400
  968. userSpaceView.setAdmin(null);
  969. JSONObject data = JSON.parseObject(JSON.toJSONString(userSpaceView));
  970. data.putAll(JSON.parseObject(JSON.toJSONString(admin)));
  971. data.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
  972. data.put("isSyncSource", isSync);
  973. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, data);
  974. if (!res.isSuccess()) {
  975. throw new Exception(res.getContent());
  976. } else {
  977. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  978. if (!result.isSuccess()) {
  979. throw new Exception(result.getErrMsg());
  980. } else {
  981. return JSON.parseObject(result.getContent().toString(), UserSpaceView.class);
  982. }
  983. }
  984. }
  985. return null;
  986. }
  987. /**
  988. * 根据token获得用户信息
  989. *
  990. * @param token tokenId
  991. * @throws Exception
  992. */
  993. public static UserView getUserByToken(String token) throws Exception {
  994. String url = AccountConfig.getUserSaveUrl();
  995. if (!StringUtils.isEmpty(url)) {
  996. url = url + "/getUserByToken";
  997. ModelMap data = new ModelMap();
  998. data.put("token", token);
  999. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1000. if (!res.isSuccess()) {
  1001. throw new Exception(res.getContent());
  1002. } else {
  1003. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1004. if (!result.isSuccess()) {
  1005. throw new Exception(result.getErrMsg());
  1006. } else if (result.getContent() != null) {
  1007. return JSONObject.parseObject(result.getContent().toString(), UserView.class);
  1008. }
  1009. }
  1010. }
  1011. return null;
  1012. }
  1013. //
  1014. // /**
  1015. // * 设置hr账号
  1016. // *
  1017. // * @param user
  1018. // * @param detail
  1019. // * @return
  1020. // * @throws Exception
  1021. // */
  1022. // public static String setHrAccount(User user, UuzcUserSpaceDetail detail) throws Exception {
  1023. // String saveUrl = AccountConfig.getUserSaveUrl();
  1024. // saveUrl = saveUrl + "/setHrAccount";
  1025. // if (!StringUtils.isEmpty(saveUrl)) {
  1026. // JSONObject formData = new JSONObject();
  1027. // if (detail != null) {
  1028. // formData = JSON.parseObject(JSON.toJSONString(detail));
  1029. // }
  1030. // if (null != user) {
  1031. // formData.putAll(JSON.parseObject(JSON.toJSONString(user)));
  1032. // }
  1033. // ResponseWrap response = HttpUtil.doPost(saveUrl, formData);
  1034. // if (!response.isSuccess())
  1035. // throw new Exception(response.getContent());
  1036. // else {
  1037. // return response.getContent();
  1038. // }
  1039. // }
  1040. // return null;
  1041. // }
  1042. //
  1043. // /**
  1044. // * 根据营业执照获取众创需要的企业资料
  1045. // *
  1046. // * @param businessCode
  1047. // * @return
  1048. // * @throws Exception
  1049. // */
  1050. // public static UuzcUserSpaceDetail getUuzcUserSpaceDetail(String businessCode) throws Exception {
  1051. // String saveUrl = AccountConfig.getUserSaveUrl();
  1052. // if (!StringUtils.isEmpty(saveUrl)) {
  1053. // ResponseWrap response = HttpUtil.doGet(saveUrl + "/uuzcSpace" , new ModelMap("businessCode", businessCode));
  1054. // if (!response.isSuccess())
  1055. // throw new Exception(response.getContent());
  1056. // else {
  1057. // return JSONObject.parseObject(response.getContent(), UuzcUserSpaceDetail.class);
  1058. // }
  1059. // }
  1060. // return null;
  1061. // }
  1062. //
  1063. // /**
  1064. // * 判断当前企业是否设置了hr
  1065. // *
  1066. // * @param businessCode
  1067. // * @return
  1068. // * @throws Exception
  1069. // */
  1070. // public static String getHrAccount(String businessCode) throws Exception {
  1071. // String saveUrl = AccountConfig.getUserSaveUrl();
  1072. // if (!StringUtils.isEmpty(saveUrl)) {
  1073. // ResponseWrap response = HttpUtil.doGet(saveUrl + "/hrcount" , new ModelMap("businessCode", businessCode));
  1074. // if (!response.isSuccess())
  1075. // throw new Exception(response.getContent());
  1076. // else {
  1077. // return response.getContent();
  1078. // }
  1079. // }
  1080. // return null;
  1081. // }
  1082. //
  1083. // /**
  1084. // * 获取当前企业的HR信息
  1085. // *
  1086. // * @param businessCode
  1087. // * @return
  1088. // * @throws Exception
  1089. // */
  1090. // public static User getHrInfo(String businessCode) throws Exception {
  1091. // String saveUrl = AccountConfig.getUserSaveUrl();
  1092. // if (!StringUtils.isEmpty(saveUrl)) {
  1093. // ResponseWrap response = HttpUtil.doGet(saveUrl + "/hrInfo" , new ModelMap("businessCode", businessCode));
  1094. // if (!response.isSuccess())
  1095. // throw new Exception(response.getContent());
  1096. // else {
  1097. // return JSONObject.parseObject(response.getContent(), User.class);
  1098. // }
  1099. // }
  1100. // return null;
  1101. // }
  1102. //
  1103. // /**
  1104. // * 获取当前企业人员账号信息
  1105. // *
  1106. // * @param businessCode
  1107. // * @return
  1108. // * @throws Exception
  1109. // */
  1110. // public static List<User> getEmployees(String businessCode) throws Exception {
  1111. // String saveUrl = AccountConfig.getUserSaveUrl();
  1112. // saveUrl = saveUrl + "/employees";
  1113. // if (!StringUtils.isEmpty(saveUrl)) {
  1114. // ResponseWrap response = HttpUtil.doPost(saveUrl, new ModelMap("businessCode", businessCode));
  1115. // if (!response.isSuccess())
  1116. // throw new Exception(response.getContent());
  1117. // else {
  1118. // return JSON.parseArray(response.getContent(), User.class);
  1119. // }
  1120. // }
  1121. // return null;
  1122. // }
  1123. //
  1124. // /**
  1125. // * 保存用户密保问题
  1126. // * @param questions
  1127. // * @throws Exception
  1128. // */
  1129. // public static void saveUserQuestions(List<UserQuestion> questions) throws Exception {
  1130. // String saveUrl = AccountConfig.getUserSaveUrl();
  1131. // saveUrl = saveUrl + "/save/question";
  1132. // if (!StringUtils.isEmpty(saveUrl)) {
  1133. // ResponseWrap res = HttpUtil.doPost(saveUrl, new ModelMap("question", questions));
  1134. // if (!res.isSuccess()) {
  1135. // throw new Exception(res.getContent());
  1136. // }
  1137. // }
  1138. // }
  1139. //
  1140. // /**
  1141. // * 保存用户密保问题
  1142. // * @param userQuestion
  1143. // * @throws Exception
  1144. // */
  1145. // public static void saveUserQuestion(UserQuestion userQuestion) throws Exception {
  1146. // String saveUrl = AccountConfig.getUserSaveUrl();
  1147. // saveUrl = saveUrl + "/save/question";
  1148. // if (!StringUtils.isEmpty(saveUrl)) {
  1149. // JSONObject formData = JSON.parseObject(JSON.toJSONString(userQuestion));
  1150. // formData.put("_count", "one");
  1151. // ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
  1152. // if (!res.isSuccess()) {
  1153. // throw new Exception(res.getContent());
  1154. // }
  1155. // }
  1156. // }
  1157. /**
  1158. * 根据imId获取用户userUU(没有则返回null)
  1159. */
  1160. public static UserView getUserByImId (Long imId) throws Exception {
  1161. String url = AccountConfig.getUserSaveUrl();
  1162. UserView user = null;
  1163. if (!StringUtils.isEmpty(url)) {
  1164. HttpUtil.ResponseWrap res = HttpUtil.doGet(url,
  1165. new ModelMap("_operate", "getUserByImId")
  1166. .addAttribute("imId", imId));
  1167. if (!res.isSuccess()) {
  1168. throw new Exception(res.getContent());
  1169. } else {
  1170. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1171. if (!result.isSuccess()) {
  1172. throw new Exception(result.getErrMsg());
  1173. } else if (result.getContent() != null) {
  1174. user = JSON.parseObject(result.getContent().toString(), UserView.class);
  1175. }
  1176. }
  1177. }
  1178. return user;
  1179. }
  1180. /**
  1181. * 根据营业执照号分页查找该企业的用户
  1182. * @param spaceUU
  1183. * @param pageNumber
  1184. * @param pageSize
  1185. * @return
  1186. * @throws Exception
  1187. */
  1188. public static Page<UserView> findUsersByBusinessCode(Long spaceUU, int pageNumber, int pageSize) throws Exception {
  1189. String url = AccountConfig.getUserSaveUrl();
  1190. if (!StringUtils.isEmpty(url)) {
  1191. url = url + "/find/member";
  1192. String appId = SSOHelper.getSSOService().getConfig().getAppName();
  1193. ModelMap data = new ModelMap();
  1194. data.put("spaceUU", spaceUU);
  1195. data.put("appId", appId);
  1196. data.put("page", pageNumber);
  1197. data.put("size", pageSize);
  1198. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1199. if (!res.isSuccess()) {
  1200. throw new Exception(res.getContent());
  1201. } else {
  1202. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1203. if (!result.isSuccess()) {
  1204. throw new Exception(result.getErrMsg());
  1205. } else if (result.getContent() != null) {
  1206. return JSON.parseObject(result.getContent().toString(), new TypeReference<Page<UserView>>() {});
  1207. }
  1208. }
  1209. }
  1210. return null;
  1211. }
  1212. /**
  1213. * 根据营业执照号分页查找该企业的用户
  1214. * @param spaceUU
  1215. * @param userUU
  1216. * @return
  1217. * @throws Exception
  1218. */
  1219. public static String getToken(Long spaceUU, Long userUU) throws Exception {
  1220. String url = AccountConfig.getUserSaveUrl();
  1221. if (!StringUtils.isEmpty(url)) {
  1222. url = url + "/getToken";
  1223. String appId = SSOHelper.getSSOService().getConfig().getAppName();
  1224. ModelMap data = new ModelMap();
  1225. data.put("spaceUU", spaceUU);
  1226. data.put("userUU", userUU);
  1227. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1228. if (!res.isSuccess()) {
  1229. throw new Exception(res.getContent());
  1230. } else {
  1231. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1232. if (!result.isSuccess()) {
  1233. throw new Exception(result.getErrMsg());
  1234. } else if (result.getContent() != null) {
  1235. return result.getContent().toString();
  1236. }
  1237. }
  1238. }
  1239. return null;
  1240. }
  1241. public static Page<ApplyUserSpaceView> findApplyAllToMall(Long speaceUU, int page, int size, Integer status, String keyword) throws Exception {
  1242. String url = AccountConfig.getSpaceSaveUrl();
  1243. if (!StringUtils.isEmpty(url)) {
  1244. url = url + "/apply/info/mall";
  1245. String appId = SSOHelper.getSSOService().getConfig().getAppName();
  1246. ModelMap data = new ModelMap();
  1247. data.put("speaceUU", speaceUU);
  1248. data.put("page", page);
  1249. data.put("size", size);
  1250. data.put("status", status);
  1251. data.put("keyword", keyword);
  1252. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1253. if (!res.isSuccess()) {
  1254. throw new Exception(res.getContent());
  1255. } else {
  1256. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1257. if (!result.isSuccess()) {
  1258. throw new Exception(result.getErrMsg());
  1259. } else if (result.getContent() != null) {
  1260. return JSON.parseObject(result.getContent().toString(), new TypeReference<Page<ApplyUserSpaceView>>() {});
  1261. }
  1262. }
  1263. }
  1264. return null;
  1265. }
  1266. public static String auditApply(Long userUU, Long id, Integer status) throws Exception {
  1267. String url = AccountConfig.getSpaceSaveUrl();
  1268. if (!StringUtils.isEmpty(url)) {
  1269. url = url + "/audit/apply";
  1270. String appId = SSOHelper.getSSOService().getConfig().getAppName();
  1271. ModelMap data = new ModelMap();
  1272. data.put("userUU", userUU);
  1273. data.put("id", id);
  1274. data.put("status", status);
  1275. HttpUtil.ResponseWrap res = HttpUtil.doPost(url, data);
  1276. if (!res.isSuccess()) {
  1277. throw new Exception(res.getContent());
  1278. } else {
  1279. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1280. if (!result.isSuccess()) {
  1281. throw new Exception(result.getErrMsg());
  1282. } else if (result.getContent() != null) {
  1283. return result.getContent().toString();
  1284. }
  1285. }
  1286. }
  1287. return null;
  1288. }
  1289. public static UserView findUserByMobile(String mobile) throws Exception {
  1290. String url = AccountConfig.getUserSaveUrl();
  1291. if (!StringUtils.isEmpty(url)) {
  1292. url = url + "/info/mobile";
  1293. ModelMap data = new ModelMap();
  1294. data.put("mobile", mobile);
  1295. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1296. if (!res.isSuccess()) {
  1297. throw new Exception(res.getContent());
  1298. } else {
  1299. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1300. if (!result.isSuccess()) {
  1301. throw new Exception(result.getErrMsg());
  1302. } else if (result.getContent() != null) {
  1303. return JSON.parseObject(result.getContent().toString(), UserView.class);
  1304. }
  1305. }
  1306. }
  1307. return null;
  1308. }
  1309. public static Map<String, Object> getUserInfo(Long userUU, Long spaceUU) throws Exception {
  1310. String url = AccountConfig.getUserSaveUrl();
  1311. if (!StringUtils.isEmpty(url)) {
  1312. url = url + "/info/userUU";
  1313. ModelMap data = new ModelMap();
  1314. data.put("userUU", userUU);
  1315. data.put("spaceUU", spaceUU);
  1316. HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
  1317. if (!res.isSuccess()) {
  1318. throw new Exception(res.getContent());
  1319. } else {
  1320. ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
  1321. if (!result.isSuccess()) {
  1322. throw new Exception(result.getErrMsg());
  1323. } else if (result.getContent() != null) {
  1324. return JSON.parseObject(result.getContent().toString());
  1325. }
  1326. }
  1327. }
  1328. return null;
  1329. }
  1330. }