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

import cn.com.tenlion.systembase.dao.logisticssafepatrol.ILogisticsSafePatrolDao;
import cn.com.tenlion.systembase.pojo.bos.logisticssafepatrol.LogisticsSafePatrolBO;
import cn.com.tenlion.systembase.pojo.dtos.logisticssafepatrol.LogisticsSafePatrolDTO;
import cn.com.tenlion.systembase.pojo.pos.logisticssafepatrol.LogisticsSafePatrolPO;
import cn.com.tenlion.systembase.pojo.vos.logisticssafepatrol.LogisticsSafePatrolVO;
import cn.com.tenlion.systembase.service.logisticssafepatrol.ILogisticsSafePatrolService;
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: LogisticsSafePatrolServiceImpl
 * @Description: 寄递物流安全巡查
 * @Author: CodeFactory
 * @Date: 2021-10-20 11:28:32
 * @Version: 3.0
 **/
@Service
public class LogisticsSafePatrolServiceImpl extends DefaultBaseService implements ILogisticsSafePatrolService {

    @Autowired
    private ILogisticsSafePatrolDao logisticsSafePatrolDao;

    @Override
    public void save(LogisticsSafePatrolVO logisticsSafePatrolVO) {
        saveReturnId(logisticsSafePatrolVO);
    }

    @Override
    public void save(String token, LogisticsSafePatrolVO logisticsSafePatrolVO) {
        saveReturnId(token, logisticsSafePatrolVO);
    }

    @Override
    public String saveReturnId(LogisticsSafePatrolVO logisticsSafePatrolVO) {
        return saveReturnId(null, logisticsSafePatrolVO);
    }

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

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

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

    @Override
    public void update(String logisticsSafePatrolId, LogisticsSafePatrolVO logisticsSafePatrolVO) {
        update(null, logisticsSafePatrolId, logisticsSafePatrolVO);
    }

    @Override
    public void update(String token, String logisticsSafePatrolId, LogisticsSafePatrolVO logisticsSafePatrolVO) {
        Map<String, Object> params = HashMapUtil.beanToMap(logisticsSafePatrolVO);
        params.put("logisticsSafePatrolId", logisticsSafePatrolId);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        logisticsSafePatrolDao.update(params);
    }

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

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

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

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

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

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

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

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

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

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

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

}