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

import cn.com.tenlion.systembase.dao.comprehensivemsgcenter.IComprehensiveMsgCenterDao;
import cn.com.tenlion.systembase.pojo.bos.comprehensivemsgcenter.ComprehensiveMsgCenterBO;
import cn.com.tenlion.systembase.pojo.dtos.comprehensivemsgcenter.ComprehensiveMsgCenterDTO;
import cn.com.tenlion.systembase.pojo.dtos.grid.GridDTO;
import cn.com.tenlion.systembase.pojo.pos.comprehensivemsgcenter.ComprehensiveMsgCenterPO;
import cn.com.tenlion.systembase.pojo.vos.comprehensivemsgcenter.ComprehensiveMsgCenterVO;
import cn.com.tenlion.systembase.service.comprehensivemsgcenter.IComprehensiveMsgCenterService;
import cn.com.tenlion.systembase.service.grid.IGridService;
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: ComprehensiveMsgCenterServiceImpl
 * @Description: 综治视联网信息中心
 * @Author: CodeFactory
 * @Date: 2021-10-12 16:04:09
 * @Version: 3.0
 **/
@Service
public class ComprehensiveMsgCenterServiceImpl extends DefaultBaseService implements IComprehensiveMsgCenterService {

    @Autowired
    private IComprehensiveMsgCenterDao comprehensiveMsgCenterDao;
    @Autowired
    private IGridService gridService;

    @Override
    public void save(ComprehensiveMsgCenterVO comprehensiveMsgCenterVO) {
        saveReturnId(comprehensiveMsgCenterVO);
    }

    @Override
    public void save(String token, ComprehensiveMsgCenterVO comprehensiveMsgCenterVO) {
        saveReturnId(token, comprehensiveMsgCenterVO);
    }

    @Override
    public String saveReturnId(ComprehensiveMsgCenterVO comprehensiveMsgCenterVO) {
        return saveReturnId(null, comprehensiveMsgCenterVO);
    }

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

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

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

    @Override
    public void update(String comprehensiveMsgCenterId, ComprehensiveMsgCenterVO comprehensiveMsgCenterVO) {
        update(null, comprehensiveMsgCenterId, comprehensiveMsgCenterVO);
    }

    @Override
    public void update(String token, String comprehensiveMsgCenterId, ComprehensiveMsgCenterVO comprehensiveMsgCenterVO) {
        Map<String, Object> params = HashMapUtil.beanToMap(comprehensiveMsgCenterVO);
        params.put("comprehensiveMsgCenterId", comprehensiveMsgCenterId);
        if (StringUtils.isBlank(token)) {
            setUpdateInfo(params);
        } else {
            setAppUpdateInfo(token, params);
        }
        comprehensiveMsgCenterDao.update(params);
    }

    @Override
    public ComprehensiveMsgCenterDTO get(Map<String, Object> params) {
        ComprehensiveMsgCenterDTO comprehensiveMsgCenterDTO = comprehensiveMsgCenterDao.get(params);
        if(null != comprehensiveMsgCenterDTO) {
            GridDTO gridDTO = gridService.get(comprehensiveMsgCenterDTO.getGrid());
            if(null != gridDTO) {
                comprehensiveMsgCenterDTO.setGridName(gridDTO.getGridName());
            }
        }
        return comprehensiveMsgCenterDTO;
    }

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

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

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

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

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

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

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

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

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

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

}