AccountUtils.java 37 KB

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