package com.hfkj.service.user.impl;

import com.hfkj.dao.BsUserComplaintMapper;
import com.hfkj.entity.BsUserComplaint;
import com.hfkj.entity.BsUserComplaintExample;
import com.hfkj.service.user.BsUserComplaintService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("bsUserComplaintService")
public class BsUserComplaintServiceImpl implements BsUserComplaintService {

    @Resource
    private BsUserComplaintMapper bsUserComplaintMapper;

    @Override
    public void create(BsUserComplaint userComplaint) {
        bsUserComplaintMapper.insert(userComplaint);
    }

    @Override
    public void update(BsUserComplaint userComplaint) {
        bsUserComplaintMapper.updateByPrimaryKeySelective(userComplaint);
    }

    @Override
    public void delete(Long id, Boolean fullDelete) {
        if (fullDelete) {
            bsUserComplaintMapper.deleteByPrimaryKey(id);
        } else {
            BsUserComplaint bsUserComplaint = queryDetail(id);
            bsUserComplaint.setUpdateTime(new Date());
            update(bsUserComplaint);
        }
    }

    @Override
    public BsUserComplaint queryDetail(Long id) {
        return bsUserComplaintMapper.selectByPrimaryKey(id);
    }

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

    @Override
    public List<BsUserComplaint> getList(Map<String, Object> map) {
        BsUserComplaintExample bsUserComplaintExample = new BsUserComplaintExample();
        BsUserComplaintExample.Criteria criteria = bsUserComplaintExample.createCriteria();

        if (StringUtils.isNotBlank(MapUtils.getString(map, "name"))) {
            criteria.andNameLike("%"+MapUtils.getString(map, "name")+"%");
        }

        if (StringUtils.isNotBlank(MapUtils.getString(map, "phone"))) {
            criteria.andPhoneLike("%"+MapUtils.getString(map, "phone")+"%");
        }

        return bsUserComplaintMapper.selectByExample(bsUserComplaintExample);
    }
}
