bihuisong 1 年之前
父节点
当前提交
ff86d41055

+ 0 - 37
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -151,41 +151,4 @@ public class CommonController {
         }
     }
 
-    @Autowired
-    private RedisTemplate redisTemplate;
-
-    @GetMapping("/test")
-    public void test() {
-        LocalDateTime startDate = LocalDateTime.now();
-        LocalDateTime endDate = ChronoUnit.MINUTES.addTo(startDate, 1);
-        long startDateEpochMilli = startDate.toInstant(ZoneOffset.of("+8")).toEpochMilli();
-        long endDateEpochMilli = endDate.toInstant(ZoneOffset.of("+8")).toEpochMilli();
-        try {
-            // 生成密钥对
-            KeyPair keyPair = RsaUtil.getKeyPair();
-            String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
-            String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
-            RSA rsa = SecureUtil.rsa(privateKey, publicKey);
-            String str = String.valueOf("123" + "," + startDateEpochMilli + "," + endDateEpochMilli);
-
-            System.out.println("私钥:" + privateKey);
-            System.out.println("公钥:" + publicKey);
-            // RSA加密
-            String secret = rsa.encryptBcd(str, KeyType.PublicKey);
-            System.out.println("加密后内容:" + secret);
-            // RSA解密
-            String strSecret = rsa.decryptStr(secret, KeyType.PrivateKey);
-            System.out.println("解密后内容:" + strSecret);
-            // RSA签名
-            String sign = RsaUtil.sign(secret, RsaUtil.getPrivateKey(privateKey));
-            // RSA验签
-            boolean result = RsaUtil.verify(secret, RsaUtil.getPublicKey(publicKey), sign);
-            System.out.print("验签结果:" + result);
-            redisTemplate.opsForValue().set("result",result,180);
-        } catch (Exception e) {
-            e.printStackTrace();
-            System.out.print("加解密异常");
-        }
-
-    }
 }

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProjectController.java

