/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.zdb.service.impl;

import org.springblade.modules.system.vo.ZdbVo;
import org.springblade.modules.zdb.entity.ZdbEntity;
import org.springblade.modules.zdb.vo.JdVo;
import org.springblade.modules.zdb.vo.SqVo;
import org.springblade.modules.zdb.vo.XqVo;
import org.springblade.modules.zdb.vo.ZdbVO;
import org.springblade.modules.zdb.excel.ZdbExcel;
import org.springblade.modules.zdb.mapper.ZdbMapper;
import org.springblade.modules.zdb.service.IZdbService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.List;

/**
 * 字典表 服务实现类
 *
 * @author BladeX
 * @since 2023-12-28
 */
@Service
public class ZdbServiceImpl extends BaseServiceImpl<ZdbMapper, ZdbEntity> implements IZdbService {

	@Override
	public IPage<ZdbVO> selectZdbPage(IPage<ZdbVO> page, ZdbVO zdb) {
		return page.setRecords(baseMapper.selectZdbPage(page, zdb));
	}


	@Override
	public List<ZdbExcel> exportZdb(Wrapper<ZdbEntity> queryWrapper) {
		List<ZdbExcel> zdbList = baseMapper.exportZdb(queryWrapper);
		//zdbList.forEach(zdb -> {
		//	zdb.setTypeName(DictCache.getValue(DictEnum.YES_NO, Zdb.getType()));
		//});
		return zdbList;
	}

	@Override
	public XqVo getChildrenByZddm(String zddm) {
		XqVo xqVo = new XqVo();
		//根据县区代码获取街道
		List<JdVo> jdList = baseMapper.getJdByZddm(zddm);
		if(jdList.size()>0){
			//循环获取街道下的社区
			for (int i = 0; i < jdList.size(); i++) {
				JdVo jdVo = jdList.get(i);
				String jdZddm = jdVo.getZddm();
				String jdZdz = jdVo.getZdz();
				List<SqVo> sqList = baseMapper.getSqByZddm(jdZddm);
				if(sqList.size()>0){
					for (int j = 0; j < sqList.size(); j++) {
						sqList.get(j).setJdZddm(jdZddm);
						sqList.get(j).setJdZdz(jdZdz);
					}
					jdVo.setSqVoList(sqList);
				}
			}
			xqVo.setJdVoList(jdList);
		}
		return xqVo;
	}

	@Override
	public List<ZdbEntity> getParentsBySqbm(String zddm) {
		return baseMapper.getParentsBySqbm(zddm);
	}

	@Override
	public ZdbEntity getDetailByZddm(String zddm) {
		return baseMapper.getDetailByZddm(zddm);
	}

	@Override
	public ZdbEntity getDeptByZddm(String zddm) {
		return baseMapper.getDeptByZddm(zddm);
	}

	@Override
	public void saveZdb(ZdbEntity zdbEntity) {
		baseMapper.saveZdb(zdbEntity);
	}

	@Override
	public ZdbEntity selectZddm(String jdid) {
		return baseMapper.selectZddm(jdid);
	}

	@Override
	public ZdbEntity selectParent(String jdid) {
		return baseMapper.selectParent(jdid);
	}
}
