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

import cn.com.victorysoft.business.condition.dao.AbnormalWellDao;
import cn.com.victorysoft.business.condition.dao.AdjustPlanDao;
import cn.com.victorysoft.business.condition.entity.AbnormalWell;
import cn.com.victorysoft.business.condition.entity.AdjustPlan;
import cn.com.victorysoft.business.condition.param.AbnormalWellParam;
import cn.com.victorysoft.business.sys.entity.WellBasic;
import cn.com.victorysoft.business.sys.param.UnitBlockDateWellPageParam;
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 AbnormalWellService {

    @Resource
    private AbnormalWellDao abnormalWellDao;
    @Resource
    private SysBaseService sysBaseService;

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

    /**
     * 查询列表数据
     */
    public List<AbnormalWell> selectList(AbnormalWellParam param) {
        return abnormalWellDao.selectList(param);
    }

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

    public AbnormalWell selectByPrimaryKey(AbnormalWell key) {
        return abnormalWellDao.selectByPrimaryKey(key);
    }

    public int update(AbnormalWell param) {
        param.setModifiedOn(new Date());
        return abnormalWellDao.updateByPrimaryKeySelective(param);
    }

    public int delete(AbnormalWell param) {
        return abnormalWellDao.deleteByPrimaryKey(param);
    }

    public int deleteByDate(Date date) {
        return abnormalWellDao.deleteByDate(date);
    }
}