@@ -87,7 +87,7 @@ public class SysProjectController extends BaseController {
     @Log(title = "删除项目管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable Long[] ids) {
-        return toAjax(sysProjectService.deleteSysProjectByIds(ids));
+        return sysProjectService.deleteSysProjectByIds(ids);
     }
 
 

+ 38 - 26
ruoyi-admin/src/main/java/com/ruoyi/web/utils/RsaUtil.java

@@ -9,7 +9,14 @@ import java.security.PublicKey;
 import java.security.Signature;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.X509EncodedKeySpec;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.temporal.ChronoUnit;
 import javax.crypto.Cipher;
+
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.asymmetric.KeyType;
+import cn.hutool.crypto.asymmetric.RSA;
 import org.apache.commons.codec.binary.Base64;
 
 public class RsaUtil {
@@ -164,30 +171,35 @@ public class RsaUtil {
         return signature.verify(Base64.decodeBase64(sign.getBytes()));
     }
 
-//    public static void main(String[] args) {
-//        try {
-//            // 生成密钥对
-//            KeyPair keyPair = getKeyPair();
-//            String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
-//            String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
-//            System.out.println("私钥:" + privateKey);
-//            System.out.println("公钥:" + publicKey);
-//            // RSA加密
-//            String data = "待加密的文字内容";
-//            String encryptData = encrypt(data, getPublicKey(publicKey));
-//            System.out.println("加密后内容:" + encryptData);
-//            // RSA解密
-//            String decryptData = decrypt(encryptData, getPrivateKey(privateKey));
-//            System.out.println("解密后内容:" + decryptData);
-//
-//            // RSA签名
-//            String sign = sign(data, getPrivateKey(privateKey));
-//            // RSA验签
-//            boolean result = verify(data, getPublicKey(publicKey), sign);
-//            System.out.print("验签结果:" + result);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//            System.out.print("加解密异常");
-//        }
-//    }
+    public static void main(String[] args) {
+        LocalDateTime startDate = LocalDateTime.now();
+        LocalDateTime endDate = ChronoUnit.MINUTES.addTo(startDate, 1);
+        long startDateEpochMilli = startDate.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        long endDateEpochMilli = endDate.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        try {
+            // 生成密钥对
+            KeyPair keyPair = RsaUtil.getKeyPair();
+            String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
+            String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
+            RSA rsa = SecureUtil.rsa(privateKey, publicKey);
+            String str = String.valueOf("123" + "," + startDateEpochMilli + "," + endDateEpochMilli);
+
+            System.out.println("私钥:" + privateKey);
+            System.out.println("公钥:" + publicKey);
+            // RSA加密
+            String secret = rsa.encryptBcd(str, KeyType.PublicKey);
+            System.out.println("加密后内容:" + secret);
+            // RSA解密
+            String strSecret = rsa.decryptStr(secret, KeyType.PrivateKey);
+            System.out.println("解密后内容:" + strSecret);
+            // RSA签名
+            String sign = RsaUtil.sign(secret, RsaUtil.getPrivateKey(privateKey));
+            // RSA验签
+            boolean result = RsaUtil.verify(secret, RsaUtil.getPublicKey(publicKey), sign);
+            System.out.print("验签结果:" + result);
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.print("加解密异常");
+        }
+    }
 }

+ 11 - 9
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysSecretProjectMapper.java

@@ -1,20 +1,20 @@
 package com.ruoyi.system.mapper;
 
 import java.util.List;
+
 import com.ruoyi.system.domain.SysSecretProject;
 import com.ruoyi.system.domain.dto.SysSecretProjectDTO;
 
 /**
  * 【请填写功能名称】Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2023-11-21
  */
-public interface SysSecretProjectMapper 
-{
+public interface SysSecretProjectMapper {
     /**
      * 查询【请填写功能名称】
-     * 
+     *
      * @param id 【请填写功能名称】主键
      * @return 【请填写功能名称】
      */
@@ -22,7 +22,7 @@ public interface SysSecretProjectMapper
 
     /**
      * 查询【请填写功能名称】列表
-     * 
+     *
      * @param sysSecretProjectDTO 【请填写功能名称】
      * @return 【请填写功能名称】集合
      */
@@ -30,7 +30,7 @@ public interface SysSecretProjectMapper
 
     /**
      * 新增【请填写功能名称】
-     * 
+     *
      * @param sysSecretProject 【请填写功能名称】
      * @return 结果
      */
@@ -38,7 +38,7 @@ public interface SysSecretProjectMapper
 
     /**
      * 修改【请填写功能名称】
-     * 
+     *
      * @param sysSecretProject 【请填写功能名称】
      * @return 结果
      */
@@ -46,7 +46,7 @@ public interface SysSecretProjectMapper
 
     /**
      * 删除【请填写功能名称】
-     * 
+     *
      * @param id 【请填写功能名称】主键
      * @return 结果
      */
@@ -54,9 +54,11 @@ public interface SysSecretProjectMapper
 
     /**
      * 批量删除【请填写功能名称】
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteSysSecretProjectByIds(Long[] ids);
+
+    public int selectCountByProjectId(Long[] ids);
 }

+ 3 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysProjectService.java

@@ -1,6 +1,8 @@
 package com.ruoyi.system.service;
 
 import java.util.List;
+
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.SysProject;
 
 /**
@@ -49,7 +51,7 @@ public interface ISysProjectService
      * @param ids 需要删除的【请填写功能名称】主键集合
      * @return 结果
      */
-    public int deleteSysProjectByIds(Long[] ids);
+    public AjaxResult deleteSysProjectByIds(Long[] ids);
 
     /**
      * 删除【请填写功能名称】信息

+ 12 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysProjectServiceImpl.java

@@ -2,6 +2,8 @@ package com.ruoyi.system.service.impl;
 
 import java.util.List;
 
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.system.mapper.SysSecretProjectMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.SysProjectMapper;
@@ -16,8 +18,11 @@ import com.ruoyi.system.service.ISysProjectService;
  */
 @Service
 public class SysProjectServiceImpl implements ISysProjectService {
+
     @Autowired
     private SysProjectMapper sysProjectMapper;
+    @Autowired
+    private SysSecretProjectMapper sysSecretProjectMapper;
 
     /**
      * 查询【请填写功能名称】
@@ -70,8 +75,13 @@ public class SysProjectServiceImpl implements ISysProjectService {
      * @return 结果
      */
     @Override
-    public int deleteSysProjectByIds(Long[] ids) {
-        return sysProjectMapper.deleteSysProjectByIds(ids);
+    public AjaxResult deleteSysProjectByIds(Long[] ids) {
+        int i = sysSecretProjectMapper.selectCountByProjectId(ids);
+        if (i > 0) {
+            return AjaxResult.error("此项目已经绑定,请勿删除!");
+        } else {
+            return AjaxResult.success(sysProjectMapper.deleteSysProjectByIds(ids));
+        }
     }
 
     /**

+ 6 - 0
ruoyi-system/src/main/resources/mapper/system/SysSecretProjectMapper.xml

@@ -67,4 +67,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+    <select id="selectCountByProjectId" resultType="java.lang.Integer">
+        select count(1) from sys_secret_project  where project_id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
 </mapper>

+ 2 - 2
ruoyi-ui/src/views/authority/project/index.vue

@@ -250,9 +250,9 @@ export default {
       const ids = row.id || this.ids;
       this.$modal.confirm('是否确认删除项目管理编号为"' + ids + '"的数据项?').then(function () {
         return delProject(ids);
-      }).then(() => {
+      }).then((res) => {
         this.getList();
-        this.$modal.msgSuccess("删除成功");
+        this.$modal.msgSuccess(res.mes);
       }).catch(() => {
       });
     },