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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package com.by4cloud.platformx.business.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.business.dto.ZBJTStatisticDTO;
import com.by4cloud.platformx.business.entity.ZbStatisticCpbk;
import com.by4cloud.platformx.business.entity.ZbStatisticXszb;
import com.by4cloud.platformx.business.mapper.ContractOutBoundMapper;
import com.by4cloud.platformx.business.mapper.ContractSubjectMatterMapper;
import com.by4cloud.platformx.business.mapper.ZbStatisticCpbkMapper;
import com.by4cloud.platformx.business.service.ZbStatisticCpbkService;
import com.by4cloud.platformx.business.vo.GcpbkwcqkItemVo;
import com.by4cloud.platformx.business.vo.GcpbkwcqkVo;
import com.by4cloud.platformx.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 产品板块
 *
 * @author syt
 * @date 2026-11-12 10:27:07
 */
@Service
@RequiredArgsConstructor
public class ZbStatisticCpbkServiceImpl extends ServiceImpl<ZbStatisticCpbkMapper, ZbStatisticCpbk> implements ZbStatisticCpbkService {
 
    private final ContractOutBoundMapper contractOutBoundMapper;
    private final ContractSubjectMatterMapper contractSubjectMatterMapper;
 
    @Override
    public R genCpbkwcqk(ZBJTStatisticDTO queryDTO) {
        if (StrUtil.isBlank(queryDTO.getYearMonth())) {
            queryDTO.setYearMonth(DateUtil.format(new Date(), DatePattern.NORM_MONTH_PATTERN));
        }
        List<ZbStatisticCpbk> list = new ArrayList<>();
        Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-01 00:00:00");
        Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59");
        Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-01 00:00:00"), -1);
        Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59"), -1);
        Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0, 4) + "-01-01 00:00:00");
        Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59");
        Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0, 4) + "-01-01 00:00:00"), -1);
        Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59"), -1);
        String curYear = queryDTO.getYearMonth().substring(0, 4);
        String curMonth = queryDTO.getYearMonth().substring(5);
        YearMonth qndy = YearMonth.of(Integer.valueOf(curYear), Integer.valueOf(curMonth)).minusYears(1);
        YearMonth sy = YearMonth.of(Integer.valueOf(curYear), Integer.valueOf(curMonth)).minusMonths(1);
        //新增合同
        List<GcpbkwcqkItemVo> itemVoListMon = contractSubjectMatterMapper.gcpbkwcqk(monstart, monend);
