package com.rf.psychological.scale.service.impl;


import com.rf.psychological.scale.dao.model.CategoryEntity;
import com.rf.psychological.dao.repository.CategoryRepository;
import com.rf.psychological.scale.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zsy
 * @description:量表类别信息管理
 * @date 2021/6/17 15:55
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;


    /**
     * 保存
     *
     * @param categoryEntity
     */
    @Override
    public void save(CategoryEntity categoryEntity) {
        this.categoryRepository.save(categoryEntity);
    }

    /**
     * 获取量表类别列表
     * @return
     *//*
    @Override
    public List<CategoryEntity> findAll(int pageNum, int pageSize) {
        int beginIndex = (pageNum-1)*pageSize;
        return this.categoryRepository.findAll( beginIndex,  pageSize);
    }

    *//**
     * 总条数
     * @return
     *//*
    @Override
    public int allNum() {
        return this.categoryRepository.allNum();
    }

    *//**
     * 根据名称模糊查询列表
     * @return
     *//*
    @Override
    public List<CategoryEntity> getSubjectListByName(int pageNum, int pageSize, String searchStr) {
        int beginIndex = (pageNum-1)*pageSize;
        return this.categoryRepository.getSubjectListByName( beginIndex,  pageSize, searchStr);
    }

    *//**
     * 根据名称模糊查询总条数
     * @return
     *//*
    @Override
    public int allNumByName(String searchStr) {
        return this.categoryRepository.allNumByName(searchStr);
    }*/

    /**
     * 效验是否存在
     *
     * @return
     */
    @Override
    public List<CategoryEntity> getCategoryByName(String name, String ename, String sequence) {
        return this.categoryRepository.getCategoryByName(name, ename, sequence);
    }

    /**
     * 查询所有类别信息
     *
     * @return
     */
    @Override
    public List<CategoryEntity> findAll(String type) {
        return this.categoryRepository.findAllOrder(type);
    }

    /**
     * 查询所有类别信息
     * @return
     */
    @Override
    public List<CategoryEntity> findAlls() {

        return this.categoryRepository.findAll();
    }

    @Override
    public List<CategoryEntity> findAllCT(String institutionNo, String groupId) {
        if (groupId.equals("") || groupId.equals("0")) {
            return this.categoryRepository.findAllCTInstitution(institutionNo);
        } else {
            return this.categoryRepository.findAllCTByGroup(groupId);
        }
    }



    @Override
    public List<CategoryEntity> findALLCategorySubject(String institutionNo, String groupId) {
        if (groupId.equals("") || groupId.equals("0")) {
            return this.categoryRepository.findAllSubjectInstitution(institutionNo);
        } else {
            return this.categoryRepository.findAllSubjectGroup(groupId);
        }
    }

    /**
     * 根据id查询类别详细信息
     *
     * @param id
     * @return
     */
    @Override
    public CategoryEntity findById(String id) {
        return this.categoryRepository.findById(id).orElse(null);
    }

    /**
     * 根据id查询类别详细信息
     * @return
     */
    /*@Override
    public CategoryEntity getone(String id) {
        return this.categoryRepository.getOne(id);
    }*/
}
