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

import cn.com.tenlion.systembase.dao.homicidevictim.IHomicideVictimDao;
import cn.com.tenlion.systembase.pojo.bos.homicidevictim.HomicideVictimBO;
import cn.com.tenlion.systembase.pojo.dtos.homicidevictim.HomicideVictimDTO;
import cn.com.tenlion.systembase.pojo.pos.homicidevictim.HomicideVictimPO;
import cn.com.tenlion.systembase.pojo.vos.homicidevictim.HomicideVictimVO;
import cn.com.tenlion.systembase.service.homicidevictim.IHomicideVictimService;
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: HomicideVictimServiceImpl
 * @Description: 命案受害人
 * @Author: CodeFactory
 * @Date: 2021-10-19 11:24:35
 * @Version: 3.0
 **/
@Service
public class HomicideVictimServiceImpl extends DefaultBaseService implements IHomicideVictimService {

    @Autowired
    private IHomicideVictimDao homicideVictimDao;

    @Override
    public void save(HomicideVictimVO homicideVictimVO) {
        saveReturnId(homicideVictimVO);
    }

    @Override
    public void save(String token, HomicideVictimVO homicideVictimVO) {
        saveReturnId(token, homicideVictimVO);
    }

    @Override
    public String saveReturnId(HomicideVictimVO homicideVictimVO) {
        return saveReturnId(null, homicideVictimVO);
    }

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

    @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("homicideVictimIds", ids);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        homicideVictimDao.remove(params);
    }

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

    @Override
    public void update(String homicideVictimId, HomicideVictimVO homicideVictimVO) {
        update(null, homicideVictimId, homicideVictimVO);
    }

    @Override
    public void update(String token, String homicideVictimId, HomicideVictimVO homicideVictimVO) {
        Map<String, Object> params = HashMapUtil.beanToMap(homicideVictimVO);
        params.put("homicideVictimId", homicideVictimId);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        homicideVictimDao.update(params);
    }

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

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

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

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

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

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

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

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

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

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

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

}