//        List<GcpbkwcqkItemVo> itemVoListMonLastYear = contractSubjectMatterMapper.gcpbkwcqk(monstartLastYear, monendLastYear);
        if (CollUtil.isNotEmpty(itemVoListMon)) {
            itemVoListMon.stream().forEach(item -> {
                ZbStatisticCpbk vo = new ZbStatisticCpbk();
                vo.setXm("新增合同");
                vo.setStatYm(queryDTO.getYearMonth());
                vo.setBkmc(item.getBkmc());
                vo.setDywc(item.getWc());
                ZbStatisticCpbk vo1 = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
                ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                ZbStatisticCpbk cpbkSy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, sy).last("limit 1"));
                if (ObjUtil.isNotNull(vo1)) {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo1.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo1.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo1.setLjwc(cpbkSy.getLjwc().add(vo1.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo1.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo1.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.updateById(vo1);
                    list.add(vo1);
                } else {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo.setLjwc(cpbkSy.getLjwc().add(vo.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.insert(vo);
                    list.add(vo);
                }
            });
        }
//        List<GcpbkwcqkItemVo> itemVoListYear = contractSubjectMatterMapper.gcpbkwcqk(yearstart,yearend);
//        List<GcpbkwcqkItemVo> itemVoListYearLastYear = contractSubjectMatterMapper.gcpbkwcqk(yearstartLastYear,yearendLastYear);
//        if (CollUtil.isNotEmpty(itemVoListYear)){
//            BigDecimal ljzh = itemVoListYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add);
//                for (GcpbkwcqkItemVo itemVo:itemVoListYear
//                ) {
//                    ZbStatisticCpbk vo = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm,"新增合同")
//                            .eq(ZbStatisticCpbk::getBkmc,itemVo.getBkmc()).eq(ZbStatisticCpbk::getStatYm,queryDTO.getYearMonth()).last("limit 1"));
//                    if (StrUtil.equals(vo.getBkmc(),itemVo.getBkmc())&&StrUtil.equals(vo.getXm(),"新增合同")){
//                        vo.setLjwc(itemVo.getWc());
//                        if (ljzh.compareTo(new BigDecimal("0"))>0){
//                            BigDecimal zb = vo.getLjwc().divide(ljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
//                            vo.setBnzb(zb.setScale(2,RoundingMode.HALF_UP)+"%");
//                        }
//
//                    }
//                    if (CollUtil.isNotEmpty(itemVoListYearLastYear)){
//                        BigDecimal qnljzh = itemVoListYearLastYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add);
//
//                        itemVoListYearLastYear.stream().forEach(item1->{
//                            if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&StrUtil.equals(vo.getXm(),"新增合同")&&
//                                    item1.getWc().compareTo(new BigDecimal("0"))>0){
//                                BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
//                                vo.setNtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%");
//                            }
//                            if (qnljzh.compareTo(new BigDecimal("0"))>0){
//                                BigDecimal qnzb = item1.getWc().multiply(new BigDecimal("100")).divide(qnljzh,2,RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
//                                if (StrUtil.isNotBlank(vo.getBnzb())){
//                                    BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0,vo.getBnzb().length()-1));
//                                    vo.setZtqb(bnzb.subtract(qnzb)+"%");
//                                }
//                            }
//                        });
//                    }
//                    baseMapper.updateById(vo);
//                }
//
//        }
        //销售收入
        List<GcpbkwcqkItemVo> itemVoSRListMon = contractOutBoundMapper.gcpbkwcqk(monstart, monend);
        List<GcpbkwcqkItemVo> itemVoListSRMonLastYear = contractOutBoundMapper.gcpbkwcqk(monstartLastYear, monendLastYear);
        if (CollUtil.isNotEmpty(itemVoSRListMon)) {
            itemVoSRListMon.stream().forEach(item -> {
                ZbStatisticCpbk vo = new ZbStatisticCpbk();
                vo.setXm("销售收入");
                vo.setStatYm(queryDTO.getYearMonth());
                vo.setBkmc(item.getBkmc());
                vo.setDywc(item.getWc());
                ZbStatisticCpbk vo1 = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
                ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                ZbStatisticCpbk cpbkSy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, sy).last("limit 1"));
                if (ObjUtil.isNotNull(vo1)) {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo1.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo1.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo1.setLjwc(cpbkSy.getLjwc().add(vo1.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo1.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo1.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.updateById(vo1);
                    list.add(vo1);
                } else {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo.setLjwc(cpbkSy.getLjwc().add(vo.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.insert(vo);
                    list.add(vo);
                }
            });
        }
//        List<GcpbkwcqkItemVo> itemVoListSRYear = contractOutBoundMapper.gcpbkwcqk(yearstart, yearend);
//        List<GcpbkwcqkItemVo> itemVoListSRYearLastYear = contractOutBoundMapper.gcpbkwcqk(yearstartLastYear, yearendLastYear);
//        if (CollUtil.isNotEmpty(itemVoListSRYear)) {
//            BigDecimal ljzh = itemVoListSRYear.stream().map(item -> item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
//            for (GcpbkwcqkItemVo itemVo : itemVoListSRYear
//            ) {
//                ZbStatisticCpbk vo = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, "销售收入")
//                        .eq(ZbStatisticCpbk::getBkmc, itemVo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
//                if (StrUtil.equals(vo.getBkmc(), itemVo.getBkmc()) && StrUtil.equals(vo.getXm(), "销售收入")) {
//                    vo.setLjwc(itemVo.getWc());
//                    if (ljzh.compareTo(new BigDecimal("0")) > 0) {
//                        BigDecimal zb = vo.getLjwc().divide(ljzh, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
//                        vo.setBnzb(zb.setScale(2, RoundingMode.HALF_UP) + "%");
//                    }
//                }
//                if (CollUtil.isNotEmpty(itemVoListSRYearLastYear)) {
//                    BigDecimal qnljzh = itemVoListSRYearLastYear.stream().map(item -> item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    itemVoListSRYearLastYear.stream().forEach(item1 -> {
//                        if (StrUtil.equals(vo.getBkmc(), item1.getBkmc()) && StrUtil.equals(vo.getXm(), "销售收入") &&
//                                item1.getWc().compareTo(new BigDecimal("0")) > 0) {
//                            BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
//                            vo.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
//                        }
//                        if (qnljzh.compareTo(new BigDecimal("0")) > 0) {
//                            BigDecimal qnzb = item1.getWc().multiply(new BigDecimal("100")).divide(qnljzh, 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
//                            if (StrUtil.isNotBlank(vo.getBnzb())) {
//                                BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0, vo.getBnzb().length() - 1));
//                                vo.setZtqb(bnzb.subtract(qnzb) + "%");
//                            }
//                        }
//                    });
//                }
//                baseMapper.updateById(vo);
//            }
//        }
        //货款回收
        List<GcpbkwcqkItemVo> itemVoListSKMon = contractSubjectMatterMapper.gcpbkwcqkBySK(monstart, monend);
        List<GcpbkwcqkItemVo> itemVoListSKMonLastYear = contractSubjectMatterMapper.gcpbkwcqkBySK(monstartLastYear, monendLastYear);
        if (CollUtil.isNotEmpty(itemVoListSKMon)) {
            itemVoListSKMon.stream().forEach(item -> {
                ZbStatisticCpbk vo = new ZbStatisticCpbk();
                vo.setXm("货款回收");
                vo.setStatYm(queryDTO.getYearMonth());
                vo.setBkmc(item.getBkmc());
                vo.setDywc(item.getWc());
                ZbStatisticCpbk vo1 = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
                ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                ZbStatisticCpbk cpbkSy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, vo.getXm())
                        .eq(ZbStatisticCpbk::getBkmc, vo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, sy).last("limit 1"));
                if (ObjUtil.isNotNull(vo1)) {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo1.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo1.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo1.setLjwc(cpbkSy.getLjwc().add(vo1.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo1.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo1.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.updateById(vo1);
                    list.add(vo1);
                } else {
                    if (ObjUtil.isNotNull(cpbkQndy)) {
                        BigDecimal percent = vo.getDywc().subtract(cpbkQndy.getDywc()).divide(cpbkQndy.getDywc(), 10, RoundingMode.HALF_UP)
                                .multiply(new BigDecimal("100"));
                        vo.setYtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    }
                    if (ObjUtil.isNotNull(cpbkSy)) {
                        vo.setLjwc(cpbkSy.getLjwc().add(vo.getDywc()));
                        if (ObjUtil.isNotNull(cpbkQndy) && cpbkQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
                            BigDecimal percent = vo.getLjwc().subtract(cpbkQndy.getLjwc()).divide(cpbkQndy.getLjwc(), 10, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal("100"));
                            vo.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                        }
                    }
                    baseMapper.insert(vo);
                    list.add(vo);
                }
            });
        }
//        List<GcpbkwcqkItemVo> itemVoListSKYear = contractSubjectMatterMapper.gcpbkwcqkBySK(yearstart, yearend);
//        List<GcpbkwcqkItemVo> itemVoListSKYearLastYear = contractSubjectMatterMapper.gcpbkwcqkBySK(yearstartLastYear, yearendLastYear);
//        if (CollUtil.isNotEmpty(itemVoListSKYear)) {
//            for (GcpbkwcqkItemVo itemVo : itemVoListSKYear
//            ) {
//                ZbStatisticCpbk vo = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, "货款回收")
//                        .eq(ZbStatisticCpbk::getBkmc, itemVo.getBkmc()).eq(ZbStatisticCpbk::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
//                if (StrUtil.equals(vo.getBkmc(), itemVo.getBkmc()) && StrUtil.equals(vo.getXm(), "货款回收")) {
//                    vo.setLjwc(itemVo.getWc());
//                }
//                if (CollUtil.isNotEmpty(itemVoListSKYearLastYear)) {
//                    BigDecimal qnljzh = itemVoListSKYearLastYear.stream().map(item -> item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    itemVoListSKYearLastYear.stream().forEach(item1 -> {
//                        if (StrUtil.equals(vo.getBkmc(), item1.getBkmc()) && StrUtil.equals(vo.getXm(), "货款回收") &&
//                                item1.getWc().compareTo(new BigDecimal("0")) > 0) {
//                            BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
//                            vo.setNtqb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
//                        }
//                        if (qnljzh.compareTo(new BigDecimal("0")) > 0) {
//                            BigDecimal qnzb = item1.getWc().multiply(new BigDecimal("100")).divide(qnljzh, 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
//                            if (StrUtil.isNotBlank(vo.getBnzb())) {
//                                BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0, vo.getBnzb().length() - 1));
//                                vo.setZtqb(bnzb.subtract(qnzb) + "%");
//                            }
//                        }
//                    });
//                }
//                baseMapper.updateById(vo);
//            }
//        }
        BigDecimal htzh = list.stream().filter(item->StrUtil.equals(item.getXm(),"新增合同")).map(item -> item.getDywc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal srzh = list.stream().filter(item->StrUtil.equals(item.getXm(),"销售收入")).map(item -> item.getDywc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal hkzh = list.stream().filter(item->StrUtil.equals(item.getXm(),"货款回收")).map(item -> item.getDywc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
        if (CollUtil.isNotEmpty(list)){
            list.stream().forEach(item->{
                if (StrUtil.equals(item.getXm(),"新增合同")&&htzh.compareTo(new BigDecimal("0"))>0){
                    BigDecimal percent = item.getDywc().divide(htzh, 10, RoundingMode.HALF_UP)
                            .multiply(new BigDecimal("100"));
                    item.setBnzb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, item.getXm())
                            .eq(ZbStatisticCpbk::getBkmc, item.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                    if (ObjUtil.isNotNull(cpbkQndy)&&ObjUtil.isNotNull(cpbkQndy.getBnzb())){
                        BigDecimal qnbnzb = new BigDecimal(cpbkQndy.getBnzb().substring(0, cpbkQndy.getBnzb().length() - 1));
                        item.setZtqb(percent.subtract(qnbnzb) + "%");
                    }
                    baseMapper.updateById(item);
                }
                if (StrUtil.equals(item.getXm(),"销售收入")&&srzh.compareTo(new BigDecimal("0"))>0){
                    BigDecimal percent = item.getDywc().divide(srzh, 10, RoundingMode.HALF_UP)
                            .multiply(new BigDecimal("100"));
                    item.setBnzb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, item.getXm())
                            .eq(ZbStatisticCpbk::getBkmc, item.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                    if (ObjUtil.isNotNull(cpbkQndy)&&ObjUtil.isNotNull(cpbkQndy.getBnzb())){
                        BigDecimal qnbnzb = new BigDecimal(cpbkQndy.getBnzb().substring(0, cpbkQndy.getBnzb().length() - 1));
                        item.setZtqb(percent.subtract(qnbnzb) + "%");
                    }
                    baseMapper.updateById(item);
                }
                if (StrUtil.equals(item.getXm(),"货款回收")&&hkzh.compareTo(new BigDecimal("0"))>0){
                    BigDecimal percent = item.getDywc().divide(hkzh, 10, RoundingMode.HALF_UP)
                            .multiply(new BigDecimal("100"));
                    item.setBnzb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
                    ZbStatisticCpbk cpbkQndy = baseMapper.selectOne(Wrappers.<ZbStatisticCpbk>lambdaQuery().eq(ZbStatisticCpbk::getXm, item.getXm())
                            .eq(ZbStatisticCpbk::getBkmc, item.getBkmc()).eq(ZbStatisticCpbk::getStatYm, qndy).last("limit 1"));
                    if (ObjUtil.isNotNull(cpbkQndy)&&ObjUtil.isNotNull(cpbkQndy.getBnzb())){
                        BigDecimal qnbnzb = new BigDecimal(cpbkQndy.getBnzb().substring(0, cpbkQndy.getBnzb().length() - 1));
                        item.setZtqb(percent.subtract(qnbnzb) + "%");
                    }
                    baseMapper.updateById(item);
                }
            });
        }
        return R.ok();
    }
}