CustomerController.java 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
package com.hqyj.seven.controller;

import com.hqyj.seven.pojo.Customer;
import com.hqyj.seven.pojo.House;
import com.hqyj.seven.pojo.PageData;
import com.hqyj.seven.service.CustomerService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    CustomerService customerService;
    @RequestMapping("/getallcus")
    @ResponseBody
    public Map<String,Object> getAllcus(){
        List<Customer> customerList = customerService.queryAll();
        Map<String,Object> customer =   new HashMap<>();
        if (customerList == null){
            customer.put("code",-1);
N
nrd 已提交
30
            customer.put("msg","没有客户信息");
31 32 33 34 35 36 37 38 39
        }else {
            customer.put("code", 0);
            customer.put("data", customerList);
            customer.put("msg","获取数据成功!");
        }
        Session session= SecurityUtils.getSubject().getSession();
        session.setAttribute("customerList",customerList);
        return customer;
    }
N
nrd 已提交
40 41 42 43 44 45


    @RequestMapping("/getonecus")
    @ResponseBody
    public Map<String,Object> getonecus(String name){
        Map<String,Object> customer = new HashMap<>();
46 47 48 49 50
        if (name==null){
            customer.put("code",-1);
            customer.put("message","查询名不为空");
        } else {
            List<Customer> customerList = customerService.queryByCusName(name);
N
nrd 已提交
51
            if (customerList != null) {
52 53 54
                customer.put("code", 1);
                customer.put("message", "查询成功");
                customer.put("data", customerList);
N
nrd 已提交
55 56 57

            } else {
                customer.put("code", 0);
N
nrd 已提交
58
                customer.put("message", "没有查询到姓名为:" + name + "的客户信息");
59
            }
N
nrd 已提交
60 61 62
        }
        return customer;
    }
63 64 65 66 67
    @RequestMapping("/updateonecus")
    @ResponseBody
    public  Map<String,Object> updateonecus(Customer customer){
         int customernum = customerService.updataOneCus(customer);
        Map<String,Object> customermap = new HashMap<>();
N
nrd 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81
        if (customernum == 0){
            customermap.put("code",-1);
            customermap.put("message","修改失败");
        }else {
            customermap.put("code",200);
            customermap.put("message","修改成功");
        }
        return customermap;
    }
    @RequestMapping("/insertonecus")
    @ResponseBody
    public  Map<String,Object> insertonecus(Customer customer){
        int customernum = customerService.insertOneCus(customer);
        Map<String,Object> customermap = new HashMap<>();
82 83 84 85 86 87 88 89 90
        if (customernum == 0){
            customermap.put("code",-1);
            customermap.put("message","插入失败");
        }else {
            customermap.put("code",200);
            customermap.put("message","插入成功");
        }
        return customermap;
    }
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    //客户信息的删除
    @RequestMapping("/deleteHouse")
    @ResponseBody
    public Map<String,Object> deleteHousei(int customer_id){
        Map<String,Object> customermap =  new HashMap<>();
        int num = customerService.deleteOneCus(customer_id);
        if (num==0){
            customermap.put("code",0);
            customermap.put("message","删除失败!");
        }else {
            customermap.put("code",200);
            customermap.put("message","删除成功!");
        }
        return customermap;
    }
106
}