package com.fuzamei.web;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.fuzamei.constant.HintMSG;
import com.fuzamei.entity.User;
import com.fuzamei.service.CarrierService;
import com.fuzamei.util.JSONUtil;
import com.fuzamei.util.ValidationUtil;

@RestController
@RequestMapping(path="/carrier")
public class CarriersAction {

	@Autowired
	private CarrierService carrierService;
	@PostMapping(value="queryCarriers")
	public Map<String, Object> queryCarriers(@RequestBody String data){
	
		try {
			List<User> list=null;
			@SuppressWarnings("unchecked")
			Map<String, Object> map = JSON.parseObject(data,Map.class);//将前端传过来的json数据转化为map对象，并将map对象传入service层进行数据校验
			int user_id = ValidationUtil.checkAndAssignInt(map.get("user_id"));//   ————————》给个用户id 判断用户id是什么权限
			
			String username=ValidationUtil.checkBlankStringAndAssignEmptyIfIsBlank(map.get("username"));//拿到前端传来的账号去service校验
			Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
			mapToService.put("user_id",user_id );
			mapToService.put("username", username);
			list=carrierService.queryCarriers(mapToService);
			return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, list);
		} catch (Exception e) {
			e.printStackTrace();
			//System.out.println(e.getMessage()+"aa");
			return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
		}
		
	}
	
	
	
	
}
