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;
|
}
|
|
|
}
|