yanghb
2025-04-25 39854ed874e1f38ce3f192ca8e0362a826cfdd55
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
package com.ruoyi.bussiness.service.impl;
 
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.bussiness.domain.Compensate;
import com.ruoyi.bussiness.enums.CompensateEnum;
import com.ruoyi.bussiness.mapper.CompensateMapper;
import com.ruoyi.bussiness.service.CompensateService;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
 
@Service
public class CompensateServiceImpl extends ServiceImpl<CompensateMapper, Compensate> implements CompensateService {
 
    @Override
    public void updateCompensate(List<Compensate> compensates) {
        if (ObjectUtil.isNull(compensates)) {
            throw new GlobalException("请至少修改一个补偿标准");
        }
        saveOrUpdateBatch(compensates);
    }
 
    @Override
    public boolean compensateSettleAreaCalculate(Date time, Integer currentCollectiveNum, Integer currentNoCollectiveNum, BigDecimal area) {
        List<Compensate> compensates = this.list();
        Map<String,Compensate> configMap = compensates.stream().collect(Collectors.toMap(Compensate::getConfigKey, Function.identity()));
        Date date = DateUtil.parse("2014-01-01 00:00:00","yyyy-MM-dd HH:mm:ss");
        Compensate org;
        Compensate noOrg;
        if (time.before(date)) {
            //14年之前
            //集体
            org = configMap.get(CompensateEnum.BEFORE_ORG_AREA.getCode());
            //非集体
            noOrg = configMap.get(CompensateEnum.BEFORE_NO_ORG_AREA.getCode());
        } else {
            //14年之后
            //集体
            org = configMap.get(CompensateEnum.AFTER_ORG_AREA.getCode());
            //非集体
            noOrg = configMap.get(CompensateEnum.AFTER_NO_ORG_AREA.getCode());
        }
        //标准面积
        BigDecimal configValue = org.getConfigValue().multiply(new BigDecimal(currentCollectiveNum))
                .add(noOrg.getConfigValue().multiply(new BigDecimal(currentNoCollectiveNum)));
        //记录面积=标准面积 = 正常
        if (area.compareTo(configValue) == 0) {
            return true;
        }
        return false;
    }
 
    @Override
    public boolean compensateSettleAreaCalculate(BigDecimal orgArea, BigDecimal noOrgArea, BigDecimal area) {
        BigDecimal totalArea = orgArea.add(noOrgArea);
        if(totalArea.compareTo(area) == 0){
            return true;
        }
        return false;
    }
 
