|
|
@@ -0,0 +1,115 @@
|
|
|
+package com.uas.sso.erp.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.sso.entity.User;
|
|
|
+import com.uas.sso.entity.Userspace;
|
|
|
+import com.uas.sso.service.UserService;
|
|
|
+import com.uas.sso.service.UserspaceService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wangmh
|
|
|
+ * @create 2018-04-27 8:54
|
|
|
+ * @desc 企业管理接口(erp接口)
|
|
|
+ **/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/userspace/erp")
|
|
|
+public class ErpUserSpaceManageController extends ErpBaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserspaceService userspaceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ private final String appId = "uas";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新erp企业信息接口
|
|
|
+ * @param data 企业信息json字符串
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/updateSpace", method = RequestMethod.POST)
|
|
|
+ public ModelMap updateSpace(@RequestParam String data) throws UnsupportedEncodingException {
|
|
|
+ Userspace userspace = JSON.parseObject(URLDecoder.decode(data, "UTF-8"), Userspace.class);
|
|
|
+ User admin = userspace.getAdmin();
|
|
|
+ // 先把企业名称、邮箱、管理员名称解码
|
|
|
+ userspace.setSpaceName(URLDecoder.decode(userspace.getSpaceName(), "UTF-8"));
|
|
|
+
|
|
|
+ Userspace oldSpace = null;
|
|
|
+ // 根据uu号查询企业
|
|
|
+ if (userspace.getSpaceUU() != null) {
|
|
|
+ oldSpace = userspaceService.findOne(userspace.getSpaceUU());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据uu号找到了企业信息,则需要校验秘钥
|
|
|
+ if (oldSpace != null) {
|
|
|
+ checkRequest(oldSpace.getAccessSecret());
|
|
|
+ oldSpace.setSpaceName(userspace.getSpaceName());
|
|
|
+ oldSpace.setBusinessCode(userspace.getBusinessCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果uu号找不到,再根据企业名称和营业执照号查询
|
|
|
+ if (oldSpace == null && !StringUtils.isEmpty(userspace.getSpaceName())) {
|
|
|
+ oldSpace = userspaceService.findBySpaceName(userspace.getSpaceName());
|
|
|
+ if (oldSpace != null && !StringUtils.isEmpty(userspace.getBusinessCode()) && !userspace.getBusinessCode().equals(oldSpace.getBusinessCode())) {
|
|
|
+ return error("企业名称(" + userspace.getSpaceName() + ")已被注册,营业执照号为:" + oldSpace.getBusinessCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (oldSpace == null && !StringUtils.isEmpty(userspace.getBusinessCode())) {
|
|
|
+ oldSpace = userspaceService.findByBusinessCode(userspace.getBusinessCode());
|
|
|
+ if (oldSpace != null && !StringUtils.isEmpty(userspace.getSpaceName()) && !userspace.getSpaceName().equals(oldSpace.getSpaceName())) {
|
|
|
+ return error("营业执照号(" + userspace.getBusinessCode() + ")已被注册,企业名称为:" + oldSpace.getSpaceName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oldSpace == null) {
|
|
|
+ return error("该企业未被注册,请到优软云进行注册之后再操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (admin.getUserUU() == null) {
|
|
|
+ // uu号不存在,则更加手机号查询,用不不存在则注册
|
|
|
+ if (StringUtils.isEmpty(admin.getMobile())) {
|
|
|
+ return error("管理员手机号不能为空");
|
|
|
+ }
|
|
|
+ checkMobile(admin.getMobile(), null);
|
|
|
+ User oldAdmin = userService.findByMobile(admin.getMobile());
|
|
|
+ if (oldAdmin == null) {
|
|
|
+ admin = userService.register(admin);
|
|
|
+ } else {
|
|
|
+ admin = oldAdmin;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果管理员的uu号和传过来的 管理员不一致,则更换
|
|
|
+ if (!admin.getUserUU().equals(oldSpace.getAdminUU())) {
|
|
|
+ userspaceService.changeAdmin(appId, oldSpace, admin);
|
|
|
+ }
|
|
|
+
|
|
|
+ Userspace newSpace = oldSpace;
|
|
|
+ newSpace.setWebsite(userspace.getWebsite());
|
|
|
+ if (StringUtils.isEmpty(newSpace.getAccessSecret())) {
|
|
|
+ newSpace.setAccessSecret(UUID.randomUUID().toString().replaceAll("\\-", ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ newSpace = userspaceService.save(newSpace);
|
|
|
+
|
|
|
+ // 返回用户信息
|
|
|
+ ModelMap returnData = new ModelMap();
|
|
|
+ returnData.put("spaceUU", newSpace.getSpaceUU());
|
|
|
+ returnData.put("businessCode", newSpace.getBusinessCode());
|
|
|
+ returnData.put("accessSecret", newSpace.getAccessSecret());
|
|
|
+ returnData.put("adminUU", newSpace.getAdminUU());
|
|
|
+ return success(returnData);
|
|
|
+ }
|
|
|
+}
|