kimi
2020-11-27 75c32d6d697a550400d0b4eec95b8570d83b726f
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
package com.highdatas.srs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.highdatas.srs.entity.Scheme;
import com.highdatas.srs.entity.SchemeBill;
import com.highdatas.srs.mapper.SchemeMapper;
import com.highdatas.srs.service.ISchemeBillService;
import com.highdatas.srs.service.ISchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kimi
 * @since 2020-01-15
 */
@Service
public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, Scheme> implements ISchemeService {
    @Autowired
    ISchemeBillService billService;
    @Override
    public Scheme refreshBudget(String schemeId) {
        Scheme scheme = selectById(schemeId);
        if (scheme == null) {
            return null;
        }
        BigDecimal decimal = new BigDecimal(0);
        List<SchemeBill> parent_id = billService.selectList(new EntityWrapper<SchemeBill>().eq("parent_id", schemeId));
        if (parent_id != null) {
            for (SchemeBill schemeBill : parent_id) {
                BigDecimal money = schemeBill.getMoney();
                if (money != null) {
                    decimal = decimal.add(money);
                }
            }
            scheme.setBudget(decimal).updateById();
        }
        return scheme;
    }
 
    @Override
    public Scheme refreshCheckMoney(String schemeId) {
        Scheme scheme = selectById(schemeId);
        if (scheme == null) {
            return null;
        }
        BigDecimal decimal = new BigDecimal(0);
        List<SchemeBill> parent_id = billService.selectList(new EntityWrapper<SchemeBill>().eq("parent_id", schemeId));
        if (parent_id != null) {
            for (SchemeBill schemeBill : parent_id) {
                BigDecimal money = schemeBill.getMoney();
                Boolean checked = schemeBill.getChecked();
                if (money != null && checked != null && checked) {
                    decimal = decimal.add(money);
                }
            }
            scheme.setPayMoney(decimal).updateById();
        }
        return scheme;
    }
}