package com.ann.demo.service.impl;

import com.ann.demo.entity.normalEntity.Department;
import com.ann.demo.entity.normalEntity.User;
import com.ann.demo.repository.DepartmentRepository;
import com.ann.demo.repository.UserRepository;
import com.ann.demo.service.DepartmentService;
import com.ann.demo.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Date 2019/7/9 16:43
 * @Created by  ljx
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {

    static final Logger logger = LoggerFactory.getLogger(DepartmentServiceImpl.class);

    @Autowired
    DepartmentRepository departmentRepository;

    @Override
    public void save(Department department) {
        //打日志信息
        try {
            departmentRepository.save(department);
        } catch (Exception e) {
            logger.error("出错咯！错误信息:" + e);
        }
    }

    @Override
    public void delete(Department department) {
        //打日志信息
        try {
            departmentRepository.delete(department);
        } catch (Exception e) {
            logger.error("出错咯！错误信息:" + e);
        }
    }

    @Override
    public Department findDepartment(String user_dept) {
        // ------------------确认 isValid 0是正常 1是停用
        return departmentRepository.findDepartmentByDeptCodeAndIsValid(user_dept, 0);
    }
}
