zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package com.changhong.epc.admin.service.cost.impl;
 
import com.changhong.epc.admin.mapper.centen.cost.CostFromTemplateMapper;
import com.changhong.epc.admin.mapper.centen.cost.CostGroupTypeMapper;
import com.changhong.epc.admin.service.cost.CostGroupTypeService;
import com.changhong.epc.bean.admin.CostFromTemplate;
import com.changhong.epc.bean.admin.CostGroupType;
import com.changhong.epc.bean.admin.extend.CostGroupTypeExtend;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service("costGroupTypeServiceImpl")
public class CostGroupTypeSerivceImpl implements CostGroupTypeService {
 
    @Resource
    private CostGroupTypeMapper costGroupTypeMapper;
 
    @Resource
    private CostFromTemplateMapper costFromTemplateMapper;
    @Resource
    private CostGroupTypeService costGroupTypeService;
 
    //查询费用组费用类型,以及相关票据数量查询
    @Override
    public List<CostGroupTypeExtend> selectTree(CostGroupType costGroupType) {
        List<CostGroupTypeExtend> costGroupTypeExtends = costGroupTypeMapper.selectTree(costGroupType);
        if(!CollectionUtils.isEmpty(costGroupTypeExtends)){
            for (CostGroupTypeExtend costGroupTypeExtend : costGroupTypeExtends) {
                List<CostGroupTypeExtend> costgt = costGroupTypeExtend.getCostgt();
                    if(!CollectionUtils.isEmpty(costgt)){
                    for (CostGroupTypeExtend costGroupTypeExtend1 :costgt){
                        CostGroupTypeExtend costGroupTypeExtend2 = costGroupTypeService.selectTreeOne(costGroupTypeExtend1);
                        if (!ObjectUtils.isEmpty(costGroupTypeExtend2) && !CollectionUtils.isEmpty(costGroupTypeExtend2.getCostFromTemplate())){
                            costGroupTypeExtend1.setCountForm(costGroupTypeExtend2.getCostFromTemplate().size());
                       }
                    }
                }
                continue;
            }
            return costGroupTypeExtends;
        }
        return null;
    }
 
    //添加费用组费用类型
    @Override
    public CostGroupType addCostType(CostGroupTypeExtend costGroupType) {
        costGroupType.initParam();
        int i = 0;
 
        costGroupTypeMapper.insertSelective(costGroupType);
        if ((costGroupType.getCostFromTemplate().size()) > 0) {
            for (CostFromTemplate form : costGroupType.getCostFromTemplate()) {
                if (form.getFId() != null && !form.getFId().equals("")) {
                    form.setCtId(costGroupType.getId());
                    form.initParam();
                    costFromTemplateMapper.insert(form);
                }
            }
        }
        if (costGroupType.getParentId() == 0) {
            CostGroupTypeExtend cte = new CostGroupTypeExtend();
            cte.SetProperties(costGroupType);
            return cte;
 
        } else if (costGroupType.getParentId() != 0) {
            costFromTemplateMapper.deleteForm(costGroupType.getParentId());
 
        }
        return costGroupType;
    }
 
    //修改费用组费用类型
    @Override
    public int updateCostType(CostGroupTypeExtend costGroupType) {
        return costGroupTypeMapper.updateCost(costGroupType);
    }
 
    @Override
    public int deleteCostType(CostGroupType costGroupType) {
        return costGroupTypeMapper.updateByPrimaryKeySelective(costGroupType);
    }
 
    //分页查询父类与所有子类
    @Override
    public List<CostGroupTypeExtend> selectTreePage(CostGroupType costGroupType) {
        costGroupType.setDataStart(0);
        List<CostGroupTypeExtend> list = costGroupTypeMapper.selectTreePage(costGroupType);
        CostFromTemplate costForm = new CostFromTemplate();
        for (CostGroupTypeExtend cost : list) {
            costForm.setCtId(cost.getId());
            cost.setCostFromTemplate(costFromTemplateMapper.select(costForm));
            for (CostGroupTypeExtend costs : cost.getCostgt()) {
                costForm.setCtId(cost.getId());
                costs.setCostFromTemplate(costFromTemplateMapper.select(costForm));
            }
        }
        return list;
    }
 
    //查询子节点与其父节点
    @Override
    public CostGroupTypeExtend selectTreeOne(CostGroupType costGroupType) {
        costGroupType.setDataStart(0);
        CostGroupTypeExtend list = costGroupTypeMapper.selectTreeOne(costGroupType);
        CostFromTemplate costForm = new CostFromTemplate();
        costForm.setCtId(list.getId());
        list.setCostFromTemplate(costFromTemplateMapper.select(costForm));
 
 
        return list;
    }
 
 
}