首页>代码>基于spring boot+spring data jpa+bootstrap的企业级进销存管理系统>/src/main/java/com/java1234/controller/admin/CustomerAdminController.java
package com.java1234.controller.admin;

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

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.java1234.entity.Customer;
import com.java1234.entity.Log;
import com.java1234.service.CustomerService;
import com.java1234.service.LogService;

/**
 * 后台管理客户Controller
 * @author java1234 小锋 老师
 *
 */
@RestController
@RequestMapping("/admin/customer")
public class CustomerAdminController {
	
	@Resource
	private CustomerService customerService;
	
	@Resource
	private LogService logService;
	
	/**
	 * 分页查询客户信息
	 * @param customer
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	@RequiresPermissions(value = { "客户管理" })
	public Map<String,Object> list(Customer customer,@RequestParam(value="page",required=false)Integer page,@RequestParam(value="rows",required=false)Integer rows)throws Exception{
		List<Customer> customerList=customerService.list(customer, page, rows, Direction.ASC, "id");
		Long total=customerService.getCount(customer);
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("rows", customerList);
		resultMap.put("total", total);
		logService.save(new Log(Log.SEARCH_ACTION,"查询客户信息")); // 写入日志
		return resultMap;
	}
	
	/**
	 * 下拉框模糊查询
	 * @param q
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/comboList")
	@RequiresPermissions(value = {"销售出库","客户退货","销售单据查询","客户退货查询"},logical=Logical.OR)
	public List<Customer> comboList(String q)throws Exception{
		if(q==null){
			q="";
		}
		return customerService.findByName("%"+q+"%");
	}
	
	
	/**
	 * 添加或者修改客户信息
	 * @param customer
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/save")
	@RequiresPermissions(value = { "客户管理" })
	public Map<String,Object> save(Customer customer)throws Exception{
		if(customer.getId()!=null){ // 写入日志
			logService.save(new Log(Log.UPDATE_ACTION,"更新客户信息"+customer)); 
		}else{
			logService.save(new Log(Log.ADD_ACTION,"添加客户信息"+customer)); 
		}
		Map<String, Object> resultMap = new HashMap<>();
		customerService.save(customer);			
		resultMap.put("success", true);
		return resultMap;
	}
	
	
	/**
	 * 删除客户信息
	 * @param id
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/delete")
	@RequiresPermissions(value = { "客户管理" })
	public Map<String,Object> delete(String ids)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		String []idsStr=ids.split(",");
		for(int i=0;i<idsStr.length;i++){
			int id=Integer.parseInt(idsStr[i]);
			logService.save(new Log(Log.DELETE_ACTION,"删除客户信息"+customerService.findById(id)));  // 写入日志
			customerService.delete(id);							
		}
		resultMap.put("success", true);
		return resultMap;
	}

}
最近下载更多
cheung524071  LV8 2023年8月23日
liushao  LV2 2023年5月12日
计算机暴龙战士  LV16 2023年4月2日
hbsoft2008  LV16 2023年3月24日
quyan5632  LV2 2023年1月30日
wuying8208  LV15 2023年1月1日
我是helloworld  LV23 2022年11月25日
chenli1212  LV5 2022年9月10日
W_123456  LV8 2022年6月8日
yayacui  LV2 2022年5月25日
最近浏览更多
PSSDZH  LV3 1月25日
952773464 1月15日
暂无贡献等级
lilong007  LV20 2023年12月30日
admin_z  LV22 2023年12月22日
fff2003  LV6 2023年12月21日
ysugxx  LV9 2023年12月13日
wnnmmb  LV2 2023年11月12日
syhsyhzxhzxh  LV3 2023年10月23日
irivn007  LV15 2023年10月19日
类人孩 2023年9月30日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友