package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.OwnerInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.OwnerInfo;
import com.jpsoft.shinestar.modules.base.service.OwnerInfoService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

@Transactional
@Component(value = "ownerInfoService")
public class OwnerInfoServiceImpl implements OwnerInfoService {
    @Resource(name = "ownerInfoDAO")
    private OwnerInfoDAO ownerInfoDAO;

    @Override
    public OwnerInfo get(String id) {
        // TODO Auto-generated method stub
        return ownerInfoDAO.get(id);
    }

    @Override
    public int insert(OwnerInfo model) {
        // TODO Auto-generated method stub
        //model.setId(UUID.randomUUID().toString());

        return ownerInfoDAO.insert(model);
    }

    @Override
    public int update(OwnerInfo model) {
        // TODO Auto-generated method stub
        return ownerInfoDAO.update(model);
    }

    @Override
    public int delete(String id) {
        // TODO Auto-generated method stub
        return ownerInfoDAO.delete(id);
    }

    @Override
    public List<Map> findByTel(String tel) {
        return ownerInfoDAO.findByTel(tel);
    }

    @Override
    public boolean exist(String id) {
        // TODO Auto-generated method stub
        int count = ownerInfoDAO.exist(id);

        return count > 0 ? true : false;
    }

    @Override
    public List<OwnerInfo> list() {
        // TODO Auto-generated method stub
        return ownerInfoDAO.list();
    }

    @Override
    public Page<OwnerInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, List<Sort> sortList) {
        Page<OwnerInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(() -> {
            ownerInfoDAO.search(searchParams, sortList);
        });

        return page;
    }
}