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

import cn.com.victorysoft.business.condition.dao.AbnormalWellReasonDao;
import cn.com.victorysoft.business.condition.entity.AbnormalWellReason;
import cn.com.victorysoft.business.condition.param.AbnormalWellReasonParam;
import cn.com.victorysoft.business.sys.entity.WellBasic;
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 AbnormalWellReasonService {

    @Resource
    private AbnormalWellReasonDao abnormalWellReasonDao;
    @Resource
    private SysBaseService sysBaseService;

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

    /**
     * 查询列表数据
     */
    public List<AbnormalWellReason> selectList(AbnormalWellReasonParam param) {
        return abnormalWellReasonDao.selectList(param);
    }

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

    public AbnormalWellReason selectByPrimaryKey(AbnormalWellReason key) {
        return abnormalWellReasonDao.selectByPrimaryKey(key);
    }

    public int update(AbnormalWellReason param) {
        param.setModifiedOn(new Date());
        return abnormalWellReasonDao.updateByPrimaryKeySelective(param);
    }

    public int delete(AbnormalWellReason param) {
        return abnormalWellReasonDao.deleteByPrimaryKey(param);
    }

}
