package com.njcn.serviceimpl.user;

import com.njcn.mapper.configuration.GDInforMapper;
import com.njcn.mapper.user.DeptsGdMapper;
import com.njcn.pojo.configuration.GDInformation;
import com.njcn.pojo.user.DeptsGd;
import com.njcn.service.user.DeptGDService;
import com.njcn.utils.redis.RedisCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DeptGDServiceImpl implements DeptGDService {
    @Resource
    DeptsGdMapper dgm;

    @Resource
    GDInforMapper gd;
    @Autowired
    private RedisCacheUtil redisCacheUtil;

    @Override
    public List<DeptsGd> selectAllGd(String deptsIndex) {
        // TODO Auto-generated method stub
        List<DeptsGd> gds = dgm.selectAllGd(deptsIndex);
         if (isNode(deptsIndex) == 0) {
             DeptsGd g = new DeptsGd();
             g.setDeptsIndex("");
             gds.add(g);
        }
        return gds;
    }

    @Override
    public int insertDeptGd(DeptsGd deptsGd) {
        // TODO Auto-generated method stub
        redisCacheUtil.clearConData();
        return dgm.insert(deptsGd);
    }

    @Override
    public int deleteDeptGd(DeptsGd deptsGd) {
        // TODO Auto-generated method stub
        redisCacheUtil.clearConData();
        return dgm.deleteDeptGd(deptsGd);
    }

    @Override
    public int deleteNowDeptGd(Long gdIndex, String sysType) {
        redisCacheUtil.clearConData();
        return dgm.deleteNowDeptGd(gdIndex, sysType);
    }

    @Override
    public int isNode(String deptsIndex) {
        return dgm.isNode(deptsIndex);
    }

    @Override
    public List<GDInformation> selectAll() {
        // TODO Auto-generated method stub
        return gd.selectAll();
    }


}
