package lingtao.net.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

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

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lingtao.net.bean.ExpressFee;
import lingtao.net.bean.Msg;
import lingtao.net.service.ExpressFeeService;

@RestController
public class ExpressFeeController {

	@Autowired
	private ExpressFeeService expressFeeService;

	/**
	 * 省份快递费列表
	 * 
	 * @return
	 */
	@RequestMapping("/getExpressFees")
	public Msg getExpressFees(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit, ExpressFee expressFee) {
		PageHelper.startPage(page, limit);
		// 带分页，用于列表展示
		List<ExpressFee> expressFeeList = expressFeeService.getExpressFees(expressFee);
		// 全国省份
		List<ExpressFee> allProvinces = expressFeeService.getAllExpressFees(expressFee);
		// 手提袋偏远地区运费
		List<ExpressFee> handBagExpressFees = expressFeeService.getHandBagExpressFees(expressFee);
		// 封套:6、房卡套:7、吊旗:13
		List<ExpressFee> taoExpressFees = expressFeeService.getTaoExpressFees(expressFee);
		// 其他产品偏远地区运费
		List<ExpressFee> orherExpressFees = expressFeeService.getOtherExpressFees(expressFee);
		PageInfo<ExpressFee> pageInfo = new PageInfo<ExpressFee>(expressFeeList);
		return Msg.success().add("list", pageInfo).add("allProvinces", allProvinces).add("handBag", handBagExpressFees)
				.add("tao", taoExpressFees).add("other", orherExpressFees);
	}

	/**
	 * 添加省份快递费
	 */
	@RequestMapping("/addExpressFee")
	public Msg addExpressFee(ExpressFee expressFee, HttpSession session) {
		expressFeeService.addExpressFee(expressFee, session);
		return Msg.success();
	}

	/**
	 * 修改省份快递费
	 */
	@RequestMapping("/updateExpressFee")
	public Msg updateExpressFee(HttpSession session, @RequestParam(value = "id") int id,
			@RequestParam(value = "field") String field, @RequestParam(value = "value") String value) throws Exception {
		return expressFeeService.updateExpressFeeById(session, id, field, value);
	}

	/**
	 * 删除
	 */
	@RequestMapping("/deleteExpressFee")
	public Msg deleteExpressFee(@RequestParam("id") Integer id) {
		expressFeeService.deleteExpressFeeById(id);
		return Msg.success();
	}
}
