|
|
@@ -356,282 +356,8 @@ public class UserspaceManagerController extends BaseController {
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 同步旧企业数据到账户中心
|
|
|
- *
|
|
|
- * @param spaceUU 企业uu号,为空则同步所有
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/saveOldUserSpaces/{spaceUU}")
|
|
|
- public ModelMap syncOldUserSpaces(@PathVariable Long spaceUU, @RequestParam(defaultValue = "1") int pageNumber,
|
|
|
- @RequestParam(defaultValue = "20") int pageSize, @RequestParam(defaultValue = "false") boolean isAll) {
|
|
|
- // 由于旧数据问题,记录重复的企业名称和营业执照号
|
|
|
- Map<String, Integer> repeatSpaceName = new HashMap<>();
|
|
|
- Map<String, Integer> repeatBusinessCode = new HashMap<>();
|
|
|
-
|
|
|
- Userspace userspace;
|
|
|
- com.uas.sso.support.Page<UserSpaceDetail> page = null;
|
|
|
- // 循环分页请求,如果是最后一页则退出循环
|
|
|
- while (page == null || !page.isLast()) {
|
|
|
- // 获取分页信息
|
|
|
- page = getUserSpace(pageNumber++, pageSize);
|
|
|
-
|
|
|
- // 循环遍历企业信息并保存
|
|
|
- int i = 1;
|
|
|
- for (UserSpaceDetail detail : page.getContent()) {
|
|
|
- try {
|
|
|
- userspace = userspaceService.findByBusinessCode(detail.getBusinessCode());
|
|
|
- if (userspace != null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- userspace = saveUserspace(detail);
|
|
|
- System.out.println(page.getNumber() + "\t" + page.getSize() + "\t" + i++ + "\t" + userspace.getSpaceName() + "\t" + userspace.getBusinessCode());
|
|
|
- } catch (Exception e) {
|
|
|
- writerToFile(page.getNumber() + "\t" + page.getSize() + "\t" + i++ + "\t" + detail.getName() + "\t" + detail.getBusinessCode(), e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- spaceNameUnique();
|
|
|
- if (!isAll) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return success();
|
|
|
- }
|
|
|
-
|
|
|
- private Userspace saveUserspace(UserSpaceDetail detail) throws Exception {
|
|
|
- Userspace userspace;
|
|
|
- userspace = new Userspace();
|
|
|
- // 设置企业秘钥
|
|
|
- userspace.setAccessSecret(getAccessSecret(detail.getBusinessCode()));
|
|
|
- // 设置管理员uu号
|
|
|
- User user = userService.findByMobile(detail.getAdminTel());
|
|
|
- userspace.setAdminUU(user == null ? null : user.getUserUU());
|
|
|
- userspace.setBusinessCode(detail.getBusinessCode());
|
|
|
- userspace.setBusinessCodeImage(detail.getBusinessCodeImage());
|
|
|
- userspace.setCorporation(detail.getCorporation());
|
|
|
- userspace.setDomain(detail.getDomain());
|
|
|
- userspace.setLogoImage(detail.getLogoImage());
|
|
|
- userspace.setProfession(detail.getProfession());
|
|
|
- userspace.setRegAddress(detail.getAddress());
|
|
|
- userspace.setRegCity(detail.getCity());
|
|
|
- userspace.setRegDistrict(detail.getDistrict());
|
|
|
- userspace.setRegProvince(detail.getProvince());
|
|
|
- userspace.setRegStreet(detail.getStreet());
|
|
|
- userspace.setRegisterDate(detail.getRegisterDate() == null ? null : new Timestamp(detail.getRegisterDate()));
|
|
|
- userspace.setSpaceName(detail.getName());
|
|
|
- // 设置企业uu号
|
|
|
- userspace.setSpaceUU(getSpaceUU(detail.getBusinessCode(), detail.getName()));
|
|
|
- userspace.setTags(detail.getTags());
|
|
|
- userspace.setTelephone(detail.getTel());
|
|
|
- userspace.setValidCode((short) Status.AUTHENTICATED.getCode());
|
|
|
- if (userspace.getSpaceUU() == null) {
|
|
|
- throw new Exception("无uu号");
|
|
|
- }
|
|
|
-// userspace.setWebsite(getWebsite());
|
|
|
-
|
|
|
- // 设置企业用户
|
|
|
- addUsersByBusinessCode(userspace);
|
|
|
-
|
|
|
- // 设置默认应用
|
|
|
- addDefaultApp(userspace);
|
|
|
- userspaceService.save(userspace);
|
|
|
- return userspace;
|
|
|
- }
|
|
|
-
|
|
|
- private void addDefaultApp(Userspace userspace) throws Exception {
|
|
|
- if (userspace.getApps() == null) {
|
|
|
- userspace.setApps(new ArrayList<App>());
|
|
|
- }
|
|
|
- String url = "http://10.1.51.50:8080/api/userspace";
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data.put("businessCode", userspace.getBusinessCode());
|
|
|
- data.put("_operate", "getapp");
|
|
|
- HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
|
|
|
- if (!res.isSuccess()) {
|
|
|
- throw new Exception(res.getContent());
|
|
|
- } else {
|
|
|
- ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
|
|
|
- if (!result.isSuccess()) {
|
|
|
- throw new Exception(result.getErrMsg());
|
|
|
- } else if (result.getContent() != null) {
|
|
|
- List<UserSpace> userSpaceList = JSON.parseArray(result.getContent().toString(), UserSpace.class);
|
|
|
- for (int i = 0; i < userSpaceList.size(); i++) {
|
|
|
- App app = appService.findOne(userSpaceList.get(i).getAppId());
|
|
|
- if (app != null && !userspace.getApps().contains(app)) {
|
|
|
- userspace.getApps().add(app);
|
|
|
- }
|
|
|
- }
|
|
|
- App app = appService.findOne("sso");
|
|
|
- if (!userspace.getApps().contains(app)) {
|
|
|
- userspace.getApps().add(app);
|
|
|
- }
|
|
|
- app = appService.findOne("mall");
|
|
|
- if (!userspace.getApps().contains(app)) {
|
|
|
- userspace.getApps().add(app);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void addUsersByBusinessCode(Userspace userspace) throws Exception {
|
|
|
- if (userspace.getUsers() == null) {
|
|
|
- userspace.setUsers(new ArrayList<User>());
|
|
|
- }
|
|
|
- int pageNumber = 1;
|
|
|
- int pageSize = 20;
|
|
|
- com.uas.sso.support.Page<com.uas.account.entity.User> page;
|
|
|
- String url = "http://10.1.51.50:8080/api/user";
|
|
|
- url = url + "/findByBusinessCode";
|
|
|
- do {
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data.put("businessCode", userspace.getBusinessCode());
|
|
|
- data.put("appId", "b2b");
|
|
|
- data.put("pageNumber", pageNumber++);
|
|
|
- data.put("pageSize", pageSize);
|
|
|
- HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
|
|
|
- if (!res.isSuccess()) {
|
|
|
- throw new Exception(res.getContent());
|
|
|
- } else {
|
|
|
- page = JSON.parseObject(res.getContent(), new TypeReference<com.uas.sso.support.Page<com.uas.account.entity.User>>() {
|
|
|
- });
|
|
|
- List<com.uas.account.entity.User> users = page.getContent();
|
|
|
- for (int i = 0; i < users.size(); i++) {
|
|
|
- User user = users.get(i).getDialectUID() == null ? userService.findByMobile(users.get(i).getUid()) : userService.findOne(Long.valueOf(users.get(i).getDialectUID()));
|
|
|
- if (user != null && !userspace.getUsers().contains(user)) {
|
|
|
- userspace.getUsers().add(user);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } while (page == null || !page.isLast());
|
|
|
- }
|
|
|
-
|
|
|
- private Long getSpaceUU(String businessCode, String name) throws Exception {
|
|
|
- if (StringUtils.isEmpty(businessCode)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- String url = "http://10.1.51.50:8080/api/userspace/info";
|
|
|
- if (!StringUtils.isEmpty(businessCode)) {
|
|
|
- businessCode = businessCode.trim();
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(name)) {
|
|
|
- name = name.trim();
|
|
|
- }
|
|
|
-// url = url + "/" + URLEncoder.encode(businessCode, "UTF-8") + "/" + URLEncoder.encode(name, "UTF-8");
|
|
|
- HttpUtil.ResponseWrap res = null;
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data.put("businessCode", businessCode);
|
|
|
- data.put("name", name);
|
|
|
- res = HttpUtil.doGet(url, data);
|
|
|
- if (res.isSuccess() && !StringUtils.isEmpty(res.getContent())) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(res.getContent());
|
|
|
- if (jsonObject.containsKey("dialectUID")) {
|
|
|
- return Long.valueOf(jsonObject.get("dialectUID").toString());
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public com.uas.sso.support.Page<UserSpaceDetail> getUserSpace(@RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "20") int pageSize) {
|
|
|
- com.uas.sso.support.Page<UserSpaceDetail> page = null;
|
|
|
- String url = "http://10.1.51.50:8080/api/partners";
|
|
|
- if (!StringUtils.isEmpty(url)) {
|
|
|
- HttpUtil.ResponseWrap res = null;
|
|
|
- try {
|
|
|
- ModelMap data = new ModelMap("_operate", "getUserSpaces");
|
|
|
- data.put("pageNumber", Integer.valueOf(pageNumber));
|
|
|
- data.put("pageSize", Integer.valueOf(pageSize));
|
|
|
- res = HttpUtil.doGet(url, data);
|
|
|
- if (res.isSuccess()) {
|
|
|
- return JSON.parseObject(res.getContent(), new TypeReference<com.uas.sso.support.Page<UserSpaceDetail>>() {
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从b2b获取erp企业秘钥
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/saveAccessSecret/{businessCode}")
|
|
|
- public ModelMap saveAccessSecret(@PathVariable String businessCode) throws UnsupportedEncodingException {
|
|
|
- if (!StringUtils.isEmpty(businessCode)) {
|
|
|
- getAccessSecret(businessCode);
|
|
|
- }
|
|
|
- return success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从b2b获取密钥
|
|
|
- *
|
|
|
- * @param businessCode 营业执照号
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getAccessSecret(String businessCode) throws UnsupportedEncodingException {
|
|
|
- String url = "http://10.1.51.50:8090/platform-b2b";
|
|
|
- url = url + "/account/enterprise/info/" + URLEncoder.encode(businessCode, "UTF-8");
|
|
|
- String accessSecret = null;
|
|
|
- try {
|
|
|
- HttpUtil.ResponseWrap responseWrap = HttpUtil.doGet(url);
|
|
|
- if (responseWrap.isSuccess()) {
|
|
|
- JSONObject enterprise = parseObject(responseWrap.getContent());
|
|
|
- accessSecret = (String) enterprise.get("accessSecret");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return accessSecret;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 写入日志
|
|
|
- *
|
|
|
- * @param businessCode 营业执照号
|
|
|
- * @param accessSecret 密钥
|
|
|
- */
|
|
|
- private void writerToFile(String businessCode, String accessSecret) {
|
|
|
- FileWriter fw = null;
|
|
|
- try {
|
|
|
- //如果文件存在,则追加内容;如果文件不存在,则创建文件
|
|
|
- File f = new File("logs/userspace.log");
|
|
|
- fw = new FileWriter(f, true);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- PrintWriter pw = new PrintWriter(fw);
|
|
|
- pw.println(businessCode + "\t" + accessSecret);
|
|
|
- pw.flush();
|
|
|
- try {
|
|
|
- fw.flush();
|
|
|
- pw.close();
|
|
|
- fw.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/spaceName/unique")
|
|
|
- public ModelMap spaceNameUnique() {
|
|
|
- List<String> repeatName = userspaceService.findRepeatName();
|
|
|
- for (String name : repeatName) {
|
|
|
- List<Userspace> userspaces = userspaceService.findAllBySpaceName(name);
|
|
|
- for (int i = 0; i < userspaces.size(); i++) {
|
|
|
- Userspace userspace = userspaces.get(i);
|
|
|
- userspace.setSpaceName(userspace.getSpaceName() + Const.REPEAT_SEPARATOR + (i + 1));
|
|
|
- userspaceService.save(userspace);
|
|
|
- }
|
|
|
- }
|
|
|
- return success();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 从其他应用注册企业信息
|
|
|
- *
|
|
|
* @param userspace 企业信息
|
|
|
*/
|
|
|
@RequestMapping(value = "/register/other", method = RequestMethod.POST)
|