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

import cn.com.victorysoft.business.condition.dao.ConditionWellDao;
import cn.com.victorysoft.business.condition.entity.ConditionWell;
import cn.com.victorysoft.business.condition.param.ConditionWellParam;
import cn.com.victorysoft.business.condition.param.ConditionWellParam;
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 ConditionWellService {

    @Resource
    private ConditionWellDao conditionWellDao;
    @Resource
    private SysBaseService sysBaseService;

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

    /**
     * 查询列表数据
     */
    public List<ConditionWell> selectList(ConditionWellParam param) {
        return conditionWellDao.selectList(param);
    }

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

    public ConditionWell selectByPrimaryKey(ConditionWell key) {
        return conditionWellDao.selectByPrimaryKey(key);
    }

    public int update(ConditionWell param) {
        param.setModifiedOn(new Date());
        return conditionWellDao.updateByPrimaryKeySelective(param);
    }

    public int delete(ConditionWell param) {
        return conditionWellDao.deleteByPrimaryKey(param);
    }

}
