Explorar o código

增加部署绑定机构,绑定设备,授权导出等功能

luoshi %!s(int64=2) %!d(string=hai) anos
pai
achega
7e7b70490b

+ 42 - 24
src/main/java/com/qmth/ops/api/controller/admin/DeployController.java

@@ -6,29 +6,23 @@ 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.api.vo.*;
 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 com.qmth.ops.biz.query.OrgQuery;
+import com.qmth.ops.biz.service.*;
 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.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/deploy")
@@ -46,28 +40,31 @@ public class DeployController {
     @Resource
     private LicenseService licenseService;
 
+    @Resource
+    private OrgService orgService;
+
     @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")
+    @PostMapping("/query")
     public DeployPageVO query(DeployQuery query) {
         return new DeployPageVO(deployService.query(query), appService);
     }
 
-    @RequestMapping("/insert")
+    @PostMapping("/insert")
     public DeployVO insert(@Validated(DeployForm.InsertGroup.class) @RequestBody DeployForm form) {
         return new DeployVO(deployService.insert(form.build()), appService);
     }
 
-    @RequestMapping("/update")
+    @PostMapping("/update")
     public DeployVO update(@Validated(DeployForm.UpdateGroup.class) @RequestBody DeployForm form) {
         return new DeployVO(deployService.update(form.build()), appService);
     }
 
-    @RequestMapping("/device/save")
+    @PostMapping("/device/save")
     public Object saveDevice(@RequestParam Long id, @RequestParam MultipartFile deviceInfo,
             @RequestParam(required = false) String remark) throws Exception {
         Deploy deploy = deployService.findById(id);
@@ -78,35 +75,35 @@ public class DeployController {
             }
             String deviceId = info.uuid();
             fileService.uploadDeviceInfo(deviceId, info);
-            deployService.bindDevice(id, deviceId, StringUtils.trimToEmpty(remark));
+            deployService.saveDevice(deploy, deviceId, StringUtils.trimToEmpty(remark));
             return new SuccessVO(true);
         } else {
             throw new ApiException(HttpStatus.BAD_REQUEST, 400100, "deploy unexists", null);
         }
     }
 
