package com.pj.project.tb_goods;

import java.util.Date;
import java.util.List;

import com.pj.project.relation_goods_type.RelationGoodsType;
import com.pj.project.tb_item_type.TbItemType;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.project4sp.SP;

import com.pj.current.satoken.StpUserUtil;
import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: tb_goods -- 商品管理
 * @author qzy 
 */
@RestController
@RequestMapping("/TbGoods/")
public class TbGoodsController {

	/** 底层 Service 对象 */
	@Autowired
	TbGoodsService tbGoodsService;

	/** 增 */  
	@RequestMapping("add")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_ADD)
	public AjaxJson add(TbGoods t){
		t.setCreateTime(new Date());
		tbGoodsService.save(t);
		return AjaxJson.getSuccessData(t);
	}

	/** 删 */  
	@RequestMapping("delete")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_DEL)
	public AjaxJson delete(Long id){
		tbGoodsService.removeById(id);
		return AjaxJson.getSuccess();
	}
	

	
	/** 改 */  
	@RequestMapping("update")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson update(TbGoods t){
		tbGoodsService.update(t);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbGoods t = tbGoodsService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
	public AjaxJson getList() { 
		SoMap so = SoMap.getRequestSoMap();
		List<TbGoods> list = tbGoodsService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}
	
	
	
	/** 改 - 状态(1=禁用,2=启用) */  
	@RequestMapping("updateStatus")
	@SaCheckPermission(TbGoods.PERMISSION_CODE)
	public AjaxJson updateStatus(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "status", value, id);
		return AjaxJson.getByLine(line);
	}




	/** 改 - 载重是否必填(1=是,0=否) */
	@RequestMapping("updateNeedWeight")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateNeedWeight(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "need_weight", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 规格是否必填(1=是,0=否) */
	@RequestMapping("updateNeedCarSize")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateNeedCarSize(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "need_car_size", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 申报单是否必填(1=是,0=否) */
	@RequestMapping("updateNeedDeclare")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateNeedDeclare(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "need_declare", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 申报时间是否必填(1=是,0=否) */
	@RequestMapping("updateNeedOperateTime")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateNeedOperateTime(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "need_operate_time", value, id);
		return AjaxJson.getByLine(line);
	}
	/** 改 - 申报时间是否必填(1=是,0=否) */
	@RequestMapping("updateVietnamCarPay")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateVietnamCarPay(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "vietnam_car_pay", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 申报时间是否必填(1=是,0=否) */
	@RequestMapping("updateChinaCarPay")
	@SaCheckPermission(TbGoods.PERMISSION_CODE_EDIT)
	public AjaxJson updateChinaCarPay(Long id, String value){
		int line = SP.publicMapper.updateColumnById(TbGoods.TABLE_NAME, "china_car_pay", value, id);
		return AjaxJson.getByLine(line);
	}
	
	
	
	
	

}
