|
@@ -1,20 +1,21 @@
|
|
|
package com.xuqm.server.appmanager.controller.sys.v1;
|
|
|
|
|
|
+import com.xuqm.server.appmanager.common.CommonHelper;
|
|
|
import com.xuqm.server.appmanager.common.JWTHelper;
|
|
|
-import com.xuqm.server.appmanager.common.TimeHelper;
|
|
|
+import com.xuqm.server.appmanager.controller.sys.v1.data.TenantAddUserData;
|
|
|
+import com.xuqm.server.appmanager.controller.sys.v1.data.TenantChangeAdminData;
|
|
|
+import com.xuqm.server.appmanager.controller.sys.v1.data.TenantCreateData;
|
|
|
+import com.xuqm.server.appmanager.controller.sys.v1.data.TenantDelUserData;
|
|
|
import com.xuqm.server.appmanager.entitys.UserInfo;
|
|
|
-import com.xuqm.server.appmanager.entitys.sys.v1.ApplicationEntity;
|
|
|
import com.xuqm.server.appmanager.entitys.sys.v1.TenantEntity;
|
|
|
import com.xuqm.server.appmanager.entitys.sys.v1.TenantUserEntity;
|
|
|
import com.xuqm.server.appmanager.http.HttpResult;
|
|
|
-import com.xuqm.server.appmanager.repository.sys.v1.ApplicationRepository;
|
|
|
import com.xuqm.server.appmanager.repository.sys.v1.TenantRepository;
|
|
|
import com.xuqm.server.appmanager.repository.sys.v1.TenantUserRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("tenant/v1")
|
|
@@ -24,11 +25,9 @@ public class TenantV1Controller {
|
|
|
private TenantRepository tenantRepository;
|
|
|
@Autowired
|
|
|
private TenantUserRepository tenantUserRepository;
|
|
|
- @Autowired
|
|
|
- private ApplicationRepository applicationRepository;
|
|
|
|
|
|
- @PostMapping("/tenant/create")
|
|
|
- public HttpResult<String> tenantCreate(@RequestBody TenantUserEntity tenant) throws Exception {
|
|
|
+ @PostMapping("/create")
|
|
|
+ public HttpResult<String> tenantCreate(@RequestBody TenantCreateData tenant) throws Exception {
|
|
|
if (null == tenant.getUserPhone() || null == tenant.getUserEmail() || null == tenant.getUserPwd()) {
|
|
|
return new HttpResult<>(201, "参数错误", null);
|
|
|
} else {
|
|
@@ -38,12 +37,14 @@ public class TenantV1Controller {
|
|
|
u.setUserEmail(tenant.getUserEmail());
|
|
|
u.setUserPhone(tenant.getUserPhone());
|
|
|
u.setUserPwd(tenant.getUserPwd());
|
|
|
- u.setUserId(TimeHelper.getTimeString("yyyyMMddHHmm") + (new Random().nextInt(899999999) + 100000000));
|
|
|
- u.setTenantNo(TimeHelper.getTimeString("yyyyMMddHHmm") + (new Random().nextInt(899999999) + 100000000));
|
|
|
+ u.setUserName(tenant.getUserName());
|
|
|
+ u.setUserId(CommonHelper.getRandomId());
|
|
|
+ u.setTenantNo(CommonHelper.getRandomId());
|
|
|
tenantUserRepository.save(u);
|
|
|
TenantEntity t = new TenantEntity();
|
|
|
t.setUserId(u.getUserId());
|
|
|
t.setTenantNo(u.getTenantNo());
|
|
|
+ t.setTenantName(tenant.getTenantName());
|
|
|
tenantRepository.save(t);
|
|
|
|
|
|
return new HttpResult<>(200, "创建成功", "创建成功");
|
|
@@ -51,42 +52,76 @@ public class TenantV1Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/manager/create")
|
|
|
- public HttpResult<String> appCreate(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
- if (null == application.getAppName() || null == application.getPackageName()) {
|
|
|
+ @PostMapping("/changeAdmin")
|
|
|
+ public HttpResult<String> changeAdmin(@RequestBody TenantChangeAdminData data, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
+ }
|
|
|
+ if (null == data.getUserId()) {
|
|
|
return new HttpResult<>(201, "参数错误", null);
|
|
|
} else {
|
|
|
- UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
- if (null == userInfo) {
|
|
|
- return new HttpResult<>(401, "登录失效", null);
|
|
|
+ TenantEntity tenant = tenantRepository.findFirstByTenantNo(userInfo.getTenantNo());
|
|
|
+ if (null == tenant) return new HttpResult<>(201, "查找租户信息失败", null);
|
|
|
+ if (!Objects.equals(tenant.getUserId(), userInfo.getUserId())) {
|
|
|
+ return new HttpResult<>(201, "请用管理员账号操作", null);
|
|
|
}
|
|
|
- ApplicationEntity app = applicationRepository.findFirstByAppNameAndTenantNo(application.getAppName(), userInfo.getTenantNo());
|
|
|
- if (null != app) return new HttpResult<>(201, "已创建相关类型的同名应用", null);
|
|
|
- app = new ApplicationEntity();
|
|
|
- app.setTenantNo(userInfo.getTenantNo());
|
|
|
- app.setAppName(application.getAppName());
|
|
|
- app.setPackageName(application.getPackageName());
|
|
|
- app.setDownloadUrl(application.getDownloadUrl());
|
|
|
- app.setAppId(TimeHelper.getTimeString("yyyyMMddHHmm") + (new Random().nextInt(899999999) + 100000000));
|
|
|
- applicationRepository.save(app);
|
|
|
-
|
|
|
- return new HttpResult<>(200, "创建成功", app.getAppId());
|
|
|
+ tenant.setUserId(data.getUserId());
|
|
|
+ tenantRepository.save(tenant);
|
|
|
+
|
|
|
+ return new HttpResult<>(200, "修改成功", "修改成功");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/manager/list")
|
|
|
- public HttpResult<List<ApplicationEntity>> appList(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+ @PostMapping("/addUser")
|
|
|
+ public HttpResult<String> addUser(@RequestBody TenantAddUserData data, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
+ }
|
|
|
+ if (null == data.getUserPhone() || null == data.getUserEmail() || null == data.getUserPwd()) {
|
|
|
+ return new HttpResult<>(201, "参数错误", null);
|
|
|
+ } else {
|
|
|
+ TenantUserEntity u = tenantUserRepository.findFirstByUserEmailOrUserPhone(data.getUserEmail(), data.getUserPhone());
|
|
|
+ if (null != u) return new HttpResult<>(201, "邮箱或手机号重复", null);
|
|
|
+ u = new TenantUserEntity();
|
|
|
+ u.setUserEmail(data.getUserEmail());
|
|
|
+ u.setUserPhone(data.getUserPhone());
|
|
|
+ u.setUserPwd(data.getUserPwd());
|
|
|
+ u.setUserName(data.getUserName());
|
|
|
+ u.setUserId(CommonHelper.getRandomId());
|
|
|
+ u.setTenantNo(userInfo.getTenantNo());
|
|
|
+ tenantUserRepository.save(u);
|
|
|
+
|
|
|
+ return new HttpResult<>(200, "添加成功", "添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ @PostMapping("/delUser")
|
|
|
+ public HttpResult<String> delUser(@RequestBody TenantDelUserData data, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
if (null == userInfo) {
|
|
|
return new HttpResult<>(401, "登录失效", null);
|
|
|
}
|
|
|
+ if (null == data.getUserId()) {
|
|
|
+ return new HttpResult<>(201, "参数错误", null);
|
|
|
+ } else {
|
|
|
+ TenantEntity tenant = tenantRepository.findFirstByTenantNo(userInfo.getTenantNo());
|
|
|
+ if (null == tenant) return new HttpResult<>(201, "查找租户信息失败", null);
|
|
|
+ if (!Objects.equals(tenant.getUserId(), userInfo.getUserId())) {
|
|
|
+ return new HttpResult<>(201, "请用管理员账号操作", null);
|
|
|
+ }
|
|
|
+ if (!Objects.equals(tenant.getUserId(), data.getUserId())) {
|
|
|
+ return new HttpResult<>(201, "无法删除管理员账号", null);
|
|
|
+ }
|
|
|
|
|
|
+ tenantUserRepository.delete(tenantUserRepository.findFirstByUserId(data.getUserId()));
|
|
|
|
|
|
- List<ApplicationEntity> apps = applicationRepository.findAllByTenantNo(userInfo.getTenantNo());
|
|
|
+ return new HttpResult<>(200, "删除成功", "删除成功");
|
|
|
+ }
|
|
|
|
|
|
- return new HttpResult<>(200, "成功", apps);
|
|
|
}
|
|
|
|
|
|
}
|