package com.railway.business.baseinfo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.railway.business.baseinfo.mapper.BasePreventTreeMapper;
import com.railway.business.baseinfo.domain.BasePreventTree;
import com.railway.business.baseinfo.service.IBasePreventTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.railway.common.utils.SecurityUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Date;
/**
* 九防台账-防树
* @author wuhonghao
* @date 2021/11/13
*/
@Service
@Transactional(readOnly = true)
public class BasePreventTreeServiceImpl implements IBasePreventTreeService{
@Autowired
private BasePreventTreeMapper basePreventTreeMapper;

	/**
	* 新增
	*/
	@Transactional(rollbackFor = Exception.class)
	public int create(BasePreventTree basePreventTree) {
	    basePreventTree.setCreateTime(new Date());
        basePreventTree.setCreateBy(SecurityUtils.getUsername());
		if(basePreventTree.getPiecewise()==null||basePreventTree.getPiecewise().equals("")){
			basePreventTree.setPiecewise("changchun");
		}
		return basePreventTreeMapper.insert(basePreventTree);
	}

	/**
	* 删除
	*/
	@Transactional(rollbackFor = Exception.class)
	public int delete(String[] ids) {
		int r =0;
		for (String id : ids) {
			int j= basePreventTreeMapper.delete(id);
			r = r + j;
		}
		return	r;
	}

	/**
	* 更新
	*/
	@Transactional(rollbackFor = Exception.class)
	public int update(BasePreventTree basePreventTree) {
		basePreventTree.setUpdateTime(new Date());
    	basePreventTree.setUpdateBy(SecurityUtils.getUsername());
		return basePreventTreeMapper.update(basePreventTree);
	}

	/**
	* 获取单个
	*/
	public BasePreventTree getInfo(String id) {
		return basePreventTreeMapper.getInfo(id);
	}

	/**
	* 查询列表
	*/
	public List<BasePreventTree> getList(BasePreventTree basePreventTree) {
		return basePreventTreeMapper.getList(basePreventTree);
	}
}
