package cn.com.victorysoft.business.condition.service;

import cn.com.victorysoft.business.condition.dao.FlushRecordDao;
import cn.com.victorysoft.business.condition.entity.FlushRecord;
import cn.com.victorysoft.business.sys.entity.WellBasic;
import cn.com.victorysoft.business.sys.param.UnitDatePageParam;
import cn.com.victorysoft.business.sys.service.SysBaseService;
import cn.com.victorysoft.business.util.PageUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class FlushRecordService {

    @Resource
    private FlushRecordDao flushRecordDao;
    @Resource
    private SysBaseService sysBaseService;

    /**
     * 查询分页数据
     */
    public PageInfo<FlushRecord> selectPage(UnitDatePageParam param) {
        PageUtils.startPage(param);
        return new PageInfo<>(this.selectList(param));
    }

    /**
     * 查询列表数据
     */
    public List<FlushRecord> selectList(UnitDatePageParam param) {
        return flushRecordDao.selectList(param);
    }

    public int insert(FlushRecord param) {
        WellBasic wellBasic = sysBaseService.selectWellBasic(param.getWellname());
        param.setUnitcode(wellBasic.getUnitcode());
        param.setCreatedOn(new Date());
        return flushRecordDao.insert(param);
    }

    public FlushRecord selectByPrimaryKey(FlushRecord key) {
        return flushRecordDao.selectByPrimaryKey(key);
    }

    public int update(FlushRecord param) {
        param.setModifiedOn(new Date());
        return flushRecordDao.updateByPrimaryKeySelective(param);
    }

    public int delete(FlushRecord param) {
        return flushRecordDao.deleteByPrimaryKey(param);
    }

}
