package com.gyee.frame.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.P3DeviceFaultMapper;
import com.gyee.frame.model.auto.P3DeviceFault;
import com.gyee.frame.model.auto.P3DeviceFaultExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * 故障知识 P3DeviceFaultService
 *
 * @author gyee_自动生成
 * @Title: P3DeviceFaultService.java 
 * @Package com.gyee.frame.service 
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class P3DeviceFaultService implements BaseService<P3DeviceFault, P3DeviceFaultExample> {
    @Resource
    private P3DeviceFaultMapper p3DeviceFaultMapper;


    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = Convert.toListStrArray(ids);
        P3DeviceFaultExample example = new P3DeviceFaultExample();
        example.createCriteria().andIdIn(lista);
        return p3DeviceFaultMapper.deleteByExample(example);


    }


    @Override
    public P3DeviceFault selectByPrimaryKey(String id) {

        return p3DeviceFaultMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(P3DeviceFault record) {
        return p3DeviceFaultMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(P3DeviceFault record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return p3DeviceFaultMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(P3DeviceFault record, P3DeviceFaultExample example) {

        return p3DeviceFaultMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(P3DeviceFault record, P3DeviceFaultExample example) {

        return p3DeviceFaultMapper.updateByExample(record, example);
    }

    @Override
    public List<P3DeviceFault> selectByExample(P3DeviceFaultExample example) {

        return p3DeviceFaultMapper.selectByExample(example);
    }


    @Override
    public long countByExample(P3DeviceFaultExample example) {

        return p3DeviceFaultMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(P3DeviceFaultExample example) {

        return p3DeviceFaultMapper.deleteByExample(example);
    }



    public PageInfo<P3DeviceFault> findP3DeviceFaultList(Tablepar tablepar, String name, String halttype, String faultlevel) {


        PageInfo<P3DeviceFault> pageInfo = new PageInfo<>();


        P3DeviceFaultExample example = new P3DeviceFaultExample();

        if (StringUtils.isNotEmpty(tablepar.getOrderByColumn())) {
            StringBuilder sb = new StringBuilder();
            sb.append(" ").append(tablepar.getOrderByColumn());
            if (StringUtils.isNotEmpty(tablepar.getIsAsc())) {
                sb.append(" ").append(tablepar.getIsAsc());
            } else {
                sb.append(" asc ");
            }
            example.setOrderByClause(String.valueOf(sb));
        } else {
            example.setOrderByClause("name ASC");
        }

        P3DeviceFaultExample.Criteria criteria = example.createCriteria();

        if (StringUtils.notEmp(name)) {

            criteria.andNameLike("%" + name + "%");
        }

        if (StringUtils.notEmp(halttype)) {

            criteria.andHalttypeLike("%" + halttype + "%");
        }

        if (StringUtils.notEmp(faultlevel)) {

            criteria.andFaultlevelEqualTo(Integer.valueOf(faultlevel) );
        }


        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
        List<P3DeviceFault> vos = p3DeviceFaultMapper.selectByExample(example);
        pageInfo = new PageInfo<P3DeviceFault>(vos);


        return pageInfo;

    }

    public List<P3DeviceFault> findAll() {

        P3DeviceFaultExample example = new P3DeviceFaultExample();

        List<P3DeviceFault> list =p3DeviceFaultMapper.selectByExample(example);

        return list;


    }
}
