package com.pj.tb_people_profit;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



/**
 * Controller: tb_people_profit -- 边民收益设置
 * @author qzyReal 
 */
@RestController
@RequestMapping("/TbPeopleProfit/")
public class TbPeopleProfitController {

	/** 底层 Service 对象 */
	@Autowired
	TbPeopleProfitService tbPeopleProfitService;

	/** 增 */  
	@RequestMapping("add")
	//@SaCheckPermission(TbPeopleProfit.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson add(TbPeopleProfit t){
		tbPeopleProfitService.add(t);
		t = tbPeopleProfitService.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(t);
	}

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

    /** 查 - 根据id */
    @RequestMapping("getOne")
    public AjaxJson getOne(){
        TbPeopleProfit t = tbPeopleProfitService.getOne();
        return AjaxJson.getSuccessData(t);
    }

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

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

	
	
	
	

}
