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

import cn.com.victorysoft.business.condition.dao.AdjustRecordDao;
import cn.com.victorysoft.business.condition.entity.AdjustRecord;
import cn.com.victorysoft.business.sys.entity.WellBasic;
import cn.com.victorysoft.business.sys.param.UnitBlockDateWellPageParam;
import cn.com.victorysoft.business.sys.param.UnitBlockWellPageParam;
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 AdjustRecordService {

    @Resource
    private AdjustRecordDao adjustRecordDao;
    @Resource
    private SysBaseService sysBaseService;

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

    /**
     * 查询列表数据
     */
    public List<AdjustRecord> selectList(UnitBlockWellPageParam param) {
        return adjustRecordDao.selectList(param);
    }

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

    public AdjustRecord selectByPrimaryKey(AdjustRecord key) {
        return adjustRecordDao.selectByPrimaryKey(key);
    }

    public int update(AdjustRecord param) {
        param.setModifiedOn(new Date());
        return adjustRecordDao.updateByPrimaryKeySelective(param);
    }

    public int delete(AdjustRecord param) {
        return adjustRecordDao.deleteByPrimaryKey(param);
    }

}
