首页>代码>基于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;
}
}
最近下载更多
monster_001 LV3
2月27日
dane168 LV10
2月25日
lz88888 LV12
2024年10月18日
微信网友_7134912998903808 LV15
2024年9月11日
shuo04 LV1
2024年7月12日
sunlea LV20
2024年6月24日
cheung524071 LV8
2023年8月23日
liushao LV2
2023年5月12日
计算机暴龙战士 LV19
2023年4月2日
hbsoft2008 LV16
2023年3月24日
最近浏览更多
hulewang LV8
7月23日
monster_001 LV3
2月27日
dane168 LV10
2月25日
huasir2018 LV14
1月29日
xianyu091012 LV5
2024年11月18日
lz88888 LV12
2024年10月18日
微信网友_7134912998903808 LV15
2024年9月11日
248727703 LV1
2024年7月14日
shuo04 LV1
2024年7月12日
sunlea LV20
2024年6月23日

