CustomerController.java 3.5 KB
package com.huaheng.pc.general.customer.controller;

import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.pc.general.customer.domain.Customer;
import com.huaheng.pc.general.customer.service.ICustomerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户 信息操作处理
 * 
 * @author huaheng
 * @date 2018-08-19
 */
@Controller
@RequestMapping("/general/customer")
public class CustomerController extends BaseController
{
    private String prefix = "general/customer";
	
	@Autowired
	private ICustomerService customerService;
	
	@RequiresPermissions("general:customer:view")
	@GetMapping()
	public String customer()
	{
	    return prefix + "/customer";
	}
	
	/**
	 * 查询客户列表
	 */
	@RequiresPermissions("general:customer:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Customer customer)
	{
		customer.setWarehouseId(ShiroUtils.getWarehouseId());
        customer.setDeleted(false);
		startPage();
		List<Customer> list = customerService.selectListEntityByLike(customer) ;
		return getDataTable(list);
	}
	
	/**
	 * 新增客户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户
	 */
	@RequiresPermissions("general:customer:add")
	@Log(title = "客户", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Customer customer)
	{
        customer.setWarehouseId(ShiroUtils.getWarehouseId());
        customer.setWarehouseCode(ShiroUtils.getWarehouseCode());
        customer.setCreatedBy(ShiroUtils.getLoginName());
        customer.setLastUpdatedBy(ShiroUtils.getLoginName());
        customer.setEnable(true);
        customer.setDeleted(false);
	    return toAjax(customerService.insert(customer));
	}

	/**
	 * 修改客户
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Customer customer = customerService.selectEntityById(id);
		mmap.put("customer", customer);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户
	 */
	@RequiresPermissions("general:customer:edit")
	@Log(title = "客户", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Customer customer)
	{
		customer.setLastUpdatedBy(ShiroUtils.getLoginName());
		return toAjax(customerService.updateByModel(customer));
	}
	
	/**
	 * 删除客户
	 */
	@RequiresPermissions("general:customer:remove")
	@Log(title = "客户", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		if (StringUtils.isEmpty(ids))
			return AjaxResult.error("id不能为空");
		for (Integer id : Convert.toIntArray(ids))
		{
			Customer customer = new Customer();
			customer.setId(id);
			customer.setDeleted(true);
			customer.setLastUpdatedBy(ShiroUtils.getLoginName());
			customerService.updateByModel(customer);
		}
		return AjaxResult.success("删除成功!");
	}
	
}