package org.linlinjava.jz.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.jz.db.dao.JzDmTicketResultMapper;
import org.linlinjava.jz.db.domain.JzDmTicketResult;
import org.linlinjava.jz.db.domain.JzDmTicketResultExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

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

/***
 * 工单处理结果处理类
 */
@Service
public class JzDmTicketResultService {

    @Resource
    private JzDmTicketResultMapper resultMapper;

    public List<JzDmTicketResult> querySelective(String name, Integer page, Integer limit, String sort, String order) {
        JzDmTicketResultExample example = new JzDmTicketResultExample();
        JzDmTicketResultExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return resultMapper.selectByExample(example);
    }

    public int add(JzDmTicketResult department) {
        department.setCreateTime(LocalDateTime.now());
        department.setUpdateTime(LocalDateTime.now());
        return resultMapper.insertSelective(department);
    }

    public int deleteById(JzDmTicketResult result) {
        result.setUpdateTime(LocalDateTime.now());
        result.setDeleted(true);
        return resultMapper.updateByPrimaryKeySelective(result);
    }

    public int updateById(JzDmTicketResult result) {
        result.setUpdateTime(LocalDateTime.now());
        return resultMapper.updateByPrimaryKeySelective(result);
    }

    public JzDmTicketResult findById(Integer id) {
        return resultMapper.selectByPrimaryKey(id);

    }

    public List<JzDmTicketResult> queryAll(){
        JzDmTicketResultExample example = new JzDmTicketResultExample();
        example.or().andDeletedEqualTo(false);
        return resultMapper.selectByExample(example);
    }
    
    public List<JzDmTicketResult> queryByType(short type){
        JzDmTicketResultExample example = new JzDmTicketResultExample();
        example.or().andDeletedEqualTo(false).andTypeEqualTo(type);
        return resultMapper.selectByExample(example);
    }
}