    @Override
    public boolean compensateBuyCalculate(Date time, String street,
                                          Integer currentCollectiveNum, Integer currentNoCollectiveNum,
                                          BigDecimal compensationNewAmount,BigDecimal compensationOldAmount,
                                          BigDecimal money) {
        List<Compensate> compensates = this.list();
        Map<String, Compensate> configMap = compensates.stream().collect(Collectors.toMap(Compensate::getConfigKey, Function.identity()));
        Date date = DateUtil.parse("2014-01-01 00:00:00","yyyy-MM-dd HH:mm:ss");
        //集体面积
        Compensate orgArea;
        //非集体面积
        Compensate noOrgArea;
        Compensate orgPrice = null;
        Compensate noOrgPrice = null;
        //14年之前
        if (time.before(date)) {
            //集体应安置面积
            orgArea = configMap.get(CompensateEnum.BEFORE_ORG_AREA.getCode());
            //非集体应安置面积
            noOrgArea = configMap.get(CompensateEnum.BEFORE_NO_ORG_AREA.getCode());
            if ("崇阳街道、崇庆街道、羊马街道、大划街道".contains(street)) {
                if (compensationNewAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 专属街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_APPOINT1.getCode());
                    //14年之前 专属街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_APPOINT1.getCode());
                }
                if (compensationOldAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 专属街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_APPOINT2.getCode());
                    //14年之前 专属街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_APPOINT2.getCode());
                }
            } else {
                if (compensationNewAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 其余街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_OTHER1.getCode());
                    //14年之前 其余街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_OTHER1.getCode());
                }
                if (compensationOldAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 其余街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_OTHER2.getCode());
                    //14年之前 其余街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_OTHER2.getCode());
                }
            }
        }
 
        //14年之后
        else{
            //集体应安置面积
            orgArea = selectCompensateByConfigKey(CompensateEnum.AFTER_ORG_AREA.getCode());
            //非集体应安置面积
            noOrgArea = selectCompensateByConfigKey(CompensateEnum.AFTER_NO_ORG_AREA.getCode());
            if ("崇阳街道、崇庆街道、羊马街道、大划街道".contains(street)) {
                if (compensationNewAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 专属街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_APPOINT1.getCode());
                    //14年之前 专属街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_APPOINT1.getCode());
                }
                if (compensationOldAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 专属街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_APPOINT2.getCode());
                    //14年之前 专属街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_APPOINT2.getCode());
                }
            } else {
                if (compensationNewAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 其他街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_OTHER1.getCode());
                    //14年之前 其他街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_OTHER1.getCode());
                }
                if (compensationOldAmount.compareTo(BigDecimal.ZERO) > 0) {
                    //14年之前 其他街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_OTHER2.getCode());
                    //14年之前 其他街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_OTHER2.getCode());
                }
            }
        }
 
        if (orgArea == null
                || noOrgArea == null
                || orgPrice == null
                || noOrgPrice == null) {
            return false;
        }
 
        //计算应安置面积
        //标准面积
        BigDecimal orgWaitArea = orgArea.getConfigValue().multiply(new BigDecimal(currentCollectiveNum));
        BigDecimal noOrgWaitArea = noOrgArea.getConfigValue().multiply(new BigDecimal(currentNoCollectiveNum));
        //标准赔偿(集体)
        BigDecimal orgAmount = orgWaitArea.multiply(orgPrice.getConfigValue());
        BigDecimal noOrgAmount = noOrgWaitArea.multiply(noOrgPrice.getConfigValue());
        BigDecimal totalAmount = orgAmount.add(noOrgAmount);
        if (money.compareTo(totalAmount) == 0) {
            return true;
        }
 
        return false;
    }
 
    @Override
    public boolean compensateBuyCalculateV2(
            Date time, String street,
            BigDecimal orgArea,BigDecimal noOrgArea,
            String compensationNewAmount,String compensationOldAmount,
            BigDecimal money
    ) {
        List<Compensate> compensates = this.list();
        Map<String, Compensate> configMap = compensates.stream().collect(Collectors.toMap(Compensate::getConfigKey, Function.identity()));
        Date date = DateUtil.parse("2014-01-01 00:00:00","yyyy-MM-dd HH:mm:ss");
 
        Compensate orgPrice = null;
        Compensate noOrgPrice = null;
        //14年之前
        if (time.before(date)) {
            if ("崇阳街道、崇庆街道、羊马街道、大划街道".contains(street)) {
                if (ObjUtil.isNotEmpty(compensationNewAmount)) {
                    //14年之前 专属街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_APPOINT1.getCode());
                    //14年之前 专属街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_APPOINT1.getCode());
                }
                if (ObjUtil.isNotEmpty(compensationOldAmount)) {
                    //14年之前 专属街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_APPOINT2.getCode());
                    //14年之前 专属街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_APPOINT2.getCode());
                }
            } else {
                if (ObjUtil.isNotEmpty(compensationNewAmount)) {
                    //14年之前 其余街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_OTHER1.getCode());
                    //14年之前 其余街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_OTHER1.getCode());
                }
                if (ObjUtil.isNotEmpty(compensationOldAmount)) {
                    //14年之前 其余街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.BEFORE_BUY_ORG_OTHER2.getCode());
                    //14年之前 其余街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.BEFORE_BUY_NO_ORG_OTHER2.getCode());
                }
            }
        }else{
            if ("崇阳街道、崇庆街道、羊马街道、大划街道".contains(street)) {
                if (ObjUtil.isNotEmpty(compensationNewAmount)) {
                    //14年之前 专属街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_APPOINT1.getCode());
                    //14年之前 专属街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_APPOINT1.getCode());
                }
                if (ObjUtil.isNotEmpty(compensationOldAmount)) {
                    //14年之前 专属街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_APPOINT2.getCode());
                    //14年之前 专属街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_APPOINT2.getCode());
                }
            } else {
                if (ObjUtil.isNotEmpty(compensationNewAmount)) {
                    //14年之前 其他街道 集体 新建房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_OTHER1.getCode());
                    //14年之前 其他街道 非集体 新建房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_OTHER1.getCode());
                }
                if (ObjUtil.isNotEmpty(compensationOldAmount)) {
                    //14年之前 其他街道 集体 二手房
                    orgPrice = configMap.get(CompensateEnum.AFTER_BUY_ORG_OTHER2.getCode());
                    //14年之前 其他街道 非集体 二手房
                    noOrgPrice = configMap.get(CompensateEnum.AFTER_BUY_NO_ORG_OTHER2.getCode());
                }
            }
        }
 
        if (orgArea == null
                || noOrgArea == null
                || orgPrice == null
                || noOrgPrice == null) {
            return false;
        }
 
        //标准赔偿(集体)
        BigDecimal orgAmount = orgArea.multiply(orgPrice.getConfigValue());
        BigDecimal noOrgAmount = noOrgArea.multiply(noOrgPrice.getConfigValue());
        BigDecimal totalAmount = orgAmount.add(noOrgAmount);
        if (money.compareTo(totalAmount) == 0) {
            return true;
        }
 
        return false;
    }
 
    @Override
    public boolean compensateSubsidyCalculate(Integer currentCount,BigDecimal money) {
        List<Compensate> compensates = this.list();
        Map<String, Compensate> configMap = compensates.stream().collect(Collectors.toMap(Compensate::getConfigKey, Function.identity()));
        Compensate compensate = configMap.get(CompensateEnum.SUBSIDIES.getCode());
        //元/人/月发送6个月过渡补偿
        BigDecimal subsidy = new BigDecimal(currentCount.toString()).multiply(compensate.getConfigValue()).multiply(new BigDecimal("6"));
        return money.multiply(new BigDecimal("10000")).compareTo(subsidy) == 0;
    }
 
    @Override
    public Compensate selectCompensateByConfigKey(String configKey) {
        LambdaQueryWrapper<Compensate> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Compensate::getConfigKey, configKey);
        return this.baseMapper.selectOne(queryWrapper);
    }
 
    @Override
    public boolean houseCalculate(Integer currentCount, BigDecimal area) {
        List<Compensate> compensates = this.list();
        Map<String, Compensate> configMap = compensates.stream().collect(Collectors.toMap(Compensate::getConfigKey, Function.identity()));
        Compensate compensate = configMap.get(CompensateEnum.HOUSING.getCode());
 
        BigDecimal configArea = compensate.getConfigValue().multiply(new BigDecimal(currentCount));
        if(area.compareTo(configArea) < 0){
            return true;
        }
        return false;
    }
}