package com.pj.project.relation_goods_type;

import java.util.List;

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: relation_goods_type -- 业务类型与作业项
 * @author qzy 
 */
@RestController
@RequestMapping("/RelationGoodsType/")
public class RelationGoodsTypeController {

	/** 底层 Service 对象 */
	@Autowired
	RelationGoodsTypeService relationGoodsTypeService;

	/** 增 */  
	@RequestMapping("saveBatch")
	public AjaxJson saveBatch(){
		SoMap so = SoMap.getRequestSoMap();
		Long goodsId=so.getLong("goodsId");
		String typeIds=so.getString("typeIds");
		relationGoodsTypeService.saveBatch(goodsId,typeIds);
		return AjaxJson.getSuccess();
	}	/** 增 */
	@RequestMapping("saveSingle")
	public AjaxJson saveSingle(){
		SoMap so = SoMap.getRequestSoMap();
		String goodsId=so.getString("goodsId");
		String typeId=so.getString("typeId");
		relationGoodsTypeService.saveSingle(goodsId,typeId);
		return AjaxJson.getSuccess();
	}

	/** 删 */  
	@RequestMapping("delete")
	public AjaxJson delete(Long id){
		relationGoodsTypeService.removeById(id);
		return AjaxJson.getSuccess();
	}
	
	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
		int line = SP.publicMapper.deleteByIds(RelationGoodsType.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 */  
	@RequestMapping("update")
	@SaCheckPermission(RelationGoodsType.PERMISSION_CODE)
	public AjaxJson update(RelationGoodsType r){
		relationGoodsTypeService.updateById(r);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		RelationGoodsType r = relationGoodsTypeService.getById(id);
		return AjaxJson.getSuccessData(r);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
	public AjaxJson getList() { 
		SoMap so = SoMap.getRequestSoMap();
		List<RelationGoodsType> list = relationGoodsTypeService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}

	
	/** 改 - 是否必选(1=是,0=否) */  
	@RequestMapping("updateNeedSelect")
	public AjaxJson updateNeedSelect(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(RelationGoodsType.TABLE_NAME, "need_select", value, id);
		return AjaxJson.getByLine(line);
	}
	
	
	// ------------------------- 前端接口 -------------------------
	

	
	
	
	
	

}
