package cn.com.tenlion.systembase.service.homicidesuspect.impl;

import cn.com.tenlion.systembase.dao.homicidesuspect.IHomicideSuspectDao;
import cn.com.tenlion.systembase.pojo.bos.homicidesuspect.HomicideSuspectBO;
import cn.com.tenlion.systembase.pojo.dtos.homicidesuspect.HomicideSuspectDTO;
import cn.com.tenlion.systembase.pojo.pos.homicidesuspect.HomicideSuspectPO;
import cn.com.tenlion.systembase.pojo.vos.homicidesuspect.HomicideSuspectVO;
import cn.com.tenlion.systembase.service.homicidesuspect.IHomicideSuspectService;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.util.map.HashMapUtil;
import ink.wgink.util.UUIDUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName: HomicideSuspectServiceImpl
 * @Description: 命案犯罪嫌疑人
 * @Author: CodeFactory
 * @Date: 2021-10-19 10:59:12
 * @Version: 3.0
 **/
@Service
public class HomicideSuspectServiceImpl extends DefaultBaseService implements IHomicideSuspectService {

    @Autowired
    private IHomicideSuspectDao homicideSuspectDao;

    @Override
    public void save(HomicideSuspectVO homicideSuspectVO) {
        saveReturnId(homicideSuspectVO);
    }

    @Override
    public void save(String token, HomicideSuspectVO homicideSuspectVO) {
        saveReturnId(token, homicideSuspectVO);
    }

    @Override
    public String saveReturnId(HomicideSuspectVO homicideSuspectVO) {
        return saveReturnId(null, homicideSuspectVO);
    }

    @Override
    public String saveReturnId(String token, HomicideSuspectVO homicideSuspectVO) {
        String homicideSuspectId = UUIDUtil.getUUID();
        Map<String, Object> params = HashMapUtil.beanToMap(homicideSuspectVO);
        params.put("homicideSuspectId", homicideSuspectId);
        if (StringUtils.isBlank(token)) {
            setSaveInfo(params);
        } else {
            setAppSaveInfo(token, params);
        }
        homicideSuspectDao.save(params);
        return homicideSuspectId;
    }

    @Override
    public void remove(List<String> ids) {
        remove(null, ids);
    }

    @Override
    public void remove(String token, List<String> ids) {
        Map<String, Object> params = getHashMap(2);
        params.put("homicideSuspectIds", ids);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        homicideSuspectDao.remove(params);
    }

    @Override
    public void delete(List<String> ids) {
        Map<String, Object> params = getHashMap(2);
        params.put("homicideSuspectIds", ids);
        homicideSuspectDao.delete(params);
    }

    @Override
    public void update(String homicideSuspectId, HomicideSuspectVO homicideSuspectVO) {
        update(null, homicideSuspectId, homicideSuspectVO);
    }

    @Override
    public void update(String token, String homicideSuspectId, HomicideSuspectVO homicideSuspectVO) {
        Map<String, Object> params = HashMapUtil.beanToMap(homicideSuspectVO);
        params.put("homicideSuspectId", homicideSuspectId);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        homicideSuspectDao.update(params);
    }

    @Override
    public HomicideSuspectDTO get(Map<String, Object> params) {
        return homicideSuspectDao.get(params);
    }

    @Override
    public HomicideSuspectDTO get(String homicideSuspectId) {
        Map<String, Object> params = super.getHashMap(2);
        params.put("homicideSuspectId", homicideSuspectId);
        return get(params);
    }

    @Override
    public HomicideSuspectBO getBO(Map<String, Object> params) {
        return homicideSuspectDao.getBO(params);
    }

    @Override
    public HomicideSuspectBO getBO(String homicideSuspectId) {
        Map<String, Object> params = super.getHashMap(2);
        params.put("homicideSuspectId", homicideSuspectId);
        return getBO(params);
    }

    @Override
    public HomicideSuspectPO getPO(Map<String, Object> params) {
        return homicideSuspectDao.getPO(params);
    }

    @Override
    public HomicideSuspectPO getPO(String homicideSuspectId) {
        Map<String, Object> params = super.getHashMap(2);
        params.put("homicideSuspectId", homicideSuspectId);
        return getPO(params);
    }

    @Override
    public List<HomicideSuspectDTO> list(Map<String, Object> params) {
        return homicideSuspectDao.list(params);
    }

    @Override
    public List<HomicideSuspectBO> listBO(Map<String, Object> params) {
        return homicideSuspectDao.listBO(params);
    }

    @Override
    public List<HomicideSuspectPO> listPO(Map<String, Object> params) {
        return homicideSuspectDao.listPO(params);
    }

    @Override
    public SuccessResultList<List<HomicideSuspectDTO>> listPage(ListPage page) {
        PageHelper.startPage(page.getPage(), page.getRows());
        List<HomicideSuspectDTO> homicideSuspectDTOs = list(page.getParams());
        PageInfo<HomicideSuspectDTO> pageInfo = new PageInfo<>(homicideSuspectDTOs);
        return new SuccessResultList<>(homicideSuspectDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
    }

    @Override
    public Integer count(Map<String, Object> params) {
        Integer count = homicideSuspectDao.count(params);
        return count == null ? 0 : count;
    }

}