-    @RequestMapping("/device/delete")
+    @PostMapping("/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);
+            deployService.deleteDevice(deploy, 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);
+    @PostMapping("/device/list")
+    public Object listDevice(@RequestParam Long id) {
+        return deployService.listDevice(id);
     }
 
-    @RequestMapping("/device/info")
+    @PostMapping("/device/info")
     public Object getDeviceInfo(@RequestParam String deviceId) throws Exception {
         return fileService.getDeviceInfo(deviceId).toString();
     }
 
-    @RequestMapping("/license/download")
+    @PostMapping("/license/download")
     public void licenseDownload(HttpServletResponse response, @RequestParam Long id,
             @RequestParam(required = false) String deviceId, @RequestParam(required = false) String version)
             throws Exception {
@@ -115,4 +112,25 @@ public class DeployController {
         licenseService.buildLicense(deployService.findById(id), deviceId, version, response.getOutputStream());
     }
 
+    @PostMapping("/org/list")
+    public List<OrgVO> listOrg(@RequestParam Long id) {
+        OrgQuery query = new OrgQuery();
+        query.setDeployId(id);
+        query.setEnable(true);
+        query.setPageNumber(1);
+        query.setPageSize(Long.MAX_VALUE);
+        return orgService.listByQuery(query).stream().map(OrgVO::new).collect(Collectors.toList());
+    }
+
+    @PostMapping("/org/update")
+    public Object updateOrg(@RequestParam Long id, @RequestParam Long[] orgId) {
+        Deploy deploy = deployService.findById(id);
+        if (deploy != null) {
+            deployService.updateOrg(deploy, orgId);
+            return orgId;
+        } else {
+            throw new ApiException(HttpStatus.BAD_REQUEST, 400100, "deploy unexists", null);
+        }
+    }
+
 }

+ 13 - 14
src/main/java/com/qmth/ops/api/controller/admin/OrgController.java

@@ -4,12 +4,15 @@ import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.core.solar.enums.OrgType;
 import com.qmth.ops.api.constants.OpsApiConstants;
+import com.qmth.ops.api.vo.OrgPageVO;
 import com.qmth.ops.api.vo.OrgTypeVO;
+import com.qmth.ops.api.vo.OrgVO;
 import com.qmth.ops.api.vo.SuccessVO;
 import com.qmth.ops.biz.domain.Org;
 import com.qmth.ops.biz.query.OrgQuery;
 import com.qmth.ops.biz.service.FileService;
 import com.qmth.ops.biz.service.OrgService;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -34,38 +37,34 @@ public class OrgController {
         return Arrays.stream(OrgType.values()).map(OrgTypeVO::new).toArray();
     }
 
-    @RequestMapping("/query")
-    public OrgQuery query(OrgQuery query) {
-        query = orgService.findByQuery(query);
-        query.getRecords().forEach(org -> org.setAccessSecret("***"));
-        return query;
+    @PostMapping("/query")
+    public OrgPageVO query(OrgQuery query) {
+        return new OrgPageVO(orgService.findByQuery(query));
     }
 
-    @RequestMapping("/insert")
-    public Org insert(Org org, @RequestParam(required = false) MultipartFile logoFile,
+    @PostMapping("/insert")
+    public OrgVO insert(Org org, @RequestParam(required = false) MultipartFile logoFile,
             @RequestParam(required = false) String logoMd5) throws Exception {
         org = orgService.insert(org);
         if (logoFile != null && logoMd5 != null) {
             fileService.uploadOrgLogo(org, logoFile, logoMd5);
             org = orgService.update(org);
         }
-        org.setAccessSecret("***");
-        return org;
+        return new OrgVO(org);
     }
 
-    @RequestMapping("/update")
-    public Object update(Org org, @RequestParam(required = false) MultipartFile logoFile,
+    @PostMapping("/update")
+    public OrgVO update(Org org, @RequestParam(required = false) MultipartFile logoFile,
             @RequestParam(required = false) String logoMd5) throws Exception {
         org = orgService.update(org);
         if (logoFile != null && logoMd5 != null) {
             fileService.uploadOrgLogo(org, logoFile, logoMd5);
             org = orgService.update(org);
         }
-        org.setAccessSecret("***");
-        return org;
+        return new OrgVO(org);
     }
 
-    @RequestMapping("/toggle")
+    @PostMapping("/toggle")
     public Object toggle(@RequestParam Long id, @RequestParam Boolean enable) {
         return new SuccessVO(orgService.toggle(id, enable));
     }

+ 20 - 0
src/main/java/com/qmth/ops/api/vo/OrgPageVO.java

@@ -0,0 +1,20 @@
+package com.qmth.ops.api.vo;
+
+import com.qmth.boot.mybatis.query.BaseQuery;
+import com.qmth.ops.biz.query.OrgQuery;
+
+import java.util.stream.Collectors;
+
+public class OrgPageVO extends BaseQuery<OrgVO> {
+
+    public OrgPageVO(OrgQuery query) {
+        setRecords(query.getRecords().stream().map(OrgVO::new).collect(Collectors.toList()));
+        setPageNumber(query.getPageNumber());
+        setPageSize(query.getPageSize());
+        setTotal(query.getTotal());
+        setCurrent(query.getCurrent());
+        setPages(query.getPages());
+        setSize(query.getSize());
+    }
+
+}

+ 112 - 0
src/main/java/com/qmth/ops/api/vo/OrgVO.java

@@ -0,0 +1,112 @@
+package com.qmth.ops.api.vo;
+
+import com.qmth.boot.core.solar.enums.OrgSubType;
+import com.qmth.boot.core.solar.enums.OrgType;
+import com.qmth.ops.biz.domain.Org;
+
+import java.util.Set;
+
+public class OrgVO {
+
+    private Long id;
+
+    private String code;
+
+    private String name;
+
+    private OrgType type;
+
+    private Set<OrgSubType> subTypes;
+
+    private Boolean enable;
+
+    private String logo;
+
+    private Long createTime;
+
+    private Long updateTime;
+
+    public OrgVO(Org org) {
+        this.id = org.getId();
+        this.code = org.getCode();
+        this.name = org.getName();
+        this.type = org.getType();
+        this.subTypes = org.getSubTypes();
+        this.enable = org.isEnable();
+        this.logo = org.getLogo();
+        this.createTime = org.getCreateTime();
+        this.updateTime = org.getUpdateTime();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public OrgType getType() {
+        return type;
+    }
+
+    public void setType(OrgType type) {
+        this.type = type;
+    }
+
+    public Set<OrgSubType> getSubTypes() {
+        return subTypes;
+    }
+
+    public void setSubTypes(Set<OrgSubType> subTypes) {
+        this.subTypes = subTypes;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getLogo() {
+        return logo;
+    }
+
+    public void setLogo(String logo) {
+        this.logo = logo;
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+}

+ 6 - 0
src/main/java/com/qmth/ops/biz/dao/DeployDeviceDao.java

@@ -2,7 +2,13 @@ package com.qmth.ops.biz.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.ops.biz.domain.DeployDevice;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
 
 public interface DeployDeviceDao extends BaseMapper<DeployDevice> {
 
+    @Update("replace into deploy_device (deploy_id, device_id, remark, create_time) "
+            + "values (#{deployId}), #{deviceId}, #{remark}, #{time}")
+    void save(@Param("deployId") Long deployId, @Param("deviceId") String deviceId, @Param("remark") String remark,
+            @Param("time") long time);
 }

+ 4 - 0
src/main/java/com/qmth/ops/biz/dao/DeployOrgDao.java

@@ -2,7 +2,11 @@ package com.qmth.ops.biz.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.ops.biz.domain.DeployOrg;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Collection;
 
 public interface DeployOrgDao extends BaseMapper<DeployOrg> {
 
+    int batchInsert(@Param("deployId") Long deployId, @Param("orgIds") Collection<Long> orgIds);
 }

+ 9 - 0
src/main/java/com/qmth/ops/biz/query/OrgQuery.java

@@ -23,6 +23,8 @@ public class OrgQuery extends BaseQuery<Org> {
 
     private Boolean enable;
 
+    private Long deployId;
+
     public Long getId() {
         return id;
     }
@@ -79,4 +81,11 @@ public class OrgQuery extends BaseQuery<Org> {
         this.enable = enable;
     }
 
+    public Long getDeployId() {
+        return deployId;
+    }
+
+    public void setDeployId(Long deployId) {
+        this.deployId = deployId;
+    }
 }

+ 33 - 0
src/main/java/com/qmth/ops/biz/service/DeployService.java

@@ -4,13 +4,20 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.ops.biz.dao.DeployDao;
+import com.qmth.ops.biz.dao.DeployDeviceDao;
+import com.qmth.ops.biz.dao.DeployOrgDao;
 import com.qmth.ops.biz.domain.Deploy;
+import com.qmth.ops.biz.domain.DeployDevice;
+import com.qmth.ops.biz.domain.DeployOrg;
 import com.qmth.ops.biz.query.DeployQuery;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.validation.constraints.NotNull;
+import java.util.Arrays;
+import java.util.List;
 import java.util.UUID;
 
 @Service
@@ -19,6 +26,12 @@ public class DeployService extends ServiceImpl<DeployDao, Deploy> {
     @Resource
     private DeployDao deployDao;
 
+    @Resource
+    private DeployDeviceDao deployDeviceDao;
+
+    @Resource
+    private DeployOrgDao deployOrgDao;
+
     @Transactional
     public Deploy insert(Deploy deploy) {
         deploy.setAccessKey(UUID.randomUUID().toString().replaceAll("-", ""));
@@ -52,5 +65,25 @@ public class DeployService extends ServiceImpl<DeployDao, Deploy> {
         return deployDao.selectById(id);
     }
 
+    public List<DeployDevice> listDevice(Long id) {
+        return deployDeviceDao.selectList(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, id));
+    }
+
+    @Transactional
+    public void saveDevice(@NotNull Deploy deploy, @NotNull String deviceId, String remark) {
+        deployDeviceDao.save(deploy.getId(), deviceId, remark, System.currentTimeMillis());
+    }
+
+    @Transactional
+    public void deleteDevice(@NotNull Deploy deploy, @NotNull String deviceId) {
+        deployDeviceDao.delete(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, deploy.getId())
+                .eq(DeployDevice::getDeviceId, deviceId));
+    }
+
+    @Transactional
+    public void updateOrg(@NotNull Deploy deploy, Long[] orgId) {
+        deployOrgDao.delete(new LambdaQueryWrapper<DeployOrg>().eq(DeployOrg::getDeployId, deploy.getId()));
+        deployOrgDao.batchInsert(deploy.getId(), Arrays.asList(orgId));
+    }
 }
 

+ 5 - 6
src/main/java/com/qmth/ops/biz/service/LicenseService.java

@@ -30,9 +30,6 @@ public class LicenseService {
 
     private RsaHelper privateKey;
 
-    @Resource
-    private DeployService deployService;
-
     @Resource
     private AppService appService;
 
@@ -52,13 +49,15 @@ public class LicenseService {
 
     public void buildLicense(@NotNull Deploy deploy, String deviceId, String version, @NotNull OutputStream ous)
             throws Exception {
-        //build app info
+        //build deploy info
         AppLicense license = new AppLicense();
-        app.buildAppInfo(license);
+        license.setId(deploy.getId());
+        license.setName(deploy.getName());
+        license.setControl(deploy.getControl());
         license.setOrgs(new ArrayList<>());
         //build org info list
         OrgQuery query = new OrgQuery();
-        query.setAppId(app.getId());
+        query.setDeployId(deploy.getId());
         query.setEnable(true);
         query.setPageNumber(1);
         query.setPageSize(100);

+ 5 - 4
src/main/java/com/qmth/ops/biz/service/OrgService.java

@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.List;
 import java.util.UUID;
 
 @Service
@@ -17,14 +18,14 @@ public class OrgService {
     @Resource
     private OrgDao orgDao;
 
-    public Org findById(Long id) {
-        return orgDao.selectById(id);
-    }
-
     public OrgQuery findByQuery(OrgQuery query) {
         return orgDao.findByQuery(query);
     }
 
+    public List<Org> listByQuery(OrgQuery query) {
+        return orgDao.findByQuery(query).getRecords();
+    }
+
     @Transactional
     public boolean toggle(Long id, boolean enable) {
         return orgDao.toggle(id, enable) > 0;

+ 12 - 0
src/main/resources/mapper/DeployOrgMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.ops.biz.dao.DeployOrgDao">
+
+    <!--MybatisPlus内置规则,开启autoResultMap后,名称为mybatis-plus_XXX-->
+    <insert id="batchInsert">
+        replace into deploy_org (deploy_id, org_id) values
+        <foreach collection="orgIds" item="orgId" separator=",">
+            (#{deployId}, #{orgId})
+        </foreach>
+    </insert>
+</mapper>

+ 6 - 0
src/main/resources/mapper/OrgMapper.xml

@@ -5,6 +5,9 @@
     <!--MybatisPlus内置规则,开启autoResultMap后,名称为mybatis-plus_XXX-->
     <select id="findByQuery" resultMap="mybatis-plus_Org">
         select g.* from org g
+        <if test="deployId != null">
+            inner join deploy_org do on g.id=do.org_id
+        </if>
         <where>
             <if test="id != null">
                 and g.id=#{id}
@@ -27,6 +30,9 @@
             <if test="enable != null">
                 and g.enable=#{enable}
             </if>
+            <if test="deployId != null">
+                and do.deploy_id=#{deployId}
+            </if>
         </where>
     </select>
 </mapper>