From dc194fb281e0e4c4ec34549adb4ad11f3cb67b35 Mon Sep 17 00:00:00 2001
From: whywhyo <1511349576@qq.com>
Date: 星期一, 05 六月 2023 20:13:30 +0800
Subject: [PATCH] 123

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 118 insertions(+), 0 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java
index 94a2fb6..b0188c1 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java
@@ -1,11 +1,28 @@
 package com.ruoyi.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.MapUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.domain.ZProperty;
 import com.ruoyi.domain.ZProperty;
 import com.ruoyi.mapper.ZPropertyMapper;
 import com.ruoyi.service.ZPropertyService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
 
 /**
  * <p>
@@ -18,4 +35,105 @@
 @Service
 public class ZPropertyServiceImpl extends ServiceImpl<ZPropertyMapper, ZProperty> implements ZPropertyService {
 
+    @Autowired
+    ZPropertyServiceImpl zPropertyService;
+
+    private LambdaQueryWrapper<ZProperty> uniqueCondition(ZProperty zProperty) {
+        LambdaQueryWrapper<ZProperty> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
+                .eq(StringUtils.isNotEmpty(zProperty.getIncomeName()), ZProperty::getIncomeName, zProperty.getIncomeName())
+                .eq(StringUtils.isNotEmpty(zProperty.getPrice()), ZProperty::getPrice, zProperty.getPrice())
+                .eq(StringUtils.isNotEmpty(zProperty.getTimeLimit()), ZProperty::getTimeLimit, zProperty.getTimeLimit())
+                .eq(StringUtils.isNotEmpty(zProperty.getIsChange()), ZProperty::getIsChange, zProperty.getIsChange())
+                .eq(StringUtils.isNotEmpty(zProperty.getPropertyRight()), ZProperty::getPropertyRight, zProperty.getPropertyRight())
+                .eq(zProperty.getHappenTime() != null, ZProperty::getHappenTime, zProperty.getHappenTime())
+                .eq(StringUtils.isNotEmpty(zProperty.getLocation()), ZProperty::getLocation, zProperty.getLocation())
+                .eq(StringUtils.isNotEmpty(zProperty.getRemark()), ZProperty::getRemark, zProperty.getRemark())
+                .eq(zProperty.getUserId() != null, ZProperty::getUserId, zProperty.getUserId());
+        return lqw;
+    }
+
+    private LambdaQueryWrapper<ZProperty> buildCondition(ZProperty zProperty, Long userId) {
+        LambdaQueryWrapper<ZProperty> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(userId != null, ZProperty::getUserId, userId)
+                .like(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
+                .like(StringUtils.isNotEmpty(zProperty.getIncomeName()), ZProperty::getIncomeName, zProperty.getIncomeName())
+                .between(zProperty.getHappenStartTime() != null && zProperty.getHappenEndTime() != null, ZProperty::getHappenTime, zProperty.getHappenStartTime(), zProperty.getHappenEndTime())
+                .orderByDesc(ZProperty::getCreateTime);
+        return lqw;
+    }
+
+    /**
+     * 鍒嗛〉鏌ユ壘
+     */
+    @Override
+    public AjaxResult selectDataList(ZProperty zProperty, Integer pageNum, Integer pageSize) {
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        Long userId = user.getUserId();
+        LambdaQueryWrapper<ZProperty> lqw = buildCondition(zProperty, userId);
+
+        Page<ZProperty> pageBean = new Page<>(pageNum, pageSize);
+        Page<ZProperty> pageResult = page(pageBean, lqw);
+
+        List<ZProperty> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹�
+
+        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
+        return AjaxResult.success(data);
+
+    }
+
+
+    @Override
+    public List<ZProperty> selectByIds(Long[] ids) {
+        List<ZProperty> list = new ArrayList<>();
+        if (ids.length != 0)
+            list = listByIds(Arrays.asList(ids));
+        else
+            list = list();
+        return list;
+    }
+
+    @Override
+    public AjaxResult mySave(ZProperty zProperty) {
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        Long userId = user.getUserId();
+        zProperty.setUserId(userId);
+
+        //妫�鏌ユ槸鍚︽湁閲嶅鏁版嵁鎻掑叆
+        LambdaQueryWrapper<ZProperty> lqw = uniqueCondition(zProperty);
+        List<ZProperty> list = list(lqw);
+        if (list.size() > 0) {
+            throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁");
+        }
+
+        if (save(zProperty)) {
+            return AjaxResult.success();
+        } else {
+            return AjaxResult.error();
+        }
+
+    }
+
+    @Override
+    @Transactional
+    public AjaxResult importExcel(MultipartFile file) {
+
+        ExcelUtil<ZProperty> util = new ExcelUtil<>(ZProperty.class);
+        List<ZProperty> dataList = null;
+        try {
+            dataList = util.importExcel(file.getInputStream());
+        } catch (Exception e) {
+            throw new RuntimeException("娌℃湁鎸夌収瑙勫垯瀵煎叆鏁版嵁");
+        }
+
+        assert dataList != null;
+
+        for (ZProperty zProperty : dataList) {
+            zPropertyService.mySave(zProperty);
+        }
+
+        return AjaxResult.success();
+
+    }
+
 }

--
Gitblit v1.9.1