package com.pj.project.tb_item;

import java.util.List;

import com.pj.utils.so.SoMap;
import org.aspectj.weaver.loadtime.Aj;
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_item -- 作业配置项
 * @author qzy 
 */
@RestController
@RequestMapping("/TbItem/")
public class TbItemController {

	/** 底层 Service 对象 */
	@Autowired
	TbItemService tbItemService;

	/** 增 */  
	@RequestMapping("add")
	@SaCheckPermission(TbItem.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson add(TbItem t){
		tbItemService.save(t);
		return AjaxJson.getSuccessData(t);
	}

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

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

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

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

    /** 改 - 状态(0=否,1=是) */
    @RequestMapping("updateStatus")
    @SaCheckPermission(TbItem.PERMISSION_CODE)
    public AjaxJson updateStatus(String id, int value){
        int line = SP.publicMapper.updateColumnById(TbItem.TABLE_NAME, "status", value, id);
        return AjaxJson.getByLine(line);
    }



    @RequestMapping(value = "getItemType")
    public AjaxJson getItemType(){
    	return AjaxJson.getSuccessData(TbItem.ItemTypeEnum.getList());
	}
	
	// ------------------------- 前端接口 -------------------------
	

	
	
	
	
	

}
