package com.pj.tb_fee_item;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pj.current.satoken.StpUserUtil;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service: tb_fee_item -- 费项管理
 * @author yzs 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbFeeItemService extends ServiceImpl<TbFeeItemMapper, TbFeeItem> implements IService<TbFeeItem>{

	/** 底层 Mapper 对象 */
	@Autowired
	TbFeeItemMapper tbFeeItemMapper;

	/** 增 */
	void add(TbFeeItem t){
		t.setCreateTime(new Date()).setUpdateTime(new Date());
		save(t);
	}

	/** 删 */
	void delete(Long id){
		removeById(id);
	}

	/** 改 */
	void update(TbFeeItem t){
		t.setCreateTime(new Date()).setUpdateTime(new Date())
				.setUpdateBy(StpUserUtil.getLoginIdAsString())
				.setUpdateByName(StpUserUtil.getLoginName());
		updateById(t);

	}

	/** 查 */
	TbFeeItem getById(Long id){
		return super.getById(id);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	public List<TbFeeItem> getList(SoMap so) {
		return tbFeeItemMapper.getList(so);	
	}

	/**
	 * 查询所有税费
	 * @return
	 */
	public List<TbFeeItem> getFeeItems() {
		SoMap so=new SoMap();
		so.put("status",1);
		return tbFeeItemMapper.getList(so);
	}

	/**
	 * 根据收费公司查找
	 * @param companyId
	 * @return
	 */
	public List<TbFeeItem> findByCompanyId(Long companyId) {
		QueryWrapper<TbFeeItem>ew=new QueryWrapper<>();
		ew.lambda().eq(TbFeeItem::getCompanyId,companyId);
		return list(ew);
	}
}
