AccountUtils.java 39 KB

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