package com.fuzamei.service.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fuzamei.constant.Roles;
import com.fuzamei.entity.User;
import com.fuzamei.mapperInterface.ReceivingClerkMapper;
import com.fuzamei.mapperInterface.SupplierMapper;
import com.fuzamei.service.SupplierService;

@Service
public class SupplierServiceImpl implements  SupplierService {
	@Autowired
	private  SupplierMapper supplierMapper;
	@Autowired
	private ReceivingClerkMapper receivingClerkMapper;
	
	@Override
	public List<User> querySupplier(Map<String, Object> map) {
		  List<User>  user= null; 
			//Map<String, Object> account = new LinkedHashMap<String, Object>(); 
		    int user_id=(int) map.get("user_id");
			String username=(String) map.get("username");
			System.out.println(username+"kkkkk");
			String role=receivingClerkMapper.selectRoleByUserId(user_id);//通过用户id查询角色   如果角色是管理员就可以看查看供应商列表
		/*	if (role.equals(Roles.ADMIN)) {
				user=supplierMapper.querySupplier(map);
			}
			else if (username!=null || !username.equals("")) {
				user=supplierMapper.querySupplier(map);
			}else {
				throw  new RuntimeException("账号异常3");
			}*/
			if (role.equals(Roles.ADMIN)) {
				user=supplierMapper.querySupplier(map);
			} 
			if (!role.equals(Roles.ADMIN)){
				throw  new RuntimeException("只能管理员查看");
			}
			if(username!=null || !username.equals("")) {
				user=supplierMapper.querySupplier(map);
			}
			
			 return user;
		//XXX 四个列表都一样这里要加个判断输入个错误的名字会怎样
	}

	@Override
	public List<User> queryPlannerBySupplierId(int supplierId) {//点击查看  根据供应商id   查询所有所属计划员
		return supplierMapper.queryPlannerBySupplierId(supplierId);
	}
}
