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


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.java1234.entity.Log;
import com.java1234.entity.CustomerReturnList;
import com.java1234.entity.CustomerReturnListGoods;
import com.java1234.service.LogService;
import com.java1234.service.UserService;
import com.java1234.service.CustomerReturnListGoodsService;
import com.java1234.service.CustomerReturnListService;
import com.java1234.util.DateUtil;
import com.java1234.util.StringUtil;

/**
 * 客户退货单Controller类
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/admin/customerReturnList")
public class CustomerReturnListAdminController {

	@Resource
	private CustomerReturnListService customerReturnListService;
	
	@Resource
	private CustomerReturnListGoodsService customerReturnListGoodsService;
	
	@Resource
	private LogService logService;
	
	@Resource
	private UserService userService;
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(true);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值,false:不能为空值
	}
	
	/**
	 * 根据条件分页查询客户退货单信息
	 * @param customerReturnList
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	@RequiresPermissions(value = { "客户退货查询" })
	public Map<String,Object> list(CustomerReturnList customerReturnList)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		List<CustomerReturnList> customerReturnListList=customerReturnListService.list(customerReturnList, Direction.DESC, "customerReturnDate");
		resultMap.put("rows", customerReturnListList);
		return resultMap;
	}
	
	/**
	 * 根据客户退货单id查询所有客户退货单商品
	 * @param customerReturnListId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listGoods")
	@RequiresPermissions(value = { "客户退货查询" })
	public Map<String,Object> listGoods(Integer customerReturnListId)throws Exception{
		if(customerReturnListId==null){
			return null;
		}
		Map<String, Object> resultMap = new HashMap<>();
		List<CustomerReturnListGoods> customerReturnListGoodsList=customerReturnListGoodsService.listByCustomerReturnListId(customerReturnListId);
		resultMap.put("rows", customerReturnListGoodsList);
		return resultMap;
	}
	
	/**
	 * 客户统计 获取客户退货单的所有商品信息
	 * @param purchaseList
	 * @param purchaseListGoods
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listCount")
	@RequiresPermissions(value = { "客户统计" })
	public Map<String,Object> listCount(CustomerReturnList customerReturnList,CustomerReturnListGoods customerReturnListGoods)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		List<CustomerReturnList> customerReturnListList=customerReturnListService.list(customerReturnList, Direction.DESC, "customerReturnDate");
		for(CustomerReturnList crl:customerReturnListList){
			customerReturnListGoods.setCustomerReturnList(crl);
			
			List<CustomerReturnListGoods> crlList=customerReturnListGoodsService.list(customerReturnListGoods);
			for(CustomerReturnListGoods crlg:crlList){
				crlg.setCustomerReturnList(null);
			}
			crl.setCustomerReturnListGoodsList(crlList);
		}
		resultMap.put("rows", customerReturnListList);
		return resultMap;
	}
	
	
	/**
	 * 获取客户退货单号
	 * @param type
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/getCustomerReturnNumber")
	@RequiresPermissions(value = {"客户退货"})
	public String genBillCode(String type)throws Exception{
		StringBuffer biilCodeStr=new StringBuffer();
		biilCodeStr.append("XT");
		biilCodeStr.append(DateUtil.getCurrentDateStr()); // 拼接当前日期
		String customerReturnNumber=customerReturnListService.getTodayMaxCustomerReturnNumber(); // 获取当天最大的客户退货单号
		if(customerReturnNumber!=null){
			biilCodeStr.append(StringUtil.formatCode(customerReturnNumber));
		}else{
			biilCodeStr.append("0001");
		}
		return biilCodeStr.toString();
	}
	
	/**
	 * 添加客户退货单 以及所有客户退货单商品
	 * @param customerReturnList
	 * @param goodsJson
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions(value = {"客户退货"})
	public Map<String,Object> save(CustomerReturnList customerReturnList,String goodsJson)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		customerReturnList.setUser(userService.findByUserName((String) SecurityUtils.getSubject().getPrincipal())); // 设置操作用户
		Gson gson = new Gson();
		List<CustomerReturnListGoods> plgList=gson.fromJson(goodsJson, new TypeToken<List<CustomerReturnListGoods>>(){}.getType());
		customerReturnListService.save(customerReturnList, plgList);
		logService.save(new Log(Log.ADD_ACTION,"添加客户退货单")); 
		resultMap.put("success", true);	
		return resultMap;
	}
	
	/**
	 * 修改退货单的支付状态
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions(value = {"客户统计"})
	public Map<String,Object> update(Integer id)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		CustomerReturnList customerReturnList=customerReturnListService.findById(id);
		customerReturnList.setState(1); // 修改成支付状态
		customerReturnListService.update(customerReturnList);
		resultMap.put("success", true);	
		return resultMap;
	}
	
	/**
	 * 根据id删除客户退货单信息 包括客户退货单里的商品
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/delete")
	@RequiresPermissions(value = { "客户退货查询" })
	public Map<String,Object> delete(Integer id)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		customerReturnListService.delete(id);
		logService.save(new Log(Log.DELETE_ACTION,"删除客户退货单信息"+customerReturnListService.findById(id)));  // 写入日志
		resultMap.put("success", true);		
		return resultMap;
	}
}
最近下载更多
cheung524071  LV8 2023年8月23日
liushao  LV2 2023年5月12日
计算机暴龙战士  LV19 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日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友