AreaServiceImpl.java 1.9 KB
/*
 * Copyright (c) 2018, 2028, glsx and/or its affiliates. All rights reserved.
 * GLSX PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package com.glsx.usercenter.service.impl;


import com.glsx.usercenter.mapper.SysAreaMapper;
import com.glsx.usercenter.pojo.user.SysArea;
import com.glsx.usercenter.pojo.user.SysAreaExample;
import com.glsx.usercenter.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Zheng Xiajun
 * @ClassName: AreaServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019年1月23日
 */
@Service
public class AreaServiceImpl implements IAreaService {


    @Autowired
    private SysAreaMapper sysAreaMapper;

    @Override
    public List<SysArea> selectByExample(SysAreaExample example) {

        return sysAreaMapper.selectByExample(example);
    }


    @Override
    public SysArea getAllChargeItems(Integer id) {
        SysArea prandPa = new SysArea();

        SysAreaExample example = new SysAreaExample();
        example.createCriteria().andIdEqualTo(id);
        List<SysArea> child = sysAreaMapper.selectByExample(example);
        example.clear();
        example.createCriteria().andIdEqualTo(child.get(0).getParentId());
        List<SysArea> parent = sysAreaMapper.selectByExample(example);
        if (!parent.isEmpty()) {
            example.clear();
            example.createCriteria().andIdEqualTo(parent.get(0).getParentId());
            prandPa = sysAreaMapper.selectByExample(example).get(0);
            if (prandPa != null){
                parent.get(0).setChildren(child);
                prandPa.setChildren(parent);
            }
        }
        return prandPa;
    }

}