package com.hfkj.service.audit.impl;

import com.hfkj.dao.AuditMsgMapper;
import com.hfkj.entity.AuditMsg;
import com.hfkj.entity.AuditMsgExample;
import com.hfkj.service.audit.AuditMsgService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("auditMsgService")
public class AuditMsgServiceImpl implements AuditMsgService {

    @Resource
    private AuditMsgMapper auditMsgMapper;

    @Override
    public void create(AuditMsg auditMsg) {
        auditMsgMapper.insert(auditMsg);
    }

    @Override
    public void update(AuditMsg auditMsg) {
        auditMsgMapper.updateByPrimaryKeySelective(auditMsg);
    }

    @Override
    public AuditMsg queryDetail(Long id) {
        return auditMsgMapper.selectByPrimaryKey(id);
    }

    @Override
    public AuditMsg queryDetailByMap(Map<String, Object> map) {
        return null;
    }

    @Override
    public List<AuditMsg> getList(Map<String, Object> map) {
        AuditMsgExample example = new AuditMsgExample();
        AuditMsgExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(MapUtils.getString(map, "submitObjectName"))) {
            criteria.andSubmitObjectNameLike("%"+MapUtils.getString(map, "submitObjectName")+"%");
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map, "submitOpName"))) {
            criteria.andSubmitOpNameLike("%"+MapUtils.getString(map, "submitOpName")+"%");
        }
        if (MapUtils.getInteger(map, "status") != null) {
            criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
        }

        example.setOrderByClause("create_time desc");
        return auditMsgMapper.selectByExample(example)  ;
    }
}
