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

import cn.com.tenlion.systembase.dao.homicidepatrol.IHomicidePatrolDao;
import cn.com.tenlion.systembase.pojo.bos.homicidepatrol.HomicidePatrolBO;
import cn.com.tenlion.systembase.pojo.dtos.homicidepatrol.HomicidePatrolDTO;
import cn.com.tenlion.systembase.pojo.pos.homicidepatrol.HomicidePatrolPO;
import cn.com.tenlion.systembase.pojo.vos.homicidepatrol.HomicidePatrolVO;
import cn.com.tenlion.systembase.service.homicidepatrol.IHomicidePatrolService;
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: HomicidePatrolServiceImpl
 * @Description: 命案发生地巡查记录
 * @Author: CodeFactory
 * @Date: 2021-10-20 10:44:13
 * @Version: 3.0
 **/
@Service
public class HomicidePatrolServiceImpl extends DefaultBaseService implements IHomicidePatrolService {

    @Autowired
    private IHomicidePatrolDao homicidePatrolDao;

    @Override
    public void save(HomicidePatrolVO homicidePatrolVO) {
        saveReturnId(homicidePatrolVO);
    }

    @Override
    public void save(String token, HomicidePatrolVO homicidePatrolVO) {
        saveReturnId(token, homicidePatrolVO);
    }

    @Override
    public String saveReturnId(HomicidePatrolVO homicidePatrolVO) {
        return saveReturnId(null, homicidePatrolVO);
    }

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

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

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

    @Override
    public void update(String homicidePatrolId, HomicidePatrolVO homicidePatrolVO) {
        update(null, homicidePatrolId, homicidePatrolVO);
    }

    @Override
    public void update(String token, String homicidePatrolId, HomicidePatrolVO homicidePatrolVO) {
        Map<String, Object> params = HashMapUtil.beanToMap(homicidePatrolVO);
        params.put("homicidePatrolId", homicidePatrolId);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        homicidePatrolDao.update(params);
    }

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

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

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

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

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

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

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

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

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

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

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

}