package com.gjp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gjp.bean.BaseDict;
import com.gjp.bean.Customer;
import com.gjp.bean.Page;
import com.gjp.bean.QueryVo;
import com.gjp.service.CustomerService;

@Controller
@RequestMapping("/customer")
public class CustomerController {
	
	@Autowired
	private CustomerService customerService;

	/**
	 * 高级查询列表信息
	 */
	@Value("${customer.dict.from}")		//客户信息来源  002
	private String from;
	@Value("${customer.dict.industry}")	//所属行业  001
	private String industry;
	@Value("${customer.dict.level}")	//所属级别  006
	private String level;
	
	/**
	 * 客户列表
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	public String list(QueryVo vo,Model model) throws Exception {
		//客户信息来源  002
		List<BaseDict> sourceList = customerService.findDictByCode(from);
		//所属行业  001
		List<BaseDict> industryList = customerService.findDictByCode(industry);
		//所属级别  006
		List<BaseDict> levelList = customerService.findDictByCode(level);
		
		//查询数据列表和数据总数
		List<Customer> resultList = customerService.findCustomerByVo(vo);
		Integer count = customerService.findCustomerByVoCount(vo);

		//分页对象
		Page<Customer> page = new Page<Customer>();
		page.setTotal(count);				//数据总数
		page.setSize(vo.getSize());			//每页显示个数
		page.setCurrentPage(vo.getPage());	//当前页数
		page.setRows(resultList);			//列表数据
		//计算总页数
    	int pageCount = page.getTotal() / page.getSize();
    	if (page.getTotal() % page.getSize() > 0) {
    		pageCount++;
    	}
    	page.setPageCount(pageCount);//总页数
		
		//分页查询数据
		model.addAttribute("page",page);
		//高级查询数据
		model.addAttribute("fromType",sourceList);
		model.addAttribute("industryType",industryList);
		model.addAttribute("levelType",levelList);
		//高级查询数据回显
		model.addAttribute("custName",vo.getCustName());
		model.addAttribute("custSource",vo.getCustSource());
		model.addAttribute("custIndustry",vo.getCustIndustry());
		model.addAttribute("custLevel",vo.getCustLevel());
		return "customer";
	}
	
	/**
	 * 客户详情信息
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/detail")
	@ResponseBody
	public Customer detail(Long id) throws Exception{
		Customer customer = customerService.findCustomerById(id);
		return customer;
	}

	/**
	 * 更新客户
	 * @param customer
	 * @throws Exception
	 */
	@RequestMapping("/update")
	public String update(Customer customer) throws Exception{
		customerService.updateCustomerById(customer);
		return "customer";
	}
	
	/**
	 * 删除客户
	 * @param id
	 * @throws Exception
	 */
	@RequestMapping("/delete")
	public String delete(Long id) throws Exception{
		customerService.deleteCustomerById(id);
		return "customer";
	}

	/**
	 * 添加客户
	 * @param customer
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/add")
	public String add(Customer customer) throws Exception{
		customerService.addCustomer(customer);
		return "customer";
	}
}
最近下载更多
森sdfgf  LV8 2月8日
zhunishimian  LV6 2023年5月22日
and123456  LV11 2022年7月12日
testuser1234567  LV24 2022年5月23日
Justice_Eternal  LV14 2022年4月12日
wanglinddad  LV54 2022年4月11日
543666826  LV33 2021年11月28日
haiwen  LV19 2021年9月9日
vNOCTISv  LV4 2021年7月27日
lianghui  LV13 2021年7月14日
最近浏览更多
shenghaer  LV1 2月9日
森sdfgf  LV8 2月8日
阿凡达  LV9 1月29日
admin_z  LV22 1月29日
binlong520 1月10日
暂无贡献等级
black8angel  LV4 2023年12月22日
wuge123  LV8 2023年12月18日
pangzhihui  LV12 2023年12月9日
yuan_bin1990  LV7 2023年10月9日
zhaozhiqi  LV5 2023年10月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友