From a64372663b31715ccbb1048eb03deb172dad2773 Mon Sep 17 00:00:00 2001
From: Jinquan_Ou <Jinquan@gdut.com>
Date: 星期三, 12 四月 2023 23:26:39 +0800
Subject: [PATCH] 做了家庭资产的查询权限

---
 zhang-content/src/main/java/com/ruoyi/util/ArraysUtil.java                         |   62 ++++++++++
 zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java                  |   13 ++
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java |    2 
 ruoyi-common/src/main/java/com/ruoyi/common/utils/MapUtils.java                    |    9 +
 zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java                       |    1 
 zhang-content/src/main/java/com/ruoyi/domain/ZInfoUser.java                        |    5 
 zhang-content/src/main/java/com/ruoyi/domain/dto/ZfPropertyDto.java                |   73 ++++++++++++
 zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java     |  160 +++++++++++++++++++++++---
 8 files changed, 302 insertions(+), 23 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
index f8aab63..5cde8b7 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
@@ -40,12 +40,10 @@
 
     @GetMapping("/all")
     public AjaxResult  listAll(ZfProperty zfProperty){
-
         Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
         Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
         return zfPropertyService.selectPropertyList(zfProperty, pageNum, pageSize);
     }
-
 
     /**
      * 瀵煎嚭瀹跺涵璧勪骇璁板綍鍒楄〃
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/MapUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/MapUtils.java
index 23a12d5..9003b2d 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/MapUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/MapUtils.java
@@ -19,4 +19,13 @@
         data.put("pageSize",pageResult.getSize());
         return data;
     }
+
+    public static HashMap<String,Object> getResult(Page pageResult,Object record){
+        HashMap<String, Object> data = new HashMap<>();
+        data.put("data",record);
+        data.put("total",pageResult.getTotal());
+        data.put("pageNum",pageResult.getCurrent());
+        data.put("pageSize",pageResult.getSize());
+        return data;
+    }
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java b/zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java
new file mode 100644
index 0000000..2cd7b86
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java
@@ -0,0 +1,13 @@
+package com.ruoyi.constant;
+
+/**
+ * @Author Jinquan_Ou
+ * @Description
+ * @Date 2023-04-12 23:08
+ * @Version 1.0.0
+ **/
+public class MenuAuthority {
+
+    public static final String PROPERTY_LIST="2007";
+
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZInfoUser.java b/zhang-content/src/main/java/com/ruoyi/domain/ZInfoUser.java
index 343e334..645a115 100644
--- a/zhang-content/src/main/java/com/ruoyi/domain/ZInfoUser.java
+++ b/zhang-content/src/main/java/com/ruoyi/domain/ZInfoUser.java
@@ -161,5 +161,10 @@
      */
     private String familyId;
 
+    /**
+     * 鍏朵粬瀹跺涵鎺堟潈id
+     */
+    private String secondFamilyId;
+
 
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java b/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java
index 5cf7cad..f1b7e6a 100644
--- a/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java
+++ b/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java
@@ -68,4 +68,5 @@
     @Excel(name="瀹跺涵缂栧彿")
     private String familyId;
 
+
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/dto/ZfPropertyDto.java b/zhang-content/src/main/java/com/ruoyi/domain/dto/ZfPropertyDto.java
new file mode 100644
index 0000000..29e024c
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/domain/dto/ZfPropertyDto.java
@@ -0,0 +1,73 @@
+package com.ruoyi.domain.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @Author Jinquan_Ou
+ * @Description
+ * @Date 2023-04-12 20:54
+ * @Version 1.0.0
+ **/
+
+@Data
+public class ZfPropertyDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+
+    private Integer id;
+
+    /**
+     * 璧勪骇绫诲瀷
+     */
+
+    private String type;
+
+    /**
+     * 鏍囬(璐﹀彿銆佸崱鍙�)
+     */
+
+    private String title;
+
+    /**
+     * 寮�鎴疯(璧勪骇鍦板潃)
+     */
+
+    private String location;
+
+    /**
+     * 鎸佹湁浜哄悕瀛�
+     */
+
+    private String holder;
+
+    /**
+     * 瀛樻斁鍦板潃
+     */
+
+    private String address;
+
+
+    private String remark;
+
+    /**
+     * 鍒涘缓鏃堕棿
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date createTime;
+
+    private String url;
+
+    /**
+     * 鏄惁鏄湰瀹跺涵鐨勬暟鎹�(0:涓嶆槸,1:鏄�)
+     */
+    private Integer ownData = 0;
+
+
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
index bcd6416..add7243 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
@@ -8,28 +8,25 @@
 import com.ruoyi.common.utils.MapUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.domain.ZInfoUser;
 import com.ruoyi.domain.ZfProperty;
-import com.ruoyi.domain.ZfEvent;
-import com.ruoyi.domain.ZfProperty;
+import com.ruoyi.domain.dto.ZfPropertyDto;
 import com.ruoyi.mapper.ZfPropertyMapper;
 import com.ruoyi.service.IZfPropertyService;
 import com.ruoyi.service.ZInfoUserService;
+import com.ruoyi.util.ArraysUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
-import java.util.function.Consumer;
 import java.util.stream.Collectors;
+
+import static com.ruoyi.constant.MenuAuthority.PROPERTY_LIST;
 
 
 /**
@@ -50,7 +47,8 @@
     @Override
     public List<ZfProperty> selectByCondition(ZfProperty zfProperty) {
         String familyIds = listFamilyIds();
-        LambdaQueryWrapper<ZfProperty> lambdaQueryWrapper = buildCondition(zfProperty, familyIds);
+        String secondFamilyIds = listSecondFamilyIds();
+        LambdaQueryWrapper<ZfProperty> lambdaQueryWrapper = buildCondition(zfProperty, familyIds, secondFamilyIds);
         List<ZfProperty> list = list(lambdaQueryWrapper);
         log.info("杩斿洖鐨勬暟鎹负:{}", list);
         return list;
@@ -69,35 +67,155 @@
         return lqw;
     }
 
-    private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty, String familyIds) {
+    private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty, String familyIds, String secondFamilyAuthority) {
+        //妯$硦鏌ヨ鐨勬潯浠�
         LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty);
-        if (familyIds.contains(",")) {
-            String[] familyList = familyIds.split(",");
-            lqw.in(ZfProperty::getFamilyId,familyList);
-        } else {
-            lqw.eq(ZfProperty::getFamilyId, familyIds);
+
+        //瀹氫箟涓�涓竷灏旀爣璁帮紝鏍囪绗竴瀹跺涵鍙锋槸鍚︽湁閫楀彿
+        boolean flag = false;
+
+        StringBuilder secondFamilyIdsBuffer = new StringBuilder();
+
+        //澶勭悊浼犲叆鐨剆econdFamilyAuthority   3{2007 2018 2015},4{2007 2019}
+
+        if (StringUtils.isNotEmpty(secondFamilyAuthority)) {
+
+            if (secondFamilyAuthority.contains(",")) {
+                //閫楀彿闅斿紑寰楀埌濡備笅涓诧細3{2007 2018 2015}
+                String[] authorityList = secondFamilyAuthority.split(",");
+                for (String authorityAndId : authorityList) {
+
+                    //寰楀埌鏉冮檺涓�
+                    String authorities = authorityAndId.substring(2, authorityAndId.length() - 1);
+
+                    if (authorities.contains(" ")) {
+                        //绌烘牸闅斿紑寰楀埌鑿滃崟id锛岀湅鏄惁鏈夊搴旂殑鏉冮檺
+                        String[] authorityIdList = authorities.split(" ");
+                        for (String s : authorityIdList) {
+                            if (s.equals(PROPERTY_LIST)) {
+                                secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(",");
+                                break;
+                            }
+                        }
+                    } else {
+                        if (authorities.equals(PROPERTY_LIST)) {
+                            secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(",");
+                        }
+                    }
+                }
+
+                //鎶婂悗闈㈢殑閫楀彿鍘绘帀
+                if (secondFamilyIdsBuffer.length() > 1) {
+                    secondFamilyIdsBuffer.deleteCharAt(secondFamilyIdsBuffer.length() - 1);
+                }
+
+            }
+
         }
+
+        //灏哠tringBuffer杞垚String
+        String secondFamilyIds = secondFamilyIdsBuffer.toString();
+
+
+        //绗竴瀹跺涵鍙风殑鏉′欢
+        if (familyIds.contains(",")) {
+            flag = true;
+        }
+
+        //绗簩瀹跺涵鍙风殑鏉′欢
+        if (StringUtils.isNotEmpty(secondFamilyIds)) {
+            if (secondFamilyIds.contains(",")) {
+                String[] secondFamilyIdList = secondFamilyIds.split(",");
+                if (flag) {
+                    //濡傛灉绗竴瀹跺涵鍙峰拰绗簩瀹跺涵鍙烽兘鏈夐�楀彿
+                    String[] familyList = familyIds.split(",");
+                    String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIdList);
+                    lqw.in(ZfProperty::getFamilyId, totalFamilyIdList);
+                } else {
+                    //濡傛灉绗竴瀹跺涵鍙锋病鏈夐�楀彿浣嗘槸绗簩瀹跺涵鍙锋湁閫楀彿
+                    String[] totalFamilyIdList = ArraysUtil.appendToArray(secondFamilyIdList, familyIds);
+                    lqw.in(ZfProperty::getFamilyId, totalFamilyIdList);
+                }
+
+            } else {
+                if (flag) {
+                    //濡傛灉绗竴瀹跺涵鍙锋湁閫楀彿浣嗙浜屽搴彿娌℃湁閫楀彿
+                    String[] familyList = familyIds.split(",");
+                    String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIds);
+                    lqw.in(ZfProperty::getFamilyId, totalFamilyIdList);
+                } else {
+                    //濡傛灉绗竴瀹跺涵鍙峰拰绗簩瀹跺涵鍙烽兘娌℃湁閫楀彿
+                    String[] totalFamilyIdList = ArraysUtil.appendToArray(familyIds, secondFamilyIds);
+                    lqw.in(ZfProperty::getFamilyId, totalFamilyIdList);
+                }
+            }
+        } else {
+            //濡傛灉娌℃湁绗簩瀹跺涵鍙�
+            if (flag) {
+                String[] familyList = familyIds.split(",");
+                lqw.in(ZfProperty::getFamilyId, familyList);
+            } else {
+                lqw.eq(ZfProperty::getFamilyId, familyIds);
+            }
+
+        }
+
+        lqw.orderByDesc(ZfProperty::getId);
         return lqw;
     }
 
-    private String listFamilyIds() {
+
+    private ZInfoUser getMySelf() {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         Long userId = user.getUserId();
         LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
         zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId, userId);
-        ZInfoUser zInfoUser = zInfoUserService.getOne(zInfoUserLambdaQueryWrapper);
-        return zInfoUser.getFamilyId();
+        return zInfoUserService.getOne(zInfoUserLambdaQueryWrapper);
+    }
+
+    private String listFamilyIds() {
+        ZInfoUser mySelf = getMySelf();
+        return mySelf.getFamilyId();
+    }
+
+    private String listSecondFamilyIds() {
+        ZInfoUser mySelf = getMySelf();
+        return mySelf.getSecondFamilyId();
     }
 
     @Override
     public AjaxResult selectPropertyList(ZfProperty zfProperty, Integer pageNum, Integer pageSize) {
         String familyIds = listFamilyIds();
-        LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty, familyIds);
+        String secondFamilyAuthority = listSecondFamilyIds();
+        LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty, familyIds, secondFamilyAuthority);
+
         Page<ZfProperty> zfPropertyPage = new Page<>(pageNum, pageSize);
         Page<ZfProperty> pageResult = page(zfPropertyPage, lqw);
-        HashMap<String, Object> data = MapUtils.getResult(pageResult);
-        return AjaxResult.success(data);
 
+        List<ZfProperty> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹�
+
+        List<ZfPropertyDto> dtoResult = beanRecords.stream().map(record -> {
+            String recordFamilyId = record.getFamilyId();
+            ZfPropertyDto zfPropertyDto = new ZfPropertyDto();
+            BeanUtils.copyProperties(record, zfPropertyDto);
+
+            if (familyIds.contains(",")) {
+                String[] familyIdList = familyIds.split(",");
+                for (String familyId : familyIdList) {
+                    if (familyId.equals(recordFamilyId)) {
+                        zfPropertyDto.setOwnData(1);
+                    }
+                }
+            } else {
+                if (familyIds.equals(recordFamilyId)) {
+                    zfPropertyDto.setOwnData(1);
+                }
+            }
+            return zfPropertyDto;
+        }).collect(Collectors.toList());
+
+        HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult);
+        return AjaxResult.success(data);
     }
 
     @Override
diff --git a/zhang-content/src/main/java/com/ruoyi/util/ArraysUtil.java b/zhang-content/src/main/java/com/ruoyi/util/ArraysUtil.java
new file mode 100644
index 0000000..d12ea45
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/util/ArraysUtil.java
@@ -0,0 +1,62 @@
+package com.ruoyi.util;
+
+/**
+ * @Author Jinquan_Ou
+ * @Description
+ * @Date 2023-04-12 23:06
+ * @Version 1.0.0
+ **/
+public class ArraysUtil {
+    /**
+     * 涓や釜瀛楃缁勬垚涓�涓暟缁�
+     *
+     * @param str1 瀛楃涓�
+     * @param str2 瀛楃浜�
+     * @return 缁撴灉鏁扮粍
+     */
+    public static String[] appendToArray(String str1, String str2) {
+        String[] newArray = new String[2];
+        newArray[0] = str1;
+        newArray[1] = str2;
+        return newArray;
+    }
+
+    /**
+     * 娣诲姞鍗曚釜瀛楃鍒板瓧绗︿覆鏁扮粍閲岋紝杩斿洖涓�涓柊鐨勬暟缁�
+     *
+     * @param array
+     * @param str
+     * @return
+     */
+    public static String[] appendToArray(String[] array, String str) {
+        String[] newArray = new String[array.length + 1];
+        for (int i = 0; i < array.length; i++) {
+            newArray[i] = array[i];
+        }
+        newArray[newArray.length - 1] = str;
+        return newArray;
+    }
+
+
+    /**
+     * 灏嗕袱涓暟缁勫悎骞朵负涓�涓暟缁勮繑鍥�
+     *
+     * @param array1 鏁扮粍1
+     * @param array2 鏁扮粍2
+     * @return 鏂版暟缁�
+     */
+    public static String[] appendToArray(String[] array1, String[] array2) {
+        String[] newArray = new String[array1.length + array2.length];
+        int index = 0;
+        for (int i = 0; i < array1.length; i++) {
+            newArray[index] = array1[i];
+            index++;
+        }
+        for (int i = 0; i < array2.length; i++) {
+            newArray[index] = array2[i];
+            index++;
+        }
+        return newArray;
+    }
+}
+

--
Gitblit v1.9.1