|
@@ -0,0 +1,118 @@
|
|
|
+package com.qmth.ops.api.controller.admin;
|
|
|
+
|
|
|
+import com.qmth.boot.api.annotation.Aac;
|
|
|
+import com.qmth.boot.api.annotation.BOOL;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.boot.tools.device.DeviceInfo;
|
|
|
+import com.qmth.ops.api.constants.OpsApiConstants;
|
|
|
+import com.qmth.ops.api.dto.DeployForm;
|
|
|
+import com.qmth.ops.api.vo.CodeNameVO;
|
|
|
+import com.qmth.ops.api.vo.DeployPageVO;
|
|
|
+import com.qmth.ops.api.vo.DeployVO;
|
|
|
+import com.qmth.ops.api.vo.SuccessVO;
|
|
|
+import com.qmth.ops.biz.domain.Deploy;
|
|
|
+import com.qmth.ops.biz.domain.DeployMode;
|
|
|
+import com.qmth.ops.biz.query.DeployQuery;
|
|
|
+import com.qmth.ops.biz.service.AppService;
|
|
|
+import com.qmth.ops.biz.service.DeployService;
|
|
|
+import com.qmth.ops.biz.service.FileService;
|
|
|
+import com.qmth.ops.biz.service.LicenseService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/deploy")
|
|
|
+public class DeployController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeployService deployService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AppService appService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LicenseService licenseService;
|
|
|
+
|
|
|
+ @RequestMapping("/modes")
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public Object getModes() {
|
|
|
+ return Arrays.stream(DeployMode.values()).map(item -> new CodeNameVO(item.getCode(), item.getName())).toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/query")
|
|
|
+ public DeployPageVO query(DeployQuery query) {
|
|
|
+ return new DeployPageVO(deployService.query(query), appService);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/insert")
|
|
|
+ public DeployVO insert(@Validated(DeployForm.InsertGroup.class) @RequestBody DeployForm form) {
|
|
|
+ return new DeployVO(deployService.insert(form.build()), appService);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/update")
|
|
|
+ public DeployVO update(@Validated(DeployForm.UpdateGroup.class) @RequestBody DeployForm form) {
|
|
|
+ return new DeployVO(deployService.update(form.build()), appService);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/device/save")
|
|
|
+ public Object saveDevice(@RequestParam Long id, @RequestParam MultipartFile deviceInfo,
|
|
|
+ @RequestParam(required = false) String remark) throws Exception {
|
|
|
+ Deploy deploy = deployService.findById(id);
|
|
|
+ if (deploy != null) {
|
|
|
+ DeviceInfo info = licenseService.parseDeviceInfo(deviceInfo);
|
|
|
+ if (info == null) {
|
|
|
+ throw new ApiException(HttpStatus.BAD_REQUEST, 400200, "DeviceInfo parse faile", null);
|
|
|
+ }
|
|
|
+ String deviceId = info.uuid();
|
|
|
+ fileService.uploadDeviceInfo(deviceId, info);
|
|
|
+ deployService.bindDevice(id, deviceId, StringUtils.trimToEmpty(remark));
|
|
|
+ return new SuccessVO(true);
|
|
|
+ } else {
|
|
|
+ throw new ApiException(HttpStatus.BAD_REQUEST, 400100, "deploy unexists", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/device/delete")
|
|
|
+ public Object deleteDevice(@RequestParam Long id, @RequestParam String deviceId) throws Exception {
|
|
|
+ Deploy deploy = deployService.findById(id);
|
|
|
+ if (deploy != null) {
|
|
|
+ deployService.unbindDevice(appId, deviceId);
|
|
|
+ return new SuccessVO(true);
|
|
|
+ } else {
|
|
|
+ throw new ApiException(HttpStatus.BAD_REQUEST, 400100, "deploy unexists", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/device/list")
|
|
|
+ public Object listDevice(@RequestParam Long id) throws Exception {
|
|
|
+ return deployService.listDevice(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/device/info")
|
|
|
+ public Object getDeviceInfo(@RequestParam String deviceId) throws Exception {
|
|
|
+ return fileService.getDeviceInfo(deviceId).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/license/download")
|
|
|
+ public void licenseDownload(HttpServletResponse response, @RequestParam Long id,
|
|
|
+ @RequestParam(required = false) String deviceId, @RequestParam(required = false) String version)
|
|
|
+ throws Exception {
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=app.lic");
|
|
|
+ licenseService.buildLicense(deployService.findById(id), deviceId, version, response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|