|
@@ -1,6 +1,8 @@
|
|
|
package com.xuqm.server.appmanager.controller.sys.v1;
|
|
|
|
|
|
-import cn.org.bjca.trust.java.imserver.common.TimeHelper;
|
|
|
+import com.xuqm.server.appmanager.common.JWTHelper;
|
|
|
+import com.xuqm.server.appmanager.common.TimeHelper;
|
|
|
+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;
|
|
@@ -9,11 +11,9 @@ 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.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Random;
|
|
|
|
|
|
@RestController
|
|
@@ -29,9 +29,7 @@ public class TenantV1Controller {
|
|
|
|
|
|
@PostMapping("/tenant/create")
|
|
|
public HttpResult<String> tenantCreate(@RequestBody TenantUserEntity tenant) throws Exception {
|
|
|
- if (null == tenant.getUserPhone() ||
|
|
|
- null == tenant.getUserEmail() ||
|
|
|
- null == tenant.getUserPwd()) {
|
|
|
+ if (null == tenant.getUserPhone() || null == tenant.getUserEmail() || null == tenant.getUserPwd()) {
|
|
|
return new HttpResult<>(201, "参数错误", null);
|
|
|
} else {
|
|
|
TenantUserEntity u = tenantUserRepository.findFirstByUserEmailOrUserPhone(tenant.getUserEmail(), tenant.getUserPhone());
|
|
@@ -53,23 +51,42 @@ public class TenantV1Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/app/create")
|
|
|
- public HttpResult<String> appCreate(@RequestBody ApplicationEntity application) throws Exception {
|
|
|
- if (null == application.getAppName() ||
|
|
|
- null == application.getTenantNo()) {
|
|
|
+ @PostMapping("/manager/create")
|
|
|
+ public HttpResult<String> appCreate(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+ if (null == application.getAppName() || null == application.getPackageName()) {
|
|
|
return new HttpResult<>(201, "参数错误", null);
|
|
|
} else {
|
|
|
- ApplicationEntity app = applicationRepository.findFirstByAppNameAndTenantNo(application.getAppName(), application.getTenantNo());
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
+ }
|
|
|
+ ApplicationEntity app = applicationRepository.findFirstByAppNameAndTenantNo(application.getAppName(), userInfo.getTenantNo());
|
|
|
if (null != app) return new HttpResult<>(201, "已创建相关类型的同名应用", null);
|
|
|
app = new ApplicationEntity();
|
|
|
- app.setTenantNo(application.getTenantNo());
|
|
|
+ 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, "创建成功", "创建成功");
|
|
|
+ return new HttpResult<>(200, "创建成功", app.getAppId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/manager/list")
|
|
|
+ public HttpResult<List<ApplicationEntity>> appList(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ List<ApplicationEntity> apps = applicationRepository.findAllByTenantNo(userInfo.getTenantNo());
|
|
|
+
|
|
|
+ return new HttpResult<>(200, "成功", apps);
|
|
|
}
|
|
|
|
|
|
}
|