feige
2025-06-23 082ba3d3cd975f182425448bcea3a9166b70980b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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.ZHonor;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZProperty;
import com.ruoyi.mapper.ZPropertyMapper;
import com.ruoyi.service.ZInfoUserService;
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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 个人财产表 服务实现类
 * </p>
 *
 * @author ojq
 * @since 2023-03-14
 */
@Service
public class ZPropertyServiceImpl extends ServiceImpl<ZPropertyMapper, ZProperty> implements ZPropertyService {
 
    @Autowired
    ZPropertyServiceImpl zPropertyService;
    @Autowired
    ZInfoUserService zInfoUserService;
    @Resource
    ZPropertyMapper zPropertyMapper;
 
    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())
                .like(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
                .like(StringUtils.isNotEmpty(zProperty.getIsChange()),ZProperty::getIsChange,zProperty.getIsChange())
                .like(StringUtils.isNotEmpty(zProperty.getRemark()), ZProperty::getRemark, zProperty.getRemark())
                .like(StringUtils.isNotEmpty(zProperty.getTimeLimit()),ZProperty::getTimeLimit,zProperty.getTimeLimit())
                .eq(zProperty.getStatus()!=null,ZProperty::getStatus,zProperty.getStatus())
                .between(zProperty.getHappenStartTime() != null && zProperty.getHappenEndTime() != null, ZProperty::getHappenTime, zProperty.getHappenStartTime(), zProperty.getHappenEndTime())
                .orderByDesc(ZProperty::getCreateTime);
        return lqw;
    }
    private LambdaQueryWrapper<ZProperty> buildConditionSec(ZProperty zProperty, List<Long> userId) {
        LambdaQueryWrapper<ZProperty> lqw = new LambdaQueryWrapper<>();
        lqw.in(ZProperty::getUserId, userId)
                .like(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
                .like(StringUtils.isNotEmpty(zProperty.getIncomeName()), ZProperty::getIncomeName, zProperty.getIncomeName())
                .like(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
                .like(StringUtils.isNotEmpty(zProperty.getIsChange()),ZProperty::getIsChange,zProperty.getIsChange())
                .like(StringUtils.isNotEmpty(zProperty.getRemark()), ZProperty::getRemark, zProperty.getRemark())
                .like(StringUtils.isNotEmpty(zProperty.getTimeLimit()),ZProperty::getTimeLimit,zProperty.getTimeLimit())
                .eq(zProperty.getStatus()!=null,ZProperty::getStatus,zProperty.getStatus())
                .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();
 
        //根据userId查询到infouser的uaid
        ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId);
        //拿到所有的sysid
        List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList());
        LambdaQueryWrapper<ZProperty> lqw;
        if(!fms.isEmpty())
            lqw = buildConditionSec(zProperty, fms);
        else
            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
    public List<ZProperty> selectByCondition() {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        ZProperty zProperty = new ZProperty();
        LambdaQueryWrapper<ZProperty> lqw = buildCondition(zProperty, userId);
        return list(lqw);
    }
 
    @Override
    public AjaxResult listType() {
        List<String> result = zPropertyMapper.listType();
        return AjaxResult.success(result);
    }
 
    @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();
 
    }
 
}