首页>代码>基于spring boot+spring data jpa+bootstrap的企业级进销存管理系统>/src/main/java/com/java1234/controller/admin/DamageListAdminController.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.DamageList;
import com.java1234.entity.DamageListGoods;
import com.java1234.service.LogService;
import com.java1234.service.UserService;
import com.java1234.service.DamageListGoodsService;
import com.java1234.service.DamageListService;
import com.java1234.util.DateUtil;
import com.java1234.util.StringUtil;

/**
 * 报损单Controller类
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/admin/damageList")
public class DamageListAdminController {

	@Resource
	private DamageListService damageListService;
	
	@Resource
	private DamageListGoodsService damageListGoodsService;
	
	@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 damageList
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	@RequiresPermissions(value = { "报损报溢查询" })
	public Map<String,Object> list(DamageList damageList)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		List<DamageList> damageListList=damageListService.list(damageList, Direction.DESC, "damageDate");
		resultMap.put("rows", damageListList);
		return resultMap;
	}
	
	/**
	 * 根据报损单id查询所有报损单商品
	 * @param damageListId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listGoods")
	@RequiresPermissions(value = { "报损报溢查询" })
	public Map<String,Object> listGoods(Integer damageListId)throws Exception{
		if(damageListId==null){
			return null;
		}
		Map<String, Object> resultMap = new HashMap<>();
		List<DamageListGoods> damageListGoodsList=damageListGoodsService.listByDamageListId(damageListId);
		resultMap.put("rows", damageListGoodsList);
		return resultMap;
	}
	
	
	/**
	 * 获取报损单号
	 * @param type
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/getDamageNumber")
	@RequiresPermissions(value = {"商品报损"})
	public String genBillCode(String type)throws Exception{
		StringBuffer biilCodeStr=new StringBuffer();
		biilCodeStr.append("BS");
		biilCodeStr.append(DateUtil.getCurrentDateStr()); // 拼接当前日期
		String damageNumber=damageListService.getTodayMaxDamageNumber(); // 获取当天最大的报损单号
		if(damageNumber!=null){
			biilCodeStr.append(StringUtil.formatCode(damageNumber));
		}else{
			biilCodeStr.append("0001");
		}
		return biilCodeStr.toString();
	}
	
	/**
	 * 添加报损单 以及所有报损单商品 以及 修改商品的成本均价
	 * @param damageList
	 * @param goodsJson
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions(value = {"商品报损"})
	public Map<String,Object> save(DamageList damageList,String goodsJson)throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		damageList.setUser(userService.findByUserName((String) SecurityUtils.getSubject().getPrincipal())); // 设置操作用户
		Gson gson = new Gson();
		List<DamageListGoods> plgList=gson.fromJson(goodsJson, new TypeToken<List<DamageListGoods>>(){}.getType());
		damageListService.save(damageList, plgList);
		logService.save(new Log(Log.ADD_ACTION,"添加报损单")); 
		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日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友